1// Copyright 2016 The Chromium Authors 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"fatal error: static_assert failed due to requirement 'static_cast<uintmax_t>\(TypeA::A\) < static_cast<uintmax_t>\(std::numeric_limits<int>::max\(\)\)': |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"fatal error: static_assert failed due to requirement 'static_cast<uintmax_t>\(TypeA::A\) < static_cast<uintmax_t>\(std::numeric_limits<int>::max\(\)\)': |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"fatal error: static_assert failed due to requirement 'static_cast<uintmax_t>\(TypeA::A\) < static_cast<uintmax_t>\(std::numeric_limits<int>::max\(\)\)': |boundary| is out of range of HistogramBase::Sample"] 54 55void WontCompile() { 56 enum TypeA { A }; 57 UMA_HISTOGRAM_ENUMERATION("", 0, TypeA::A); 58} 59 60#elif defined(NCTEST_FUNCTION_ENUM_NO_MAXVALUE) // [r"no member named 'kMaxValue' in 'base::NoMaxValue'"] 61 62enum class NoMaxValue { 63 kMoo, 64}; 65 66void WontCompile() { 67 UmaHistogramEnumeration("", NoMaxValue::kMoo); 68} 69 70#elif defined(NCTEST_FUNCTION_INT_AS_ENUM) // [r"static assertion failed due to requirement 'std::is_enum<int>::value'"] 71 72void WontCompile() { 73 UmaHistogramEnumeration("", 1, 2); 74} 75 76#elif defined(NCTEST_FUNCTION_DIFFERENT_ENUM) // [r"no matching function for call to 'UmaHistogramEnumeration'"] 77 78void WontCompile() { 79 enum TypeA { A }; 80 enum TypeB { B }; 81 UmaHistogramEnumeration("", A, B); 82} 83 84#elif defined(NCTEST_FUNCTION_FIRST_NOT_ENUM) // [r"no matching function for call to 'UmaHistogramEnumeration'"] 85 86void WontCompile() { 87 enum TypeB { B }; 88 UmaHistogramEnumeration("", 1, B); 89} 90 91#elif defined(NCTEST_FUNCTION_SECOND_NOT_ENUM) // [r"no matching function for call to 'UmaHistogramEnumeration'"] 92 93void WontCompile() { 94 enum TypeA { A }; 95 UmaHistogramEnumeration("", A, 2); 96} 97 98#endif 99 100} // namespace base 101