Commit fdcdf60e authored by hybrid's avatar hybrid

Add a test for proper file loading from archives, despite two files in the...

Add a test for proper file loading from archives, despite two files in the archive have the same name.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3536 dfc29bdd-3216-0410-991c-e03cc46cb475
parent ad14e9c0
...@@ -93,7 +93,7 @@ CMountPointReader::CMountPointReader(IFileSystem * parent, const io::path& basen ...@@ -93,7 +93,7 @@ CMountPointReader::CMountPointReader(IFileSystem * parent, const io::path& basen
if (Path.lastChar() != '/' ) if (Path.lastChar() != '/' )
Path.append('/'); Path.append('/');
const io::path work = Parent->getWorkingDirectory(); const io::path& work = Parent->getWorkingDirectory();
Parent->changeWorkingDirectoryTo(basename); Parent->changeWorkingDirectoryTo(basename);
buildDirectory(); buildDirectory();
......
...@@ -88,40 +88,50 @@ bool testArchive(IFileSystem* fs, const io::path& archiveName) ...@@ -88,40 +88,50 @@ bool testArchive(IFileSystem* fs, const io::path& archiveName)
return false; return false;
} }
filename="test/test.txt"; const char* names[] = {"test/test.txt", "mypath/myfile.txt", "mypath/mypath/myfile.txt"};
if (!fs->existFile(filename)) const char* basenames[] = {"test.txt", "myfile.txt", "myfile.txt"};
{ const char* content[] = {"Hello world!", "1est\n", "2est"};
logTestString("existFile failed\n");
while (fs->getFileArchiveCount())
fs->removeFileArchive(fs->getFileArchiveCount()-1);
return false;
}
IReadFile* readFile = fs->createAndOpenFile(filename); for (u32 i=0; i<3; ++i)
if ( !readFile )
{ {
logTestString("createAndOpenFile failed\n"); if (!fs->existFile(names[i]))
while (fs->getFileArchiveCount()) {
fs->removeFileArchive(fs->getFileArchiveCount()-1); logTestString("existFile failed\n");
return false; while (fs->getFileArchiveCount())
} fs->removeFileArchive(fs->getFileArchiveCount()-1);
return false;
}
if (fs->getFileBasename(readFile->getFileName()) != "test.txt") IReadFile* readFile = fs->createAndOpenFile(names[i]);
{ if (!readFile)
logTestString("Wrong filename, file list seems to be corrupt\n"); {
while (fs->getFileArchiveCount()) logTestString("createAndOpenFile failed\n");
fs->removeFileArchive(fs->getFileArchiveCount()-1); while (fs->getFileArchiveCount())
return false; fs->removeFileArchive(fs->getFileArchiveCount()-1);
} return false;
char tmp[13] = {'\0'}; }
readFile->read(tmp, 12);
if (strncmp(tmp, "Hello world!", 12)) if (fs->getFileBasename(readFile->getFileName()) != basenames[i])
{ {
logTestString("Read bad data from archive: %s\n", tmp); logTestString("Wrong filename, file list seems to be corrupt\n");
while (fs->getFileArchiveCount()) while (fs->getFileArchiveCount())
fs->removeFileArchive(fs->getFileArchiveCount()-1); fs->removeFileArchive(fs->getFileArchiveCount()-1);
return false; readFile->drop();
return false;
}
char tmp[13] = {'\0'};
readFile->read(tmp, 12);
if (strcmp(tmp, content[i]))
{
logTestString("Read bad data from archive: %s\n", tmp);
while (fs->getFileArchiveCount())
fs->removeFileArchive(fs->getFileArchiveCount()-1);
readFile->drop();
return false;
}
readFile->drop();
} }
if (!fs->removeFileArchive(fs->getFileArchiveCount()-1)) if (!fs->removeFileArchive(fs->getFileArchiveCount()-1))
{ {
logTestString("Couldn't remove archive.\n"); logTestString("Couldn't remove archive.\n");
...@@ -132,8 +142,6 @@ bool testArchive(IFileSystem* fs, const io::path& archiveName) ...@@ -132,8 +142,6 @@ bool testArchive(IFileSystem* fs, const io::path& archiveName)
if ( fs->getFileArchiveCount() ) if ( fs->getFileArchiveCount() )
return false; return false;
readFile->drop();
return true; return true;
} }
...@@ -230,6 +238,42 @@ bool testEncryptedZip(IFileSystem* fs) ...@@ -230,6 +238,42 @@ bool testEncryptedZip(IFileSystem* fs)
return true; return true;
} }
static bool testMountFile(IFileSystem* fs)
{
bool result = true;
#if 1
fs->changeWorkingDirectoryTo("empty");
// log what we got
const io::IFileList* fileList = fs->createFileList();
for ( u32 f=0; f < fileList->getFileCount(); ++f)
{
logTestString("File name: %s\n", fileList->getFileName(f).c_str());
logTestString("Full path: %s\n", fileList->getFullFileName(f).c_str());
logTestString("ID: %d\n", fileList->getID(f));
}
fileList->drop();
fs->changeWorkingDirectoryTo("..");
#endif
if (!fs->addFileArchive("empty"), false)
result = false;
const IFileList* list = fs->getFileArchive(0)->getFileList();
#if 1
// log what we got
io::IFileArchive* archive = fs->getFileArchive(fs->getFileArchiveCount()-1);
fileList = archive->getFileList();
for ( u32 f=0; f < fileList->getFileCount(); ++f)
{
logTestString("File name: %s\n", fileList->getFileName(f).c_str());
logTestString("Full path: %s\n", fileList->getFullFileName(f).c_str());
logTestString("ID: %d\n", fileList->getID(f));
}
#endif
if (list->getFileName(0) != "burnings video 0.39b.png")
result = false;
return result;
}
bool archiveReader() bool archiveReader()
{ {
IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2d<u32>(1, 1)); IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2d<u32>(1, 1));
...@@ -254,6 +298,8 @@ bool archiveReader() ...@@ -254,6 +298,8 @@ bool archiveReader()
ret &= testArchive(fs, "media/file_with_path.npk"); ret &= testArchive(fs, "media/file_with_path.npk");
logTestString("Testing encrypted zip files.\n"); logTestString("Testing encrypted zip files.\n");
ret &= testEncryptedZip(fs); ret &= testEncryptedZip(fs);
// logTestString("Testing complex mount file.\n");
// ret &= testMountFile(fs);
device->closeDevice(); device->closeDevice();
device->run(); device->run();
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#if defined(_MSC_VER) #if defined(_MSC_VER)
#define _CRT_SECURE_NO_WARNINGS 1 #define _CRT_SECURE_NO_WARNINGS 1
#define TESTING_ON_WINDOWS
#endif // _MSC_VER #endif // _MSC_VER
#include "testUtils.h" #include "testUtils.h"
......
Tests finished. 61 tests of 61 passed. Tests finished. 61 tests of 61 passed.
Compiled as DEBUG Compiled as DEBUG
Test suite pass at GMT Mon Jan 03 17:33:16 2011 Test suite pass at GMT Wed Jan 05 18:07:13 2011
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment