1 #include "testUtils.h"
\r
4 using namespace core;
\r
7 static bool testgetAbsoluteFilename(io::IFileSystem* fs)
\r
10 io::path apath = fs->getAbsolutePath("media");
\r
11 io::path cwd = fs->getWorkingDirectory();
\r
12 if (apath!=(cwd+"/media"))
\r
14 logTestString("getAbsolutePath failed on existing dir %s\n", apath.c_str());
\r
18 apath = fs->getAbsolutePath("../media/");
\r
19 core::deletePathFromPath(cwd, 1);
\r
20 if (apath!=(cwd+"media/"))
\r
22 logTestString("getAbsolutePath failed on dir with postfix / %s\n", apath.c_str());
\r
26 apath = fs->getAbsolutePath ("../nothere.txt"); // file does not exist
\r
27 if (apath!=(cwd+"nothere.txt"))
\r
29 logTestString("getAbsolutePath failed on non-existing file %s\n", apath.c_str());
\r
36 static bool testFlattenFilename(io::IFileSystem* fs)
\r
39 io::path tmpString="../tmp";
\r
40 io::path refString="../tmp/";
\r
41 fs->flattenFilename(tmpString);
\r
42 if (tmpString != refString)
\r
44 logTestString("flattening destroys path.\n%s!=%s\n", tmpString.c_str(),refString.c_str());
\r
48 tmpString="tmp/tmp/../";
\r
50 fs->flattenFilename(tmpString);
\r
51 if (tmpString != refString)
\r
53 logTestString("flattening destroys path.\n%s!=%s\n", tmpString.c_str(),refString.c_str());
\r
57 tmpString="tmp/tmp/..";
\r
58 fs->flattenFilename(tmpString);
\r
59 if (tmpString != refString)
\r
61 logTestString("flattening destroys path.\n%s!=%s\n", tmpString.c_str(),refString.c_str());
\r
65 tmpString="tmp/next/../third";
\r
66 refString="tmp/third/";
\r
67 fs->flattenFilename(tmpString);
\r
68 if (tmpString != refString)
\r
70 logTestString("flattening destroys path.\n%s!=%s\n", tmpString.c_str(),refString.c_str());
\r
74 tmpString="this/tmp/next/../../my/fourth";
\r
75 refString="this/my/fourth/";
\r
76 fs->flattenFilename(tmpString);
\r
77 if (tmpString != refString)
\r
79 logTestString("flattening destroys path.\n%s!=%s\n", tmpString.c_str(),refString.c_str());
\r
83 tmpString="this/is/../../../a/fifth/test/";
\r
84 refString="../a/fifth/test/";
\r
85 fs->flattenFilename(tmpString);
\r
86 if (tmpString != refString)
\r
88 logTestString("flattening destroys path.\n%s!=%s\n", tmpString.c_str(),refString.c_str());
\r
92 tmpString="this/../is/../../a/sixth/test/";
\r
93 refString="../a/sixth/test/";
\r
94 fs->flattenFilename(tmpString);
\r
95 if (tmpString != refString)
\r
97 logTestString("flattening destroys path.\n%s!=%s\n", tmpString.c_str(),refString.c_str());
\r
104 static bool testgetRelativeFilename(io::IFileSystem* fs)
\r
107 io::path apath = fs->getAbsolutePath("media");
\r
108 io::path cwd = fs->getWorkingDirectory();
\r
109 if (fs->getRelativeFilename(apath, cwd) != "media")
\r
111 logTestString("getRelativePath failed on %s\n", apath.c_str());
\r
115 apath = fs->getAbsolutePath("../media/");
\r
116 if (fs->getRelativeFilename(apath, cwd) != "../media/")
\r
118 logTestString("getRelativePath failed on %s\n", apath.c_str());
\r
125 bool filesystem(void)
\r
127 IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2d<u32>(1, 1));
\r
128 assert_log(device);
\r
132 io::IFileSystem * fs = device->getFileSystem ();
\r
136 bool result = true;
\r
138 io::path workingDir = device->getFileSystem()->getWorkingDirectory();
\r
141 if ( fs->existFile(empty) )
\r
143 logTestString("Empty filename should not exist.\n");
\r
147 io::path newWd = workingDir + "/media";
\r
148 bool changed = device->getFileSystem()->changeWorkingDirectoryTo(newWd);
\r
149 assert_log(changed);
\r
151 if ( fs->existFile(empty) )
\r
153 logTestString("Empty filename should not exist even in another workingdirectory.\n");
\r
157 // The working directory must be restored for the other tests to work.
\r
158 changed = device->getFileSystem()->changeWorkingDirectoryTo(workingDir.c_str());
\r
159 assert_log(changed);
\r
161 // adding a folder archive which just should not really change anything
\r
162 device->getFileSystem()->addFileArchive( "./" );
\r
164 if ( fs->existFile(empty) )
\r
166 logTestString("Empty filename should not exist in folder file archive.\n");
\r
170 // remove it again to not affect other tests
\r
171 device->getFileSystem()->removeFileArchive( device->getFileSystem()->getFileArchiveCount() );
\r
173 result &= testFlattenFilename(fs);
\r
174 result &= testgetAbsoluteFilename(fs);
\r
175 result &= testgetRelativeFilename(fs);
\r
177 device->closeDevice();
\r