Matt Spinler | 15ee6ae | 2019-07-08 16:50:06 -0500 | [diff] [blame] | 1 | #include "extensions/openpower-pels/additional_data.hpp" |
| 2 | |
| 3 | #include <gtest/gtest.h> |
| 4 | |
| 5 | using namespace openpower::pels; |
| 6 | |
| 7 | TEST(AdditionalDataTest, GetKeywords) |
| 8 | { |
| 9 | std::vector<std::string> data{"KEY1=VALUE1", "KEY2=VALUE2", |
| 10 | "KEY3=", "HELLOWORLD", "=VALUE5"}; |
| 11 | AdditionalData ad{data}; |
| 12 | |
| 13 | EXPECT_TRUE(ad.getValue("KEY1")); |
| 14 | EXPECT_EQ(*(ad.getValue("KEY1")), "VALUE1"); |
| 15 | |
| 16 | EXPECT_TRUE(ad.getValue("KEY2")); |
| 17 | EXPECT_EQ(*(ad.getValue("KEY2")), "VALUE2"); |
| 18 | |
| 19 | EXPECT_FALSE(ad.getValue("x")); |
| 20 | |
| 21 | auto value3 = ad.getValue("KEY3"); |
| 22 | EXPECT_TRUE(value3); |
| 23 | EXPECT_TRUE((*value3).empty()); |
| 24 | |
| 25 | EXPECT_FALSE(ad.getValue("HELLOWORLD")); |
| 26 | EXPECT_FALSE(ad.getValue("VALUE5")); |
Matt Spinler | afa857c | 2019-10-24 13:03:46 -0500 | [diff] [blame^] | 27 | |
| 28 | auto json = ad.toJSON(); |
| 29 | std::string expected = R"({"KEY1":"VALUE1","KEY2":"VALUE2","KEY3":""})"; |
| 30 | EXPECT_EQ(json.dump(), expected); |
| 31 | |
| 32 | ad.remove("KEY1"); |
| 33 | EXPECT_FALSE(ad.getValue("KEY1")); |
Matt Spinler | 15ee6ae | 2019-07-08 16:50:06 -0500 | [diff] [blame] | 34 | } |