changeset 1091:a66224eec125

encoding tests
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 05 Aug 2014 12:28:55 +0200
parents e494ceb8d763
children 88fcf73fbe39
files OrthancServer/ParsedDicomFile.cpp Resources/EncodingTests.h Resources/EncodingTests.py UnitTestsSources/FromDcmtkTests.cpp
diffstat 4 files changed, 61 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/ParsedDicomFile.cpp	Tue Aug 05 12:04:23 2014 +0200
+++ b/OrthancServer/ParsedDicomFile.cpp	Tue Aug 05 12:28:55 2014 +0200
@@ -1265,11 +1265,13 @@
         s = "ISO_IR 138";
         break;
 
-        /*
-          case Encoding_Japanese:
-          s = "ISO_IR 13";
-          break;
-        */
+      case Encoding_Japanese:
+        s = "ISO_IR 13";
+        break;
+
+      case Encoding_Chinese:
+        s = "GB18030";
+        break;
 
       case Encoding_Thai:
         s = "ISO_IR 166";
@@ -1279,7 +1281,7 @@
         throw OrthancException(ErrorCode_ParameterOutOfRange);
     }
 
-    Replace(DICOM_TAG_SPECIFIC_CHARACTER_SET, "", DicomReplaceMode_InsertIfAbsent);
+    Replace(DICOM_TAG_SPECIFIC_CHARACTER_SET, s, DicomReplaceMode_InsertIfAbsent);
   }
 
 }
--- a/Resources/EncodingTests.h	Tue Aug 05 12:04:23 2014 +0200
+++ b/Resources/EncodingTests.h	Tue Aug 05 12:28:55 2014 +0200
@@ -16,34 +16,34 @@
   ::Orthanc::Encoding_Chinese
 };
 static const char *testEncodingsEncoded[14] = {
-  "\xe9\xe4\xf6\xf2\xdd",
-  "\xe3",
-  "\xc8",
-  "\xd5",
-  "\xb4\xfb",
-  "\xe9\xe4\xf6\xf3",
-  "\xe9\xe4\xf6\xf2\xf8\xa9",
-  "\xe9\xe4\xf6",
-  "\xe9\xe4\xf6\xf2",
-  "\xc3\xa9\xc3\xa4\xc3\xb6\xc3\xb2\xd0\x94\xce\x98\xc4\x9d\xd7\x93\xd8\xb5\xc4\xb7\xd1\x9b\xe0\xb9\x9b\xef\xbe\x88\xc4\xb0",
-  "\xfb",
-  "\x84\x44\x83\xa6\xc8",
-  "",
+  "\x54\x65\x73\x74\xe9\xe4\xf6\xf2\xdd",
+  "\x54\x65\x73\x74\xe3",
+  "\x54\x65\x73\x74\xc8",
+  "\x54\x65\x73\x74\xd5",
+  "\x54\x65\x73\x74\xb4\xfb",
+  "\x54\x65\x73\x74\xe9\xe4\xf6\xf3",
+  "\x54\x65\x73\x74\xe9\xe4\xf6\xf2\xf8\xa9",
+  "\x54\x65\x73\x74\xe9\xe4\xf6",
+  "\x54\x65\x73\x74\xe9\xe4\xf6\xf2",
+  "\x54\x65\x73\x74\xc3\xa9\xc3\xa4\xc3\xb6\xc3\xb2\xd0\x94\xce\x98\xc4\x9d\xd7\x93\xd8\xb5\xc4\xb7\xd1\x9b\xe0\xb9\x9b\xef\xbe\x88\xc4\xb0",
+  "\x54\x65\x73\x74\xfb",
+  "\x54\x65\x73\x74\x84\x44\x83\xa6\xc8",
+  "\x54\x65\x73\x74",
   "\x81\x30\x89\x37\x81\x30\x89\x38\xA8\xA4\xA8\xA2\x81\x30\x89\x39\x81\x30\x8A\x30"
 };
 static const char *testEncodingsExpected[14] = {
-  "\xc3\xa9\xc3\xa4\xc3\xb6\xc3\xb2\xc4\xb0",
-  "\xd7\x93",
-  "\xce\x98",
-  "\xd8\xb5",
-  "\xd0\x94\xd1\x9b",
-  "\xc3\xa9\xc3\xa4\xc3\xb6\xc4\xb7",
-  "\xc3\xa9\xc3\xa4\xc3\xb6\xc3\xb2\xc4\x9d\xc4\xb0",
-  "\xc3\xa9\xc3\xa4\xc3\xb6",
-  "\xc3\xa9\xc3\xa4\xc3\xb6\xc3\xb2",
-  "\xc3\xa9\xc3\xa4\xc3\xb6\xc3\xb2\xd0\x94\xce\x98\xc4\x9d\xd7\x93\xd8\xb5\xc4\xb7\xd1\x9b\xe0\xb9\x9b\xef\xbe\x88\xc4\xb0",
-  "\xe0\xb9\x9b",
-  "\xd0\x94\xce\x98\xef\xbe\x88",
-  "",
+  "\x54\x65\x73\x74\xc3\xa9\xc3\xa4\xc3\xb6\xc3\xb2\xc4\xb0",
+  "\x54\x65\x73\x74\xd7\x93",
+  "\x54\x65\x73\x74\xce\x98",
+  "\x54\x65\x73\x74\xd8\xb5",
+  "\x54\x65\x73\x74\xd0\x94\xd1\x9b",
+  "\x54\x65\x73\x74\xc3\xa9\xc3\xa4\xc3\xb6\xc4\xb7",
+  "\x54\x65\x73\x74\xc3\xa9\xc3\xa4\xc3\xb6\xc3\xb2\xc4\x9d\xc4\xb0",
+  "\x54\x65\x73\x74\xc3\xa9\xc3\xa4\xc3\xb6",
+  "\x54\x65\x73\x74\xc3\xa9\xc3\xa4\xc3\xb6\xc3\xb2",
+  "\x54\x65\x73\x74\xc3\xa9\xc3\xa4\xc3\xb6\xc3\xb2\xd0\x94\xce\x98\xc4\x9d\xd7\x93\xd8\xb5\xc4\xb7\xd1\x9b\xe0\xb9\x9b\xef\xbe\x88\xc4\xb0",
+  "\x54\x65\x73\x74\xe0\xb9\x9b",
+  "\x54\x65\x73\x74\xd0\x94\xce\x98\xef\xbe\x88",
+  "\x54\x65\x73\x74",
   "\xc3\x9e\xc3\x9f\xc3\xa0\xc3\xa1\xc3\xa2\xc3\xa3"
 };
