xref: /aosp_15_r20/external/cronet/base/metrics/histogram_nocompile.nc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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
13void NotEnums() {
14  // Sample and boundary values must both be enums.
15  enum EnumA { A };
16  enum EnumB { B };
17
18  UmaHistogramEnumeration("", A, 2);  // expected-error {{no matching function for call to 'UmaHistogramEnumeration'}}
19  UmaHistogramEnumeration("", 1, B);  // expected-error {{no matching function for call to 'UmaHistogramEnumeration'}}
20  UmaHistogramEnumeration("", 1, 2);  // expected-error@*:* {{static assertion failed due to requirement 'std::is_enum_v<int>'}}
21}
22
23void DifferentEnums() {
24  // Sample and boundary values must not come from different enums.
25  enum EnumA { A };
26  enum EnumB { B };
27  enum class EnumC { C };
28  enum class EnumD { D };
29
30  UMA_HISTOGRAM_ENUMERATION("", A, B);                // expected-error {{|sample| and |boundary| shouldn't be of different enums}}
31  UMA_HISTOGRAM_ENUMERATION("", A, EnumD::D);         // expected-error {{|sample| and |boundary| shouldn't be of different enums}}
32  UMA_HISTOGRAM_ENUMERATION("", EnumC::C, B);         // expected-error {{|sample| and |boundary| shouldn't be of different enums}}
33  UMA_HISTOGRAM_ENUMERATION("", EnumC::C, EnumD::D);  // expected-error {{|sample| and |boundary| shouldn't be of different enums}}
34
35  UmaHistogramEnumeration("", A, B);  // expected-error {{no matching function for call to 'UmaHistogramEnumeration'}}
36}
37
38void MaxOutOfRange() {
39  // Boundaries must be nonnegative and fit in an int.
40  enum class TypeA { A = -1 };
41  enum class TypeB : uint32_t { B = 0xffffffff };
42
43  UMA_HISTOGRAM_ENUMERATION("", TypeA::A, TypeA::A);  // expected-error {{|boundary| is out of range of HistogramBase::Sample}}
44  UMA_HISTOGRAM_ENUMERATION("", TypeB::B, TypeB::B);  // expected-error {{|boundary| is out of range of HistogramBase::Sample}}
45}
46
47void NoMaxValue() {
48  // When boundary is omitted, sample enum must define `kMaxValue`.
49  enum class NoMax { kVal };
50
51  UmaHistogramEnumeration("", NoMax::kVal);  // expected-error@*:* {{no member named 'kMaxValue' in 'NoMax'}}
52}
53
54}  // namespace base
55