histogram_enum_reader_unittest.cc 1005 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2018 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. #include "base/test/metrics/histogram_enum_reader.h"
  5. #include "testing/gtest/include/gtest/gtest.h"
  6. #include "third_party/abseil-cpp/absl/types/optional.h"
  7. namespace base {
  8. TEST(HistogramEnumReaderTest, SanityChecks) {
  9. {
  10. // NOTE: This results in a dependency on the enums.xml file, but to
  11. // otherwise inject content would circumvent a lot of the logic of the
  12. // method and add additional complexity. "Boolean" is hopefully a pretty
  13. // stable enum.
  14. absl::optional<HistogramEnumEntryMap> results =
  15. ReadEnumFromEnumsXml("Boolean");
  16. ASSERT_TRUE(results);
  17. EXPECT_EQ("False", results->at(0));
  18. EXPECT_EQ("True", results->at(1));
  19. }
  20. {
  21. absl::optional<HistogramEnumEntryMap> results =
  22. ReadEnumFromEnumsXml("TheWorstNameForAnEnum");
  23. ASSERT_FALSE(results);
  24. }
  25. }
  26. } // namespace base