PEL: Add class to wrap AdditionalData
The AdditionalData property on the xyz.openbmc_project.Logging.Entry
interface is a vector of strings of the form: "KEY=VALUE". The
PEL processing code will be interested in those keys and values, and
this class adds a way to get at those values based on a key without
having to do string parsing each time. It returns an
std::optional<std::string> value, and if the key isn't found, then the
std::optional value will be empty.
For Example:
AdditionalData ad{additionalDataPropertyValue};
// Get the value for the FOO key
std::optional<std::string> val = ad.getValue("FOO");
if (val)
std::cout << (*val).size();
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I6ba458840278784b1cc6a0ed88a7fece8794df7d
diff --git a/test/openpower-pels/additional_data_test.cpp b/test/openpower-pels/additional_data_test.cpp
new file mode 100644
index 0000000..2be06c4
--- /dev/null
+++ b/test/openpower-pels/additional_data_test.cpp
@@ -0,0 +1,27 @@
+#include "extensions/openpower-pels/additional_data.hpp"
+
+#include <gtest/gtest.h>
+
+using namespace openpower::pels;
+
+TEST(AdditionalDataTest, GetKeywords)
+{
+ std::vector<std::string> data{"KEY1=VALUE1", "KEY2=VALUE2",
+ "KEY3=", "HELLOWORLD", "=VALUE5"};
+ AdditionalData ad{data};
+
+ EXPECT_TRUE(ad.getValue("KEY1"));
+ EXPECT_EQ(*(ad.getValue("KEY1")), "VALUE1");
+
+ EXPECT_TRUE(ad.getValue("KEY2"));
+ EXPECT_EQ(*(ad.getValue("KEY2")), "VALUE2");
+
+ EXPECT_FALSE(ad.getValue("x"));
+
+ auto value3 = ad.getValue("KEY3");
+ EXPECT_TRUE(value3);
+ EXPECT_TRUE((*value3).empty());
+
+ EXPECT_FALSE(ad.getValue("HELLOWORLD"));
+ EXPECT_FALSE(ad.getValue("VALUE5"));
+}