changeset 1691:e447f3cb8b30

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 08 Oct 2015 10:53:14 +0200
parents ae09132e4237
children 4eaf164dd574
files OrthancServer/FromDcmtkBridge.cpp UnitTestsSources/FromDcmtkTests.cpp
diffstat 2 files changed, 19 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/FromDcmtkBridge.cpp	Wed Oct 07 17:42:42 2015 +0200
+++ b/OrthancServer/FromDcmtkBridge.cpp	Thu Oct 08 10:53:14 2015 +0200
@@ -701,7 +701,12 @@
                                unsigned int maxStringLength,
                                Encoding encoding)
   {
-    parent = Json::objectValue;
+    if (parent.type() == Json::nullValue)
+    {
+      parent = Json::objectValue;
+    }
+
+    assert(parent.type() == Json::objectValue);
     Json::Value& target = PrepareNode(parent, element, format);
 
     if (element.isLeaf())
--- a/UnitTestsSources/FromDcmtkTests.cpp	Wed Oct 07 17:42:42 2015 +0200
+++ b/UnitTestsSources/FromDcmtkTests.cpp	Thu Oct 08 10:53:14 2015 +0200
@@ -343,8 +343,6 @@
     ASSERT_EQ("Hello", b["0010,0010"].asString());
   }
 
-  printf("ici\n");
-
   {
     Json::Value a = Json::arrayValue;
 
@@ -352,6 +350,7 @@
       Json::Value b = Json::objectValue;
       b["PatientName"] = "Hello";
       b["PatientID"] = "World";
+      b["StudyDescription"] = "Toto";
       a.append(b);
     }
 
@@ -363,15 +362,22 @@
     }
 
     element.reset(FromDcmtkBridge::FromJson(a, REFERENCED_STUDY_SEQUENCE, false));
-    element->writeXML(std::cout);
 
     {
       Json::Value b;
-      FromDcmtkBridge::ToJson(b, *element, DicomToJsonFormat_Full, 0, Encoding_Ascii);
-      /*ASSERT_EQ(Json::arrayValue, b["0008,1110"].type());
-        ASSERT_EQ(2, b["0008,1110"].size());*/
+      FromDcmtkBridge::ToJson(b, *element, DicomToJsonFormat_Short, 0, Encoding_Ascii);
+      ASSERT_EQ(Json::arrayValue, b["0008,1110"].type());
+      ASSERT_EQ(2, b["0008,1110"].size());
+      
+      Json::Value::ArrayIndex i = (b["0008,1110"][0]["0010,0010"].asString() == "Hello") ? 0 : 1;
 
-      std::cout << b;
+      ASSERT_EQ(3, b["0008,1110"][i].size());
+      ASSERT_EQ(2, b["0008,1110"][1 - i].size());
+      ASSERT_EQ(b["0008,1110"][i]["0010,0010"].asString(), "Hello");
+      ASSERT_EQ(b["0008,1110"][i]["0010,0020"].asString(), "World");
+      ASSERT_EQ(b["0008,1110"][i]["0008,1030"].asString(), "Toto");
+      ASSERT_EQ(b["0008,1110"][1 - i]["0010,0010"].asString(), "Hello2");
+      ASSERT_EQ(b["0008,1110"][1 - i]["0010,0020"].asString(), "World2");
     }
   }