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}
This commit is contained in:
hbos 2016-11-21 09:17:41 -08:00 committed by Commit bot
parent f570a2804e
commit 28747969cd
2 changed files with 8 additions and 0 deletions

View File

@ -271,6 +271,8 @@ class RTCStatsMember : public RTCStatsMemberInterface {
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;

View File

@ -172,6 +172,12 @@ TEST(RTCStatsTest, EqualityOperator) {
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) {