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

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

Issue 2886933003: Use stricter type checking in UMA_HISTOGRAM_ENUMERATION (Closed)
Patch Set: simplify type checking Created 3 years, 5 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/debug/activity_tracker.cc ('k') | base/metrics/histogram_macros_internal.h » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/metrics/histogram_functions.h" 5 #include "base/metrics/histogram_functions.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "base/test/histogram_tester.h" 8 #include "base/test/histogram_tester.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 29 matching lines...) Expand all
40 TEST(HistogramFunctionsTest, HistogramEnumeration) { 40 TEST(HistogramFunctionsTest, HistogramEnumeration) {
41 std::string histogram("Testing.UMA.HistogramEnumeration"); 41 std::string histogram("Testing.UMA.HistogramEnumeration");
42 HistogramTester tester; 42 HistogramTester tester;
43 UmaHistogramEnumeration(histogram, UMA_HISTOGRAM_TESTING_ENUM_FIRST, 43 UmaHistogramEnumeration(histogram, UMA_HISTOGRAM_TESTING_ENUM_FIRST,
44 UMA_HISTOGRAM_TESTING_ENUM_THIRD); 44 UMA_HISTOGRAM_TESTING_ENUM_THIRD);
45 tester.ExpectUniqueSample(histogram, UMA_HISTOGRAM_TESTING_ENUM_FIRST, 1); 45 tester.ExpectUniqueSample(histogram, UMA_HISTOGRAM_TESTING_ENUM_FIRST, 1);
46 46
47 // Verify the overflow & underflow bucket exists. 47 // Verify the overflow & underflow bucket exists.
48 UMA_HISTOGRAM_ENUMERATION( 48 UMA_HISTOGRAM_ENUMERATION(
49 histogram, static_cast<int>(UMA_HISTOGRAM_TESTING_ENUM_THIRD) + 10, 49 histogram, static_cast<int>(UMA_HISTOGRAM_TESTING_ENUM_THIRD) + 10,
50 UMA_HISTOGRAM_TESTING_ENUM_THIRD); 50 static_cast<int>(UMA_HISTOGRAM_TESTING_ENUM_THIRD));
51 tester.ExpectBucketCount( 51 tester.ExpectBucketCount(
52 histogram, static_cast<int>(UMA_HISTOGRAM_TESTING_ENUM_THIRD) + 1, 1); 52 histogram, static_cast<int>(UMA_HISTOGRAM_TESTING_ENUM_THIRD) + 1, 1);
53 tester.ExpectTotalCount(histogram, 2); 53 tester.ExpectTotalCount(histogram, 2);
54 } 54 }
55 55
56 TEST(HistogramFunctionsTest, HistogramBoolean) { 56 TEST(HistogramFunctionsTest, HistogramBoolean) {
57 std::string histogram("Testing.UMA.HistogramBoolean"); 57 std::string histogram("Testing.UMA.HistogramBoolean");
58 HistogramTester tester; 58 HistogramTester tester;
59 UmaHistogramBoolean(histogram, true); 59 UmaHistogramBoolean(histogram, true);
60 tester.ExpectUniqueSample(histogram, 1, 1); 60 tester.ExpectUniqueSample(histogram, 1, 1);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 tester.ExpectTotalCount(histogram, 2); 100 tester.ExpectTotalCount(histogram, 2);
101 UmaHistogramTimes(histogram, TimeDelta::FromSeconds(10)); // Overflows 101 UmaHistogramTimes(histogram, TimeDelta::FromSeconds(10)); // Overflows
102 tester.ExpectTimeBucketCount(histogram, TimeDelta::FromSeconds(10), 1); 102 tester.ExpectTimeBucketCount(histogram, TimeDelta::FromSeconds(10), 1);
103 UmaHistogramTimes(histogram, TimeDelta::FromSeconds(20)); // Overflows. 103 UmaHistogramTimes(histogram, TimeDelta::FromSeconds(20)); // Overflows.
104 // Check the value by picking any overflow time. 104 // Check the value by picking any overflow time.
105 tester.ExpectTimeBucketCount(histogram, TimeDelta::FromSeconds(11), 2); 105 tester.ExpectTimeBucketCount(histogram, TimeDelta::FromSeconds(11), 2);
106 tester.ExpectTotalCount(histogram, 4); 106 tester.ExpectTotalCount(histogram, 4);
107 } 107 }
108 108
109 } // namespace base. 109 } // namespace base.
OLDNEW
« no previous file with comments | « base/debug/activity_tracker.cc ('k') | base/metrics/histogram_macros_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698