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 | // Regsiter the suite
|
---|
29 | CPPUNIT_TEST_SUITE_REGISTRATION( ZipArchiveTests );
|
---|
30 |
|
---|
31 | void ZipArchiveTests::setUp()
|
---|
32 | {
|
---|
33 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
34 | testPath = "../../../../Tests/OgreMain/misc/ArchiveTest.zip";
|
---|
35 | #else
|
---|
36 | testPath = "../../../Tests/OgreMain/misc/ArchiveTest.zip";
|
---|
37 | #endif
|
---|
38 | }
|
---|
39 | void ZipArchiveTests::tearDown()
|
---|
40 | {
|
---|
41 | }
|
---|
42 |
|
---|
43 | void ZipArchiveTests::testListNonRecursive()
|
---|
44 | {
|
---|
45 | ZipArchive arch(testPath, "Zip");
|
---|
46 | arch.load();
|
---|
47 | StringVectorPtr vec = arch.list(false);
|
---|
48 |
|
---|
49 | CPPUNIT_ASSERT_EQUAL((size_t)2, vec->size());
|
---|
50 | CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), vec->at(0));
|
---|
51 | CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), vec->at(1));
|
---|
52 |
|
---|
53 | }
|
---|
54 | void ZipArchiveTests::testListRecursive()
|
---|
55 | {
|
---|
56 | ZipArchive arch(testPath, "Zip");
|
---|
57 | arch.load();
|
---|
58 | StringVectorPtr vec = arch.list(true);
|
---|
59 |
|
---|
60 | CPPUNIT_ASSERT_EQUAL((size_t)6, vec->size());
|
---|
61 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/file.material"), vec->at(0));
|
---|
62 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/file2.material"), vec->at(1));
|
---|
63 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/file3.material"), vec->at(2));
|
---|
64 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/file4.material"), vec->at(3));
|
---|
65 | CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), vec->at(4));
|
---|
66 | CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), vec->at(5));
|
---|
67 | }
|
---|
68 | void ZipArchiveTests::testListFileInfoNonRecursive()
|
---|
69 | {
|
---|
70 | ZipArchive arch(testPath, "Zip");
|
---|
71 | arch.load();
|
---|
72 | FileInfoListPtr vec = arch.listFileInfo(false);
|
---|
73 |
|
---|
74 | CPPUNIT_ASSERT_EQUAL((size_t)2, vec->size());
|
---|
75 | FileInfo& fi1 = vec->at(0);
|
---|
76 | CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), fi1.filename);
|
---|
77 | CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), fi1.basename);
|
---|
78 | CPPUNIT_ASSERT_EQUAL(StringUtil::BLANK, fi1.path);
|
---|
79 | CPPUNIT_ASSERT_EQUAL((size_t)40, fi1.compressedSize);
|
---|
80 | CPPUNIT_ASSERT_EQUAL((size_t)130, fi1.uncompressedSize);
|
---|
81 |
|
---|
82 | FileInfo& fi2 = vec->at(1);
|
---|
83 | CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), fi2.filename);
|
---|
84 | CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), fi2.basename);
|
---|
85 | CPPUNIT_ASSERT_EQUAL(StringUtil::BLANK, fi2.path);
|
---|
86 | CPPUNIT_ASSERT_EQUAL((size_t)45, fi2.compressedSize);
|
---|
87 | CPPUNIT_ASSERT_EQUAL((size_t)156, fi2.uncompressedSize);
|
---|
88 | }
|
---|
89 | void ZipArchiveTests::testListFileInfoRecursive()
|
---|
90 | {
|
---|
91 | ZipArchive arch(testPath, "Zip");
|
---|
92 | arch.load();
|
---|
93 | FileInfoListPtr vec = arch.listFileInfo(true);
|
---|
94 |
|
---|
95 | CPPUNIT_ASSERT_EQUAL((size_t)6, vec->size());
|
---|
96 | FileInfo& fi3 = vec->at(0);
|
---|
97 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/file.material"), fi3.filename);
|
---|
98 | CPPUNIT_ASSERT_EQUAL(String("file.material"), fi3.basename);
|
---|
99 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/"), fi3.path);
|
---|
100 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi3.compressedSize);
|
---|
101 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi3.uncompressedSize);
|
---|
102 |
|
---|
103 | FileInfo& fi4 = vec->at(1);
|
---|
104 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/file2.material"), fi4.filename);
|
---|
105 | CPPUNIT_ASSERT_EQUAL(String("file2.material"), fi4.basename);
|
---|
106 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/"), fi4.path);
|
---|
107 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi4.compressedSize);
|
---|
108 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi4.uncompressedSize);
|
---|
109 |
|
---|
110 |
|
---|
111 | FileInfo& fi5 = vec->at(2);
|
---|
112 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/file3.material"), fi5.filename);
|
---|
113 | CPPUNIT_ASSERT_EQUAL(String("file3.material"), fi5.basename);
|
---|
114 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/"), fi5.path);
|
---|
115 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi5.compressedSize);
|
---|
116 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi5.uncompressedSize);
|
---|
117 |
|
---|
118 | FileInfo& fi6 = vec->at(3);
|
---|
119 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/file4.material"), fi6.filename);
|
---|
120 | CPPUNIT_ASSERT_EQUAL(String("file4.material"), fi6.basename);
|
---|
121 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/"), fi6.path);
|
---|
122 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi6.compressedSize);
|
---|
123 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi6.uncompressedSize);
|
---|
124 |
|
---|
125 | FileInfo& fi1 = vec->at(4);
|
---|
126 | CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), fi1.filename);
|
---|
127 | CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), fi1.basename);
|
---|
128 | CPPUNIT_ASSERT_EQUAL(StringUtil::BLANK, fi1.path);
|
---|
129 | CPPUNIT_ASSERT_EQUAL((size_t)40, fi1.compressedSize);
|
---|
130 | CPPUNIT_ASSERT_EQUAL((size_t)130, fi1.uncompressedSize);
|
---|
131 |
|
---|
132 | FileInfo& fi2 = vec->at(5);
|
---|
133 | CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), fi2.filename);
|
---|
134 | CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), fi2.basename);
|
---|
135 | CPPUNIT_ASSERT_EQUAL(StringUtil::BLANK, fi2.path);
|
---|
136 | CPPUNIT_ASSERT_EQUAL((size_t)45, fi2.compressedSize);
|
---|
137 | CPPUNIT_ASSERT_EQUAL((size_t)156, fi2.uncompressedSize);
|
---|
138 |
|
---|
139 | }
|
---|
140 | void ZipArchiveTests::testFindNonRecursive()
|
---|
141 | {
|
---|
142 | ZipArchive arch(testPath, "Zip");
|
---|
143 | arch.load();
|
---|
144 | StringVectorPtr vec = arch.find("*.txt", false);
|
---|
145 |
|
---|
146 | CPPUNIT_ASSERT_EQUAL((size_t)2, vec->size());
|
---|
147 | CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), vec->at(0));
|
---|
148 | CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), vec->at(1));
|
---|
149 | }
|
---|
150 | void ZipArchiveTests::testFindRecursive()
|
---|
151 | {
|
---|
152 | ZipArchive arch(testPath, "Zip");
|
---|
153 | arch.load();
|
---|
154 | StringVectorPtr vec = arch.find("*.material", true);
|
---|
155 |
|
---|
156 | CPPUNIT_ASSERT_EQUAL((size_t)4, vec->size());
|
---|
157 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/file.material"), vec->at(0));
|
---|
158 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/file2.material"), vec->at(1));
|
---|
159 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/file3.material"), vec->at(2));
|
---|
160 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/file4.material"), vec->at(3));
|
---|
161 | }
|
---|
162 | void ZipArchiveTests::testFindFileInfoNonRecursive()
|
---|
163 | {
|
---|
164 | ZipArchive arch(testPath, "Zip");
|
---|
165 | arch.load();
|
---|
166 | FileInfoListPtr vec = arch.findFileInfo("*.txt", false);
|
---|
167 |
|
---|
168 | CPPUNIT_ASSERT_EQUAL((size_t)2, vec->size());
|
---|
169 | FileInfo& fi1 = vec->at(0);
|
---|
170 | CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), fi1.filename);
|
---|
171 | CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), fi1.basename);
|
---|
172 | CPPUNIT_ASSERT_EQUAL(StringUtil::BLANK, fi1.path);
|
---|
173 | CPPUNIT_ASSERT_EQUAL((size_t)40, fi1.compressedSize);
|
---|
174 | CPPUNIT_ASSERT_EQUAL((size_t)130, fi1.uncompressedSize);
|
---|
175 |
|
---|
176 | FileInfo& fi2 = vec->at(1);
|
---|
177 | CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), fi2.filename);
|
---|
178 | CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), fi2.basename);
|
---|
179 | CPPUNIT_ASSERT_EQUAL(StringUtil::BLANK, fi2.path);
|
---|
180 | CPPUNIT_ASSERT_EQUAL((size_t)45, fi2.compressedSize);
|
---|
181 | CPPUNIT_ASSERT_EQUAL((size_t)156, fi2.uncompressedSize);
|
---|
182 | }
|
---|
183 | void ZipArchiveTests::testFindFileInfoRecursive()
|
---|
184 | {
|
---|
185 | ZipArchive arch(testPath, "Zip");
|
---|
186 | arch.load();
|
---|
187 | FileInfoListPtr vec = arch.findFileInfo("*.material", true);
|
---|
188 |
|
---|
189 | CPPUNIT_ASSERT_EQUAL((size_t)4, vec->size());
|
---|
190 |
|
---|
191 | FileInfo& fi3 = vec->at(0);
|
---|
192 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/file.material"), fi3.filename);
|
---|
193 | CPPUNIT_ASSERT_EQUAL(String("file.material"), fi3.basename);
|
---|
194 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/"), fi3.path);
|
---|
195 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi3.compressedSize);
|
---|
196 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi3.uncompressedSize);
|
---|
197 |
|
---|
198 | FileInfo& fi4 = vec->at(1);
|
---|
199 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/file2.material"), fi4.filename);
|
---|
200 | CPPUNIT_ASSERT_EQUAL(String("file2.material"), fi4.basename);
|
---|
201 | CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/"), fi4.path);
|
---|
202 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi4.compressedSize);
|
---|
203 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi4.uncompressedSize);
|
---|
204 |
|
---|
205 |
|
---|
206 | FileInfo& fi5 = vec->at(2);
|
---|
207 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/file3.material"), fi5.filename);
|
---|
208 | CPPUNIT_ASSERT_EQUAL(String("file3.material"), fi5.basename);
|
---|
209 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/"), fi5.path);
|
---|
210 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi5.compressedSize);
|
---|
211 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi5.uncompressedSize);
|
---|
212 |
|
---|
213 | FileInfo& fi6 = vec->at(3);
|
---|
214 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/file4.material"), fi6.filename);
|
---|
215 | CPPUNIT_ASSERT_EQUAL(String("file4.material"), fi6.basename);
|
---|
216 | CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/"), fi6.path);
|
---|
217 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi6.compressedSize);
|
---|
218 | CPPUNIT_ASSERT_EQUAL((size_t)0, fi6.uncompressedSize);
|
---|
219 | }
|
---|
220 | void ZipArchiveTests::testFileRead()
|
---|
221 | {
|
---|
222 | ZipArchive arch(testPath, "Zip");
|
---|
223 | arch.load();
|
---|
224 |
|
---|
225 | DataStreamPtr stream = arch.open("rootfile.txt");
|
---|
226 | CPPUNIT_ASSERT_EQUAL(String("this is line 1 in file 1"), stream->getLine());
|
---|
227 | CPPUNIT_ASSERT_EQUAL(String("this is line 2 in file 1"), stream->getLine());
|
---|
228 | CPPUNIT_ASSERT_EQUAL(String("this is line 3 in file 1"), stream->getLine());
|
---|
229 | CPPUNIT_ASSERT_EQUAL(String("this is line 4 in file 1"), stream->getLine());
|
---|
230 | CPPUNIT_ASSERT_EQUAL(String("this is line 5 in file 1"), stream->getLine());
|
---|
231 | CPPUNIT_ASSERT(stream->eof());
|
---|
232 |
|
---|
233 | }
|
---|
234 | void ZipArchiveTests::testReadInterleave()
|
---|
235 | {
|
---|
236 | // Test overlapping reads from same archive
|
---|
237 |
|
---|
238 | ZipArchive arch(testPath, "Zip");
|
---|
239 | arch.load();
|
---|
240 |
|
---|
241 | // File 1
|
---|
242 | DataStreamPtr stream1 = arch.open("rootfile.txt");
|
---|
243 | CPPUNIT_ASSERT_EQUAL(String("this is line 1 in file 1"), stream1->getLine());
|
---|
244 | CPPUNIT_ASSERT_EQUAL(String("this is line 2 in file 1"), stream1->getLine());
|
---|
245 |
|
---|
246 | // File 2
|
---|
247 | DataStreamPtr stream2 = arch.open("rootfile2.txt");
|
---|
248 | CPPUNIT_ASSERT_EQUAL(String("this is line 1 in file 2"), stream2->getLine());
|
---|
249 | CPPUNIT_ASSERT_EQUAL(String("this is line 2 in file 2"), stream2->getLine());
|
---|
250 | CPPUNIT_ASSERT_EQUAL(String("this is line 3 in file 2"), stream2->getLine());
|
---|
251 |
|
---|
252 |
|
---|
253 | // File 1
|
---|
254 | CPPUNIT_ASSERT_EQUAL(String("this is line 3 in file 1"), stream1->getLine());
|
---|
255 | CPPUNIT_ASSERT_EQUAL(String("this is line 4 in file 1"), stream1->getLine());
|
---|
256 | CPPUNIT_ASSERT_EQUAL(String("this is line 5 in file 1"), stream1->getLine());
|
---|
257 | CPPUNIT_ASSERT(stream1->eof());
|
---|
258 |
|
---|
259 |
|
---|
260 | // File 2
|
---|
261 | CPPUNIT_ASSERT_EQUAL(String("this is line 4 in file 2"), stream2->getLine());
|
---|
262 | CPPUNIT_ASSERT_EQUAL(String("this is line 5 in file 2"), stream2->getLine());
|
---|
263 | CPPUNIT_ASSERT_EQUAL(String("this is line 6 in file 2"), stream2->getLine());
|
---|
264 | CPPUNIT_ASSERT(stream2->eof());
|
---|
265 |
|
---|
266 | }
|
---|