chore: re-enabled unit tests

pull/3/head
Falk Werner 4 years ago
parent df52f1b753
commit 7d4f6a3d55

@ -109,8 +109,9 @@ alltests = executable('alltests',
'test/webfuse_provider/test_util/webfuse_server.cc',
'test/webfuse_provider/test_util/client.cc',
'test/webfuse_provider/test_util/jansson_test_environment.cc',
'test/webfuse_provider/test_util/json_doc.cc',
'test/webfuse_provider/mocks/fake_invokation_context.cc',
# 'test/webfuse_provider/mocks/mock_request.cc',
'test/webfuse_provider/mocks/mock_request.cc',
'test/webfuse_provider/mocks/mock_provider_client.cc',
'test/webfuse_provider/mocks/mock_provider.cc',
'test/webfuse_provider/mocks/mock_jsonrpc_proxy.cc',
@ -137,11 +138,11 @@ alltests = executable('alltests',
'test/webfuse_provider/provider/test_client_protocol.cc',
'test/webfuse_provider/provider/test_dirbuffer.cc',
'test/webfuse_provider/provider/operation/test_close.cc',
# 'test/webfuse_provider/provider/operation/test_getattr.cc',
# 'test/webfuse_provider/provider/operation/test_lookup.cc',
# 'test/webfuse_provider/provider/operation/test_open.cc',
# 'test/webfuse_provider/provider/operation/test_read.cc',
# 'test/webfuse_provider/provider/operation/test_readdir.cc',
'test/webfuse_provider/provider/operation/test_getattr.cc',
'test/webfuse_provider/provider/operation/test_lookup.cc',
'test/webfuse_provider/provider/operation/test_open.cc',
'test/webfuse_provider/provider/operation/test_read.cc',
'test/webfuse_provider/provider/operation/test_readdir.cc',
link_args: [
'-Wl,--wrap=wfp_timer_manager_create',
'-Wl,--wrap=wfp_timer_manager_dispose',

@ -1,33 +1,61 @@
#include "webfuse_provider/mocks/mock_request.hpp"
#include "webfuse_provider/impl/json/parser.h"
#include "webfuse_provider/impl/message.h"
#include "webfuse_provider/impl/message_writer.h"
#include "webfuse_provider/status.h"
#include <cstdlib>
extern "C"
{
static void webfuse_test_MockRequest_respond(
json_t * response,
struct wfp_message * response,
void * user_data)
{
auto * request = reinterpret_cast<webfuse_test::MockRequest*>(user_data);
json_t * result = json_object_get(response, "result");
json_t * error = json_object_get(response, "error");
json_t * id_holder = json_object_get(response, "id");
int error_code = WFP_BAD;
int id = -1;
if (json_is_integer(id_holder))
{
id = json_integer_value(id_holder);
}
if (nullptr != result)
wfp_json_doc * doc = wfp_impl_json_parse_buffer(response->data, response->length);
if (NULL != doc)
{
request->respond(result, id);
wfp_json const * response = wfp_impl_json_root(doc);
wfp_json const * result = wfp_impl_json_object_get(response, "result");
wfp_json const * id_holder = wfp_impl_json_object_get(response, "id");
if (wfp_impl_json_is_int(id_holder))
{
id = wfp_impl_json_get_int(id_holder);
}
if (nullptr != result)
{
error_code = WFP_GOOD;
request->respond(result, id);
}
else
{
wfp_json const * error = wfp_impl_json_object_get(response, "error");
if (wfp_impl_json_is_object(error))
{
wfp_json const * error_code_holder = wfp_impl_json_object_get(response, "error");
if (wfp_impl_json_is_int(error_code_holder))
{
error_code = wfp_impl_json_get_int(error_code_holder);
}
}
}
wfp_impl_json_dispose(doc);
}
else
if (WFP_GOOD != error_code)
{
request->respond_error(error, id);
request->respond_error(error_code, id);
}
wfp_message_dispose(response);
}
}
@ -41,6 +69,7 @@ struct wfp_request * MockRequest::create_request(int id)
request->respond = &webfuse_test_MockRequest_respond;
request->user_data = reinterpret_cast<void*>(this);
request->id = id;
request->writer = wfp_impl_message_writer_create(id);
return request;
}

@ -1,10 +1,10 @@
#ifndef WFP_MOCK_REQUEST_HPP
#define WFP_MOCK_REQUEST_HPP
#include "webfuse_provider/impl/request.h"
#include "webfuse_provider/impl/json/node.h"
#include <gmock/gmock.h>
#include <jansson.h>
#include <cstring>
#include "webfuse_provider/impl/request.h"
namespace webfuse_test
@ -14,28 +14,28 @@ class MockRequest
{
public:
struct wfp_request * create_request(int id);
MOCK_METHOD2(respond, void(json_t * result, int id));
MOCK_METHOD2(respond_error, void(json_t * error, int id));
MOCK_METHOD2(respond, void(wfp_json const * result, int id));
MOCK_METHOD2(respond_error, void(int error_code, int id));
};
MATCHER_P3(StatMatcher, inode, mode, file_type, "")
{
json_t * inode_holder = json_object_get(arg, "inode");
if ((!json_is_integer(inode_holder)) || (inode != json_integer_value(inode_holder)))
wfp_json const * inode_holder = wfp_impl_json_object_get(arg, "inode");
if ((!wfp_impl_json_is_int(inode_holder)) || (inode != wfp_impl_json_get_int(inode_holder)))
{
*result_listener << "missing inode";
return false;
}
json_t * mode_holder = json_object_get(arg, "mode");
if ((!json_is_integer(mode_holder)) || (mode != json_integer_value(mode_holder)))
wfp_json const * mode_holder = wfp_impl_json_object_get(arg, "mode");
if ((!wfp_impl_json_is_int(mode_holder)) || (mode != wfp_impl_json_get_int(mode_holder)))
{
*result_listener << "missing mode";
return false;
}
json_t * type_holder = json_object_get(arg, "type");
if ((!json_is_string(type_holder)) || (0 != strcmp(file_type, json_string_value(type_holder))))
wfp_json const * type_holder = wfp_impl_json_object_get(arg, "type");
if ((!wfp_impl_json_is_string(type_holder)) || (0 != strcmp(file_type, wfp_impl_json_get_string(type_holder))))
{
*result_listener << "missing type";
return false;
@ -46,8 +46,8 @@ MATCHER_P3(StatMatcher, inode, mode, file_type, "")
MATCHER_P(OpenMatcher, handle, "")
{
json_t * handle_holder = json_object_get(arg, "handle");
if ((!json_is_integer(handle_holder)) || (handle != json_integer_value(handle_holder)))
wfp_json const * handle_holder = wfp_impl_json_object_get(arg, "handle");
if ((!wfp_impl_json_is_int(handle_holder)) || (handle != wfp_impl_json_get_int(handle_holder)))
{
*result_listener << "missing handle";
return false;
@ -58,24 +58,24 @@ MATCHER_P(OpenMatcher, handle, "")
MATCHER_P3(ReadResultMatcher, data, format, count, "")
{
json_t * format_holder = json_object_get(arg, "format");
if ((!json_is_string(format_holder)) || (0 != strcmp(format, json_string_value(format_holder))))
wfp_json const * format_holder = wfp_impl_json_object_get(arg, "format");
if ((!wfp_impl_json_is_string(format_holder)) || (0 != strcmp(format, wfp_impl_json_get_string(format_holder))))
{
*result_listener << "invalid or missing format: " << json_string_value(format_holder);
*result_listener << "invalid or missing format: " << wfp_impl_json_get_string(format_holder);
return false;
}
json_t * count_holder = json_object_get(arg, "count");
if ((!json_is_integer(count_holder)) || (count != json_integer_value(count_holder)))
wfp_json const * count_holder = wfp_impl_json_object_get(arg, "count");
if ((!wfp_impl_json_is_int(count_holder)) || (count != wfp_impl_json_get_int(count_holder)))
{
*result_listener << "invalid or missing count: " << json_integer_value(count_holder);
*result_listener << "invalid or missing count: " << wfp_impl_json_get_int(count_holder);
return false;
}
json_t * data_holder = json_object_get(arg, "data");
if ((!json_is_string(data_holder)) || (0 != strcmp(data, json_string_value(data_holder))))
wfp_json const * data_holder = wfp_impl_json_object_get(arg, "data");
if ((!wfp_impl_json_is_string(data_holder)) || (0 != strcmp(data, wfp_impl_json_get_string(data_holder))))
{
*result_listener << "invalid or missing data: " << json_string_value(data_holder);
*result_listener << "invalid or missing data: " << wfp_impl_json_get_string(data_holder);
return false;
}
@ -84,28 +84,26 @@ MATCHER_P3(ReadResultMatcher, data, format, count, "")
MATCHER_P(ReaddirMatcher, contained_elements , "")
{
if (!json_is_array(arg))
if (!wfp_impl_json_is_array(arg))
{
*result_listener << "result is not array";
return false;
}
{
size_t i;
json_t * value;
json_array_foreach(arg, i, value)
for(size_t i = 0; i < wfp_impl_json_array_size(arg); i++)
{
json_t * inode = json_object_get(value, "inode");
json_t * name = json_object_get(value, "name");
wfp_json const * value = wfp_impl_json_array_get(arg, i);
wfp_json const * inode = wfp_impl_json_object_get(value, "inode");
wfp_json const * name = wfp_impl_json_object_get(value, "name");
if(!json_is_integer(inode))
if(!wfp_impl_json_is_int(inode))
{
*result_listener << "invalid result: missing inode";
return false;
}
if (!json_is_string(name))
if (!wfp_impl_json_is_string(name))
{
*result_listener << "invalid result: missing name";
return false;
@ -117,14 +115,13 @@ MATCHER_P(ReaddirMatcher, contained_elements , "")
{
char const * element = contained_elements[i];
bool found = false;
size_t j;
json_t * value;
json_array_foreach(arg, j, value)
for(size_t j = 0; j < wfp_impl_json_array_size(arg); j++)
{
json_t * name = json_object_get(value, "name");
wfp_json const * value = wfp_impl_json_array_get(arg, j);
wfp_json const * name = wfp_impl_json_object_get(value, "name");
found = (0 == strcmp(element, json_string_value(name)));
found = (0 == strcmp(element, wfp_impl_json_get_string(name)));
if (found)
{
break;

@ -2,6 +2,7 @@
#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/test_util/json_doc.hpp"
#include <gtest/gtest.h>
#include <cstdlib>
@ -10,6 +11,7 @@ using ::webfuse_test::MockProvider;
using ::webfuse_test::MockRequest;
using ::webfuse_test::StatMatcher;
using ::webfuse_test::create_context;
using ::webfuse_test::JsonDoc;
using ::testing::_;
using ::testing::Invoke;
@ -18,7 +20,7 @@ namespace
void free_request(wfp_request * request, ino_t)
{
free(request);
wfp_impl_request_dispose(request);
}
}
@ -60,19 +62,14 @@ TEST(wfp_impl_getattr, respond_dir)
TEST(wfp_impl_getattr, invoke_provider)
{
ino_t inode = 23;
MockProvider provider;
EXPECT_CALL(provider,getattr(_, inode)).Times(1).WillOnce(Invoke(free_request));
EXPECT_CALL(provider,getattr(_, 23)).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);
JsonDoc doc("[\"test.filesystem\", 23]");
wfp_impl_getattr(&context, doc.root(), 42);
}
TEST(wfp_impl_getattr, fail_invalid_param_count)
@ -83,11 +80,8 @@ TEST(wfp_impl_getattr, fail_invalid_param_count)
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);
JsonDoc doc("[\"test.filesystem\"]");
wfp_impl_getattr(&context, doc.root(), 42);
}
TEST(wfp_impl_getattr, fail_invalid_inode_type)
@ -98,10 +92,6 @@ TEST(wfp_impl_getattr, fail_invalid_inode_type)
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);
JsonDoc doc("[\"test.filesystem\", \"42\"]");
wfp_impl_getattr(&context, doc.root(), 42);
}

@ -2,6 +2,7 @@
#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/test_util/json_doc.hpp"
#include <gtest/gtest.h>
#include <cstdlib>
@ -10,6 +11,7 @@ using ::webfuse_test::MockProvider;
using ::webfuse_test::MockRequest;
using ::webfuse_test::StatMatcher;
using ::webfuse_test::create_context;
using ::webfuse_test::JsonDoc;
using ::testing::_;
using ::testing::Invoke;
using ::testing::StrEq;
@ -19,28 +21,22 @@ namespace
void free_request(wfp_request * request, ino_t, char const *)
{
free(request);
wfp_impl_request_dispose(request);
}
}
TEST(wfp_impl_lookup, invoke_provider)
{
ino_t inode = 42;
MockProvider provider;
EXPECT_CALL(provider,lookup(_, inode,StrEq("some.file"))).Times(1)
EXPECT_CALL(provider,lookup(_, 42,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);
JsonDoc doc("[\"test.filesystem\", 42, \"some.file\"]");
wfp_impl_lookup(&context, doc.root(), 42);
}
TEST(wfp_impl_lookup, fail_invalid_param_count)
@ -51,12 +47,8 @@ TEST(wfp_impl_lookup, fail_invalid_param_count)
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);
JsonDoc doc("[\"test.filesystem\", 23]");
wfp_impl_lookup(&context, doc.root(), 42);
}
TEST(wfp_impl_lookup, fail_invalid_inode_type)
@ -67,13 +59,8 @@ TEST(wfp_impl_lookup, fail_invalid_inode_type)
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);
JsonDoc doc("[\"test.filesystem\", \"23\", \"some.file\"]");
wfp_impl_lookup(&context, doc.root(), 42);
}
TEST(wfp_impl_lookup, fail_invalid_name_type)
@ -84,13 +71,8 @@ TEST(wfp_impl_lookup, fail_invalid_name_type)
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);
JsonDoc doc("[\"test.filesystem\", 23, 1]");
wfp_impl_lookup(&context, doc.root(), 42);
}
TEST(wfp_impl_lookup, default_responds_error)

@ -2,6 +2,7 @@
#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/test_util/json_doc.hpp"
#include <gtest/gtest.h>
#include <cstdlib>
@ -10,6 +11,7 @@ using ::webfuse_test::MockProvider;
using ::webfuse_test::MockRequest;
using ::webfuse_test::OpenMatcher;
using ::webfuse_test::create_context;
using ::webfuse_test::JsonDoc;
using ::testing::_;
using ::testing::Invoke;
using ::testing::StrEq;
@ -19,29 +21,22 @@ namespace
void free_request(wfp_request * request, ino_t, int)
{
free(request);
wfp_impl_request_dispose(request);
}
}
TEST(wfp_impl_open, invoke_provider)
{
ino_t inode = 42;
int flags = 0;
MockProvider provider;
EXPECT_CALL(provider,open(_, inode, flags)).Times(1)
EXPECT_CALL(provider,open(_, 42, 0)).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);
JsonDoc doc("[\"test.filesystem\",42,0]");
wfp_impl_open(&context, doc.root(), 42);
}
TEST(wfp_impl_open, fail_invalid_param_count)
@ -52,12 +47,8 @@ TEST(wfp_impl_open, fail_invalid_param_count)
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);
JsonDoc doc("[\"test.filesystem\", 23]");
wfp_impl_open(&context, doc.root(), 42);
}
TEST(wfp_impl_open, fail_invalid_inode_type)
@ -68,13 +59,8 @@ TEST(wfp_impl_open, fail_invalid_inode_type)
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);
JsonDoc doc("[\"test.filesystem\", \"\", 0]");
wfp_impl_open(&context, doc.root(), 42);
}
TEST(wfp_impl_open, fail_invalid_flags_type)
@ -85,13 +71,8 @@ TEST(wfp_impl_open, fail_invalid_flags_type)
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);
JsonDoc doc("[\"test.filesystem\", 23, \"\"]");
wfp_impl_open(&context, doc.root(), 42);
}
TEST(wfp_impl_open, default_responds_error)

@ -2,6 +2,7 @@
#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/test_util/json_doc.hpp"
#include <gtest/gtest.h>
#include <cstdlib>
@ -10,6 +11,7 @@ using ::webfuse_test::MockProvider;
using ::webfuse_test::MockRequest;
using ::webfuse_test::ReadResultMatcher;
using ::webfuse_test::create_context;
using ::webfuse_test::JsonDoc;
using ::testing::_;
using ::testing::Invoke;
using ::testing::StrEq;
@ -19,33 +21,22 @@ namespace
void free_request(wfp_request * request, ino_t, uint32_t, size_t ,size_t)
{
free(request);
wfp_impl_request_dispose(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)
EXPECT_CALL(provider, read(_, 42, 5, 2, 1)).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);
JsonDoc doc("[\"test.filesystem\",42,5,2,1]");
wfp_impl_read(&context, doc.root(), 42);
}
TEST(wfp_impl_read, fail_invalid_param_count)
@ -56,16 +47,8 @@ TEST(wfp_impl_read, fail_invalid_param_count)
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);
JsonDoc doc("[\"test.filesyste\",1,2,3,4,5]");
wfp_impl_read(&context, doc.root(), 42);
}
TEST(wfp_impl_read, fail_invalid_inode_type)
@ -76,15 +59,8 @@ TEST(wfp_impl_read, fail_invalid_inode_type)
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);
JsonDoc doc("[\"test.filesyste\",\"42\",2,3,4]");
wfp_impl_read(&context, doc.root(), 42);
}
TEST(wfp_impl_read, fail_invalid_handle_type)
@ -95,15 +71,8 @@ TEST(wfp_impl_read, fail_invalid_handle_type)
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);
JsonDoc doc("[\"test.filesyste\",1,\"42\",3,4]");
wfp_impl_read(&context, doc.root(), 42);
}
TEST(wfp_impl_read, fail_invalid_offset_type)
@ -114,15 +83,8 @@ TEST(wfp_impl_read, fail_invalid_offset_type)
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);
JsonDoc doc("[\"test.filesyste\",1,2,\"42\",4]");
wfp_impl_read(&context, doc.root(), 42);
}
TEST(wfp_impl_read, fail_invalid_length_type)
@ -133,15 +95,8 @@ TEST(wfp_impl_read, fail_invalid_length_type)
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);
JsonDoc doc("[\"test.filesyste\",1,2,3,\"42\"]");
wfp_impl_read(&context, doc.root(), 42);
}
TEST(wfp_impl_read, default_responds_error)

