aboutsummaryrefslogtreecommitdiffstats
path: root/brillo/variant_dictionary_test.cc
blob: 73ead2c97d93c33c0103aad7c07cc2c27f8f62c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright 2015 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <string>

#include <brillo/any.h>
#include <brillo/variant_dictionary.h>
#include <gtest/gtest.h>

using brillo::VariantDictionary;
using brillo::GetVariantValueOrDefault;

TEST(VariantDictionary, GetVariantValueOrDefault) {
  VariantDictionary dictionary;
  dictionary.emplace("a", 1);
  dictionary.emplace("b", "string");

  // Test values that are present in the VariantDictionary.
  EXPECT_EQ(1, GetVariantValueOrDefault<int>(dictionary, "a"));
  EXPECT_EQ("string", GetVariantValueOrDefault<const char*>(dictionary, "b"));

  // Test that missing keys result in defaults.
  EXPECT_EQ("", GetVariantValueOrDefault<std::string>(dictionary, "missing"));
  EXPECT_EQ(0, GetVariantValueOrDefault<int>(dictionary, "missing"));
}