blob: 82e21b9f3c330fcb0d8f6f491ab9556708cd1c42 [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
Patrick Williamsbd79bce2024-08-16 15:22:20 -040028const std::string boilerplateEnd =
29 "</div>\n"
30 "</body>\n"
31 "</html>\n";
Ed Tanousbb8f3bb2023-05-18 14:05:17 -070032
Ed Tanous5a60c562023-05-18 13:52:34 -070033TEST(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,
Ed Tanousbb8f3bb2023-05-18 14:05:17 -070041 boilerplateStart +
42 "<div class=\"content\">\n"
43 "{<div class=tab>&quot@odata.id&quot: <a href=\"/redfish/v1\">\"/redfish/v1\"</a><br></div>}</div>\n" +
44 boilerplateEnd);
45}
46
47TEST(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
56TEST(JsonHtmlSerializer, dumpstring)
57{
58 std::string out;
59 nlohmann::json j = "foobar";
60 dumpHtml(out, j);
Patrick Williamsbd79bce2024-08-16 15:22:20 -040061 EXPECT_EQ(out,
62 boilerplateStart + "<div class=\"content\">\n\"foobar\"</div>\n" +
63 boilerplateEnd);
Ed Tanous5a60c562023-05-18 13:52:34 -070064}
65} // namespace
66} // namespace json_html_util