• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3// found in the LICENSE file.
4
5// This is a "No Compile Test" suite.
6// http://dev.chromium.org/developers/testing/no-compile-tests
7
8#include "base/metrics/histogram_functions.h"
9#include "base/metrics/histogram_macros.h"
10
11namespace base {
12
13#if defined(NCTEST_DIFFERENT_ENUM)  // [r"\|sample\| and \|boundary\| shouldn't be of different enums"]
14
15void WontCompile() {
16  enum TypeA { A };
17  enum TypeB { B };
18  UMA_HISTOGRAM_ENUMERATION("", A, B);
19}
20
21#elif defined(NCTEST_DIFFERENT_ENUM_CLASS)  // [r"\|sample\| and \|boundary\| shouldn't be of different enums"]
22
23void WontCompile() {
24  enum class TypeA { A };
25  enum class TypeB { B };
26  UMA_HISTOGRAM_ENUMERATION("", TypeA::A, TypeB::B);
27}
28
29#elif defined(NCTEST_DIFFERENT_ENUM_MIXED)  // [r"\|sample\| and \|boundary\| shouldn't be of different enums"]
30
31void WontCompile() {
32  enum class TypeA { A };
33  enum TypeB { B };
34  UMA_HISTOGRAM_ENUMERATION("", TypeA::A, B);
35}
36
37#elif defined(NCTEST_NEGATIVE_ENUM_MAX)  // [r'static_assert failed "\|boundary\| is out of range of HistogramBase::Sample"']
38
39void WontCompile() {
40  // Buckets for enumeration start from 0, so a boundary < 0 is illegal.
41  enum class TypeA { A = -1 };
42  UMA_HISTOGRAM_ENUMERATION("", TypeA::A, TypeA::A);
43}
44
45#elif defined(NCTEST_ENUM_MAX_OUT_OF_RANGE)  // [r'static_assert failed "\|boundary\| is out of range of HistogramBase::Sample"']
46
47void WontCompile() {
48  // HistogramBase::Sample is an int and can't hold larger values.
49  enum class TypeA : uint32_t { A = 0xffffffff };
50  UMA_HISTOGRAM_ENUMERATION("", TypeA::A, TypeA::A);
51}
52
53#elif defined(NCTEST_SAMPLE_NOT_ENUM)  // [r'static_assert failed "Unexpected: \|boundary\| is enum, but \|sample\| is not."']
54
55void WontCompile() {
56  enum TypeA { A };
57  UMA_HISTOGRAM_ENUMERATION("", 0, TypeA::A);
58}
59
60#elif defined(NCTEST_FUNCTION_INT)  // [r"Non enum passed to UmaHistogramEnumeration"]
61
62void WontCompile() {
63  UmaHistogramEnumeration("", 1, 2);
64}
65
66#elif defined(NCTEST_FUNCTION_DIFFERENT_ENUM)  // [r"no matching function for call to 'UmaHistogramEnumeration'"]
67
68void WontCompile() {
69  enum TypeA { A };
70  enum TypeB { B };
71  UmaHistogramEnumeration("", A, B);
72}
73
74#elif defined(NCTEST_FUNCTION_FIRST_NOT_ENUM)  // [r"no matching function for call to 'UmaHistogramEnumeration'"]
75
76void WontCompile() {
77  enum TypeB { B };
78  UmaHistogramEnumeration("", 1, B);
79}
80
81#elif defined(NCTEST_FUNCTION_SECOND_NOT_ENUM)  // [r"no matching function for call to 'UmaHistogramEnumeration'"]
82
83void WontCompile() {
84  enum TypeA { A };
85  UmaHistogramEnumeration("", A, 2);
86}
87
88#endif
89
90}  // namespace base
91