1 /**
2  * Copyright © 2019 IBM Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include "extensions/openpower-pels/additional_data.hpp"
17 
18 #include <gtest/gtest.h>
19 
20 using namespace openpower::pels;
21 
22 TEST(AdditionalDataTest, GetKeywords)
23 {
24     std::vector<std::string> data{"KEY1=VALUE1", "KEY2=VALUE2",
25                                   "KEY3=", "HELLOWORLD", "=VALUE5"};
26     AdditionalData ad{data};
27 
28     EXPECT_TRUE(ad.getValue("KEY1"));
29     EXPECT_EQ(*(ad.getValue("KEY1")), "VALUE1");
30 
31     EXPECT_TRUE(ad.getValue("KEY2"));
32     EXPECT_EQ(*(ad.getValue("KEY2")), "VALUE2");
33 
34     EXPECT_FALSE(ad.getValue("x"));
35 
36     auto value3 = ad.getValue("KEY3");
37     EXPECT_TRUE(value3);
38     EXPECT_TRUE((*value3).empty());
39 
40     EXPECT_FALSE(ad.getValue("HELLOWORLD"));
41     EXPECT_FALSE(ad.getValue("VALUE5"));
42 
43     auto json = ad.toJSON();
44     std::string expected = R"({"KEY1":"VALUE1","KEY2":"VALUE2","KEY3":""})";
45     EXPECT_EQ(json.dump(), expected);
46 
47     ad.remove("KEY1");
48     EXPECT_FALSE(ad.getValue("KEY1"));
49 }
50 
51 TEST(AdditionalDataTest, AddData)
52 {
53     AdditionalData ad;
54 
55     ad.add("KEY1", "VALUE1");
56     EXPECT_EQ(*(ad.getValue("KEY1")), "VALUE1");
57 
58     ad.add("KEY2", "VALUE2");
59     EXPECT_EQ(*(ad.getValue("KEY2")), "VALUE2");
60 
61     std::map<std::string, std::string> expected{{"KEY1", "VALUE1"},
62                                                 {"KEY2", "VALUE2"}};
63 
64     EXPECT_EQ(expected, ad.getData());
65 }
66