Home | History | Annotate | Download | only in brillo
      1 // Copyright 2015 The Chromium OS 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 
      5 #include <string>
      6 
      7 #include <brillo/any.h>
      8 #include <brillo/variant_dictionary.h>
      9 #include <gtest/gtest.h>
     10 
     11 using brillo::VariantDictionary;
     12 using brillo::GetVariantValueOrDefault;
     13 
     14 TEST(VariantDictionary, GetVariantValueOrDefault) {
     15   VariantDictionary dictionary;
     16   dictionary.emplace("a", 1);
     17   dictionary.emplace("b", "string");
     18 
     19   // Test values that are present in the VariantDictionary.
     20   EXPECT_EQ(1, GetVariantValueOrDefault<int>(dictionary, "a"));
     21   EXPECT_EQ("string", GetVariantValueOrDefault<const char*>(dictionary, "b"));
     22 
     23   // Test that missing keys result in defaults.
     24   EXPECT_EQ("", GetVariantValueOrDefault<std::string>(dictionary, "missing"));
     25   EXPECT_EQ(0, GetVariantValueOrDefault<int>(dictionary, "missing"));
     26 }
     27