diff options
Diffstat (limited to 'src/unittest/test_filepath.cpp')
-rw-r--r-- | src/unittest/test_filepath.cpp | 117 |
1 files changed, 62 insertions, 55 deletions
diff --git a/src/unittest/test_filepath.cpp b/src/unittest/test_filepath.cpp index dea290ab6..ac2d69b5a 100644 --- a/src/unittest/test_filepath.cpp +++ b/src/unittest/test_filepath.cpp @@ -26,8 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "nodedef.h" #include "noise.h" -class TestFilePath : public TestBase -{ +class TestFilePath : public TestBase { public: TestFilePath() { TestManager::registerTestModule(this); } const char *getName() { return "TestFilePath"; } @@ -66,14 +65,15 @@ std::string p(std::string path) } } -#ifdef _WIN32 + #ifdef _WIN32 if (path[0] == '\\') path = "C:" + path; -#endif + #endif return path; } + void TestFilePath::testIsDirDelimiter() { UASSERT(fs::IsDirDelimiter('/') == true); @@ -86,22 +86,23 @@ void TestFilePath::testIsDirDelimiter() #endif } + void TestFilePath::testPathStartsWith() { const int numpaths = 12; std::string paths[numpaths] = { - "", - p("/"), - p("/home/user/minetest"), - p("/home/user/minetest/bin"), - p("/home/user/.minetest"), - p("/tmp/dir/file"), - p("/tmp/file/"), - p("/tmP/file"), - p("/tmp"), - p("/tmp/dir"), - p("/home/user2/minetest/worlds"), - p("/home/user2/minetest/world"), + "", + p("/"), + p("/home/user/minetest"), + p("/home/user/minetest/bin"), + p("/home/user/.minetest"), + p("/tmp/dir/file"), + p("/tmp/file/"), + p("/tmP/file"), + p("/tmp"), + p("/tmp/dir"), + p("/home/user2/minetest/worlds"), + p("/home/user2/minetest/world"), }; /* expected fs::PathStartsWith results @@ -113,51 +114,55 @@ void TestFilePath::testPathStartsWith() FILESYS_CASE_INSENSITIVE is true */ int expected_results[numpaths][numpaths] = { - {1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0}, - {1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0}, - {1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0}, - {1, 1, 0, 0, 0, 0, 1, 4, 1, 0, 0, 0}, - {1, 1, 0, 0, 0, 0, 4, 1, 4, 0, 0, 0}, - {1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0}, - {1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0}, - {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, - {1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, + {1,2,0,0,0,0,0,0,0,0,0,0}, + {1,1,0,0,0,0,0,0,0,0,0,0}, + {1,1,1,0,0,0,0,0,0,0,0,0}, + {1,1,1,1,0,0,0,0,0,0,0,0}, + {1,1,0,0,1,0,0,0,0,0,0,0}, + {1,1,0,0,0,1,0,0,1,1,0,0}, + {1,1,0,0,0,0,1,4,1,0,0,0}, + {1,1,0,0,0,0,4,1,4,0,0,0}, + {1,1,0,0,0,0,0,0,1,0,0,0}, + {1,1,0,0,0,0,0,0,1,1,0,0}, + {1,1,0,0,0,0,0,0,0,0,1,0}, + {1,1,0,0,0,0,0,0,0,0,0,1}, }; for (int i = 0; i < numpaths; i++) - for (int j = 0; j < numpaths; j++) { - /*verbosestream<<"testing fs::PathStartsWith(\"" - <<paths[i]<<"\", \"" - <<paths[j]<<"\")"<<std::endl;*/ - bool starts = fs::PathStartsWith(paths[i], paths[j]); - int expected = expected_results[i][j]; - if (expected == 0) { - UASSERT(starts == false); - } else if (expected == 1) { - UASSERT(starts == true); - } -#ifdef _WIN32 - else if (expected == 2) { - UASSERT(starts == false); - } else if (expected == 3) { - UASSERT(starts == true); - } -#else - else if (expected == 2) { - UASSERT(starts == true); - } else if (expected == 3) { - UASSERT(starts == false); - } -#endif - else if (expected == 4) { - UASSERT(starts == (bool)FILESYS_CASE_INSENSITIVE); - } + for (int j = 0; j < numpaths; j++){ + /*verbosestream<<"testing fs::PathStartsWith(\"" + <<paths[i]<<"\", \"" + <<paths[j]<<"\")"<<std::endl;*/ + bool starts = fs::PathStartsWith(paths[i], paths[j]); + int expected = expected_results[i][j]; + if(expected == 0){ + UASSERT(starts == false); + } + else if(expected == 1){ + UASSERT(starts == true); } + #ifdef _WIN32 + else if(expected == 2){ + UASSERT(starts == false); + } + else if(expected == 3){ + UASSERT(starts == true); + } + #else + else if(expected == 2){ + UASSERT(starts == true); + } + else if(expected == 3){ + UASSERT(starts == false); + } + #endif + else if(expected == 4){ + UASSERT(starts == (bool)FILESYS_CASE_INSENSITIVE); + } + } } + void TestFilePath::testRemoveLastPathComponent() { std::string path, result, removed; @@ -194,6 +199,7 @@ void TestFilePath::testRemoveLastPathComponent() UASSERT(removed == p("home/user/minetest/bin/../worlds/world1")); } + void TestFilePath::testRemoveLastPathComponentWithTrailingDelimiter() { std::string path, result, removed; @@ -229,6 +235,7 @@ void TestFilePath::testRemoveLastPathComponentWithTrailingDelimiter() UASSERT(removed == p("home/user/minetest/bin/../worlds/world1")); } + void TestFilePath::testRemoveRelativePathComponent() { std::string path, result, removed; |