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

Side by Side Diff: base/test/histogram_tester_unittest.cc

Issue 1647803004: Move base to DEPS (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 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/test/histogram_tester.cc ('k') | base/test/icu_test_util.h » ('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 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/test/histogram_tester.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/metrics/histogram_macros.h"
9 #include "base/metrics/histogram_samples.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace base {
14
15 using ::testing::ElementsAre;
16
17 const std::string kHistogram1 = "Test1";
18 const std::string kHistogram2 = "Test2";
19 const std::string kHistogram3 = "Test3";
20 const std::string kHistogram4 = "Test4";
21 const std::string kHistogram5 = "Test5";
22
23 typedef testing::Test HistogramTesterTest;
24
25 TEST_F(HistogramTesterTest, Scope) {
26 // Record a histogram before the creation of the recorder.
27 UMA_HISTOGRAM_BOOLEAN(kHistogram1, true);
28
29 HistogramTester tester;
30
31 // Verify that no histogram is recorded.
32 scoped_ptr<HistogramSamples> samples(
33 tester.GetHistogramSamplesSinceCreation(kHistogram1));
34 EXPECT_FALSE(samples);
35
36 // Record a histogram after the creation of the recorder.
37 UMA_HISTOGRAM_BOOLEAN(kHistogram1, true);
38
39 // Verify that one histogram is recorded.
40 samples = tester.GetHistogramSamplesSinceCreation(kHistogram1);
41 EXPECT_TRUE(samples);
42 EXPECT_EQ(1, samples->TotalCount());
43 }
44
45 TEST_F(HistogramTesterTest, TestUniqueSample) {
46 HistogramTester tester;
47
48 // Record into a sample thrice
49 UMA_HISTOGRAM_COUNTS_100(kHistogram2, 2);
50 UMA_HISTOGRAM_COUNTS_100(kHistogram2, 2);
51 UMA_HISTOGRAM_COUNTS_100(kHistogram2, 2);
52
53 tester.ExpectUniqueSample(kHistogram2, 2, 3);
54 }
55
56 TEST_F(HistogramTesterTest, TestBucketsSample) {
57 HistogramTester tester;
58
59 // Record into a sample twice
60 UMA_HISTOGRAM_COUNTS_100(kHistogram3, 2);
61 UMA_HISTOGRAM_COUNTS_100(kHistogram3, 2);
62 UMA_HISTOGRAM_COUNTS_100(kHistogram3, 2);
63 UMA_HISTOGRAM_COUNTS_100(kHistogram3, 2);
64 UMA_HISTOGRAM_COUNTS_100(kHistogram3, 3);
65
66 tester.ExpectBucketCount(kHistogram3, 2, 4);
67 tester.ExpectBucketCount(kHistogram3, 3, 1);
68
69 tester.ExpectTotalCount(kHistogram3, 5);
70 }
71
72 TEST_F(HistogramTesterTest, TestBucketsSampleWithScope) {
73 // Record into a sample twice, once before the tester creation and once after.
74 UMA_HISTOGRAM_COUNTS_100(kHistogram4, 2);
75
76 HistogramTester tester;
77 UMA_HISTOGRAM_COUNTS_100(kHistogram4, 3);
78
79 tester.ExpectBucketCount(kHistogram4, 2, 0);
80 tester.ExpectBucketCount(kHistogram4, 3, 1);
81
82 tester.ExpectTotalCount(kHistogram4, 1);
83 }
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
96 } // namespace base
OLDNEW
« no previous file with comments | « base/test/histogram_tester.cc ('k') | base/test/icu_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698