comparison UnitTestsSources/FromDcmtkTests.cpp @ 3276:9b0e67161600

More tolerance wrt. invalid DICOM files that must be returned by Orthanc C-FIND SCP
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 21 Feb 2019 10:21:12 +0100
parents 77e8378f0323
children 8711cd9b47c5
comparison
equal deleted inserted replaced
3275:5cd4c672d63c 3276:9b0e67161600
1124 CheckEncoding(dicom, Encoding_Ascii); 1124 CheckEncoding(dicom, Encoding_Ascii);
1125 } 1125 }
1126 1126
1127 { 1127 {
1128 DicomMap m; 1128 DicomMap m;
1129 ParsedDicomFile dicom(m, Encoding_Latin4); 1129 ParsedDicomFile dicom(m, Encoding_Latin4, false);
1130 ASSERT_EQ(1u, dicom.GetDcmtkObject().getDataset()->card()); 1130 ASSERT_EQ(1u, dicom.GetDcmtkObject().getDataset()->card());
1131 CheckEncoding(dicom, Encoding_Latin4); 1131 CheckEncoding(dicom, Encoding_Latin4);
1132 } 1132 }
1133 1133
1134 { 1134 {
1140 } 1140 }
1141 1141
1142 { 1142 {
1143 DicomMap m; 1143 DicomMap m;
1144 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "ISO_IR 148", false); 1144 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "ISO_IR 148", false);
1145 ParsedDicomFile dicom(m, Encoding_Latin1); 1145 ParsedDicomFile dicom(m, Encoding_Latin1, false);
1146 ASSERT_EQ(1u, dicom.GetDcmtkObject().getDataset()->card()); 1146 ASSERT_EQ(1u, dicom.GetDcmtkObject().getDataset()->card());
1147 CheckEncoding(dicom, Encoding_Latin5); 1147 CheckEncoding(dicom, Encoding_Latin5);
1148 } 1148 }
1149 } 1149 }
1150 1150
1190 1190
1191 { 1191 {
1192 DicomMap m; 1192 DicomMap m;
1193 m.SetValue(DICOM_TAG_PATIENT_NAME, testEncodingsExpected[i], false); 1193 m.SetValue(DICOM_TAG_PATIENT_NAME, testEncodingsExpected[i], false);
1194 1194
1195 ParsedDicomFile dicom(m, testEncodings[i]); 1195 ParsedDicomFile dicom(m, testEncodings[i], false);
1196 1196
1197 const char* encoded = NULL; 1197 const char* encoded = NULL;
1198 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->findAndGetString(DCM_PatientName, encoded).good()); 1198 ASSERT_TRUE(dicom.GetDcmtkObject().getDataset()->findAndGetString(DCM_PatientName, encoded).good());
1199 ASSERT_STREQ(testEncodingsEncoded[i], encoded); 1199 ASSERT_STREQ(testEncodingsEncoded[i], encoded);
1200 1200
1210 { 1210 {
1211 DicomMap m; 1211 DicomMap m;
1212 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, GetDicomSpecificCharacterSet(testEncodings[i]), false); 1212 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, GetDicomSpecificCharacterSet(testEncodings[i]), false);
1213 m.SetValue(DICOM_TAG_PATIENT_NAME, testEncodingsExpected[i], false); 1213 m.SetValue(DICOM_TAG_PATIENT_NAME, testEncodingsExpected[i], false);
1214 1214
1215 ParsedDicomFile dicom(m, testEncodings[i]); 1215 ParsedDicomFile dicom(m, testEncodings[i], false);
1216 1216
1217 Json::Value v2; 1217 Json::Value v2;
1218 dicom.DatasetToJson(v2, DicomToJsonFormat_Human, DicomToJsonFlags_Default, 0); 1218 dicom.DatasetToJson(v2, DicomToJsonFormat_Human, DicomToJsonFlags_Default, 0);
1219 1219
1220 ASSERT_EQ(v2["PatientName"].asString(), v["PatientName"].asString()); 1220 ASSERT_EQ(v2["PatientName"].asString(), v["PatientName"].asString());
1235 DicomMap m; 1235 DicomMap m;
1236 m.SetValue(DICOM_TAG_PATIENT_NAME, testEncodingsExpected[i], false); 1236 m.SetValue(DICOM_TAG_PATIENT_NAME, testEncodingsExpected[i], false);
1237 1237
1238 std::string tag; 1238 std::string tag;
1239 1239
1240 ParsedDicomFile dicom(m, Encoding_Utf8); 1240 ParsedDicomFile dicom(m, Encoding_Utf8, false);
1241 bool hasCodeExtensions; 1241 bool hasCodeExtensions;
1242 ASSERT_EQ(Encoding_Utf8, dicom.DetectEncoding(hasCodeExtensions)); 1242 ASSERT_EQ(Encoding_Utf8, dicom.DetectEncoding(hasCodeExtensions));
1243 ASSERT_FALSE(hasCodeExtensions); 1243 ASSERT_FALSE(hasCodeExtensions);
1244 ASSERT_TRUE(dicom.GetTagValue(tag, DICOM_TAG_PATIENT_NAME)); 1244 ASSERT_TRUE(dicom.GetTagValue(tag, DICOM_TAG_PATIENT_NAME));
1245 ASSERT_EQ(tag, testEncodingsExpected[i]); 1245 ASSERT_EQ(tag, testEncodingsExpected[i]);
1286 { 1286 {
1287 // No encoding provided, fallback to default encoding 1287 // No encoding provided, fallback to default encoding
1288 DicomMap m; 1288 DicomMap m;
1289 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false); 1289 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false);
1290 1290
1291 ParsedDicomFile d(m, Encoding_Latin3 /* default encoding */); 1291 ParsedDicomFile d(m, Encoding_Latin3 /* default encoding */, false);
1292 1292
1293 bool hasCodeExtensions; 1293 bool hasCodeExtensions;
1294 ASSERT_EQ(Encoding_Latin3, d.DetectEncoding(hasCodeExtensions)); 1294 ASSERT_EQ(Encoding_Latin3, d.DetectEncoding(hasCodeExtensions));
1295 ASSERT_FALSE(hasCodeExtensions); 1295 ASSERT_FALSE(hasCodeExtensions);
1296 } 1296 }
1299 // Valid encoding, "ISO_IR 13" is Japanese 1299 // Valid encoding, "ISO_IR 13" is Japanese
1300 DicomMap m; 1300 DicomMap m;
1301 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "ISO_IR 13", false); 1301 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "ISO_IR 13", false);
1302 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false); 1302 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false);
1303 1303
1304 ParsedDicomFile d(m, Encoding_Latin3 /* default encoding */); 1304 ParsedDicomFile d(m, Encoding_Latin3 /* default encoding */, false);
1305 1305
1306 bool hasCodeExtensions; 1306 bool hasCodeExtensions;
1307 ASSERT_EQ(Encoding_Japanese, d.DetectEncoding(hasCodeExtensions)); 1307 ASSERT_EQ(Encoding_Japanese, d.DetectEncoding(hasCodeExtensions));
1308 ASSERT_FALSE(hasCodeExtensions); 1308 ASSERT_FALSE(hasCodeExtensions);
1309 } 1309 }
1312 // Invalid value for an encoding ("nope" is not in the DICOM standard) 1312 // Invalid value for an encoding ("nope" is not in the DICOM standard)
1313 DicomMap m; 1313 DicomMap m;
1314 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "nope", false); 1314 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "nope", false);
1315 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false); 1315 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false);
1316 1316
1317 ASSERT_THROW(ParsedDicomFile d(m, Encoding_Latin3), OrthancException); 1317 ASSERT_THROW(ParsedDicomFile d(m, Encoding_Latin3, false), OrthancException);
1318 } 1318 }
1319 1319
1320 { 1320 {
1321 // Invalid encoding, as provided as a binary string 1321 // Invalid encoding, as provided as a binary string
1322 DicomMap m; 1322 DicomMap m;
1323 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "ISO_IR 13", true); 1323 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "ISO_IR 13", true);
1324 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false); 1324 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false);
1325 1325
1326 ASSERT_THROW(ParsedDicomFile d(m, Encoding_Latin3), OrthancException); 1326 ASSERT_THROW(ParsedDicomFile d(m, Encoding_Latin3, false), OrthancException);
1327 } 1327 }
1328 1328
1329 { 1329 {
1330 // Encoding provided as an empty string, fallback to default encoding 1330 // Encoding provided as an empty string, fallback to default encoding
1331 // In Orthanc <= 1.3.1, this test was throwing an exception 1331 // In Orthanc <= 1.3.1, this test was throwing an exception
1332 DicomMap m; 1332 DicomMap m;
1333 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "", false); 1333 m.SetValue(DICOM_TAG_SPECIFIC_CHARACTER_SET, "", false);
1334 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false); 1334 m.SetValue(DICOM_TAG_PATIENT_NAME, "HELLO", false);
1335 1335
1336 ParsedDicomFile d(m, Encoding_Latin3 /* default encoding */); 1336 ParsedDicomFile d(m, Encoding_Latin3 /* default encoding */, false);
1337 1337
1338 bool hasCodeExtensions; 1338 bool hasCodeExtensions;
1339 ASSERT_EQ(Encoding_Latin3, d.DetectEncoding(hasCodeExtensions)); 1339 ASSERT_EQ(Encoding_Latin3, d.DetectEncoding(hasCodeExtensions));
1340 ASSERT_FALSE(hasCodeExtensions); 1340 ASSERT_FALSE(hasCodeExtensions);
1341 } 1341 }