mirror of
https://github.com/falk-werner/webfuse
synced 2025-06-13 12:54:15 +00:00
adds mock of wpf_request
This commit is contained in:
parent
fc21b7ee2b
commit
27553a14d7
@ -290,6 +290,7 @@ pkg_check_modules(GMOCK gmock)
|
|||||||
add_executable(alltests
|
add_executable(alltests
|
||||||
test/msleep.cc
|
test/msleep.cc
|
||||||
test/mock_authenticator.cc
|
test/mock_authenticator.cc
|
||||||
|
test/mock_request.cc
|
||||||
test/test_container_of.cc
|
test/test_container_of.cc
|
||||||
test/test_response_parser.cc
|
test/test_response_parser.cc
|
||||||
test/test_server.cc
|
test/test_server.cc
|
||||||
@ -302,6 +303,7 @@ add_executable(alltests
|
|||||||
test/test_string.cc
|
test/test_string.cc
|
||||||
test/test_slist.cc
|
test/test_slist.cc
|
||||||
test/test_path.cc
|
test/test_path.cc
|
||||||
|
test/test_static_filesystem.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(alltests PUBLIC webfuse-adapter-static webfuse-provider-static webfuse-core ${EXTRA_LIBS} ${GMOCK_LIBRARIES} ${GTEST_LIBRARIES})
|
target_link_libraries(alltests PUBLIC webfuse-adapter-static webfuse-provider-static webfuse-core ${EXTRA_LIBS} ${GMOCK_LIBRARIES} ${GTEST_LIBRARIES})
|
||||||
|
37
test/mock_request.cc
Normal file
37
test/mock_request.cc
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include "mock_request.hpp"
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
extern "C" void
|
||||||
|
respond(
|
||||||
|
json_t * response,
|
||||||
|
void * user_data)
|
||||||
|
{
|
||||||
|
(void) response;
|
||||||
|
|
||||||
|
webfuse_test::Request * request = reinterpret_cast<webfuse_test::Request*>(user_data);
|
||||||
|
request->respond_error(nullptr, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace webfuse_test
|
||||||
|
{
|
||||||
|
|
||||||
|
struct wfp_request *
|
||||||
|
request_create(
|
||||||
|
Request * req,
|
||||||
|
int id)
|
||||||
|
{
|
||||||
|
struct wfp_request * request = reinterpret_cast<struct wfp_request *>(malloc(sizeof(struct wfp_request)));
|
||||||
|
request->id = id;
|
||||||
|
request->user_data = reinterpret_cast<void*>(req);
|
||||||
|
request->respond = &respond;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
35
test/mock_request.hpp
Normal file
35
test/mock_request.hpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef WF_MOCK_REQUEST_HPP
|
||||||
|
#define WF_MOCK_REQUEST_HPP
|
||||||
|
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
#include <jansson.h>
|
||||||
|
#include "webfuse/provider/impl/request.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace webfuse_test
|
||||||
|
{
|
||||||
|
|
||||||
|
class Request
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~Request() { }
|
||||||
|
virtual void respond(json_t * result, int id) = 0;
|
||||||
|
virtual void respond_error(json_t * error, int id) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MockRequest: public Request
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MOCK_METHOD2(respond, void(json_t * result, int id));
|
||||||
|
MOCK_METHOD2(respond_error, void(json_t * error, int id));
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct wfp_request *
|
||||||
|
request_create(
|
||||||
|
Request * req,
|
||||||
|
int id);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
29
test/test_static_filesystem.cc
Normal file
29
test/test_static_filesystem.cc
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "webfuse/provider/impl/static_filesystem.h"
|
||||||
|
#include "webfuse/provider/client_config.h"
|
||||||
|
#include "webfuse/provider/impl/client_config.h"
|
||||||
|
|
||||||
|
#include "mock_request.hpp"
|
||||||
|
|
||||||
|
using webfuse_test::request_create;
|
||||||
|
using webfuse_test::MockRequest;
|
||||||
|
using testing::_;
|
||||||
|
|
||||||
|
TEST(wfp_static_filesystem, init)
|
||||||
|
{
|
||||||
|
struct wfp_client_config * config = wfp_client_config_create();
|
||||||
|
struct wfp_static_filesystem * filesystem = wfp_impl_static_filesystem_create(config);
|
||||||
|
|
||||||
|
MockRequest mock;
|
||||||
|
struct wfp_request * request = request_create(&mock, 42);
|
||||||
|
|
||||||
|
EXPECT_CALL(mock, respond_error(_,_)).Times(1);
|
||||||
|
|
||||||
|
config->provider.getattr(request, 1, config->user_data);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wfp_impl_static_filesystem_dispose(filesystem);
|
||||||
|
wfp_client_config_dispose(config);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user