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