summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-02-14 20:17:37 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2016-02-14 20:17:37 +0000
commitaefcd5dcdcbc9a265b54a331b212f269769c61cd (patch)
tree1c46969d86b18ffdb1fc915774141b32417ee594
parentSingle instance of testExport path (diff)
downloadnetfs-aefcd5dcdcbc9a265b54a331b212f269769c61cd.tar.bz2
netfs-aefcd5dcdcbc9a265b54a331b212f269769c61cd.tar.xz
netfs-aefcd5dcdcbc9a265b54a331b212f269769c61cd.zip
Almost complete coverage of basic directory operations
-rw-r--r--netfs/daemon/daemonDirectory.cpp4
-rw-r--r--netfs/unittests/testCore.cpp54
2 files changed, 58 insertions, 0 deletions
diff --git a/netfs/daemon/daemonDirectory.cpp b/netfs/daemon/daemonDirectory.cpp
index 86b595f..8c6c344 100644
--- a/netfs/daemon/daemonDirectory.cpp
+++ b/netfs/daemon/daemonDirectory.cpp
@@ -20,7 +20,9 @@ DirectoryServer::close(const Ice::Current & ice)
{
errno = 0;
if (::closedir(od) != 0) {
+ // LCOV_EXCL_START
throw NetFS::SystemError(errno);
+ // LCOV_EXCL_STOP
}
ice.adapter->remove(ice.id);
}
@@ -32,7 +34,9 @@ DirectoryServer::readdir(const Ice::Current&)
NetFS::NameList list;
while (dirent * d = ::readdir(od)) {
if (errno) {
+ // LCOV_EXCL_START
throw NetFS::SystemError(errno);
+ // LCOV_EXCL_STOP
}
list.push_back(d->d_name);
}
diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp
index 6f8eb57..9610111 100644
--- a/netfs/unittests/testCore.cpp
+++ b/netfs/unittests/testCore.cpp
@@ -5,6 +5,7 @@
#include <definedDirs.h>
#include <boost/filesystem/path.hpp>
#include <ostream>
+#include <algorithm>
const auto testExport = stringbf("testExport-%d", getpid());
const std::string testEndpoint("tcp -h localhost -p 12012");
@@ -131,6 +132,59 @@ BOOST_AUTO_TEST_CASE( testSandboxing )
BOOST_REQUIRE(boost::filesystem::exists(binDir / testExport / "inside"));
}
+int
+nameListAdd(void *buf, const char *name, const struct stat *, off_t)
+{
+ static_cast<NetFS::NameList *>(buf)->push_back(name);
+ return 0;
+}
+
+BOOST_AUTO_TEST_CASE( directories )
+{
+ struct fuse_file_info fi;
+ memset(&fi, 0, sizeof(fi));
+ struct stat st;
+ memset(&st, 0, sizeof(st));
+ BOOST_REQUIRE_EQUAL(fuse->mkdir("/test", 0700), 0);
+ BOOST_REQUIRE(boost::filesystem::is_directory(binDir / testExport / "test"));
+ BOOST_REQUIRE_EQUAL(fuse->mkdir("/test", 0700), -EEXIST);
+ BOOST_REQUIRE_EQUAL(fuse->getattr("/test", &st), 0);
+
+ BOOST_REQUIRE_EQUAL(fuse->opendir("/test", &fi), 0);
+ NetFS::NameList nl;
+ BOOST_REQUIRE_EQUAL(fuse->readdir("/test", &nl, &nameListAdd, 0, &fi), 0);
+ BOOST_REQUIRE_EQUAL(nl.size(), 2);
+ std::sort(nl.begin(), nl.end());
+ BOOST_REQUIRE_EQUAL(nl[0], ".");
+ BOOST_REQUIRE_EQUAL(nl[1], "..");
+ BOOST_REQUIRE_EQUAL(fuse->getattr("/test/.", &st), 0);
+ BOOST_REQUIRE_EQUAL(fuse->getattr("/test/..", &st), 0);
+ BOOST_REQUIRE_EQUAL(fuse->releasedir("/test", &fi), 0);
+ nl.clear();
+
+ BOOST_REQUIRE_EQUAL(fuse->mkdir("/test/sub", 0700), 0);
+ BOOST_REQUIRE_EQUAL(fuse->opendir("/test", &fi), 0);
+ BOOST_REQUIRE_EQUAL(fuse->readdir("/test", &nl, &nameListAdd, 0, &fi), 0);
+ BOOST_REQUIRE_EQUAL(nl.size(), 3);
+ std::sort(nl.begin(), nl.end());
+ BOOST_REQUIRE_EQUAL(nl[0], ".");
+ BOOST_REQUIRE_EQUAL(nl[1], "..");
+ BOOST_REQUIRE_EQUAL(nl[2], "sub");
+ BOOST_REQUIRE_EQUAL(fuse->releasedir("/test", &fi), 0);
+ nl.clear();
+
+ BOOST_REQUIRE_EQUAL(fuse->readdir("/test", &nl, &nameListAdd, 0, &fi), -EBADF);
+ BOOST_REQUIRE_EQUAL(fuse->releasedir("/test", &fi), -EBADF);
+
+ BOOST_REQUIRE_EQUAL(fuse->rmdir("/test"), -ENOTEMPTY);
+ BOOST_REQUIRE_EQUAL(fuse->rmdir("/test/sub"), 0);
+ BOOST_REQUIRE_EQUAL(fuse->rmdir("/test"), 0);
+ BOOST_REQUIRE(!boost::filesystem::is_directory(binDir / testExport / "test"));
+ BOOST_REQUIRE_EQUAL(fuse->rmdir("/test"), -ENOENT);
+ BOOST_REQUIRE_EQUAL(fuse->getattr("/test", &st), -ENOENT);
+ BOOST_REQUIRE_EQUAL(fuse->opendir("/test", &fi), -ENOENT);
+}
+
BOOST_AUTO_TEST_SUITE_END();
BOOST_AUTO_TEST_CASE( testNoAuthNoPass )