Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit 77ba81c

Browse files
authored
Add operator!= to SpanContext. (#193)
Motivated by EXPECT_NE() in unit tests.
1 parent 8e16ed0 commit 77ba81c

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

opencensus/trace/internal/span_context.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ bool SpanContext::operator==(const SpanContext& that) const {
2323
return trace_id_ == that.trace_id() && span_id_ == that.span_id();
2424
}
2525

26+
bool SpanContext::operator!=(const SpanContext& that) const {
27+
return !(*this == that);
28+
}
29+
2630
bool SpanContext::IsValid() const {
2731
return trace_id_.IsValid() && span_id_.IsValid();
2832
}

opencensus/trace/internal/span_context_test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ TEST(SpanContextTest, Equality) {
4747
SpanContext ctx4{TraceId(trace_id), SpanId(span_id), TraceOptions(opts)};
4848

4949
EXPECT_EQ(ctx1, ctx1);
50+
EXPECT_NE(ctx1, ctx2);
5051
EXPECT_EQ(ctx1, ctx3) << "Same contents, different objects.";
5152
EXPECT_EQ(ctx1, ctx4) << "Comparison ignores options.";
5253
EXPECT_FALSE(ctx1 == ctx2);

opencensus/trace/span_context.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class SpanContext final {
5656
// not TraceOptions!
5757
bool operator==(const SpanContext& that) const;
5858

59+
// Compares two SpanContexts for inequality. Only compares TraceId and SpanId,
60+
// not TraceOptions!
61+
bool operator!=(const SpanContext& that) const;
62+
5963
// Returns true if SpanId and TraceId are valid.
6064
bool IsValid() const;
6165

0 commit comments

Comments
 (0)