@ -3,6 +3,7 @@
#include "webfuse_provider/mocks/mock_provider.hpp"
#include "webfuse_provider/mocks/fake_invokation_context.hpp"
#include "webfuse_provider/dirbuffer.h"
#include "webfuse_provider/test_util/json_doc.hpp"
#include <gtest/gtest.h>
#include <cstdlib>
@ -11,6 +12,7 @@ using ::webfuse_test::MockProvider;
using ::webfuse_test::MockRequest;
using ::webfuse_test::ReaddirMatcher;
using ::webfuse_test::create_context;
using ::webfuse_test::JsonDoc;
using ::testing::_;
using ::testing::Invoke;
@ -19,26 +21,21 @@ namespace
void free_request(wfp_request * request, ino_t)
{
free(request);
wfp_impl_request_dispose(request);
}
}
TEST(wfp_impl_readdir, invoke_provider)
{
ino_t inode = 23;
MockProvider provider;
EXPECT_CALL(provider,readdir(_, inode)).Times(1).WillOnce(Invoke(free_request));
EXPECT_CALL(provider,readdir(_, 23)).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);
JsonDoc doc("[\"test.filesystem\",23]");
wfp_impl_readdir(&context, doc.root(), 42);
}
TEST(wfp_impl_readdir, fail_invalid_param_count)
@ -49,13 +46,8 @@ TEST(wfp_impl_readdir, fail_invalid_param_count)
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);
JsonDoc doc("[\"test.filesystem\",1,1]");
wfp_impl_readdir(&context, doc.root(), 42);
}
TEST(wfp_impl_readdir, fail_invalid_inode_type)
@ -66,12 +58,8 @@ TEST(wfp_impl_readdir, fail_invalid_inode_type)
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);
JsonDoc doc("[\"test.filesystem\",\"1\"]");
wfp_impl_readdir(&context, doc.root(), 42);
}
TEST(wfp_impl_readdir, default_responds_error)

@ -0,0 +1,22 @@
#include "webfuse_provider/test_util/json_doc.hpp"
namespace webfuse_test
{
JsonDoc::JsonDoc(std::string const & json)
: contents(json)
{
doc = wfp_impl_json_parse(const_cast<char*>(contents.data()));
}
JsonDoc::~JsonDoc()
{
wfp_impl_json_dispose(doc);
}
wfp_json const * JsonDoc::root()
{
return wfp_impl_json_root(doc);
}
}

@ -0,0 +1,25 @@
#ifndef WFP_TEST_UTIL_JSON_DOC_HPP
#define WFP_TEST_UTIL_JSON_DOC_HPP
#include "webfuse_provider/impl/json/parser.h"
#include "webfuse_provider/impl/json/node.h"
#include <string>
namespace webfuse_test
{
class JsonDoc
{
public:
JsonDoc(std::string const & json);
~JsonDoc();
wfp_json const * root();
private:
std::string contents;
wfp_json_doc * doc;
};
}
#endif
Loading…
Cancel
Save