1 #include "json_html_serializer.hpp" 2 3 #include <nlohmann/json.hpp> 4 5 #include <string> 6 7 #include <gtest/gtest.h> // IWYU pragma: keep 8 9 // IWYU pragma: no_include <gtest/gtest-message.h> 10 // IWYU pragma: no_include <gtest/gtest-test-part.h> 11 // IWYU pragma: no_include "gtest/gtest_pred_impl.h" 12 13 namespace json_html_util 14 { 15 namespace 16 { 17 18 const std::string boilerplateStart = 19 "<html>\n" 20 "<head>\n" 21 "<title>Redfish API</title>\n" 22 "<link href=\"/styles/redfish.css\" rel=\"stylesheet\">\n" 23 "</head>\n" 24 "<body>\n" 25 "<div class=\"container\">\n" 26 "<img src=\"/images/DMTF_Redfish_logo_2017.svg\" alt=\"redfish\" height=\"406px\" width=\"576px\">\n"; 27 28 const std::string boilerplateEnd = "</div>\n" 29 "</body>\n" 30 "</html>\n"; 31 32 TEST(JsonHtmlSerializer, dumpHtmlLink) 33 { 34 std::string out; 35 nlohmann::json j; 36 j["@odata.id"] = "/redfish/v1"; 37 dumpHtml(out, j); 38 EXPECT_EQ( 39 out, 40 boilerplateStart + 41 "<div class=\"content\">\n" 42 "{<div class=tab>"@odata.id": <a href=\"/redfish/v1\">\"/redfish/v1\"</a><br></div>}</div>\n" + 43 boilerplateEnd); 44 } 45 46 TEST(JsonHtmlSerializer, dumpint) 47 { 48 std::string out; 49 nlohmann::json j = 42; 50 dumpHtml(out, j); 51 EXPECT_EQ(out, boilerplateStart + "<div class=\"content\">\n42</div>\n" + 52 boilerplateEnd); 53 } 54 55 TEST(JsonHtmlSerializer, dumpstring) 56 { 57 std::string out; 58 nlohmann::json j = "foobar"; 59 dumpHtml(out, j); 60 EXPECT_EQ(out, boilerplateStart + 61 "<div class=\"content\">\n\"foobar\"</div>\n" + 62 boilerplateEnd); 63 } 64 } // namespace 65 } // namespace json_html_util 66