blob: aff6ab30bd9bf8a53e5d9b05478a2e4c4007062d [file] [log] [blame]
hbos615d3012016-08-24 01:33:13 -07001/*
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Steve Anton10542f22019-01-11 09:11:00 -080011#include "api/stats/rtc_stats.h"
hbos615d3012016-08-24 01:33:13 -070012
ehmaldonado35a872c2017-07-28 07:29:12 -070013#include <cmath>
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <cstdint>
hbosfdafab82016-09-14 06:02:13 -070015#include <cstring>
Yves Gerey3e707812018-11-28 16:47:49 +010016#include <iostream>
hbosfdafab82016-09-14 06:02:13 -070017
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "rtc_base/checks.h"
Sam Zackrissonb45bdb52018-10-02 16:25:59 +020019#include "rtc_base/strings/json.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "stats/test/rtc_test_stats.h"
Yves Gerey3e707812018-11-28 16:47:49 +010021#include "test/gtest.h"
hbos615d3012016-08-24 01:33:13 -070022
23namespace webrtc {
24
ehmaldonado35a872c2017-07-28 07:29:12 -070025namespace {
26
27// JSON stores numbers as floating point numbers with 53 significant bits, which
28// amounts to about 15.95 decimal digits. Thus, when comparing large numbers
29// processed by JSON, that's all the precision we should expect.
30const double JSON_EPSILON = 1e-15;
31
32// We do this since Google Test doesn't support relative error.
33// This is computed as follows:
34// If |a - b| / |a| < EPS, then |a - b| < |a| * EPS, so |a| * EPS is the
35// maximum expected error.
36double GetExpectedError(const double expected_value) {
37 return JSON_EPSILON * fabs(expected_value);
38}
39
40} // namespace
41
hbos615d3012016-08-24 01:33:13 -070042class RTCChildStats : public RTCStats {
43 public:
hbosfc5e0502016-10-06 02:06:10 -070044 WEBRTC_RTCSTATS_DECL();
45
hbos0e6758d2016-08-31 07:57:36 -070046 RTCChildStats(const std::string& id, int64_t timestamp_us)
Yves Gerey665174f2018-06-19 15:03:05 +020047 : RTCStats(id, timestamp_us), child_int("childInt") {}
hbos615d3012016-08-24 01:33:13 -070048
hbos615d3012016-08-24 01:33:13 -070049 RTCStatsMember<int32_t> child_int;
50};
51
Mirko Bonadeic4dd7302019-02-25 09:12:02 +010052WEBRTC_RTCSTATS_IMPL(RTCChildStats, RTCStats, "child-stats", &child_int)
hbos615d3012016-08-24 01:33:13 -070053
54class RTCGrandChildStats : public RTCChildStats {
55 public:
hbosfc5e0502016-10-06 02:06:10 -070056 WEBRTC_RTCSTATS_DECL();
57
hbos0e6758d2016-08-31 07:57:36 -070058 RTCGrandChildStats(const std::string& id, int64_t timestamp_us)
Yves Gerey665174f2018-06-19 15:03:05 +020059 : RTCChildStats(id, timestamp_us), grandchild_int("grandchildInt") {}
hbos615d3012016-08-24 01:33:13 -070060
hbos615d3012016-08-24 01:33:13 -070061 RTCStatsMember<int32_t> grandchild_int;
62};
63
Yves Gerey665174f2018-06-19 15:03:05 +020064WEBRTC_RTCSTATS_IMPL(RTCGrandChildStats,
65 RTCChildStats,
66 "grandchild-stats",
Mirko Bonadeic4dd7302019-02-25 09:12:02 +010067 &grandchild_int)
hbos615d3012016-08-24 01:33:13 -070068
69TEST(RTCStatsTest, RTCStatsAndMembers) {
hbos0e6758d2016-08-31 07:57:36 -070070 RTCTestStats stats("testId", 42);
hbos615d3012016-08-24 01:33:13 -070071 EXPECT_EQ(stats.id(), "testId");
hbos0e6758d2016-08-31 07:57:36 -070072 EXPECT_EQ(stats.timestamp_us(), static_cast<int64_t>(42));
hbos615d3012016-08-24 01:33:13 -070073 std::vector<const RTCStatsMemberInterface*> members = stats.Members();
Byoungchan Lee0a52ede2021-05-22 08:41:02 +090074 EXPECT_EQ(members.size(), static_cast<size_t>(16));
hbos615d3012016-08-24 01:33:13 -070075 for (const RTCStatsMemberInterface* member : members) {
76 EXPECT_FALSE(member->is_defined());
77 }
hbosb20f3872016-10-04 14:37:11 -070078 stats.m_bool = true;
hbos615d3012016-08-24 01:33:13 -070079 stats.m_int32 = 123;
80 stats.m_uint32 = 123;
81 stats.m_int64 = 123;
82 stats.m_uint64 = 123;
83 stats.m_double = 123.0;
hbos615d3012016-08-24 01:33:13 -070084 stats.m_string = std::string("123");
hbosfdafab82016-09-14 06:02:13 -070085
hbosb20f3872016-10-04 14:37:11 -070086 std::vector<bool> sequence_bool;
87 sequence_bool.push_back(true);
hbosfdafab82016-09-14 06:02:13 -070088 std::vector<int32_t> sequence_int32;
89 sequence_int32.push_back(static_cast<int32_t>(1));
90 std::vector<uint32_t> sequence_uint32;
91 sequence_uint32.push_back(static_cast<uint32_t>(2));
92 std::vector<int64_t> sequence_int64;
93 sequence_int64.push_back(static_cast<int64_t>(3));
94 std::vector<uint64_t> sequence_uint64;
95 sequence_uint64.push_back(static_cast<uint64_t>(4));
96 std::vector<double> sequence_double;
97 sequence_double.push_back(5.0);
hbosfdafab82016-09-14 06:02:13 -070098 std::vector<std::string> sequence_string;
hbos8faf9e02016-09-15 06:52:43 -070099 sequence_string.push_back(std::string("six"));
hbosfdafab82016-09-14 06:02:13 -0700100
Byoungchan Lee0a52ede2021-05-22 08:41:02 +0900101 std::map<std::string, uint64_t> map_string_uint64{{"seven", 8}};
102 std::map<std::string, double> map_string_double{{"nine", 10.0}};
103
hbosb20f3872016-10-04 14:37:11 -0700104 stats.m_sequence_bool = sequence_bool;
hbosfdafab82016-09-14 06:02:13 -0700105 stats.m_sequence_int32 = sequence_int32;
106 stats.m_sequence_uint32 = sequence_uint32;
hbos615d3012016-08-24 01:33:13 -0700107 EXPECT_FALSE(stats.m_sequence_int64.is_defined());
hbosfdafab82016-09-14 06:02:13 -0700108 stats.m_sequence_int64 = sequence_int64;
109 stats.m_sequence_uint64 = sequence_uint64;
110 stats.m_sequence_double = sequence_double;
hbosfdafab82016-09-14 06:02:13 -0700111 stats.m_sequence_string = sequence_string;
Byoungchan Lee0a52ede2021-05-22 08:41:02 +0900112 stats.m_map_string_uint64 = map_string_uint64;
113 stats.m_map_string_double = map_string_double;
hbos615d3012016-08-24 01:33:13 -0700114 for (const RTCStatsMemberInterface* member : members) {
115 EXPECT_TRUE(member->is_defined());
116 }
hbosb20f3872016-10-04 14:37:11 -0700117 EXPECT_EQ(*stats.m_bool, true);
hbos615d3012016-08-24 01:33:13 -0700118 EXPECT_EQ(*stats.m_int32, static_cast<int32_t>(123));
119 EXPECT_EQ(*stats.m_uint32, static_cast<uint32_t>(123));
120 EXPECT_EQ(*stats.m_int64, static_cast<int64_t>(123));
121 EXPECT_EQ(*stats.m_uint64, static_cast<uint64_t>(123));
122 EXPECT_EQ(*stats.m_double, 123.0);
hbos615d3012016-08-24 01:33:13 -0700123 EXPECT_EQ(*stats.m_string, std::string("123"));
hbosb20f3872016-10-04 14:37:11 -0700124 EXPECT_EQ(*stats.m_sequence_bool, sequence_bool);
hbosfdafab82016-09-14 06:02:13 -0700125 EXPECT_EQ(*stats.m_sequence_int32, sequence_int32);
126 EXPECT_EQ(*stats.m_sequence_uint32, sequence_uint32);
127 EXPECT_EQ(*stats.m_sequence_int64, sequence_int64);
128 EXPECT_EQ(*stats.m_sequence_uint64, sequence_uint64);
129 EXPECT_EQ(*stats.m_sequence_double, sequence_double);
hbosfdafab82016-09-14 06:02:13 -0700130 EXPECT_EQ(*stats.m_sequence_string, sequence_string);
Byoungchan Lee0a52ede2021-05-22 08:41:02 +0900131 EXPECT_EQ(*stats.m_map_string_uint64, map_string_uint64);
132 EXPECT_EQ(*stats.m_map_string_double, map_string_double);
hbosfdafab82016-09-14 06:02:13 -0700133
Yves Gerey665174f2018-06-19 15:03:05 +0200134 int32_t numbers[] = {4, 8, 15, 16, 23, 42};
hbosfdafab82016-09-14 06:02:13 -0700135 std::vector<int32_t> numbers_sequence(&numbers[0], &numbers[6]);
136 stats.m_sequence_int32->clear();
hbos615d3012016-08-24 01:33:13 -0700137 stats.m_sequence_int32->insert(stats.m_sequence_int32->end(),
138 numbers_sequence.begin(),
139 numbers_sequence.end());
140 EXPECT_EQ(*stats.m_sequence_int32, numbers_sequence);
141}
142
hbos67c8bc42016-10-25 04:31:23 -0700143TEST(RTCStatsTest, EqualityOperator) {
144 RTCTestStats empty_stats("testId", 123);
145 EXPECT_EQ(empty_stats, empty_stats);
146
147 RTCTestStats stats_with_all_values = empty_stats;
148 stats_with_all_values.m_bool = true;
149 stats_with_all_values.m_int32 = 123;
150 stats_with_all_values.m_uint32 = 123;
151 stats_with_all_values.m_int64 = 123;
152 stats_with_all_values.m_uint64 = 123;
153 stats_with_all_values.m_double = 123.0;
154 stats_with_all_values.m_string = "123";
155 stats_with_all_values.m_sequence_bool = std::vector<bool>();
156 stats_with_all_values.m_sequence_int32 = std::vector<int32_t>();
157 stats_with_all_values.m_sequence_uint32 = std::vector<uint32_t>();
158 stats_with_all_values.m_sequence_int64 = std::vector<int64_t>();
159 stats_with_all_values.m_sequence_uint64 = std::vector<uint64_t>();
160 stats_with_all_values.m_sequence_double = std::vector<double>();
161 stats_with_all_values.m_sequence_string = std::vector<std::string>();
Byoungchan Lee0a52ede2021-05-22 08:41:02 +0900162 stats_with_all_values.m_map_string_uint64 = std::map<std::string, uint64_t>();
163 stats_with_all_values.m_map_string_double = std::map<std::string, double>();
hbos67c8bc42016-10-25 04:31:23 -0700164 EXPECT_NE(stats_with_all_values, empty_stats);
165 EXPECT_EQ(stats_with_all_values, stats_with_all_values);
166 EXPECT_NE(stats_with_all_values.m_int32, stats_with_all_values.m_uint32);
167
168 RTCTestStats one_member_different[] = {
Yves Gerey665174f2018-06-19 15:03:05 +0200169 stats_with_all_values, stats_with_all_values, stats_with_all_values,
170 stats_with_all_values, stats_with_all_values, stats_with_all_values,
171 stats_with_all_values, stats_with_all_values, stats_with_all_values,
172 stats_with_all_values, stats_with_all_values, stats_with_all_values,
173 stats_with_all_values, stats_with_all_values,
hbos67c8bc42016-10-25 04:31:23 -0700174 };
175 for (size_t i = 0; i < 14; ++i) {
176 EXPECT_EQ(stats_with_all_values, one_member_different[i]);
177 }
178 one_member_different[0].m_bool = false;
179 one_member_different[1].m_int32 = 321;
180 one_member_different[2].m_uint32 = 321;
181 one_member_different[3].m_int64 = 321;
182 one_member_different[4].m_uint64 = 321;
183 one_member_different[5].m_double = 321.0;
184 one_member_different[6].m_string = "321";
185 one_member_different[7].m_sequence_bool->push_back(false);
186 one_member_different[8].m_sequence_int32->push_back(321);
187 one_member_different[9].m_sequence_uint32->push_back(321);
188 one_member_different[10].m_sequence_int64->push_back(321);
189 one_member_different[11].m_sequence_uint64->push_back(321);
190 one_member_different[12].m_sequence_double->push_back(321.0);
191 one_member_different[13].m_sequence_string->push_back("321");
Byoungchan Lee0a52ede2021-05-22 08:41:02 +0900192 (*one_member_different[13].m_map_string_uint64)["321"] = 321;
193 (*one_member_different[13].m_map_string_double)["321"] = 321.0;
hbos67c8bc42016-10-25 04:31:23 -0700194 for (size_t i = 0; i < 14; ++i) {
195 EXPECT_NE(stats_with_all_values, one_member_different[i]);
196 }
197
198 RTCTestStats empty_stats_different_id("testId2", 123);
199 EXPECT_NE(empty_stats, empty_stats_different_id);
200 RTCTestStats empty_stats_different_timestamp("testId", 321);
hbos0583b282016-11-30 01:50:14 -0800201 EXPECT_EQ(empty_stats, empty_stats_different_timestamp);
hbos67c8bc42016-10-25 04:31:23 -0700202
203 RTCChildStats child("childId", 42);
204 RTCGrandChildStats grandchild("grandchildId", 42);
205 EXPECT_NE(child, grandchild);
hbos28747962016-11-21 09:17:41 -0800206
207 RTCChildStats stats_with_defined_member("leId", 0);
208 stats_with_defined_member.child_int = 0;
209 RTCChildStats stats_with_undefined_member("leId", 0);
210 EXPECT_NE(stats_with_defined_member, stats_with_undefined_member);
211 EXPECT_NE(stats_with_undefined_member, stats_with_defined_member);
hbos67c8bc42016-10-25 04:31:23 -0700212}
213
hbos615d3012016-08-24 01:33:13 -0700214TEST(RTCStatsTest, RTCStatsGrandChild) {
215 RTCGrandChildStats stats("grandchild", 0.0);
216 stats.child_int = 1;
217 stats.grandchild_int = 2;
218 int32_t sum = 0;
219 for (const RTCStatsMemberInterface* member : stats.Members()) {
220 sum += *member->cast_to<const RTCStatsMember<int32_t>>();
221 }
222 EXPECT_EQ(sum, static_cast<int32_t>(3));
223
224 std::unique_ptr<RTCStats> copy_ptr = stats.copy();
225 const RTCGrandChildStats& copy = copy_ptr->cast_to<RTCGrandChildStats>();
226 EXPECT_EQ(*copy.child_int, *stats.child_int);
227 EXPECT_EQ(*copy.grandchild_int, *stats.grandchild_int);
228}
229
ehmaldonado35a872c2017-07-28 07:29:12 -0700230TEST(RTCStatsTest, RTCStatsPrintsValidJson) {
231 std::string id = "statsId";
232 int timestamp = 42;
233 bool m_bool = true;
234 int m_int32 = 123;
235 int64_t m_int64 = 1234567890123456499L;
236 double m_double = 123.4567890123456499;
237 std::string m_string = "123";
238
239 std::vector<bool> sequence_bool;
240 std::vector<int32_t> sequence_int32;
241 sequence_int32.push_back(static_cast<int32_t>(1));
242 std::vector<int64_t> sequence_int64;
243 sequence_int64.push_back(static_cast<int64_t>(-1234567890123456499L));
244 sequence_int64.push_back(static_cast<int64_t>(1));
245 sequence_int64.push_back(static_cast<int64_t>(1234567890123456499L));
246 std::vector<double> sequence_double;
247 sequence_double.push_back(123.4567890123456499);
248 sequence_double.push_back(1234567890123.456499);
249 std::vector<std::string> sequence_string;
250 sequence_string.push_back(std::string("four"));
251
Byoungchan Lee0a52ede2021-05-22 08:41:02 +0900252 std::map<std::string, uint64_t> map_string_uint64{
253 {"long", static_cast<uint64_t>(1234567890123456499L)}};
254 std::map<std::string, double> map_string_double{
255 {"three", 123.4567890123456499}, {"thirteen", 123.4567890123456499}};
256
ehmaldonado35a872c2017-07-28 07:29:12 -0700257 RTCTestStats stats(id, timestamp);
258 stats.m_bool = m_bool;
259 stats.m_int32 = m_int32;
260 stats.m_int64 = m_int64;
261 stats.m_double = m_double;
262 stats.m_string = m_string;
263 stats.m_sequence_bool = sequence_bool;
264 stats.m_sequence_int32 = sequence_int32;
265 stats.m_sequence_int64 = sequence_int64;
266 stats.m_sequence_double = sequence_double;
267 stats.m_sequence_string = sequence_string;
Byoungchan Lee0a52ede2021-05-22 08:41:02 +0900268 stats.m_map_string_uint64 = map_string_uint64;
269 stats.m_map_string_double = map_string_double;
ehmaldonado35a872c2017-07-28 07:29:12 -0700270
271 Json::Value json_output;
272 EXPECT_TRUE(Json::Reader().parse(stats.ToJson(), json_output));
273
274 EXPECT_TRUE(rtc::GetStringFromJsonObject(json_output, "id", &id));
275 EXPECT_TRUE(rtc::GetIntFromJsonObject(json_output, "timestamp", &timestamp));
276 EXPECT_TRUE(rtc::GetBoolFromJsonObject(json_output, "mBool", &m_bool));
277 EXPECT_TRUE(rtc::GetIntFromJsonObject(json_output, "mInt32", &m_int32));
278 EXPECT_TRUE(rtc::GetDoubleFromJsonObject(json_output, "mDouble", &m_double));
279 EXPECT_TRUE(rtc::GetStringFromJsonObject(json_output, "mString", &m_string));
280
281 Json::Value json_array;
282
283 EXPECT_TRUE(
284 rtc::GetValueFromJsonObject(json_output, "mSequenceBool", &json_array));
285 EXPECT_TRUE(rtc::JsonArrayToBoolVector(json_array, &sequence_bool));
286
287 EXPECT_TRUE(
288 rtc::GetValueFromJsonObject(json_output, "mSequenceInt32", &json_array));
289 EXPECT_TRUE(rtc::JsonArrayToIntVector(json_array, &sequence_int32));
290
291 EXPECT_TRUE(
292 rtc::GetValueFromJsonObject(json_output, "mSequenceDouble", &json_array));
293 EXPECT_TRUE(rtc::JsonArrayToDoubleVector(json_array, &sequence_double));
294
295 EXPECT_TRUE(
296 rtc::GetValueFromJsonObject(json_output, "mSequenceString", &json_array));
297 EXPECT_TRUE(rtc::JsonArrayToStringVector(json_array, &sequence_string));
298
Byoungchan Lee0a52ede2021-05-22 08:41:02 +0900299 Json::Value json_map;
300 EXPECT_TRUE(
301 rtc::GetValueFromJsonObject(json_output, "mMapStringDouble", &json_map));
302 for (const auto& entry : map_string_double) {
303 double double_output = 0.0;
304 EXPECT_TRUE(
305 rtc::GetDoubleFromJsonObject(json_map, entry.first, &double_output));
306 EXPECT_NEAR(double_output, entry.second, GetExpectedError(entry.second));
307 }
308
ehmaldonado35a872c2017-07-28 07:29:12 -0700309 EXPECT_EQ(id, stats.id());
310 EXPECT_EQ(timestamp, stats.timestamp_us());
311 EXPECT_EQ(m_bool, *stats.m_bool);
312 EXPECT_EQ(m_int32, *stats.m_int32);
313 EXPECT_EQ(m_string, *stats.m_string);
314 EXPECT_EQ(sequence_bool, *stats.m_sequence_bool);
315 EXPECT_EQ(sequence_int32, *stats.m_sequence_int32);
316 EXPECT_EQ(sequence_string, *stats.m_sequence_string);
Byoungchan Lee0a52ede2021-05-22 08:41:02 +0900317 EXPECT_EQ(map_string_double, *stats.m_map_string_double);
ehmaldonado35a872c2017-07-28 07:29:12 -0700318
319 EXPECT_NEAR(m_double, *stats.m_double, GetExpectedError(*stats.m_double));
320
321 EXPECT_EQ(sequence_double.size(), stats.m_sequence_double->size());
322 for (size_t i = 0; i < stats.m_sequence_double->size(); ++i) {
323 EXPECT_NEAR(sequence_double[i], stats.m_sequence_double->at(i),
324 GetExpectedError(stats.m_sequence_double->at(i)));
325 }
326
Byoungchan Lee0a52ede2021-05-22 08:41:02 +0900327 EXPECT_EQ(map_string_double.size(), stats.m_map_string_double->size());
328 for (const auto& entry : map_string_double) {
329 auto it = stats.m_map_string_double->find(entry.first);
330 EXPECT_NE(it, stats.m_map_string_double->end());
331 EXPECT_NEAR(entry.second, it->second, GetExpectedError(it->second));
332 }
333
ehmaldonado35a872c2017-07-28 07:29:12 -0700334 // We read mInt64 as double since JSON stores all numbers as doubles, so there
335 // is not enough precision to represent large numbers.
336 double m_int64_as_double;
337 std::vector<double> sequence_int64_as_double;
338
339 EXPECT_TRUE(
340 rtc::GetDoubleFromJsonObject(json_output, "mInt64", &m_int64_as_double));
341
342 EXPECT_TRUE(
343 rtc::GetValueFromJsonObject(json_output, "mSequenceInt64", &json_array));
344 EXPECT_TRUE(
345 rtc::JsonArrayToDoubleVector(json_array, &sequence_int64_as_double));
346
347 double stats_m_int64_as_double = static_cast<double>(*stats.m_int64);
348 EXPECT_NEAR(m_int64_as_double, stats_m_int64_as_double,
349 GetExpectedError(stats_m_int64_as_double));
350
351 EXPECT_EQ(sequence_int64_as_double.size(), stats.m_sequence_int64->size());
352 for (size_t i = 0; i < stats.m_sequence_int64->size(); ++i) {
353 const double stats_value_as_double =
354 static_cast<double>((*stats.m_sequence_int64)[i]);
355 EXPECT_NEAR(sequence_int64_as_double[i], stats_value_as_double,
356 GetExpectedError(stats_value_as_double));
357 }
358
Byoungchan Lee0a52ede2021-05-22 08:41:02 +0900359 // Similarly, read Uint64 as double
360 EXPECT_TRUE(
361 rtc::GetValueFromJsonObject(json_output, "mMapStringUint64", &json_map));
362 for (const auto& entry : map_string_uint64) {
363 const double stats_value_as_double =
364 static_cast<double>((*stats.m_map_string_uint64)[entry.first]);
365 double double_output = 0.0;
366 EXPECT_TRUE(
367 rtc::GetDoubleFromJsonObject(json_map, entry.first, &double_output));
368 EXPECT_NEAR(double_output, stats_value_as_double,
369 GetExpectedError(stats_value_as_double));
370 }
371
ehmaldonado35a872c2017-07-28 07:29:12 -0700372 // Neither stats.m_uint32 nor stats.m_uint64 are defined, so "mUint64" and
373 // "mUint32" should not be part of the generated JSON object.
374 int m_uint32;
375 int m_uint64;
376 EXPECT_FALSE(stats.m_uint32.is_defined());
377 EXPECT_FALSE(stats.m_uint64.is_defined());
378 EXPECT_FALSE(rtc::GetIntFromJsonObject(json_output, "mUint32", &m_uint32));
379 EXPECT_FALSE(rtc::GetIntFromJsonObject(json_output, "mUint64", &m_uint64));
380
381 std::cout << stats.ToJson() << std::endl;
382}
383
Taylor Brandstettere2751742018-06-25 13:42:44 -0700384TEST(RTCStatsTest, IsStandardized) {
385 RTCStatsMember<int32_t> standardized("standardized");
386 RTCNonStandardStatsMember<int32_t> unstandardized("unstandardized");
387 EXPECT_TRUE(standardized.is_standardized());
388 EXPECT_FALSE(unstandardized.is_standardized());
389}
390
Jakob Ivarsson758d9462019-03-19 15:38:49 +0100391TEST(RTCStatsTest, NonStandardGroupId) {
Jakob Ivarssonaa023e22019-03-27 10:17:31 +0100392 auto group_id = NonStandardGroupId::kGroupIdForTesting;
Jakob Ivarsson758d9462019-03-19 15:38:49 +0100393 RTCNonStandardStatsMember<int32_t> with_group_id("stat", {group_id});
394 std::vector<NonStandardGroupId> expected_ids({group_id});
395 EXPECT_EQ(expected_ids, with_group_id.group_ids());
396
397 RTCNonStandardStatsMember<int32_t> without_group_id("stat");
398 EXPECT_TRUE(without_group_id.group_ids().empty());
399}
400
hbos615d3012016-08-24 01:33:13 -0700401// Death tests.
402// Disabled on Android because death tests misbehave on Android, see
403// base/test/gtest_util.h.
404#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
405
406TEST(RTCStatsDeathTest, ValueOfUndefinedMember) {
407 RTCTestStats stats("testId", 0.0);
408 EXPECT_FALSE(stats.m_int32.is_defined());
409 EXPECT_DEATH(*stats.m_int32, "");
410}
411
412TEST(RTCStatsDeathTest, InvalidCasting) {
413 RTCGrandChildStats stats("grandchild", 0.0);
414 EXPECT_DEATH(stats.cast_to<RTCChildStats>(), "");
415}
416
417#endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
418
419} // namespace webrtc