histogram_unittest.nc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. // This is a "No Compile Test" suite.
  5. // http://dev.chromium.org/developers/testing/no-compile-tests
  6. #include "base/metrics/histogram_functions.h"
  7. #include "base/metrics/histogram_macros.h"
  8. namespace base {
  9. #if defined(NCTEST_DIFFERENT_ENUM) // [r"\|sample\| and \|boundary\| shouldn't be of different enums"]
  10. void WontCompile() {
  11. enum TypeA { A };
  12. enum TypeB { B };
  13. UMA_HISTOGRAM_ENUMERATION("", A, B);
  14. }
  15. #elif defined(NCTEST_DIFFERENT_ENUM_CLASS) // [r"\|sample\| and \|boundary\| shouldn't be of different enums"]
  16. void WontCompile() {
  17. enum class TypeA { A };
  18. enum class TypeB { B };
  19. UMA_HISTOGRAM_ENUMERATION("", TypeA::A, TypeB::B);
  20. }
  21. #elif defined(NCTEST_DIFFERENT_ENUM_MIXED) // [r"\|sample\| and \|boundary\| shouldn't be of different enums"]
  22. void WontCompile() {
  23. enum class TypeA { A };
  24. enum TypeB { B };
  25. UMA_HISTOGRAM_ENUMERATION("", TypeA::A, B);
  26. }
  27. #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"]
  28. void WontCompile() {
  29. // Buckets for enumeration start from 0, so a boundary < 0 is illegal.
  30. enum class TypeA { A = -1 };
  31. UMA_HISTOGRAM_ENUMERATION("", TypeA::A, TypeA::A);
  32. }
  33. #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"]
  34. void WontCompile() {
  35. // HistogramBase::Sample is an int and can't hold larger values.
  36. enum class TypeA : uint32_t { A = 0xffffffff };
  37. UMA_HISTOGRAM_ENUMERATION("", TypeA::A, TypeA::A);
  38. }
  39. #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"]
  40. void WontCompile() {
  41. enum TypeA { A };
  42. UMA_HISTOGRAM_ENUMERATION("", 0, TypeA::A);
  43. }
  44. #elif defined(NCTEST_FUNCTION_ENUM_NO_MAXVALUE) // [r"no member named 'kMaxValue' in 'base::NoMaxValue'"]
  45. enum class NoMaxValue {
  46. kMoo,
  47. };
  48. void WontCompile() {
  49. UmaHistogramEnumeration("", NoMaxValue::kMoo);
  50. }
  51. #elif defined(NCTEST_FUNCTION_INT_AS_ENUM) // [r"static assertion failed due to requirement 'std::is_enum<int>::value'"]
  52. void WontCompile() {
  53. UmaHistogramEnumeration("", 1, 2);
  54. }
  55. #elif defined(NCTEST_FUNCTION_DIFFERENT_ENUM) // [r"no matching function for call to 'UmaHistogramEnumeration'"]
  56. void WontCompile() {
  57. enum TypeA { A };
  58. enum TypeB { B };
  59. UmaHistogramEnumeration("", A, B);
  60. }
  61. #elif defined(NCTEST_FUNCTION_FIRST_NOT_ENUM) // [r"no matching function for call to 'UmaHistogramEnumeration'"]
  62. void WontCompile() {
  63. enum TypeB { B };
  64. UmaHistogramEnumeration("", 1, B);
  65. }
  66. #elif defined(NCTEST_FUNCTION_SECOND_NOT_ENUM) // [r"no matching function for call to 'UmaHistogramEnumeration'"]
  67. void WontCompile() {
  68. enum TypeA { A };
  69. UmaHistogramEnumeration("", A, 2);
  70. }
  71. #endif
  72. } // namespace base