diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-02-15 20:23:07 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-02-15 20:23:07 +0000 |
commit | 9ff154ff10db6fc499c7e120b7744bbae139adad (patch) | |
tree | 980fd1bc76f95fd02848db30822744a7ca1d8ec9 | |
parent | Test statfs on missing file (diff) | |
download | netfs-9ff154ff10db6fc499c7e120b7744bbae139adad.tar.bz2 netfs-9ff154ff10db6fc499c7e120b7744bbae139adad.tar.xz netfs-9ff154ff10db6fc499c7e120b7744bbae139adad.zip |
Test file behaviour
-rw-r--r-- | netfs/unittests/testCore.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index 083cbab..2f1c512 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -184,6 +184,63 @@ BOOST_AUTO_TEST_CASE( directories ) BOOST_REQUIRE_EQUAL(fuse->opendir("/test", &fi), -ENOENT); } +BOOST_AUTO_TEST_CASE( files ) +{ + struct fuse_file_info fi; + memset(&fi, 0, sizeof(fi)); + struct stat st, st2; + memset(&st, 0, sizeof(st)); + memset(&st2, 0, sizeof(st2)); + fi.flags = O_RDWR; + BOOST_REQUIRE_EQUAL(fuse->create("/test", 0600, &fi), 0); + BOOST_REQUIRE_EQUAL(fuse->release("/test", &fi), 0); + BOOST_REQUIRE_EQUAL(fuse->release("/test", &fi), -EBADF); + BOOST_REQUIRE_EQUAL(fuse->create("/test", 0600, &fi), -EEXIST); + + BOOST_REQUIRE_EQUAL(fuse->open("/test", &fi), 0); + BOOST_REQUIRE_EQUAL(fuse->write("/test", "some test buffer", 16, 0, &fi), 16); + BOOST_REQUIRE_EQUAL(fuse->getattr("/test", &st), 0); + BOOST_REQUIRE_EQUAL(st.st_size, 16); + BOOST_REQUIRE_EQUAL(fuse->getattr("/test2", &st), -ENOENT); + BOOST_REQUIRE_EQUAL(fuse->rename("/test", "/test2"), 0); + BOOST_REQUIRE_EQUAL(fuse->getattr("/test", &st), -ENOENT); + BOOST_REQUIRE_EQUAL(fuse->getattr("/test2", &st2), 0); + BOOST_REQUIRE_EQUAL(st, st2); + BOOST_REQUIRE_EQUAL(fuse->fgetattr("/test2", &st2, &fi), 0); + BOOST_REQUIRE_EQUAL(st, st2); + BOOST_REQUIRE_EQUAL(st2.st_size, 16); + BOOST_REQUIRE_EQUAL(fuse->write("/test2", "BUFFER some", 11, 10, &fi), 11); + BOOST_REQUIRE_EQUAL(fuse->fgetattr("/test2", &st2, &fi), 0); + BOOST_REQUIRE_EQUAL(st2.st_size, 21); + char buf[11]; + memset(&buf, 0, sizeof(buf)); + BOOST_REQUIRE_EQUAL(fuse->read("/test2", buf, 10, 5, &fi), 10); + BOOST_REQUIRE_EQUAL(buf, "test BUFFE"); + BOOST_REQUIRE_EQUAL(fuse->ftruncate("/test2", 11, &fi), 0); + BOOST_REQUIRE_EQUAL(fuse->fgetattr("/test2", &st2, &fi), 0); + BOOST_REQUIRE_EQUAL(st2.st_size, 11); + memset(&buf, 0, sizeof(buf)); + BOOST_REQUIRE_EQUAL(fuse->read("/test2", buf, 10, 5, &fi), 6); + BOOST_REQUIRE_EQUAL(buf, "test B"); + BOOST_REQUIRE_EQUAL(fuse->truncate("/test2", 7), 0); + BOOST_REQUIRE_EQUAL(fuse->fgetattr("/test2", &st2, &fi), 0); + BOOST_REQUIRE_EQUAL(st2.st_size, 7); + memset(&buf, 0, sizeof(buf)); + BOOST_REQUIRE_EQUAL(fuse->read("/test2", buf, 10, 5, &fi), 2); + BOOST_REQUIRE_EQUAL(buf, "te"); + BOOST_REQUIRE_EQUAL(fuse->release("/test2", &fi), 0); + + BOOST_REQUIRE_EQUAL(fuse->link("/test3", "/test2"), -ENOENT); + BOOST_REQUIRE_EQUAL(fuse->link("/test2", "/test3"), 0); + BOOST_REQUIRE_EQUAL(fuse->getattr("/test2", &st), 0); + BOOST_REQUIRE_EQUAL(fuse->getattr("/test3", &st2), 0); + BOOST_REQUIRE_EQUAL(st, st2); + BOOST_REQUIRE_EQUAL(fuse->unlink("/test2"), 0); + BOOST_REQUIRE_EQUAL(fuse->unlink("/test2"), -ENOENT); + BOOST_REQUIRE_EQUAL(fuse->unlink("/test3"), 0); + BOOST_REQUIRE_EQUAL(fuse->unlink("/test3"), -ENOENT); +} + BOOST_AUTO_TEST_SUITE_END(); BOOST_AUTO_TEST_CASE( testNoAuthNoPass ) |