1*1a96fba6SXin Li // Copyright 2015 The Chromium OS Authors. All rights reserved.
2*1a96fba6SXin Li // Use of this source code is governed by a BSD-style license that can be
3*1a96fba6SXin Li // found in the LICENSE file.
4*1a96fba6SXin Li
5*1a96fba6SXin Li #include <string>
6*1a96fba6SXin Li
7*1a96fba6SXin Li #include <brillo/any.h>
8*1a96fba6SXin Li #include <brillo/variant_dictionary.h>
9*1a96fba6SXin Li #include <gtest/gtest.h>
10*1a96fba6SXin Li
11*1a96fba6SXin Li using brillo::VariantDictionary;
12*1a96fba6SXin Li using brillo::GetVariantValueOrDefault;
13*1a96fba6SXin Li
TEST(VariantDictionary,GetVariantValueOrDefault)14*1a96fba6SXin Li TEST(VariantDictionary, GetVariantValueOrDefault) {
15*1a96fba6SXin Li VariantDictionary dictionary;
16*1a96fba6SXin Li dictionary.emplace("a", 1);
17*1a96fba6SXin Li dictionary.emplace("b", "string");
18*1a96fba6SXin Li
19*1a96fba6SXin Li // Test values that are present in the VariantDictionary.
20*1a96fba6SXin Li EXPECT_EQ(1, GetVariantValueOrDefault<int>(dictionary, "a"));
21*1a96fba6SXin Li EXPECT_EQ("string", GetVariantValueOrDefault<const char*>(dictionary, "b"));
22*1a96fba6SXin Li
23*1a96fba6SXin Li // Test that missing keys result in defaults.
24*1a96fba6SXin Li EXPECT_EQ("", GetVariantValueOrDefault<std::string>(dictionary, "missing"));
25*1a96fba6SXin Li EXPECT_EQ(0, GetVariantValueOrDefault<int>(dictionary, "missing"));
26*1a96fba6SXin Li }
27