1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | #include "ZipArchiveTests.h"
|
---|
26 | #include "OgreZip.h"
|
---|
27 |
|
---|
28 | using namespace Ogre;
|
---|
29 |
|
---|
30 | // Regsiter the suite
|
---|
31 | CPPUNIT_TEST_SUITE_REGISTRATION( ZipArchiveTests );
|
---|
32 |
|
---|
33 | void ZipArchiveTests::setUp()
|
---|
34 | {
|
---|
35 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
36 | testPath = "../../../../Tests/OgreMain/misc/ArchiveTest.zip";
|
---|
37 | #else
|
---|
38 | testPath = "../../../Tests/OgreMain/misc/ArchiveTest.zip";
|
---|
39 | #endif
|
---|
40 | }
|
---|
41 | void ZipArchiveTests::tearDown()
|
---|
42 | {
|
---|
43 | }
|
---|
44 |
|
---|
45 | void ZipArchiveTests::testListNonRecursive()
|
---|
46 | {
|
---|
47 | ZipArchive arch(testPath, "Zip");
|
---|
48 | arch.load();
|
---|
49 | StringVectorPtr vec = arch.list(false);
|
---|
50 |
|
---|
51 | CPPUNIT_ASSERT_EQUAL((size_t)2, vec->size());
|
---|
52 | CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), vec->at(0));
|
---|
53 | CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), vec->at(1));
|
---|
54 |
|
---|
55 | }
|
---|
56 | void ZipArchiveTests::testListRecursive()
|
---|
57 | {
|
---|
58 | ZipArchive arch(testPath, "Zip");
|
---|
59 | arch.load();
|
---|
60 | StringVectorPtr vec = arch.list(true);
|
---|
61 |
|
---|
62 | CPPUNIT_ASSERT_EQUAL((size_t)6, vec->size());
|
---|
63 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/file.material"), vec->at(0));
|
---|
64 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/file2.material"), vec->at(1));
|
---|
65 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/file3.material"), vec->at(2));
|
---|
66 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/file4.material"), vec->at(3));
|
---|
67 | CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), vec->at(4));
|
---|
68 | CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), vec->at(5));
|
---|
69 | }
|
---|
70 | void ZipArchiveTests::testListFileInfoNonRecursive()
|
---|
71 | {
|
---|
72 | ZipArchive arch(testPath, "Zip");
|
---|
73 | arch.load();
|
---|
74 | FileInfoListPtr vec = arch.listFileInfo(false);
|
---|
75 |
|
---|
76 | CPPUNIT_ASSERT_EQUAL((size_t)2, vec->size());
|
---|
77 | FileInfo& fi1 = vec->at(0);
|
---|
78 | CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), fi1.filename);
|
---|
79 | CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), fi1.basename);
|
---|
80 | CPPUNIT_ASSERT_EQUAL(StringUtil::BLANK, fi1.path);
|
---|
81 | CPPUNIT_ASSERT_EQUAL((size_t)40, fi1.compressedSize);
|
---|
82 | CPPUNIT_ASSERT_EQUAL((size_t)130, fi1.uncompressedSize);
|
---|
83 |
|
---|
84 | FileInfo& fi2 = vec->at(1);
|
---|
85 | CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), fi2.filename);
|
---|
86 | CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), fi2.basename);
|
---|
87 | CPPUNIT_ASSERT_EQUAL(StringUtil::BLANK, fi2.path);
|
---|
88 | CPPUNIT_ASSERT_EQUAL((size_t)45, fi2.compressedSize);
|
---|
89 | CPPUNIT_ASSERT_EQUAL((size_t)156, fi2.uncompressedSize);
|
---|
90 | }
|
---|
91 | void ZipArchiveTests::testListFileInfoRecursive()
|
---|
92 | {
|
---|
93 | ZipArchive arch(testPath, "Zip");
|
---|
94 | arch.load();
|
---|
95 | FileInfoListPtr vec = arch.listFileInfo(true);
|
---|
96 |
|
---|
97 | CPPUNIT_ASSERT_EQUAL((size_t)6, vec->size());
|
---|
98 | FileInfo& fi3 = vec->at(0);
|
---|
99 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/file.material"), fi3.filename);
|
---|
100 | CPPUNIT_ASSERT_EQUAL(String("file.material"), fi3.basename);
|
---|
101 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/"), fi3.path);
|
---|
102 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi3.compressedSize);
|
---|
103 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi3.uncompressedSize);
|
---|
104 |
|
---|
105 | FileInfo& fi4 = vec->at(1);
|
---|
106 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/file2.material"), fi4.filename);
|
---|
107 | CPPUNIT_ASSERT_EQUAL(String("file2.material"), fi4.basename);
|
---|
108 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/"), fi4.path);
|
---|
109 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi4.compressedSize);
|
---|
110 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi4.uncompressedSize);
|
---|
111 |
|
---|
112 |
|
---|
113 | FileInfo& fi5 = vec->at(2);
|
---|
114 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/file3.material"), fi5.filename);
|
---|
115 | CPPUNIT_ASSERT_EQUAL(String("file3.material"), fi5.basename);
|
---|
116 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/"), fi5.path);
|
---|
117 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi5.compressedSize);
|
---|
118 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi5.uncompressedSize);
|
---|
119 |
|
---|
120 | FileInfo& fi6 = vec->at(3);
|
---|
121 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/file4.material"), fi6.filename);
|
---|
122 | CPPUNIT_ASSERT_EQUAL(String("file4.material"), fi6.basename);
|
---|
123 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/"), fi6.path);
|
---|
124 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi6.compressedSize);
|
---|
125 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi6.uncompressedSize);
|
---|
126 |
|
---|
127 | FileInfo& fi1 = vec->at(4);
|
---|
128 | CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), fi1.filename);
|
---|
129 | CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), fi1.basename);
|
---|
130 | CPPUNIT_ASSERT_EQUAL(StringUtil::BLANK, fi1.path);
|
---|
131 | CPPUNIT_ASSERT_EQUAL((size_t)40, fi1.compressedSize);
|
---|
132 | CPPUNIT_ASSERT_EQUAL((size_t)130, fi1.uncompressedSize);
|
---|
133 |
|
---|
134 | FileInfo& fi2 = vec->at(5);
|
---|
135 | CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), fi2.filename);
|
---|
136 | CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), fi2.basename);
|
---|
137 | CPPUNIT_ASSERT_EQUAL(StringUtil::BLANK, fi2.path);
|
---|
138 | CPPUNIT_ASSERT_EQUAL((size_t)45, fi2.compressedSize);
|
---|
139 | CPPUNIT_ASSERT_EQUAL((size_t)156, fi2.uncompressedSize);
|
---|
140 |
|
---|
141 | }
|
---|
142 | void ZipArchiveTests::testFindNonRecursive()
|
---|
143 | {
|
---|
144 | ZipArchive arch(testPath, "Zip");
|
---|
145 | arch.load();
|
---|
146 | StringVectorPtr vec = arch.find("*.txt", false);
|
---|
147 |
|
---|
148 | CPPUNIT_ASSERT_EQUAL((size_t)2, vec->size());
|
---|
149 | CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), vec->at(0));
|
---|
150 | CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), vec->at(1));
|
---|
151 | }
|
---|
152 | void ZipArchiveTests::testFindRecursive()
|
---|
153 | {
|
---|
154 | ZipArchive arch(testPath, "Zip");
|
---|
155 | arch.load();
|
---|
156 | StringVectorPtr vec = arch.find("*.material", true);
|
---|
157 |
|
---|
158 | CPPUNIT_ASSERT_EQUAL((size_t)4, vec->size());
|
---|
159 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/file.material"), vec->at(0));
|
---|
160 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/file2.material"), vec->at(1));
|
---|
161 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/file3.material"), vec->at(2));
|
---|
162 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/file4.material"), vec->at(3));
|
---|
163 | }
|
---|
164 | void ZipArchiveTests::testFindFileInfoNonRecursive()
|
---|
165 | {
|
---|
166 | ZipArchive arch(testPath, "Zip");
|
---|
167 | arch.load();
|
---|
168 | FileInfoListPtr vec = arch.findFileInfo("*.txt", false);
|
---|
169 |
|
---|
170 | CPPUNIT_ASSERT_EQUAL((size_t)2, vec->size());
|
---|
171 | FileInfo& fi1 = vec->at(0);
|
---|
172 | CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), fi1.filename);
|
---|
173 | CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), fi1.basename);
|
---|
174 | CPPUNIT_ASSERT_EQUAL(StringUtil::BLANK, fi1.path);
|
---|
175 | CPPUNIT_ASSERT_EQUAL((size_t)40, fi1.compressedSize);
|
---|
176 | CPPUNIT_ASSERT_EQUAL((size_t)130, fi1.uncompressedSize);
|
---|
177 |
|
---|
178 | FileInfo& fi2 = vec->at(1);
|
---|
179 | CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), fi2.filename);
|
---|
180 | CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), fi2.basename);
|
---|
181 | CPPUNIT_ASSERT_EQUAL(StringUtil::BLANK, fi2.path);
|
---|
182 | CPPUNIT_ASSERT_EQUAL((size_t)45, fi2.compressedSize);
|
---|
183 | CPPUNIT_ASSERT_EQUAL((size_t)156, fi2.uncompressedSize);
|
---|
184 | }
|
---|
185 | void ZipArchiveTests::testFindFileInfoRecursive()
|
---|
186 | {
|
---|
187 | ZipArchive arch(testPath, "Zip");
|
---|
188 | arch.load();
|
---|
189 | FileInfoListPtr vec = arch.findFileInfo("*.material", true);
|
---|
190 |
|
---|
191 | CPPUNIT_ASSERT_EQUAL((size_t)4, vec->size());
|
---|
192 |
|
---|
193 | FileInfo& fi3 = vec->at(0);
|
---|
194 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/file.material"), fi3.filename);
|
---|
195 | CPPUNIT_ASSERT_EQUAL(String("file.material"), fi3.basename);
|
---|
196 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/"), fi3.path);
|
---|
197 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi3.compressedSize);
|
---|
198 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi3.uncompressedSize);
|
---|
199 |
|
---|
200 | FileInfo& fi4 = vec->at(1);
|
---|
201 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/file2.material"), fi4.filename);
|
---|
202 | CPPUNIT_ASSERT_EQUAL(String("file2.material"), fi4.basename);
|
---|
203 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/"), fi4.path);
|
---|
204 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi4.compressedSize);
|
---|
205 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi4.uncompressedSize);
|
---|
206 |
|
---|
207 |
|
---|
208 | FileInfo& fi5 = vec->at(2);
|
---|
209 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/file3.material"), fi5.filename);
|
---|
210 | CPPUNIT_ASSERT_EQUAL(String("file3.material"), fi5.basename);
|
---|
211 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/"), fi5.path);
|
---|
212 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi5.compressedSize);
|
---|
213 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi5.uncompressedSize);
|
---|
214 |
|
---|
215 | FileInfo& fi6 = vec->at(3);
|
---|
216 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/file4.material"), fi6.filename);
|
---|
217 | CPPUNIT_ASSERT_EQUAL(String("file4.material"), fi6.basename);
|
---|
218 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/"), fi6.path);
|
---|
219 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi6.compressedSize);
|
---|
220 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi6.uncompressedSize);
|
---|
221 | }
|
---|
222 | void ZipArchiveTests::testFileRead()
|
---|
223 | {
|
---|
224 | ZipArchive arch(testPath, "Zip");
|
---|
225 | arch.load();
|
---|
226 |
|
---|
227 | DataStreamPtr stream = arch.open("rootfile.txt");
|
---|
228 | CPPUNIT_ASSERT_EQUAL(String("this is line 1 in file 1"), stream->getLine());
|
---|
229 | CPPUNIT_ASSERT_EQUAL(String("this is line 2 in file 1"), stream->getLine());
|
---|
230 | CPPUNIT_ASSERT_EQUAL(String("this is line 3 in file 1"), stream->getLine());
|
---|
231 | CPPUNIT_ASSERT_EQUAL(String("this is line 4 in file 1"), stream->getLine());
|
---|
232 | CPPUNIT_ASSERT_EQUAL(String("this is line 5 in file 1"), stream->getLine());
|
---|
233 | CPPUNIT_ASSERT(stream->eof());
|
---|
234 |
|
---|
235 | }
|
---|
236 | void ZipArchiveTests::testReadInterleave()
|
---|
237 | {
|
---|
238 | // Test overlapping reads from same archive
|
---|
239 |
|
---|
240 | ZipArchive arch(testPath, "Zip");
|
---|
241 | arch.load();
|
---|
242 |
|
---|
243 | // File 1
|
---|
244 | DataStreamPtr stream1 = arch.open("rootfile.txt");
|
---|
245 | CPPUNIT_ASSERT_EQUAL(String("this is line 1 in file 1"), stream1->getLine());
|
---|
246 | CPPUNIT_ASSERT_EQUAL(String("this is line 2 in file 1"), stream1->getLine());
|
---|
247 |
|
---|
248 | // File 2
|
---|
249 | DataStreamPtr stream2 = arch.open("rootfile2.txt");
|
---|
250 | CPPUNIT_ASSERT_EQUAL(String("this is line 1 in file 2"), stream2->getLine());
|
---|
251 | CPPUNIT_ASSERT_EQUAL(String("this is line 2 in file 2"), stream2->getLine());
|
---|
252 | CPPUNIT_ASSERT_EQUAL(String("this is line 3 in file 2"), stream2->getLine());
|
---|
253 |
|
---|
254 |
|
---|
255 | // File 1
|
---|
256 | CPPUNIT_ASSERT_EQUAL(String("this is line 3 in file 1"), stream1->getLine());
|
---|
257 | CPPUNIT_ASSERT_EQUAL(String("this is line 4 in file 1"), stream1->getLine());
|
---|
258 | CPPUNIT_ASSERT_EQUAL(String("this is line 5 in file 1"), stream1->getLine());
|
---|
259 | CPPUNIT_ASSERT(stream1->eof());
|
---|
260 |
|
---|
261 |
|
---|
262 | // File 2
|
---|
263 | CPPUNIT_ASSERT_EQUAL(String("this is line 4 in file 2"), stream2->getLine());
|
---|
264 | CPPUNIT_ASSERT_EQUAL(String("this is line 5 in file 2"), stream2->getLine());
|
---|
265 | CPPUNIT_ASSERT_EQUAL(String("this is line 6 in file 2"), stream2->getLine());
|
---|
266 | CPPUNIT_ASSERT(stream2->eof());
|
---|
267 |
|
---|
268 | }
|
---|