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

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

Issue 2340443002: Making sure rtc_stats_unittests passes on all bots (tsan fix) (Closed)
Patch Set: String compare fix 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/rtcstatscollector_unittest.cc ('k') | webrtc/stats/stats.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/api/rtcstatsreport.h"
12
13 #include "webrtc/api/rtcstats.h"
14 #include "webrtc/base/checks.h"
15 #include "webrtc/base/gunit.h"
16
17 namespace webrtc {
18
19 class RTCTestStats1 : public RTCStats {
20 public:
21 RTCTestStats1(const std::string& id, int64_t timestamp_us)
22 : RTCStats(id, timestamp_us),
23 integer("integer") {}
24
25 WEBRTC_RTCSTATS_IMPL(RTCStats, RTCTestStats1,
26 &integer);
27
28 RTCStatsMember<int32_t> integer;
29 };
30
31 const char RTCTestStats1::kType[] = "test-stats-1";
32
33 class RTCTestStats2 : public RTCStats {
34 public:
35 RTCTestStats2(const std::string& id, int64_t timestamp_us)
36 : RTCStats(id, timestamp_us),
37 number("number") {}
38
39 WEBRTC_RTCSTATS_IMPL(RTCStats, RTCTestStats2,
40 &number);
41
42 RTCStatsMember<double> number;
43 };
44
45 const char RTCTestStats2::kType[] = "test-stats-2";
46
47 class RTCTestStats3 : public RTCStats {
48 public:
49 RTCTestStats3(const std::string& id, int64_t timestamp_us)
50 : RTCStats(id, timestamp_us),
51 string("string") {}
52
53 WEBRTC_RTCSTATS_IMPL(RTCStats, RTCTestStats3,
54 &string);
55
56 RTCStatsMember<std::string> string;
57 };
58
59 const char RTCTestStats3::kType[] = "test-stats-3";
60
61 TEST(RTCStatsReport, AddAndGetStats) {
62 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create();
63 EXPECT_EQ(report->size(), static_cast<size_t>(0));
64 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a0", 1)));
65 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a1", 2)));
66 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("b0", 4)));
67 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("b1", 8)));
68 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("a2", 16)));
69 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("b2", 32)));
70 EXPECT_EQ(report->size(), static_cast<size_t>(6));
71
72 EXPECT_EQ(report->Get("missing"), nullptr);
73 EXPECT_EQ(report->Get("a0")->id(), "a0");
74 EXPECT_EQ(report->Get("b2")->id(), "b2");
75
76 std::vector<const RTCTestStats1*> a = report->GetStatsOfType<RTCTestStats1>();
77 EXPECT_EQ(a.size(), static_cast<size_t>(3));
78 int64_t mask = 0;
79 for (const RTCTestStats1* stats : a)
80 mask |= stats->timestamp_us();
81 EXPECT_EQ(mask, static_cast<int64_t>(1 | 2 | 16));
82
83 std::vector<const RTCTestStats2*> b = report->GetStatsOfType<RTCTestStats2>();
84 EXPECT_EQ(b.size(), static_cast<size_t>(3));
85 mask = 0;
86 for (const RTCTestStats2* stats : b)
87 mask |= stats->timestamp_us();
88 EXPECT_EQ(mask, static_cast<int64_t>(4 | 8 | 32));
89
90 EXPECT_EQ(report->GetStatsOfType<RTCTestStats3>().size(),
91 static_cast<size_t>(0));
92 }
93
94 TEST(RTCStatsReport, StatsOrder) {
95 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create();
96 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("C", 2)));
97 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("D", 3)));
98 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("B", 1)));
99 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("A", 0)));
100 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("E", 4)));
101 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("F", 5)));
102 report->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats2("G", 6)));
103 int64_t i = 0;
104 for (const RTCStats& stats : *report) {
105 EXPECT_EQ(stats.timestamp_us(), i);
106 ++i;
107 }
108 EXPECT_EQ(i, static_cast<int64_t>(7));
109 }
110
111 TEST(RTCStatsReport, TakeMembersFrom) {
112 rtc::scoped_refptr<RTCStatsReport> a = RTCStatsReport::Create();
113 a->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("B", 1)));
114 a->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("C", 2)));
115 a->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("E", 4)));
116 rtc::scoped_refptr<RTCStatsReport> b = RTCStatsReport::Create();
117 b->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("A", 0)));
118 b->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("D", 3)));
119 b->AddStats(std::unique_ptr<RTCStats>(new RTCTestStats1("F", 5)));
120
121 a->TakeMembersFrom(b);
122 EXPECT_EQ(b->size(), static_cast<size_t>(0));
123 int64_t i = 0;
124 for (const RTCStats& stats : *a) {
125 EXPECT_EQ(stats.timestamp_us(), i);
126 ++i;
127 }
128 EXPECT_EQ(i, static_cast<int64_t>(6));
129 }
130
131 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/stats/rtcstatscollector_unittest.cc ('k') | webrtc/stats/stats.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698