7
bool testArchive(IFileSystem* fs, const io::path& archiveName)
9
// make sure there is no archive mounted
10
if ( fs->getFileArchiveCount() )
12
logTestString("Already mounted archives found\n");
16
if ( !fs->addFileArchive(archiveName, /*bool ignoreCase=*/true, /*bool ignorePaths=*/false) )
18
logTestString("Mounting archive failed\n");
22
// make sure there is an archive mounted
23
if ( !fs->getFileArchiveCount() )
25
logTestString("Mounted archive not in list\n");
30
if ( !fs->addFileArchive(archiveName, /*bool ignoreCase=*/true, /*bool ignorePaths=*/false) )
32
logTestString("Mounting a second time failed\n");
33
fs->removeFileArchive(fs->getFileArchiveCount()-1);
37
// make sure there is exactly one archive mounted
38
if ( fs->getFileArchiveCount() != 1 )
40
logTestString("Duplicate mount not recognized\n");
41
while (fs->getFileArchiveCount())
42
fs->removeFileArchive(fs->getFileArchiveCount()-1);
45
if (fs->getFileArchive(0)->getType()==io::EFAT_FOLDER)
47
// mount again with different path end symbol (either with slash or without)
48
core::stringc newArchiveName=archiveName;
49
if (archiveName.lastChar()=='/')
50
newArchiveName.erase(newArchiveName.size()-1);
52
newArchiveName.append('/');
53
if ( !fs->addFileArchive(newArchiveName, /*bool ignoreCase=*/true, /*bool ignorePaths=*/false) )
55
logTestString("Mounting a second time with different name failed\n");
56
fs->removeFileArchive(fs->getFileArchiveCount()-1);
60
// make sure there is exactly one archive mounted
61
if ( fs->getFileArchiveCount() != 1 )
63
logTestString("Duplicate mount with different filename not recognized\n");
64
while (fs->getFileArchiveCount())
65
fs->removeFileArchive(fs->getFileArchiveCount()-1);
72
io::IFileArchive* archive = fs->getFileArchive(fs->getFileArchiveCount()-1);
73
const io::IFileList* fileList = archive->getFileList();
74
for ( u32 f=0; f < fileList->getFileCount(); ++f)
76
logTestString("File name: %s\n", fileList->getFileName(f).c_str());
77
logTestString("Full path: %s\n", fileList->getFullFileName(f).c_str());
78
logTestString("ID: %d\n", fileList->getID(f));
82
io::path filename("mypath/mypath/myfile.txt");
83
if (!fs->existFile(filename))
85
logTestString("existFile with deep path failed\n");
86
while (fs->getFileArchiveCount())
87
fs->removeFileArchive(fs->getFileArchiveCount()-1);
91
const char* names[] = {"test/test.txt", "mypath/myfile.txt", "mypath/mypath/myfile.txt"};
92
const char* basenames[] = {"test.txt", "myfile.txt", "myfile.txt"};
93
const char* content[] = {"Hello world!", "1est\n", "2est"};
95
for (u32 i=0; i<3; ++i)
97
if (!fs->existFile(names[i]))
99
logTestString("existFile failed\n");
100
while (fs->getFileArchiveCount())
101
fs->removeFileArchive(fs->getFileArchiveCount()-1);
105
IReadFile* readFile = fs->createAndOpenFile(names[i]);
108
logTestString("createAndOpenFile failed\n");
109
while (fs->getFileArchiveCount())
110
fs->removeFileArchive(fs->getFileArchiveCount()-1);
114
if (fs->getFileBasename(readFile->getFileName()) != basenames[i])
116
logTestString("Wrong filename, file list seems to be corrupt\n");
117
while (fs->getFileArchiveCount())
118
fs->removeFileArchive(fs->getFileArchiveCount()-1);
122
char tmp[13] = {'\0'};
123
readFile->read(tmp, 12);
124
if (strcmp(tmp, content[i]))
126
logTestString("Read bad data from archive: %s\n", tmp);
127
while (fs->getFileArchiveCount())
128
fs->removeFileArchive(fs->getFileArchiveCount()-1);
135
if (!fs->removeFileArchive(fs->getFileArchiveCount()-1))
137
logTestString("Couldn't remove archive.\n");
141
// make sure there is no archive mounted
142
if ( fs->getFileArchiveCount() )
148
bool testEncryptedZip(IFileSystem* fs)
150
// make sure there is no archive mounted
151
if ( fs->getFileArchiveCount() )
153
logTestString("Already mounted archives found\n");
157
const char* archiveName = "media/enc.zip";
158
if ( !fs->addFileArchive(archiveName, /*bool ignoreCase=*/true, /*bool ignorePaths=*/false) )
160
logTestString("Mounting archive failed\n");
164
// make sure there is an archive mounted
165
if ( !fs->getFileArchiveCount() )
167
logTestString("Mounted archive not in list\n");
172
if ( !fs->addFileArchive(archiveName, /*bool ignoreCase=*/true, /*bool ignorePaths=*/false) )
174
logTestString("Mounting a second time failed\n");
175
fs->removeFileArchive(fs->getFileArchiveCount()-1);
179
// make sure there is exactly one archive mounted
180
if ( fs->getFileArchiveCount() != 1 )
182
logTestString("Duplicate mount not recognized\n");
183
while (fs->getFileArchiveCount())
184
fs->removeFileArchive(fs->getFileArchiveCount()-1);
189
io::IFileArchive* archive = fs->getFileArchive(fs->getFileArchiveCount()-1);
190
io::path filename("doc");
191
const io::IFileList* fileList = archive->getFileList();
192
for ( u32 f=0; f < fileList->getFileCount(); ++f)
194
logTestString("%s name: %s\n", fileList->isDirectory(f)?"Directory":"File", fileList->getFileName(f).c_str());
195
logTestString("Full path: %s\n", fileList->getFullFileName(f).c_str());
197
if (fileList->findFile(filename) != -1)
199
logTestString("findFile wrongly succeeded on directory\n");
200
fs->removeFileArchive(fs->getFileArchiveCount()-1);
203
if (fileList->findFile(filename, true)==-1)
205
logTestString("findFile failed on directory\n");
206
fs->removeFileArchive(fs->getFileArchiveCount()-1);
210
filename="doc/readme.txt";
211
if (fileList->findFile(filename)==-1)
213
logTestString("findFile failed\n");
214
fs->removeFileArchive(fs->getFileArchiveCount()-1);
217
if (fileList->findFile(filename, true) != -1)
219
logTestString("findFile wrongly succeeded on non-directory\n");
220
fs->removeFileArchive(fs->getFileArchiveCount()-1);
224
if (!fs->existFile(filename))
226
logTestString("existFile failed\n");
227
fs->removeFileArchive(fs->getFileArchiveCount()-1);
232
if (fs->existFile(filename))
234
logTestString("existFile succeeded wrongly on directory\n");
235
fs->removeFileArchive(fs->getFileArchiveCount()-1);
239
filename="doc/readme.txt";
240
IReadFile* readFile = fs->createAndOpenFile(filename);
243
logTestString("createAndOpenFile succeeded, even though no password was set.\n");
245
fs->removeFileArchive(fs->getFileArchiveCount()-1);
249
archive->Password="33445";
250
readFile = fs->createAndOpenFile(filename);
251
#ifdef _IRR_COMPILE_WITH_ZIP_ENCRYPTION_
254
logTestString("createAndOpenFile failed\n");
255
fs->removeFileArchive(fs->getFileArchiveCount()-1);
259
char tmp[13] = {'\0'};
260
readFile->read(tmp, 12);
261
if (strncmp(tmp, "Linux Users:", 12))
263
logTestString("Read bad data from archive: %s\n", tmp);
268
if (!fs->removeFileArchive(fs->getFileArchiveCount()-1))
270
logTestString("Couldn't remove archive.\n");
274
// make sure there is no archive mounted
275
if ( fs->getFileArchiveCount() )
283
bool testSpecialZip(IFileSystem* fs)
285
// make sure there is no archive mounted
286
if ( fs->getFileArchiveCount() )
288
logTestString("Already mounted archives found\n");
292
const char* archiveName = "media/Monty.zip";
293
if ( !fs->addFileArchive(archiveName, /*bool ignoreCase=*/true, /*bool ignorePaths=*/false) )
295
logTestString("Mounting archive failed\n");
299
// make sure there is an archive mounted
300
if ( !fs->getFileArchiveCount() )
302
logTestString("Mounted archive not in list\n");
307
io::IFileArchive* archive = fs->getFileArchive(fs->getFileArchiveCount()-1);
308
const io::IFileList* fileList = archive->getFileList();
309
for ( u32 f=0; f < fileList->getFileCount(); ++f)
311
logTestString("%s name: %s\n", fileList->isDirectory(f)?"Directory":"File", fileList->getFileName(f).c_str());
312
logTestString("Full path: %s\n", fileList->getFullFileName(f).c_str());
315
io::path filename("monty/license.txt");
316
if (!fs->existFile(filename))
318
logTestString("existFile failed\n");
319
fs->removeFileArchive(fs->getFileArchiveCount()-1);
323
IReadFile* readFile = fs->createAndOpenFile(filename);
326
logTestString("createAndOpenFile failed\n");
327
fs->removeFileArchive(fs->getFileArchiveCount()-1);
331
char tmp[6] = {'\0'};
332
readFile->read(tmp, 5);
333
if (strcmp(tmp, "Monty"))
335
logTestString("Read bad data from archive: %s\n", tmp);
337
fs->removeFileArchive(fs->getFileArchiveCount()-1);
343
if (!fs->removeFileArchive(fs->getFileArchiveCount()-1))
345
logTestString("Couldn't remove archive.\n");
349
// make sure there is no archive mounted
350
if ( fs->getFileArchiveCount() )
356
static bool testMountFile(IFileSystem* fs)
360
fs->changeWorkingDirectoryTo("empty");
362
const io::IFileList* fileList = fs->createFileList();
363
for ( u32 f=0; f < fileList->getFileCount(); ++f)
365
logTestString("File name: %s\n", fileList->getFileName(f).c_str());
366
logTestString("Full path: %s\n", fileList->getFullFileName(f).c_str());
367
logTestString("ID: %d\n", fileList->getID(f));
370
fs->changeWorkingDirectoryTo("..");
372
if (!fs->addFileArchive("empty"), false)
374
const IFileList* list = fs->getFileArchive(0)->getFileList();
377
io::IFileArchive* archive = fs->getFileArchive(fs->getFileArchiveCount()-1);
378
fileList = archive->getFileList();
379
for ( u32 f=0; f < fileList->getFileCount(); ++f)
381
logTestString("File name: %s\n", fileList->getFileName(f).c_str());
382
logTestString("Full path: %s\n", fileList->getFullFileName(f).c_str());
383
logTestString("ID: %d\n", fileList->getID(f));
387
if (list->getFileName(0) != "burnings video 0.39b.png")
394
IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2d<u32>(1, 1));
399
io::IFileSystem * fs = device->getFileSystem ();
404
logTestString("Testing mount file.\n");
405
ret &= testArchive(fs, "media/file_with_path");
406
logTestString("Testing mount file.\n");
407
ret &= testArchive(fs, "media/file_with_path/");
408
logTestString("Testing zip files.\n");
409
ret &= testArchive(fs, "media/file_with_path.zip");
410
logTestString("Testing pak files.\n");
411
ret &= testArchive(fs, "media/sample_pakfile.pak");
412
logTestString("Testing npk files.\n");
413
ret &= testArchive(fs, "media/file_with_path.npk");
414
logTestString("Testing encrypted zip files.\n");
415
ret &= testEncryptedZip(fs);
416
logTestString("Testing special zip files.\n");
417
ret &= testSpecialZip(fs);
418
// logTestString("Testing complex mount file.\n");
419
// ret &= testMountFile(fs);
421
device->closeDevice();