source: OGRE/trunk/ogrenew/Tests/OgreMain/src/FileSystemArchiveTests.cpp @ 692

Revision 692, 11.9 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

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