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 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 106 |
107 int32_t numbers[] = { 4, 8, 15, 16, 23, 42 }; | 107 int32_t numbers[] = { 4, 8, 15, 16, 23, 42 }; |
108 std::vector<int32_t> numbers_sequence(&numbers[0], &numbers[6]); | 108 std::vector<int32_t> numbers_sequence(&numbers[0], &numbers[6]); |
109 stats.m_sequence_int32->clear(); | 109 stats.m_sequence_int32->clear(); |
110 stats.m_sequence_int32->insert(stats.m_sequence_int32->end(), | 110 stats.m_sequence_int32->insert(stats.m_sequence_int32->end(), |
111 numbers_sequence.begin(), | 111 numbers_sequence.begin(), |
112 numbers_sequence.end()); | 112 numbers_sequence.end()); |
113 EXPECT_EQ(*stats.m_sequence_int32, numbers_sequence); | 113 EXPECT_EQ(*stats.m_sequence_int32, numbers_sequence); |
114 } | 114 } |
115 | 115 |
| 116 TEST(RTCStatsTest, EqualityOperator) { |
| 117 RTCTestStats empty_stats("testId", 123); |
| 118 EXPECT_EQ(empty_stats, empty_stats); |
| 119 |
| 120 RTCTestStats stats_with_all_values = empty_stats; |
| 121 stats_with_all_values.m_bool = true; |
| 122 stats_with_all_values.m_int32 = 123; |
| 123 stats_with_all_values.m_uint32 = 123; |
| 124 stats_with_all_values.m_int64 = 123; |
| 125 stats_with_all_values.m_uint64 = 123; |
| 126 stats_with_all_values.m_double = 123.0; |
| 127 stats_with_all_values.m_string = "123"; |
| 128 stats_with_all_values.m_sequence_bool = std::vector<bool>(); |
| 129 stats_with_all_values.m_sequence_int32 = std::vector<int32_t>(); |
| 130 stats_with_all_values.m_sequence_uint32 = std::vector<uint32_t>(); |
| 131 stats_with_all_values.m_sequence_int64 = std::vector<int64_t>(); |
| 132 stats_with_all_values.m_sequence_uint64 = std::vector<uint64_t>(); |
| 133 stats_with_all_values.m_sequence_double = std::vector<double>(); |
| 134 stats_with_all_values.m_sequence_string = std::vector<std::string>(); |
| 135 EXPECT_NE(stats_with_all_values, empty_stats); |
| 136 EXPECT_EQ(stats_with_all_values, stats_with_all_values); |
| 137 EXPECT_NE(stats_with_all_values.m_int32, stats_with_all_values.m_uint32); |
| 138 |
| 139 RTCTestStats one_member_different[] = { |
| 140 stats_with_all_values, stats_with_all_values, stats_with_all_values, |
| 141 stats_with_all_values, stats_with_all_values, stats_with_all_values, |
| 142 stats_with_all_values, stats_with_all_values, stats_with_all_values, |
| 143 stats_with_all_values, stats_with_all_values, stats_with_all_values, |
| 144 stats_with_all_values, stats_with_all_values, |
| 145 }; |
| 146 for (size_t i = 0; i < 14; ++i) { |
| 147 EXPECT_EQ(stats_with_all_values, one_member_different[i]); |
| 148 } |
| 149 one_member_different[0].m_bool = false; |
| 150 one_member_different[1].m_int32 = 321; |
| 151 one_member_different[2].m_uint32 = 321; |
| 152 one_member_different[3].m_int64 = 321; |
| 153 one_member_different[4].m_uint64 = 321; |
| 154 one_member_different[5].m_double = 321.0; |
| 155 one_member_different[6].m_string = "321"; |
| 156 one_member_different[7].m_sequence_bool->push_back(false); |
| 157 one_member_different[8].m_sequence_int32->push_back(321); |
| 158 one_member_different[9].m_sequence_uint32->push_back(321); |
| 159 one_member_different[10].m_sequence_int64->push_back(321); |
| 160 one_member_different[11].m_sequence_uint64->push_back(321); |
| 161 one_member_different[12].m_sequence_double->push_back(321.0); |
| 162 one_member_different[13].m_sequence_string->push_back("321"); |
| 163 for (size_t i = 0; i < 14; ++i) { |
| 164 EXPECT_NE(stats_with_all_values, one_member_different[i]); |
| 165 } |
| 166 |
| 167 RTCTestStats empty_stats_different_id("testId2", 123); |
| 168 EXPECT_NE(empty_stats, empty_stats_different_id); |
| 169 RTCTestStats empty_stats_different_timestamp("testId", 321); |
| 170 EXPECT_NE(empty_stats, empty_stats_different_timestamp); |
| 171 |
| 172 RTCChildStats child("childId", 42); |
| 173 RTCGrandChildStats grandchild("grandchildId", 42); |
| 174 EXPECT_NE(child, grandchild); |
| 175 } |
| 176 |
116 TEST(RTCStatsTest, RTCStatsGrandChild) { | 177 TEST(RTCStatsTest, RTCStatsGrandChild) { |
117 RTCGrandChildStats stats("grandchild", 0.0); | 178 RTCGrandChildStats stats("grandchild", 0.0); |
118 stats.child_int = 1; | 179 stats.child_int = 1; |
119 stats.grandchild_int = 2; | 180 stats.grandchild_int = 2; |
120 int32_t sum = 0; | 181 int32_t sum = 0; |
121 for (const RTCStatsMemberInterface* member : stats.Members()) { | 182 for (const RTCStatsMemberInterface* member : stats.Members()) { |
122 sum += *member->cast_to<const RTCStatsMember<int32_t>>(); | 183 sum += *member->cast_to<const RTCStatsMember<int32_t>>(); |
123 } | 184 } |
124 EXPECT_EQ(sum, static_cast<int32_t>(3)); | 185 EXPECT_EQ(sum, static_cast<int32_t>(3)); |
125 | 186 |
(...skipping 15 matching lines...) Expand all Loading... |
141 } | 202 } |
142 | 203 |
143 TEST(RTCStatsDeathTest, InvalidCasting) { | 204 TEST(RTCStatsDeathTest, InvalidCasting) { |
144 RTCGrandChildStats stats("grandchild", 0.0); | 205 RTCGrandChildStats stats("grandchild", 0.0); |
145 EXPECT_DEATH(stats.cast_to<RTCChildStats>(), ""); | 206 EXPECT_DEATH(stats.cast_to<RTCChildStats>(), ""); |
146 } | 207 } |
147 | 208 |
148 #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | 209 #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
149 | 210 |
150 } // namespace webrtc | 211 } // namespace webrtc |
OLD | NEW |