| 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/stats/rtcstats.h" | 11 #include "webrtc/api/stats/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 #include "webrtc/stats/test/rtcteststats.h" | 17 #include "webrtc/stats/test/rtcteststats.h" |
| 18 | 18 |
| 19 namespace webrtc { | 19 namespace webrtc { |
| 20 | 20 |
| 21 class RTCChildStats : public RTCStats { | 21 class RTCChildStats : public RTCStats { |
| 22 public: | 22 public: |
| 23 WEBRTC_RTCSTATS_DECL(); |
| 24 |
| 23 RTCChildStats(const std::string& id, int64_t timestamp_us) | 25 RTCChildStats(const std::string& id, int64_t timestamp_us) |
| 24 : RTCStats(id, timestamp_us), | 26 : RTCStats(id, timestamp_us), |
| 25 child_int("childInt") {} | 27 child_int("childInt") {} |
| 26 | 28 |
| 27 WEBRTC_RTCSTATS_IMPL(RTCStats, RTCChildStats, | |
| 28 &child_int); | |
| 29 | |
| 30 RTCStatsMember<int32_t> child_int; | 29 RTCStatsMember<int32_t> child_int; |
| 31 }; | 30 }; |
| 32 | 31 |
| 33 const char RTCChildStats::kType[] = "child-stats"; | 32 WEBRTC_RTCSTATS_IMPL(RTCChildStats, RTCStats, "child-stats", |
| 33 &child_int); |
| 34 | 34 |
| 35 class RTCGrandChildStats : public RTCChildStats { | 35 class RTCGrandChildStats : public RTCChildStats { |
| 36 public: | 36 public: |
| 37 WEBRTC_RTCSTATS_DECL(); |
| 38 |
| 37 RTCGrandChildStats(const std::string& id, int64_t timestamp_us) | 39 RTCGrandChildStats(const std::string& id, int64_t timestamp_us) |
| 38 : RTCChildStats(id, timestamp_us), | 40 : RTCChildStats(id, timestamp_us), |
| 39 grandchild_int("grandchildInt") {} | 41 grandchild_int("grandchildInt") {} |
| 40 | 42 |
| 41 WEBRTC_RTCSTATS_IMPL(RTCChildStats, RTCGrandChildStats, | |
| 42 &grandchild_int); | |
| 43 | |
| 44 RTCStatsMember<int32_t> grandchild_int; | 43 RTCStatsMember<int32_t> grandchild_int; |
| 45 }; | 44 }; |
| 46 | 45 |
| 47 const char RTCGrandChildStats::kType[] = "grandchild-stats"; | 46 WEBRTC_RTCSTATS_IMPL(RTCGrandChildStats, RTCChildStats, "grandchild-stats", |
| 47 &grandchild_int); |
| 48 | 48 |
| 49 TEST(RTCStatsTest, RTCStatsAndMembers) { | 49 TEST(RTCStatsTest, RTCStatsAndMembers) { |
| 50 RTCTestStats stats("testId", 42); | 50 RTCTestStats stats("testId", 42); |
| 51 EXPECT_EQ(stats.id(), "testId"); | 51 EXPECT_EQ(stats.id(), "testId"); |
| 52 EXPECT_EQ(stats.timestamp_us(), static_cast<int64_t>(42)); | 52 EXPECT_EQ(stats.timestamp_us(), static_cast<int64_t>(42)); |
| 53 std::vector<const RTCStatsMemberInterface*> members = stats.Members(); | 53 std::vector<const RTCStatsMemberInterface*> members = stats.Members(); |
| 54 EXPECT_EQ(members.size(), static_cast<size_t>(14)); | 54 EXPECT_EQ(members.size(), static_cast<size_t>(14)); |
| 55 for (const RTCStatsMemberInterface* member : members) { | 55 for (const RTCStatsMemberInterface* member : members) { |
| 56 EXPECT_FALSE(member->is_defined()); | 56 EXPECT_FALSE(member->is_defined()); |
| 57 } | 57 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } | 141 } |
| 142 | 142 |
| 143 TEST(RTCStatsDeathTest, InvalidCasting) { | 143 TEST(RTCStatsDeathTest, InvalidCasting) { |
| 144 RTCGrandChildStats stats("grandchild", 0.0); | 144 RTCGrandChildStats stats("grandchild", 0.0); |
| 145 EXPECT_DEATH(stats.cast_to<RTCChildStats>(), ""); | 145 EXPECT_DEATH(stats.cast_to<RTCChildStats>(), ""); |
| 146 } | 146 } |
| 147 | 147 |
| 148 #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) | 148 #endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
| 149 | 149 |
| 150 } // namespace webrtc | 150 } // namespace webrtc |
| OLD | NEW |