OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/test/histogram_tester.h" | 5 #include "base/test/histogram_tester.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
9 #include "base/metrics/histogram_samples.h" | 9 #include "base/metrics/histogram_samples.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 namespace base { | 13 namespace base { |
13 | 14 |
| 15 using ::testing::ElementsAre; |
| 16 |
14 const std::string kHistogram1 = "Test1"; | 17 const std::string kHistogram1 = "Test1"; |
15 const std::string kHistogram2 = "Test2"; | 18 const std::string kHistogram2 = "Test2"; |
16 const std::string kHistogram3 = "Test3"; | 19 const std::string kHistogram3 = "Test3"; |
17 const std::string kHistogram4 = "Test4"; | 20 const std::string kHistogram4 = "Test4"; |
| 21 const std::string kHistogram5 = "Test5"; |
18 | 22 |
19 typedef testing::Test HistogramTesterTest; | 23 typedef testing::Test HistogramTesterTest; |
20 | 24 |
21 TEST_F(HistogramTesterTest, Scope) { | 25 TEST_F(HistogramTesterTest, Scope) { |
22 // Record a histogram before the creation of the recorder. | 26 // Record a histogram before the creation of the recorder. |
23 UMA_HISTOGRAM_BOOLEAN(kHistogram1, true); | 27 UMA_HISTOGRAM_BOOLEAN(kHistogram1, true); |
24 | 28 |
25 HistogramTester tester; | 29 HistogramTester tester; |
26 | 30 |
27 // Verify that no histogram is recorded. | 31 // Verify that no histogram is recorded. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 75 |
72 HistogramTester tester; | 76 HistogramTester tester; |
73 UMA_HISTOGRAM_COUNTS_100(kHistogram4, 3); | 77 UMA_HISTOGRAM_COUNTS_100(kHistogram4, 3); |
74 | 78 |
75 tester.ExpectBucketCount(kHistogram4, 2, 0); | 79 tester.ExpectBucketCount(kHistogram4, 2, 0); |
76 tester.ExpectBucketCount(kHistogram4, 3, 1); | 80 tester.ExpectBucketCount(kHistogram4, 3, 1); |
77 | 81 |
78 tester.ExpectTotalCount(kHistogram4, 1); | 82 tester.ExpectTotalCount(kHistogram4, 1); |
79 } | 83 } |
80 | 84 |
| 85 TEST_F(HistogramTesterTest, TestGetAllSamples) { |
| 86 HistogramTester tester; |
| 87 UMA_HISTOGRAM_ENUMERATION(kHistogram5, 2, 5); |
| 88 UMA_HISTOGRAM_ENUMERATION(kHistogram5, 3, 5); |
| 89 UMA_HISTOGRAM_ENUMERATION(kHistogram5, 3, 5); |
| 90 UMA_HISTOGRAM_ENUMERATION(kHistogram5, 5, 5); |
| 91 |
| 92 EXPECT_THAT(tester.GetAllSamples(kHistogram5), |
| 93 ElementsAre(Bucket(2, 1), Bucket(3, 2), Bucket(5, 1))); |
| 94 } |
| 95 |
81 } // namespace base | 96 } // namespace base |
OLD | NEW |