summaryrefslogtreecommitdiff
path: root/test/include/json_html_serializer.cpp
blob: b941a59a45e174f6ca717fbd27f57d04f57f5580 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "json_html_serializer.hpp"

#include <nlohmann/json.hpp>

#include <string>

#include <gtest/gtest.h> // IWYU pragma: keep

// IWYU pragma: no_include <gtest/gtest-message.h>
// IWYU pragma: no_include <gtest/gtest-test-part.h>
// IWYU pragma: no_include "gtest/gtest_pred_impl.h"

namespace json_html_util
{
namespace
{

const std::string boilerplateStart =
    "<html>\n"
    "<head>\n"
    "<title>Redfish API</title>\n"
    "<link href=\"/redfish.css\" rel=\"stylesheet\">\n"
    "</head>\n"
    "<body>\n"
    "<div class=\"container\">\n"
    "<img src=\"/DMTF_Redfish_logo_2017.svg\" alt=\"redfish\" height=\"406px\" width=\"576px\">\n";

const std::string boilerplateEnd = "</div>\n"
                                   "</body>\n"
                                   "</html>\n";

TEST(JsonHtmlSerializer, dumpHtmlLink)
{
    std::string out;
    nlohmann::json j;
    j["@odata.id"] = "/redfish/v1";
    dumpHtml(out, j);
    EXPECT_EQ(
        out,
        boilerplateStart +
            "<div class=\"content\">\n"
            "{<div class=tab>&quot@odata.id&quot: <a href=\"/redfish/v1\">\"/redfish/v1\"</a><br></div>}</div>\n" +
            boilerplateEnd);
}

TEST(JsonHtmlSerializer, dumpint)
{
    std::string out;
    nlohmann::json j = 42;
    dumpHtml(out, j);
    EXPECT_EQ(out, boilerplateStart + "<div class=\"content\">\n42</div>\n" +
                       boilerplateEnd);
}

TEST(JsonHtmlSerializer, dumpstring)
{
    std::string out;
    nlohmann::json j = "foobar";
    dumpHtml(out, j);
    EXPECT_EQ(out, boilerplateStart +
                       "<div class=\"content\">\n\"foobar\"</div>\n" +
                       boilerplateEnd);
}
} // namespace
} // namespace json_html_util