1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00

added tests for wfp_impl_close

This commit is contained in:
Falk Werner 2020-03-29 19:30:08 +02:00
parent 39855a9995
commit 8d28da5e82
4 changed files with 282 additions and 0 deletions

View File

@ -28,6 +28,7 @@ add_executable(alltests
test/webfuse/mocks/mock_authenticator.cc test/webfuse/mocks/mock_authenticator.cc
test/webfuse/mocks/mock_request.cc test/webfuse/mocks/mock_request.cc
test/webfuse/mocks/mock_provider_client.cc test/webfuse/mocks/mock_provider_client.cc
test/webfuse/mocks/mock_provider.cc
test/webfuse//tests/core/test_util.cc test/webfuse//tests/core/test_util.cc
test/webfuse/tests/core/test_container_of.cc test/webfuse/tests/core/test_container_of.cc
test/webfuse/tests/core/test_string.cc test/webfuse/tests/core/test_string.cc
@ -45,6 +46,7 @@ add_executable(alltests
test/webfuse/tests/adapter/test_fuse_req.cc test/webfuse/tests/adapter/test_fuse_req.cc
test/webfuse/tests/provider/test_url.cc test/webfuse/tests/provider/test_url.cc
test/webfuse/tests/provider/test_client_protocol.cc test/webfuse/tests/provider/test_client_protocol.cc
test/webfuse/tests/provider/operation/test_close.cc
test/webfuse/tests/integration/test_integration.cc test/webfuse/tests/integration/test_integration.cc
test/webfuse/tests/integration/server.cc test/webfuse/tests/integration/server.cc
test/webfuse/tests/integration/provider.cc test/webfuse/tests/integration/provider.cc

View File

@ -0,0 +1,138 @@
#include "webfuse/mocks/mock_provider.hpp"
extern "C"
{
using webfuse_test::MockProvider;
static void webfuse_test_MockProvider_connected(
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->connected();
}
static void webfuse_test_MockProvider_disconnected(
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->disconnected();
}
static void webfuse_test_MockProvider_on_timer(
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->on_timer();
}
static void webfuse_test_MockProvider_lookup(
wfp_request * request,
ino_t parent,
char const * name,
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->lookup(request, parent, name);
}
static void webfuse_test_MockProvider_getattr(
wfp_request * request,
ino_t inode,
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->getattr(request, inode);
}
static void webfuse_test_MockProvider_readdir(
wfp_request * request,
ino_t directory,
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->readdir(request, directory);
}
static void webfuse_test_MockProvider_open(
wfp_request * request,
ino_t inode,
int flags,
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->open(request, inode, flags);
}
static void webfuse_test_MockProvider_close(
ino_t inode,
uint32_t handle,
int flags,
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->close(inode, handle, flags);
}
static void webfuse_test_MockProvider_read(
wfp_request * request,
ino_t inode,
uint32_t handle,
size_t offset,
size_t length,
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->read(request, inode, handle, offset, length);
}
static void webfuse_test_MockProvider_get_credentials(
wfp_credentials * credentials,
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->get_credentials(credentials);
}
static wfp_provider const webfuse_test_MockProvider =
{
&webfuse_test_MockProvider_connected,
&webfuse_test_MockProvider_disconnected,
&webfuse_test_MockProvider_on_timer,
&webfuse_test_MockProvider_lookup,
&webfuse_test_MockProvider_getattr,
&webfuse_test_MockProvider_readdir,
&webfuse_test_MockProvider_open,
&webfuse_test_MockProvider_close,
&webfuse_test_MockProvider_read,
&webfuse_test_MockProvider_get_credentials,
};
}
namespace webfuse_test
{
MockProvider::MockProvider()
{
}
MockProvider::~MockProvider()
{
}
wfp_provider const * MockProvider::get_provider()
{
return &webfuse_test_MockProvider;
}
void * MockProvider::get_userdata()
{
return reinterpret_cast<void*>(this);
}
}

View File

@ -0,0 +1,31 @@
#ifndef WF_MOCK_PROVIDER_HPP
#define WF_MOCK_PROVIDER_HPP
#include "webfuse/provider/impl/provider.h"
#include <gmock/gmock.h>
namespace webfuse_test
{
class MockProvider
{
public:
MockProvider();
~MockProvider();
wfp_provider const * get_provider();
void * get_userdata();
MOCK_METHOD0(connected, void ());
MOCK_METHOD0(disconnected, void ());
MOCK_METHOD0(on_timer, void());
MOCK_METHOD3(lookup, void(wfp_request * request, ino_t parent, char const * name));
MOCK_METHOD2(getattr, void(wfp_request * request, ino_t inode));
MOCK_METHOD2(readdir, void(wfp_request * request, ino_t directory));
MOCK_METHOD3(open, void(wfp_request * request, ino_t inode, int flags));
MOCK_METHOD3(close, void(ino_t inode, uint32_t handle, int flags));
MOCK_METHOD5(read, void(wfp_request * request, ino_t inode, uint32_t handle, size_t offset, size_t length));
MOCK_METHOD1(get_credentials, void(wfp_credentials * credentials));
};
}
#endif

View File

@ -0,0 +1,111 @@
#include "webfuse/provider/impl/operation/close.h"
#include "webfuse/mocks/mock_provider.hpp"
#include <gtest/gtest.h>
using ::webfuse_test::MockProvider;
using ::testing::_;
namespace
{
wfp_impl_invokation_context create_context(MockProvider& provider)
{
wfp_impl_invokation_context context =
{
provider.get_provider(),
provider.get_userdata(),
nullptr
};
return context;
}
}
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);
}