xref: /aosp_15_r20/external/cronet/base/test/metrics/histogram_enum_reader_unittest.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2018 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 #include "base/test/metrics/histogram_enum_reader.h"
6 
7 #include <optional>
8 
9 #include "testing/gtest/include/gtest/gtest.h"
10 
11 namespace base {
12 
TEST(HistogramEnumReaderTest,SanityChecks)13 TEST(HistogramEnumReaderTest, SanityChecks) {
14   {
15     // NOTE: This results in a dependency on the enums.xml file, but to
16     // otherwise inject content would circumvent a lot of the logic of the
17     // method and add additional complexity. "Boolean" is hopefully a pretty
18     // stable enum.
19     std::optional<HistogramEnumEntryMap> results =
20         ReadEnumFromEnumsXml("Boolean");
21     ASSERT_TRUE(results);
22     EXPECT_EQ("False", results->at(0));
23     EXPECT_EQ("True", results->at(1));
24   }
25 
26   {
27     std::optional<HistogramEnumEntryMap> results =
28         ReadEnumFromEnumsXml("TheWorstNameForAnEnum");
29     ASSERT_FALSE(results);
30   }
31 }
32 
33 }  // namespace base
34