Mercurial > hg > orthanc
comparison UnitTestsSources/FileStorageTests.cpp @ 1549:e5e975e9b738
refactoring and simplification of StorageAccessor
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 17 Aug 2015 10:47:04 +0200 |
parents | d73a2178b319 |
children | b1291df2f780 |
comparison
equal
deleted
inserted
replaced
1548:e9325f3ac496 | 1549:e5e975e9b738 |
---|---|
34 #include "gtest/gtest.h" | 34 #include "gtest/gtest.h" |
35 | 35 |
36 #include <ctype.h> | 36 #include <ctype.h> |
37 | 37 |
38 #include "../Core/FileStorage/FilesystemStorage.h" | 38 #include "../Core/FileStorage/FilesystemStorage.h" |
39 #include "../Core/FileStorage/StorageAccessor.h" | |
40 #include "../Core/HttpServer/BufferHttpSender.h" | |
41 #include "../Core/HttpServer/FilesystemHttpSender.h" | |
42 #include "../Core/Logging.h" | |
43 #include "../Core/OrthancException.h" | |
44 #include "../Core/Toolbox.h" | |
45 #include "../Core/Uuid.h" | |
39 #include "../OrthancServer/ServerIndex.h" | 46 #include "../OrthancServer/ServerIndex.h" |
40 #include "../Core/Logging.h" | |
41 #include "../Core/Toolbox.h" | |
42 #include "../Core/OrthancException.h" | |
43 #include "../Core/Uuid.h" | |
44 #include "../Core/HttpServer/FilesystemHttpSender.h" | |
45 #include "../Core/HttpServer/BufferHttpSender.h" | |
46 #include "../Core/FileStorage/FileStorageAccessor.h" | |
47 #include "../Core/FileStorage/CompressedFileStorageAccessor.h" | |
48 | 47 |
49 using namespace Orthanc; | 48 using namespace Orthanc; |
50 | 49 |
51 | 50 |
52 static void StringToVector(std::vector<uint8_t>& v, | 51 static void StringToVector(std::vector<uint8_t>& v, |
121 s.ListAllFiles(ss); | 120 s.ListAllFiles(ss); |
122 ASSERT_EQ(0u, ss.size()); | 121 ASSERT_EQ(0u, ss.size()); |
123 } | 122 } |
124 | 123 |
125 | 124 |
126 TEST(FileStorageAccessor, Simple) | 125 TEST(StorageAccessor, NoCompression) |
127 { | 126 { |
128 FilesystemStorage s("UnitTestsStorage"); | 127 FilesystemStorage s("UnitTestsStorage"); |
129 FileStorageAccessor accessor(s); | 128 StorageAccessor accessor(s); |
130 | 129 |
131 std::string data = "Hello world"; | 130 std::string data = "Hello world"; |
132 FileInfo info = accessor.Write(data, FileContentType_Dicom); | 131 FileInfo info = accessor.Write(data, FileContentType_Dicom, CompressionType_None, true); |
133 | 132 |
134 std::string r; | 133 std::string r; |
135 accessor.Read(r, info.GetUuid(), FileContentType_Unknown); | 134 accessor.Read(r, info); |
136 | 135 |
137 ASSERT_EQ(data, r); | 136 ASSERT_EQ(data, r); |
138 ASSERT_EQ(CompressionType_None, info.GetCompressionType()); | 137 ASSERT_EQ(CompressionType_None, info.GetCompressionType()); |
139 ASSERT_EQ(11u, info.GetUncompressedSize()); | 138 ASSERT_EQ(11u, info.GetUncompressedSize()); |
140 ASSERT_EQ(11u, info.GetCompressedSize()); | 139 ASSERT_EQ(11u, info.GetCompressedSize()); |
141 ASSERT_EQ(FileContentType_Dicom, info.GetContentType()); | 140 ASSERT_EQ(FileContentType_Dicom, info.GetContentType()); |
141 ASSERT_EQ("3e25960a79dbc69b674cd4ec67a72c62", info.GetUncompressedMD5()); | |
142 ASSERT_EQ(info.GetUncompressedMD5(), info.GetCompressedMD5()); | |
142 } | 143 } |
143 | 144 |
144 | 145 |
145 TEST(FileStorageAccessor, NoCompression) | 146 TEST(StorageAccessor, Compression) |
146 { | 147 { |
147 FilesystemStorage s("UnitTestsStorage"); | 148 FilesystemStorage s("UnitTestsStorage"); |
148 CompressedFileStorageAccessor accessor(s); | 149 StorageAccessor accessor(s); |
149 | 150 |
150 accessor.SetCompressionForNextOperations(CompressionType_None); | |
151 std::string data = "Hello world"; | 151 std::string data = "Hello world"; |
152 FileInfo info = accessor.Write(data, FileContentType_Dicom); | 152 FileInfo info = accessor.Write(data, FileContentType_DicomAsJson, CompressionType_ZlibWithSize, true); |
153 | 153 |
154 std::string r; | 154 std::string r; |
155 accessor.Read(r, info.GetUuid(), FileContentType_Unknown); | 155 accessor.Read(r, info); |
156 | |
157 ASSERT_EQ(data, r); | |
158 ASSERT_EQ(CompressionType_None, info.GetCompressionType()); | |
159 ASSERT_EQ(11u, info.GetUncompressedSize()); | |
160 ASSERT_EQ(11u, info.GetCompressedSize()); | |
161 ASSERT_EQ(FileContentType_Dicom, info.GetContentType()); | |
162 } | |
163 | |
164 | |
165 TEST(FileStorageAccessor, NoCompression2) | |
166 { | |
167 FilesystemStorage s("UnitTestsStorage"); | |
168 CompressedFileStorageAccessor accessor(s); | |
169 | |
170 accessor.SetCompressionForNextOperations(CompressionType_None); | |
171 std::vector<uint8_t> data; | |
172 StringToVector(data, "Hello world"); | |
173 FileInfo info = accessor.Write(data, FileContentType_Dicom); | |
174 | |
175 std::string r; | |
176 accessor.Read(r, info.GetUuid(), FileContentType_Unknown); | |
177 | |
178 ASSERT_EQ(0, memcmp(&r[0], &data[0], data.size())); | |
179 ASSERT_EQ(CompressionType_None, info.GetCompressionType()); | |
180 ASSERT_EQ(11u, info.GetUncompressedSize()); | |
181 ASSERT_EQ(11u, info.GetCompressedSize()); | |
182 ASSERT_EQ(FileContentType_Dicom, info.GetContentType()); | |
183 } | |
184 | |
185 | |
186 TEST(FileStorageAccessor, Compression) | |
187 { | |
188 FilesystemStorage s("UnitTestsStorage"); | |
189 CompressedFileStorageAccessor accessor(s); | |
190 | |
191 accessor.SetCompressionForNextOperations(CompressionType_ZlibWithSize); | |
192 std::string data = "Hello world"; | |
193 FileInfo info = accessor.Write(data, FileContentType_Dicom); | |
194 | |
195 std::string r; | |
196 accessor.Read(r, info.GetUuid(), FileContentType_Unknown); | |
197 | 156 |
198 ASSERT_EQ(data, r); | 157 ASSERT_EQ(data, r); |
199 ASSERT_EQ(CompressionType_ZlibWithSize, info.GetCompressionType()); | 158 ASSERT_EQ(CompressionType_ZlibWithSize, info.GetCompressionType()); |
200 ASSERT_EQ(11u, info.GetUncompressedSize()); | 159 ASSERT_EQ(11u, info.GetUncompressedSize()); |
201 ASSERT_EQ(FileContentType_Dicom, info.GetContentType()); | 160 ASSERT_EQ(FileContentType_DicomAsJson, info.GetContentType()); |
161 ASSERT_EQ("3e25960a79dbc69b674cd4ec67a72c62", info.GetUncompressedMD5()); | |
162 ASSERT_NE(info.GetUncompressedMD5(), info.GetCompressedMD5()); | |
202 } | 163 } |
203 | 164 |
204 | 165 |
205 TEST(FileStorageAccessor, Mix) | 166 TEST(StorageAccessor, Mix) |
206 { | 167 { |
207 FilesystemStorage s("UnitTestsStorage"); | 168 FilesystemStorage s("UnitTestsStorage"); |
208 CompressedFileStorageAccessor accessor(s); | 169 StorageAccessor accessor(s); |
209 | 170 |
210 std::string r; | 171 std::string r; |
211 std::string compressedData = "Hello"; | 172 std::string compressedData = "Hello"; |
212 std::string uncompressedData = "HelloWorld"; | 173 std::string uncompressedData = "HelloWorld"; |
213 | 174 |
214 accessor.SetCompressionForNextOperations(CompressionType_ZlibWithSize); | 175 FileInfo compressedInfo = accessor.Write(compressedData, FileContentType_Dicom, CompressionType_ZlibWithSize, false); |
215 FileInfo compressedInfo = accessor.Write(compressedData, FileContentType_Dicom); | 176 FileInfo uncompressedInfo = accessor.Write(uncompressedData, FileContentType_Dicom, CompressionType_None, false); |
216 | 177 |
217 accessor.SetCompressionForNextOperations(CompressionType_None); | 178 accessor.Read(r, compressedInfo); |
218 FileInfo uncompressedInfo = accessor.Write(uncompressedData, FileContentType_Dicom); | |
219 | |
220 accessor.SetCompressionForNextOperations(CompressionType_ZlibWithSize); | |
221 accessor.Read(r, compressedInfo.GetUuid(), FileContentType_Unknown); | |
222 ASSERT_EQ(compressedData, r); | 179 ASSERT_EQ(compressedData, r); |
223 | 180 |
224 accessor.SetCompressionForNextOperations(CompressionType_None); | 181 accessor.Read(r, uncompressedInfo); |
225 accessor.Read(r, compressedInfo.GetUuid(), FileContentType_Unknown); | 182 ASSERT_EQ(uncompressedData, r); |
226 ASSERT_NE(compressedData, r); | 183 ASSERT_NE(compressedData, r); |
227 | 184 |
228 /* | 185 /* |
229 // This test is too slow on Windows | 186 // This test is too slow on Windows |
230 accessor.SetCompressionForNextOperations(CompressionType_ZlibWithSize); | 187 accessor.SetCompressionForNextOperations(CompressionType_ZlibWithSize); |