1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2026-03-02 04:09:18 +00:00

added unit tests of uuid_mountpoint_factory

This commit is contained in:
Falk Werner
2020-02-16 17:33:11 +01:00
parent 096c244445
commit 2b91f159cf
7 changed files with 148 additions and 41 deletions

View File

@@ -1,46 +1,16 @@
#include <gtest/gtest.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "tempdir.hpp"
#include "file_utils.hpp"
#include "webfuse_adapter.h"
#include "webfuse/adapter/impl/uuid_mountpoint.h"
#include <string>
using webfuse_test::TempDir;
namespace
{
bool is_dir(std::string const & path)
{
struct stat info;
int rc = stat(path.c_str(), &info);
return (0 == rc) && (S_ISDIR(info.st_mode));
}
bool is_symlink(std::string const & path)
{
struct stat info;
int rc = lstat(path.c_str(), &info);
return (0 == rc) && (S_ISLNK(info.st_mode));
}
bool is_same_path(std::string const & path, std::string const & other)
{
struct stat info;
int rc = stat(path.c_str(), &info);
struct stat info_other;
int rc_other = stat(other.c_str(), &info_other);
return (0 == rc) && (0 == rc_other) && (info.st_ino == info_other.st_ino);
}
}
using webfuse_test::is_dir;
using webfuse_test::is_symlink;
using webfuse_test::is_same_path;
TEST(uuid_mountpoint, create)
{

View File

@@ -0,0 +1,60 @@
#include <gtest/gtest.h>
#include "webfuse_adapter.h"
#include "webfuse/adapter/impl/uuid_mountpoint_factory.h"
#include "tempdir.hpp"
#include "file_utils.hpp"
using webfuse_test::TempDir;
using webfuse_test::is_dir;
TEST(uuid_mountpoint_factory, create_existing_dir)
{
TempDir temp("uuid_mountpoint_factory");
void * factory = wf_impl_uuid_mountpoint_factory_create(temp.path());
ASSERT_NE(nullptr, factory);
ASSERT_TRUE(is_dir(temp.path()));
wf_mountpoint * mountpoint = wf_impl_uuid_mountpoint_factory_create_mountpoint("dummy", factory);
std::string path = wf_mountpoint_get_path(mountpoint);
ASSERT_NE(nullptr, factory);
ASSERT_TRUE(is_dir(path));
wf_mountpoint_dispose(mountpoint);
ASSERT_FALSE(is_dir(path));
wf_impl_uuid_mountpoint_factory_dispose(factory);
// keep dir not created by factory
ASSERT_TRUE(is_dir(temp.path()));
}
TEST(uuid_mountpoint_factory, create_nonexisting_dir)
{
TempDir temp("uuid_mountpoint_factory");
std::string root_path = std::string(temp.path()) + "/root";
void * factory = wf_impl_uuid_mountpoint_factory_create(root_path.c_str());
ASSERT_NE(nullptr, factory);
ASSERT_TRUE(is_dir(root_path));
wf_mountpoint * mountpoint = wf_impl_uuid_mountpoint_factory_create_mountpoint("dummy", factory);
std::string path = wf_mountpoint_get_path(mountpoint);
ASSERT_NE(nullptr, factory);
ASSERT_TRUE(is_dir(path));
wf_mountpoint_dispose(mountpoint);
ASSERT_FALSE(is_dir(path));
wf_impl_uuid_mountpoint_factory_dispose(factory);
// remove dir, created by factory
ASSERT_FALSE(is_dir(root_path));
}
TEST(uuid_mountpoint_factory, fail_to_created_nested_dir)
{
TempDir temp("uuid_mountpoint_factory");
std::string root_path = std::string(temp.path()) + "/nested/root";
void * factory = wf_impl_uuid_mountpoint_factory_create(root_path.c_str());
ASSERT_EQ(nullptr, factory);
}

38
test/file_utils.cc Normal file
View File

@@ -0,0 +1,38 @@
#include "file_utils.hpp"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
namespace webfuse_test
{
bool is_dir(std::string const & path)
{
struct stat info;
int rc = stat(path.c_str(), &info);
return (0 == rc) && (S_ISDIR(info.st_mode));
}
bool is_symlink(std::string const & path)
{
struct stat info;
int rc = lstat(path.c_str(), &info);
return (0 == rc) && (S_ISLNK(info.st_mode));
}
bool is_same_path(std::string const & path, std::string const & other)
{
struct stat info;
int rc = stat(path.c_str(), &info);
struct stat info_other;
int rc_other = stat(other.c_str(), &info_other);
return (0 == rc) && (0 == rc_other) && (info.st_ino == info_other.st_ino);
}
}

17
test/file_utils.hpp Normal file
View File

@@ -0,0 +1,17 @@
#ifndef WF_TEST_FILE_UTILS_HPP
#define WF_TEST_FILE_UTILS_HPP
#include <string>
namespace webfuse_test
{
bool is_dir(std::string const & path);
bool is_symlink(std::string const & path);
bool is_same_path(std::string const & path, std::string const & other);
}
#endif