blob: 5aebb3a74c025796947636503ca41527ac0c6a32 [file] [log] [blame]
Ed Tanous5a60c562023-05-18 13:52:34 -07001#include "json_html_serializer.hpp"
2
3#include <nlohmann/json.hpp>
4
5#include <string>
6
Ed Tanous478b7ad2024-07-15 19:11:54 -07007#include <gtest/gtest.h>
Ed Tanous5a60c562023-05-18 13:52:34 -07008
9namespace json_html_util
10{
11namespace
12{
13
Ed Tanousbb8f3bb2023-05-18 14:05:17 -070014const std::string boilerplateStart =
15 "<html>\n"
16 "<head>\n"
17 "<title>Redfish API</title>\n"
Ed Tanousa529a6a2024-05-29 16:51:37 -070018 "<link href=\"/styles/redfish.css\" rel=\"stylesheet\">\n"
Ed Tanousbb8f3bb2023-05-18 14:05:17 -070019 "</head>\n"
20 "<body>\n"
21 "<div class=\"container\">\n"
Ed Tanousa529a6a2024-05-29 16:51:37 -070022 "<img src=\"/images/DMTF_Redfish_logo_2017.svg\" alt=\"redfish\" height=\"406px\" width=\"576px\">\n";
Ed Tanousbb8f3bb2023-05-18 14:05:17 -070023
Patrick Williamsbd79bce2024-08-16 15:22:20 -040024const std::string boilerplateEnd =
25 "</div>\n"
26 "</body>\n"
27 "</html>\n";
Ed Tanousbb8f3bb2023-05-18 14:05:17 -070028
Ed Tanous5a60c562023-05-18 13:52:34 -070029TEST(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,
Ed Tanousbb8f3bb2023-05-18 14:05:17 -070037 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
43TEST(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
52TEST(JsonHtmlSerializer, dumpstring)
53{
54 std::string out;
55 nlohmann::json j = "foobar";
56 dumpHtml(out, j);
Patrick Williamsbd79bce2024-08-16 15:22:20 -040057 EXPECT_EQ(out,
58 boilerplateStart + "<div class=\"content\">\n\"foobar\"</div>\n" +
59 boilerplateEnd);
Ed Tanous5a60c562023-05-18 13:52:34 -070060}
61} // namespace
62} // namespace json_html_util