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/rtcstatsreport.h" | 11 #include "webrtc/api/stats/rtcstatsreport.h" |
12 | 12 |
13 #include "webrtc/api/stats/rtcstats.h" | 13 #include "webrtc/api/stats/rtcstats.h" |
14 #include "webrtc/base/checks.h" | 14 #include "webrtc/base/checks.h" |
15 #include "webrtc/base/gunit.h" | 15 #include "webrtc/base/gunit.h" |
16 | 16 |
17 namespace webrtc { | 17 namespace webrtc { |
18 | 18 |
19 class RTCTestStats1 : public RTCStats { | 19 class RTCTestStats1 : public RTCStats { |
20 public: | 20 public: |
| 21 WEBRTC_RTCSTATS_DECL(); |
| 22 |
21 RTCTestStats1(const std::string& id, int64_t timestamp_us) | 23 RTCTestStats1(const std::string& id, int64_t timestamp_us) |
22 : RTCStats(id, timestamp_us), | 24 : RTCStats(id, timestamp_us), |
23 integer("integer") {} | 25 integer("integer") {} |
24 | 26 |
25 WEBRTC_RTCSTATS_IMPL(RTCStats, RTCTestStats1, | |
26 &integer); | |
27 | |
28 RTCStatsMember<int32_t> integer; | 27 RTCStatsMember<int32_t> integer; |
29 }; | 28 }; |
30 | 29 |
31 const char RTCTestStats1::kType[] = "test-stats-1"; | 30 WEBRTC_RTCSTATS_IMPL(RTCTestStats1, RTCStats, "test-stats-1", |
| 31 &integer); |
32 | 32 |
33 class RTCTestStats2 : public RTCStats { | 33 class RTCTestStats2 : public RTCStats { |
34 public: | 34 public: |
| 35 WEBRTC_RTCSTATS_DECL(); |
| 36 |
35 RTCTestStats2(const std::string& id, int64_t timestamp_us) | 37 RTCTestStats2(const std::string& id, int64_t timestamp_us) |
36 : RTCStats(id, timestamp_us), | 38 : RTCStats(id, timestamp_us), |
37 number("number") {} | 39 number("number") {} |
38 | 40 |
39 WEBRTC_RTCSTATS_IMPL(RTCStats, RTCTestStats2, | |
40 &number); | |
41 | |
42 RTCStatsMember<double> number; | 41 RTCStatsMember<double> number; |
43 }; | 42 }; |
44 | 43 |
45 const char RTCTestStats2::kType[] = "test-stats-2"; | 44 WEBRTC_RTCSTATS_IMPL(RTCTestStats2, RTCStats, "test-stats-2", |
| 45 &number); |
46 | 46 |
47 class RTCTestStats3 : public RTCStats { | 47 class RTCTestStats3 : public RTCStats { |
48 public: | 48 public: |
| 49 WEBRTC_RTCSTATS_DECL(); |
| 50 |
49 RTCTestStats3(const std::string& id, int64_t timestamp_us) | 51 RTCTestStats3(const std::string& id, int64_t timestamp_us) |
50 : RTCStats(id, timestamp_us), | 52 : RTCStats(id, timestamp_us), |
51 string("string") {} | 53 string("string") {} |
52 | 54 |
53 WEBRTC_RTCSTATS_IMPL(RTCStats, RTCTestStats3, | |
54 &string); | |
55 | |
56 RTCStatsMember<std::string> string; | 55 RTCStatsMember<std::string> string; |
57 }; | 56 }; |
58 | 57 |
59 const char RTCTestStats3::kType[] = "test-stats-3"; | 58 WEBRTC_RTCSTATS_IMPL(RTCTestStats3, RTCStats, "test-stats-3", |
| 59 &string); |
60 | 60 |
61 TEST(RTCStatsReport, AddAndGetStats) { | 61 TEST(RTCStatsReport, AddAndGetStats) { |
62 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(); | 62 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(); |
63 EXPECT_EQ(report->size(), static_cast<size_t>(0)); | 63 EXPECT_EQ(report->size(), static_cast<size_t>(0)); |
64 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a0", 1))); | 64 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a0", 1))); |
65 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a1", 2))); | 65 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a1", 2))); |
66 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("b0", 4))); | 66 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("b0", 4))); |
67 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("b1", 8))); | 67 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("b1", 8))); |
68 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a2", 16))); | 68 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a2", 16))); |
69 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("b2", 32))); | 69 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("b2", 32))); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 EXPECT_EQ(b->size(), static_cast<size_t>(0)); | 122 EXPECT_EQ(b->size(), static_cast<size_t>(0)); |
123 int64_t i = 0; | 123 int64_t i = 0; |
124 for (const RTCStats& stats : *a) { | 124 for (const RTCStats& stats : *a) { |
125 EXPECT_EQ(stats.timestamp_us(), i); | 125 EXPECT_EQ(stats.timestamp_us(), i); |
126 ++i; | 126 ++i; |
127 } | 127 } |
128 EXPECT_EQ(i, static_cast<int64_t>(6)); | 128 EXPECT_EQ(i, static_cast<int64_t>(6)); |
129 } | 129 } |
130 | 130 |
131 } // namespace webrtc | 131 } // namespace webrtc |
OLD | NEW |