diff UnitTestsSources/FromDcmtkTests.cpp @ 2445:6e5bc5c6d1a4

Fix to allow creating DICOM instances with empty Specific Character Set (0008,0005)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 14 Dec 2017 13:02:06 +0100
parents 82d5e305fbd9
children 878b59270859
line wrap: on
line diff
--- a/UnitTestsSources/FromDcmtkTests.cpp	Fri Dec 08 10:21:24 2017 +0100
+++ b/UnitTestsSources/FromDcmtkTests.cpp	Thu Dec 14 13:02:06 2017 +0100
@@ -1250,3 +1250,56 @@
 {
   ASSERT_EQ(toUpperResult, Toolbox::ToUpperCaseWithAccents(toUpperSource));
 }
+
+
+
+TEST(ParsedDicomFile, InvalidCharacterSets)
+{
+  {
+    // No encoding provided, fallback to default encoding
+    DicomMap m;
+    m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false);
+
+    ParsedDicomFile d(m, Encoding_Latin3 /* default encoding */);
+    ASSERT_EQ(Encoding_Latin3, d.GetEncoding());
+  }
+  
+  {
+    // Valid encoding, "ISO_IR 13" is Japanese
+    DicomMap m;
+    m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "ISO_IR 13", false);
+    m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false);
+
+    ParsedDicomFile d(m, Encoding_Latin3 /* default encoding */);
+    ASSERT_EQ(Encoding_Japanese, d.GetEncoding());
+  }
+  
+  {
+    // Invalid value for an encoding ("nope" is not in the DICOM standard)
+    DicomMap m;
+    m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "nope", false);
+    m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false);
+
+    ASSERT_THROW(ParsedDicomFile d(m, Encoding_Latin3), OrthancException);
+  }
+  
+  {
+    // Invalid encoding, as provided as a binary string
+    DicomMap m;
+    m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "ISO_IR 13", true);
+    m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false);
+
+    ASSERT_THROW(ParsedDicomFile d(m, Encoding_Latin3), OrthancException);
+  }
+  
+  {
+    // Encoding provided as an empty string, fallback to default encoding
+    // In Orthanc <= 1.3.1, this test was throwing an exception
+    DicomMap m;
+    m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "", false);
+    m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false);
+
+    ParsedDicomFile d(m, Encoding_Latin3 /* default encoding */);
+    ASSERT_EQ(Encoding_Latin3, d.GetEncoding());
+  }
+}