]> git.localhorst.tv Git - blobs.git/commitdiff
extended filesystem test
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 18 Dec 2017 10:01:27 +0000 (11:01 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 18 Dec 2017 10:01:27 +0000 (11:01 +0100)
src/io/filesystem.cpp
tst/io/FilesystemTest.cpp

index feb1cac7d0bcc2ef7a0aab77b28312e155249470..c916e15427aca02ccbbb4042c5e4f34050ce60ed 100644 (file)
@@ -186,6 +186,9 @@ bool remove_dir(const std::string &path) {
 #else
 
        DIR *dir = opendir(path.c_str());
+       if (!dir) {
+               return errno == ENOENT;
+       }
        for (dirent *entry = readdir(dir); entry != nullptr; entry = readdir(dir)) {
                if (
                        strncmp(entry->d_name, ".", 2) == 0 ||
index a098c2bf30cfa8841d03503fa39f9e1992252701..d19cfd1a92ad318941bce7c2e57cd1106f32c767 100644 (file)
@@ -82,8 +82,8 @@ void FilesystemTest::testDirectory() {
        const string test_file = test_subsubdir + "\\c.txt";
 #else
        const string test_subdir = test_dir + "/a";
-       const string test_subsubdir = test_subdir + "/b";
-       const string test_file = test_subsubdir + "/c";
+       const string test_subsubdir = test_subdir + "/b/";
+       const string test_file = test_subsubdir + "c";
 #endif
 
        CPPUNIT_ASSERT_MESSAGE(
@@ -116,6 +116,9 @@ void FilesystemTest::testDirectory() {
        CPPUNIT_ASSERT_MESSAGE(
                "failed to create test subdirs",
                make_dirs(test_subsubdir));
+       CPPUNIT_ASSERT_MESSAGE(
+               "creating an existing dir should silently succeed",
+               make_dirs(test_subsubdir));
        CPPUNIT_ASSERT_MESSAGE(
                "created directory is a file",
                !is_file(test_subdir));
@@ -136,10 +139,13 @@ void FilesystemTest::testDirectory() {
        CPPUNIT_ASSERT_MESSAGE(
                "failed to create test file",
                is_file(test_file));
+       CPPUNIT_ASSERT_MESSAGE(
+               "creating a dir where a regular file is should fail",
+               !make_dirs(test_file));
 
        CPPUNIT_ASSERT_MESSAGE(
-               "failed to remove test subdir",
-               remove_dir(test_subdir));
+               "failed to remove test dir",
+               remove_dir(test_dir));
        CPPUNIT_ASSERT_MESSAGE(
                "removed directory became a file",
                !is_file(test_subdir));