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
if (Path.lastChar() != '/' )
Path.append('/');
const io::path work = Parent->getWorkingDirectory();
const io::path& work = Parent->getWorkingDirectory();
Parent->changeWorkingDirectoryTo(basename);
buildDirectory();
......
......@@ -88,40 +88,50 @@ bool testArchive(IFileSystem* fs, const io::path& archiveName)
return false;
}
filename="test/test.txt";
if (!fs->existFile(filename))
{
logTestString("existFile failed\n");
while (fs->getFileArchiveCount())
fs->removeFileArchive(fs->getFileArchiveCount()-1);
return false;
}
const char* names[] = {"test/test.txt", "mypath/myfile.txt", "mypath/mypath/myfile.txt"};
const char* basenames[] = {"test.txt", "myfile.txt", "myfile.txt"};
const char* content[] = {"Hello world!", "1est\n", "2est"};
IReadFile* readFile = fs->createAndOpenFile(filename);
if ( !readFile )
for (u32 i=0; i<3; ++i)
{
logTestString("createAndOpenFile failed\n");
while (fs->getFileArchiveCount())
fs->removeFileArchive(fs->getFileArchiveCount()-1);
return false;
}
if (!fs->existFile(names[i]))
{
logTestString("existFile failed\n");
while (fs->getFileArchiveCount())
fs->removeFileArchive(fs->getFileArchiveCount()-1);
return false;
}
if (fs->getFileBasename(readFile->getFileName()) != "test.txt")
{
logTestString("Wrong filename, file list seems to be corrupt\n");
while (fs->getFileArchiveCount())
fs->removeFileArchive(fs->getFileArchiveCount()-1);
return false;
}
char tmp[13] = {'\0'};
readFile->read(tmp, 12);
if (strncmp(tmp, "Hello world!", 12))
{
logTestString("Read bad data from archive: %s\n", tmp);
while (fs->getFileArchiveCount())
fs->removeFileArchive(fs->getFileArchiveCount()-1);
return false;
IReadFile* readFile = fs->createAndOpenFile(names[i]);
if (!readFile)
{
logTestString("createAndOpenFile failed\n");
while (fs->getFileArchiveCount())
fs->removeFileArchive(fs->getFileArchiveCount()-1);
return false;
}
if (fs->getFileBasename(readFile->getFileName()) != basenames[i])
{
logTestString("Wrong filename, file list seems to be corrupt\n");
while (fs->getFileArchiveCount())
fs->removeFileArchive(fs->getFileArchiveCount()-1);
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))
{
logTestString("Couldn't remove archive.\n");
......@@ -132,8 +142,6 @@ bool testArchive(IFileSystem* fs, const io::path& archiveName)
if ( fs->getFileArchiveCount() )
return false;
readFile->drop();
return true;
}
......@@ -230,6 +238,42 @@ bool testEncryptedZip(IFileSystem* fs)
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()
{
IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2d<u32>(1, 1));
......@@ -254,6 +298,8 @@ bool archiveReader()
ret &= testArchive(fs, "media/file_with_path.npk");
logTestString("Testing encrypted zip files.\n");
ret &= testEncryptedZip(fs);
// logTestString("Testing complex mount file.\n");
// ret &= testMountFile(fs);
device->closeDevice();
device->run();
......
......@@ -3,6 +3,7 @@
#if defined(_MSC_VER)
#define _CRT_SECURE_NO_WARNINGS 1
#define TESTING_ON_WINDOWS
#endif // _MSC_VER
#include "testUtils.h"
......
Tests finished. 61 tests of 61 passed.
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