From 289264e2691f39ddb20afc75cd386551eb715741 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 08:55:59 +0200 Subject: [PATCH] added unit tests for close operation (adapter) --- cmake/unit_tests.cmake | 2 + cmake/webfuse_core.cmake | 2 +- lib/webfuse/adapter/impl/filesystem.c | 1 + lib/webfuse/adapter/impl/operation/close.h | 20 +++++++ lib/webfuse/adapter/impl/operations.h | 5 -- lib/webfuse/core/jsonrpc/proxy.c | 8 +-- lib/webfuse/core/jsonrpc/proxy_intern.h | 6 ++ .../{proxy_invoke.c => proxy_variadic.c} | 13 +++++ test/webfuse/mocks/mock_jsonrpc_proxy.cc | 6 ++ test/webfuse/mocks/mock_jsonrpc_proxy.hpp | 5 ++ .../tests/adapter/operation/test_close.cc | 56 +++++++++++++++++++ 11 files changed, 112 insertions(+), 12 deletions(-) create mode 100644 lib/webfuse/adapter/impl/operation/close.h rename lib/webfuse/core/jsonrpc/{proxy_invoke.c => proxy_variadic.c} (59%) create mode 100644 test/webfuse/tests/adapter/operation/test_close.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 4934a05..1ba7e5a 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -49,6 +49,7 @@ add_executable(alltests test/webfuse/tests/adapter/test_mountpoint.cc test/webfuse/tests/adapter/test_fuse_req.cc test/webfuse/tests/adapter/operation/test_open.cc + test/webfuse/tests/adapter/operation/test_close.cc test/webfuse/tests/provider/test_url.cc test/webfuse/tests/provider/test_client_protocol.cc test/webfuse/tests/provider/operation/test_close.cc @@ -73,6 +74,7 @@ target_link_libraries(alltests PUBLIC -Wl,--wrap=wf_timer_cancel -Wl,--wrap=wf_impl_operations_context_get_proxy -Wl,--wrap=wf_jsonrpc_proxy_vinvoke + -Wl,--wrap=wf_jsonrpc_proxy_vnotify -Wl,--wrap=fuse_req_userdata -Wl,--wrap=fuse_reply_open -Wl,--wrap=fuse_reply_err diff --git a/cmake/webfuse_core.cmake b/cmake/webfuse_core.cmake index 3dfa958..c0b1b88 100644 --- a/cmake/webfuse_core.cmake +++ b/cmake/webfuse_core.cmake @@ -13,7 +13,7 @@ add_library(webfuse-core STATIC lib/webfuse/core/timer/timepoint.c lib/webfuse/core/timer/timer.c lib/webfuse/core/jsonrpc/proxy.c - lib/webfuse/core/jsonrpc/proxy_invoke.c + lib/webfuse/core/jsonrpc/proxy_variadic.c lib/webfuse/core/jsonrpc/server.c lib/webfuse/core/jsonrpc/method.c lib/webfuse/core/jsonrpc/request.c diff --git a/lib/webfuse/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c index 67fef92..da9c87b 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -1,6 +1,7 @@ #include "webfuse/adapter/impl/filesystem.h" #include "webfuse/adapter/impl/operations.h" #include "webfuse/adapter/impl/operation/open.h" +#include "webfuse/adapter/impl/operation/close.h" #include "webfuse/adapter/impl/session.h" #include "webfuse/adapter/impl/mountpoint.h" diff --git a/lib/webfuse/adapter/impl/operation/close.h b/lib/webfuse/adapter/impl/operation/close.h new file mode 100644 index 0000000..d254f67 --- /dev/null +++ b/lib/webfuse/adapter/impl/operation/close.h @@ -0,0 +1,20 @@ +#ifndef WF_ADAPTER_IMPL_OPERATION_CLOSE_H +#define WF_ADAPTER_IMPL_OPERATION_CLOSE_H + +#include "webfuse/adapter/impl/fuse_wrapper.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wf_impl_operation_close( + fuse_req_t request, + fuse_ino_t inode, + struct fuse_file_info * file_info); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/webfuse/adapter/impl/operations.h b/lib/webfuse/adapter/impl/operations.h index 162ee15..01808bc 100644 --- a/lib/webfuse/adapter/impl/operations.h +++ b/lib/webfuse/adapter/impl/operations.h @@ -34,11 +34,6 @@ extern void wf_impl_operation_readdir ( off_t offset, struct fuse_file_info *file_info); -extern void wf_impl_operation_close( - fuse_req_t request, - fuse_ino_t inode, - struct fuse_file_info * file_info); - extern void wf_impl_operation_read( fuse_req_t request, fuse_ino_t ino, size_t size, off_t off, diff --git a/lib/webfuse/core/jsonrpc/proxy.c b/lib/webfuse/core/jsonrpc/proxy.c index 90a9d56..ee5fc0d 100644 --- a/lib/webfuse/core/jsonrpc/proxy.c +++ b/lib/webfuse/core/jsonrpc/proxy.c @@ -174,17 +174,13 @@ void wf_jsonrpc_proxy_vinvoke( } } -extern void wf_jsonrpc_proxy_notify( +extern void wf_jsonrpc_proxy_vnotify( struct wf_jsonrpc_proxy * proxy, char const * method_name, char const * param_info, - ... -) + va_list args) { - va_list args; - va_start(args, param_info); json_t * request = wf_jsonrpc_request_create(method_name, 0, param_info, args); - va_end(args); if (NULL != request) { diff --git a/lib/webfuse/core/jsonrpc/proxy_intern.h b/lib/webfuse/core/jsonrpc/proxy_intern.h index 920bd56..fd284a0 100644 --- a/lib/webfuse/core/jsonrpc/proxy_intern.h +++ b/lib/webfuse/core/jsonrpc/proxy_intern.h @@ -49,6 +49,12 @@ extern void wf_jsonrpc_proxy_vinvoke( char const * param_info, va_list args); +extern void wf_jsonrpc_proxy_vnotify( + struct wf_jsonrpc_proxy * proxy, + char const * method_name, + char const * param_info, + va_list args); + #ifdef __cplusplus } #endif diff --git a/lib/webfuse/core/jsonrpc/proxy_invoke.c b/lib/webfuse/core/jsonrpc/proxy_variadic.c similarity index 59% rename from lib/webfuse/core/jsonrpc/proxy_invoke.c rename to lib/webfuse/core/jsonrpc/proxy_variadic.c index ada6b9e..2447511 100644 --- a/lib/webfuse/core/jsonrpc/proxy_invoke.c +++ b/lib/webfuse/core/jsonrpc/proxy_variadic.c @@ -13,3 +13,16 @@ void wf_jsonrpc_proxy_invoke( wf_jsonrpc_proxy_vinvoke(proxy, finished, user_data, method_name, param_info, args); va_end(args); } + +extern void wf_jsonrpc_proxy_notify( + struct wf_jsonrpc_proxy * proxy, + char const * method_name, + char const * param_info, + ... +) +{ + va_list args; + va_start(args, param_info); + wf_jsonrpc_proxy_vnotify(proxy, method_name, param_info, args); + va_end(args); +} diff --git a/test/webfuse/mocks/mock_jsonrpc_proxy.cc b/test/webfuse/mocks/mock_jsonrpc_proxy.cc index 569dfa8..3cb0a8e 100644 --- a/test/webfuse/mocks/mock_jsonrpc_proxy.cc +++ b/test/webfuse/mocks/mock_jsonrpc_proxy.cc @@ -12,6 +12,12 @@ WF_WRAP_FUNC6(webfuse_test_MockJsonRpcProxy, void, wf_jsonrpc_proxy_vinvoke, char const *, char const *, va_list); + +WF_WRAP_FUNC4(webfuse_test_MockJsonRpcProxy, void, wf_jsonrpc_proxy_vnotify, + struct wf_jsonrpc_proxy *, + char const *, + char const *, + va_list); } namespace webfuse_test diff --git a/test/webfuse/mocks/mock_jsonrpc_proxy.hpp b/test/webfuse/mocks/mock_jsonrpc_proxy.hpp index 97a1b1b..fc39e1f 100644 --- a/test/webfuse/mocks/mock_jsonrpc_proxy.hpp +++ b/test/webfuse/mocks/mock_jsonrpc_proxy.hpp @@ -19,6 +19,11 @@ public: char const * method_name, char const * param_info, va_list args)); + MOCK_METHOD4(wf_jsonrpc_proxy_vnotify, void ( + struct wf_jsonrpc_proxy * proxy, + char const * method_name, + char const * param_info, + va_list args)); }; diff --git a/test/webfuse/tests/adapter/operation/test_close.cc b/test/webfuse/tests/adapter/operation/test_close.cc new file mode 100644 index 0000000..b7a7a9b --- /dev/null +++ b/test/webfuse/tests/adapter/operation/test_close.cc @@ -0,0 +1,56 @@ +#include "webfuse/adapter/impl/operation/close.h" +#include + +#include "webfuse/mocks/mock_fuse.hpp" +#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/mocks/mock_jsonrpc_proxy.hpp" + +#include + +using webfuse_test::MockJsonRpcProxy; +using webfuse_test::MockOperationsContext; +using webfuse_test::FuseMock; +using testing::_; +using testing::Return; +using testing::StrEq; + +TEST(wf_impl_operation_close, notify_proxy) +{ + MockJsonRpcProxy proxy; + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vnotify(_,StrEq("close"),StrEq("siii"),_)).Times(1); + + MockOperationsContext context; + EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + .WillOnce(Return(reinterpret_cast(&proxy))); + + wf_impl_operations_context op_context; + op_context.name = nullptr; + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); + EXPECT_CALL(fuse, fuse_reply_err(_, 0)).Times(1).WillOnce(Return(0)); + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + fuse_file_info file_info; + file_info.flags = 0; + wf_impl_operation_close(request, inode, &file_info); +} + +TEST(wf_impl_operation_close, fail_rpc_null) +{ + MockJsonRpcProxy proxy; + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vnotify(_,_,_,_)).Times(0); + + MockOperationsContext context; + EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + .WillOnce(Return(nullptr)); + + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(nullptr)); + EXPECT_CALL(fuse, fuse_reply_err(_, 0)).Times(1).WillOnce(Return(0)); + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + fuse_file_info * file_info = nullptr; + wf_impl_operation_close(request, inode, file_info); +}