diff options
| author | Matt Spinler <spinler@us.ibm.com> | 2020-01-22 15:44:35 -0600 | 
|---|---|---|
| committer | Matt Spinler <spinler@us.ibm.com> | 2020-02-13 14:57:59 +0000 | 
| commit | ce3f450b97b56fbf639cd4a271a3ba124b5d6406 (patch) | |
| tree | 4f95b12a904d5362b5201ee705ac4e5d58d871a3 /test | |
| parent | e2d1bf317c0ddf25ddd305aa8f3c6f09118f799c (diff) | |
| download | phosphor-logging-ce3f450b97b56fbf639cd4a271a3ba124b5d6406.tar.gz phosphor-logging-ce3f450b97b56fbf639cd4a271a3ba124b5d6406.zip  | |
PEL: Add Section::getJSON() implementer test
Test that the PEL section classes that provide a getJSON()
implementation return valid JSON.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I10dc6bbd0e1e4d63e6416928e9951ac6f85ba774
Diffstat (limited to 'test')
| -rw-r--r-- | test/openpower-pels/pel_test.cpp | 41 | 
1 files changed, 41 insertions, 0 deletions
diff --git a/test/openpower-pels/pel_test.cpp b/test/openpower-pels/pel_test.cpp index 32f8d5e..2cf58d7 100644 --- a/test/openpower-pels/pel_test.cpp +++ b/test/openpower-pels/pel_test.cpp @@ -344,3 +344,44 @@ TEST_F(PELTest, SysInfoSectionTest)      auto version = json["BMC Version ID"].get<std::string>();      EXPECT_EQ(version, "ABCD1234");  } + +// Test that the sections that override +//     virtual std::optional<std::string> Section::getJSON() const +// return valid JSON. +TEST_F(PELTest, SectionJSONTest) +{ +    auto data = pelDataFactory(TestPELType::pelSimple); +    PEL pel{data}; + +    // Check that all JSON returned from the sections is +    // parseable by nlohmann::json, which will throw an +    // exception and fail the test if there is a problem. + +    // The getJSON() response needs to be wrapped in a { } to make +    // actual valid JSON (PEL::toJSON() usually handles that). + +    auto jsonString = pel.privateHeader().getJSON(); + +    // PrivateHeader always prints JSON +    ASSERT_TRUE(jsonString); +    *jsonString = '{' + *jsonString + '}'; +    auto json = nlohmann::json::parse(*jsonString); + +    jsonString = pel.userHeader().getJSON(); + +    // UserHeader always prints JSON +    ASSERT_TRUE(jsonString); +    *jsonString = '{' + *jsonString + '}'; +    json = nlohmann::json::parse(*jsonString); + +    for (const auto& section : pel.optionalSections()) +    { +        // The optional sections may or may not have implemented getJSON(). +        jsonString = section->getJSON(); +        if (jsonString) +        { +            *jsonString = '{' + *jsonString + '}'; +            auto json = nlohmann::json::parse(*jsonString); +        } +    } +}  | 

