Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/Tests/OgreMain/src/FileSystemArchiveTests.cpp @ 1

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