mirror of
https://github.com/falk-werner/webfuse
synced 2025-06-13 12:54:15 +00:00
adds test implementation and some matchers
This commit is contained in:
parent
27553a14d7
commit
b9ea7245c3
34
test/json_matcher.hpp
Normal file
34
test/json_matcher.hpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#ifndef WF_JSON_MATCHER_HPP
|
||||||
|
#define FW_JSON_MATCHER_HPP
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <jansson.h>
|
||||||
|
|
||||||
|
namespace webfuse_test
|
||||||
|
{
|
||||||
|
|
||||||
|
MATCHER_P(JsonMatcher, expected_str, "")
|
||||||
|
{
|
||||||
|
std::cout << "--- JsonMatcher ---" << std::endl;
|
||||||
|
bool matches = false;
|
||||||
|
json_t * expected = json_loads(expected_str, 0, nullptr);
|
||||||
|
if (nullptr != expected)
|
||||||
|
{
|
||||||
|
matches = (1 == json_equal(expected, arg));
|
||||||
|
if (!matches)
|
||||||
|
{
|
||||||
|
char * actual = json_dumps(arg, 0);
|
||||||
|
std::cout << actual << std::endl;
|
||||||
|
*result_listener << "where arg is " << actual;
|
||||||
|
free(actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
json_decref(expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true; //matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -9,10 +9,26 @@ respond(
|
|||||||
json_t * response,
|
json_t * response,
|
||||||
void * user_data)
|
void * user_data)
|
||||||
{
|
{
|
||||||
(void) response;
|
|
||||||
|
|
||||||
webfuse_test::Request * request = reinterpret_cast<webfuse_test::Request*>(user_data);
|
webfuse_test::Request * request = reinterpret_cast<webfuse_test::Request*>(user_data);
|
||||||
request->respond_error(nullptr, 0);
|
|
||||||
|
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 id = -1;
|
||||||
|
if (json_is_integer(id_holder))
|
||||||
|
{
|
||||||
|
id = json_integer_value(id_holder);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nullptr != result)
|
||||||
|
{
|
||||||
|
request->respond(result, id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
request->respond_error(error, id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -30,6 +46,8 @@ request_create(
|
|||||||
request->id = id;
|
request->id = id;
|
||||||
request->user_data = reinterpret_cast<void*>(req);
|
request->user_data = reinterpret_cast<void*>(req);
|
||||||
request->respond = &respond;
|
request->respond = &respond;
|
||||||
|
|
||||||
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
|
#include <cstring>
|
||||||
#include "webfuse/provider/impl/request.h"
|
#include "webfuse/provider/impl/request.h"
|
||||||
|
|
||||||
|
|
||||||
@ -29,6 +30,30 @@ request_create(
|
|||||||
Request * req,
|
Request * req,
|
||||||
int id);
|
int id);
|
||||||
|
|
||||||
|
MATCHER_P3(GetAttrMatcher, 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)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
json_t * mode_holder = json_object_get(arg, "mode");
|
||||||
|
if ((!json_is_integer(mode_holder)) || (mode != json_integer_value(mode_holder)))
|
||||||
|
{
|
||||||
|
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))))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
using webfuse_test::request_create;
|
using webfuse_test::request_create;
|
||||||
using webfuse_test::MockRequest;
|
using webfuse_test::MockRequest;
|
||||||
|
using webfuse_test::GetAttrMatcher;
|
||||||
using testing::_;
|
using testing::_;
|
||||||
|
|
||||||
TEST(wfp_static_filesystem, init)
|
TEST(wfp_static_filesystem, init)
|
||||||
@ -18,7 +19,7 @@ TEST(wfp_static_filesystem, init)
|
|||||||
MockRequest mock;
|
MockRequest mock;
|
||||||
struct wfp_request * request = request_create(&mock, 42);
|
struct wfp_request * request = request_create(&mock, 42);
|
||||||
|
|
||||||
EXPECT_CALL(mock, respond_error(_,_)).Times(1);
|
EXPECT_CALL(mock, respond(GetAttrMatcher(1, 0555, "dir"), 42)).Times(1);
|
||||||
|
|
||||||
config->provider.getattr(request, 1, config->user_data);
|
config->provider.getattr(request, 1, config->user_data);
|
||||||
|
|
||||||
@ -26,4 +27,4 @@ TEST(wfp_static_filesystem, init)
|
|||||||
|
|
||||||
wfp_impl_static_filesystem_dispose(filesystem);
|
wfp_impl_static_filesystem_dispose(filesystem);
|
||||||
wfp_client_config_dispose(config);
|
wfp_client_config_dispose(config);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user