Add unit tests for RTCStatMember properties

Bug: None
Change-Id: I3cf9639229c3519b894882805fac7203ad8cf172
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/278840
Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38360}
This commit is contained in:
Evan Shrubsole 2022-10-11 13:18:38 +00:00 committed by WebRTC LUCI CQ
parent 4d47e0b2be
commit 22e0e614bb

View file

@ -393,6 +393,116 @@ TEST(RTCStatsTest, IsStandardized) {
EXPECT_FALSE(unstandardized.is_standardized()); EXPECT_FALSE(unstandardized.is_standardized());
} }
TEST(RTCStatsTest, IsSequence) {
RTCTestStats stats("statsId", 42);
EXPECT_FALSE(stats.m_bool.is_sequence());
EXPECT_FALSE(stats.m_int32.is_sequence());
EXPECT_FALSE(stats.m_uint32.is_sequence());
EXPECT_FALSE(stats.m_int64.is_sequence());
EXPECT_FALSE(stats.m_uint64.is_sequence());
EXPECT_FALSE(stats.m_double.is_sequence());
EXPECT_FALSE(stats.m_string.is_sequence());
EXPECT_TRUE(stats.m_sequence_bool.is_sequence());
EXPECT_TRUE(stats.m_sequence_int32.is_sequence());
EXPECT_TRUE(stats.m_sequence_uint32.is_sequence());
EXPECT_TRUE(stats.m_sequence_int64.is_sequence());
EXPECT_TRUE(stats.m_sequence_uint64.is_sequence());
EXPECT_TRUE(stats.m_sequence_double.is_sequence());
EXPECT_TRUE(stats.m_sequence_string.is_sequence());
EXPECT_FALSE(stats.m_map_string_uint64.is_sequence());
EXPECT_FALSE(stats.m_map_string_double.is_sequence());
}
TEST(RTCStatsTest, Type) {
RTCTestStats stats("statsId", 42);
EXPECT_EQ(RTCStatsMemberInterface::kBool, stats.m_bool.type());
EXPECT_EQ(RTCStatsMemberInterface::kInt32, stats.m_int32.type());
EXPECT_EQ(RTCStatsMemberInterface::kUint32, stats.m_uint32.type());
EXPECT_EQ(RTCStatsMemberInterface::kInt64, stats.m_int64.type());
EXPECT_EQ(RTCStatsMemberInterface::kUint64, stats.m_uint64.type());
EXPECT_EQ(RTCStatsMemberInterface::kDouble, stats.m_double.type());
EXPECT_EQ(RTCStatsMemberInterface::kString, stats.m_string.type());
EXPECT_EQ(RTCStatsMemberInterface::kSequenceBool,
stats.m_sequence_bool.type());
EXPECT_EQ(RTCStatsMemberInterface::kSequenceInt32,
stats.m_sequence_int32.type());
EXPECT_EQ(RTCStatsMemberInterface::kSequenceUint32,
stats.m_sequence_uint32.type());
EXPECT_EQ(RTCStatsMemberInterface::kSequenceInt64,
stats.m_sequence_int64.type());
EXPECT_EQ(RTCStatsMemberInterface::kSequenceUint64,
stats.m_sequence_uint64.type());
EXPECT_EQ(RTCStatsMemberInterface::kSequenceDouble,
stats.m_sequence_double.type());
EXPECT_EQ(RTCStatsMemberInterface::kSequenceString,
stats.m_sequence_string.type());
EXPECT_EQ(RTCStatsMemberInterface::kMapStringUint64,
stats.m_map_string_uint64.type());
EXPECT_EQ(RTCStatsMemberInterface::kMapStringDouble,
stats.m_map_string_double.type());
}
TEST(RTCStatsTest, IsString) {
RTCTestStats stats("statsId", 42);
EXPECT_TRUE(stats.m_string.is_string());
EXPECT_FALSE(stats.m_bool.is_string());
EXPECT_FALSE(stats.m_int32.is_string());
EXPECT_FALSE(stats.m_uint32.is_string());
EXPECT_FALSE(stats.m_int64.is_string());
EXPECT_FALSE(stats.m_uint64.is_string());
EXPECT_FALSE(stats.m_double.is_string());
EXPECT_FALSE(stats.m_sequence_bool.is_string());
EXPECT_FALSE(stats.m_sequence_int32.is_string());
EXPECT_FALSE(stats.m_sequence_uint32.is_string());
EXPECT_FALSE(stats.m_sequence_int64.is_string());
EXPECT_FALSE(stats.m_sequence_uint64.is_string());
EXPECT_FALSE(stats.m_sequence_double.is_string());
EXPECT_FALSE(stats.m_sequence_string.is_string());
EXPECT_FALSE(stats.m_map_string_uint64.is_string());
EXPECT_FALSE(stats.m_map_string_double.is_string());
}
TEST(RTCStatsTest, ValueToString) {
RTCTestStats stats("statsId", 42);
stats.m_bool = true;
EXPECT_EQ("true", stats.m_bool.ValueToString());
stats.m_string = "foo";
EXPECT_EQ("foo", stats.m_string.ValueToString());
stats.m_int32 = -32;
EXPECT_EQ("-32", stats.m_int32.ValueToString());
stats.m_uint32 = 32;
EXPECT_EQ("32", stats.m_uint32.ValueToString());
stats.m_int64 = -64;
EXPECT_EQ("-64", stats.m_int64.ValueToString());
stats.m_uint64 = 64;
EXPECT_EQ("64", stats.m_uint64.ValueToString());
stats.m_double = 0.5;
EXPECT_EQ("0.5", stats.m_double.ValueToString());
stats.m_sequence_bool = {true, false};
EXPECT_EQ("[true,false]", stats.m_sequence_bool.ValueToString());
stats.m_sequence_int32 = {-32, 32};
EXPECT_EQ("[-32,32]", stats.m_sequence_int32.ValueToString());
stats.m_sequence_uint32 = {64, 32};
EXPECT_EQ("[64,32]", stats.m_sequence_uint32.ValueToString());
stats.m_sequence_int64 = {-64, 32};
EXPECT_EQ("[-64,32]", stats.m_sequence_int64.ValueToString());
stats.m_sequence_uint64 = {16, 32};
EXPECT_EQ("[16,32]", stats.m_sequence_uint64.ValueToString());
stats.m_sequence_double = {0.5, 0.25};
EXPECT_EQ("[0.5,0.25]", stats.m_sequence_double.ValueToString());
stats.m_sequence_string = {"foo", "bar"};
EXPECT_EQ("[\"foo\",\"bar\"]", stats.m_sequence_string.ValueToString());
stats.m_map_string_uint64 = std::map<std::string, uint64_t>();
stats.m_map_string_uint64->emplace("foo", 32);
stats.m_map_string_uint64->emplace("bar", 64);
EXPECT_EQ("{bar:64,foo:32}", stats.m_map_string_uint64.ValueToString());
stats.m_map_string_double = std::map<std::string, double>();
stats.m_map_string_double->emplace("foo", 0.5);
stats.m_map_string_double->emplace("bar", 0.25);
EXPECT_EQ("{bar:0.25,foo:0.5}", stats.m_map_string_double.ValueToString());
}
TEST(RTCStatsTest, NonStandardGroupId) { TEST(RTCStatsTest, NonStandardGroupId) {
auto group_id = NonStandardGroupId::kGroupIdForTesting; auto group_id = NonStandardGroupId::kGroupIdForTesting;
RTCNonStandardStatsMember<int32_t> with_group_id("stat", {group_id}); RTCNonStandardStatsMember<int32_t> with_group_id("stat", {group_id});