blob: 9bbff28b132a6d0c5e45c7bafeb12f89faf4e5b8 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Ed Tanous5a60c562023-05-18 13:52:34 -07003#include "json_html_serializer.hpp"
4
5#include <nlohmann/json.hpp>
6
7#include <string>
8
Ed Tanous478b7ad2024-07-15 19:11:54 -07009#include <gtest/gtest.h>
Ed Tanous5a60c562023-05-18 13:52:34 -070010
11namespace json_html_util
12{
13namespace
14{
15
Ed Tanousbb8f3bb2023-05-18 14:05:17 -070016const std::string boilerplateStart =
17 "<html>\n"
18 "<head>\n"
19 "<title>Redfish API</title>\n"
Ed Tanousa529a6a2024-05-29 16:51:37 -070020 "<link href=\"/styles/redfish.css\" rel=\"stylesheet\">\n"
Ed Tanousbb8f3bb2023-05-18 14:05:17 -070021 "</head>\n"
22 "<body>\n"
23 "<div class=\"container\">\n"
Ed Tanousa529a6a2024-05-29 16:51:37 -070024 "<img src=\"/images/DMTF_Redfish_logo_2017.svg\" alt=\"redfish\" height=\"406px\" width=\"576px\">\n";
Ed Tanousbb8f3bb2023-05-18 14:05:17 -070025
Patrick Williamsbd79bce2024-08-16 15:22:20 -040026const std::string boilerplateEnd =
27 "</div>\n"
28 "</body>\n"
29 "</html>\n";
Ed Tanousbb8f3bb2023-05-18 14:05:17 -070030
Ed Tanous5a60c562023-05-18 13:52:34 -070031TEST(JsonHtmlSerializer, dumpHtmlLink)
32{
33 std::string out;
34 nlohmann::json j;
35 j["@odata.id"] = "/redfish/v1";
36 dumpHtml(out, j);
37 EXPECT_EQ(
38 out,
Ed Tanousbb8f3bb2023-05-18 14:05:17 -070039 boilerplateStart +
40 "<div class=\"content\">\n"
41 "{<div class=tab>&quot@odata.id&quot: <a href=\"/redfish/v1\">\"/redfish/v1\"</a><br></div>}</div>\n" +
42 boilerplateEnd);
43}
44
45TEST(JsonHtmlSerializer, dumpint)
46{
47 std::string out;
48 nlohmann::json j = 42;
49 dumpHtml(out, j);
50 EXPECT_EQ(out, boilerplateStart + "<div class=\"content\">\n42</div>\n" +
51 boilerplateEnd);
52}
53
54TEST(JsonHtmlSerializer, dumpstring)
55{
56 std::string out;
57 nlohmann::json j = "foobar";
58 dumpHtml(out, j);
Patrick Williamsbd79bce2024-08-16 15:22:20 -040059 EXPECT_EQ(out,
60 boilerplateStart + "<div class=\"content\">\n\"foobar\"</div>\n" +
61 boilerplateEnd);
Ed Tanous5a60c562023-05-18 13:52:34 -070062}
63} // namespace
64} // namespace json_html_util