// Copyright (c) 2014 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 #include #include namespace brillo { class MapUtilsTest : public ::testing::Test { public: void SetUp() override { map_ = { {"key1", 1}, {"key2", 2}, {"key3", 3}, {"key4", 4}, {"key5", 5}, }; } void TearDown() override { map_.clear(); } std::map map_; }; TEST_F(MapUtilsTest, GetMapKeys) { std::set keys = GetMapKeys(map_); EXPECT_EQ((std::set{"key1", "key2", "key3", "key4", "key5"}), keys); } TEST_F(MapUtilsTest, GetMapKeysAsVector) { std::vector keys = GetMapKeysAsVector(map_); EXPECT_EQ((std::vector{"key1", "key2", "key3", "key4", "key5"}), keys); } TEST_F(MapUtilsTest, GetMapValues) { std::vector values = GetMapValues(map_); EXPECT_EQ((std::vector{1, 2, 3, 4, 5}), values); } TEST_F(MapUtilsTest, MapToVector) { std::vector> elements = MapToVector(map_); std::vector> expected{ {"key1", 1}, {"key2", 2}, {"key3", 3}, {"key4", 4}, {"key5", 5}, }; EXPECT_EQ(expected, elements); } TEST_F(MapUtilsTest, Empty) { std::map empty_map; EXPECT_TRUE(GetMapKeys(empty_map).empty()); EXPECT_TRUE(GetMapKeysAsVector(empty_map).empty()); EXPECT_TRUE(GetMapValues(empty_map).empty()); EXPECT_TRUE(MapToVector(empty_map).empty()); } } // namespace brillo