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

Side by Side Diff: base/metrics/histogram_base_unittest.cc

Issue 2973863002: Remove std::string histogram name from HistogramBase object.
Patch Set: rebased Created 3 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 | « base/metrics/histogram_base.cc ('k') | base/metrics/histogram_snapshot_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/metrics/histogram_base.h" 8 #include "base/metrics/histogram_base.h"
9 #include "base/metrics/sparse_histogram.h" 9 #include "base/metrics/sparse_histogram.h"
10 #include "base/metrics/statistics_recorder.h" 10 #include "base/metrics/statistics_recorder.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 PickleIterator iter(pickle); 55 PickleIterator iter(pickle);
56 HistogramBase* deserialized = DeserializeHistogramInfo(&iter); 56 HistogramBase* deserialized = DeserializeHistogramInfo(&iter);
57 EXPECT_EQ(histogram, deserialized); 57 EXPECT_EQ(histogram, deserialized);
58 58
59 ResetStatisticsRecorder(); 59 ResetStatisticsRecorder();
60 60
61 PickleIterator iter2(pickle); 61 PickleIterator iter2(pickle);
62 deserialized = DeserializeHistogramInfo(&iter2); 62 deserialized = DeserializeHistogramInfo(&iter2);
63 EXPECT_TRUE(deserialized); 63 EXPECT_TRUE(deserialized);
64 EXPECT_NE(histogram, deserialized); 64 EXPECT_NE(histogram, deserialized);
65 EXPECT_EQ("TestHistogram", deserialized->histogram_name()); 65 EXPECT_EQ("TestHistogram", StringPiece(deserialized->histogram_name()));
66 EXPECT_TRUE(deserialized->HasConstructionArguments(1, 1000, 10)); 66 EXPECT_TRUE(deserialized->HasConstructionArguments(1, 1000, 10));
67 67
68 // kIPCSerializationSourceFlag will be cleared. 68 // kIPCSerializationSourceFlag will be cleared.
69 EXPECT_EQ(HistogramBase::kUmaTargetedHistogramFlag, deserialized->flags()); 69 EXPECT_EQ(HistogramBase::kUmaTargetedHistogramFlag, deserialized->flags());
70 } 70 }
71 71
72 TEST_F(HistogramBaseTest, DeserializeLinearHistogram) { 72 TEST_F(HistogramBaseTest, DeserializeLinearHistogram) {
73 HistogramBase* histogram = LinearHistogram::FactoryGet( 73 HistogramBase* histogram = LinearHistogram::FactoryGet(
74 "TestHistogram", 1, 1000, 10, 74 "TestHistogram", 1, 1000, 10,
75 HistogramBase::kIPCSerializationSourceFlag); 75 HistogramBase::kIPCSerializationSourceFlag);
76 76
77 Pickle pickle; 77 Pickle pickle;
78 ASSERT_TRUE(histogram->SerializeInfo(&pickle)); 78 ASSERT_TRUE(histogram->SerializeInfo(&pickle));
79 79
80 PickleIterator iter(pickle); 80 PickleIterator iter(pickle);
81 HistogramBase* deserialized = DeserializeHistogramInfo(&iter); 81 HistogramBase* deserialized = DeserializeHistogramInfo(&iter);
82 EXPECT_EQ(histogram, deserialized); 82 EXPECT_EQ(histogram, deserialized);
83 83
84 ResetStatisticsRecorder(); 84 ResetStatisticsRecorder();
85 85
86 PickleIterator iter2(pickle); 86 PickleIterator iter2(pickle);
87 deserialized = DeserializeHistogramInfo(&iter2); 87 deserialized = DeserializeHistogramInfo(&iter2);
88 EXPECT_TRUE(deserialized); 88 EXPECT_TRUE(deserialized);
89 EXPECT_NE(histogram, deserialized); 89 EXPECT_NE(histogram, deserialized);
90 EXPECT_EQ("TestHistogram", deserialized->histogram_name()); 90 EXPECT_EQ("TestHistogram", StringPiece(deserialized->histogram_name()));
91 EXPECT_TRUE(deserialized->HasConstructionArguments(1, 1000, 10)); 91 EXPECT_TRUE(deserialized->HasConstructionArguments(1, 1000, 10));
92 EXPECT_EQ(0, deserialized->flags()); 92 EXPECT_EQ(0, deserialized->flags());
93 } 93 }
94 94
95 TEST_F(HistogramBaseTest, DeserializeBooleanHistogram) { 95 TEST_F(HistogramBaseTest, DeserializeBooleanHistogram) {
96 HistogramBase* histogram = BooleanHistogram::FactoryGet( 96 HistogramBase* histogram = BooleanHistogram::FactoryGet(
97 "TestHistogram", HistogramBase::kIPCSerializationSourceFlag); 97 "TestHistogram", HistogramBase::kIPCSerializationSourceFlag);
98 98
99 Pickle pickle; 99 Pickle pickle;
100 ASSERT_TRUE(histogram->SerializeInfo(&pickle)); 100 ASSERT_TRUE(histogram->SerializeInfo(&pickle));
101 101
102 PickleIterator iter(pickle); 102 PickleIterator iter(pickle);
103 HistogramBase* deserialized = DeserializeHistogramInfo(&iter); 103 HistogramBase* deserialized = DeserializeHistogramInfo(&iter);
104 EXPECT_EQ(histogram, deserialized); 104 EXPECT_EQ(histogram, deserialized);
105 105
106 ResetStatisticsRecorder(); 106 ResetStatisticsRecorder();
107 107
108 PickleIterator iter2(pickle); 108 PickleIterator iter2(pickle);
109 deserialized = DeserializeHistogramInfo(&iter2); 109 deserialized = DeserializeHistogramInfo(&iter2);
110 EXPECT_TRUE(deserialized); 110 EXPECT_TRUE(deserialized);
111 EXPECT_NE(histogram, deserialized); 111 EXPECT_NE(histogram, deserialized);
112 EXPECT_EQ("TestHistogram", deserialized->histogram_name()); 112 EXPECT_EQ("TestHistogram", StringPiece(deserialized->histogram_name()));
113 EXPECT_TRUE(deserialized->HasConstructionArguments(1, 2, 3)); 113 EXPECT_TRUE(deserialized->HasConstructionArguments(1, 2, 3));
114 EXPECT_EQ(0, deserialized->flags()); 114 EXPECT_EQ(0, deserialized->flags());
115 } 115 }
116 116
117 TEST_F(HistogramBaseTest, DeserializeCustomHistogram) { 117 TEST_F(HistogramBaseTest, DeserializeCustomHistogram) {
118 std::vector<HistogramBase::Sample> ranges; 118 std::vector<HistogramBase::Sample> ranges;
119 ranges.push_back(13); 119 ranges.push_back(13);
120 ranges.push_back(5); 120 ranges.push_back(5);
121 ranges.push_back(9); 121 ranges.push_back(9);
122 122
123 HistogramBase* histogram = CustomHistogram::FactoryGet( 123 HistogramBase* histogram = CustomHistogram::FactoryGet(
124 "TestHistogram", ranges, HistogramBase::kIPCSerializationSourceFlag); 124 "TestHistogram", ranges, HistogramBase::kIPCSerializationSourceFlag);
125 125
126 Pickle pickle; 126 Pickle pickle;
127 ASSERT_TRUE(histogram->SerializeInfo(&pickle)); 127 ASSERT_TRUE(histogram->SerializeInfo(&pickle));
128 128
129 PickleIterator iter(pickle); 129 PickleIterator iter(pickle);
130 HistogramBase* deserialized = DeserializeHistogramInfo(&iter); 130 HistogramBase* deserialized = DeserializeHistogramInfo(&iter);
131 EXPECT_EQ(histogram, deserialized); 131 EXPECT_EQ(histogram, deserialized);
132 132
133 ResetStatisticsRecorder(); 133 ResetStatisticsRecorder();
134 134
135 PickleIterator iter2(pickle); 135 PickleIterator iter2(pickle);
136 deserialized = DeserializeHistogramInfo(&iter2); 136 deserialized = DeserializeHistogramInfo(&iter2);
137 EXPECT_TRUE(deserialized); 137 EXPECT_TRUE(deserialized);
138 EXPECT_NE(histogram, deserialized); 138 EXPECT_NE(histogram, deserialized);
139 EXPECT_EQ("TestHistogram", deserialized->histogram_name()); 139 EXPECT_EQ("TestHistogram", StringPiece(deserialized->histogram_name()));
140 EXPECT_TRUE(deserialized->HasConstructionArguments(5, 13, 4)); 140 EXPECT_TRUE(deserialized->HasConstructionArguments(5, 13, 4));
141 EXPECT_EQ(0, deserialized->flags()); 141 EXPECT_EQ(0, deserialized->flags());
142 } 142 }
143 143
144 TEST_F(HistogramBaseTest, DeserializeSparseHistogram) { 144 TEST_F(HistogramBaseTest, DeserializeSparseHistogram) {
145 HistogramBase* histogram = SparseHistogram::FactoryGet( 145 HistogramBase* histogram = SparseHistogram::FactoryGet(
146 "TestHistogram", HistogramBase::kIPCSerializationSourceFlag); 146 "TestHistogram", HistogramBase::kIPCSerializationSourceFlag);
147 147
148 Pickle pickle; 148 Pickle pickle;
149 ASSERT_TRUE(histogram->SerializeInfo(&pickle)); 149 ASSERT_TRUE(histogram->SerializeInfo(&pickle));
150 150
151 PickleIterator iter(pickle); 151 PickleIterator iter(pickle);
152 HistogramBase* deserialized = DeserializeHistogramInfo(&iter); 152 HistogramBase* deserialized = DeserializeHistogramInfo(&iter);
153 EXPECT_EQ(histogram, deserialized); 153 EXPECT_EQ(histogram, deserialized);
154 154
155 ResetStatisticsRecorder(); 155 ResetStatisticsRecorder();
156 156
157 PickleIterator iter2(pickle); 157 PickleIterator iter2(pickle);
158 deserialized = DeserializeHistogramInfo(&iter2); 158 deserialized = DeserializeHistogramInfo(&iter2);
159 EXPECT_TRUE(deserialized); 159 EXPECT_TRUE(deserialized);
160 EXPECT_NE(histogram, deserialized); 160 EXPECT_NE(histogram, deserialized);
161 EXPECT_EQ("TestHistogram", deserialized->histogram_name()); 161 EXPECT_EQ("TestHistogram", StringPiece(deserialized->histogram_name()));
162 EXPECT_EQ(0, deserialized->flags()); 162 EXPECT_EQ(0, deserialized->flags());
163 } 163 }
164 164
165 TEST_F(HistogramBaseTest, CreationReportHistogram) { 165 TEST_F(HistogramBaseTest, CreationReportHistogram) {
166 // Enabled creation report. Itself is not included in the report. 166 // Enabled creation report. Itself is not included in the report.
167 HistogramBase* report = GetCreationReportHistogram("CreationReportTest"); 167 HistogramBase* report = GetCreationReportHistogram("CreationReportTest");
168 ASSERT_TRUE(report); 168 ASSERT_TRUE(report);
169 169
170 std::vector<HistogramBase::Sample> ranges; 170 std::vector<HistogramBase::Sample> ranges;
171 ranges.push_back(1); 171 ranges.push_back(1);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 BooleanHistogram::FactoryGet("CRH-Boolean", 0); 213 BooleanHistogram::FactoryGet("CRH-Boolean", 0);
214 CustomHistogram::FactoryGet("CRH-Custom", ranges, 0); 214 CustomHistogram::FactoryGet("CRH-Custom", ranges, 0);
215 SparseHistogram::FactoryGet("CRH-Sparse", 0); 215 SparseHistogram::FactoryGet("CRH-Sparse", 0);
216 samples = report->SnapshotSamples(); 216 samples = report->SnapshotSamples();
217 EXPECT_EQ(1, samples->GetCount(HISTOGRAM_REPORT_CREATED)); 217 EXPECT_EQ(1, samples->GetCount(HISTOGRAM_REPORT_CREATED));
218 EXPECT_EQ(9, samples->GetCount(HISTOGRAM_REPORT_HISTOGRAM_CREATED)); 218 EXPECT_EQ(9, samples->GetCount(HISTOGRAM_REPORT_HISTOGRAM_CREATED));
219 EXPECT_EQ(5, samples->GetCount(HISTOGRAM_REPORT_HISTOGRAM_LOOKUP)); 219 EXPECT_EQ(5, samples->GetCount(HISTOGRAM_REPORT_HISTOGRAM_LOOKUP));
220 } 220 }
221 221
222 } // namespace base 222 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/histogram_base.cc ('k') | base/metrics/histogram_snapshot_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698