Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: webrtc/stats/rtcstats_unittest.cc

Issue 2340303002: Removed the const char* (StaticString) type from RTCStatsMember. (Closed)
Patch Set: Fixed error Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/stats/rtcstats.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/api/rtcstats.h" 11 #include "webrtc/api/rtcstats.h"
12 12
13 #include <cstring> 13 #include <cstring>
14 14
15 #include "webrtc/base/checks.h" 15 #include "webrtc/base/checks.h"
16 #include "webrtc/base/gunit.h" 16 #include "webrtc/base/gunit.h"
17 17
18 namespace webrtc { 18 namespace webrtc {
19 19
20 class RTCTestStats : public RTCStats { 20 class RTCTestStats : public RTCStats {
21 public: 21 public:
22 RTCTestStats(const std::string& id, int64_t timestamp_us) 22 RTCTestStats(const std::string& id, int64_t timestamp_us)
23 : RTCStats(id, timestamp_us), 23 : RTCStats(id, timestamp_us),
24 m_int32("mInt32"), 24 m_int32("mInt32"),
25 m_uint32("mUint32"), 25 m_uint32("mUint32"),
26 m_int64("mInt64"), 26 m_int64("mInt64"),
27 m_uint64("mUint64"), 27 m_uint64("mUint64"),
28 m_double("mDouble"), 28 m_double("mDouble"),
29 m_static_string("mStaticString"),
30 m_string("mString"), 29 m_string("mString"),
31 m_sequence_int32("mSequenceInt32"), 30 m_sequence_int32("mSequenceInt32"),
32 m_sequence_uint32("mSequenceUint32"), 31 m_sequence_uint32("mSequenceUint32"),
33 m_sequence_int64("mSequenceInt64"), 32 m_sequence_int64("mSequenceInt64"),
34 m_sequence_uint64("mSequenceUint64"), 33 m_sequence_uint64("mSequenceUint64"),
35 m_sequence_double("mSequenceDouble"), 34 m_sequence_double("mSequenceDouble"),
36 m_sequence_static_string("mSequenceStaticString"),
37 m_sequence_string("mSequenceString") { 35 m_sequence_string("mSequenceString") {
38 } 36 }
39 37
40 WEBRTC_RTCSTATS_IMPL(RTCStats, RTCTestStats, 38 WEBRTC_RTCSTATS_IMPL(RTCStats, RTCTestStats,
41 &m_int32, 39 &m_int32,
42 &m_uint32, 40 &m_uint32,
43 &m_int64, 41 &m_int64,
44 &m_uint64, 42 &m_uint64,
45 &m_double, 43 &m_double,
46 &m_static_string,
47 &m_string, 44 &m_string,
48 &m_sequence_int32, 45 &m_sequence_int32,
49 &m_sequence_uint32, 46 &m_sequence_uint32,
50 &m_sequence_int64, 47 &m_sequence_int64,
51 &m_sequence_uint64, 48 &m_sequence_uint64,
52 &m_sequence_double, 49 &m_sequence_double,
53 &m_sequence_static_string,
54 &m_sequence_string); 50 &m_sequence_string);
55 51
56 RTCStatsMember<int32_t> m_int32; 52 RTCStatsMember<int32_t> m_int32;
57 RTCStatsMember<uint32_t> m_uint32; 53 RTCStatsMember<uint32_t> m_uint32;
58 RTCStatsMember<int64_t> m_int64; 54 RTCStatsMember<int64_t> m_int64;
59 RTCStatsMember<uint64_t> m_uint64; 55 RTCStatsMember<uint64_t> m_uint64;
60 RTCStatsMember<double> m_double; 56 RTCStatsMember<double> m_double;
61 RTCStatsMember<const char*> m_static_string;
62 RTCStatsMember<std::string> m_string; 57 RTCStatsMember<std::string> m_string;
63 58
64 RTCStatsMember<std::vector<int32_t>> m_sequence_int32; 59 RTCStatsMember<std::vector<int32_t>> m_sequence_int32;
65 RTCStatsMember<std::vector<uint32_t>> m_sequence_uint32; 60 RTCStatsMember<std::vector<uint32_t>> m_sequence_uint32;
66 RTCStatsMember<std::vector<int64_t>> m_sequence_int64; 61 RTCStatsMember<std::vector<int64_t>> m_sequence_int64;
67 RTCStatsMember<std::vector<uint64_t>> m_sequence_uint64; 62 RTCStatsMember<std::vector<uint64_t>> m_sequence_uint64;
68 RTCStatsMember<std::vector<double>> m_sequence_double; 63 RTCStatsMember<std::vector<double>> m_sequence_double;
69 RTCStatsMember<std::vector<const char*>> m_sequence_static_string;
70 RTCStatsMember<std::vector<std::string>> m_sequence_string; 64 RTCStatsMember<std::vector<std::string>> m_sequence_string;
71 }; 65 };
72 66
73 const char RTCTestStats::kType[] = "test-stats"; 67 const char RTCTestStats::kType[] = "test-stats";
74 68
75 class RTCChildStats : public RTCStats { 69 class RTCChildStats : public RTCStats {
76 public: 70 public:
77 RTCChildStats(const std::string& id, int64_t timestamp_us) 71 RTCChildStats(const std::string& id, int64_t timestamp_us)
78 : RTCStats(id, timestamp_us), 72 : RTCStats(id, timestamp_us),
79 child_int("childInt") {} 73 child_int("childInt") {}
(...skipping 18 matching lines...) Expand all
98 RTCStatsMember<int32_t> grandchild_int; 92 RTCStatsMember<int32_t> grandchild_int;
99 }; 93 };
100 94
101 const char RTCGrandChildStats::kType[] = "grandchild-stats"; 95 const char RTCGrandChildStats::kType[] = "grandchild-stats";
102 96
103 TEST(RTCStatsTest, RTCStatsAndMembers) { 97 TEST(RTCStatsTest, RTCStatsAndMembers) {
104 RTCTestStats stats("testId", 42); 98 RTCTestStats stats("testId", 42);
105 EXPECT_EQ(stats.id(), "testId"); 99 EXPECT_EQ(stats.id(), "testId");
106 EXPECT_EQ(stats.timestamp_us(), static_cast<int64_t>(42)); 100 EXPECT_EQ(stats.timestamp_us(), static_cast<int64_t>(42));
107 std::vector<const RTCStatsMemberInterface*> members = stats.Members(); 101 std::vector<const RTCStatsMemberInterface*> members = stats.Members();
108 EXPECT_EQ(members.size(), static_cast<size_t>(14)); 102 EXPECT_EQ(members.size(), static_cast<size_t>(12));
109 for (const RTCStatsMemberInterface* member : members) { 103 for (const RTCStatsMemberInterface* member : members) {
110 EXPECT_FALSE(member->is_defined()); 104 EXPECT_FALSE(member->is_defined());
111 } 105 }
112 stats.m_int32 = 123; 106 stats.m_int32 = 123;
113 stats.m_uint32 = 123; 107 stats.m_uint32 = 123;
114 stats.m_int64 = 123; 108 stats.m_int64 = 123;
115 stats.m_uint64 = 123; 109 stats.m_uint64 = 123;
116 stats.m_double = 123.0; 110 stats.m_double = 123.0;
117 stats.m_static_string = "123";
118 stats.m_string = std::string("123"); 111 stats.m_string = std::string("123");
119 112
120 std::vector<int32_t> sequence_int32; 113 std::vector<int32_t> sequence_int32;
121 sequence_int32.push_back(static_cast<int32_t>(1)); 114 sequence_int32.push_back(static_cast<int32_t>(1));
122 std::vector<uint32_t> sequence_uint32; 115 std::vector<uint32_t> sequence_uint32;
123 sequence_uint32.push_back(static_cast<uint32_t>(2)); 116 sequence_uint32.push_back(static_cast<uint32_t>(2));
124 std::vector<int64_t> sequence_int64; 117 std::vector<int64_t> sequence_int64;
125 sequence_int64.push_back(static_cast<int64_t>(3)); 118 sequence_int64.push_back(static_cast<int64_t>(3));
126 std::vector<uint64_t> sequence_uint64; 119 std::vector<uint64_t> sequence_uint64;
127 sequence_uint64.push_back(static_cast<uint64_t>(4)); 120 sequence_uint64.push_back(static_cast<uint64_t>(4));
128 std::vector<double> sequence_double; 121 std::vector<double> sequence_double;
129 sequence_double.push_back(5.0); 122 sequence_double.push_back(5.0);
130 std::vector<const char*> sequence_static_string;
131 sequence_static_string.push_back("six");
132 std::vector<std::string> sequence_string; 123 std::vector<std::string> sequence_string;
133 sequence_string.push_back(std::string("seven")); 124 sequence_string.push_back(std::string("six"));
134 125
135 stats.m_sequence_int32 = sequence_int32; 126 stats.m_sequence_int32 = sequence_int32;
136 stats.m_sequence_uint32 = sequence_uint32; 127 stats.m_sequence_uint32 = sequence_uint32;
137 EXPECT_FALSE(stats.m_sequence_int64.is_defined()); 128 EXPECT_FALSE(stats.m_sequence_int64.is_defined());
138 stats.m_sequence_int64 = sequence_int64; 129 stats.m_sequence_int64 = sequence_int64;
139 stats.m_sequence_uint64 = sequence_uint64; 130 stats.m_sequence_uint64 = sequence_uint64;
140 stats.m_sequence_double = sequence_double; 131 stats.m_sequence_double = sequence_double;
141 stats.m_sequence_static_string = sequence_static_string;
142 stats.m_sequence_string = sequence_string; 132 stats.m_sequence_string = sequence_string;
143 for (const RTCStatsMemberInterface* member : members) { 133 for (const RTCStatsMemberInterface* member : members) {
144 EXPECT_TRUE(member->is_defined()); 134 EXPECT_TRUE(member->is_defined());
145 } 135 }
146 EXPECT_EQ(*stats.m_int32, static_cast<int32_t>(123)); 136 EXPECT_EQ(*stats.m_int32, static_cast<int32_t>(123));
147 EXPECT_EQ(*stats.m_uint32, static_cast<uint32_t>(123)); 137 EXPECT_EQ(*stats.m_uint32, static_cast<uint32_t>(123));
148 EXPECT_EQ(*stats.m_int64, static_cast<int64_t>(123)); 138 EXPECT_EQ(*stats.m_int64, static_cast<int64_t>(123));
149 EXPECT_EQ(*stats.m_uint64, static_cast<uint64_t>(123)); 139 EXPECT_EQ(*stats.m_uint64, static_cast<uint64_t>(123));
150 EXPECT_EQ(*stats.m_double, 123.0); 140 EXPECT_EQ(*stats.m_double, 123.0);
151 EXPECT_EQ(strcmp(*stats.m_static_string, "123"), 0);
152 EXPECT_EQ(*stats.m_string, std::string("123")); 141 EXPECT_EQ(*stats.m_string, std::string("123"));
153 EXPECT_EQ(*stats.m_sequence_int32, sequence_int32); 142 EXPECT_EQ(*stats.m_sequence_int32, sequence_int32);
154 EXPECT_EQ(*stats.m_sequence_uint32, sequence_uint32); 143 EXPECT_EQ(*stats.m_sequence_uint32, sequence_uint32);
155 EXPECT_EQ(*stats.m_sequence_int64, sequence_int64); 144 EXPECT_EQ(*stats.m_sequence_int64, sequence_int64);
156 EXPECT_EQ(*stats.m_sequence_uint64, sequence_uint64); 145 EXPECT_EQ(*stats.m_sequence_uint64, sequence_uint64);
157 EXPECT_EQ(*stats.m_sequence_double, sequence_double); 146 EXPECT_EQ(*stats.m_sequence_double, sequence_double);
158 EXPECT_EQ(stats.m_sequence_static_string->size(),
159 sequence_static_string.size());
160 for (size_t i = 0; i < sequence_static_string.size(); ++i) {
161 EXPECT_EQ(strcmp((*stats.m_sequence_static_string)[i],
162 sequence_static_string[i]), 0);
163 }
164 EXPECT_EQ(*stats.m_sequence_string, sequence_string); 147 EXPECT_EQ(*stats.m_sequence_string, sequence_string);
165 148
166 int32_t numbers[] = { 4, 8, 15, 16, 23, 42 }; 149 int32_t numbers[] = { 4, 8, 15, 16, 23, 42 };
167 std::vector<int32_t> numbers_sequence(&numbers[0], &numbers[6]); 150 std::vector<int32_t> numbers_sequence(&numbers[0], &numbers[6]);
168 stats.m_sequence_int32->clear(); 151 stats.m_sequence_int32->clear();
169 stats.m_sequence_int32->insert(stats.m_sequence_int32->end(), 152 stats.m_sequence_int32->insert(stats.m_sequence_int32->end(),
170 numbers_sequence.begin(), 153 numbers_sequence.begin(),
171 numbers_sequence.end()); 154 numbers_sequence.end());
172 EXPECT_EQ(*stats.m_sequence_int32, numbers_sequence); 155 EXPECT_EQ(*stats.m_sequence_int32, numbers_sequence);
173 } 156 }
(...skipping 26 matching lines...) Expand all
200 } 183 }
201 184
202 TEST(RTCStatsDeathTest, InvalidCasting) { 185 TEST(RTCStatsDeathTest, InvalidCasting) {
203 RTCGrandChildStats stats("grandchild", 0.0); 186 RTCGrandChildStats stats("grandchild", 0.0);
204 EXPECT_DEATH(stats.cast_to<RTCChildStats>(), ""); 187 EXPECT_DEATH(stats.cast_to<RTCChildStats>(), "");
205 } 188 }
206 189
207 #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) 190 #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
208 191
209 } // namespace webrtc 192 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/stats/rtcstats.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698