Mercurial > hg > orthanc
comparison OrthancFramework/UnitTestsSources/ZipTests.cpp @ 4355:460a71988208
new class: ZipReader
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 08 Dec 2020 12:38:59 +0100 |
parents | bcfb53d1bc56 |
children | d9473bd5ed43 |
comparison
equal
deleted
inserted
replaced
4354:bcfb53d1bc56 | 4355:460a71988208 |
---|---|
25 # include <OrthancFramework.h> | 25 # include <OrthancFramework.h> |
26 #endif | 26 #endif |
27 | 27 |
28 #include <gtest/gtest.h> | 28 #include <gtest/gtest.h> |
29 | 29 |
30 #include "../Sources/Compression/HierarchicalZipWriter.h" | |
31 #include "../Sources/Compression/ZipReader.h" | |
30 #include "../Sources/OrthancException.h" | 32 #include "../Sources/OrthancException.h" |
31 #include "../Sources/Compression/ZipWriter.h" | 33 #include "../Sources/TemporaryFile.h" |
32 #include "../Sources/Compression/HierarchicalZipWriter.h" | |
33 #include "../Sources/Toolbox.h" | 34 #include "../Sources/Toolbox.h" |
34 | 35 |
35 | 36 |
36 using namespace Orthanc; | 37 using namespace Orthanc; |
37 | 38 |
180 | 181 |
181 **/ | 182 **/ |
182 } | 183 } |
183 | 184 |
184 | 185 |
185 | 186 TEST(ZipReader, Basic) |
186 | 187 { |
187 | 188 TemporaryFile f; |
188 #include "../Resources/ThirdParty/minizip/unzip.h" | |
189 | |
190 TEST(ZipReader, DISABLED_Basic) | |
191 { | |
192 unzFile zip = unzOpen("/home/jodogne/DICOM/Demo/BRAINIX.zip"); | |
193 printf(">> %d\n", zip); | |
194 | |
195 unz_global_info info; | |
196 printf(">> %d\n", unzGetGlobalInfo(zip, &info)); | |
197 printf("%d %d\n", info.number_entry, info.size_comment); | |
198 | |
199 unsigned int count = 0; | |
200 printf(">> %d\n", unzGoToFirstFile(zip)); | |
201 for (;;) | |
202 { | |
203 char f[1024]; | |
204 unz_file_info64_s j; | |
205 unzGetCurrentFileInfo64(zip, &j, f, sizeof(f) - 1, NULL, 0, NULL, 0); | |
206 printf("[%s] %d %d\n", f, j.uncompressed_size, j.size_filename); | |
207 | |
208 | |
209 printf("%d\n", unzOpenCurrentFile(zip)); | |
210 | |
211 std::string content; | |
212 content.resize(j.uncompressed_size); | |
213 if (!content.empty()) | |
214 { | |
215 printf("%d\n", unzReadCurrentFile(zip, &content[0], content.size())); | |
216 | |
217 char g[1024]; | |
218 sprintf(g, "/tmp/i/zip-%06d.dcm", count); | |
219 FILE* h = fopen(g, "wb"); | |
220 fwrite(content.c_str(), content.size(), 1, h); | |
221 fclose(h); | |
222 } | |
223 | |
224 printf("%d\n", unzCloseCurrentFile(zip)); | |
225 | 189 |
226 | 190 { |
227 count += 1; | 191 Orthanc::ZipWriter w; |
228 int i = unzGoToNextFile(zip); | 192 w.SetOutputPath(f.GetPath().c_str()); |
229 if (i != 0) | 193 w.Open(); |
230 { | 194 w.OpenFile("world/hello"); |
231 printf("done\n"); | 195 w.Write("Hello world"); |
232 break; | 196 } |
233 } | 197 |
234 } | 198 ASSERT_TRUE(ZipReader::IsZipFile(f.GetPath())); |
235 | 199 |
236 printf("count: %d\n", count); | 200 std::unique_ptr<ZipReader> reader(ZipReader::CreateFromFile(f.GetPath())); |
201 | |
202 ASSERT_EQ(1u, reader->GetFilesCount()); | |
237 | 203 |
238 unzClose(zip); | 204 std::string filename, content; |
239 } | 205 ASSERT_TRUE(reader->ReadNextFile(filename, content)); |
240 | 206 ASSERT_EQ("world/hello", filename); |
207 ASSERT_EQ("Hello world", content); | |
208 ASSERT_FALSE(reader->ReadNextFile(filename, content)); | |
209 } | |
210 |