blob: 69ac51ae838acc15a8dc23050fc5b04dbb2276ce [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
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
13namespace json_html_util
14{
15namespace
16{
17
Ed Tanousbb8f3bb2023-05-18 14:05:17 -070018const std::string boilerplateStart =
19 "<html>\n"
20 "<head>\n"
21 "<title>Redfish API</title>\n"
Ed Tanousa529a6a2024-05-29 16:51:37 -070022 "<link href=\"/styles/redfish.css\" rel=\"stylesheet\">\n"
Ed Tanousbb8f3bb2023-05-18 14:05:17 -070023 "</head>\n"
24 "<body>\n"
25 "<div class=\"container\">\n"
Ed Tanousa529a6a2024-05-29 16:51:37 -070026 "<img src=\"/images/DMTF_Redfish_logo_2017.svg\" alt=\"redfish\" height=\"406px\" width=\"576px\">\n";
Ed Tanousbb8f3bb2023-05-18 14:05:17 -070027
28const std::string boilerplateEnd = "</div>\n"
29 "</body>\n"
30 "</html>\n";
31
Ed Tanous5a60c562023-05-18 13:52:34 -070032TEST(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,
Ed Tanousbb8f3bb2023-05-18 14:05:17 -070040 boilerplateStart +
41 "<div class=\"content\">\n"
42 "{<div class=tab>&quot@odata.id&quot: <a href=\"/redfish/v1\">\"/redfish/v1\"</a><br></div>}</div>\n" +
43 boilerplateEnd);
44}
45
46TEST(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
55TEST(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);
Ed Tanous5a60c562023-05-18 13:52:34 -070063}
64} // namespace
65} // namespace json_html_util