OLD | NEW |
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> |
| 14 |
13 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
14 #include "webrtc/base/gunit.h" | 16 #include "webrtc/base/gunit.h" |
15 | 17 |
16 namespace webrtc { | 18 namespace webrtc { |
17 | 19 |
18 class RTCTestStats : public RTCStats { | 20 class RTCTestStats : public RTCStats { |
19 public: | 21 public: |
20 RTCTestStats(const std::string& id, int64_t timestamp_us) | 22 RTCTestStats(const std::string& id, int64_t timestamp_us) |
21 : RTCStats(id, timestamp_us), | 23 : RTCStats(id, timestamp_us), |
22 m_int32("mInt32"), | 24 m_int32("mInt32"), |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 for (const RTCStatsMemberInterface* member : members) { | 109 for (const RTCStatsMemberInterface* member : members) { |
108 EXPECT_FALSE(member->is_defined()); | 110 EXPECT_FALSE(member->is_defined()); |
109 } | 111 } |
110 stats.m_int32 = 123; | 112 stats.m_int32 = 123; |
111 stats.m_uint32 = 123; | 113 stats.m_uint32 = 123; |
112 stats.m_int64 = 123; | 114 stats.m_int64 = 123; |
113 stats.m_uint64 = 123; | 115 stats.m_uint64 = 123; |
114 stats.m_double = 123.0; | 116 stats.m_double = 123.0; |
115 stats.m_static_string = "123"; | 117 stats.m_static_string = "123"; |
116 stats.m_string = std::string("123"); | 118 stats.m_string = std::string("123"); |
117 stats.m_sequence_int32 = std::vector<int32_t>(); | 119 |
118 stats.m_sequence_uint32 = std::vector<uint32_t>(); | 120 std::vector<int32_t> sequence_int32; |
| 121 sequence_int32.push_back(static_cast<int32_t>(1)); |
| 122 std::vector<uint32_t> sequence_uint32; |
| 123 sequence_uint32.push_back(static_cast<uint32_t>(2)); |
| 124 std::vector<int64_t> sequence_int64; |
| 125 sequence_int64.push_back(static_cast<int64_t>(3)); |
| 126 std::vector<uint64_t> sequence_uint64; |
| 127 sequence_uint64.push_back(static_cast<uint64_t>(4)); |
| 128 std::vector<double> sequence_double; |
| 129 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; |
| 133 sequence_string.push_back(std::string("seven")); |
| 134 |
| 135 stats.m_sequence_int32 = sequence_int32; |
| 136 stats.m_sequence_uint32 = sequence_uint32; |
119 EXPECT_FALSE(stats.m_sequence_int64.is_defined()); | 137 EXPECT_FALSE(stats.m_sequence_int64.is_defined()); |
120 stats.m_sequence_int64 = std::vector<int64_t>(); | 138 stats.m_sequence_int64 = sequence_int64; |
121 stats.m_sequence_uint64 = std::vector<uint64_t>(); | 139 stats.m_sequence_uint64 = sequence_uint64; |
122 stats.m_sequence_double = std::vector<double>(); | 140 stats.m_sequence_double = sequence_double; |
123 stats.m_sequence_static_string = std::vector<const char*>(); | 141 stats.m_sequence_static_string = sequence_static_string; |
124 stats.m_sequence_string = std::vector<std::string>(); | 142 stats.m_sequence_string = sequence_string; |
125 for (const RTCStatsMemberInterface* member : members) { | 143 for (const RTCStatsMemberInterface* member : members) { |
126 EXPECT_TRUE(member->is_defined()); | 144 EXPECT_TRUE(member->is_defined()); |
127 } | 145 } |
128 EXPECT_EQ(*stats.m_int32, static_cast<int32_t>(123)); | 146 EXPECT_EQ(*stats.m_int32, static_cast<int32_t>(123)); |
129 EXPECT_EQ(*stats.m_uint32, static_cast<uint32_t>(123)); | 147 EXPECT_EQ(*stats.m_uint32, static_cast<uint32_t>(123)); |
130 EXPECT_EQ(*stats.m_int64, static_cast<int64_t>(123)); | 148 EXPECT_EQ(*stats.m_int64, static_cast<int64_t>(123)); |
131 EXPECT_EQ(*stats.m_uint64, static_cast<uint64_t>(123)); | 149 EXPECT_EQ(*stats.m_uint64, static_cast<uint64_t>(123)); |
132 EXPECT_EQ(*stats.m_double, 123.0); | 150 EXPECT_EQ(*stats.m_double, 123.0); |
133 EXPECT_EQ(*stats.m_static_string, "123"); | 151 EXPECT_EQ(strcmp(*stats.m_static_string, "123"), 0); |
134 EXPECT_EQ(*stats.m_string, std::string("123")); | 152 EXPECT_EQ(*stats.m_string, std::string("123")); |
135 EXPECT_EQ(*stats.m_sequence_int32, std::vector<int32_t>()); | 153 EXPECT_EQ(*stats.m_sequence_int32, sequence_int32); |
136 EXPECT_EQ(*stats.m_sequence_uint32, std::vector<uint32_t>()); | 154 EXPECT_EQ(*stats.m_sequence_uint32, sequence_uint32); |
137 EXPECT_EQ(*stats.m_sequence_int64, std::vector<int64_t>()); | 155 EXPECT_EQ(*stats.m_sequence_int64, sequence_int64); |
138 EXPECT_EQ(*stats.m_sequence_uint64, std::vector<uint64_t>()); | 156 EXPECT_EQ(*stats.m_sequence_uint64, sequence_uint64); |
139 EXPECT_EQ(*stats.m_sequence_double, std::vector<double>()); | 157 EXPECT_EQ(*stats.m_sequence_double, sequence_double); |
140 EXPECT_EQ(*stats.m_sequence_static_string, std::vector<const char*>()); | 158 EXPECT_EQ(stats.m_sequence_static_string->size(), |
141 EXPECT_EQ(*stats.m_sequence_string, std::vector<std::string>()); | 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); |
| 165 |
142 int32_t numbers[] = { 4, 8, 15, 16, 23, 42 }; | 166 int32_t numbers[] = { 4, 8, 15, 16, 23, 42 }; |
143 std::vector<int32_t> numbers_sequence(&numbers[0], &numbers[5]); | 167 std::vector<int32_t> numbers_sequence(&numbers[0], &numbers[6]); |
| 168 stats.m_sequence_int32->clear(); |
144 stats.m_sequence_int32->insert(stats.m_sequence_int32->end(), | 169 stats.m_sequence_int32->insert(stats.m_sequence_int32->end(), |
145 numbers_sequence.begin(), | 170 numbers_sequence.begin(), |
146 numbers_sequence.end()); | 171 numbers_sequence.end()); |
147 EXPECT_EQ(*stats.m_sequence_int32, numbers_sequence); | 172 EXPECT_EQ(*stats.m_sequence_int32, numbers_sequence); |
148 } | 173 } |
149 | 174 |
150 TEST(RTCStatsTest, RTCStatsGrandChild) { | 175 TEST(RTCStatsTest, RTCStatsGrandChild) { |
151 RTCGrandChildStats stats("grandchild", 0.0); | 176 RTCGrandChildStats stats("grandchild", 0.0); |
152 stats.child_int = 1; | 177 stats.child_int = 1; |
153 stats.grandchild_int = 2; | 178 stats.grandchild_int = 2; |
(...skipping 21 matching lines...) Expand all Loading... |
175 } | 200 } |
176 | 201 |
177 TEST(RTCStatsDeathTest, InvalidCasting) { | 202 TEST(RTCStatsDeathTest, InvalidCasting) { |
178 RTCGrandChildStats stats("grandchild", 0.0); | 203 RTCGrandChildStats stats("grandchild", 0.0); |
179 EXPECT_DEATH(stats.cast_to<RTCChildStats>(), ""); | 204 EXPECT_DEATH(stats.cast_to<RTCChildStats>(), ""); |
180 } | 205 } |
181 | 206 |
182 #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | 207 #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
183 | 208 |
184 } // namespace webrtc | 209 } // namespace webrtc |
OLD | NEW |