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 <memory> |
| 8 |
8 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
9 #include "base/metrics/histogram_samples.h" | 10 #include "base/metrics/histogram_samples.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 | 13 |
13 using ::testing::ElementsAre; | 14 using ::testing::ElementsAre; |
14 using ::testing::IsEmpty; | 15 using ::testing::IsEmpty; |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
(...skipping 15 matching lines...) Expand all Loading... |
33 | 34 |
34 HistogramTester tester; | 35 HistogramTester tester; |
35 | 36 |
36 // Verify that no histogram is recorded. | 37 // Verify that no histogram is recorded. |
37 tester.ExpectTotalCount(kHistogram1, 0); | 38 tester.ExpectTotalCount(kHistogram1, 0); |
38 | 39 |
39 // Record a histogram after the creation of the recorder. | 40 // Record a histogram after the creation of the recorder. |
40 UMA_HISTOGRAM_BOOLEAN(kHistogram1, true); | 41 UMA_HISTOGRAM_BOOLEAN(kHistogram1, true); |
41 | 42 |
42 // Verify that one histogram is recorded. | 43 // Verify that one histogram is recorded. |
43 scoped_ptr<HistogramSamples> samples( | 44 std::unique_ptr<HistogramSamples> samples( |
44 tester.GetHistogramSamplesSinceCreation(kHistogram1)); | 45 tester.GetHistogramSamplesSinceCreation(kHistogram1)); |
45 EXPECT_TRUE(samples); | 46 EXPECT_TRUE(samples); |
46 EXPECT_EQ(1, samples->TotalCount()); | 47 EXPECT_EQ(1, samples->TotalCount()); |
47 } | 48 } |
48 | 49 |
49 TEST_F(HistogramTesterTest, GetHistogramSamplesSinceCreationNotNull) { | 50 TEST_F(HistogramTesterTest, GetHistogramSamplesSinceCreationNotNull) { |
50 // Chose the histogram name uniquely, to ensure nothing was recorded for it so | 51 // Chose the histogram name uniquely, to ensure nothing was recorded for it so |
51 // far. | 52 // far. |
52 static const char kHistogram[] = | 53 static const char kHistogram[] = |
53 "GetHistogramSamplesSinceCreationNotNullHistogram"; | 54 "GetHistogramSamplesSinceCreationNotNullHistogram"; |
54 HistogramTester tester; | 55 HistogramTester tester; |
55 | 56 |
56 // Verify that the returned samples are empty but not null. | 57 // Verify that the returned samples are empty but not null. |
57 scoped_ptr<HistogramSamples> samples( | 58 std::unique_ptr<HistogramSamples> samples( |
58 tester.GetHistogramSamplesSinceCreation(kHistogram1)); | 59 tester.GetHistogramSamplesSinceCreation(kHistogram1)); |
59 EXPECT_TRUE(samples); | 60 EXPECT_TRUE(samples); |
60 tester.ExpectTotalCount(kHistogram, 0); | 61 tester.ExpectTotalCount(kHistogram, 0); |
61 } | 62 } |
62 | 63 |
63 TEST_F(HistogramTesterTest, TestUniqueSample) { | 64 TEST_F(HistogramTesterTest, TestUniqueSample) { |
64 HistogramTester tester; | 65 HistogramTester tester; |
65 | 66 |
66 // Record into a sample thrice | 67 // Record into a sample thrice |
67 UMA_HISTOGRAM_COUNTS_100(kHistogram2, 2); | 68 UMA_HISTOGRAM_COUNTS_100(kHistogram2, 2); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 EXPECT_THAT(tester.GetAllSamples(kHistogram5), | 111 EXPECT_THAT(tester.GetAllSamples(kHistogram5), |
111 ElementsAre(Bucket(2, 1), Bucket(3, 2), Bucket(5, 1))); | 112 ElementsAre(Bucket(2, 1), Bucket(3, 2), Bucket(5, 1))); |
112 } | 113 } |
113 | 114 |
114 TEST_F(HistogramTesterTest, TestGetAllSamples_NoSamples) { | 115 TEST_F(HistogramTesterTest, TestGetAllSamples_NoSamples) { |
115 HistogramTester tester; | 116 HistogramTester tester; |
116 EXPECT_THAT(tester.GetAllSamples(kHistogram5), IsEmpty()); | 117 EXPECT_THAT(tester.GetAllSamples(kHistogram5), IsEmpty()); |
117 } | 118 } |
118 | 119 |
119 } // namespace base | 120 } // namespace base |
OLD | NEW |