RTCStats operator== bugfix
a == b would return true if a.member is defined even if b.member is
undefined if their values were equal. We would say that b does not have
a value in that case but its value_ member would still be initialized to
something that is being compared to. Bugfix makes sure not to do value
comparison in this case if b is undefined.
BUG=chromium:627816
Review-Url: https://codereview.webrtc.org/2517163002
Cr-Commit-Position: refs/heads/master@{#15172}
diff --git a/webrtc/api/stats/rtcstats.h b/webrtc/api/stats/rtcstats.h
index d23e928..aea47c2 100644
--- a/webrtc/api/stats/rtcstats.h
+++ b/webrtc/api/stats/rtcstats.h
@@ -271,6 +271,8 @@
static_cast<const RTCStatsMember<T>&>(other);
if (!is_defined_)
return !other_t.is_defined();
+ if (!other.is_defined())
+ return false;
return value_ == other_t.value_;
}
std::string ValueToString() const override;
diff --git a/webrtc/stats/rtcstats_unittest.cc b/webrtc/stats/rtcstats_unittest.cc
index f245194..7854355 100644
--- a/webrtc/stats/rtcstats_unittest.cc
+++ b/webrtc/stats/rtcstats_unittest.cc
@@ -172,6 +172,12 @@
RTCChildStats child("childId", 42);
RTCGrandChildStats grandchild("grandchildId", 42);
EXPECT_NE(child, grandchild);
+
+ RTCChildStats stats_with_defined_member("leId", 0);
+ stats_with_defined_member.child_int = 0;
+ RTCChildStats stats_with_undefined_member("leId", 0);
+ EXPECT_NE(stats_with_defined_member, stats_with_undefined_member);
+ EXPECT_NE(stats_with_undefined_member, stats_with_defined_member);
}
TEST(RTCStatsTest, RTCStatsGrandChild) {