Write test capable of catching regressions
This is a pretty simple test, but should be able to catch the regression
injected in the previous commit.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I67de097059a6e0dd8d2c02c1aa6c69954a6d7be3
diff --git a/test/include/json_html_serializer.cpp b/test/include/json_html_serializer.cpp
index b8afc9b..b941a59 100644
--- a/test/include/json_html_serializer.cpp
+++ b/test/include/json_html_serializer.cpp
@@ -15,6 +15,20 @@
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;
@@ -23,19 +37,29 @@
dumpHtml(out, j);
EXPECT_EQ(
out,
- "<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"
- "<div class=\"content\">\n"
- "{<div class=tab>"@odata.id": <a href=\"/redfish/v1\">\"/redfish/v1\"</a><br></div>}</div>\n"
- "</div>\n"
- "</body>\n"
- "</html>\n");
+ boilerplateStart +
+ "<div class=\"content\">\n"
+ "{<div class=tab>"@odata.id": <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