X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fmisc%2Fpath_test.cxx;h=fb9c4dae0903596639d962eb0583189ce031bd20;hb=5c4696a28af5ea701af4a22a5ab1ed423a661427;hp=bfe8754612e3ba47815f8e45ad6ccf3ea24d7336;hpb=8fb26c9a005c35fb2a04afec73e289d565c43ce7;p=simgear.git diff --git a/simgear/misc/path_test.cxx b/simgear/misc/path_test.cxx index bfe87546..fb9c4dae 100644 --- a/simgear/misc/path_test.cxx +++ b/simgear/misc/path_test.cxx @@ -9,20 +9,10 @@ using std::cout; using std::cerr; using std::endl; -#define COMPARE(a, b) \ - if ((a) != (b)) { \ - cerr << "failed:" << #a << " != " << #b << endl; \ - exit(1); \ - } - -#define VERIFY(a) \ - if (!(a)) { \ - cerr << "failed:" << #a << endl; \ - exit(1); \ - } - +#include #include #include +#include void test_dir() { @@ -81,6 +71,69 @@ SGPath::Permissions validateWrite(const SGPath&) return p; } +void test_path_dir() +{ + simgear::Dir temp = simgear::Dir::tempDir("path_dir"); + temp.remove(true); + SGPath p = temp.path(); + + VERIFY(p.isAbsolute()); + COMPARE(p.create_dir(0755), 0); + + SGPath sub = p / "subA" / "subB"; + VERIFY(!sub.exists()); + + SGPath subFile = sub / "fileABC.txt"; + COMPARE(subFile.create_dir(0755), 0); + VERIFY(!subFile.exists()); + + sub.set_cached(false); + VERIFY(sub.exists()); + VERIFY(sub.isDir()); + + SGPath sub2 = p / "subA" / "fileA"; + { + sg_ofstream os(sub2); + VERIFY(os.is_open()); + for (int i = 0; i < 50; ++i) { + os << "ABCD" << endl; + } + } + VERIFY(sub2.isFile()); + COMPARE(sub2.sizeInBytes(), 250); + + SGPath sub3 = p / "subß" / "file𝕽"; + sub3.create_dir(0755); + + { + sg_ofstream os(sub3); + VERIFY(os.is_open()); + for (int i = 0; i < 20; ++i) { + os << "EFGH" << endl; + } + } + + sub3.set_cached(false); + VERIFY(sub3.exists()); + COMPARE(sub3.sizeInBytes(), 100); + COMPARE(sub3.file(), "file𝕽"); + + simgear::Dir subD(p / "subA"); + simgear::PathList dirChildren = subD.children(simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT); + COMPARE(dirChildren.size(), 1); + COMPARE(dirChildren[0], subD.path() / "subB"); + + simgear::PathList fileChildren = subD.children(simgear::Dir::TYPE_FILE | simgear::Dir::NO_DOT_OR_DOTDOT); + COMPARE(fileChildren.size(), 1); + COMPARE(fileChildren[0], subD.path() / "fileA"); + + simgear::Dir subS(sub3.dirPath()); + fileChildren = subS.children(simgear::Dir::TYPE_FILE | simgear::Dir::NO_DOT_OR_DOTDOT); + COMPARE(fileChildren.size(), 1); + COMPARE(fileChildren[0], subS.path() / "file𝕽"); + +} + int main(int argc, char* argv[]) { SGPath pa; @@ -197,6 +250,8 @@ int main(int argc, char* argv[]) test_dir(); + test_path_dir(); + cout << "all tests passed OK" << endl; return 0; // passed }