mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
simplified test structure
This commit is contained in:
99
test/webfuse_provider/provider/operation/test_close.cc
Normal file
99
test/webfuse_provider/provider/operation/test_close.cc
Normal file
@@ -0,0 +1,99 @@
|
||||
#include "webfuse_provider/impl/operation/close.h"
|
||||
#include "webfuse_provider/mocks/mock_provider.hpp"
|
||||
#include "webfuse_provider/mocks/fake_invokation_context.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using ::webfuse_test::MockProvider;
|
||||
using ::webfuse_test::create_context;
|
||||
using ::testing::_;
|
||||
|
||||
TEST(wfp_close, close)
|
||||
{
|
||||
int inode = 42;
|
||||
int handle = 0xdeadbeef;
|
||||
int flags = 23;
|
||||
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider, close(inode, handle, flags)).Times(1);
|
||||
|
||||
wfp_impl_invokation_context context = create_context(provider);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_integer(inode));
|
||||
json_array_append_new(params, json_integer(handle));
|
||||
json_array_append_new(params, json_integer(flags));
|
||||
|
||||
wfp_impl_close(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_close, close_fail_invalid_param_count)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider, close(_,_,_)).Times(0);
|
||||
|
||||
wfp_impl_invokation_context context = create_context(provider);
|
||||
|
||||
json_t * params = json_array();
|
||||
wfp_impl_close(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_close, close_fail_inode_invalid_type)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider, close(_,_,_)).Times(0);
|
||||
|
||||
wfp_impl_invokation_context context = create_context(provider);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_string("42"));
|
||||
json_array_append_new(params, json_integer(0));
|
||||
json_array_append_new(params, json_integer(0));
|
||||
|
||||
wfp_impl_close(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_close, close_fail_handle_invalid_type)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider, close(_,_,_)).Times(0);
|
||||
|
||||
wfp_impl_invokation_context context = create_context(provider);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_integer(0));
|
||||
json_array_append_new(params, json_string("42"));
|
||||
json_array_append_new(params, json_integer(0));
|
||||
|
||||
wfp_impl_close(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_close, close_fail_flags_invalid_type)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider, close(_,_,_)).Times(0);
|
||||
|
||||
wfp_impl_invokation_context context = create_context(provider);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_integer(0));
|
||||
json_array_append_new(params, json_integer(0));
|
||||
json_array_append_new(params, json_string("42"));
|
||||
|
||||
wfp_impl_close(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
|
||||
TEST(wfp_close, default_nop)
|
||||
{
|
||||
wfp_impl_close_default(0, 0, 0, nullptr);
|
||||
}
|
||||
107
test/webfuse_provider/provider/operation/test_getattr.cc
Normal file
107
test/webfuse_provider/provider/operation/test_getattr.cc
Normal file
@@ -0,0 +1,107 @@
|
||||
#include "webfuse_provider/impl/operation/getattr.h"
|
||||
#include "webfuse_provider/mocks/mock_request.hpp"
|
||||
#include "webfuse_provider/mocks/mock_provider.hpp"
|
||||
#include "webfuse_provider/mocks/fake_invokation_context.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstdlib>
|
||||
|
||||
using ::webfuse_test::MockProvider;
|
||||
using ::webfuse_test::MockRequest;
|
||||
using ::webfuse_test::StatMatcher;
|
||||
using ::webfuse_test::create_context;
|
||||
using ::testing::_;
|
||||
using ::testing::Invoke;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void free_request(wfp_request * request, ino_t)
|
||||
{
|
||||
free(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(wfp_impl_getattr, default_responds_error)
|
||||
{
|
||||
MockRequest request;
|
||||
auto * req = request.create_request(42);
|
||||
EXPECT_CALL(request, respond_error(_,42)).Times(1);
|
||||
|
||||
wfp_impl_getattr_default(req, 0, nullptr);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_getattr, respond_file)
|
||||
{
|
||||
MockRequest request;
|
||||
auto * req = request.create_request(42);
|
||||
EXPECT_CALL(request, respond(StatMatcher(23, 0754, "file"), 42)).Times(1);
|
||||
|
||||
struct stat buffer;
|
||||
memset(&buffer, 0, sizeof(buffer));
|
||||
buffer.st_ino = 23;
|
||||
buffer.st_mode = S_IFREG | 0754;
|
||||
wfp_impl_respond_getattr(req, &buffer);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_getattr, respond_dir)
|
||||
{
|
||||
MockRequest request;
|
||||
auto * req = request.create_request(42);
|
||||
EXPECT_CALL(request, respond(StatMatcher(23, 0754, "dir"), 42)).Times(1);
|
||||
|
||||
struct stat buffer;
|
||||
memset(&buffer, 0, sizeof(buffer));
|
||||
buffer.st_ino = 23;
|
||||
buffer.st_mode = S_IFDIR | 0754;
|
||||
wfp_impl_respond_getattr(req, &buffer);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_getattr, invoke_provider)
|
||||
{
|
||||
ino_t inode = 23;
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider,getattr(_, inode)).Times(1).WillOnce(Invoke(free_request));
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_integer(inode));
|
||||
|
||||
wfp_impl_getattr(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_getattr, fail_invalid_param_count)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider,getattr(_, _)).Times(0);
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
|
||||
wfp_impl_getattr(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_getattr, fail_invalid_inode_type)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider,getattr(_, _)).Times(0);
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_string("42"));
|
||||
|
||||
wfp_impl_getattr(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
129
test/webfuse_provider/provider/operation/test_lookup.cc
Normal file
129
test/webfuse_provider/provider/operation/test_lookup.cc
Normal file
@@ -0,0 +1,129 @@
|
||||
#include "webfuse_provider/impl/operation/lookup.h"
|
||||
#include "webfuse_provider/mocks/mock_request.hpp"
|
||||
#include "webfuse_provider/mocks/mock_provider.hpp"
|
||||
#include "webfuse_provider/mocks/fake_invokation_context.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstdlib>
|
||||
|
||||
using ::webfuse_test::MockProvider;
|
||||
using ::webfuse_test::MockRequest;
|
||||
using ::webfuse_test::StatMatcher;
|
||||
using ::webfuse_test::create_context;
|
||||
using ::testing::_;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::StrEq;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void free_request(wfp_request * request, ino_t, char const *)
|
||||
{
|
||||
free(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(wfp_impl_lookup, invoke_provider)
|
||||
{
|
||||
ino_t inode = 42;
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider,lookup(_, inode,StrEq("some.file"))).Times(1)
|
||||
.WillOnce(Invoke(free_request));
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_integer(inode));
|
||||
json_array_append_new(params, json_string("some.file"));
|
||||
|
||||
wfp_impl_lookup(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_lookup, fail_invalid_param_count)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider,lookup(_, _,_)).Times(0);
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_integer(23));
|
||||
|
||||
wfp_impl_lookup(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_lookup, fail_invalid_inode_type)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider,lookup(_, _,_)).Times(0);
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_string("23"));
|
||||
json_array_append_new(params, json_string("some.file"));
|
||||
|
||||
wfp_impl_lookup(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_lookup, fail_invalid_name_type)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider,lookup(_, _,_)).Times(0);
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_integer(23));
|
||||
json_array_append_new(params, json_integer(1));
|
||||
|
||||
wfp_impl_lookup(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_lookup, default_responds_error)
|
||||
{
|
||||
MockRequest request;
|
||||
auto * req = request.create_request(42);
|
||||
EXPECT_CALL(request, respond_error(_,42)).Times(1);
|
||||
|
||||
wfp_impl_lookup_default(req, 1, "some.file", nullptr);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_lookup, respond_file)
|
||||
{
|
||||
MockRequest request;
|
||||
auto * req = request.create_request(42);
|
||||
EXPECT_CALL(request, respond(StatMatcher(23, 0754, "file"), 42)).Times(1);
|
||||
|
||||
struct stat buffer;
|
||||
memset(&buffer, 0, sizeof(buffer));
|
||||
buffer.st_ino = 23;
|
||||
buffer.st_mode = S_IFREG | 0754;
|
||||
wfp_impl_respond_lookup(req, &buffer);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_lookup, respond_dir)
|
||||
{
|
||||
MockRequest request;
|
||||
auto * req = request.create_request(42);
|
||||
EXPECT_CALL(request, respond(StatMatcher(23, 0754, "dir"), 42)).Times(1);
|
||||
|
||||
struct stat buffer;
|
||||
memset(&buffer, 0, sizeof(buffer));
|
||||
buffer.st_ino = 23;
|
||||
buffer.st_mode = S_IFDIR | 0754;
|
||||
wfp_impl_respond_lookup(req, &buffer);
|
||||
}
|
||||
114
test/webfuse_provider/provider/operation/test_open.cc
Normal file
114
test/webfuse_provider/provider/operation/test_open.cc
Normal file
@@ -0,0 +1,114 @@
|
||||
#include "webfuse_provider/impl/operation/open.h"
|
||||
#include "webfuse_provider/mocks/mock_request.hpp"
|
||||
#include "webfuse_provider/mocks/mock_provider.hpp"
|
||||
#include "webfuse_provider/mocks/fake_invokation_context.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstdlib>
|
||||
|
||||
using ::webfuse_test::MockProvider;
|
||||
using ::webfuse_test::MockRequest;
|
||||
using ::webfuse_test::OpenMatcher;
|
||||
using ::webfuse_test::create_context;
|
||||
using ::testing::_;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::StrEq;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void free_request(wfp_request * request, ino_t, int)
|
||||
{
|
||||
free(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(wfp_impl_open, invoke_provider)
|
||||
{
|
||||
ino_t inode = 42;
|
||||
int flags = 0;
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider,open(_, inode, flags)).Times(1)
|
||||
.WillOnce(Invoke(free_request));
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_integer(inode));
|
||||
json_array_append_new(params, json_integer(flags));
|
||||
|
||||
wfp_impl_open(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_open, fail_invalid_param_count)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider,open(_, _, _)).Times(0);
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_integer(23));
|
||||
|
||||
wfp_impl_open(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_open, fail_invalid_inode_type)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider,open(_, _, _)).Times(0);
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_string(""));
|
||||
json_array_append_new(params, json_integer(0));
|
||||
|
||||
wfp_impl_open(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_open, fail_invalid_flags_type)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider,open(_, _, _)).Times(0);
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_integer(23));
|
||||
json_array_append_new(params, json_string(""));
|
||||
|
||||
wfp_impl_open(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_open, default_responds_error)
|
||||
{
|
||||
MockRequest request;
|
||||
auto * req = request.create_request(42);
|
||||
EXPECT_CALL(request, respond_error(_,42)).Times(1);
|
||||
|
||||
wfp_impl_open_default(req, 1, 0, nullptr);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_open, respond)
|
||||
{
|
||||
MockRequest request;
|
||||
auto * req = request.create_request(42);
|
||||
EXPECT_CALL(request, respond(OpenMatcher(23), 42)).Times(1);
|
||||
|
||||
wfp_impl_respond_open(req, 23);
|
||||
}
|
||||
|
||||
173
test/webfuse_provider/provider/operation/test_read.cc
Normal file
173
test/webfuse_provider/provider/operation/test_read.cc
Normal file
@@ -0,0 +1,173 @@
|
||||
#include "webfuse_provider/impl/operation/read.h"
|
||||
#include "webfuse_provider/mocks/mock_request.hpp"
|
||||
#include "webfuse_provider/mocks/mock_provider.hpp"
|
||||
#include "webfuse_provider/mocks/fake_invokation_context.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstdlib>
|
||||
|
||||
using ::webfuse_test::MockProvider;
|
||||
using ::webfuse_test::MockRequest;
|
||||
using ::webfuse_test::ReadResultMatcher;
|
||||
using ::webfuse_test::create_context;
|
||||
using ::testing::_;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::StrEq;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void free_request(wfp_request * request, ino_t, uint32_t, size_t ,size_t)
|
||||
{
|
||||
free(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(wfp_impl_read, invoke_provider)
|
||||
{
|
||||
ino_t inode = 42;
|
||||
uint32_t handle = 5;
|
||||
size_t offset = 2;
|
||||
size_t length = 1;
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider, read(_, inode, handle, offset, length)).Times(1)
|
||||
.WillOnce(Invoke(free_request));
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_integer(inode));
|
||||
json_array_append_new(params, json_integer(handle));
|
||||
json_array_append_new(params, json_integer(offset));
|
||||
json_array_append_new(params, json_integer(length));
|
||||
|
||||
wfp_impl_read(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_read, fail_invalid_param_count)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0);
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_integer(1));
|
||||
json_array_append_new(params, json_integer(2));
|
||||
json_array_append_new(params, json_integer(3));
|
||||
json_array_append_new(params, json_integer(4));
|
||||
json_array_append_new(params, json_integer(5));
|
||||
|
||||
wfp_impl_read(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_read, fail_invalid_inode_type)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0);
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_string("42"));
|
||||
json_array_append_new(params, json_integer(2));
|
||||
json_array_append_new(params, json_integer(3));
|
||||
json_array_append_new(params, json_integer(4));
|
||||
|
||||
wfp_impl_read(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_read, fail_invalid_handle_type)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0);
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_integer(1));
|
||||
json_array_append_new(params, json_string("42"));
|
||||
json_array_append_new(params, json_integer(3));
|
||||
json_array_append_new(params, json_integer(4));
|
||||
|
||||
wfp_impl_read(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_read, fail_invalid_offset_type)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0);
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_integer(1));
|
||||
json_array_append_new(params, json_integer(2));
|
||||
json_array_append_new(params, json_string("42"));
|
||||
json_array_append_new(params, json_integer(4));
|
||||
|
||||
wfp_impl_read(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_read, fail_invalid_length_type)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0);
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_integer(1));
|
||||
json_array_append_new(params, json_integer(2));
|
||||
json_array_append_new(params, json_integer(3));
|
||||
json_array_append_new(params, json_string("42"));
|
||||
|
||||
wfp_impl_read(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_read, default_responds_error)
|
||||
{
|
||||
MockRequest request;
|
||||
auto * req = request.create_request(42);
|
||||
EXPECT_CALL(request, respond_error(_,42)).Times(1);
|
||||
|
||||
wfp_impl_read_default(req, 0, 0, 1, 2, nullptr);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_read, respond)
|
||||
{
|
||||
MockRequest request;
|
||||
auto * req = request.create_request(42);
|
||||
EXPECT_CALL(request, respond(ReadResultMatcher("d2Y=", "base64", 2), 42)).Times(1);
|
||||
|
||||
char const data[] = "wf";
|
||||
wfp_impl_respond_read(req, data, 2);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_read, respond_empty)
|
||||
{
|
||||
MockRequest request;
|
||||
auto * req = request.create_request(42);
|
||||
EXPECT_CALL(request, respond(ReadResultMatcher("", "identity", 0), 42)).Times(1);
|
||||
|
||||
wfp_impl_respond_read(req, nullptr, 0);
|
||||
}
|
||||
100
test/webfuse_provider/provider/operation/test_readdir.cc
Normal file
100
test/webfuse_provider/provider/operation/test_readdir.cc
Normal file
@@ -0,0 +1,100 @@
|
||||
#include "webfuse_provider/impl/operation/readdir.h"
|
||||
#include "webfuse_provider/mocks/mock_request.hpp"
|
||||
#include "webfuse_provider/mocks/mock_provider.hpp"
|
||||
#include "webfuse_provider/mocks/fake_invokation_context.hpp"
|
||||
#include "webfuse_provider/dirbuffer.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstdlib>
|
||||
|
||||
using ::webfuse_test::MockProvider;
|
||||
using ::webfuse_test::MockRequest;
|
||||
using ::webfuse_test::ReaddirMatcher;
|
||||
using ::webfuse_test::create_context;
|
||||
using ::testing::_;
|
||||
using ::testing::Invoke;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void free_request(wfp_request * request, ino_t)
|
||||
{
|
||||
free(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(wfp_impl_readdir, invoke_provider)
|
||||
{
|
||||
ino_t inode = 23;
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider,readdir(_, inode)).Times(1).WillOnce(Invoke(free_request));
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_integer(inode));
|
||||
|
||||
wfp_impl_readdir(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_readdir, fail_invalid_param_count)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider,readdir(_, _)).Times(0);
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_integer(1));
|
||||
json_array_append_new(params, json_integer(1));
|
||||
|
||||
wfp_impl_readdir(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_readdir, fail_invalid_inode_type)
|
||||
{
|
||||
MockProvider provider;
|
||||
EXPECT_CALL(provider,readdir(_, _)).Times(0);
|
||||
|
||||
wfp_request request = {nullptr, nullptr, 0};
|
||||
wfp_impl_invokation_context context = create_context(provider, &request);
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string("test.filesystem"));
|
||||
json_array_append_new(params, json_string("1"));
|
||||
|
||||
wfp_impl_readdir(&context, params, 42);
|
||||
json_decref(params);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_readdir, default_responds_error)
|
||||
{
|
||||
MockRequest request;
|
||||
auto * req = request.create_request(42);
|
||||
EXPECT_CALL(request, respond_error(_,42)).Times(1);
|
||||
|
||||
wfp_impl_readdir_default(req, 0, nullptr);
|
||||
}
|
||||
|
||||
TEST(wfp_impl_readdir, respond)
|
||||
{
|
||||
char const item0[] = "some.file";
|
||||
char const * items[] = { item0, nullptr };
|
||||
|
||||
MockRequest request;
|
||||
auto * req = request.create_request(42);
|
||||
EXPECT_CALL(request, respond(ReaddirMatcher(items), 42)).Times(1);
|
||||
|
||||
wfp_dirbuffer * buffer = wfp_dirbuffer_create();
|
||||
wfp_dirbuffer_add(buffer, item0, 42);
|
||||
wfp_impl_respond_readdir(req, buffer);
|
||||
wfp_dirbuffer_dispose(buffer);
|
||||
|
||||
}
|
||||
268
test/webfuse_provider/provider/test_client_protocol.cc
Normal file
268
test/webfuse_provider/provider/test_client_protocol.cc
Normal file
@@ -0,0 +1,268 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include <webfuse_provider/client_protocol.h>
|
||||
#include <webfuse_provider/client_config.h>
|
||||
#include "webfuse_provider/utils/ws_server.h"
|
||||
#include "webfuse_provider/mocks/mock_provider_client.hpp"
|
||||
#include "webfuse_provider/protocol_names.h"
|
||||
#include "webfuse_provider/utils/timeout_watcher.hpp"
|
||||
|
||||
#include <libwebsockets.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
|
||||
using webfuse_test::WsServer;
|
||||
using webfuse_test::MockProviderClient;
|
||||
using webfuse_test::IProviderClient;
|
||||
using webfuse_test::TimeoutWatcher;
|
||||
using testing::_;
|
||||
using testing::AtMost;
|
||||
using testing::Invoke;
|
||||
|
||||
#define DEFAULT_TIMEOUT (std::chrono::milliseconds(5 * 1000))
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
class ClientProtocolFixture
|
||||
{
|
||||
ClientProtocolFixture(ClientProtocolFixture const &) = delete;
|
||||
ClientProtocolFixture& operator=(ClientProtocolFixture const &) = delete;
|
||||
public:
|
||||
explicit ClientProtocolFixture(IProviderClient& client, bool enableAuthentication = false)
|
||||
{
|
||||
server = new WsServer(WFP_PROTOCOL_NAME_ADAPTER_SERVER);
|
||||
|
||||
config = wfp_client_config_create();
|
||||
client.AttachTo(config, enableAuthentication);
|
||||
protocol = wfp_client_protocol_create(config);
|
||||
|
||||
memset(protocols, 0, sizeof(struct lws_protocols) * 2);
|
||||
wfp_client_protocol_init_lws(protocol, protocols);
|
||||
|
||||
memset(&info, 0, sizeof(struct lws_context_creation_info));
|
||||
info.port = CONTEXT_PORT_NO_LISTEN;
|
||||
info.protocols = protocols;
|
||||
info.uid = -1;
|
||||
info.gid = -1;
|
||||
|
||||
context = lws_create_context(&info);
|
||||
}
|
||||
|
||||
~ClientProtocolFixture()
|
||||
{
|
||||
lws_context_destroy(context);
|
||||
wfp_client_protocol_dispose(protocol);
|
||||
wfp_client_config_dispose(config);
|
||||
delete server;
|
||||
}
|
||||
|
||||
void Connect()
|
||||
{
|
||||
TimeoutWatcher watcher(DEFAULT_TIMEOUT);
|
||||
|
||||
wfp_client_protocol_connect(protocol, context, server->GetUrl().c_str());
|
||||
while (!server->IsConnected())
|
||||
{
|
||||
watcher.check();
|
||||
lws_service(context, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void Disconnect()
|
||||
{
|
||||
wfp_client_protocol_disconnect(protocol);
|
||||
}
|
||||
|
||||
void SendToClient(json_t * request)
|
||||
{
|
||||
server->SendMessage(request);
|
||||
}
|
||||
|
||||
json_t * ReceiveMessageFromClient()
|
||||
{
|
||||
TimeoutWatcher watcher(DEFAULT_TIMEOUT);
|
||||
json_t * result = server->ReceiveMessage();
|
||||
while (nullptr == result)
|
||||
{
|
||||
watcher.check();
|
||||
lws_service(context, 0);
|
||||
result = server->ReceiveMessage();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void AwaitAuthentication(
|
||||
std::string const & expected_username,
|
||||
std::string const & expected_password)
|
||||
{
|
||||
json_t * request = ReceiveMessageFromClient();
|
||||
ASSERT_TRUE(json_is_object(request));
|
||||
|
||||
json_t * method = json_object_get(request, "method");
|
||||
ASSERT_TRUE(json_is_string(method));
|
||||
ASSERT_STREQ("authenticate", json_string_value(method));
|
||||
|
||||
json_t * id = json_object_get(request, "id");
|
||||
ASSERT_TRUE(json_is_integer(id));
|
||||
|
||||
json_t * params = json_object_get(request, "params");
|
||||
ASSERT_TRUE(json_is_array(params));
|
||||
ASSERT_EQ(2, json_array_size(params));
|
||||
|
||||
json_t * type = json_array_get(params, 0);
|
||||
ASSERT_TRUE(json_is_string(type));
|
||||
ASSERT_STREQ("username", json_string_value(type));
|
||||
|
||||
json_t * credentials = json_array_get(params, 1);
|
||||
ASSERT_TRUE(json_is_object(credentials));
|
||||
|
||||
json_t * username = json_object_get(credentials, "username");
|
||||
ASSERT_TRUE(json_is_string(username));
|
||||
ASSERT_STREQ(expected_username.c_str(), json_string_value(username));
|
||||
|
||||
json_t * password = json_object_get(credentials, "password");
|
||||
ASSERT_TRUE(json_is_string(password));
|
||||
ASSERT_STREQ(expected_password.c_str(), json_string_value(password));
|
||||
|
||||
json_t * response = json_object();
|
||||
json_object_set_new(response, "result", json_object());
|
||||
json_object_set(response, "id", id);
|
||||
SendToClient(response);
|
||||
|
||||
json_decref(request);
|
||||
}
|
||||
|
||||
void AwaitAddFilesystem(std::string& filesystemName)
|
||||
{
|
||||
json_t * addFilesystemRequest = ReceiveMessageFromClient();
|
||||
ASSERT_NE(nullptr, addFilesystemRequest);
|
||||
ASSERT_TRUE(json_is_object(addFilesystemRequest));
|
||||
|
||||
json_t * method = json_object_get(addFilesystemRequest, "method");
|
||||
ASSERT_TRUE(json_is_string(method));
|
||||
ASSERT_STREQ("add_filesystem", json_string_value(method));
|
||||
|
||||
json_t * params = json_object_get(addFilesystemRequest, "params");
|
||||
ASSERT_TRUE(json_is_array(params));
|
||||
ASSERT_EQ(1, json_array_size(params));
|
||||
|
||||
json_t * filesystem = json_array_get(params, 0);
|
||||
ASSERT_TRUE(json_is_string(filesystem));
|
||||
filesystemName = json_string_value(filesystem);
|
||||
|
||||
json_t * id = json_object_get(addFilesystemRequest, "id");
|
||||
ASSERT_TRUE(json_is_integer(id));
|
||||
|
||||
json_t * response = json_object();
|
||||
json_t * result = json_object();
|
||||
json_object_set(result, "id", filesystem);
|
||||
json_object_set_new(response, "result", result);
|
||||
json_object_set(response, "id", id);
|
||||
|
||||
SendToClient(response);
|
||||
|
||||
json_decref(addFilesystemRequest);
|
||||
}
|
||||
|
||||
private:
|
||||
WsServer * server;
|
||||
wfp_client_config * config;
|
||||
wfp_client_protocol * protocol;
|
||||
struct lws_context_creation_info info;
|
||||
struct lws_protocols protocols[2];
|
||||
struct lws_context * context;
|
||||
|
||||
};
|
||||
|
||||
void GetCredentials(wfp_credentials * credentials)
|
||||
{
|
||||
wfp_credentials_set_type(credentials, "username");
|
||||
wfp_credentials_add(credentials, "username", "bob");
|
||||
wfp_credentials_add(credentials, "password", "secret");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(client_protocol, connect)
|
||||
{
|
||||
MockProviderClient provider;
|
||||
ClientProtocolFixture fixture(provider);
|
||||
|
||||
EXPECT_CALL(provider, OnConnected()).Times(AtMost(1));
|
||||
EXPECT_CALL(provider, OnDisconnected()).Times(1);
|
||||
|
||||
fixture.Connect();
|
||||
if (HasFatalFailure()) { return; }
|
||||
|
||||
std::string filesystem;
|
||||
fixture.AwaitAddFilesystem(filesystem);
|
||||
if (HasFatalFailure()) { return; }
|
||||
}
|
||||
|
||||
TEST(client_protocol, disconnect_without_connect)
|
||||
{
|
||||
MockProviderClient provider;
|
||||
ClientProtocolFixture fixture(provider);
|
||||
|
||||
EXPECT_CALL(provider, OnDisconnected()).Times(1);
|
||||
|
||||
fixture.Disconnect();
|
||||
}
|
||||
|
||||
TEST(client_protocol, connect_with_username_authentication)
|
||||
{
|
||||
MockProviderClient provider;
|
||||
ClientProtocolFixture fixture(provider, true);
|
||||
|
||||
EXPECT_CALL(provider, OnConnected()).Times(AtMost(1));
|
||||
EXPECT_CALL(provider, OnDisconnected()).Times(1);
|
||||
EXPECT_CALL(provider, GetCredentials(_)).Times(1).WillOnce(Invoke(GetCredentials));
|
||||
|
||||
fixture.Connect();
|
||||
if (HasFatalFailure()) { return; }
|
||||
|
||||
fixture.AwaitAuthentication("bob", "secret");
|
||||
if (HasFatalFailure()) { return; }
|
||||
|
||||
std::string filesystem;
|
||||
fixture.AwaitAddFilesystem(filesystem);
|
||||
if (HasFatalFailure()) { return; }
|
||||
}
|
||||
|
||||
TEST(client_protocol, getattr)
|
||||
{
|
||||
MockProviderClient provider;
|
||||
ClientProtocolFixture fixture(provider);
|
||||
|
||||
EXPECT_CALL(provider, OnConnected()).Times(1);
|
||||
EXPECT_CALL(provider, OnDisconnected()).Times(1);
|
||||
EXPECT_CALL(provider, GetAttr(1, _)).Times(1);
|
||||
|
||||
fixture.Connect();
|
||||
if (HasFatalFailure()) { return; }
|
||||
|
||||
std::string filesystem;
|
||||
fixture.AwaitAddFilesystem(filesystem);
|
||||
if (HasFatalFailure()) { return; }
|
||||
|
||||
json_t * params = json_array();
|
||||
json_array_append_new(params, json_string(filesystem.c_str()));
|
||||
json_array_append_new(params, json_integer(1));
|
||||
json_t * request = json_object();
|
||||
json_object_set_new(request, "method", json_string("getattr"));
|
||||
json_object_set_new(request, "params", params);
|
||||
json_object_set_new(request, "id", json_integer(42));
|
||||
|
||||
fixture.SendToClient(request);
|
||||
json_t * response = fixture.ReceiveMessageFromClient();
|
||||
ASSERT_TRUE(json_is_object(response));
|
||||
|
||||
json_decref(response);
|
||||
|
||||
fixture.Disconnect();
|
||||
}
|
||||
32
test/webfuse_provider/provider/test_dirbuffer.cc
Normal file
32
test/webfuse_provider/provider/test_dirbuffer.cc
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "webfuse_provider/impl/dirbuffer.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(DirBuffer, CreateDispose)
|
||||
{
|
||||
wfp_dirbuffer * buffer = wfp_impl_dirbuffer_create();
|
||||
wfp_impl_dirbuffer_dispose(buffer);
|
||||
}
|
||||
|
||||
TEST(DirBuffer, Add)
|
||||
{
|
||||
wfp_dirbuffer * buffer = wfp_impl_dirbuffer_create();
|
||||
wfp_impl_dirbuffer_add(buffer, "answer", 42);
|
||||
|
||||
ASSERT_EQ(1, json_array_size(buffer->entries));
|
||||
|
||||
json_t * entry = json_array_get(buffer->entries, 0);
|
||||
ASSERT_STREQ("answer", json_string_value(json_object_get(entry, "name")));
|
||||
ASSERT_EQ(42, json_integer_value(json_object_get(entry, "inode")));
|
||||
|
||||
wfp_impl_dirbuffer_dispose(buffer);
|
||||
}
|
||||
|
||||
TEST(DirBuffer, Take)
|
||||
{
|
||||
wfp_dirbuffer * buffer = wfp_impl_dirbuffer_create();
|
||||
json_t * entries = wfp_impl_dirbuffer_take(buffer);
|
||||
wfp_impl_dirbuffer_dispose(buffer);
|
||||
|
||||
ASSERT_TRUE(json_is_array(entries));
|
||||
json_decref(entries);
|
||||
}
|
||||
Reference in New Issue
Block a user