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 = 29 "</div>\n" 30 "</body>\n" 31 "</html>\n"; 32 33 TEST(JsonHtmlSerializer, dumpHtmlLink) 34 { 35 std::string out; 36 nlohmann::json j; 37 j["@odata.id"] = "/redfish/v1"; 38 dumpHtml(out, j); 39 EXPECT_EQ( 40 out, 41 boilerplateStart + 42 "<div class=\"content\">\n" 43 "{<div class=tab>"@odata.id": <a href=\"/redfish/v1\">\"/redfish/v1\"</a><br></div>}</div>\n" + 44 boilerplateEnd); 45 } 46 47 TEST(JsonHtmlSerializer, dumpint) 48 { 49 std::string out; 50 nlohmann::json j = 42; 51 dumpHtml(out, j); 52 EXPECT_EQ(out, boilerplateStart + "<div class=\"content\">\n42</div>\n" + 53 boilerplateEnd); 54 } 55 56 TEST(JsonHtmlSerializer, dumpstring) 57 { 58 std::string out; 59 nlohmann::json j = "foobar"; 60 dumpHtml(out, j); 61 EXPECT_EQ(out, 62 boilerplateStart + "<div class=\"content\">\n\"foobar\"</div>\n" + 63 boilerplateEnd); 64 } 65 } // namespace 66 } // namespace json_html_util 67