--- a/Resources/EncodingTests.py	Tue Aug 05 12:04:23 2014 +0200
+++ b/Resources/EncodingTests.py	Tue Aug 05 12:28:55 2014 +0200
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 
-source = u'éäöòДΘĝדصķћ๛ネİ'
+source = u'TestéäöòДΘĝדصķћ๛ネİ'
 
 encodings = {
     'UTF-8' : 'Utf8',
@@ -17,7 +17,7 @@
     'ISO-8859-8' : 'Hebrew',
     'TIS-620' : 'Thai',
     'SHIFT-JIS' : 'Japanese',
-    #'GB18030' : 'Chinese',
+    #'GB18030' : 'Chinese',  # Done manually below (*)
 }
 
 #from encodings.aliases import aliases
@@ -44,7 +44,7 @@
     expected.append(ToArray(s.decode(encoding).encode('utf-8')))
 
 
-# https://en.wikipedia.org/wiki/GB_18030#Technical_details
+# https://en.wikipedia.org/wiki/GB_18030#Technical_details  (*)
 l.append('::Orthanc::Encoding_Chinese')
 expected.append(ToArray('Þßàáâã'))
 encoded.append('"\\x81\\x30\\x89\\x37\\x81\\x30\\x89\\x38\\xA8\\xA4\\xA8\\xA2\\x81\\x30\\x89\\x39\\x81\\x30\\x8A\\x30"')
--- a/UnitTestsSources/FromDcmtkTests.cpp	Tue Aug 05 12:04:23 2014 +0200
+++ b/UnitTestsSources/FromDcmtkTests.cpp	Tue Aug 05 12:28:55 2014 +0200
@@ -237,17 +237,33 @@
 }
 
 
-TEST(FromDcmtkBridge, DISABLED_Encodings3)
+TEST(FromDcmtkBridge, Encodings3)
 {
   for (unsigned int i = 0; i < testEncodingsCount; i++)
   {
-    ParsedDicomFile f;
-    f.SetEncoding(testEncodings[i]);
+    std::cout << EnumerationToString(testEncodings[i]) << std::endl;
+    std::string dicom;
+
+    {
+      ParsedDicomFile f;
+      f.SetEncoding(testEncodings[i]);
+      f.Insert(DICOM_TAG_PATIENT_NAME, testEncodingsEncoded[i]);
+      f.SaveToMemoryBuffer(dicom);
+    }
 
-    std::string source(testEncodingsEncoded[i]);
-    std::string expected(testEncodingsExpected[i]);
-    std::string s = Toolbox::ConvertToUtf8(source, testEncodings[i]);
-    std::cout << EnumerationToString(testEncodings[i]) << std::endl;
-    EXPECT_EQ(expected, s);
+    {
+      ParsedDicomFile g(dicom);
+
+      if (testEncodings[i] != Encoding_Ascii)
+      {
+        ASSERT_EQ(testEncodings[i], g.GetEncoding());
+      }
+
+      std::string tag;
+      ASSERT_TRUE(g.GetTagValue(tag, DICOM_TAG_PATIENT_NAME));
+
+      std::string expected();
+      ASSERT_EQ(std::string(testEncodingsExpected[i]), tag);
+    }
   }
 }