diff OrthancFramework/UnitTestsSources/ToolboxTests.cpp @ 4393:e8e95b80194f

removing usage of deprecated JsonCpp classes
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 21 Dec 2020 18:55:32 +0100
parents bf7b9edf6b81
children f7104e9d044c
line wrap: on
line diff
--- a/OrthancFramework/UnitTestsSources/ToolboxTests.cpp	Mon Dec 21 18:09:47 2020 +0100
+++ b/OrthancFramework/UnitTestsSources/ToolboxTests.cpp	Mon Dec 21 18:55:32 2020 +0100
@@ -34,6 +34,36 @@
 
 using namespace Orthanc;
 
+TEST(Toolbox, Json)
+{
+  Json::Value a = Json::objectValue;
+  a["hello"] = "world";
+
+  std::string b = "{\"hello\"    :   \"world\"}";
+
+  Json::Value c;
+  ASSERT_TRUE(Toolbox::ReadJson(c, b));
+
+  std::string d, e;
+  Toolbox::WriteJson(d, a, true);
+  Toolbox::WriteJson(e, c, true);
+  ASSERT_EQ(d, e);
+
+  std::string f, g;
+  Toolbox::WriteJson(f, a, false);
+  Toolbox::WriteJson(g, c, false);
+  ASSERT_EQ(f, g);
+
+  /**
+   * Check compatibility with the serialized string generated by
+   * JsonCpp 1.7.4 (Ubuntu 18.04). "StripSpaces()" removes the
+   * trailing end-of-line character that was not present in the
+   * deprecated serialization classes of JsonCpp.
+   **/
+  ASSERT_EQ(Toolbox::StripSpaces(d), "{\"hello\":\"world\"}");
+  ASSERT_EQ(Toolbox::StripSpaces(f), "{\n   \"hello\" : \"world\"\n}");
+}
+
 TEST(Toolbox, Base64_allByteValues)
 {
   std::string toEncode;