annotate OrthancFramework/UnitTestsSources/ZipTests.cpp @ 4834:bec432ee1094

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