diff UnitTestsSources/FromDcmtkTests.cpp @ 1736:b953c6eef28d

ToJson: IncludePrivateTags and IncludeUnknownTags
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 21 Oct 2015 16:52:23 +0200
parents a001f6226c7c
children df331354cea2
line wrap: on
line diff
--- a/UnitTestsSources/FromDcmtkTests.cpp	Wed Oct 21 16:25:09 2015 +0200
+++ b/UnitTestsSources/FromDcmtkTests.cpp	Wed Oct 21 16:52:23 2015 +0200
@@ -523,20 +523,51 @@
 
 TEST(ParsedDicomFile, ToJsonFlags)
 {
+  FromDcmtkBridge::RegisterDictionaryTag(DicomTag(0x7053, 0x1000), EVR_PN, "MyPrivateTag", 1, 1);
+  FromDcmtkBridge::RegisterDictionaryTag(DicomTag(0x7050, 0x1000), EVR_PN, "Declared public tag", 1, 1);
+
   {
     ParsedDicomFile f;
-    f.Insert(DicomTag(0x7053, 0x1000), "Some private tag", false);
+    f.Insert(DicomTag(0x7050, 0x1000), "Some public tag", false);  // Even group => public tag
+    f.Insert(DicomTag(0x7052, 0x1000), "Some unknown tag", false);  // Even group => public, unknown tag
+    f.Insert(DicomTag(0x7053, 0x1000), "Some private tag", false);  // Odd group => private tag
 
     Json::Value v;
     f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_None, 0);
     ASSERT_EQ(Json::objectValue, v.type());
-    ASSERT_EQ(5, v.getMemberNames().size());
-    ASSERT_FALSE(v.isMember("7053-1000"));
+    ASSERT_EQ(6, v.getMemberNames().size());
+    ASSERT_FALSE(v.isMember("7052,1000"));
+    ASSERT_FALSE(v.isMember("7053,1000"));
+    ASSERT_TRUE(v.isMember("7050,1000"));
+    ASSERT_EQ(Json::stringValue, v["7050,1000"].type());
+    ASSERT_EQ("Some public tag", v["7050,1000"].asString());
 
     f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_IncludePrivateTags, 0);
     ASSERT_EQ(Json::objectValue, v.type());
-    ASSERT_EQ(6, v.getMemberNames().size());
+    ASSERT_EQ(7, v.getMemberNames().size());
+    ASSERT_FALSE(v.isMember("7052,1000"));
+    ASSERT_TRUE(v.isMember("7050,1000"));
     ASSERT_TRUE(v.isMember("7053,1000"));
-    ASSERT_EQ(Json::nullValue, v["7053,1000"].type());
+    ASSERT_EQ("Some public tag", v["7050,1000"].asString());
+    ASSERT_EQ(Json::nullValue, v["7053,1000"].type());  // TODO SHOULD BE STRING
+
+    f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_IncludeUnknownTags, 0);
+    ASSERT_EQ(Json::objectValue, v.type());
+    ASSERT_EQ(7, v.getMemberNames().size());
+    ASSERT_TRUE(v.isMember("7050,1000"));
+    ASSERT_TRUE(v.isMember("7052,1000"));
+    ASSERT_FALSE(v.isMember("7053,1000"));
+    ASSERT_EQ("Some public tag", v["7050,1000"].asString());
+    ASSERT_EQ(Json::nullValue, v["7052,1000"].type());  // TODO SHOULD BE STRING
+
+    f.ToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludeUnknownTags | DicomToJsonFlags_IncludePrivateTags), 0);
+    ASSERT_EQ(Json::objectValue, v.type());
+    ASSERT_EQ(8, v.getMemberNames().size());
+    ASSERT_TRUE(v.isMember("7050,1000"));
+    ASSERT_TRUE(v.isMember("7052,1000"));
+    ASSERT_TRUE(v.isMember("7053,1000"));
+    ASSERT_EQ("Some public tag", v["7050,1000"].asString());
+    ASSERT_EQ(Json::nullValue, v["7052,1000"].type());  // TODO SHOULD BE STRING
+    ASSERT_EQ(Json::nullValue, v["7053,1000"].type());  // TODO SHOULD BE STRING
   }
 }