Mercurial > hg > orthanc
comparison OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp @ 4681:c5528c7847a6
new class DicomPath
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 07 Jun 2021 17:05:48 +0200 |
parents | 11bfea08341a |
children | d38a7040474a |
comparison
equal
deleted
inserted
replaced
4680:898e8ac8c453 | 4681:c5528c7847a6 |
---|---|
34 #endif | 34 #endif |
35 | 35 |
36 #include <gtest/gtest.h> | 36 #include <gtest/gtest.h> |
37 | 37 |
38 #include "../Sources/Compatibility.h" | 38 #include "../Sources/Compatibility.h" |
39 #include "../Sources/DicomFormat/DicomPath.h" | |
39 #include "../Sources/DicomNetworking/DicomFindAnswers.h" | 40 #include "../Sources/DicomNetworking/DicomFindAnswers.h" |
40 #include "../Sources/DicomParsing/DicomModification.h" | 41 #include "../Sources/DicomParsing/DicomModification.h" |
41 #include "../Sources/DicomParsing/DicomWebJsonVisitor.h" | 42 #include "../Sources/DicomParsing/DicomWebJsonVisitor.h" |
42 #include "../Sources/DicomParsing/FromDcmtkBridge.h" | 43 #include "../Sources/DicomParsing/FromDcmtkBridge.h" |
44 #include "../Sources/DicomParsing/ParsedDicomCache.h" | |
43 #include "../Sources/DicomParsing/ToDcmtkBridge.h" | 45 #include "../Sources/DicomParsing/ToDcmtkBridge.h" |
44 #include "../Sources/DicomParsing/ParsedDicomCache.h" | |
45 #include "../Sources/Endianness.h" | 46 #include "../Sources/Endianness.h" |
46 #include "../Sources/Images/Image.h" | 47 #include "../Sources/Images/Image.h" |
47 #include "../Sources/Images/ImageBuffer.h" | 48 #include "../Sources/Images/ImageBuffer.h" |
48 #include "../Sources/Images/ImageProcessing.h" | 49 #include "../Sources/Images/ImageProcessing.h" |
49 #include "../Sources/Images/PngReader.h" | 50 #include "../Sources/Images/PngReader.h" |
50 #include "../Sources/Images/PngWriter.h" | 51 #include "../Sources/Images/PngWriter.h" |
51 #include "../Sources/Logging.h" | 52 #include "../Sources/Logging.h" |
52 #include "../Sources/OrthancException.h" | 53 #include "../Sources/OrthancException.h" |
54 | |
53 #include "../Resources/CodeGeneration/EncodingTests.h" | 55 #include "../Resources/CodeGeneration/EncodingTests.h" |
54 | 56 |
55 #if ORTHANC_SANDBOXED != 1 | 57 #if ORTHANC_SANDBOXED != 1 |
56 # include "../Sources/SystemToolbox.h" | 58 # include "../Sources/SystemToolbox.h" |
57 #endif | 59 #endif |
2254 ASSERT_EQ(0u, cache.GetNumberOfItems()); | 2256 ASSERT_EQ(0u, cache.GetNumberOfItems()); |
2255 ASSERT_FALSE(ParsedDicomCache::Accessor(cache, "e").IsValid()); | 2257 ASSERT_FALSE(ParsedDicomCache::Accessor(cache, "e").IsValid()); |
2256 } | 2258 } |
2257 | 2259 |
2258 | 2260 |
2261 TEST(DicomModification, DicomPath) | |
2262 { | |
2263 // Those are samples inspired by those from "man dcmodify" | |
2264 | |
2265 static const DicomTag DICOM_TAG_ACQUISITION_MATRIX(0x0018, 0x1310); | |
2266 static const DicomTag DICOM_TAG_REFERENCED_PERFORMED_PROCEDURE_STEP_SEQUENCE(0x0008, 0x1111); | |
2267 | |
2268 DicomPath path = DicomPath::Parse("(0010,0010)", true); | |
2269 ASSERT_EQ(0u, path.GetPrefixLength()); | |
2270 ASSERT_EQ(DICOM_TAG_PATIENT_NAME, path.GetFinalTag()); | |
2271 ASSERT_THROW(path.GetPrefixTag(0), OrthancException); | |
2272 | |
2273 path = DicomPath::Parse("0018,1310", true); | |
2274 ASSERT_EQ(0u, path.GetPrefixLength()); | |
2275 ASSERT_EQ(DICOM_TAG_ACQUISITION_MATRIX, path.GetFinalTag()); | |
2276 ASSERT_EQ("(0018,1310)", path.Format()); | |
2277 | |
2278 // The following sample won't work without DCMTK | |
2279 path = DicomPath::Parse("PatientID", true); | |
2280 ASSERT_EQ(0u, path.GetPrefixLength()); | |
2281 ASSERT_EQ(DICOM_TAG_PATIENT_ID, path.GetFinalTag()); | |
2282 ASSERT_EQ("(0010,0020)", path.Format()); | |
2283 | |
2284 path = DicomPath::Parse("(0018,1310)", true); | |
2285 ASSERT_EQ(0u, path.GetPrefixLength()); | |
2286 ASSERT_EQ(DICOM_TAG_ACQUISITION_MATRIX, path.GetFinalTag()); | |
2287 ASSERT_EQ("(0018,1310)", path.Format()); | |
2288 | |
2289 path = DicomPath::Parse("(0008,1111)[0].PatientName", true); | |
2290 ASSERT_EQ(1u, path.GetPrefixLength()); | |
2291 ASSERT_EQ(DICOM_TAG_REFERENCED_PERFORMED_PROCEDURE_STEP_SEQUENCE, path.GetPrefixTag(0)); | |
2292 ASSERT_FALSE(path.IsPrefixUniversal(0)); | |
2293 ASSERT_EQ(0, path.GetPrefixIndex(0)); | |
2294 ASSERT_THROW(path.GetPrefixTag(1), OrthancException); | |
2295 ASSERT_EQ(DICOM_TAG_PATIENT_NAME, path.GetFinalTag()); | |
2296 | |
2297 path = DicomPath::Parse("(0008,1111)[1].(0008,1111)[2].(0010,0010)", true); | |
2298 ASSERT_EQ(2u, path.GetPrefixLength()); | |
2299 ASSERT_EQ(DICOM_TAG_REFERENCED_PERFORMED_PROCEDURE_STEP_SEQUENCE, path.GetPrefixTag(0)); | |
2300 ASSERT_FALSE(path.IsPrefixUniversal(0)); | |
2301 ASSERT_EQ(1, path.GetPrefixIndex(0)); | |
2302 ASSERT_EQ(DICOM_TAG_REFERENCED_PERFORMED_PROCEDURE_STEP_SEQUENCE, path.GetPrefixTag(1)); | |
2303 ASSERT_FALSE(path.IsPrefixUniversal(1)); | |
2304 ASSERT_EQ(2, path.GetPrefixIndex(1)); | |
2305 ASSERT_THROW(path.GetPrefixTag(2), OrthancException); | |
2306 ASSERT_EQ(DICOM_TAG_PATIENT_NAME, path.GetFinalTag()); | |
2307 | |
2308 path = DicomPath::Parse("(0008,1111)[*].PatientName", true); | |
2309 ASSERT_EQ(1u, path.GetPrefixLength()); | |
2310 ASSERT_EQ(DICOM_TAG_REFERENCED_PERFORMED_PROCEDURE_STEP_SEQUENCE, path.GetPrefixTag(0)); | |
2311 ASSERT_TRUE(path.IsPrefixUniversal(0)); | |
2312 ASSERT_THROW(path.GetPrefixIndex(0), OrthancException); | |
2313 ASSERT_THROW(path.GetPrefixTag(1), OrthancException); | |
2314 ASSERT_EQ(DICOM_TAG_PATIENT_NAME, path.GetFinalTag()); | |
2315 ASSERT_EQ("(0008,1111)[*].(0010,0010)", path.Format()); | |
2316 | |
2317 ASSERT_THROW(DicomPath::Parse("(0008,1111)[*].PatientName", false), OrthancException); | |
2318 | |
2319 path = DicomPath::Parse("(0008,1111)[1].(0008,1111)[*].(0010,0010)", true); | |
2320 ASSERT_EQ(2u, path.GetPrefixLength()); | |
2321 ASSERT_EQ(DICOM_TAG_REFERENCED_PERFORMED_PROCEDURE_STEP_SEQUENCE, path.GetPrefixTag(0)); | |
2322 ASSERT_FALSE(path.IsPrefixUniversal(0)); | |
2323 ASSERT_EQ(1, path.GetPrefixIndex(0)); | |
2324 ASSERT_EQ(DICOM_TAG_REFERENCED_PERFORMED_PROCEDURE_STEP_SEQUENCE, path.GetPrefixTag(0)); | |
2325 ASSERT_TRUE(path.IsPrefixUniversal(1)); | |
2326 ASSERT_THROW(path.GetPrefixIndex(1), OrthancException); | |
2327 ASSERT_THROW(path.GetPrefixTag(2), OrthancException); | |
2328 ASSERT_EQ(DICOM_TAG_PATIENT_NAME, path.GetFinalTag()); | |
2329 | |
2330 path = DicomPath::Parse("PatientID[1].PatientName", true); | |
2331 ASSERT_EQ(1u, path.GetPrefixLength()); | |
2332 ASSERT_EQ(DICOM_TAG_PATIENT_ID, path.GetPrefixTag(0)); | |
2333 ASSERT_FALSE(path.IsPrefixUniversal(0)); | |
2334 ASSERT_EQ(1, path.GetPrefixIndex(0)); | |
2335 ASSERT_THROW(path.GetPrefixTag(1), OrthancException); | |
2336 ASSERT_EQ(DICOM_TAG_PATIENT_NAME, path.GetFinalTag()); | |
2337 | |
2338 path = DicomPath::Parse(" PatientID [ 42 ] . PatientName ", true); | |
2339 ASSERT_EQ(1u, path.GetPrefixLength()); | |
2340 ASSERT_EQ(DICOM_TAG_PATIENT_ID, path.GetPrefixTag(0)); | |
2341 ASSERT_FALSE(path.IsPrefixUniversal(0)); | |
2342 ASSERT_EQ(42, path.GetPrefixIndex(0)); | |
2343 ASSERT_THROW(path.GetPrefixTag(1), OrthancException); | |
2344 ASSERT_EQ(DICOM_TAG_PATIENT_NAME, path.GetFinalTag()); | |
2345 ASSERT_EQ("(0010,0020)[42].(0010,0010)", path.Format()); | |
2346 | |
2347 ASSERT_THROW(DicomPath::Parse("nope", true), OrthancException); | |
2348 ASSERT_THROW(DicomPath::Parse("(0010,0010)[.PatientID", true), OrthancException); | |
2349 ASSERT_THROW(DicomPath::Parse("(0010,0010)[].PatientID", true), OrthancException); | |
2350 ASSERT_THROW(DicomPath::Parse("(0010,0010[].PatientID", true), OrthancException); | |
2351 ASSERT_THROW(DicomPath::Parse("(0010,0010)0].PatientID", true), OrthancException); | |
2352 ASSERT_THROW(DicomPath::Parse("(0010,0010)[-1].PatientID", true), OrthancException); | |
2353 } | |
2354 | |
2259 | 2355 |
2260 | 2356 |
2261 #if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1 | 2357 #if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1 |
2262 | 2358 |
2263 #include "../Sources/DicomNetworking/DicomStoreUserConnection.h" | 2359 #include "../Sources/DicomNetworking/DicomStoreUserConnection.h" |