Andrew de los Reyes | 785bc35 | 2010-05-26 12:34:53 -0700 | [diff] [blame] | 1 | // Copyright (c) 2010 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 <map> |
| 6 | #include <string> |
| 7 | #include <gtest/gtest.h> |
| 8 | #include "base/string_util.h" |
| 9 | #include "update_engine/simple_key_value_store.h" |
| 10 | |
| 11 | using std::map; |
| 12 | using std::string; |
| 13 | |
| 14 | namespace chromeos_update_engine { |
| 15 | |
| 16 | class SimpleKeyValueStoreTest : public ::testing::Test {}; |
| 17 | |
| 18 | TEST(SimpleKeyValueStoreTest, SimpleTest) { |
| 19 | string blob = "A=B\nC=\n=\nFOO=BAR=BAZ\nBAR=BAX\nMISSING=NEWLINE"; |
| 20 | map<string, string> parts = simple_key_value_store::ParseString(blob); |
| 21 | string combined = simple_key_value_store::AssembleString(parts); |
| 22 | map<string, string> combined_parts = |
| 23 | simple_key_value_store::ParseString(combined); |
| 24 | map<string, string>* maps[] = { &parts, &combined_parts }; |
| 25 | for (size_t i = 0; i < arraysize(maps); i++) { |
| 26 | map<string, string>* test_map = maps[i]; |
| 27 | EXPECT_EQ(6, test_map->size()) << "i = " << i; |
| 28 | EXPECT_EQ("B", (*test_map)["A"]) << "i = " << i; |
| 29 | EXPECT_EQ("", (*test_map)["C"]) << "i = " << i; |
| 30 | EXPECT_EQ("", (*test_map)[""]) << "i = " << i; |
| 31 | EXPECT_EQ("BAR=BAZ", (*test_map)["FOO"]) << "i = " << i; |
| 32 | EXPECT_EQ("BAX", (*test_map)["BAR"]) << "i = " << i; |
| 33 | EXPECT_EQ("NEWLINE", (*test_map)["MISSING"]) << "i = " << i; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | TEST(SimpleKeyValueStoreTest, EmptyTest) { |
| 38 | map<string, string> empty_map = simple_key_value_store::ParseString(""); |
| 39 | EXPECT_TRUE(empty_map.empty()); |
| 40 | string str = simple_key_value_store::AssembleString(empty_map); |
| 41 | if (!str.empty()) |
| 42 | EXPECT_EQ("\n", str); // Optionally may end in newline |
| 43 | } |
| 44 | |
| 45 | } // namespace chromeos_update_engine |