annotate OrthancFramework/UnitTestsSources/ZipTests.cpp @ 5765:247fc5368693 find-refactoring

un-sharing DatabaseConstraint and ISqlLookupFormatter with orthanc-databases
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 09 Sep 2024 16:14:22 +0200
parents f7adfb22e20e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
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
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
8 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
9 * 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
10 * 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
11 * 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
12 * 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
13 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
14 * 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
15 * 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
16 * 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
17 * Lesser General Public License for more details.
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
18 *
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
19 * 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
20 * 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
21 * <http://www.gnu.org/licenses/>.
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
22 **/
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
23
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 803
diff changeset
24
3992
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
25 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
26 // 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
27 # include <OrthancFramework.h>
3992
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
28 #endif
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
29
4062
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
30 #include <gtest/gtest.h>
81
0ec5e2e327b1 zip writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
4355
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
32 #include "../Sources/Compression/HierarchicalZipWriter.h"
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
33 #include "../Sources/Compression/ZipReader.h"
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
34 #include "../Sources/OrthancException.h"
4672
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
35 #include "../Sources/SystemToolbox.h"
4355
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
36 #include "../Sources/TemporaryFile.h"
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
37 #include "../Sources/Toolbox.h"
81
0ec5e2e327b1 zip writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
0ec5e2e327b1 zip writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
40 using namespace Orthanc;
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
41
81
0ec5e2e327b1 zip writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 TEST(ZipWriter, Basic)
0ec5e2e327b1 zip writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
0ec5e2e327b1 zip writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 Orthanc::ZipWriter w;
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 644
diff changeset
45 w.SetOutputPath("UnitTestsResults/hello.zip");
81
0ec5e2e327b1 zip writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 w.Open();
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
47 w.OpenFile("world/hello");
81
0ec5e2e327b1 zip writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 w.Write("Hello world");
0ec5e2e327b1 zip writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 }
0ec5e2e327b1 zip writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
0ec5e2e327b1 zip writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
644
eb5a0b21d05e do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
52 TEST(ZipWriter, Basic64)
eb5a0b21d05e do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
53 {
eb5a0b21d05e do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
54 Orthanc::ZipWriter w;
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 644
diff changeset
55 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
56 w.SetZip64(true);
eb5a0b21d05e do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
57 w.Open();
eb5a0b21d05e do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
58 w.OpenFile("world/hello");
eb5a0b21d05e do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
59 w.Write("Hello world");
eb5a0b21d05e do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
60 }
eb5a0b21d05e do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
61
eb5a0b21d05e do not use ZIP64 as the default format anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
62
81
0ec5e2e327b1 zip writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 TEST(ZipWriter, Exceptions)
0ec5e2e327b1 zip writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
0ec5e2e327b1 zip writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 Orthanc::ZipWriter w;
0ec5e2e327b1 zip writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 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
67 w.SetOutputPath("UnitTestsResults/hello3.zip");
81
0ec5e2e327b1 zip writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 w.Open();
0ec5e2e327b1 zip writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 ASSERT_THROW(w.Write("hello world"), Orthanc::OrthancException);
0ec5e2e327b1 zip writer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
71
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
72
1277
46bca019587e primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
73 TEST(ZipWriter, Append)
46bca019587e primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
74 {
46bca019587e primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
75 {
46bca019587e primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
76 Orthanc::ZipWriter w;
46bca019587e primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
77 w.SetAppendToExisting(false);
46bca019587e primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
78 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
79 w.Open();
46bca019587e primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
80 w.OpenFile("world/hello");
46bca019587e primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
81 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
82 }
46bca019587e primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
83
46bca019587e primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
84 {
46bca019587e primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
85 Orthanc::ZipWriter w;
46bca019587e primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
86 w.SetAppendToExisting(true);
46bca019587e primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
87 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
88 w.Open();
46bca019587e primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
89 w.OpenFile("world/appended");
46bca019587e primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
90 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
91 }
46bca019587e primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
92 }
46bca019587e primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
93
46bca019587e primitives to add new content to existing ZIP files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
94
247
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
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
97
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
98 namespace Orthanc
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
99 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
100 // The namespace is necessary
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
101 // 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
102
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
103 TEST(HierarchicalZipWriter, Index)
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
104 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
105 HierarchicalZipWriter::Index i;
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
106 ASSERT_EQ("hello", i.OpenFile("hello"));
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
107 ASSERT_EQ("hello-2", i.OpenFile("hello"));
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
108 ASSERT_EQ("coucou", i.OpenFile("coucou"));
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
109 ASSERT_EQ("hello-3", i.OpenFile("hello"));
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
110
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
111 i.OpenDirectory("coucou");
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
112
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
113 ASSERT_EQ("coucou-2/world", i.OpenFile("world"));
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
114 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
115
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
116 i.OpenDirectory("world");
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
117
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
118 ASSERT_EQ("coucou-2/world-3/hello", i.OpenFile("hello"));
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
119 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
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
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
123 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
124
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
125 i.CloseDirectory();
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
126
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
127 ASSERT_EQ("coucou-3", i.OpenFile("coucou"));
247
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 ASSERT_THROW(i.CloseDirectory(), OrthancException);
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
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
132
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
133 TEST(HierarchicalZipWriter, Filenames)
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
134 {
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
135 ASSERT_EQ("trE hell", HierarchicalZipWriter::Index::KeepAlphanumeric(" ÊtrE hellô "));
251
4dc9d00c359c fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
136
4dc9d00c359c fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
137 // The "^" character is considered as a space in DICOM
4dc9d00c359c fix test
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 249
diff changeset
138 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
139 }
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
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
142
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
143 TEST(HierarchicalZipWriter, Basic)
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 static const std::string SPACES = " ";
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
146
803
4689e400e0fa directory to store the results of the unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 644
diff changeset
147 HierarchicalZipWriter w("UnitTestsResults/hello2.zip");
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
148
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
149 w.SetCompressionLevel(0);
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
150
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
151 // Inside "/"
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
152 w.OpenFile("hello");
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
153 w.Write(SPACES + "hello\n");
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
154 w.OpenFile("hello");
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
155 w.Write(SPACES + "hello-2\n");
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
156 w.OpenDirectory("hello");
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
157
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
158 // Inside "/hello-3"
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
159 w.OpenFile("hello");
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
160 w.Write(SPACES + "hello\n");
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
161 w.OpenDirectory("hello");
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
162
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
163 w.SetCompressionLevel(9);
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
164
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
165 // Inside "/hello-3/hello-2"
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
166 w.OpenFile("hello");
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
167 w.Write(SPACES + "hello\n");
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
168 w.OpenFile("hello");
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
169 w.Write(SPACES + "hello-2\n");
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
170 w.CloseDirectory();
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 // Inside "/hello-3"
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 247
diff changeset
173 w.OpenFile("hello");
247
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
174 w.Write(SPACES + "hello-3\n");
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 /**
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 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
179
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
180 # unzip -v hello2.zip
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 => 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
183 compression ratio.
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
184
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
185 **/
c9b3ba0fd140 path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 81
diff changeset
186 }
4354
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
4355
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
189 TEST(ZipReader, Basic)
4354
bcfb53d1bc56 trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
190 {
4355
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
191 TemporaryFile f;
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
192
4354
bcfb53d1bc56 trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
193 {
4355
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
194 Orthanc::ZipWriter w;
4700
863383e7e582 fix warnings in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4672
diff changeset
195 ASSERT_EQ(0u, w.GetArchiveSize());
4672
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
196
4355
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
197 w.SetOutputPath(f.GetPath().c_str());
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
198 w.Open();
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
199 w.OpenFile("world/hello");
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
200 w.Write("Hello world");
4672
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
201
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
202 ASSERT_EQ(w.GetArchiveSize(), SystemToolbox::GetFileSize(f.GetPath()));
4354
bcfb53d1bc56 trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
203 }
bcfb53d1bc56 trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
204
4355
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
205 ASSERT_TRUE(ZipReader::IsZipFile(f.GetPath()));
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
206
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
207 std::unique_ptr<ZipReader> reader(ZipReader::CreateFromFile(f.GetPath()));
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
208
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
209 ASSERT_EQ(1u, reader->GetFilesCount());
4354
bcfb53d1bc56 trying to uncompress one zip archive
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
210
4355
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
211 std::string filename, content;
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
212 ASSERT_TRUE(reader->ReadNextFile(filename, content));
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
213 ASSERT_EQ("world/hello", filename);
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
214 ASSERT_EQ("Hello world", content);
460a71988208 new class: ZipReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4354
diff changeset
215 ASSERT_FALSE(reader->ReadNextFile(filename, content));
4354
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
4670
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
218
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
219
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
220 TEST(ZipWriter, Stream)
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
221 {
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
222 std::string memory;
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
223
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
224 std::string large;
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
225 large.resize(4 * 65536);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
226 for (size_t i = 0; i < large.size(); i++)
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
227 {
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
228 large[i] = rand() % 256;
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
229 }
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
230
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
231 for (int i = 0; i < 2; i++)
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
232 {
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
233 {
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
234 Orthanc::ZipWriter w;
4672
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
235 w.SetMemoryOutput(memory, (i == 0) /* ZIP64? */);
4670
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
236 w.Open();
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
237
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
238 w.OpenFile("world/hello");
4672
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
239 w.Write("Hello");
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
240 w.CancelStream();
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
241 }
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
242
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
243 ASSERT_THROW(ZipReader::CreateFromMemory(memory), Orthanc::OrthancException);
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
244
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
245 memory.clear();
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
246 uint64_t archiveSize;
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
247
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
248 {
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
249 Orthanc::ZipWriter w;
4700
863383e7e582 fix warnings in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4672
diff changeset
250 ASSERT_EQ(0u, w.GetArchiveSize());
4672
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
251
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
252 w.SetMemoryOutput(memory, (i == 0) /* ZIP64? */);
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
253 w.Open();
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
254
4700
863383e7e582 fix warnings in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4672
diff changeset
255 ASSERT_EQ(0u, w.GetArchiveSize());
4672
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
256
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
257 w.OpenFile("world/hello");
4670
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
258 w.Write(large);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
259 w.OpenFile("world/hello2");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
260 w.Write(large);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
261 w.OpenFile("world/hello3");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
262 w.Write("Hello world");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
263 w.OpenFile("world/hello4");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
264 w.Write(large);
4672
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
265
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
266 ASSERT_TRUE(memory.empty());
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
267
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
268 uint64_t s1 = w.GetArchiveSize();
4700
863383e7e582 fix warnings in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4672
diff changeset
269 ASSERT_NE(0u, s1);
4672
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
270
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
271 w.Close();
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
272 archiveSize = w.GetArchiveSize();
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
273
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
274 ASSERT_NE(archiveSize, s1);
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
275 ASSERT_EQ(archiveSize, w.GetArchiveSize());
4670
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
276 }
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
277
4672
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
278 ASSERT_EQ(archiveSize, memory.size());
d9942d48fea7 ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4670
diff changeset
279
4670
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
280 std::unique_ptr<ZipReader> reader(ZipReader::CreateFromMemory(memory));
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
281
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
282 ASSERT_EQ(4u, reader->GetFilesCount());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
283
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
284 {
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
285 std::string filename, content;
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
286 ASSERT_TRUE(reader->ReadNextFile(filename, content));
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
287 ASSERT_EQ("world/hello", filename);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
288 ASSERT_EQ(large.size(), content.size());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
289 ASSERT_TRUE(memcmp(large.c_str(), content.c_str(), large.size()) == 0);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
290 }
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
291
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
292 {
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
293 std::string filename, content;
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
294 ASSERT_TRUE(reader->ReadNextFile(filename, content));
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
295 ASSERT_EQ("world/hello2", filename);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
296 ASSERT_EQ(large.size(), content.size());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
297 ASSERT_TRUE(memcmp(large.c_str(), content.c_str(), large.size()) == 0);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
298 }
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
299
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
300 {
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
301 std::string filename, content;
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
302 ASSERT_TRUE(reader->ReadNextFile(filename, content));
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
303 ASSERT_EQ("world/hello3", filename);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
304 ASSERT_EQ("Hello world", content);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
305 }
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
306
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
307 {
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
308 std::string filename, content;
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
309 ASSERT_TRUE(reader->ReadNextFile(filename, content));
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
310 ASSERT_EQ("world/hello4", filename);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
311 ASSERT_EQ(large.size(), content.size());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
312 ASSERT_TRUE(memcmp(large.c_str(), content.c_str(), large.size()) == 0);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
313 }
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
314
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
315 {
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
316 std::string filename, content;
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
317 ASSERT_FALSE(reader->ReadNextFile(filename, content));
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
318 }
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
319 }
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
320 }
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
321
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
322
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
323 namespace Orthanc
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
324 {
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
325 // The namespace is necessary because of FRIEND_TEST
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
326 // http://code.google.com/p/googletest/wiki/AdvancedGuide#Private_Class_Members
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
327
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
328 TEST(ZipWriter, BufferWithSeek)
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
329 {
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
330 ZipWriter::BufferWithSeek buffer;
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
331 ASSERT_EQ(0u, buffer.GetSize());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
332
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
333 std::string s;
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
334 buffer.Flush(s);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
335 ASSERT_TRUE(s.empty());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
336
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
337 buffer.Write("hello");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
338 ASSERT_EQ(5u, buffer.GetSize());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
339 ASSERT_EQ(5u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
340 buffer.Write("world");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
341 ASSERT_EQ(10u, buffer.GetSize());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
342 ASSERT_EQ(10u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
343 buffer.Flush(s);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
344 ASSERT_EQ("helloworld", s);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
345 ASSERT_EQ(0u, buffer.GetSize());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
346 ASSERT_EQ(0u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
347
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
348 buffer.Write("hello world");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
349 buffer.Seek(4);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
350 ASSERT_EQ(4u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
351 buffer.Write("ab");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
352 ASSERT_EQ(6u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
353 buffer.Flush(s);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
354 ASSERT_EQ("hellabworld", s);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
355 ASSERT_EQ(0u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
356
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
357 buffer.Seek(0);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
358 ASSERT_EQ(0u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
359 buffer.Write("abc");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
360 buffer.Write("");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
361 ASSERT_EQ(3u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
362 buffer.Seek(3);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
363 ASSERT_THROW(buffer.Seek(4), OrthancException);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
364 ASSERT_EQ(3u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
365 buffer.Write("de");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
366 buffer.Write("");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
367 ASSERT_EQ(5u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
368 buffer.Seek(3);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
369 buffer.Seek(3);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
370 ASSERT_EQ(3u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
371 ASSERT_THROW(buffer.Write("def"), OrthancException);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
372 buffer.Write("");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
373 ASSERT_EQ(3u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
374 buffer.Write("fg");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
375 ASSERT_EQ(5u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
376 buffer.Write("hi");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
377 ASSERT_EQ(7u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
378 buffer.Flush(s);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
379 ASSERT_EQ("abcfghi", s);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
380 ASSERT_EQ(0u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
381
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
382 buffer.Write("abc");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
383 ASSERT_EQ(3u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
384 buffer.Seek(2);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
385 ASSERT_EQ(2u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
386 buffer.Write("z");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
387 ASSERT_EQ(3u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
388 buffer.Seek(1);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
389 ASSERT_EQ(1u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
390 buffer.Write("y");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
391 ASSERT_EQ(2u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
392 buffer.Flush(s);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
393 ASSERT_EQ("ayz", s);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
394 ASSERT_EQ(0u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
395
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
396 ASSERT_EQ(0u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
397 buffer.Write("abc");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
398 ASSERT_EQ(3u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
399 buffer.Seek(1);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
400 ASSERT_EQ(1u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
401 buffer.Write("z");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
402 ASSERT_EQ(2u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
403 buffer.Seek(3);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
404 ASSERT_EQ(3u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
405 buffer.Write("y");
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
406 ASSERT_EQ(4u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
407 buffer.Flush(s);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
408 ASSERT_EQ("azcy", s);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
409 ASSERT_EQ(0u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
410
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
411 buffer.Flush(s);
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
412 ASSERT_TRUE(s.empty());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
413 ASSERT_EQ(0u, buffer.GetPosition());
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
414 }
b12faca76a52 support of output streams in ZipWriter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
415 }