From 4c25da8a7ba7437657c3e2da592145113d3532f4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 20 Jul 2019 10:53:14 +0100 Subject: Initial commit Not a lot of stuff, hard coded paths, tests against /usr/portage --- unittests/Jamfile.jam | 29 +++++++++++++++++++++ unittests/core.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ unittests/mockDefs.cpp | 26 +++++++++++++++++++ unittests/mockDefs.h | 31 +++++++++++++++++++++++ 4 files changed, 155 insertions(+) create mode 100644 unittests/Jamfile.jam create mode 100644 unittests/core.cpp create mode 100644 unittests/mockDefs.cpp create mode 100644 unittests/mockDefs.h (limited to 'unittests') diff --git a/unittests/Jamfile.jam b/unittests/Jamfile.jam new file mode 100644 index 0000000..9de6ea6 --- /dev/null +++ b/unittests/Jamfile.jam @@ -0,0 +1,29 @@ +import testing ; + +lib boost_utf : : boost_unit_test_framework ; +lib dryice : : : : ..//icetray ; + +path-constant me : . ; + +lib common : + mockDefs.cpp + : + dryice + ../src//gitfs + ..//adhocutil + boost_utf + ROOT=\"$(me)\" + : : + dryice + ../src//gitfs + boost_utf + ROOT=\"$(me)\" + BOOST_TEST_DYN_LINK + ; + + +run core.cpp : : : + ../src//gitfs + common + ; + diff --git a/unittests/core.cpp b/unittests/core.cpp new file mode 100644 index 0000000..9b38dfe --- /dev/null +++ b/unittests/core.cpp @@ -0,0 +1,69 @@ +#define BOOST_TEST_MODULE GitFS_Core +#include + +#include "mockDefs.h" +#include "sys/stat.h" + +using namespace GitFS; +using namespace GitFS::Test; + +BOOST_TEST_GLOBAL_FIXTURE(Service); + +BOOST_FIXTURE_TEST_SUITE(client, Client) + + // TODO + +BOOST_AUTO_TEST_SUITE_END(); + +BOOST_FIXTURE_TEST_SUITE(volume, VolumeClient) + +BOOST_AUTO_TEST_CASE( access ) +{ + // Noting is writable + // Directories are all readable and executable + + BOOST_CHECK_EQUAL(EINVAL, v->access(env, "", R_OK)); + + BOOST_CHECK_EQUAL(0, v->access(env, "/", R_OK)); + BOOST_CHECK_EQUAL(EACCES, v->access(env, "/", W_OK)); + BOOST_CHECK_EQUAL(0, v->access(env, "/", X_OK)); + + BOOST_CHECK_EQUAL(0, v->access(env, "/metadata", R_OK)); + BOOST_CHECK_EQUAL(EACCES, v->access(env, "/metadata", W_OK)); + BOOST_CHECK_EQUAL(0, v->access(env, "/metadata", X_OK)); + + BOOST_CHECK_EQUAL(0, v->access(env, "/metadata/timestamp.chk", R_OK)); + BOOST_CHECK_EQUAL(EACCES, v->access(env, "/metadata/timestamp.chk", W_OK)); + BOOST_CHECK_EQUAL(EACCES, v->access(env, "/metadata/timestamp.chk", X_OK)); + + BOOST_CHECK_EQUAL(0, v->access(env, "/app-antivirus/skyldav/files/skyldav.initd", R_OK)); + BOOST_CHECK_EQUAL(EACCES, v->access(env, "/app-antivirus/skyldav/files/skyldav.initd", W_OK)); + BOOST_CHECK_EQUAL(0, v->access(env, "/app-antivirus/skyldav/files/skyldav.initd", X_OK)); + + BOOST_CHECK_EQUAL(ENOENT, v->access(env, "/missing", R_OK)); + BOOST_CHECK_EQUAL(EACCES, v->access(env, "/missing", W_OK)); + BOOST_CHECK_EQUAL(ENOENT, v->access(env, "/missing", X_OK)); + + BOOST_CHECK_EQUAL(ENOENT, v->access(env, "/.", R_OK)); + BOOST_CHECK_EQUAL(ENOENT, v->access(env, "/../", R_OK)); + BOOST_CHECK_EQUAL(ENOENT, v->access(env, ".", R_OK)); + BOOST_CHECK_EQUAL(ENOENT, v->access(env, "..", R_OK)); + BOOST_CHECK_EQUAL(ENOENT, v->access(env, "../", R_OK)); +} + +BOOST_AUTO_TEST_CASE( statRoot ) +{ + //auto a = v->getattr(env, "/"); + //BOOST_CHECK_EQUAL(0170555, a.mode); + //BOOST_CHECK_EQUAL(1563566842, a.mtime); + //BOOST_CHECK_EQUAL(1563566842, a.ctime); + //BOOST_CHECK_EQUAL(1563566842, a.atime); +} + +BOOST_AUTO_TEST_CASE(stat_root) +{ + auto attr = v->getattr(env, ""); +} + +BOOST_AUTO_TEST_SUITE_END(); + diff --git a/unittests/mockDefs.cpp b/unittests/mockDefs.cpp new file mode 100644 index 0000000..78ad270 --- /dev/null +++ b/unittests/mockDefs.cpp @@ -0,0 +1,26 @@ +#include +#include "mockDefs.h" + +GitFS::Test::Service::Service() +{ +} + +GitFS::Test::Client::Client() : + s(getProxy("Service")) +{ + BOOST_TEST_REQUIRE(s); + s->ice_ping(); +} + +GitFS::Test::VolumeClient::VolumeClient() : + v(s->connect("testrepo", "testauth")) +{ + BOOST_TEST_REQUIRE(v); + v->ice_ping(); +} + +GitFS::Test::VolumeClient::~VolumeClient() +{ + v->disconnect(); +} + diff --git a/unittests/mockDefs.h b/unittests/mockDefs.h new file mode 100644 index 0000000..f6a6c99 --- /dev/null +++ b/unittests/mockDefs.h @@ -0,0 +1,31 @@ +#ifndef GITFS_TEST_MOCKDEFS_H +#define GITFS_TEST_MOCKDEFS_H + +#include +#include +#include + +namespace GitFS::Test { + class DLL_PUBLIC Service : public IceTray::DryIce { + public: + Service(); + }; + + class DLL_PUBLIC Client : public IceTray::DryIceClient { + public: + Client(); + + const NetFS::ServicePrxPtr s; + }; + class DLL_PUBLIC VolumeClient : public Client { + public: + VolumeClient(); + ~VolumeClient(); + + const NetFS::ReqEnv env; + const NetFS::VolumePrxPtr v; + }; +} + +#endif + -- cgit v1.2.3