Mercurial > hg > orthanc
annotate OrthancFramework/UnitTestsSources/ZipTests.cpp @ 4354:bcfb53d1bc56
trying to uncompress one zip archive
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 07 Dec 2020 20:38:31 +0100 |
parents | bf7b9edf6b81 |
children | 460a71988208 |
rev | line source |
---|---|
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
1 /** |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1277
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
6 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
10 * the License, or (at your option) any later version. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
11 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
15 * Lesser General Public License for more details. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
16 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
18 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
19 * <http://www.gnu.org/licenses/>. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
20 **/ |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
21 |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
22 |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
23 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1 |
4063
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
24 // Must be the first to be sure to use the Orthanc framework shared library |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3992
diff
changeset
|
25 # include <OrthancFramework.h> |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
26 #endif |
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
27 |
4062 | 28 #include <gtest/gtest.h> |
81 | 29 |
4045 | 30 #include "../Sources/OrthancException.h" |
31 #include "../Sources/Compression/ZipWriter.h" | |
32 #include "../Sources/Compression/HierarchicalZipWriter.h" | |
33 #include "../Sources/Toolbox.h" | |
81 | 34 |
35 | |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
36 using namespace Orthanc; |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
37 |
81 | 38 TEST(ZipWriter, Basic) |
39 { | |
40 Orthanc::ZipWriter w; | |
803
4689e400e0fa
directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
644
diff
changeset
|
41 w.SetOutputPath("UnitTestsResults/hello.zip"); |
81 | 42 w.Open(); |
249 | 43 w.OpenFile("world/hello"); |
81 | 44 w.Write("Hello world"); |
45 } | |
46 | |
47 | |
644
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
48 TEST(ZipWriter, Basic64) |
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
49 { |
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
50 Orthanc::ZipWriter w; |
803
4689e400e0fa
directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
644
diff
changeset
|
51 w.SetOutputPath("UnitTestsResults/hello64.zip"); |
644
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
52 w.SetZip64(true); |
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
53 w.Open(); |
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
54 w.OpenFile("world/hello"); |
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
55 w.Write("Hello world"); |
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
56 } |
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
57 |
eb5a0b21d05e
do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
58 |
81 | 59 TEST(ZipWriter, Exceptions) |
60 { | |
61 Orthanc::ZipWriter w; | |
62 ASSERT_THROW(w.Open(), Orthanc::OrthancException); | |
803
4689e400e0fa
directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
644
diff
changeset
|
63 w.SetOutputPath("UnitTestsResults/hello3.zip"); |
81 | 64 w.Open(); |
65 ASSERT_THROW(w.Write("hello world"), Orthanc::OrthancException); | |
66 } | |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
67 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
68 |
1277
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
69 TEST(ZipWriter, Append) |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
70 { |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
71 { |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
72 Orthanc::ZipWriter w; |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
73 w.SetAppendToExisting(false); |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
74 w.SetOutputPath("UnitTestsResults/append.zip"); |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
75 w.Open(); |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
76 w.OpenFile("world/hello"); |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
77 w.Write("Hello world 1"); |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
78 } |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
79 |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
80 { |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
81 Orthanc::ZipWriter w; |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
82 w.SetAppendToExisting(true); |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
83 w.SetOutputPath("UnitTestsResults/append.zip"); |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
84 w.Open(); |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
85 w.OpenFile("world/appended"); |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
86 w.Write("Hello world 2"); |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
87 } |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
88 } |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
89 |
46bca019587e
primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
90 |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
91 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
92 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
93 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
94 namespace Orthanc |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
95 { |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
96 // The namespace is necessary |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
97 // http://code.google.com/p/googletest/wiki/AdvancedGuide#Private_Class_Members |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
98 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
99 TEST(HierarchicalZipWriter, Index) |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
100 { |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
101 HierarchicalZipWriter::Index i; |
249 | 102 ASSERT_EQ("hello", i.OpenFile("hello")); |
103 ASSERT_EQ("hello-2", i.OpenFile("hello")); | |
104 ASSERT_EQ("coucou", i.OpenFile("coucou")); | |
105 ASSERT_EQ("hello-3", i.OpenFile("hello")); | |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
106 |
249 | 107 i.OpenDirectory("coucou"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
108 |
249 | 109 ASSERT_EQ("coucou-2/world", i.OpenFile("world")); |
110 ASSERT_EQ("coucou-2/world-2", i.OpenFile("world")); | |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
111 |
249 | 112 i.OpenDirectory("world"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
113 |
249 | 114 ASSERT_EQ("coucou-2/world-3/hello", i.OpenFile("hello")); |
115 ASSERT_EQ("coucou-2/world-3/hello-2", i.OpenFile("hello")); | |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
116 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
117 i.CloseDirectory(); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
118 |
249 | 119 ASSERT_EQ("coucou-2/world-4", i.OpenFile("world")); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
120 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
121 i.CloseDirectory(); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
122 |
249 | 123 ASSERT_EQ("coucou-3", i.OpenFile("coucou")); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
124 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
125 ASSERT_THROW(i.CloseDirectory(), OrthancException); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
126 } |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
127 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
128 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
129 TEST(HierarchicalZipWriter, Filenames) |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
130 { |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
131 ASSERT_EQ("trE hell", HierarchicalZipWriter::Index::KeepAlphanumeric(" ÊtrE hellô ")); |
251 | 132 |
133 // The "^" character is considered as a space in DICOM | |
134 ASSERT_EQ("Hel lo world", HierarchicalZipWriter::Index::KeepAlphanumeric(" Hel^^ ^\r\n\t^^lo \t <world> ")); | |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
135 } |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
136 } |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
137 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
138 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
139 TEST(HierarchicalZipWriter, Basic) |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
140 { |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
141 static const std::string SPACES = " "; |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
142 |
803
4689e400e0fa
directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
644
diff
changeset
|
143 HierarchicalZipWriter w("UnitTestsResults/hello2.zip"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
144 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
145 w.SetCompressionLevel(0); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
146 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
147 // Inside "/" |
249 | 148 w.OpenFile("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
149 w.Write(SPACES + "hello\n"); |
249 | 150 w.OpenFile("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
151 w.Write(SPACES + "hello-2\n"); |
249 | 152 w.OpenDirectory("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
153 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
154 // Inside "/hello-3" |
249 | 155 w.OpenFile("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
156 w.Write(SPACES + "hello\n"); |
249 | 157 w.OpenDirectory("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
158 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
159 w.SetCompressionLevel(9); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
160 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
161 // Inside "/hello-3/hello-2" |
249 | 162 w.OpenFile("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
163 w.Write(SPACES + "hello\n"); |
249 | 164 w.OpenFile("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
165 w.Write(SPACES + "hello-2\n"); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
166 w.CloseDirectory(); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
167 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
168 // Inside "/hello-3" |
249 | 169 w.OpenFile("hello"); |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
170 w.Write(SPACES + "hello-3\n"); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
171 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
172 /** |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
173 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
174 TO CHECK THE CONTENT OF THE "hello2.zip" FILE: |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
175 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
176 # unzip -v hello2.zip |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
177 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
178 => There must be 6 files. The first 3 files must have a negative |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
179 compression ratio. |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
180 |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
181 **/ |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
81
diff
changeset
|
182 } |
4354
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
183 |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
184 |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
185 |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
186 |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
187 |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
188 #include "../Resources/ThirdParty/minizip/unzip.h" |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
189 |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
190 TEST(ZipReader, DISABLED_Basic) |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
191 { |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
192 unzFile zip = unzOpen("/home/jodogne/DICOM/Demo/BRAINIX.zip"); |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
193 printf(">> %d\n", zip); |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
194 |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
195 unz_global_info info; |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
196 printf(">> %d\n", unzGetGlobalInfo(zip, &info)); |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
197 printf("%d %d\n", info.number_entry, info.size_comment); |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
198 |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
199 unsigned int count = 0; |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
200 printf(">> %d\n", unzGoToFirstFile(zip)); |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
201 for (;;) |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
202 { |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
203 char f[1024]; |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
204 unz_file_info64_s j; |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
205 unzGetCurrentFileInfo64(zip, &j, f, sizeof(f) - 1, NULL, 0, NULL, 0); |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
206 printf("[%s] %d %d\n", f, j.uncompressed_size, j.size_filename); |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
207 |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
208 |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
209 printf("%d\n", unzOpenCurrentFile(zip)); |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
210 |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
211 std::string content; |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
212 content.resize(j.uncompressed_size); |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
213 if (!content.empty()) |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
214 { |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
215 printf("%d\n", unzReadCurrentFile(zip, &content[0], content.size())); |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
216 |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
217 char g[1024]; |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
218 sprintf(g, "/tmp/i/zip-%06d.dcm", count); |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
219 FILE* h = fopen(g, "wb"); |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
220 fwrite(content.c_str(), content.size(), 1, h); |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
221 fclose(h); |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
222 } |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
223 |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
224 printf("%d\n", unzCloseCurrentFile(zip)); |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
225 |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
226 |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
227 count += 1; |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
228 int i = unzGoToNextFile(zip); |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
229 if (i != 0) |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
230 { |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
231 printf("done\n"); |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
232 break; |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
233 } |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
234 } |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
235 |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
236 printf("count: %d\n", count); |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
237 |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
238 unzClose(zip); |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
239 } |
bcfb53d1bc56
trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
240 |