comparison OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp @ 4456:3e4f7b7840f0

new class: ParsedDicomCache()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 19 Jan 2021 16:11:23 +0100
parents d9473bd5ed43
children 789676a8c96a
comparison
equal deleted inserted replaced
4455:a8f554ca5ac6 4456:3e4f7b7840f0
39 #include "../Sources/DicomNetworking/DicomFindAnswers.h" 39 #include "../Sources/DicomNetworking/DicomFindAnswers.h"
40 #include "../Sources/DicomParsing/DicomModification.h" 40 #include "../Sources/DicomParsing/DicomModification.h"
41 #include "../Sources/DicomParsing/DicomWebJsonVisitor.h" 41 #include "../Sources/DicomParsing/DicomWebJsonVisitor.h"
42 #include "../Sources/DicomParsing/FromDcmtkBridge.h" 42 #include "../Sources/DicomParsing/FromDcmtkBridge.h"
43 #include "../Sources/DicomParsing/ToDcmtkBridge.h" 43 #include "../Sources/DicomParsing/ToDcmtkBridge.h"
44 #include "../Sources/DicomParsing/ParsedDicomCache.h"
44 #include "../Sources/Endianness.h" 45 #include "../Sources/Endianness.h"
45 #include "../Sources/Images/Image.h" 46 #include "../Sources/Images/Image.h"
46 #include "../Sources/Images/ImageBuffer.h" 47 #include "../Sources/Images/ImageBuffer.h"
47 #include "../Sources/Images/ImageProcessing.h" 48 #include "../Sources/Images/ImageProcessing.h"
48 #include "../Sources/Images/PngReader.h" 49 #include "../Sources/Images/PngReader.h"
2082 ASSERT_EQ(0u, m.GetSize()); // Sequences are not handled by DicomMap 2083 ASSERT_EQ(0u, m.GetSize()); // Sequences are not handled by DicomMap
2083 } 2084 }
2084 } 2085 }
2085 2086
2086 2087
2088 TEST(ParsedDicomCache, Basic)
2089 {
2090 ParsedDicomCache cache(10);
2091 ASSERT_EQ(0, cache.GetCurrentSize());
2092
2093 DicomMap tags;
2094 tags.SetValue(DICOM_TAG_PATIENT_ID, "patient1", false);
2095 cache.Acquire("a", new ParsedDicomFile(tags, Encoding_Latin1, true), 20);
2096 ASSERT_EQ(20, cache.GetCurrentSize());
2097
2098 {
2099 ParsedDicomCache::Accessor accessor(cache, "b");
2100 ASSERT_FALSE(accessor.IsValid());
2101 ASSERT_THROW(accessor.GetDicom(), OrthancException);
2102 ASSERT_THROW(accessor.GetFileSize(), OrthancException);
2103 }
2104
2105 {
2106 ParsedDicomCache::Accessor accessor(cache, "a");
2107 ASSERT_TRUE(accessor.IsValid());
2108 std::string s;
2109 ASSERT_TRUE(accessor.GetDicom().GetTagValue(s, DICOM_TAG_PATIENT_ID));
2110 ASSERT_EQ("patient1", s);
2111 ASSERT_EQ(20u, accessor.GetFileSize());
2112 }
2113
2114 tags.SetValue(DICOM_TAG_PATIENT_ID, "patient2", false);
2115 cache.Acquire("b", new ParsedDicomFile(tags, Encoding_Latin1, true), 5);
2116 ASSERT_EQ(5, cache.GetCurrentSize());
2117
2118 cache.Acquire("c", new ParsedDicomFile(true), 5);
2119 ASSERT_EQ(10, cache.GetCurrentSize());
2120
2121 {
2122 ParsedDicomCache::Accessor accessor(cache, "b");
2123 ASSERT_TRUE(accessor.IsValid());
2124 std::string s;
2125 ASSERT_TRUE(accessor.GetDicom().GetTagValue(s, DICOM_TAG_PATIENT_ID));
2126 ASSERT_EQ("patient2", s);
2127 ASSERT_EQ(5u, accessor.GetFileSize());
2128 }
2129
2130 cache.Acquire("d", new ParsedDicomFile(true), 5);
2131 ASSERT_EQ(10, cache.GetCurrentSize());
2132
2133 ASSERT_TRUE(ParsedDicomCache::Accessor(cache, "b").IsValid());
2134 ASSERT_FALSE(ParsedDicomCache::Accessor(cache, "c").IsValid()); // recycled by LRU
2135 ASSERT_TRUE(ParsedDicomCache::Accessor(cache, "d").IsValid());
2136
2137 cache.Acquire("e", new ParsedDicomFile(true), 15);
2138 ASSERT_EQ(15, cache.GetCurrentSize());
2139
2140 ASSERT_FALSE(ParsedDicomCache::Accessor(cache, "c").IsValid());
2141 ASSERT_FALSE(ParsedDicomCache::Accessor(cache, "d").IsValid());
2142 ASSERT_TRUE(ParsedDicomCache::Accessor(cache, "e").IsValid());
2143 }
2144
2145
2087 2146
2088 2147
2089 #if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1 2148 #if ORTHANC_ENABLE_DCMTK_TRANSCODING == 1
2090 2149
2091 #include "../Sources/DicomNetworking/DicomStoreUserConnection.h" 2150 #include "../Sources/DicomNetworking/DicomStoreUserConnection.h"