From 220df4ad5001e0c92682c5dc860a1f815049062f Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 21 Mar 2020 21:08:25 +0100 Subject: [PATCH 01/43] specify branch detection --- codecov.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/codecov.yml b/codecov.yml index 2efff1f..c629bb3 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,2 +1,10 @@ ignore: - test + +parsers: + gcov: + branch_detection: + conditional: yes + loop: yes + method: no + macro: no From 214d6b738d4f586e63922361337415c45ad7a4d7 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 21 Mar 2020 21:22:22 +0100 Subject: [PATCH 02/43] removed NULL-checks after malloc: they are not necessary, they were not consequently used and objects constructed by 3rd party libs are also unchecked --- lib/webfuse/adapter/impl/authenticator.c | 11 +++---- lib/webfuse/adapter/impl/filesystem.c | 11 +++---- lib/webfuse/adapter/impl/operation/read.c | 2 +- lib/webfuse/adapter/impl/server.c | 11 +++---- lib/webfuse/adapter/impl/server_config.c | 5 +-- lib/webfuse/adapter/impl/server_protocol.c | 11 +++---- lib/webfuse/adapter/impl/session.c | 21 ++++++------- lib/webfuse/core/message.c | 9 ++---- lib/webfuse/core/string.c | 19 +++++------ lib/webfuse/provider/impl/client.c | 33 +++++++++----------- lib/webfuse/provider/impl/client_config.c | 11 +++---- lib/webfuse/provider/impl/client_protocol.c | 5 +-- lib/webfuse/provider/impl/dirbuffer.c | 5 +-- lib/webfuse/provider/impl/operation/read.c | 21 +++++-------- lib/webfuse/provider/impl/request.c | 9 ++---- lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c | 11 +++---- lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c | 5 +-- lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c | 9 ++---- lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c | 5 +-- lib/wf/timer/src/wf/timer/impl/manager.c | 5 +-- test/webfuse/utils/path.c | 27 +++++++--------- test/webfuse/utils/static_filesystem.c | 23 ++++++-------- 22 files changed, 101 insertions(+), 168 deletions(-) diff --git a/lib/webfuse/adapter/impl/authenticator.c b/lib/webfuse/adapter/impl/authenticator.c index 0be4b62..562a1dd 100644 --- a/lib/webfuse/adapter/impl/authenticator.c +++ b/lib/webfuse/adapter/impl/authenticator.c @@ -11,13 +11,10 @@ struct wf_impl_authenticator * wf_impl_authenticator_create( void * user_data) { struct wf_impl_authenticator * authenticator = malloc(sizeof(struct wf_impl_authenticator)); - if (NULL != authenticator) - { - authenticator->type = strdup(type); - authenticator->authenticate = authenticate; - authenticator->user_data = user_data; - authenticator->next = NULL; - } + authenticator->type = strdup(type); + authenticator->authenticate = authenticate; + authenticator->user_data = user_data; + authenticator->next = NULL; return authenticator; } diff --git a/lib/webfuse/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c index 03c2217..b7966a1 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -99,14 +99,11 @@ struct wf_impl_filesystem * wf_impl_filesystem_create( struct wf_mountpoint * mountpoint) { struct wf_impl_filesystem * filesystem = malloc(sizeof(struct wf_impl_filesystem)); - if (NULL != filesystem) + bool success = wf_impl_filesystem_init(filesystem, session, name, mountpoint); + if (!success) { - bool success = wf_impl_filesystem_init(filesystem, session, name, mountpoint); - if (!success) - { - free(filesystem); - filesystem = NULL; - } + free(filesystem); + filesystem = NULL; } return filesystem; diff --git a/lib/webfuse/adapter/impl/operation/read.c b/lib/webfuse/adapter/impl/operation/read.c index 87330fc..8fa5bee 100644 --- a/lib/webfuse/adapter/impl/operation/read.c +++ b/lib/webfuse/adapter/impl/operation/read.c @@ -20,7 +20,7 @@ static char * wf_impl_fill_buffer( *status = WF_GOOD; char * buffer = malloc(count); - if ((NULL != buffer) && (0 < count)) + if (0 < count) { if (0 == strcmp("identity", format)) { diff --git a/lib/webfuse/adapter/impl/server.c b/lib/webfuse/adapter/impl/server.c index f6e1f63..8f9a01d 100644 --- a/lib/webfuse/adapter/impl/server.c +++ b/lib/webfuse/adapter/impl/server.c @@ -83,13 +83,10 @@ struct wf_server * wf_impl_server_create( if (wf_impl_mountpoint_factory_isvalid(&config->mountpoint_factory)) { server = malloc(sizeof(struct wf_server)); - if (NULL != server) - { - wf_impl_server_protocol_init(&server->protocol, &config->mountpoint_factory); - wf_impl_server_config_clone(config, &server->config); - wf_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators); - server->context = wf_impl_server_context_create(server); - } + wf_impl_server_protocol_init(&server->protocol, &config->mountpoint_factory); + wf_impl_server_config_clone(config, &server->config); + wf_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators); + server->context = wf_impl_server_context_create(server); } return server; diff --git a/lib/webfuse/adapter/impl/server_config.c b/lib/webfuse/adapter/impl/server_config.c index bcf022e..ab214f3 100644 --- a/lib/webfuse/adapter/impl/server_config.c +++ b/lib/webfuse/adapter/impl/server_config.c @@ -56,10 +56,7 @@ void wf_impl_server_config_clone( struct wf_server_config * wf_impl_server_config_create(void) { struct wf_server_config * config = malloc(sizeof(struct wf_server_config)); - if (NULL != config) - { - wf_impl_server_config_init(config); - } + wf_impl_server_config_init(config); return config; } diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index 927d1cb..ee5cbb0 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -85,14 +85,11 @@ struct wf_server_protocol * wf_impl_server_protocol_create( void * create_mountpoint_context) { struct wf_server_protocol * protocol = malloc(sizeof(struct wf_server_protocol)); - if (NULL != protocol) - { - struct wf_impl_mountpoint_factory mountpoint_factory; - wf_impl_mountpoint_factory_init(&mountpoint_factory, - create_mountpoint, create_mountpoint_context); + struct wf_impl_mountpoint_factory mountpoint_factory; + wf_impl_mountpoint_factory_init(&mountpoint_factory, + create_mountpoint, create_mountpoint_context); - wf_impl_server_protocol_init(protocol, &mountpoint_factory); - } + wf_impl_server_protocol_init(protocol, &mountpoint_factory); return protocol; diff --git a/lib/webfuse/adapter/impl/session.c b/lib/webfuse/adapter/impl/session.c index e1fdd87..778d155 100644 --- a/lib/webfuse/adapter/impl/session.c +++ b/lib/webfuse/adapter/impl/session.c @@ -51,18 +51,15 @@ struct wf_impl_session * wf_impl_session_create( { struct wf_impl_session * session = malloc(sizeof(struct wf_impl_session)); - if (NULL != session) - { - wf_slist_init(&session->filesystems); - - session->wsi = wsi; - session->is_authenticated = false; - session->authenticators = authenticators; - session->server = server; - session->mountpoint_factory = mountpoint_factory; - session->rpc = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session); - wf_slist_init(&session->messages); - } + wf_slist_init(&session->filesystems); + + session->wsi = wsi; + session->is_authenticated = false; + session->authenticators = authenticators; + session->server = server; + session->mountpoint_factory = mountpoint_factory; + session->rpc = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session); + wf_slist_init(&session->messages); return session; } diff --git a/lib/webfuse/core/message.c b/lib/webfuse/core/message.c index e94d1c6..bfb0016 100644 --- a/lib/webfuse/core/message.c +++ b/lib/webfuse/core/message.c @@ -12,13 +12,10 @@ extern struct wf_message * wf_message_create(json_t const * value) { char * data = malloc(sizeof(struct wf_message) + LWS_PRE + length); message = (struct wf_message *) data; - if (NULL != message) - { - message->data = &data[sizeof(struct wf_message) + LWS_PRE]; - message->length = length; + message->data = &data[sizeof(struct wf_message) + LWS_PRE]; + message->length = length; - json_dumpb(value, message->data, length, JSON_COMPACT); - } + json_dumpb(value, message->data, length, JSON_COMPACT); } return message; diff --git a/lib/webfuse/core/string.c b/lib/webfuse/core/string.c index c5117eb..84608cb 100644 --- a/lib/webfuse/core/string.c +++ b/lib/webfuse/core/string.c @@ -16,18 +16,15 @@ char * wf_create_string(char const * format, ...) if (0 <= needed) { result = malloc(needed + 1); - if (NULL != result) - { - va_list args; - va_start(args, format); - int count = vsnprintf(result, needed + 1, format, args); - va_end(args); + va_list args; + va_start(args, format); + int count = vsnprintf(result, needed + 1, format, args); + va_end(args); - if ((count < 0) || (needed < count)) - { - free(result); - result = NULL; - } + if ((count < 0) || (needed < count)) + { + free(result); + result = NULL; } } diff --git a/lib/webfuse/provider/impl/client.c b/lib/webfuse/provider/impl/client.c index 21af148..c3b432c 100644 --- a/lib/webfuse/provider/impl/client.c +++ b/lib/webfuse/provider/impl/client.c @@ -30,27 +30,24 @@ struct wfp_client * wfp_impl_client_create( wf_lwslog_disable(); struct wfp_client * client = malloc(sizeof(struct wfp_client)); - if (NULL != client) + wfp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data); + + memset(client->protocols, 0, sizeof(struct lws_protocols) * WFP_CLIENT_PROTOCOL_COUNT); + wfp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]); + + memset(&client->info, 0, sizeof(struct lws_context_creation_info)); + client->info.port = CONTEXT_PORT_NO_LISTEN; + client->info.protocols = client->protocols; + client->info.uid = -1; + client->info.gid = -1; + + if ((NULL != config->cert_path) && (NULL != config->key_path)) { - wfp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data); - - memset(client->protocols, 0, sizeof(struct lws_protocols) * WFP_CLIENT_PROTOCOL_COUNT); - wfp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]); - - memset(&client->info, 0, sizeof(struct lws_context_creation_info)); - client->info.port = CONTEXT_PORT_NO_LISTEN; - client->info.protocols = client->protocols; - client->info.uid = -1; - client->info.gid = -1; - - if ((NULL != config->cert_path) && (NULL != config->key_path)) - { - - } - - client->context = lws_create_context(&client->info); + } + client->context = lws_create_context(&client->info); + return client; } diff --git a/lib/webfuse/provider/impl/client_config.c b/lib/webfuse/provider/impl/client_config.c index 0e8afc6..3bbb3ea 100644 --- a/lib/webfuse/provider/impl/client_config.c +++ b/lib/webfuse/provider/impl/client_config.c @@ -6,13 +6,10 @@ struct wfp_client_config * wfp_impl_client_config_create(void) { struct wfp_client_config * config = malloc(sizeof(struct wfp_client_config)); - if (NULL != config) - { - wfp_impl_provider_init(&config->provider); - config->user_data = NULL; - config->key_path = NULL; - config->cert_path = NULL; - } + wfp_impl_provider_init(&config->provider); + config->user_data = NULL; + config->key_path = NULL; + config->cert_path = NULL; return config; } diff --git a/lib/webfuse/provider/impl/client_protocol.c b/lib/webfuse/provider/impl/client_protocol.c index 4f61b8a..4e2b176 100644 --- a/lib/webfuse/provider/impl/client_protocol.c +++ b/lib/webfuse/provider/impl/client_protocol.c @@ -270,10 +270,7 @@ struct wfp_client_protocol * wfp_impl_client_protocol_create( struct wfp_client_config const * config) { struct wfp_client_protocol * protocol = malloc(sizeof(struct wfp_client_protocol)); - if (NULL != protocol) - { - wfp_impl_client_protocol_init(protocol, &config->provider, config->user_data); - } + wfp_impl_client_protocol_init(protocol, &config->provider, config->user_data); return protocol; } diff --git a/lib/webfuse/provider/impl/dirbuffer.c b/lib/webfuse/provider/impl/dirbuffer.c index db401ef..9bc5f22 100644 --- a/lib/webfuse/provider/impl/dirbuffer.c +++ b/lib/webfuse/provider/impl/dirbuffer.c @@ -4,10 +4,7 @@ struct wfp_dirbuffer * wfp_impl_dirbuffer_create(void) { struct wfp_dirbuffer * buffer = malloc(sizeof(struct wfp_dirbuffer)); - if (NULL != buffer) - { - buffer->entries = json_array(); - } + buffer->entries = json_array(); return buffer; } diff --git a/lib/webfuse/provider/impl/operation/read.c b/lib/webfuse/provider/impl/operation/read.c index 3101ea0..7be4bf3 100644 --- a/lib/webfuse/provider/impl/operation/read.c +++ b/lib/webfuse/provider/impl/operation/read.c @@ -56,22 +56,15 @@ void wfp_impl_respond_read( { size_t const size = wf_base64_encoded_size(length) + 1; char * buffer = malloc(size); - if (NULL != buffer) - { - wf_base64_encode((uint8_t const *) data, length, buffer, size); + wf_base64_encode((uint8_t const *) data, length, buffer, size); - json_t * result = json_object(); - json_object_set_new(result, "data", json_string(buffer)); - json_object_set_new(result, "format", json_string("base64")); - json_object_set_new(result, "count", json_integer((int) length)); + json_t * result = json_object(); + json_object_set_new(result, "data", json_string(buffer)); + json_object_set_new(result, "format", json_string("base64")); + json_object_set_new(result, "count", json_integer((int) length)); - wfp_impl_respond(request, result); - free(buffer); - } - else - { - wfp_impl_respond_error(request, WF_BAD); - } + wfp_impl_respond(request, result); + free(buffer); } else { diff --git a/lib/webfuse/provider/impl/request.c b/lib/webfuse/provider/impl/request.c index 42ea835..7f8b05f 100644 --- a/lib/webfuse/provider/impl/request.c +++ b/lib/webfuse/provider/impl/request.c @@ -8,12 +8,9 @@ struct wfp_request * wfp_impl_request_create( int id) { struct wfp_request * request = malloc(sizeof(struct wfp_request)); - if (NULL != request) - { - request->respond = prototype->respond; - request->user_data = prototype->user_data; - request->id = id; - } + request->respond = prototype->respond; + request->user_data = prototype->user_data; + request->id = id; return request; } diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c index 87b3ff1..ef0d16c 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c @@ -8,13 +8,10 @@ struct wf_jsonrpc_method * wf_jsonrpc_impl_method_create( void * user_data) { struct wf_jsonrpc_method * method = malloc(sizeof(struct wf_jsonrpc_method)); - if (NULL != method) - { - method->next = NULL; - method->name = strdup(method_name); - method->invoke = invoke; - method->user_data = user_data; - } + method->next = NULL; + method->name = strdup(method_name); + method->invoke = invoke; + method->user_data = user_data; return method; } diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c index a2b9816..99b3f03 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c @@ -16,10 +16,7 @@ wf_jsonrpc_impl_proxy_create( void * user_data) { struct wf_jsonrpc_proxy * proxy = malloc(sizeof(struct wf_jsonrpc_proxy)); - if (NULL != proxy) - { - wf_jsonrpc_impl_proxy_init(proxy, manager, timeout, send, user_data); - } + wf_jsonrpc_impl_proxy_init(proxy, manager, timeout, send, user_data); return proxy; } diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c index e46f19e..071ec4b 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c @@ -29,12 +29,9 @@ wf_jsonrpc_impl_request_create( void * user_data) { struct wf_jsonrpc_request * request = malloc(sizeof(struct wf_jsonrpc_request)); - if (NULL != request) - { - request->id = id; - request->send = send; - request->user_data = user_data; - } + request->id = id; + request->send = send; + request->user_data = user_data; return request; } diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c index e510daa..b3e27c8 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c @@ -24,10 +24,7 @@ struct wf_jsonrpc_server * wf_jsonrpc_impl_server_create(void) { struct wf_jsonrpc_server * server = malloc(sizeof(struct wf_jsonrpc_server)); - if (NULL != server) - { - wf_jsonrpc_impl_server_init(server); - } + wf_jsonrpc_impl_server_init(server); return server; } diff --git a/lib/wf/timer/src/wf/timer/impl/manager.c b/lib/wf/timer/src/wf/timer/impl/manager.c index 2b00f80..f198502 100644 --- a/lib/wf/timer/src/wf/timer/impl/manager.c +++ b/lib/wf/timer/src/wf/timer/impl/manager.c @@ -14,10 +14,7 @@ struct wf_timer_manager * wf_timer_impl_manager_create(void) { struct wf_timer_manager * manager = malloc(sizeof(struct wf_timer_manager)); - if (NULL != manager) - { - manager->timers = NULL; - } + manager->timers = NULL; return manager; } diff --git a/test/webfuse/utils/path.c b/test/webfuse/utils/path.c index 3cb222e..e63aafb 100644 --- a/test/webfuse/utils/path.c +++ b/test/webfuse/utils/path.c @@ -45,24 +45,21 @@ wf_path_create( char const * value) { struct wf_path * path = malloc(sizeof(struct wf_path)); - if (NULL != path) + path->elements = malloc(sizeof(char*) * WF_PATH_DEFAULT_CAPACITY); + path->capacity = WF_PATH_DEFAULT_CAPACITY; + path->count = 0; + + char const * remainder = value; + char const * pos = strchr(remainder, '/'); + while (NULL != pos) { - path->elements = malloc(sizeof(char*) * WF_PATH_DEFAULT_CAPACITY); - path->capacity = WF_PATH_DEFAULT_CAPACITY; - path->count = 0; - - char const * remainder = value; - char const * pos = strchr(remainder, '/'); - while (NULL != pos) - { - wf_path_add(path, remainder, (pos - remainder)); - remainder = pos + 1; - pos = strchr(remainder, '/'); - } - - wf_path_add(path, remainder, strlen(remainder)); + wf_path_add(path, remainder, (pos - remainder)); + remainder = pos + 1; + pos = strchr(remainder, '/'); } + wf_path_add(path, remainder, strlen(remainder)); + return path; } diff --git a/test/webfuse/utils/static_filesystem.c b/test/webfuse/utils/static_filesystem.c index 62b507a..855564b 100644 --- a/test/webfuse/utils/static_filesystem.c +++ b/test/webfuse/utils/static_filesystem.c @@ -332,21 +332,18 @@ wfp_static_filesystem_create( (void) config; struct wfp_static_filesystem * filesystem = malloc(sizeof(struct wfp_static_filesystem)); - if (NULL != filesystem) - { - filesystem->entries = malloc(sizeof(struct wfp_static_filesystem_entry) * WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY); - filesystem->size = 0; - filesystem->capacity = WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY; + filesystem->entries = malloc(sizeof(struct wfp_static_filesystem_entry) * WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY); + filesystem->size = 0; + filesystem->capacity = WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY; - wfp_static_filesystem_add_dir(filesystem, 0, ""); + wfp_static_filesystem_add_dir(filesystem, 0, ""); - wfp_client_config_set_userdata(config, filesystem); - wfp_client_config_set_onlookup(config, &wfp_static_filesystem_lookup); - wfp_client_config_set_ongetattr(config, &wfp_static_filesystem_getattr); - wfp_client_config_set_onreaddir(config, &wfp_static_filesystem_readdir); - wfp_client_config_set_onopen(config, &wfp_static_filesystem_open); - wfp_client_config_set_onread(config, &wfp_static_filesystem_read); - } + wfp_client_config_set_userdata(config, filesystem); + wfp_client_config_set_onlookup(config, &wfp_static_filesystem_lookup); + wfp_client_config_set_ongetattr(config, &wfp_static_filesystem_getattr); + wfp_client_config_set_onreaddir(config, &wfp_static_filesystem_readdir); + wfp_client_config_set_onopen(config, &wfp_static_filesystem_open); + wfp_client_config_set_onread(config, &wfp_static_filesystem_read); return filesystem; } From 6a2b423a105ded958ee25154c2bdeb40d9c3ad10 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 21 Mar 2020 21:57:33 +0100 Subject: [PATCH 03/43] enhanced branch detection --- codecov.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codecov.yml b/codecov.yml index c629bb3..0937e15 100644 --- a/codecov.yml +++ b/codecov.yml @@ -6,5 +6,5 @@ parsers: branch_detection: conditional: yes loop: yes - method: no - macro: no + method: yes + macro: yes From b3ec92b202390a591b35b97b0de8ab674371e07c Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 21 Mar 2020 22:06:36 +0100 Subject: [PATCH 04/43] ignore test dirs --- codecov.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codecov.yml b/codecov.yml index 0937e15..e0d4bce 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,5 +1,7 @@ ignore: - test + - lib/wf/timer/test + - lib/wf/jsonrpc/test parsers: gcov: From 71a8c30d36abcd76533ffbcbb0ff0fb2e1b47641 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 21 Mar 2020 22:25:50 +0100 Subject: [PATCH 05/43] increased test coverage --- .../webfuse/tests/adapter/test_credentials.cc | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/test/webfuse/tests/adapter/test_credentials.cc b/test/webfuse/tests/adapter/test_credentials.cc index 72350d4..88e2552 100644 --- a/test/webfuse/tests/adapter/test_credentials.cc +++ b/test/webfuse/tests/adapter/test_credentials.cc @@ -1,5 +1,6 @@ #include +#include "webfuse/adapter/credentials.h" #include "webfuse/adapter/impl/credentials.h" #include @@ -8,7 +9,7 @@ TEST(Credentials, Type) struct wf_credentials creds; wf_impl_credentials_init(&creds, "test", nullptr); - ASSERT_STREQ("test", wf_impl_credentials_type(&creds)); + ASSERT_STREQ("test", wf_credentials_type(&creds)); wf_impl_credentials_cleanup(&creds); } @@ -20,9 +21,9 @@ TEST(Credentials, Get) json_object_set_new(data, "password", json_string("")); wf_impl_credentials_init(&creds, "username", data); - ASSERT_STREQ("username", wf_impl_credentials_type(&creds)); - ASSERT_STREQ("bob", wf_impl_credentials_get(&creds, "username")); - ASSERT_STREQ("", wf_impl_credentials_get(&creds, "password")); + ASSERT_STREQ("username", wf_credentials_type(&creds)); + ASSERT_STREQ("bob", wf_credentials_get(&creds, "username")); + ASSERT_STREQ("", wf_credentials_get(&creds, "password")); wf_impl_credentials_cleanup(&creds); json_decref(data); @@ -34,9 +35,9 @@ TEST(Credentials, FailedToGetNonexistingValue) json_t * data = json_object(); wf_impl_credentials_init(&creds, "username", data); - ASSERT_STREQ("username", wf_impl_credentials_type(&creds)); - ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "username")); - ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "password")); + ASSERT_STREQ("username", wf_credentials_type(&creds)); + ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "username")); + ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "password")); wf_impl_credentials_cleanup(&creds); json_decref(data); @@ -47,9 +48,9 @@ TEST(Credentials, FailedToGetWithoutData) struct wf_credentials creds; wf_impl_credentials_init(&creds, "username", nullptr); - ASSERT_STREQ("username", wf_impl_credentials_type(&creds)); - ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "username")); - ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "password")); + ASSERT_STREQ("username", wf_credentials_type(&creds)); + ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "username")); + ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "password")); wf_impl_credentials_cleanup(&creds); } @@ -60,11 +61,25 @@ TEST(Credentials, FailedToGetWrongDataType) json_t * data = json_string("invalid_creds"); wf_impl_credentials_init(&creds, "username", data); - ASSERT_STREQ("username", wf_impl_credentials_type(&creds)); - ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "username")); - ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "password")); + ASSERT_STREQ("username", wf_credentials_type(&creds)); + ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "username")); + ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "password")); wf_impl_credentials_cleanup(&creds); json_decref(data); } +TEST(Credentials, FailedToGetWrongElementDataType) +{ + struct wf_credentials creds; + json_t * data = json_object(); + json_object_set_new(data, "username", json_integer(42)); + + wf_impl_credentials_init(&creds, "username", data); + ASSERT_STREQ("username", wf_credentials_type(&creds)); + ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "username")); + ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "password")); + + wf_impl_credentials_cleanup(&creds); + json_decref(data); +} From d5adfc6f81803386c142160e4c1113e7d4b44d02 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 22 Mar 2020 11:36:45 +0100 Subject: [PATCH 06/43] increased test coverage --- lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc | 120 +++++++++++++++++- 1 file changed, 119 insertions(+), 1 deletion(-) diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc index 14f7ac5..894c607 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc @@ -69,6 +69,36 @@ TEST(wf_jsonrpc_server, process_request) wf_jsonrpc_server_dispose(server); } +TEST(wf_jsonrpc_server, process_request_with_oject_params) +{ + struct wf_jsonrpc_server * server = wf_jsonrpc_server_create(); + wf_jsonrpc_server_add(server, "sayHello", &sayHello, nullptr); + + Context context{nullptr, false}; + void * user_data = reinterpret_cast(&context); + json_t * request = json_object(); + json_object_set_new(request, "method", json_string("sayHello")); + json_object_set_new(request, "params", json_object()); + json_object_set_new(request, "id", json_integer(23)); + wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data); + + ASSERT_TRUE(context.is_called); + ASSERT_NE(nullptr, context.response); + ASSERT_TRUE(json_is_object(context.response)); + + json_t * id = json_object_get(context.response, "id"); + ASSERT_TRUE(json_is_integer(id)); + ASSERT_EQ(23, json_integer_value(id)); + + json_t * result = json_object_get(context.response, "result"); + ASSERT_TRUE(json_is_string(result)); + ASSERT_STREQ("Hello", json_string_value(result)); + + json_decref(context.response); + json_decref(request); + wf_jsonrpc_server_dispose(server); +} + TEST(wf_jsonrpc_server, invoke_unknown_method) { struct wf_jsonrpc_server * server = wf_jsonrpc_server_create(); @@ -105,7 +135,7 @@ TEST(wf_jsonrpc_server, invoke_unknown_method) wf_jsonrpc_server_dispose(server); } -TEST(wf_jsonrpc_server, skip_invalid_request) +TEST(wf_jsonrpc_server, skip_invalid_request_missing_id) { struct wf_jsonrpc_server * server = wf_jsonrpc_server_create(); @@ -121,3 +151,91 @@ TEST(wf_jsonrpc_server, skip_invalid_request) json_decref(request); wf_jsonrpc_server_dispose(server); } + +TEST(wf_jsonrpc_server, skip_invalid_request_wrong_id_type) +{ + struct wf_jsonrpc_server * server = wf_jsonrpc_server_create(); + + Context context{nullptr, false}; + void * user_data = reinterpret_cast(&context); + json_t * request = json_object(); + json_object_set_new(request, "method", json_string("sayHello")); + json_object_set_new(request, "params", json_array()); + json_object_set_new(request, "id", json_string("42")); + wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data); + + ASSERT_FALSE(context.is_called); + + json_decref(request); + wf_jsonrpc_server_dispose(server); +} + +TEST(wf_jsonrpc_server, skip_invalid_request_missing_params) +{ + struct wf_jsonrpc_server * server = wf_jsonrpc_server_create(); + + Context context{nullptr, false}; + void * user_data = reinterpret_cast(&context); + json_t * request = json_object(); + json_object_set_new(request, "method", json_string("sayHello")); + json_object_set_new(request, "id", json_integer(42)); + wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data); + + ASSERT_FALSE(context.is_called); + + json_decref(request); + wf_jsonrpc_server_dispose(server); +} + +TEST(wf_jsonrpc_server, skip_invalid_request_wrong_params_type) +{ + struct wf_jsonrpc_server * server = wf_jsonrpc_server_create(); + + Context context{nullptr, false}; + void * user_data = reinterpret_cast(&context); + json_t * request = json_object(); + json_object_set_new(request, "method", json_string("sayHello")); + json_object_set_new(request, "params", json_string("invalid")); + json_object_set_new(request, "id", json_integer(42)); + wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data); + + ASSERT_FALSE(context.is_called); + + json_decref(request); + wf_jsonrpc_server_dispose(server); +} + +TEST(wf_jsonrpc_server, skip_invalid_request_missing_method) +{ + struct wf_jsonrpc_server * server = wf_jsonrpc_server_create(); + + Context context{nullptr, false}; + void * user_data = reinterpret_cast(&context); + json_t * request = json_object(); + json_object_set_new(request, "params", json_array()); + json_object_set_new(request, "id", json_integer(42)); + wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data); + + ASSERT_FALSE(context.is_called); + + json_decref(request); + wf_jsonrpc_server_dispose(server); +} + +TEST(wf_jsonrpc_server, skip_invalid_request_wront_method_type) +{ + struct wf_jsonrpc_server * server = wf_jsonrpc_server_create(); + + Context context{nullptr, false}; + void * user_data = reinterpret_cast(&context); + json_t * request = json_object(); + json_object_set_new(request, "method", json_integer(42)); + json_object_set_new(request, "params", json_array()); + json_object_set_new(request, "id", json_integer(42)); + wf_jsonrpc_server_process(server, request, &jsonrpc_send, user_data); + + ASSERT_FALSE(context.is_called); + + json_decref(request); + wf_jsonrpc_server_dispose(server); +} \ No newline at end of file From 843368f483ef1437d1d548d93ef657e70bccbed8 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 22 Mar 2020 12:51:54 +0100 Subject: [PATCH 07/43] increased test coverage --- lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c | 2 +- .../jsonrpc/test/wf/jsonrpc/test_response.cc | 91 ++++++++++++++++++- 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c index 07171fb..f9fe180 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c +++ b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c @@ -25,7 +25,7 @@ wf_jsonrpc_impl_response_init( result->error = NULL; json_t * id_holder = json_object_get(response, "id"); - if ((NULL == id_holder) || (!json_is_integer(id_holder))) + if (!json_is_integer(id_holder)) { result->error = wf_jsonrpc_impl_error(WF_JSONRPC_BAD_FORMAT, "invalid format: missing id"); return; diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc index e8515aa..b71d7f3 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc @@ -41,7 +41,7 @@ TEST(wf_json_response, init_error) json_decref(message); } -TEST(wf_json_response, init_format_error) +TEST(wf_json_response, init_fail_missing_result_and_error) { json_t * message = json_object(); json_object_set_new(message, "id", json_integer(12)); @@ -56,3 +56,92 @@ TEST(wf_json_response, init_format_error) wf_jsonrpc_impl_response_cleanup(&response); json_decref(message); } + +TEST(wf_json_response, init_fail_missing_id) +{ + json_t * message = json_object(); + json_object_set_new(message, "result", json_integer(47)); + + struct wf_jsonrpc_response response; + wf_jsonrpc_impl_response_init(&response, message); + + ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); + ASSERT_EQ(nullptr, response.result); + ASSERT_EQ(-1, response.id); + + wf_jsonrpc_impl_response_cleanup(&response); + json_decref(message); +} + +TEST(wf_json_response, init_fail_wrong_id_type) +{ + json_t * message = json_object(); + json_object_set_new(message, "result", json_integer(47)); + json_object_set_new(message, "id", json_string("42")); + + struct wf_jsonrpc_response response; + wf_jsonrpc_impl_response_init(&response, message); + + ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); + ASSERT_EQ(nullptr, response.result); + ASSERT_EQ(-1, response.id); + + wf_jsonrpc_impl_response_cleanup(&response); + json_decref(message); +} + +TEST(wf_json_response, init_fail_error_missing_code) +{ + json_t * message = json_object(); + json_t * err = json_object(); + json_object_set_new(err, "message", json_string("Don't Panic!")); + json_object_set_new(message, "error", err); + json_object_set_new(message, "id", json_integer(23)); + + struct wf_jsonrpc_response response; + wf_jsonrpc_impl_response_init(&response, message); + + ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); + ASSERT_EQ(nullptr, response.result); + ASSERT_EQ(23, response.id); + + wf_jsonrpc_impl_response_cleanup(&response); + json_decref(message); +} + +TEST(wf_json_response, init_fail_error_wrong_code_type) +{ + json_t * message = json_object(); + json_t * err = json_object(); + json_object_set_new(err, "code", json_string("42")); + json_object_set_new(err, "message", json_string("Don't Panic!")); + json_object_set_new(message, "error", err); + json_object_set_new(message, "id", json_integer(23)); + + struct wf_jsonrpc_response response; + wf_jsonrpc_impl_response_init(&response, message); + + ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); + ASSERT_EQ(nullptr, response.result); + ASSERT_EQ(23, response.id); + + wf_jsonrpc_impl_response_cleanup(&response); + json_decref(message); +} + +TEST(wf_json_response, init_fail_error_wrong_type) +{ + json_t * message = json_object(); + json_object_set_new(message, "error", json_string("invalid error type")); + json_object_set_new(message, "id", json_integer(23)); + + struct wf_jsonrpc_response response; + wf_jsonrpc_impl_response_init(&response, message); + + ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); + ASSERT_EQ(nullptr, response.result); + ASSERT_EQ(23, response.id); + + wf_jsonrpc_impl_response_cleanup(&response); + json_decref(message); +} From 643d1d52373c9264808887c7cffbd6830de479f5 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 22 Mar 2020 13:36:03 +0100 Subject: [PATCH 08/43] increased test coverage --- .../jsonrpc/test/wf/jsonrpc/test_request.cc | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc index eb15e91..a8f7986 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc @@ -101,3 +101,38 @@ TEST(wf_jsonrpc_request, respond_error) json_decref(response); } + +TEST(wf_jsonrpc_request, is_request_object_params) +{ + json_t * request = json_object(); + json_object_set_new(request, "method", json_string("some_method")); + json_object_set_new(request, "params", json_object()); + json_object_set_new(request, "id", json_integer(42)); + + ASSERT_TRUE(wf_jsonrpc_is_request(request)); + + json_decref(request); +} + +TEST(wf_jsonrpc_request, is_request_fail_missing_params) +{ + json_t * request = json_object(); + json_object_set_new(request, "method", json_string("some_method")); + json_object_set_new(request, "id", json_integer(42)); + + ASSERT_FALSE(wf_jsonrpc_is_request(request)); + + json_decref(request); +} + +TEST(wf_jsonrpc_request, is_request_fail_params_wrong_type) +{ + json_t * request = json_object(); + json_object_set_new(request, "method", json_string("some_method")); + json_object_set_new(request, "params", json_string("invalid_params")); + json_object_set_new(request, "id", json_integer(42)); + + ASSERT_FALSE(wf_jsonrpc_is_request(request)); + + json_decref(request); +} From 7e1d9bbb507267f3f565a5d56385fd6586dfdf7a Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 22 Mar 2020 17:41:34 +0100 Subject: [PATCH 09/43] increased test coverage --- lib/wf/timer/test/wf/timer/test_timer.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/wf/timer/test/wf/timer/test_timer.cc b/lib/wf/timer/test/wf/timer/test_timer.cc index e97c011..2141314 100644 --- a/lib/wf/timer/test/wf/timer/test_timer.cc +++ b/lib/wf/timer/test/wf/timer/test_timer.cc @@ -37,8 +37,7 @@ TEST(wf_timer, trigger) struct wf_timer_manager * manager = wf_timer_manager_create(); struct wf_timer * timer = wf_timer_create(manager, &on_timeout, reinterpret_cast(&triggered)); - wf_timer_start(timer, 250); - std::this_thread::sleep_for(500ms); + wf_timer_start(timer, -1); wf_timer_manager_check(manager); ASSERT_TRUE(triggered); @@ -135,3 +134,15 @@ TEST(wf_timer, multiple_timers) wf_timer_manager_dispose(manager); } + +TEST(wf_timer, dont_trigger_null_callback) +{ + struct wf_timer_manager * manager = wf_timer_manager_create(); + struct wf_timer * timer = wf_timer_create(manager, nullptr, nullptr); + + wf_timer_start(timer, -1); + wf_timer_manager_check(manager); + + wf_timer_dispose(timer); + wf_timer_manager_dispose(manager); +} From 1d4db34ecb2921a32c4cedb5b0d9923d5e9f0588 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 22 Mar 2020 20:09:40 +0100 Subject: [PATCH 10/43] increased test coverage --- cmake/unit_tests.cmake | 13 +++- lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc | 31 ++++++++ lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.hpp | 47 ++++++++++++ .../test/wf/jsonrpc/mock_timer_callback.cc | 41 ++++++++++ .../test/wf/jsonrpc/mock_timer_callback.hpp | 23 ++++++ lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc | 49 +++++++++++- lib/wf/jsonrpc/test/wf/jsonrpc/wrap.hpp | 74 +++++++++++++++++++ 7 files changed, 276 insertions(+), 2 deletions(-) create mode 100644 lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc create mode 100644 lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.hpp create mode 100644 lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc create mode 100644 lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.hpp create mode 100644 lib/wf/jsonrpc/test/wf/jsonrpc/wrap.hpp diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index aaf5381..1722301 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -7,6 +7,8 @@ include(GoogleTest) pkg_check_modules(GMOCK gmock) add_executable(alltests + lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc + lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc @@ -51,6 +53,7 @@ add_executable(alltests target_include_directories(alltests PRIVATE lib/wf/jsonrpc/include lib/wf/jsonrpc/src + lib/wf/jsonrpc/test lib/wf/timer/include lib/wf/timer/src ${FUSE3_INCLUDE_DIRS} @@ -60,7 +63,15 @@ target_compile_options(alltests PUBLIC ${FUSE3_CFLAGS_OTHER} ) -target_link_libraries(alltests PUBLIC +target_link_libraries(alltests PUBLIC + -Wl,--wrap=wf_timer_manager_create + -Wl,--wrap=wf_timer_manager_dispose + -Wl,--wrap=wf_timer_manager_check + -Wl,--wrap=wf_timer_create + -Wl,--wrap=wf_timer_dispose + -Wl,--wrap=wf_timer_start + -Wl,--wrap=wf_timer_cancel + webfuse-adapter-static webfuse-provider-static webfuse-core diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc new file mode 100644 index 0000000..bdfde2b --- /dev/null +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc @@ -0,0 +1,31 @@ +#include "wf/jsonrpc/mock_timer.hpp" +#include "wf/jsonrpc/wrap.hpp" + +extern "C" +{ +static wf_jsonrpc_test::ITimer * wf_jsonrpc_MockTimer = nullptr; + +WF_WRAP_FUNC0(wf_jsonrpc_MockTimer, wf_timer_manager *, wf_timer_manager_create); +WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_timer_manager_dispose, wf_timer_manager *); +WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_timer_manager_check, wf_timer_manager *); + +WF_WRAP_FUNC3(wf_jsonrpc_MockTimer, wf_timer *, wf_timer_create, wf_timer_manager *, wf_timer_on_timer_fn *, void *); +WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_timer_dispose, wf_timer *); +WF_WRAP_FUNC2(wf_jsonrpc_MockTimer, void, wf_timer_start, wf_timer *, int); +WF_WRAP_FUNC1(wf_jsonrpc_MockTimer, void, wf_timer_cancel, wf_timer *); + +} + +namespace wf_jsonrpc_test +{ +MockTimer::MockTimer() +{ + wf_jsonrpc_MockTimer = this; +} + +MockTimer::~MockTimer() +{ + wf_jsonrpc_MockTimer = nullptr; +} + +} \ No newline at end of file diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.hpp b/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.hpp new file mode 100644 index 0000000..3fde45e --- /dev/null +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.hpp @@ -0,0 +1,47 @@ +#ifndef WF_JSONRPC_MOCK_TIMERMANAGER_HPP +#define WF_JSONRPC_MOCK_TIMERMANAGER_HPP + +#include +#include + +namespace wf_jsonrpc_test +{ + +class ITimer +{ +public: + virtual ~ITimer() = default; + virtual wf_timer_manager * wf_timer_manager_create() = 0; + virtual void wf_timer_manager_dispose(wf_timer_manager * manager) = 0; + virtual void wf_timer_manager_check(wf_timer_manager * manager) = 0; + virtual wf_timer * wf_timer_create( + wf_timer_manager * manager, + wf_timer_on_timer_fn * on_timer, + void * user_data) = 0; + virtual void wf_timer_dispose(wf_timer * timer) = 0; + virtual void wf_timer_start(wf_timer * timer, int timeout_ms) = 0; + virtual void wf_timer_cancel(wf_timer * timer) = 0; +}; + +class MockTimer: public ITimer +{ +public: + MockTimer(); + ~MockTimer() override; + MOCK_METHOD0(wf_timer_manager_create, wf_timer_manager * ()); + MOCK_METHOD1(wf_timer_manager_dispose, void(wf_timer_manager * manager)); + MOCK_METHOD1(wf_timer_manager_check, void (wf_timer_manager * manager)); + MOCK_METHOD3(wf_timer_create, wf_timer *( + wf_timer_manager * manager, + wf_timer_on_timer_fn * on_timer, + void * user_data)); + MOCK_METHOD1(wf_timer_dispose, void (wf_timer * timer)); + MOCK_METHOD2(wf_timer_start, void (wf_timer * timer, int timeout_ms)); + MOCK_METHOD1(wf_timer_cancel, void (wf_timer * timer)); + +}; + + +} + +#endif diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc new file mode 100644 index 0000000..dd3cc3b --- /dev/null +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc @@ -0,0 +1,41 @@ +#include "wf/jsonrpc/mock_timer_callback.hpp" + +extern "C" +{ +using wf_jsonrpc_test::MockTimerCallback; + +static void wf_jsonrpc_test_MockTimerCallback_on_timer( + wf_timer * timer, + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + self->on_timer(timer, user_data); +} + +} + +namespace wf_jsonrpc_test +{ + +MockTimerCallback::MockTimerCallback() +{ + +} + +MockTimerCallback::~MockTimerCallback() +{ + +} + +wf_timer_on_timer_fn * MockTimerCallback::on_timer_fn() +{ + return &wf_jsonrpc_test_MockTimerCallback_on_timer; +} + +void * MockTimerCallback::user_data() +{ + return reinterpret_cast(this); +} + + +} \ No newline at end of file diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.hpp b/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.hpp new file mode 100644 index 0000000..cdbf2d6 --- /dev/null +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.hpp @@ -0,0 +1,23 @@ +#ifndef WF_JSONRPC_MOCK_TIMERCALLBACK_HPP +#define WF_JSONRPC_MOCK_TIMERCALLBACK_HPP + +#include "wf/timer.h" +#include + +namespace wf_jsonrpc_test +{ +class MockTimerCallback +{ +public: + MockTimerCallback(); + virtual ~MockTimerCallback(); + wf_timer_on_timer_fn * on_timer_fn(); + void * user_data(); + + MOCK_METHOD2(on_timer, void (wf_timer * timer, void * user_data)); + +}; + +} + +#endif diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc b/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc index 66eafa9..763fa51 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc @@ -3,11 +3,17 @@ #include "wf/jsonrpc/status.h" #include "wf/timer/manager.h" +#include "wf/jsonrpc/mock_timer.hpp" + #include #include using namespace std::chrono_literals; - +using wf_jsonrpc_test::MockTimer; +using testing::Return; +using testing::_; +using testing::DoAll; +using testing::SaveArg; #define WF_DEFAULT_TIMEOUT (10 * 1000) @@ -380,3 +386,44 @@ TEST(wf_jsonrpc_proxy, notify_dont_send_invalid_request) wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); } + +TEST(wf_jsonrpc_proxy, swallow_timeout_if_no_request_pending) +{ + MockTimer timer_api; + + wf_timer_on_timer_fn * on_timer = nullptr; + void * timer_context = nullptr; + EXPECT_CALL(timer_api, wf_timer_create(_, _, _)) + .Times(1) + .WillOnce(DoAll(SaveArg<1>(&on_timer), SaveArg<2>(&timer_context), Return(nullptr))); + + SendContext send_context; + void * send_data = reinterpret_cast(&send_context); + struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(nullptr, 1, &jsonrpc_send, send_data); + + on_timer(nullptr, timer_context); + ASSERT_FALSE(send_context.is_called); + + + wf_jsonrpc_proxy_dispose(proxy); +} + +TEST(wf_jsonrpc_proxy, on_result_swallow_if_no_request_pending) +{ + struct wf_timer_manager * timer_manager = wf_timer_manager_create(); + + SendContext send_context; + void * send_data = reinterpret_cast(&send_context); + struct wf_jsonrpc_proxy * proxy = wf_jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &jsonrpc_send, send_data); + + json_t * response = json_object(); + json_object_set_new(response, "result", json_string("okay")); + json_object_set_new(response, "id", json_integer(42)); + + wf_jsonrpc_proxy_onresult(proxy, response); + json_decref(response); + + wf_jsonrpc_proxy_dispose(proxy); + wf_timer_manager_dispose(timer_manager); +} + diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/wrap.hpp b/lib/wf/jsonrpc/test/wf/jsonrpc/wrap.hpp new file mode 100644 index 0000000..9d062d8 --- /dev/null +++ b/lib/wf/jsonrpc/test/wf/jsonrpc/wrap.hpp @@ -0,0 +1,74 @@ +#ifndef WF_WRAP_HPP +#define WF_WRAP_HPP + +#define WF_WRAP_FUNC0( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME ) \ + extern RETURN_TYPE __real_ ## FUNC_NAME (); \ + RETURN_TYPE __wrap_ ## FUNC_NAME () \ + { \ + if (nullptr == GLOBAL_VAR ) \ + { \ + return __real_ ## FUNC_NAME (); \ + } \ + else \ + { \ + return GLOBAL_VAR -> FUNC_NAME(); \ + } \ + } + +#define WF_WRAP_FUNC1( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE ) \ + extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE); \ + RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1) \ + { \ + if (nullptr == GLOBAL_VAR ) \ + { \ + return __real_ ## FUNC_NAME (arg1); \ + } \ + else \ + { \ + return GLOBAL_VAR -> FUNC_NAME(arg1); \ + } \ + } + +#define WF_WRAP_FUNC2( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE ) \ + extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE); \ + RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2) \ + { \ + if (nullptr == GLOBAL_VAR ) \ + { \ + return __real_ ## FUNC_NAME (arg1, arg2); \ + } \ + else \ + { \ + return GLOBAL_VAR -> FUNC_NAME(arg1, arg2); \ + } \ + } + +#define WF_WRAP_FUNC3( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE ) \ + extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE); \ + RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3) \ + { \ + if (nullptr == GLOBAL_VAR ) \ + { \ + return __real_ ## FUNC_NAME (arg1, arg2, arg3); \ + } \ + else \ + { \ + return GLOBAL_VAR -> FUNC_NAME(arg1, arg2, arg3); \ + } \ + } + +#define WF_WRAP_FUNC4( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE ) \ + extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE); \ + RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3, ARG4_TYPE arg4) \ + { \ + if (nullptr == GLOBAL_VAR ) \ + { \ + return __real_ ## FUNC_NAME (arg1, arg2, arg3, arg4); \ + } \ + else \ + { \ + return GLOBAL_VAR -> FUNC_NAME(arg1, arg2, arg3, arg4); \ + } \ + } + +#endif From bbdd5a24f59f5b301b7d70c15134637fc8ec6143 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 29 Mar 2020 17:40:33 +0200 Subject: [PATCH 11/43] integrated libwf_timer and libwf_jsonrpc into libwebfuse-core --- CMakeLists.txt | 2 - cmake/unit_tests.cmake | 43 ++---- cmake/webfuse_adapter.cmake | 4 +- cmake/webfuse_core.cmake | 10 ++ cmake/webfuse_provider.cmake | 4 +- cmake/wf_jsonrpc.cmake | 24 --- cmake/wf_timer.cmake | 18 --- lib/webfuse/adapter/impl/operation/close.c | 2 +- lib/webfuse/adapter/impl/operation/getattr.c | 2 +- lib/webfuse/adapter/impl/operation/lookup.c | 2 +- lib/webfuse/adapter/impl/operation/open.c | 2 +- lib/webfuse/adapter/impl/operation/read.c | 2 +- lib/webfuse/adapter/impl/operation/readdir.c | 2 +- lib/webfuse/adapter/impl/server_protocol.c | 6 +- lib/webfuse/adapter/impl/server_protocol.h | 4 +- lib/webfuse/adapter/impl/session.c | 6 +- lib/webfuse/adapter/impl/session.h | 4 +- lib/webfuse/core/json_util.c | 23 +-- .../impl => webfuse/core/jsonrpc}/error.c | 8 +- .../impl => webfuse/core/jsonrpc}/error.h | 10 +- .../impl => webfuse/core/jsonrpc}/method.c | 6 +- .../impl => webfuse/core/jsonrpc}/method.h | 10 +- .../core}/jsonrpc/method_invoke_fn.h | 2 - .../impl => webfuse/core/jsonrpc}/proxy.c | 63 ++++---- .../wf => webfuse/core}/jsonrpc/proxy.h | 15 +- .../core}/jsonrpc/proxy_finished_fn.h | 0 lib/webfuse/core/jsonrpc/proxy_intern.h | 48 ++++++ .../impl => webfuse/core/jsonrpc}/request.c | 22 +-- .../wf => webfuse/core}/jsonrpc/request.h | 15 +- .../impl => webfuse/core/jsonrpc}/response.c | 16 +- .../wf => webfuse/core}/jsonrpc/response.h | 3 +- .../core/jsonrpc/response_intern.h} | 16 +- .../wf => webfuse/core}/jsonrpc/send_fn.h | 1 - .../impl => webfuse/core/jsonrpc}/server.c | 57 ++++--- .../wf => webfuse/core}/jsonrpc/server.h | 13 +- .../impl => webfuse/core/timer}/manager.c | 24 +-- .../wf => webfuse/core}/timer/manager.h | 8 +- lib/webfuse/core/timer/manager_intern.h | 26 ++++ .../wf => webfuse/core}/timer/on_timer_fn.h | 0 .../impl => webfuse/core/timer}/timepoint.c | 12 +- .../impl => webfuse/core/timer}/timepoint.h | 10 +- .../timer/impl => webfuse/core/timer}/timer.c | 26 ++-- .../include/wf => webfuse/core}/timer/timer.h | 11 +- lib/webfuse/core/timer/timer_intern.h | 40 +++++ lib/webfuse/provider/impl/client_protocol.c | 8 +- lib/wf/jsonrpc/include/wf/jsonrpc.h | 14 -- lib/wf/jsonrpc/include/wf/jsonrpc/api.h | 8 - lib/wf/jsonrpc/include/wf/jsonrpc/status.h | 11 -- lib/wf/jsonrpc/src/wf/jsonrpc/api.c | 144 ------------------ lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h | 84 ---------- lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h | 53 ------- lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h | 41 ----- .../src/wf/jsonrpc/impl/unused_param.h | 10 -- lib/wf/timer/include/wf/timer.h | 9 -- lib/wf/timer/include/wf/timer/api.h | 8 - lib/wf/timer/src/wf/timer/api.c | 59 ------- lib/wf/timer/src/wf/timer/impl/manager.h | 36 ----- lib/wf/timer/src/wf/timer/impl/timer.h | 59 ------- lib/wf/timer/test/wf/timer/test_timepoint.cc | 38 ----- .../webfuse/tests/core}/jsonrpc/mock_timer.cc | 4 +- .../tests/core}/jsonrpc/mock_timer.hpp | 3 +- .../core}/jsonrpc/mock_timer_callback.cc | 2 +- .../core}/jsonrpc/mock_timer_callback.hpp | 2 +- .../tests/core}/jsonrpc/test_is_request.cc | 2 +- .../tests/core}/jsonrpc/test_is_response.cc | 2 +- .../webfuse/tests/core}/jsonrpc/test_proxy.cc | 16 +- .../tests/core}/jsonrpc/test_request.cc | 8 +- .../tests/core}/jsonrpc/test_response.cc | 48 +++--- .../core}/jsonrpc/test_response_parser.cc | 14 +- .../tests/core}/jsonrpc/test_server.cc | 8 +- .../tests/core/timer/test_timepoint.cc | 38 +++++ .../webfuse/tests/core}/timer/test_timer.cc | 4 +- .../jsonrpc => test/webfuse/utils}/wrap.hpp | 0 73 files changed, 426 insertions(+), 929 deletions(-) delete mode 100644 cmake/wf_jsonrpc.cmake delete mode 100644 cmake/wf_timer.cmake rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/error.c (73%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/error.h (63%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/method.c (77%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/method.h (70%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/method_invoke_fn.h (92%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/proxy.c (74%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/proxy.h (80%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/proxy_finished_fn.h (100%) create mode 100644 lib/webfuse/core/jsonrpc/proxy_intern.h rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/request.c (76%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/request.h (64%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/response.c (73%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/response.h (74%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl/response.h => webfuse/core/jsonrpc/response_intern.h} (57%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/send_fn.h (90%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/server.c (59%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/server.h (69%) rename lib/{wf/timer/src/wf/timer/impl => webfuse/core/timer}/manager.c (73%) rename lib/{wf/timer/include/wf => webfuse/core}/timer/manager.h (72%) create mode 100644 lib/webfuse/core/timer/manager_intern.h rename lib/{wf/timer/include/wf => webfuse/core}/timer/on_timer_fn.h (100%) rename lib/{wf/timer/src/wf/timer/impl => webfuse/core/timer}/timepoint.c (59%) rename lib/{wf/timer/src/wf/timer/impl => webfuse/core/timer}/timepoint.h (57%) rename lib/{wf/timer/src/wf/timer/impl => webfuse/core/timer}/timer.c (61%) rename lib/{wf/timer/include/wf => webfuse/core}/timer/timer.h (72%) create mode 100644 lib/webfuse/core/timer/timer_intern.h delete mode 100644 lib/wf/jsonrpc/include/wf/jsonrpc.h delete mode 100644 lib/wf/jsonrpc/include/wf/jsonrpc/api.h delete mode 100644 lib/wf/jsonrpc/include/wf/jsonrpc/status.h delete mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/api.c delete mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h delete mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h delete mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h delete mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/impl/unused_param.h delete mode 100644 lib/wf/timer/include/wf/timer.h delete mode 100644 lib/wf/timer/include/wf/timer/api.h delete mode 100644 lib/wf/timer/src/wf/timer/api.c delete mode 100644 lib/wf/timer/src/wf/timer/impl/manager.h delete mode 100644 lib/wf/timer/src/wf/timer/impl/timer.h delete mode 100644 lib/wf/timer/test/wf/timer/test_timepoint.cc rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/mock_timer.cc (90%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/mock_timer.hpp (94%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/mock_timer_callback.cc (90%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/mock_timer_callback.hpp (89%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_is_request.cc (98%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_is_response.cc (98%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_proxy.cc (97%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_request.cc (95%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_response.cc (69%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_response_parser.cc (80%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_server.cc (97%) create mode 100644 test/webfuse/tests/core/timer/test_timepoint.cc rename {lib/wf/timer/test/wf => test/webfuse/tests/core}/timer/test_timer.cc (97%) rename {lib/wf/jsonrpc/test/wf/jsonrpc => test/webfuse/utils}/wrap.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index cfe430b..5e3f18c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,8 +37,6 @@ add_compile_options( "-pthread" ) -include(wf_timer) -include(wf_jsonrpc) include(webfuse_core) include(webfuse_adapter) include(webfuse_provider) diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 1722301..8f21188 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -7,17 +7,17 @@ include(GoogleTest) pkg_check_modules(GMOCK gmock) add_executable(alltests - lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc - lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc - lib/wf/timer/test/wf/timer/test_timepoint.cc - lib/wf/timer/test/wf/timer/test_timer.cc + test/webfuse/tests/core/jsonrpc/mock_timer_callback.cc + test/webfuse/tests/core/jsonrpc/mock_timer.cc + test/webfuse/tests/core/jsonrpc/test_is_request.cc + test/webfuse/tests/core/jsonrpc/test_request.cc + test/webfuse/tests/core/jsonrpc/test_is_response.cc + test/webfuse/tests/core/jsonrpc/test_response.cc + test/webfuse/tests/core/jsonrpc/test_server.cc + test/webfuse/tests/core/jsonrpc/test_proxy.cc + test/webfuse/tests/core/jsonrpc/test_response_parser.cc + test/webfuse/tests/core/timer/test_timepoint.cc + test/webfuse/tests/core/timer/test_timer.cc test/webfuse/utils/tempdir.cc test/webfuse/utils/file_utils.cc test/webfuse/utils/die_if.cc @@ -50,19 +50,6 @@ add_executable(alltests test/webfuse/tests/integration/provider.cc ) -target_include_directories(alltests PRIVATE - lib/wf/jsonrpc/include - lib/wf/jsonrpc/src - lib/wf/jsonrpc/test - lib/wf/timer/include - lib/wf/timer/src - ${FUSE3_INCLUDE_DIRS} -) - -target_compile_options(alltests PUBLIC - ${FUSE3_CFLAGS_OTHER} -) - target_link_libraries(alltests PUBLIC -Wl,--wrap=wf_timer_manager_create -Wl,--wrap=wf_timer_manager_dispose @@ -75,8 +62,6 @@ target_link_libraries(alltests PUBLIC webfuse-adapter-static webfuse-provider-static webfuse-core - wf_jsonrpc - wf_timer ${FUSE3_LIBRARIES} ${LWS_LIBRARIES} ${JANSSON_LIBRARIES} @@ -85,8 +70,8 @@ target_link_libraries(alltests PUBLIC ${GTEST_LIBRARIES} ) -target_include_directories(alltests PUBLIC test lib ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}) -target_compile_options(alltests PUBLIC ${GMOCK_CFLAGS} ${GTEST_CFLAGS}) +target_include_directories(alltests PUBLIC test lib ${FUSE3_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}) +target_compile_options(alltests PUBLIC ${FUSE3_CFLAGS_OTHER} ${GMOCK_CFLAGS} ${GTEST_CFLAGS}) enable_testing() gtest_discover_tests(alltests TEST_PREFIX alltests:) @@ -102,7 +87,7 @@ add_custom_target(coverage add_dependencies(coverage alltests) add_custom_target(coverage-report - COMMAND genhtml --branch-coverage --highlight --legend --prefix "${CMAKE_SOURCE_DIR}" coverage/lcov.info --output-directory coverage/report + COMMAND genhtml --branch-coverage --highlight --legend coverage/lcov.info --output-directory coverage/report ) add_dependencies(coverage-report coverage) diff --git a/cmake/webfuse_adapter.cmake b/cmake/webfuse_adapter.cmake index f6e777c..fab0f55 100644 --- a/cmake/webfuse_adapter.cmake +++ b/cmake/webfuse_adapter.cmake @@ -26,8 +26,6 @@ add_library(webfuse-adapter-static STATIC target_include_directories(webfuse-adapter-static PRIVATE lib - lib/wf/timer/include - lib/wf/jsonrpc/include ${FUSE3_INCLUDE_DIRS} ) @@ -56,7 +54,7 @@ set_target_properties(webfuse-adapter PROPERTIES SOVERSION 0) set_target_properties(webfuse-adapter PROPERTIES C_VISIBILITY_PRESET hidden) set_target_properties(webfuse-adapter PROPERTIES COMPILE_DEFINITIONS "WF_API=WF_EXPORT") -target_link_libraries(webfuse-adapter PRIVATE webfuse-adapter-static webfuse-core wf_jsonrpc wf_timer) +target_link_libraries(webfuse-adapter PRIVATE webfuse-adapter-static webfuse-core) file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-adapter.pc" "prefix=\"${CMAKE_INSTALL_PREFIX}\" diff --git a/cmake/webfuse_core.cmake b/cmake/webfuse_core.cmake index dab6223..fb25b75 100644 --- a/cmake/webfuse_core.cmake +++ b/cmake/webfuse_core.cmake @@ -9,6 +9,16 @@ add_library(webfuse-core STATIC lib/webfuse/core/base64.c lib/webfuse/core/lws_log.c lib/webfuse/core/json_util.c + lib/webfuse/core/timer/manager.c + lib/webfuse/core/timer/timepoint.c + lib/webfuse/core/timer/timer.c + lib/webfuse/core/jsonrpc/proxy.c + lib/webfuse/core/jsonrpc/server.c + lib/webfuse/core/jsonrpc/method.c + lib/webfuse/core/jsonrpc/request.c + lib/webfuse/core/jsonrpc/response.c + lib/webfuse/core/jsonrpc/error.c + ) set_target_properties(webfuse-core PROPERTIES OUTPUT_NAME webfuse-core) diff --git a/cmake/webfuse_provider.cmake b/cmake/webfuse_provider.cmake index 4cf285d..fbfa104 100644 --- a/cmake/webfuse_provider.cmake +++ b/cmake/webfuse_provider.cmake @@ -22,8 +22,6 @@ set_target_properties(webfuse-provider-static PROPERTIES OUTPUT_NAME webfuse-pro set_target_properties(webfuse-provider-static PROPERTIES C_VISIBILITY_PRESET hidden) target_include_directories(webfuse-provider-static PRIVATE lib - lib/wf/timer/include - lib/wf/jsonrpc/include ) add_library(webfuse-provider SHARED @@ -36,7 +34,7 @@ set_target_properties(webfuse-provider PROPERTIES C_VISIBILITY_PRESET hidden) set_target_properties(webfuse-provider PROPERTIES COMPILE_DEFINITIONS "WFP_API=WFP_EXPORT") target_include_directories(webfuse-provider PUBLIC lib) -target_link_libraries(webfuse-provider PRIVATE webfuse-provider-static webfuse-core wf_jsonrpc wf_timer) +target_link_libraries(webfuse-provider PRIVATE webfuse-provider-static webfuse-core) file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-provider.pc" "prefix=\"${CMAKE_INSTALL_PREFIX}\" diff --git a/cmake/wf_jsonrpc.cmake b/cmake/wf_jsonrpc.cmake deleted file mode 100644 index fae8d74..0000000 --- a/cmake/wf_jsonrpc.cmake +++ /dev/null @@ -1,24 +0,0 @@ -# wf_jsonrpc - -add_library(wf_jsonrpc STATIC - lib/wf/jsonrpc/src/wf/jsonrpc/api.c - lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c - lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c - lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c - lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c - lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c - lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.c -) - -target_link_libraries(wf_jsonrpc PUBLIC wf_timer) - -target_include_directories(wf_jsonrpc PRIVATE - lib/wf/timer/include - lib/wf/jsonrpc/src -) - -target_include_directories(wf_jsonrpc PUBLIC - lib/wf/jsonrpc/include -) - -set_target_properties(wf_jsonrpc PROPERTIES C_VISIBILITY_PRESET hidden) diff --git a/cmake/wf_timer.cmake b/cmake/wf_timer.cmake deleted file mode 100644 index 8bdecf2..0000000 --- a/cmake/wf_timer.cmake +++ /dev/null @@ -1,18 +0,0 @@ -# timer - -add_library(wf_timer STATIC - lib/wf/timer/src/wf/timer/api.c - lib/wf/timer/src/wf/timer/impl/manager.c - lib/wf/timer/src/wf/timer/impl/timepoint.c - lib/wf/timer/src/wf/timer/impl/timer.c -) - -target_include_directories(wf_timer PRIVATE - lib/wf/timer/src -) - -target_include_directories(wf_timer PUBLIC - lib/wf/timer/include -) - -set_target_properties(wf_timer PROPERTIES C_VISIBILITY_PRESET hidden) diff --git a/lib/webfuse/adapter/impl/operation/close.c b/lib/webfuse/adapter/impl/operation/close.c index dcb65fb..5f6e49b 100644 --- a/lib/webfuse/adapter/impl/operation/close.c +++ b/lib/webfuse/adapter/impl/operation/close.c @@ -4,7 +4,7 @@ #include #include -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/util.h" void wf_impl_operation_close( diff --git a/lib/webfuse/adapter/impl/operation/getattr.c b/lib/webfuse/adapter/impl/operation/getattr.c index 767b06c..ae64a25 100644 --- a/lib/webfuse/adapter/impl/operation/getattr.c +++ b/lib/webfuse/adapter/impl/operation/getattr.c @@ -7,7 +7,7 @@ #include #include -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/json_util.h" #include "webfuse/core/util.h" diff --git a/lib/webfuse/adapter/impl/operation/lookup.c b/lib/webfuse/adapter/impl/operation/lookup.c index 596f7e4..4b64320 100644 --- a/lib/webfuse/adapter/impl/operation/lookup.c +++ b/lib/webfuse/adapter/impl/operation/lookup.c @@ -10,7 +10,7 @@ #include -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/json_util.h" #include "webfuse/core/util.h" diff --git a/lib/webfuse/adapter/impl/operation/open.c b/lib/webfuse/adapter/impl/operation/open.c index 0c10c45..8e21100 100644 --- a/lib/webfuse/adapter/impl/operation/open.c +++ b/lib/webfuse/adapter/impl/operation/open.c @@ -4,7 +4,7 @@ #include #include -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/util.h" #include "webfuse/core/status.h" #include "webfuse/core/json_util.h" diff --git a/lib/webfuse/adapter/impl/operation/read.c b/lib/webfuse/adapter/impl/operation/read.c index 8fa5bee..7896b30 100644 --- a/lib/webfuse/adapter/impl/operation/read.c +++ b/lib/webfuse/adapter/impl/operation/read.c @@ -5,7 +5,7 @@ #include #include -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/base64.h" #include "webfuse/core/json_util.h" diff --git a/lib/webfuse/adapter/impl/operation/readdir.c b/lib/webfuse/adapter/impl/operation/readdir.c index f188084..804a80e 100644 --- a/lib/webfuse/adapter/impl/operation/readdir.c +++ b/lib/webfuse/adapter/impl/operation/readdir.c @@ -8,7 +8,7 @@ #include #include -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/util.h" #include "webfuse/core/json_util.h" diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index ee5cbb0..7caf0bc 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -11,9 +11,9 @@ #include "webfuse/adapter/impl/credentials.h" #include "webfuse/core/status_intern.h" -#include "wf/jsonrpc/request.h" -#include "wf/timer/manager.h" -#include "wf/timer/timer.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/timer/manager.h" +#include "webfuse/core/timer/timer.h" static int wf_impl_server_protocol_callback( struct lws * wsi, diff --git a/lib/webfuse/adapter/impl/server_protocol.h b/lib/webfuse/adapter/impl/server_protocol.h index df98c8f..269e3be 100644 --- a/lib/webfuse/adapter/impl/server_protocol.h +++ b/lib/webfuse/adapter/impl/server_protocol.h @@ -4,8 +4,8 @@ #include "webfuse/adapter/impl/authenticators.h" #include "webfuse/adapter/impl/mountpoint_factory.h" #include "webfuse/adapter/impl/session_manager.h" -#include "wf/jsonrpc/proxy.h" -#include "wf/jsonrpc/server.h" +#include "webfuse/core/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/server.h" #ifndef __cplusplus #include diff --git a/lib/webfuse/adapter/impl/session.c b/lib/webfuse/adapter/impl/session.c index 778d155..6bacd10 100644 --- a/lib/webfuse/adapter/impl/session.c +++ b/lib/webfuse/adapter/impl/session.c @@ -8,9 +8,9 @@ #include "webfuse/core/container_of.h" #include "webfuse/core/util.h" -#include "wf/jsonrpc/proxy.h" -#include "wf/jsonrpc/request.h" -#include "wf/jsonrpc/response.h" +#include "webfuse/core/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/jsonrpc/response.h" #include #include diff --git a/lib/webfuse/adapter/impl/session.h b/lib/webfuse/adapter/impl/session.h index 82b042f..1046a2e 100644 --- a/lib/webfuse/adapter/impl/session.h +++ b/lib/webfuse/adapter/impl/session.h @@ -13,8 +13,8 @@ using std::size_t; #include "webfuse/adapter/impl/filesystem.h" #include "webfuse/core/slist.h" -#include "wf/jsonrpc/proxy.h" -#include "wf/jsonrpc/server.h" +#include "webfuse/core/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/server.h" #ifdef __cplusplus extern "C" diff --git a/lib/webfuse/core/json_util.c b/lib/webfuse/core/json_util.c index 48fe956..535e07e 100644 --- a/lib/webfuse/core/json_util.c +++ b/lib/webfuse/core/json_util.c @@ -1,5 +1,4 @@ #include "webfuse/core/json_util.h" -#include "wf/jsonrpc/status.h" int wf_impl_json_get_int(json_t const * object, char const * key, int default_value) { @@ -14,25 +13,6 @@ int wf_impl_json_get_int(json_t const * object, char const * key, int default_va return result; } -static wf_status wf_impl_jsonrc_code_to_status(int code) -{ - switch (code) - { - case WF_JSONRPC_GOOD: - return WF_GOOD; - case WF_JSONRPC_BAD: - return WF_BAD; - case WF_JSONRPC_BAD_BUSY: - return WF_BAD_BUSY; - case WF_JSONRPC_BAD_TIMEOUT: - return WF_BAD_TIMEOUT; - case WF_JSONRPC_BAD_FORMAT: - return WF_BAD_FORMAT; - default: - return (wf_status) code; - } -} - wf_status wf_impl_jsonrpc_get_status( json_t const * error) @@ -40,8 +20,7 @@ wf_impl_jsonrpc_get_status( wf_status status = WF_GOOD; if (NULL != error) { - int code = wf_impl_json_get_int(error, "code", WF_BAD_FORMAT); - status = wf_impl_jsonrc_code_to_status(code); + status = wf_impl_json_get_int(error, "code", WF_BAD_FORMAT); } return status; diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.c b/lib/webfuse/core/jsonrpc/error.c similarity index 73% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.c rename to lib/webfuse/core/jsonrpc/error.c index eba2e86..ad74a58 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.c +++ b/lib/webfuse/core/jsonrpc/error.c @@ -1,7 +1,7 @@ -#include "wf/jsonrpc/impl/error.h" +#include "webfuse/core/jsonrpc/error.h" json_t * -wf_jsonrpc_impl_error( +wf_jsonrpc_error( int code, char const * message) { @@ -13,13 +13,13 @@ wf_jsonrpc_impl_error( } void -wf_jsonrpc_impl_propate_error( +wf_jsonrpc_propate_error( wf_jsonrpc_proxy_finished_fn * finised, void * user_data, int code, char const * message) { - json_t * error = wf_jsonrpc_impl_error(code, message); + json_t * error = wf_jsonrpc_error(code, message); finised(user_data, NULL, error); json_decref(error); diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.h b/lib/webfuse/core/jsonrpc/error.h similarity index 63% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.h rename to lib/webfuse/core/jsonrpc/error.h index fda0f89..2edfd92 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.h +++ b/lib/webfuse/core/jsonrpc/error.h @@ -1,8 +1,8 @@ -#ifndef WF_JSONRPC_IMPL_ERROR_H -#define WF_JSONRPC_IMPL_ERROR_H +#ifndef WF_JSONRPC_ERROR_H +#define WF_JSONRPC_ERROR_H #include -#include "wf/jsonrpc/proxy_finished_fn.h" +#include "webfuse/core/jsonrpc/proxy_finished_fn.h" #ifdef __cplusplus extern "C" @@ -10,12 +10,12 @@ extern "C" #endif extern json_t * -wf_jsonrpc_impl_error( +wf_jsonrpc_error( int code, char const * message); extern void -wf_jsonrpc_impl_propate_error( +wf_jsonrpc_propate_error( wf_jsonrpc_proxy_finished_fn * finised, void * user_data, int code, diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c b/lib/webfuse/core/jsonrpc/method.c similarity index 77% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c rename to lib/webfuse/core/jsonrpc/method.c index ef0d16c..a184dca 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c +++ b/lib/webfuse/core/jsonrpc/method.c @@ -1,8 +1,8 @@ -#include "wf/jsonrpc/impl/method.h" +#include "webfuse/core/jsonrpc/method.h" #include #include -struct wf_jsonrpc_method * wf_jsonrpc_impl_method_create( +struct wf_jsonrpc_method * wf_jsonrpc_method_create( char const * method_name, wf_jsonrpc_method_invoke_fn * invoke, void * user_data) @@ -16,7 +16,7 @@ struct wf_jsonrpc_method * wf_jsonrpc_impl_method_create( return method; } -void wf_jsonrpc_impl_method_dispose( +void wf_jsonrpc_method_dispose( struct wf_jsonrpc_method * method) { free(method->name); diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.h b/lib/webfuse/core/jsonrpc/method.h similarity index 70% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.h rename to lib/webfuse/core/jsonrpc/method.h index d0e42f0..e196bff 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.h +++ b/lib/webfuse/core/jsonrpc/method.h @@ -1,7 +1,7 @@ -#ifndef WF_JSONRPC_IMPL_METHOD_H -#define WF_JSONRPC_IMPL_METHOD_H +#ifndef WF_JSONRPC_METHOD_H +#define WF_JSONRPC_METHOD_H -#include "wf/jsonrpc/method_invoke_fn.h" +#include "webfuse/core/jsonrpc/method_invoke_fn.h" #ifdef __cplusplus extern "C" @@ -17,13 +17,13 @@ struct wf_jsonrpc_method }; extern struct wf_jsonrpc_method * -wf_jsonrpc_impl_method_create( +wf_jsonrpc_method_create( char const * method_name, wf_jsonrpc_method_invoke_fn * invoke, void * user_data); extern void -wf_jsonrpc_impl_method_dispose( +wf_jsonrpc_method_dispose( struct wf_jsonrpc_method * method); #ifdef __cplusplus diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/method_invoke_fn.h b/lib/webfuse/core/jsonrpc/method_invoke_fn.h similarity index 92% rename from lib/wf/jsonrpc/include/wf/jsonrpc/method_invoke_fn.h rename to lib/webfuse/core/jsonrpc/method_invoke_fn.h index d7a9cc8..046dfb6 100644 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/method_invoke_fn.h +++ b/lib/webfuse/core/jsonrpc/method_invoke_fn.h @@ -1,7 +1,6 @@ #ifndef WF_JSONRPC_METHOD_INVOKE_FN_H #define WF_JSONRPC_METHOD_INVOKE_FN_H -#include #include #ifdef __cplusplus @@ -17,7 +16,6 @@ typedef void wf_jsonrpc_method_invoke_fn( json_t * params, void * user_data); - #ifdef __cplusplus } #endif diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c b/lib/webfuse/core/jsonrpc/proxy.c similarity index 74% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c rename to lib/webfuse/core/jsonrpc/proxy.c index 99b3f03..67fd6d8 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c +++ b/lib/webfuse/core/jsonrpc/proxy.c @@ -1,34 +1,34 @@ -#include "wf/jsonrpc/impl/proxy.h" -#include "wf/jsonrpc/impl/response.h" -#include "wf/jsonrpc/impl/error.h" -#include "wf/jsonrpc/status.h" +#include "webfuse/core/jsonrpc/proxy_intern.h" +#include "webfuse/core/jsonrpc/response_intern.h" +#include "webfuse/core/jsonrpc/error.h" +#include "webfuse/core/status.h" -#include +#include "webfuse/core/timer/timer.h" #include #include struct wf_jsonrpc_proxy * -wf_jsonrpc_impl_proxy_create( +wf_jsonrpc_proxy_create( struct wf_timer_manager * manager, int timeout, wf_jsonrpc_send_fn * send, void * user_data) { struct wf_jsonrpc_proxy * proxy = malloc(sizeof(struct wf_jsonrpc_proxy)); - wf_jsonrpc_impl_proxy_init(proxy, manager, timeout, send, user_data); + wf_jsonrpc_proxy_init(proxy, manager, timeout, send, user_data); return proxy; } -void wf_jsonrpc_impl_proxy_dispose( +void wf_jsonrpc_proxy_dispose( struct wf_jsonrpc_proxy * proxy) { - wf_jsonrpc_impl_proxy_cleanup(proxy); + wf_jsonrpc_proxy_cleanup(proxy); free(proxy); } -static void wf_jsonrpc_impl_proxy_on_timeout( +static void wf_jsonrpc_proxy_on_timeout( struct wf_timer * timer, void * proxy_ptr) { struct wf_jsonrpc_proxy * proxy = proxy_ptr; @@ -44,11 +44,11 @@ static void wf_jsonrpc_impl_proxy_on_timeout( proxy->request.finished = NULL; wf_timer_cancel(timer); - wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD_TIMEOUT, "Timeout"); + wf_jsonrpc_propate_error(finished, user_data, WF_BAD_TIMEOUT, "Timeout"); } } -static json_t * wf_jsonrpc_impl_request_create( +static json_t * wf_jsonrpc_request_create( char const * method, int id, char const * param_info, @@ -98,7 +98,7 @@ static json_t * wf_jsonrpc_impl_request_create( return request; } -void wf_jsonrpc_impl_proxy_init( +void wf_jsonrpc_proxy_init( struct wf_jsonrpc_proxy * proxy, struct wf_timer_manager * timeout_manager, int timeout, @@ -110,10 +110,10 @@ void wf_jsonrpc_impl_proxy_init( proxy->user_data = user_data; proxy->request.is_pending = false; proxy->request.timer = wf_timer_create(timeout_manager, - &wf_jsonrpc_impl_proxy_on_timeout, proxy); + &wf_jsonrpc_proxy_on_timeout, proxy); } -void wf_jsonrpc_impl_proxy_cleanup( +void wf_jsonrpc_proxy_cleanup( struct wf_jsonrpc_proxy * proxy) { if (proxy->request.is_pending) @@ -127,19 +127,19 @@ void wf_jsonrpc_impl_proxy_cleanup( proxy->request.id = 0; wf_timer_cancel(proxy->request.timer); - wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD, "Bad: cancelled pending request during shutdown"); + wf_jsonrpc_propate_error(finished, user_data, WF_BAD, "Bad: cancelled pending request during shutdown"); } wf_timer_dispose(proxy->request.timer); } -void wf_jsonrpc_impl_proxy_invoke( +void wf_jsonrpc_proxy_invoke( struct wf_jsonrpc_proxy * proxy, wf_jsonrpc_proxy_finished_fn * finished, void * user_data, char const * method_name, char const * param_info, - va_list args + ... ) { if (!proxy->request.is_pending) @@ -150,7 +150,10 @@ void wf_jsonrpc_impl_proxy_invoke( proxy->request.id = 42; wf_timer_start(proxy->request.timer, proxy->timeout); - json_t * request = wf_jsonrpc_impl_request_create(method_name, proxy->request.id, param_info, args); + va_list args; + va_start(args, param_info); + json_t * request = wf_jsonrpc_request_create(method_name, proxy->request.id, param_info, args); + va_end(args); bool const is_send = ((NULL != request) && (proxy->send(request, proxy->user_data))); if (!is_send) @@ -161,7 +164,7 @@ void wf_jsonrpc_impl_proxy_invoke( proxy->request.id = 0; wf_timer_cancel(proxy->request.timer); - wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD, "Bad: requenst is not sent"); + wf_jsonrpc_propate_error(finished, user_data, WF_BAD, "Bad: requenst is not sent"); } if (NULL != request) @@ -171,18 +174,22 @@ void wf_jsonrpc_impl_proxy_invoke( } else { - wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD_BUSY, "Busy"); + wf_jsonrpc_propate_error(finished, user_data, WF_BAD_BUSY, "Busy"); } } -extern void wf_jsonrpc_impl_proxy_notify( +extern void wf_jsonrpc_proxy_notify( struct wf_jsonrpc_proxy * proxy, char const * method_name, char const * param_info, - va_list args + ... ) -{ - json_t * request = wf_jsonrpc_impl_request_create(method_name, 0, param_info, 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) { proxy->send(request, proxy->user_data); @@ -191,12 +198,12 @@ extern void wf_jsonrpc_impl_proxy_notify( } -void wf_jsonrpc_impl_proxy_onresult( +void wf_jsonrpc_proxy_onresult( struct wf_jsonrpc_proxy * proxy, json_t * message) { struct wf_jsonrpc_response response; - wf_jsonrpc_impl_response_init(&response, message); + wf_jsonrpc_response_init(&response, message); if ((proxy->request.is_pending) && (response.id == proxy->request.id)) { @@ -212,6 +219,6 @@ void wf_jsonrpc_impl_proxy_onresult( finished(user_data, response.result, response.error); } - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); } diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/proxy.h b/lib/webfuse/core/jsonrpc/proxy.h similarity index 80% rename from lib/wf/jsonrpc/include/wf/jsonrpc/proxy.h rename to lib/webfuse/core/jsonrpc/proxy.h index 66fd1a5..8a69936 100644 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/proxy.h +++ b/lib/webfuse/core/jsonrpc/proxy.h @@ -12,9 +12,8 @@ using std::size_t; #endif #include -#include -#include -#include +#include "webfuse/core/jsonrpc/send_fn.h" +#include "webfuse/core/jsonrpc/proxy_finished_fn.h" #ifdef __cplusplus extern "C" { @@ -23,14 +22,14 @@ extern "C" { struct wf_jsonrpc_proxy; struct wf_timer_manager; -extern WF_JSONRPC_API struct wf_jsonrpc_proxy * +extern struct wf_jsonrpc_proxy * wf_jsonrpc_proxy_create( struct wf_timer_manager * manager, int timeout, wf_jsonrpc_send_fn * send, void * user_data); -extern WF_JSONRPC_API void wf_jsonrpc_proxy_dispose( +extern void wf_jsonrpc_proxy_dispose( struct wf_jsonrpc_proxy * proxy); //------------------------------------------------------------------------------ @@ -47,7 +46,7 @@ extern WF_JSONRPC_API void wf_jsonrpc_proxy_dispose( /// \param param_info types of the param (s = string, i = integer, j = json) /// \param ... params //------------------------------------------------------------------------------ -extern WF_JSONRPC_API void wf_jsonrpc_proxy_invoke( +extern void wf_jsonrpc_proxy_invoke( struct wf_jsonrpc_proxy * proxy, wf_jsonrpc_proxy_finished_fn * finished, void * user_data, @@ -56,14 +55,14 @@ extern WF_JSONRPC_API void wf_jsonrpc_proxy_invoke( ... ); -extern WF_JSONRPC_API void wf_jsonrpc_proxy_notify( +extern void wf_jsonrpc_proxy_notify( struct wf_jsonrpc_proxy * proxy, char const * method_name, char const * param_info, ... ); -extern WF_JSONRPC_API void wf_jsonrpc_proxy_onresult( +extern void wf_jsonrpc_proxy_onresult( struct wf_jsonrpc_proxy * proxy, json_t * message); diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/proxy_finished_fn.h b/lib/webfuse/core/jsonrpc/proxy_finished_fn.h similarity index 100% rename from lib/wf/jsonrpc/include/wf/jsonrpc/proxy_finished_fn.h rename to lib/webfuse/core/jsonrpc/proxy_finished_fn.h diff --git a/lib/webfuse/core/jsonrpc/proxy_intern.h b/lib/webfuse/core/jsonrpc/proxy_intern.h new file mode 100644 index 0000000..3186e14 --- /dev/null +++ b/lib/webfuse/core/jsonrpc/proxy_intern.h @@ -0,0 +1,48 @@ +#ifndef WF_JSONRPC_PROXY_INTERN_H +#define WF_JSONRPC_PROXY_INTERN_H + +#include "webfuse/core/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy_finished_fn.h" +#include "webfuse/core/jsonrpc/send_fn.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_timer; + +struct wf_jsonrpc_request +{ + bool is_pending; + wf_jsonrpc_proxy_finished_fn * finished; + void * user_data; + int id; + struct wf_timer * timer; +}; + +struct wf_jsonrpc_proxy +{ + struct wf_jsonrpc_request request; + int timeout; + wf_jsonrpc_send_fn * send; + void * user_data; +}; + +extern void +wf_jsonrpc_proxy_init( + struct wf_jsonrpc_proxy * proxy, + struct wf_timer_manager * manager, + int timeout, + wf_jsonrpc_send_fn * send, + void * user_data); + +extern void +wf_jsonrpc_proxy_cleanup( + struct wf_jsonrpc_proxy * proxy); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c b/lib/webfuse/core/jsonrpc/request.c similarity index 76% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c rename to lib/webfuse/core/jsonrpc/request.c index 071ec4b..30212bd 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c +++ b/lib/webfuse/core/jsonrpc/request.c @@ -1,5 +1,5 @@ -#include "wf/jsonrpc/impl/request.h" -#include "wf/jsonrpc/impl/error.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/jsonrpc/error.h" #include struct wf_jsonrpc_request @@ -10,7 +10,7 @@ struct wf_jsonrpc_request }; bool -wf_jsonrpc_impl_is_request( +wf_jsonrpc_is_request( json_t * message) { json_t * id = json_object_get(message, "id"); @@ -23,7 +23,7 @@ wf_jsonrpc_impl_is_request( struct wf_jsonrpc_request * -wf_jsonrpc_impl_request_create( +wf_jsonrpc_request_create( int id, wf_jsonrpc_send_fn * send, void * user_data) @@ -37,14 +37,14 @@ wf_jsonrpc_impl_request_create( } void -wf_jsonrpc_impl_request_dispose( +wf_jsonrpc_request_dispose( struct wf_jsonrpc_request * request) { free(request); } void * -wf_jsonrpc_impl_request_get_userdata( +wf_jsonrpc_request_get_userdata( struct wf_jsonrpc_request * request) { return request->user_data; @@ -52,7 +52,7 @@ wf_jsonrpc_impl_request_get_userdata( void -wf_jsonrpc_impl_respond( +wf_jsonrpc_respond( struct wf_jsonrpc_request * request, json_t * result) { @@ -62,20 +62,20 @@ wf_jsonrpc_impl_respond( request->send(response, request->user_data); json_decref(response); - wf_jsonrpc_impl_request_dispose(request); + wf_jsonrpc_request_dispose(request); } -void wf_jsonrpc_impl_respond_error( +void wf_jsonrpc_respond_error( struct wf_jsonrpc_request * request, int code, char const * message) { json_t * response = json_object(); - json_object_set_new(response, "error", wf_jsonrpc_impl_error(code, message)); + json_object_set_new(response, "error", wf_jsonrpc_error(code, message)); json_object_set_new(response, "id", json_integer(request->id)); request->send(response, request->user_data); json_decref(response); - wf_jsonrpc_impl_request_dispose(request); + wf_jsonrpc_request_dispose(request); } diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/request.h b/lib/webfuse/core/jsonrpc/request.h similarity index 64% rename from lib/wf/jsonrpc/include/wf/jsonrpc/request.h rename to lib/webfuse/core/jsonrpc/request.h index 73295e6..234ec62 100644 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/request.h +++ b/lib/webfuse/core/jsonrpc/request.h @@ -12,8 +12,7 @@ using std::size_t; #endif #include -#include -#include "wf/jsonrpc/send_fn.h" +#include "webfuse/core/jsonrpc/send_fn.h" #ifdef __cplusplus extern "C" @@ -22,26 +21,26 @@ extern "C" struct wf_jsonrpc_request; -extern WF_JSONRPC_API bool wf_jsonrpc_is_request( +extern bool wf_jsonrpc_is_request( json_t * message); -extern WF_JSONRPC_API struct wf_jsonrpc_request * +extern struct wf_jsonrpc_request * wf_jsonrpc_request_create( int id, wf_jsonrpc_send_fn * send, void * user_data); -extern WF_JSONRPC_API void wf_jsonrpc_request_dispose( +extern void wf_jsonrpc_request_dispose( struct wf_jsonrpc_request * request); -extern WF_JSONRPC_API void * wf_jsonrpc_request_get_userdata( +extern void * wf_jsonrpc_request_get_userdata( struct wf_jsonrpc_request * request); -extern WF_JSONRPC_API void wf_jsonrpc_respond( +extern void wf_jsonrpc_respond( struct wf_jsonrpc_request * request, json_t * result); -extern WF_JSONRPC_API void wf_jsonrpc_respond_error( +extern void wf_jsonrpc_respond_error( struct wf_jsonrpc_request * request, int code, char const * message); diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c b/lib/webfuse/core/jsonrpc/response.c similarity index 73% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c rename to lib/webfuse/core/jsonrpc/response.c index f9fe180..69f7033 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c +++ b/lib/webfuse/core/jsonrpc/response.c @@ -1,9 +1,9 @@ -#include "wf/jsonrpc/impl/response.h" -#include "wf/jsonrpc/impl/error.h" -#include "wf/jsonrpc/status.h" +#include "webfuse/core/jsonrpc/response_intern.h" +#include "webfuse/core/jsonrpc/error.h" +#include "webfuse/core/status.h" bool -wf_jsonrpc_impl_is_response( +wf_jsonrpc_is_response( json_t * message) { json_t * id = json_object_get(message, "id"); @@ -16,7 +16,7 @@ wf_jsonrpc_impl_is_response( void -wf_jsonrpc_impl_response_init( +wf_jsonrpc_response_init( struct wf_jsonrpc_response * result, json_t * response) { @@ -27,7 +27,7 @@ wf_jsonrpc_impl_response_init( json_t * id_holder = json_object_get(response, "id"); if (!json_is_integer(id_holder)) { - result->error = wf_jsonrpc_impl_error(WF_JSONRPC_BAD_FORMAT, "invalid format: missing id"); + result->error = wf_jsonrpc_error(WF_BAD_FORMAT, "invalid format: missing id"); return; } @@ -47,13 +47,13 @@ wf_jsonrpc_impl_response_init( } else { - result->error = wf_jsonrpc_impl_error(WF_JSONRPC_BAD_FORMAT, "invalid format: invalid error object"); + result->error = wf_jsonrpc_error(WF_BAD_FORMAT, "invalid format: invalid error object"); } } } void -wf_jsonrpc_impl_response_cleanup( +wf_jsonrpc_response_cleanup( struct wf_jsonrpc_response * response) { if (NULL != response->result) diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/response.h b/lib/webfuse/core/jsonrpc/response.h similarity index 74% rename from lib/wf/jsonrpc/include/wf/jsonrpc/response.h rename to lib/webfuse/core/jsonrpc/response.h index abe2011..0bf0561 100644 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/response.h +++ b/lib/webfuse/core/jsonrpc/response.h @@ -6,14 +6,13 @@ #endif #include -#include #ifdef __cplusplus extern "C" { #endif -extern WF_JSONRPC_API bool wf_jsonrpc_is_response( +extern bool wf_jsonrpc_is_response( json_t * message); #ifdef __cplusplus diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.h b/lib/webfuse/core/jsonrpc/response_intern.h similarity index 57% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.h rename to lib/webfuse/core/jsonrpc/response_intern.h index 3e1e02e..137a615 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.h +++ b/lib/webfuse/core/jsonrpc/response_intern.h @@ -1,16 +1,15 @@ -#ifndef WF_JSONRPC_IMPL_RESPONSE_H -#define WF_JSONRPC_IMPL_RESPONSE_H +#ifndef WF_JSONRPC_RESPONSE_INTERN_H +#define WF_JSONRPC_RESPONSE_INTERN_H + +#include "webfuse/core/jsonrpc/response.h" #ifndef __cplusplus -#include #include #else #include using std::size_t; #endif -#include - #ifdef __cplusplus extern "C" { #endif @@ -22,14 +21,11 @@ struct wf_jsonrpc_response int id; }; -extern bool wf_jsonrpc_impl_is_response( - json_t * message); - -extern void wf_jsonrpc_impl_response_init( +extern void wf_jsonrpc_response_init( struct wf_jsonrpc_response * response, json_t * message); -extern void wf_jsonrpc_impl_response_cleanup( +extern void wf_jsonrpc_response_cleanup( struct wf_jsonrpc_response * response); #ifdef __cplusplus diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/send_fn.h b/lib/webfuse/core/jsonrpc/send_fn.h similarity index 90% rename from lib/wf/jsonrpc/include/wf/jsonrpc/send_fn.h rename to lib/webfuse/core/jsonrpc/send_fn.h index 9ea9ef4..2892687 100644 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/send_fn.h +++ b/lib/webfuse/core/jsonrpc/send_fn.h @@ -6,7 +6,6 @@ #endif #include -#include #ifdef __cplusplus extern "C" diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c b/lib/webfuse/core/jsonrpc/server.c similarity index 59% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c rename to lib/webfuse/core/jsonrpc/server.c index b3e27c8..03e30ae 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c +++ b/lib/webfuse/core/jsonrpc/server.c @@ -1,8 +1,8 @@ -#include "wf/jsonrpc/impl/server.h" -#include "wf/jsonrpc/impl/method.h" -#include "wf/jsonrpc/impl/request.h" -#include "wf/jsonrpc/impl/unused_param.h" -#include "wf/jsonrpc/status.h" +#include "webfuse/core/jsonrpc/server.h" +#include "webfuse/core/jsonrpc/method.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/status.h" +#include "webfuse/core/util.h" #include #include @@ -13,80 +13,79 @@ struct wf_jsonrpc_server }; static void -wf_jsonrpc_impl_server_init( +wf_jsonrpc_server_init( struct wf_jsonrpc_server * server); static void -wf_jsonrpc_impl_server_cleanup( +wf_jsonrpc_server_cleanup( struct wf_jsonrpc_server * server); struct wf_jsonrpc_server * -wf_jsonrpc_impl_server_create(void) +wf_jsonrpc_server_create(void) { struct wf_jsonrpc_server * server = malloc(sizeof(struct wf_jsonrpc_server)); - wf_jsonrpc_impl_server_init(server); + wf_jsonrpc_server_init(server); return server; } void -wf_jsonrpc_impl_server_dispose( +wf_jsonrpc_server_dispose( struct wf_jsonrpc_server * server) { - wf_jsonrpc_impl_server_cleanup(server); + wf_jsonrpc_server_cleanup(server); free(server); } - -static void wf_jsonrpc_impl_server_init( +static void wf_jsonrpc_server_init( struct wf_jsonrpc_server * server) { server->methods = NULL; } -static void wf_jsonrpc_impl_server_cleanup( +static void wf_jsonrpc_server_cleanup( struct wf_jsonrpc_server * server) { struct wf_jsonrpc_method * current = server->methods; while (NULL != current) { struct wf_jsonrpc_method * next = current->next; - wf_jsonrpc_impl_method_dispose(current); + wf_jsonrpc_method_dispose(current); current = next; } server->methods = NULL; } -void wf_jsonrpc_impl_server_add( +void wf_jsonrpc_server_add( struct wf_jsonrpc_server * server, char const * method_name, wf_jsonrpc_method_invoke_fn * invoke, void * user_data) { - struct wf_jsonrpc_method * method = wf_jsonrpc_impl_method_create(method_name, invoke, user_data); + struct wf_jsonrpc_method * method = wf_jsonrpc_method_create(method_name, invoke, user_data); method->next = server->methods; server->methods = method; } -static void wf_jsonrpc_impl_server_invalid_method_invoke( +static void wf_jsonrpc_server_invalid_method_invoke( struct wf_jsonrpc_request * request, - char const * WF_JSONRPC_UNUSED_PARAM(method_name), - json_t * WF_JSONRPC_UNUSED_PARAM(params), - void * WF_JSONRPC_UNUSED_PARAM(user_data)) + char const * WF_UNUSED_PARAM(method_name), + json_t * WF_UNUSED_PARAM(params), + void * WF_UNUSED_PARAM(user_data)) { - wf_jsonrpc_impl_respond_error(request, WF_JSONRPC_BAD_NOTIMPLEMENTED, "not implemented"); + wf_jsonrpc_respond_error(request, WF_BAD_NOTIMPLEMENTED, "not implemented"); } -static struct wf_jsonrpc_method const wf_jsonrpc_impl_server_invalid_method = +static struct wf_jsonrpc_method const wf_jsonrpc_server_invalid_method = { .next = NULL, .name = "", - .invoke = &wf_jsonrpc_impl_server_invalid_method_invoke, + .invoke = &wf_jsonrpc_server_invalid_method_invoke, .user_data = NULL }; static struct wf_jsonrpc_method const * -wf_jsonrpc_impl_server_get_method( +wf_jsonrpc_server_get_method( struct wf_jsonrpc_server * server, char const * method_name) { @@ -101,10 +100,10 @@ wf_jsonrpc_impl_server_get_method( current = current->next; } - return &wf_jsonrpc_impl_server_invalid_method; + return &wf_jsonrpc_server_invalid_method; } -void wf_jsonrpc_impl_server_process( +void wf_jsonrpc_server_process( struct wf_jsonrpc_server * server, json_t * request_data, wf_jsonrpc_send_fn * send, @@ -120,8 +119,8 @@ void wf_jsonrpc_impl_server_process( { char const * method_name = json_string_value(method_holder); int id = json_integer_value(id_holder); - struct wf_jsonrpc_request * request = wf_jsonrpc_impl_request_create(id, send, user_data); - struct wf_jsonrpc_method const * method = wf_jsonrpc_impl_server_get_method(server, method_name); + struct wf_jsonrpc_request * request = wf_jsonrpc_request_create(id, send, user_data); + struct wf_jsonrpc_method const * method = wf_jsonrpc_server_get_method(server, method_name); method->invoke(request, method_name, params, method->user_data); } diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/server.h b/lib/webfuse/core/jsonrpc/server.h similarity index 69% rename from lib/wf/jsonrpc/include/wf/jsonrpc/server.h rename to lib/webfuse/core/jsonrpc/server.h index c4850a5..143f121 100644 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/server.h +++ b/lib/webfuse/core/jsonrpc/server.h @@ -9,9 +9,8 @@ #endif #include -#include -#include -#include +#include "webfuse/core/jsonrpc/method_invoke_fn.h" +#include "webfuse/core/jsonrpc/send_fn.h" #ifdef __cplusplus extern "C" @@ -20,20 +19,20 @@ extern "C" struct wf_jsonrpc_server; -extern WF_JSONRPC_API struct wf_jsonrpc_server * +extern struct wf_jsonrpc_server * wf_jsonrpc_server_create(void); -extern WF_JSONRPC_API void +extern void wf_jsonrpc_server_dispose( struct wf_jsonrpc_server * server); -extern WF_JSONRPC_API void wf_jsonrpc_server_add( +extern void wf_jsonrpc_server_add( struct wf_jsonrpc_server * server, char const * method_name, wf_jsonrpc_method_invoke_fn * invoke, void * user_data); -extern WF_JSONRPC_API void wf_jsonrpc_server_process( +extern void wf_jsonrpc_server_process( struct wf_jsonrpc_server * server, json_t * request, wf_jsonrpc_send_fn * send, diff --git a/lib/wf/timer/src/wf/timer/impl/manager.c b/lib/webfuse/core/timer/manager.c similarity index 73% rename from lib/wf/timer/src/wf/timer/impl/manager.c rename to lib/webfuse/core/timer/manager.c index f198502..99540e9 100644 --- a/lib/wf/timer/src/wf/timer/impl/manager.c +++ b/lib/webfuse/core/timer/manager.c @@ -1,6 +1,6 @@ -#include "wf/timer/impl/manager.h" -#include "wf/timer/impl/timer.h" -#include "wf/timer/impl/timepoint.h" +#include "webfuse/core/timer/manager_intern.h" +#include "webfuse/core/timer/timer_intern.h" +#include "webfuse/core/timer/timepoint.h" #include #include @@ -11,7 +11,7 @@ struct wf_timer_manager }; struct wf_timer_manager * -wf_timer_impl_manager_create(void) +wf_timer_manager_create(void) { struct wf_timer_manager * manager = malloc(sizeof(struct wf_timer_manager)); manager->timers = NULL; @@ -20,7 +20,7 @@ wf_timer_impl_manager_create(void) } void -wf_timer_impl_manager_dispose( +wf_timer_manager_dispose( struct wf_timer_manager * manager) { struct wf_timer * timer = manager->timers; @@ -28,7 +28,7 @@ wf_timer_impl_manager_dispose( { struct wf_timer * next = timer->next; - wf_timer_impl_trigger(timer); + wf_timer_trigger(timer); timer = next; } @@ -36,7 +36,7 @@ wf_timer_impl_manager_dispose( } -void wf_timer_impl_manager_check( +void wf_timer_manager_check( struct wf_timer_manager * manager) { struct wf_timer * timer = manager->timers; @@ -44,17 +44,17 @@ void wf_timer_impl_manager_check( { struct wf_timer * next = timer->next; - if (wf_timer_impl_is_timeout(timer)) + if (wf_timer_is_timeout(timer)) { - wf_timer_impl_manager_removetimer(manager, timer); - wf_timer_impl_trigger(timer); + wf_timer_manager_removetimer(manager, timer); + wf_timer_trigger(timer); } timer = next; } } -void wf_timer_impl_manager_addtimer( +void wf_timer_manager_addtimer( struct wf_timer_manager * manager, struct wf_timer * timer) { @@ -68,7 +68,7 @@ void wf_timer_impl_manager_addtimer( manager->timers = timer; } -void wf_timer_impl_manager_removetimer( +void wf_timer_manager_removetimer( struct wf_timer_manager * manager, struct wf_timer * timer) { diff --git a/lib/wf/timer/include/wf/timer/manager.h b/lib/webfuse/core/timer/manager.h similarity index 72% rename from lib/wf/timer/include/wf/timer/manager.h rename to lib/webfuse/core/timer/manager.h index e0febc0..870a2d0 100644 --- a/lib/wf/timer/include/wf/timer/manager.h +++ b/lib/webfuse/core/timer/manager.h @@ -1,8 +1,6 @@ #ifndef WF_TIMER_MANAGER_H #define WF_TIMER_MANAGER_H -#include - #ifdef __cplusplus extern "C" { @@ -10,14 +8,14 @@ extern "C" struct wf_timer_manager; -extern WF_TIMER_API struct wf_timer_manager * +extern struct wf_timer_manager * wf_timer_manager_create(void); -extern WF_TIMER_API void +extern void wf_timer_manager_dispose( struct wf_timer_manager * manager); -extern WF_TIMER_API void +extern void wf_timer_manager_check( struct wf_timer_manager * manager); diff --git a/lib/webfuse/core/timer/manager_intern.h b/lib/webfuse/core/timer/manager_intern.h new file mode 100644 index 0000000..473df2b --- /dev/null +++ b/lib/webfuse/core/timer/manager_intern.h @@ -0,0 +1,26 @@ +#ifndef WF_TIMER_MANAGER_INTERN_H +#define WF_TIMER_MANAGER_INTERN_H + +#include "webfuse/core/timer/manager.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_timer; + +extern void wf_timer_manager_addtimer( + struct wf_timer_manager * manager, + struct wf_timer * timer); + +extern void wf_timer_manager_removetimer( + struct wf_timer_manager * manager, + struct wf_timer * timer); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/lib/wf/timer/include/wf/timer/on_timer_fn.h b/lib/webfuse/core/timer/on_timer_fn.h similarity index 100% rename from lib/wf/timer/include/wf/timer/on_timer_fn.h rename to lib/webfuse/core/timer/on_timer_fn.h diff --git a/lib/wf/timer/src/wf/timer/impl/timepoint.c b/lib/webfuse/core/timer/timepoint.c similarity index 59% rename from lib/wf/timer/src/wf/timer/impl/timepoint.c rename to lib/webfuse/core/timer/timepoint.c index 877b9c9..09fc025 100644 --- a/lib/wf/timer/src/wf/timer/impl/timepoint.c +++ b/lib/webfuse/core/timer/timepoint.c @@ -1,11 +1,11 @@ -#include "wf/timer/impl/timepoint.h" +#include "webfuse/core/timer/timepoint.h" #include #define WF_TIMER_MSEC_PER_SEC ((wf_timer_timepoint) 1000) #define WF_TIMER_NSEC_PER_MSEC ((wf_timer_timepoint) 1000 * 1000) -wf_timer_timepoint wf_timer_impl_timepoint_now(void) +wf_timer_timepoint wf_timer_timepoint_now(void) { struct timespec tp; clock_gettime(CLOCK_MONOTONIC, &tp); @@ -14,17 +14,17 @@ wf_timer_timepoint wf_timer_impl_timepoint_now(void) return now; } -wf_timer_timepoint wf_timer_impl_timepoint_in_msec(wf_timer_timediff value) +wf_timer_timepoint wf_timer_timepoint_in_msec(wf_timer_timediff value) { - wf_timer_timepoint const now = wf_timer_impl_timepoint_now(); + wf_timer_timepoint const now = wf_timer_timepoint_now(); wf_timer_timepoint result = now + ((wf_timer_timepoint) value); return result; } -bool wf_timer_impl_timepoint_is_elapsed(wf_timer_timepoint tp) +bool wf_timer_timepoint_is_elapsed(wf_timer_timepoint tp) { - wf_timer_timepoint const now = wf_timer_impl_timepoint_now(); + wf_timer_timepoint const now = wf_timer_timepoint_now(); wf_timer_timediff const diff = (wf_timer_timediff) (tp - now); return (0 > diff); diff --git a/lib/wf/timer/src/wf/timer/impl/timepoint.h b/lib/webfuse/core/timer/timepoint.h similarity index 57% rename from lib/wf/timer/src/wf/timer/impl/timepoint.h rename to lib/webfuse/core/timer/timepoint.h index 584aa92..cb78197 100644 --- a/lib/wf/timer/src/wf/timer/impl/timepoint.h +++ b/lib/webfuse/core/timer/timepoint.h @@ -1,5 +1,5 @@ -#ifndef WF_TIMER_IMPL_TIMEPOINT_H -#define WF_TIMER_IMPL_TIMEPOINT_H +#ifndef WF_TIMER_TIMEPOINT_H +#define WF_TIMER_TIMEPOINT_H #ifndef __cplusplus #include @@ -16,12 +16,12 @@ extern "C" typedef uint64_t wf_timer_timepoint; typedef int64_t wf_timer_timediff; -extern wf_timer_timepoint wf_timer_impl_timepoint_now(void); +extern wf_timer_timepoint wf_timer_timepoint_now(void); -extern wf_timer_timepoint wf_timer_impl_timepoint_in_msec( +extern wf_timer_timepoint wf_timer_timepoint_in_msec( wf_timer_timediff value); -extern bool wf_timer_impl_timepoint_is_elapsed( +extern bool wf_timer_timepoint_is_elapsed( wf_timer_timepoint timepoint); #ifdef __cplusplus diff --git a/lib/wf/timer/src/wf/timer/impl/timer.c b/lib/webfuse/core/timer/timer.c similarity index 61% rename from lib/wf/timer/src/wf/timer/impl/timer.c rename to lib/webfuse/core/timer/timer.c index 5559451..1f4d650 100644 --- a/lib/wf/timer/src/wf/timer/impl/timer.c +++ b/lib/webfuse/core/timer/timer.c @@ -1,13 +1,13 @@ -#include "wf/timer/impl/timer.h" -#include "wf/timer/impl/manager.h" -#include "wf/timer/impl/timepoint.h" +#include "webfuse/core/timer/timer_intern.h" +#include "webfuse/core/timer/manager_intern.h" +#include "webfuse/core/timer/timepoint.h" #include #include #include struct wf_timer * -wf_timer_impl_create( +wf_timer_create( struct wf_timer_manager * manager, wf_timer_on_timer_fn * on_timer, void * user_data) @@ -24,37 +24,37 @@ wf_timer_impl_create( } void -wf_timer_impl_dispose( +wf_timer_dispose( struct wf_timer * timer) { free(timer); } -void wf_timer_impl_start( +void wf_timer_start( struct wf_timer * timer, int timeout_ms) { - timer->timeout = wf_timer_impl_timepoint_in_msec(timeout_ms); + timer->timeout = wf_timer_timepoint_in_msec(timeout_ms); - wf_timer_impl_manager_addtimer(timer->manager, timer); + wf_timer_manager_addtimer(timer->manager, timer); } -void wf_timer_impl_cancel( +void wf_timer_cancel( struct wf_timer * timer) { - wf_timer_impl_manager_removetimer(timer->manager, timer); + wf_timer_manager_removetimer(timer->manager, timer); timer->timeout = 0; } -bool wf_timer_impl_is_timeout( +bool wf_timer_is_timeout( struct wf_timer * timer) { - return wf_timer_impl_timepoint_is_elapsed(timer->timeout); + return wf_timer_timepoint_is_elapsed(timer->timeout); } -void wf_timer_impl_trigger( +void wf_timer_trigger( struct wf_timer * timer) { if (0 != timer->on_timer) diff --git a/lib/wf/timer/include/wf/timer/timer.h b/lib/webfuse/core/timer/timer.h similarity index 72% rename from lib/wf/timer/include/wf/timer/timer.h rename to lib/webfuse/core/timer/timer.h index 686eb89..48149bd 100644 --- a/lib/wf/timer/include/wf/timer/timer.h +++ b/lib/webfuse/core/timer/timer.h @@ -1,8 +1,7 @@ #ifndef WF_TIMER_TIMER_H #define WF_TIMER_TIMER_H -#include -#include +#include "webfuse/core/timer/on_timer_fn.h" #ifdef __cplusplus extern "C" @@ -12,22 +11,22 @@ extern "C" struct wf_timer; struct wf_timer_manager; -extern WF_TIMER_API struct wf_timer * +extern struct wf_timer * wf_timer_create( struct wf_timer_manager * manager, wf_timer_on_timer_fn * on_timer, void * user_data); -extern WF_TIMER_API void +extern void wf_timer_dispose( struct wf_timer * timer); -extern WF_TIMER_API void +extern void wf_timer_start( struct wf_timer * timer, int timeout_ms); -extern WF_TIMER_API void +extern void wf_timer_cancel( struct wf_timer * timer); diff --git a/lib/webfuse/core/timer/timer_intern.h b/lib/webfuse/core/timer/timer_intern.h new file mode 100644 index 0000000..c910a3b --- /dev/null +++ b/lib/webfuse/core/timer/timer_intern.h @@ -0,0 +1,40 @@ +#ifndef WF_TIMER_TIMER_H +#define WF_TIMER_TIMER_H + +#include "webfuse/core/timer/timer.h" +#include "webfuse/core/timer/on_timer_fn.h" +#include "webfuse/core/timer/timepoint.h" + +#ifndef __cplusplus +#include +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_timer +{ + struct wf_timer_manager * manager; + wf_timer_timepoint timeout; + wf_timer_on_timer_fn * on_timer; + void * user_data; + struct wf_timer * next; + struct wf_timer * prev; +}; + +extern bool wf_timer_is_timeout( + struct wf_timer * timer); + +extern void wf_timer_trigger( + struct wf_timer * timer); + + +#ifdef __cplusplus +} +#endif + + + +#endif diff --git a/lib/webfuse/provider/impl/client_protocol.c b/lib/webfuse/provider/impl/client_protocol.c index 4e2b176..a85514a 100644 --- a/lib/webfuse/provider/impl/client_protocol.c +++ b/lib/webfuse/provider/impl/client_protocol.c @@ -16,11 +16,11 @@ #include "webfuse/provider/impl/url.h" #include "webfuse/core/protocol_names.h" -#include "wf/timer/manager.h" +#include "webfuse/core/timer/manager.h" -#include "wf/jsonrpc/response.h" -#include "wf/jsonrpc/request.h" -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/response.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/jsonrpc/proxy.h" #define WF_DEFAULT_TIMEOUT (10 * 1000) diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc.h b/lib/wf/jsonrpc/include/wf/jsonrpc.h deleted file mode 100644 index ab7f1dc..0000000 --- a/lib/wf/jsonrpc/include/wf/jsonrpc.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef WF_JSONRPC_H -#define WF_JSONRPC_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/api.h b/lib/wf/jsonrpc/include/wf/jsonrpc/api.h deleted file mode 100644 index 648bf0f..0000000 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/api.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef WF_JSONRPC_API_H -#define WF_JSONRPC_API_H - -#ifndef WF_JSONRPC_API -#define WF_JSONRPC_API -#endif - -#endif diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/status.h b/lib/wf/jsonrpc/include/wf/jsonrpc/status.h deleted file mode 100644 index 85da73d..0000000 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/status.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef WF_JSONRPC_STATUS_H -#define WF_JSONRPC_STATUS_H - -#define WF_JSONRPC_GOOD 0 -#define WF_JSONRPC_BAD -1 -#define WF_JSONRPC_BAD_NOTIMPLEMENTED -2 -#define WF_JSONRPC_BAD_TIMEOUT -3 -#define WF_JSONRPC_BAD_BUSY -4 -#define WF_JSONRPC_BAD_FORMAT -5 - -#endif diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/api.c b/lib/wf/jsonrpc/src/wf/jsonrpc/api.c deleted file mode 100644 index 891bcce..0000000 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/api.c +++ /dev/null @@ -1,144 +0,0 @@ -#include "wf/jsonrpc.h" - -#include "wf/jsonrpc/impl/proxy.h" -#include "wf/jsonrpc/impl/request.h" -#include "wf/jsonrpc/impl/response.h" -#include "wf/jsonrpc/impl/server.h" - -// proxy - -struct wf_jsonrpc_proxy * -wf_jsonrpc_proxy_create( - struct wf_timer_manager * manager, - int timeout, - wf_jsonrpc_send_fn * send, - void * user_data) -{ - return wf_jsonrpc_impl_proxy_create(manager, timeout, send, user_data); -} - -void wf_jsonrpc_proxy_dispose( - struct wf_jsonrpc_proxy * proxy) -{ - wf_jsonrpc_impl_proxy_dispose(proxy); -} - -void wf_jsonrpc_proxy_invoke( - struct wf_jsonrpc_proxy * proxy, - wf_jsonrpc_proxy_finished_fn * finished, - void * user_data, - char const * method_name, - char const * param_info, - ... -) -{ - va_list args; - va_start(args, param_info); - wf_jsonrpc_impl_proxy_invoke(proxy, finished, user_data, method_name, param_info, args); - va_end(args); -} - -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_impl_proxy_notify(proxy, method_name, param_info, args); - va_end(args); -} - -void wf_jsonrpc_proxy_onresult( - struct wf_jsonrpc_proxy * proxy, - json_t * message) -{ - wf_jsonrpc_impl_proxy_onresult(proxy, message); -} - - -// request - -bool wf_jsonrpc_is_request( - json_t * message) -{ - return wf_jsonrpc_impl_is_request(message); -} - -struct wf_jsonrpc_request * wf_jsonrpc_request_create( - int id, - wf_jsonrpc_send_fn * send, - void * user_data) -{ - return wf_jsonrpc_impl_request_create(id, send, user_data); -} - -void wf_jsonrpc_request_dispose( - struct wf_jsonrpc_request * request) -{ - wf_jsonrpc_impl_request_dispose(request); -} - -void * wf_jsonrpc_request_get_userdata( - struct wf_jsonrpc_request * request) -{ - return wf_jsonrpc_impl_request_get_userdata(request); -} - -void wf_jsonrpc_respond( - struct wf_jsonrpc_request * request, - json_t * result) -{ - wf_jsonrpc_impl_respond(request, result); -} - -void wf_jsonrpc_respond_error( - struct wf_jsonrpc_request * request, - int code, - char const * message) -{ - wf_jsonrpc_impl_respond_error(request, code, message); -} - -// response - -bool wf_jsonrpc_is_response( - json_t * message) -{ - return wf_jsonrpc_impl_is_response(message); -} - -// server - -struct wf_jsonrpc_server * -wf_jsonrpc_server_create(void) -{ - return wf_jsonrpc_impl_server_create(); -} - -void -wf_jsonrpc_server_dispose( - struct wf_jsonrpc_server * server) -{ - wf_jsonrpc_impl_server_dispose(server); -} - -void wf_jsonrpc_server_add( - struct wf_jsonrpc_server * server, - char const * method_name, - wf_jsonrpc_method_invoke_fn * invoke, - void * user_data) -{ - wf_jsonrpc_impl_server_add(server, method_name, invoke, user_data); -} - -void wf_jsonrpc_server_process( - struct wf_jsonrpc_server * server, - json_t * request, - wf_jsonrpc_send_fn * send, - void * user_data) -{ - wf_jsonrpc_impl_server_process(server, request, send, user_data); -} diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h deleted file mode 100644 index 60d2f7a..0000000 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef WF_JSONRPC_IMPL_PROXY_H -#define WF_JSONRPC_IMPL_PROXY_H - -#include "wf/jsonrpc/proxy_finished_fn.h" -#include "wf/jsonrpc/send_fn.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wf_timer_manager; -struct wf_timer; - -struct wf_jsonrpc_request -{ - bool is_pending; - wf_jsonrpc_proxy_finished_fn * finished; - void * user_data; - int id; - struct wf_timer * timer; -}; - -struct wf_jsonrpc_proxy -{ - struct wf_jsonrpc_request request; - int timeout; - wf_jsonrpc_send_fn * send; - void * user_data; -}; - -extern void -wf_jsonrpc_impl_proxy_init( - struct wf_jsonrpc_proxy * proxy, - struct wf_timer_manager * manager, - int timeout, - wf_jsonrpc_send_fn * send, - void * user_data); - -extern void -wf_jsonrpc_impl_proxy_cleanup( - struct wf_jsonrpc_proxy * proxy); - -extern struct wf_jsonrpc_proxy * -wf_jsonrpc_impl_proxy_create( - struct wf_timer_manager * manager, - int timeout, - wf_jsonrpc_send_fn * send, - void * user_data); - -extern void -wf_jsonrpc_impl_proxy_dispose( - struct wf_jsonrpc_proxy * proxy); - - -extern void -wf_jsonrpc_impl_proxy_invoke( - struct wf_jsonrpc_proxy * proxy, - wf_jsonrpc_proxy_finished_fn * finished, - void * user_data, - char const * method_name, - char const * param_info, - va_list args -); - -extern void -wf_jsonrpc_impl_proxy_notify( - struct wf_jsonrpc_proxy * proxy, - char const * method_name, - char const * param_info, - va_list args -); - -extern void -wf_jsonrpc_impl_proxy_onresult( - struct wf_jsonrpc_proxy * proxy, - json_t * message); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h deleted file mode 100644 index 0d510e9..0000000 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef WF_JSONRPC_IMPL_REQUEST_H -#define WF_JSONRPC_IMPL_REQUEST_H - -#ifndef __cplusplus -#include -#include -#include -#else -#include -#include -using std::size_t; -#endif - -#include -#include -#include "wf/jsonrpc/send_fn.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wf_jsonrpc_request; - -extern bool wf_jsonrpc_impl_is_request( - json_t * message); - -extern struct wf_jsonrpc_request * wf_jsonrpc_impl_request_create( - int id, - wf_jsonrpc_send_fn * send, - void * user_data); - -extern void wf_jsonrpc_impl_request_dispose( - struct wf_jsonrpc_request * request); - -extern void * wf_jsonrpc_impl_request_get_userdata( - struct wf_jsonrpc_request * request); - -extern void wf_jsonrpc_impl_respond( - struct wf_jsonrpc_request * request, - json_t * result); - -extern void wf_jsonrpc_impl_respond_error( - struct wf_jsonrpc_request * request, - int code, - char const * message); - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h deleted file mode 100644 index 82c7421..0000000 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef WF_JSONRPC_IMPL_SERVER_H -#define WF_JSONRPC_IMPL_SERVER_H - -#include -#include "wf/jsonrpc/method_invoke_fn.h" -#include "wf/jsonrpc/send_fn.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wf_jsonrpc_server; - -extern struct wf_jsonrpc_server * -wf_jsonrpc_impl_server_create(void); - -extern void -wf_jsonrpc_impl_server_dispose( - struct wf_jsonrpc_server * server); - -extern void -wf_jsonrpc_impl_server_add( - struct wf_jsonrpc_server * server, - char const * method_name, - wf_jsonrpc_method_invoke_fn * invoke, - void * user_data); - -extern void -wf_jsonrpc_impl_server_process( - struct wf_jsonrpc_server * server, - json_t * request, - wf_jsonrpc_send_fn * send, - void * user_data); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/unused_param.h b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/unused_param.h deleted file mode 100644 index 41323c8..0000000 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/unused_param.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef WF_JSONRPC_UTIL_H -#define WF_JSONRPC_UTIL_H - -#ifdef __GNUC__ -#define WF_JSONRPC_UNUSED_PARAM(param) param __attribute__((unused)) -#else -#define WF_JSONRPC_UNUSED_PARAM(param) -#endif - -#endif diff --git a/lib/wf/timer/include/wf/timer.h b/lib/wf/timer/include/wf/timer.h deleted file mode 100644 index 341792b..0000000 --- a/lib/wf/timer/include/wf/timer.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef WF_TIMER_H -#define WF_TIMER_H - -#include -#include -#include -#include - -#endif diff --git a/lib/wf/timer/include/wf/timer/api.h b/lib/wf/timer/include/wf/timer/api.h deleted file mode 100644 index c327ba7..0000000 --- a/lib/wf/timer/include/wf/timer/api.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef WF_TIMER_API_H -#define WF_TIMER_API_H - -#ifndef WF_TIMER_API -#define WF_TIMER_API -#endif - -#endif diff --git a/lib/wf/timer/src/wf/timer/api.c b/lib/wf/timer/src/wf/timer/api.c deleted file mode 100644 index d0399a9..0000000 --- a/lib/wf/timer/src/wf/timer/api.c +++ /dev/null @@ -1,59 +0,0 @@ -#include "wf/timer.h" - -#include "wf/timer/impl/manager.h" -#include "wf/timer/impl/timer.h" - -// manager - -struct wf_timer_manager * -wf_timer_manager_create(void) -{ - return wf_timer_impl_manager_create(); -} - -void -wf_timer_manager_dispose( - struct wf_timer_manager * manager) -{ - wf_timer_impl_manager_dispose(manager); -} - -void -wf_timer_manager_check( - struct wf_timer_manager * manager) -{ - wf_timer_impl_manager_check(manager); -} - -// timer - -struct wf_timer * -wf_timer_create( - struct wf_timer_manager * manager, - wf_timer_on_timer_fn * on_timer, - void * user_data) -{ - return wf_timer_impl_create(manager, on_timer, user_data); -} - -void -wf_timer_dispose( - struct wf_timer * timer) -{ - wf_timer_impl_dispose(timer); -} - -void -wf_timer_start( - struct wf_timer * timer, - int timeout_ms) -{ - wf_timer_impl_start(timer, timeout_ms); -} - -void -wf_timer_cancel( - struct wf_timer * timer) -{ - wf_timer_impl_cancel(timer); -} diff --git a/lib/wf/timer/src/wf/timer/impl/manager.h b/lib/wf/timer/src/wf/timer/impl/manager.h deleted file mode 100644 index c4fc64a..0000000 --- a/lib/wf/timer/src/wf/timer/impl/manager.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef WF_TIMER_IMPL_MANAGER_H -#define WF_TIMER_IMPL_MANAGER_H - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wf_timer; -struct wf_timer_manager; - -extern struct wf_timer_manager * -wf_timer_impl_manager_create(void); - -extern void -wf_timer_impl_manager_dispose( - struct wf_timer_manager * manager); - -extern void -wf_timer_impl_manager_check( - struct wf_timer_manager * manager); - -extern void wf_timer_impl_manager_addtimer( - struct wf_timer_manager * manager, - struct wf_timer * timer); - -extern void wf_timer_impl_manager_removetimer( - struct wf_timer_manager * manager, - struct wf_timer * timer); - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/wf/timer/src/wf/timer/impl/timer.h b/lib/wf/timer/src/wf/timer/impl/timer.h deleted file mode 100644 index 2e18a8b..0000000 --- a/lib/wf/timer/src/wf/timer/impl/timer.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef WF_ADAPTER_IMPL_TIME_TIMER_H -#define WF_ADAPTER_IMPL_TIME_TIMER_H - -#include "wf/timer/on_timer_fn.h" -#include "wf/timer/impl/timepoint.h" - -#ifndef __cplusplus -#include -#endif - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wf_timer_manager; - -struct wf_timer -{ - struct wf_timer_manager * manager; - wf_timer_timepoint timeout; - wf_timer_on_timer_fn * on_timer; - void * user_data; - struct wf_timer * next; - struct wf_timer * prev; -}; - - -struct wf_timer * -wf_timer_impl_create( - struct wf_timer_manager * manager, - wf_timer_on_timer_fn * on_timer, - void * user_data); - -void -wf_timer_impl_dispose( - struct wf_timer * timer); - -extern void wf_timer_impl_start( - struct wf_timer * timer, - int timeout_ms); - -extern void wf_timer_impl_cancel( - struct wf_timer * timer); - -extern bool wf_timer_impl_is_timeout( - struct wf_timer * timer); - -extern void wf_timer_impl_trigger( - struct wf_timer * timer); - - -#ifdef __cplusplus -} -#endif - - - -#endif diff --git a/lib/wf/timer/test/wf/timer/test_timepoint.cc b/lib/wf/timer/test/wf/timer/test_timepoint.cc deleted file mode 100644 index 723ff6a..0000000 --- a/lib/wf/timer/test/wf/timer/test_timepoint.cc +++ /dev/null @@ -1,38 +0,0 @@ -#include - -#include "wf/timer/impl/timepoint.h" - -#include -#include - -using namespace std::chrono_literals; - -TEST(wf_timer_timepoint, now) -{ - wf_timer_timepoint start = wf_timer_impl_timepoint_now(); - std::this_thread::sleep_for(42ms); - wf_timer_timepoint end = wf_timer_impl_timepoint_now(); - - ASSERT_LT(start, end); - ASSERT_LT(end, start + 500); -} - -TEST(wf_timer_timepoint, in_msec) -{ - wf_timer_timepoint now = wf_timer_impl_timepoint_now(); - wf_timer_timepoint later = wf_timer_impl_timepoint_in_msec(42); - - ASSERT_LT(now, later); - ASSERT_LT(later, now + 500); -} - -TEST(wf_timer_timepoint, elapsed) -{ - wf_timer_timepoint now; - - now = wf_timer_impl_timepoint_now(); - ASSERT_TRUE(wf_timer_impl_timepoint_is_elapsed(now - 1)); - - now = wf_timer_impl_timepoint_now(); - ASSERT_FALSE(wf_timer_impl_timepoint_is_elapsed(now + 500)); -} diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc b/test/webfuse/tests/core/jsonrpc/mock_timer.cc similarity index 90% rename from lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc rename to test/webfuse/tests/core/jsonrpc/mock_timer.cc index bdfde2b..3cf8e74 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc +++ b/test/webfuse/tests/core/jsonrpc/mock_timer.cc @@ -1,5 +1,5 @@ -#include "wf/jsonrpc/mock_timer.hpp" -#include "wf/jsonrpc/wrap.hpp" +#include "webfuse/tests/core/jsonrpc/mock_timer.hpp" +#include "webfuse/utils/wrap.hpp" extern "C" { diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.hpp b/test/webfuse/tests/core/jsonrpc/mock_timer.hpp similarity index 94% rename from lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.hpp rename to test/webfuse/tests/core/jsonrpc/mock_timer.hpp index 3fde45e..5c95852 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.hpp +++ b/test/webfuse/tests/core/jsonrpc/mock_timer.hpp @@ -1,7 +1,8 @@ #ifndef WF_JSONRPC_MOCK_TIMERMANAGER_HPP #define WF_JSONRPC_MOCK_TIMERMANAGER_HPP -#include +#include "webfuse/core/timer/timer.h" +#include "webfuse/core/timer/manager.h" #include namespace wf_jsonrpc_test diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc b/test/webfuse/tests/core/jsonrpc/mock_timer_callback.cc similarity index 90% rename from lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc rename to test/webfuse/tests/core/jsonrpc/mock_timer_callback.cc index dd3cc3b..7e62c31 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc +++ b/test/webfuse/tests/core/jsonrpc/mock_timer_callback.cc @@ -1,4 +1,4 @@ -#include "wf/jsonrpc/mock_timer_callback.hpp" +#include "webfuse/tests/core/jsonrpc/mock_timer_callback.hpp" extern "C" { diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.hpp b/test/webfuse/tests/core/jsonrpc/mock_timer_callback.hpp similarity index 89% rename from lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.hpp rename to test/webfuse/tests/core/jsonrpc/mock_timer_callback.hpp index cdbf2d6..e55b7e1 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.hpp +++ b/test/webfuse/tests/core/jsonrpc/mock_timer_callback.hpp @@ -1,7 +1,7 @@ #ifndef WF_JSONRPC_MOCK_TIMERCALLBACK_HPP #define WF_JSONRPC_MOCK_TIMERCALLBACK_HPP -#include "wf/timer.h" +#include "webfuse/core/timer/on_timer_fn.h" #include namespace wf_jsonrpc_test diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc b/test/webfuse/tests/core/jsonrpc/test_is_request.cc similarity index 98% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc rename to test/webfuse/tests/core/jsonrpc/test_is_request.cc index 55e40c6..4599611 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc +++ b/test/webfuse/tests/core/jsonrpc/test_is_request.cc @@ -1,5 +1,5 @@ #include -#include "wf/jsonrpc/request.h" +#include "webfuse/core/jsonrpc/request.h" TEST(wf_jsonrpc_is_request, request_with_object_params) { diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc b/test/webfuse/tests/core/jsonrpc/test_is_response.cc similarity index 98% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc rename to test/webfuse/tests/core/jsonrpc/test_is_response.cc index 690bb6c..908ddf0 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc +++ b/test/webfuse/tests/core/jsonrpc/test_is_response.cc @@ -1,5 +1,5 @@ #include -#include "wf/jsonrpc/response.h" +#include "webfuse/core/jsonrpc/response.h" TEST(wf_jsonrpc_is_response, valid_result) { diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc b/test/webfuse/tests/core/jsonrpc/test_proxy.cc similarity index 97% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc rename to test/webfuse/tests/core/jsonrpc/test_proxy.cc index 763fa51..bdc8a15 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc +++ b/test/webfuse/tests/core/jsonrpc/test_proxy.cc @@ -1,9 +1,9 @@ #include -#include "wf/jsonrpc/proxy.h" -#include "wf/jsonrpc/status.h" -#include "wf/timer/manager.h" +#include "webfuse/core/jsonrpc/proxy.h" +#include "webfuse/core/status.h" +#include "webfuse/core/timer/manager.h" -#include "wf/jsonrpc/mock_timer.hpp" +#include "webfuse/tests/core/jsonrpc/mock_timer.hpp" #include #include @@ -22,7 +22,7 @@ namespace int jsonrpc_get_status(json_t * error) { json_t * code = json_object_get(error, "code"); - return (json_is_integer(code)) ? json_integer_value(code) : WF_JSONRPC_BAD_FORMAT; + return (json_is_integer(code)) ? json_integer_value(code) : WF_BAD_FORMAT; } struct SendContext @@ -196,7 +196,7 @@ TEST(wf_jsonrpc_proxy, invoke_fails_if_another_request_is_pending) ASSERT_FALSE(finished_context.is_called); ASSERT_TRUE(finished_context2.is_called); - ASSERT_EQ(WF_JSONRPC_BAD_BUSY, jsonrpc_get_status(finished_context2.error)); + ASSERT_EQ(WF_BAD_BUSY, jsonrpc_get_status(finished_context2.error)); wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); @@ -217,7 +217,7 @@ TEST(wf_jsonrpc_proxy, invoke_fails_if_request_is_invalid) ASSERT_FALSE(send_context.is_called); ASSERT_TRUE(finished_context.is_called); - ASSERT_EQ(WF_JSONRPC_BAD, jsonrpc_get_status(finished_context.error)); + ASSERT_EQ(WF_BAD, jsonrpc_get_status(finished_context.error)); wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); @@ -307,7 +307,7 @@ TEST(wf_jsonrpc_proxy, timeout) wf_timer_manager_check(timer_manager); ASSERT_TRUE(finished_context.is_called); - ASSERT_EQ(WF_JSONRPC_BAD_TIMEOUT, jsonrpc_get_status(finished_context.error)); + ASSERT_EQ(WF_BAD_TIMEOUT, jsonrpc_get_status(finished_context.error)); wf_jsonrpc_proxy_dispose(proxy); wf_timer_manager_dispose(timer_manager); diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc b/test/webfuse/tests/core/jsonrpc/test_request.cc similarity index 95% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc rename to test/webfuse/tests/core/jsonrpc/test_request.cc index a8f7986..8d37a9f 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc +++ b/test/webfuse/tests/core/jsonrpc/test_request.cc @@ -1,6 +1,6 @@ #include -#include "wf/jsonrpc/request.h" -#include "wf/jsonrpc/status.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/status.h" namespace { @@ -74,7 +74,7 @@ TEST(wf_jsonrpc_request, respond_error) struct wf_jsonrpc_request * request = wf_jsonrpc_request_create(42, &jsonrpc_send, user_data); - wf_jsonrpc_respond_error(request, WF_JSONRPC_BAD, "Bad"); + wf_jsonrpc_respond_error(request, WF_BAD, "Bad"); ASSERT_NE(nullptr, context.response); @@ -93,7 +93,7 @@ TEST(wf_jsonrpc_request, respond_error) json_t * err_code = json_object_get(err, "code"); ASSERT_TRUE(json_is_integer(err_code)); - ASSERT_EQ(WF_JSONRPC_BAD, json_integer_value(err_code)); + ASSERT_EQ(WF_BAD, json_integer_value(err_code)); json_t * err_message = json_object_get(err, "message"); ASSERT_TRUE(json_is_string(err_message)); diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc b/test/webfuse/tests/core/jsonrpc/test_response.cc similarity index 69% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc rename to test/webfuse/tests/core/jsonrpc/test_response.cc index b71d7f3..f6ef9e7 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc +++ b/test/webfuse/tests/core/jsonrpc/test_response.cc @@ -1,6 +1,6 @@ #include -#include "wf/jsonrpc/impl/response.h" -#include "wf/jsonrpc/status.h" +#include "webfuse/core/jsonrpc/response_intern.h" +#include "webfuse/core/status.h" TEST(wf_json_response, init_result) { @@ -9,14 +9,14 @@ TEST(wf_json_response, init_result) json_object_set_new(message, "id", json_integer(11)); struct wf_jsonrpc_response response; - wf_jsonrpc_impl_response_init(&response, message); + wf_jsonrpc_response_init(&response, message); ASSERT_EQ(nullptr, response.error); ASSERT_TRUE(json_is_integer(response.result)); ASSERT_EQ(47, json_integer_value(response.result)); ASSERT_EQ(11, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); json_decref(message); } @@ -30,14 +30,14 @@ TEST(wf_json_response, init_error) json_object_set_new(message, "id", json_integer(23)); struct wf_jsonrpc_response response; - wf_jsonrpc_impl_response_init(&response, message); + wf_jsonrpc_response_init(&response, message); ASSERT_EQ(42, json_integer_value(json_object_get(response.error, "code"))); ASSERT_STREQ("Don't Panic!", json_string_value(json_object_get(response.error, "message"))); ASSERT_EQ(nullptr, response.result); ASSERT_EQ(23, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); json_decref(message); } @@ -47,13 +47,13 @@ TEST(wf_json_response, init_fail_missing_result_and_error) json_object_set_new(message, "id", json_integer(12)); struct wf_jsonrpc_response response; - wf_jsonrpc_impl_response_init(&response, message); + wf_jsonrpc_response_init(&response, message); - ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); + ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(nullptr, response.result); ASSERT_EQ(12, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); json_decref(message); } @@ -63,13 +63,13 @@ TEST(wf_json_response, init_fail_missing_id) json_object_set_new(message, "result", json_integer(47)); struct wf_jsonrpc_response response; - wf_jsonrpc_impl_response_init(&response, message); + wf_jsonrpc_response_init(&response, message); - ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); + ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(nullptr, response.result); ASSERT_EQ(-1, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); json_decref(message); } @@ -80,13 +80,13 @@ TEST(wf_json_response, init_fail_wrong_id_type) json_object_set_new(message, "id", json_string("42")); struct wf_jsonrpc_response response; - wf_jsonrpc_impl_response_init(&response, message); + wf_jsonrpc_response_init(&response, message); - ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); + ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(nullptr, response.result); ASSERT_EQ(-1, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); json_decref(message); } @@ -99,13 +99,13 @@ TEST(wf_json_response, init_fail_error_missing_code) json_object_set_new(message, "id", json_integer(23)); struct wf_jsonrpc_response response; - wf_jsonrpc_impl_response_init(&response, message); + wf_jsonrpc_response_init(&response, message); - ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); + ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(nullptr, response.result); ASSERT_EQ(23, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); json_decref(message); } @@ -119,13 +119,13 @@ TEST(wf_json_response, init_fail_error_wrong_code_type) json_object_set_new(message, "id", json_integer(23)); struct wf_jsonrpc_response response; - wf_jsonrpc_impl_response_init(&response, message); + wf_jsonrpc_response_init(&response, message); - ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); + ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(nullptr, response.result); ASSERT_EQ(23, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); json_decref(message); } @@ -136,12 +136,12 @@ TEST(wf_json_response, init_fail_error_wrong_type) json_object_set_new(message, "id", json_integer(23)); struct wf_jsonrpc_response response; - wf_jsonrpc_impl_response_init(&response, message); + wf_jsonrpc_response_init(&response, message); - ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); + ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(nullptr, response.result); ASSERT_EQ(23, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); json_decref(message); } diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc b/test/webfuse/tests/core/jsonrpc/test_response_parser.cc similarity index 80% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc rename to test/webfuse/tests/core/jsonrpc/test_response_parser.cc index e3301fa..f9941c1 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc +++ b/test/webfuse/tests/core/jsonrpc/test_response_parser.cc @@ -1,7 +1,7 @@ #include #include -#include "wf/jsonrpc/impl/response.h" +#include "webfuse/core/jsonrpc/response_intern.h" static void response_parse_str( @@ -11,7 +11,7 @@ static void response_parse_str( json_t * message = json_loadb(buffer.c_str(), buffer.size(), 0, nullptr); if (nullptr != message) { - wf_jsonrpc_impl_response_init(response, message); + wf_jsonrpc_response_init(response, message); json_decref(message); } } @@ -25,21 +25,21 @@ TEST(response_parser, test) ASSERT_NE(nullptr, response.error); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); // empty response_parse_str("{}", &response); ASSERT_NE(nullptr, response.error); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); // no data response_parse_str("{\"id\":42}", &response); ASSERT_NE(nullptr, response.error); ASSERT_EQ(42, response.id); ASSERT_EQ(nullptr, response.result); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); // custom error code response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response); @@ -47,12 +47,12 @@ TEST(response_parser, test) ASSERT_EQ(42, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(42, response.id); ASSERT_EQ(nullptr, response.result); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); // valid response response_parse_str("{\"result\": true, \"id\": 42}", &response); ASSERT_EQ(nullptr, response.error); ASSERT_EQ(42, response.id); ASSERT_NE(nullptr, response.result); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); } diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc b/test/webfuse/tests/core/jsonrpc/test_server.cc similarity index 97% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc rename to test/webfuse/tests/core/jsonrpc/test_server.cc index 894c607..688028f 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc +++ b/test/webfuse/tests/core/jsonrpc/test_server.cc @@ -1,7 +1,7 @@ #include -#include "wf/jsonrpc/server.h" -#include "wf/jsonrpc/request.h" -#include "wf/jsonrpc/status.h" +#include "webfuse/core/jsonrpc/server.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/status.h" namespace { @@ -125,7 +125,7 @@ TEST(wf_jsonrpc_server, invoke_unknown_method) json_t * err_code = json_object_get(err, "code"); ASSERT_TRUE(json_is_integer(err_code)); - ASSERT_EQ(WF_JSONRPC_BAD_NOTIMPLEMENTED, json_integer_value(err_code)); + ASSERT_EQ(WF_BAD_NOTIMPLEMENTED, json_integer_value(err_code)); json_t * err_message = json_object_get(err, "message"); ASSERT_TRUE(json_is_string(err_message)); diff --git a/test/webfuse/tests/core/timer/test_timepoint.cc b/test/webfuse/tests/core/timer/test_timepoint.cc new file mode 100644 index 0000000..f55adab --- /dev/null +++ b/test/webfuse/tests/core/timer/test_timepoint.cc @@ -0,0 +1,38 @@ +#include + +#include "webfuse/core/timer/timepoint.h" + +#include +#include + +using namespace std::chrono_literals; + +TEST(wf_timer_timepoint, now) +{ + wf_timer_timepoint start = wf_timer_timepoint_now(); + std::this_thread::sleep_for(42ms); + wf_timer_timepoint end = wf_timer_timepoint_now(); + + ASSERT_LT(start, end); + ASSERT_LT(end, start + 500); +} + +TEST(wf_timer_timepoint, in_msec) +{ + wf_timer_timepoint now = wf_timer_timepoint_now(); + wf_timer_timepoint later = wf_timer_timepoint_in_msec(42); + + ASSERT_LT(now, later); + ASSERT_LT(later, now + 500); +} + +TEST(wf_timer_timepoint, elapsed) +{ + wf_timer_timepoint now; + + now = wf_timer_timepoint_now(); + ASSERT_TRUE(wf_timer_timepoint_is_elapsed(now - 1)); + + now = wf_timer_timepoint_now(); + ASSERT_FALSE(wf_timer_timepoint_is_elapsed(now + 500)); +} diff --git a/lib/wf/timer/test/wf/timer/test_timer.cc b/test/webfuse/tests/core/timer/test_timer.cc similarity index 97% rename from lib/wf/timer/test/wf/timer/test_timer.cc rename to test/webfuse/tests/core/timer/test_timer.cc index 2141314..d25b1f5 100644 --- a/lib/wf/timer/test/wf/timer/test_timer.cc +++ b/test/webfuse/tests/core/timer/test_timer.cc @@ -4,8 +4,8 @@ #include #include -#include "wf/timer/timer.h" -#include "wf/timer/manager.h" +#include "webfuse/core/timer/timer.h" +#include "webfuse/core/timer/manager.h" using std::size_t; using namespace std::chrono_literals; diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/wrap.hpp b/test/webfuse/utils/wrap.hpp similarity index 100% rename from lib/wf/jsonrpc/test/wf/jsonrpc/wrap.hpp rename to test/webfuse/utils/wrap.hpp From 39855a99952744188f71c1d623f70772b6d16b91 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 29 Mar 2020 18:38:58 +0200 Subject: [PATCH 12/43] fix: make provider const --- lib/webfuse/provider/impl/provider.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/webfuse/provider/impl/provider.h b/lib/webfuse/provider/impl/provider.h index a9b814d..1e8ec1f 100644 --- a/lib/webfuse/provider/impl/provider.h +++ b/lib/webfuse/provider/impl/provider.h @@ -30,7 +30,7 @@ struct wfp_provider struct wfp_impl_invokation_context { - struct wfp_provider * provider; + struct wfp_provider const * provider; void * user_data; struct wfp_request * request; }; From 8d28da5e82b22e80174d37672252535b4e041714 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 29 Mar 2020 19:30:08 +0200 Subject: [PATCH 13/43] added tests for wfp_impl_close --- cmake/unit_tests.cmake | 2 + test/webfuse/mocks/mock_provider.cc | 138 ++++++++++++++++++ test/webfuse/mocks/mock_provider.hpp | 31 ++++ .../tests/provider/operation/test_close.cc | 111 ++++++++++++++ 4 files changed, 282 insertions(+) create mode 100644 test/webfuse/mocks/mock_provider.cc create mode 100644 test/webfuse/mocks/mock_provider.hpp create mode 100644 test/webfuse/tests/provider/operation/test_close.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 8f21188..adbde38 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -28,6 +28,7 @@ add_executable(alltests test/webfuse/mocks/mock_authenticator.cc test/webfuse/mocks/mock_request.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_container_of.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/provider/test_url.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/server.cc test/webfuse/tests/integration/provider.cc diff --git a/test/webfuse/mocks/mock_provider.cc b/test/webfuse/mocks/mock_provider.cc new file mode 100644 index 0000000..a81b302 --- /dev/null +++ b/test/webfuse/mocks/mock_provider.cc @@ -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(user_data); + provider->connected(); +} + +static void webfuse_test_MockProvider_disconnected( + void * user_data) +{ + auto * provider = reinterpret_cast(user_data); + provider->disconnected(); +} + +static void webfuse_test_MockProvider_on_timer( + void * user_data) +{ + auto * provider = reinterpret_cast(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(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(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(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(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(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(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(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(this); +} + +} \ No newline at end of file diff --git a/test/webfuse/mocks/mock_provider.hpp b/test/webfuse/mocks/mock_provider.hpp new file mode 100644 index 0000000..1f03b08 --- /dev/null +++ b/test/webfuse/mocks/mock_provider.hpp @@ -0,0 +1,31 @@ +#ifndef WF_MOCK_PROVIDER_HPP +#define WF_MOCK_PROVIDER_HPP + +#include "webfuse/provider/impl/provider.h" +#include + +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 diff --git a/test/webfuse/tests/provider/operation/test_close.cc b/test/webfuse/tests/provider/operation/test_close.cc new file mode 100644 index 0000000..8c5fc2d --- /dev/null +++ b/test/webfuse/tests/provider/operation/test_close.cc @@ -0,0 +1,111 @@ +#include "webfuse/provider/impl/operation/close.h" +#include "webfuse/mocks/mock_provider.hpp" + +#include + +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); +} \ No newline at end of file From 70e9f0a278495cfc82133966407bd7ca3a099e6e Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 29 Mar 2020 20:41:31 +0200 Subject: [PATCH 14/43] added tests for wfp_impl_getattr --- cmake/unit_tests.cmake | 1 + test/webfuse/mocks/mock_request.cc | 19 ++++----- test/webfuse/mocks/mock_request.hpp | 16 +------ .../tests/provider/operation/test_getattr.cc | 42 +++++++++++++++++++ 4 files changed, 52 insertions(+), 26 deletions(-) create mode 100644 test/webfuse/tests/provider/operation/test_getattr.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index adbde38..24cf694 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -47,6 +47,7 @@ add_executable(alltests test/webfuse/tests/provider/test_url.cc test/webfuse/tests/provider/test_client_protocol.cc test/webfuse/tests/provider/operation/test_close.cc + test/webfuse/tests/provider/operation/test_getattr.cc test/webfuse/tests/integration/test_integration.cc test/webfuse/tests/integration/server.cc test/webfuse/tests/integration/provider.cc diff --git a/test/webfuse/mocks/mock_request.cc b/test/webfuse/mocks/mock_request.cc index c2dd441..5b31c63 100644 --- a/test/webfuse/mocks/mock_request.cc +++ b/test/webfuse/mocks/mock_request.cc @@ -1,15 +1,14 @@ #include "webfuse/mocks/mock_request.hpp" #include -namespace +extern "C" { -extern "C" void -respond( +static void webfuse_test_MockRequest_respond( json_t * response, void * user_data) { - webfuse_test::Request * request = reinterpret_cast(user_data); + auto * request = reinterpret_cast(user_data); json_t * result = json_object_get(response, "result"); json_t * error = json_object_get(response, "error"); @@ -31,21 +30,17 @@ respond( } } - } namespace webfuse_test { -struct wfp_request * -request_create( - Request * req, - int id) +struct wfp_request * MockRequest::create_request(int id) { - struct wfp_request * request = reinterpret_cast(malloc(sizeof(struct wfp_request))); + auto * request = reinterpret_cast(malloc(sizeof(wfp_request))); + request->respond = &webfuse_test_MockRequest_respond; + request->user_data = reinterpret_cast(this); request->id = id; - request->user_data = reinterpret_cast(req); - request->respond = &respond; return request; } diff --git a/test/webfuse/mocks/mock_request.hpp b/test/webfuse/mocks/mock_request.hpp index 51884f4..fec99d2 100644 --- a/test/webfuse/mocks/mock_request.hpp +++ b/test/webfuse/mocks/mock_request.hpp @@ -10,26 +10,14 @@ 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 +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)); }; -extern struct wfp_request * -request_create( - Request * req, - int id); - MATCHER_P3(GetAttrMatcher, inode, mode, file_type, "") { json_t * inode_holder = json_object_get(arg, "inode"); diff --git a/test/webfuse/tests/provider/operation/test_getattr.cc b/test/webfuse/tests/provider/operation/test_getattr.cc new file mode 100644 index 0000000..39a40c7 --- /dev/null +++ b/test/webfuse/tests/provider/operation/test_getattr.cc @@ -0,0 +1,42 @@ +#include "webfuse/provider/impl/operation/getattr.h" +#include "webfuse/mocks/mock_request.hpp" +#include + +using ::webfuse_test::MockRequest; +using ::webfuse_test::GetAttrMatcher; +using ::testing::_; + +TEST(wfp_impl_getattr, default_responds_error) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond_error(_,42)).Times(1); + + wfp_impl_getattr_default(req, 0, nullptr); +} + +TEST(wfp_impl_getattr, respond_file) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond(GetAttrMatcher(23, 0754, "file"), 42)).Times(1); + + struct stat buffer; + memset(&buffer, 0, sizeof(buffer)); + buffer.st_ino = 23; + buffer.st_mode = S_IFREG | 0754; + wfp_impl_respond_getattr(req, &buffer); +} + +TEST(wfp_impl_getattr, respond_dir) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond(GetAttrMatcher(23, 0754, "dir"), 42)).Times(1); + + struct stat buffer; + memset(&buffer, 0, sizeof(buffer)); + buffer.st_ino = 23; + buffer.st_mode = S_IFDIR | 0754; + wfp_impl_respond_getattr(req, &buffer); +} \ No newline at end of file From e9f371c14a54b358094305a481cf351cb07bf76f Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 30 Mar 2020 20:40:03 +0200 Subject: [PATCH 15/43] added tests for wfp_impl_getattr --- cmake/unit_tests.cmake | 1 + test/webfuse/mocks/fake_invokation_context.cc | 17 +++++ .../webfuse/mocks/fake_invokation_context.hpp | 16 +++++ .../tests/provider/operation/test_close.cc | 16 +---- .../tests/provider/operation/test_getattr.cc | 69 ++++++++++++++++++- 5 files changed, 103 insertions(+), 16 deletions(-) create mode 100644 test/webfuse/mocks/fake_invokation_context.cc create mode 100644 test/webfuse/mocks/fake_invokation_context.hpp diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 24cf694..1205ae4 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -25,6 +25,7 @@ add_executable(alltests test/webfuse/utils/path.c test/webfuse/utils/static_filesystem.c test/webfuse/utils/ws_server.cc + test/webfuse/mocks/fake_invokation_context.cc test/webfuse/mocks/mock_authenticator.cc test/webfuse/mocks/mock_request.cc test/webfuse/mocks/mock_provider_client.cc diff --git a/test/webfuse/mocks/fake_invokation_context.cc b/test/webfuse/mocks/fake_invokation_context.cc new file mode 100644 index 0000000..4aea3ee --- /dev/null +++ b/test/webfuse/mocks/fake_invokation_context.cc @@ -0,0 +1,17 @@ +#include "webfuse/mocks/fake_invokation_context.hpp" + +namespace webfuse_test +{ + +wfp_impl_invokation_context create_context(MockProvider& provider, wfp_request * request) +{ + wfp_impl_invokation_context context = + { + provider.get_provider(), + provider.get_userdata(), + request + }; + return context; +} + +} \ No newline at end of file diff --git a/test/webfuse/mocks/fake_invokation_context.hpp b/test/webfuse/mocks/fake_invokation_context.hpp new file mode 100644 index 0000000..07eb971 --- /dev/null +++ b/test/webfuse/mocks/fake_invokation_context.hpp @@ -0,0 +1,16 @@ +#ifndef FAKE_INVOCATION_CONTEXT_HPP +#define FAKE_INVOCATION_CONTEXT_HPP + +#include "webfuse/provider/impl/provider.h" +#include "webfuse/mocks/mock_provider.hpp" + +namespace webfuse_test +{ + +wfp_impl_invokation_context create_context( + MockProvider& provider, + wfp_request * request = nullptr); + +} + +#endif \ No newline at end of file diff --git a/test/webfuse/tests/provider/operation/test_close.cc b/test/webfuse/tests/provider/operation/test_close.cc index 8c5fc2d..3769579 100644 --- a/test/webfuse/tests/provider/operation/test_close.cc +++ b/test/webfuse/tests/provider/operation/test_close.cc @@ -1,25 +1,13 @@ #include "webfuse/provider/impl/operation/close.h" #include "webfuse/mocks/mock_provider.hpp" +#include "webfuse/mocks/fake_invokation_context.hpp" #include using ::webfuse_test::MockProvider; +using ::webfuse_test::create_context; 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; diff --git a/test/webfuse/tests/provider/operation/test_getattr.cc b/test/webfuse/tests/provider/operation/test_getattr.cc index 39a40c7..b499d1c 100644 --- a/test/webfuse/tests/provider/operation/test_getattr.cc +++ b/test/webfuse/tests/provider/operation/test_getattr.cc @@ -1,10 +1,27 @@ #include "webfuse/provider/impl/operation/getattr.h" #include "webfuse/mocks/mock_request.hpp" -#include +#include "webfuse/mocks/mock_provider.hpp" +#include "webfuse/mocks/fake_invokation_context.hpp" +#include +#include + +using ::webfuse_test::MockProvider; using ::webfuse_test::MockRequest; using ::webfuse_test::GetAttrMatcher; +using ::webfuse_test::create_context; using ::testing::_; +using ::testing::Invoke; + +namespace +{ + +void free_request(wfp_request * request, ino_t) +{ + free(request); +} + +} TEST(wfp_impl_getattr, default_responds_error) { @@ -39,4 +56,52 @@ TEST(wfp_impl_getattr, respond_dir) buffer.st_ino = 23; buffer.st_mode = S_IFDIR | 0754; wfp_impl_respond_getattr(req, &buffer); -} \ No newline at end of file +} + +TEST(wfp_impl_getattr, invoke_provider) +{ + ino_t inode = 23; + MockProvider provider; + EXPECT_CALL(provider,getattr(_, inode)).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); +} + +TEST(wfp_impl_getattr, fail_invalid_param_count) +{ + MockProvider provider; + EXPECT_CALL(provider,getattr(_, _)).Times(0); + + 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); +} + +TEST(wfp_impl_getattr, fail_invalid_inode_type) +{ + MockProvider provider; + EXPECT_CALL(provider,getattr(_, _)).Times(0); + + 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); +} From 2c62e16c98a1ab4d7fb7b98242facf75a13aee15 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 30 Mar 2020 21:16:32 +0200 Subject: [PATCH 16/43] added test for wfp_impl_lookup --- cmake/unit_tests.cmake | 1 + test/webfuse/mocks/mock_request.hpp | 3 +- .../tests/provider/operation/test_getattr.cc | 6 +- .../tests/provider/operation/test_lookup.cc | 129 ++++++++++++++++++ 4 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 test/webfuse/tests/provider/operation/test_lookup.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 1205ae4..3ded8ae 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -49,6 +49,7 @@ add_executable(alltests test/webfuse/tests/provider/test_client_protocol.cc test/webfuse/tests/provider/operation/test_close.cc test/webfuse/tests/provider/operation/test_getattr.cc + test/webfuse/tests/provider/operation/test_lookup.cc test/webfuse/tests/integration/test_integration.cc test/webfuse/tests/integration/server.cc test/webfuse/tests/integration/provider.cc diff --git a/test/webfuse/mocks/mock_request.hpp b/test/webfuse/mocks/mock_request.hpp index fec99d2..e3476ba 100644 --- a/test/webfuse/mocks/mock_request.hpp +++ b/test/webfuse/mocks/mock_request.hpp @@ -18,7 +18,7 @@ public: MOCK_METHOD2(respond_error, void(json_t * error, int id)); }; -MATCHER_P3(GetAttrMatcher, inode, mode, file_type, "") +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))) @@ -44,7 +44,6 @@ MATCHER_P3(GetAttrMatcher, inode, mode, file_type, "") return true; } - MATCHER_P(ReaddirMatcher, contained_elements , "") { if (!json_is_array(arg)) diff --git a/test/webfuse/tests/provider/operation/test_getattr.cc b/test/webfuse/tests/provider/operation/test_getattr.cc index b499d1c..332ab89 100644 --- a/test/webfuse/tests/provider/operation/test_getattr.cc +++ b/test/webfuse/tests/provider/operation/test_getattr.cc @@ -8,7 +8,7 @@ using ::webfuse_test::MockProvider; using ::webfuse_test::MockRequest; -using ::webfuse_test::GetAttrMatcher; +using ::webfuse_test::StatMatcher; using ::webfuse_test::create_context; using ::testing::_; using ::testing::Invoke; @@ -36,7 +36,7 @@ TEST(wfp_impl_getattr, respond_file) { MockRequest request; auto * req = request.create_request(42); - EXPECT_CALL(request, respond(GetAttrMatcher(23, 0754, "file"), 42)).Times(1); + EXPECT_CALL(request, respond(StatMatcher(23, 0754, "file"), 42)).Times(1); struct stat buffer; memset(&buffer, 0, sizeof(buffer)); @@ -49,7 +49,7 @@ TEST(wfp_impl_getattr, respond_dir) { MockRequest request; auto * req = request.create_request(42); - EXPECT_CALL(request, respond(GetAttrMatcher(23, 0754, "dir"), 42)).Times(1); + EXPECT_CALL(request, respond(StatMatcher(23, 0754, "dir"), 42)).Times(1); struct stat buffer; memset(&buffer, 0, sizeof(buffer)); diff --git a/test/webfuse/tests/provider/operation/test_lookup.cc b/test/webfuse/tests/provider/operation/test_lookup.cc new file mode 100644 index 0000000..32d98eb --- /dev/null +++ b/test/webfuse/tests/provider/operation/test_lookup.cc @@ -0,0 +1,129 @@ +#include "webfuse/provider/impl/operation/lookup.h" +#include "webfuse/mocks/mock_request.hpp" +#include "webfuse/mocks/mock_provider.hpp" +#include "webfuse/mocks/fake_invokation_context.hpp" + +#include +#include + +using ::webfuse_test::MockProvider; +using ::webfuse_test::MockRequest; +using ::webfuse_test::StatMatcher; +using ::webfuse_test::create_context; +using ::testing::_; +using ::testing::Invoke; +using ::testing::StrEq; + +namespace +{ + +void free_request(wfp_request * request, ino_t, char const *) +{ + free(request); +} + +} + +TEST(wfp_impl_lookup, invoke_provider) +{ + ino_t inode = 42; + MockProvider provider; + EXPECT_CALL(provider,lookup(_, inode,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); +} + +TEST(wfp_impl_lookup, fail_invalid_param_count) +{ + MockProvider provider; + EXPECT_CALL(provider,lookup(_, _,_)).Times(0); + + 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); +} + +TEST(wfp_impl_lookup, fail_invalid_inode_type) +{ + MockProvider provider; + EXPECT_CALL(provider,lookup(_, _,_)).Times(0); + + 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); +} + +TEST(wfp_impl_lookup, fail_invalid_name_type) +{ + MockProvider provider; + EXPECT_CALL(provider,lookup(_, _,_)).Times(0); + + 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_integer(1)); + + wfp_impl_lookup(&context, params, 42); + json_decref(params); +} + +TEST(wfp_impl_lookup, default_responds_error) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond_error(_,42)).Times(1); + + wfp_impl_lookup_default(req, 1, "some.file", nullptr); +} + +TEST(wfp_impl_lookup, respond_file) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond(StatMatcher(23, 0754, "file"), 42)).Times(1); + + struct stat buffer; + memset(&buffer, 0, sizeof(buffer)); + buffer.st_ino = 23; + buffer.st_mode = S_IFREG | 0754; + wfp_impl_respond_lookup(req, &buffer); +} + +TEST(wfp_impl_lookup, respond_dir) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond(StatMatcher(23, 0754, "dir"), 42)).Times(1); + + struct stat buffer; + memset(&buffer, 0, sizeof(buffer)); + buffer.st_ino = 23; + buffer.st_mode = S_IFDIR | 0754; + wfp_impl_respond_lookup(req, &buffer); +} From 821c67ee4661a53c8122832107f6d3952f015bdd Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 30 Mar 2020 21:28:59 +0200 Subject: [PATCH 17/43] fixed test --- test/webfuse/tests/provider/operation/test_lookup.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/webfuse/tests/provider/operation/test_lookup.cc b/test/webfuse/tests/provider/operation/test_lookup.cc index 32d98eb..4cbccd4 100644 --- a/test/webfuse/tests/provider/operation/test_lookup.cc +++ b/test/webfuse/tests/provider/operation/test_lookup.cc @@ -86,7 +86,7 @@ TEST(wfp_impl_lookup, fail_invalid_name_type) 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_integer(23)); json_array_append_new(params, json_integer(1)); wfp_impl_lookup(&context, params, 42); From 0b0c16bf10708f41ba7dda4725bca581bac22aaf Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 30 Mar 2020 21:42:13 +0200 Subject: [PATCH 18/43] added tests for wfp_impl_open --- cmake/unit_tests.cmake | 1 + test/webfuse/mocks/mock_request.hpp | 12 ++ .../tests/provider/operation/test_open.cc | 110 ++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 test/webfuse/tests/provider/operation/test_open.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 3ded8ae..2c271b5 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -50,6 +50,7 @@ add_executable(alltests test/webfuse/tests/provider/operation/test_close.cc test/webfuse/tests/provider/operation/test_getattr.cc test/webfuse/tests/provider/operation/test_lookup.cc + test/webfuse/tests/provider/operation/test_open.cc test/webfuse/tests/integration/test_integration.cc test/webfuse/tests/integration/server.cc test/webfuse/tests/integration/provider.cc diff --git a/test/webfuse/mocks/mock_request.hpp b/test/webfuse/mocks/mock_request.hpp index e3476ba..f286409 100644 --- a/test/webfuse/mocks/mock_request.hpp +++ b/test/webfuse/mocks/mock_request.hpp @@ -44,6 +44,18 @@ MATCHER_P3(StatMatcher, inode, mode, file_type, "") return true; } +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))) + { + *result_listener << "missing handle"; + return false; + } + + return true; +} + MATCHER_P(ReaddirMatcher, contained_elements , "") { if (!json_is_array(arg)) diff --git a/test/webfuse/tests/provider/operation/test_open.cc b/test/webfuse/tests/provider/operation/test_open.cc new file mode 100644 index 0000000..68a53f0 --- /dev/null +++ b/test/webfuse/tests/provider/operation/test_open.cc @@ -0,0 +1,110 @@ +#include "webfuse/provider/impl/operation/open.h" +#include "webfuse/mocks/mock_request.hpp" +#include "webfuse/mocks/mock_provider.hpp" +#include "webfuse/mocks/fake_invokation_context.hpp" + +#include +#include + +using ::webfuse_test::MockProvider; +using ::webfuse_test::MockRequest; +using ::webfuse_test::OpenMatcher; +using ::webfuse_test::create_context; +using ::testing::_; +using ::testing::Invoke; +using ::testing::StrEq; + +namespace +{ + +void free_request(wfp_request * request, ino_t, int) +{ + free(request); +} + +} + +TEST(wfp_impl_open, invoke_provider) +{ + ino_t inode = 42; + int flags = 0; + MockProvider provider; + EXPECT_CALL(provider,open(_, inode, flags)).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); +} + +TEST(wfp_impl_open, fail_invalid_param_count) +{ + MockProvider provider; + EXPECT_CALL(provider,open(_, _, _)).Times(0); + + 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); +} + +TEST(wfp_impl_open, fail_invalid_inode_type) +{ + MockProvider provider; + EXPECT_CALL(provider,open(_, _, _)).Times(0); + + 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); +} + +TEST(wfp_impl_open, fail_invalid_flags_type) +{ + MockProvider provider; + EXPECT_CALL(provider,open(_, _, _)).Times(0); + + 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); +} + +TEST(wfp_impl_open, default_responds_error) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond_error(_,42)).Times(1); + + wfp_impl_open_default(req, 1, 0, nullptr); +} + +TEST(wfp_impl_open, respond) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond(OpenMatcher(23), 42)).Times(1); + + wfp_impl_respond_open(req, 23); +} + From 6ccc738d17d28e6aff3f32a3b3baa426b6139c0b Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 30 Mar 2020 21:50:49 +0200 Subject: [PATCH 19/43] simplified check --- lib/webfuse/provider/impl/provider.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/webfuse/provider/impl/provider.c b/lib/webfuse/provider/impl/provider.c index 14282d2..c9c159f 100644 --- a/lib/webfuse/provider/impl/provider.c +++ b/lib/webfuse/provider/impl/provider.c @@ -94,8 +94,7 @@ void wfp_impl_provider_invoke( json_t * params = json_object_get(request, "params"); json_t * id_holder = json_object_get(request, "id"); - if ((NULL != method_holder) && (json_is_string(method_holder)) && - (NULL != params) && (json_is_array(params))) + if ((json_is_string(method_holder)) && (json_is_array(params))) { char const * method = json_string_value(method_holder); int id = json_is_integer(id_holder) ? json_integer_value(id_holder) : 0; From db536142de7692a307b82673a5026c9179f3d3b3 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 30 Mar 2020 22:21:41 +0200 Subject: [PATCH 20/43] fixed empty result --- lib/webfuse/provider/impl/operation/read.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/webfuse/provider/impl/operation/read.c b/lib/webfuse/provider/impl/operation/read.c index 7be4bf3..5c2b639 100644 --- a/lib/webfuse/provider/impl/operation/read.c +++ b/lib/webfuse/provider/impl/operation/read.c @@ -70,7 +70,7 @@ void wfp_impl_respond_read( { json_t * result = json_object(); json_object_set_new(result, "data", json_string("")); - json_object_set_new(result, "format", json_string("identitiy")); + json_object_set_new(result, "format", json_string("identity")); json_object_set_new(result, "count", json_integer(0)); wfp_impl_respond(request, result); From d482f4dfe5963e66adb21ed41a31772fc361114e Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 30 Mar 2020 22:25:14 +0200 Subject: [PATCH 21/43] added test for wfp_impl_read --- cmake/unit_tests.cmake | 1 + test/webfuse/mocks/mock_request.hpp | 26 +++ .../tests/provider/operation/test_read.cc | 173 ++++++++++++++++++ 3 files changed, 200 insertions(+) create mode 100644 test/webfuse/tests/provider/operation/test_read.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 2c271b5..156ee61 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -51,6 +51,7 @@ add_executable(alltests test/webfuse/tests/provider/operation/test_getattr.cc test/webfuse/tests/provider/operation/test_lookup.cc test/webfuse/tests/provider/operation/test_open.cc + test/webfuse/tests/provider/operation/test_read.cc test/webfuse/tests/integration/test_integration.cc test/webfuse/tests/integration/server.cc test/webfuse/tests/integration/provider.cc diff --git a/test/webfuse/mocks/mock_request.hpp b/test/webfuse/mocks/mock_request.hpp index f286409..0582d6a 100644 --- a/test/webfuse/mocks/mock_request.hpp +++ b/test/webfuse/mocks/mock_request.hpp @@ -56,6 +56,32 @@ MATCHER_P(OpenMatcher, handle, "") return true; } +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)))) + { + *result_listener << "invalid or missing format: " << json_string_value(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))) + { + *result_listener << "invalid or missing count: " << json_integer_value(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)))) + { + *result_listener << "invalid or missing data: " << json_string_value(data_holder); + return false; + } + + return true; +} + MATCHER_P(ReaddirMatcher, contained_elements , "") { if (!json_is_array(arg)) diff --git a/test/webfuse/tests/provider/operation/test_read.cc b/test/webfuse/tests/provider/operation/test_read.cc new file mode 100644 index 0000000..36bf14f --- /dev/null +++ b/test/webfuse/tests/provider/operation/test_read.cc @@ -0,0 +1,173 @@ +#include "webfuse/provider/impl/operation/read.h" +#include "webfuse/mocks/mock_request.hpp" +#include "webfuse/mocks/mock_provider.hpp" +#include "webfuse/mocks/fake_invokation_context.hpp" + +#include +#include + +using ::webfuse_test::MockProvider; +using ::webfuse_test::MockRequest; +using ::webfuse_test::ReadResultMatcher; +using ::webfuse_test::create_context; +using ::testing::_; +using ::testing::Invoke; +using ::testing::StrEq; + +namespace +{ + +void free_request(wfp_request * request, ino_t, uint32_t, size_t ,size_t) +{ + free(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) + .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); +} + +TEST(wfp_impl_read, fail_invalid_param_count) +{ + MockProvider provider; + EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0); + + 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); +} + +TEST(wfp_impl_read, fail_invalid_inode_type) +{ + MockProvider provider; + EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0); + + 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); +} + +TEST(wfp_impl_read, fail_invalid_handle_type) +{ + MockProvider provider; + EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0); + + 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); +} + +TEST(wfp_impl_read, fail_invalid_offset_type) +{ + MockProvider provider; + EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0); + + 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); +} + +TEST(wfp_impl_read, fail_invalid_length_type) +{ + MockProvider provider; + EXPECT_CALL(provider, read(_, _, _, _, _)).Times(0); + + 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); +} + +TEST(wfp_impl_read, default_responds_error) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond_error(_,42)).Times(1); + + wfp_impl_read_default(req, 0, 0, 1, 2, nullptr); +} + +TEST(wfp_impl_read, respond) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond(ReadResultMatcher("d2Y=", "base64", 2), 42)).Times(1); + + char const data[] = "wf"; + wfp_impl_respond_read(req, data, 2); +} + +TEST(wfp_impl_read, respond_empty) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond(ReadResultMatcher("", "identity", 0), 42)).Times(1); + + wfp_impl_respond_read(req, nullptr, 0); +} From b2142ee963f96676a57642eceed6244423d86cb0 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 30 Mar 2020 22:38:12 +0200 Subject: [PATCH 22/43] added tests for wfp_impl_readdir --- cmake/unit_tests.cmake | 1 + .../tests/provider/operation/test_readdir.cc | 100 ++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 test/webfuse/tests/provider/operation/test_readdir.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 156ee61..b1d9b99 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -52,6 +52,7 @@ add_executable(alltests test/webfuse/tests/provider/operation/test_lookup.cc test/webfuse/tests/provider/operation/test_open.cc test/webfuse/tests/provider/operation/test_read.cc + test/webfuse/tests/provider/operation/test_readdir.cc test/webfuse/tests/integration/test_integration.cc test/webfuse/tests/integration/server.cc test/webfuse/tests/integration/provider.cc diff --git a/test/webfuse/tests/provider/operation/test_readdir.cc b/test/webfuse/tests/provider/operation/test_readdir.cc new file mode 100644 index 0000000..33557f5 --- /dev/null +++ b/test/webfuse/tests/provider/operation/test_readdir.cc @@ -0,0 +1,100 @@ +#include "webfuse/provider/impl/operation/readdir.h" +#include "webfuse/mocks/mock_request.hpp" +#include "webfuse/mocks/mock_provider.hpp" +#include "webfuse/mocks/fake_invokation_context.hpp" +#include "webfuse/provider/dirbuffer.h" + +#include +#include + +using ::webfuse_test::MockProvider; +using ::webfuse_test::MockRequest; +using ::webfuse_test::ReaddirMatcher; +using ::webfuse_test::create_context; +using ::testing::_; +using ::testing::Invoke; + +namespace +{ + +void free_request(wfp_request * request, ino_t) +{ + free(request); +} + +} + +TEST(wfp_impl_readdir, invoke_provider) +{ + ino_t inode = 23; + MockProvider provider; + EXPECT_CALL(provider,readdir(_, inode)).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); +} + +TEST(wfp_impl_readdir, fail_invalid_param_count) +{ + MockProvider provider; + EXPECT_CALL(provider,readdir(_, _)).Times(0); + + 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); +} + +TEST(wfp_impl_readdir, fail_invalid_inode_type) +{ + MockProvider provider; + EXPECT_CALL(provider,readdir(_, _)).Times(0); + + 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); +} + +TEST(wfp_impl_readdir, default_responds_error) +{ + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond_error(_,42)).Times(1); + + wfp_impl_readdir_default(req, 0, nullptr); +} + +TEST(wfp_impl_readdir, respond) +{ + char const item0[] = "some.file"; + char const * items[] = { item0, nullptr }; + + MockRequest request; + auto * req = request.create_request(42); + EXPECT_CALL(request, respond(ReaddirMatcher(items), 42)).Times(1); + + wfp_dirbuffer * buffer = wfp_dirbuffer_create(); + wfp_dirbuffer_add(buffer, item0, 42); + wfp_impl_respond_readdir(req, buffer); + wfp_dirbuffer_dispose(buffer); + +} From c62b6edde21b0deeda6a48406f7c68bf1959c6a8 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 30 Mar 2020 22:40:15 +0200 Subject: [PATCH 23/43] chore: simplified check --- lib/webfuse/provider/impl/operation/readdir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/webfuse/provider/impl/operation/readdir.c b/lib/webfuse/provider/impl/operation/readdir.c index 4fc3db7..63d59c1 100644 --- a/lib/webfuse/provider/impl/operation/readdir.c +++ b/lib/webfuse/provider/impl/operation/readdir.c @@ -14,7 +14,7 @@ void wfp_impl_readdir( { json_t * inode_holder = json_array_get(params, 1); - if ((NULL != inode_holder) && (json_is_integer(inode_holder))) + if (json_is_integer(inode_holder)) { ino_t inode = (ino_t) json_integer_value(inode_holder); struct wfp_request * request = wfp_impl_request_create(context->request, id); From f8a402c3a1ed5069d6e5a032a9b4eecceadff8a7 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Wed, 1 Apr 2020 21:42:50 +0200 Subject: [PATCH 24/43] use TLS in integration test --- cmake/unit_tests.cmake | 8 ++++++++ include/webfuse/provider/client_config.h | 13 +++++++++++++ lib/webfuse/provider/api.c | 7 +++++++ lib/webfuse/provider/impl/client.c | 5 ++++- lib/webfuse/provider/impl/client_config.c | 10 ++++++++++ lib/webfuse/provider/impl/client_config.h | 5 +++++ test/webfuse/tests/integration/provider.cc | 3 +++ test/webfuse/tests/integration/server.cc | 2 ++ test/webfuse/tests/integration/test_integration.cc | 2 +- 9 files changed, 53 insertions(+), 2 deletions(-) diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index b1d9b99..31d3c12 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -81,6 +81,14 @@ target_link_libraries(alltests PUBLIC target_include_directories(alltests PUBLIC test lib ${FUSE3_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}) target_compile_options(alltests PUBLIC ${FUSE3_CFLAGS_OTHER} ${GMOCK_CFLAGS} ${GTEST_CFLAGS}) +add_custom_command(OUTPUT server-key.pem + COMMAND openssl req -x509 -newkey rsa:4096 -keyout server-key.pem -out server-cert.pem -days 365 -nodes -batch -subj '/CN=localhost' + COMMAND openssl req -x509 -newkey rsa:4096 -keyout client-key.pem -out client-cert.pem -days 365 -nodes -batch -subj '/CN=localhost' +) + +add_custom_target(gen-tls DEPENDS server-key.pem) +add_dependencies(alltests gen-tls) + enable_testing() gtest_discover_tests(alltests TEST_PREFIX alltests:) diff --git a/include/webfuse/provider/client_config.h b/include/webfuse/provider/client_config.h index 0c79dd7..fe138f6 100644 --- a/include/webfuse/provider/client_config.h +++ b/include/webfuse/provider/client_config.h @@ -108,6 +108,19 @@ extern WFP_API void wfp_client_config_set_certpath( struct wfp_client_config * config, char const * cert_path); +//------------------------------------------------------------------------------ +/// \brief Sets the path of ca file to verify servers. +/// +/// \note To enable TLS both, private key and certificate, must be specified. +/// Otherwise, TLS is not used. +/// +/// \param config pointer to client configuration +/// \param ca_filepath path of the ca file (pem file) +//------------------------------------------------------------------------------ +extern WFP_API void wfp_client_config_set_ca_filepath( + struct wfp_client_config * config, + char const * ca_filepath); + //------------------------------------------------------------------------------ /// \brief Sets the onconnected handler. /// diff --git a/lib/webfuse/provider/api.c b/lib/webfuse/provider/api.c index 0704095..dc42fba 100644 --- a/lib/webfuse/provider/api.c +++ b/lib/webfuse/provider/api.c @@ -95,6 +95,13 @@ void wfp_client_config_set_certpath( wfp_impl_client_config_set_certpath(config, cert_path); } +void wfp_client_config_set_ca_filepath( + struct wfp_client_config * config, + char const * ca_filepath) +{ + wfp_impl_client_config_set_ca_filepath(config, ca_filepath); +} + void wfp_client_config_set_onconnected( struct wfp_client_config * config, wfp_connected_fn * handler) diff --git a/lib/webfuse/provider/impl/client.c b/lib/webfuse/provider/impl/client.c index c3b432c..f10450f 100644 --- a/lib/webfuse/provider/impl/client.c +++ b/lib/webfuse/provider/impl/client.c @@ -43,7 +43,10 @@ struct wfp_client * wfp_impl_client_create( if ((NULL != config->cert_path) && (NULL != config->key_path)) { - + client->info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + client->info.client_ssl_cert_filepath = config->cert_path; + client->info.client_ssl_private_key_filepath = config->key_path; + client->info.client_ssl_ca_filepath = config->ca_filepath; } client->context = lws_create_context(&client->info); diff --git a/lib/webfuse/provider/impl/client_config.c b/lib/webfuse/provider/impl/client_config.c index 3bbb3ea..9e6489b 100644 --- a/lib/webfuse/provider/impl/client_config.c +++ b/lib/webfuse/provider/impl/client_config.c @@ -10,6 +10,7 @@ struct wfp_client_config * wfp_impl_client_config_create(void) config->user_data = NULL; config->key_path = NULL; config->cert_path = NULL; + config->ca_filepath = NULL; return config; } @@ -19,6 +20,7 @@ void wfp_impl_client_config_dispose( { free(config->key_path); free(config->cert_path); + free(config->ca_filepath); free(config); } @@ -45,6 +47,14 @@ void wfp_impl_client_config_set_certpath( config->cert_path = strdup(cert_path); } +void wfp_impl_client_config_set_ca_filepath( + struct wfp_client_config * config, + char const * ca_filepath) +{ + free(config->ca_filepath); + config->ca_filepath = strdup(ca_filepath); +} + void wfp_impl_client_config_set_onconnected( struct wfp_client_config * config, wfp_connected_fn * handler) diff --git a/lib/webfuse/provider/impl/client_config.h b/lib/webfuse/provider/impl/client_config.h index f8d5b9b..a15ff87 100644 --- a/lib/webfuse/provider/impl/client_config.h +++ b/lib/webfuse/provider/impl/client_config.h @@ -15,6 +15,7 @@ struct wfp_client_config void * user_data; char * key_path; char * cert_path; + char * ca_filepath; }; extern struct wfp_client_config * wfp_impl_client_config_create(void); @@ -34,6 +35,10 @@ extern void wfp_impl_client_config_set_certpath( struct wfp_client_config * config, char const * cert_path); +extern void wfp_impl_client_config_set_ca_filepath( + struct wfp_client_config * config, + char const * ca_filepath); + extern void wfp_impl_client_config_set_onconnected( struct wfp_client_config * config, wfp_connected_fn * handler); diff --git a/test/webfuse/tests/integration/provider.cc b/test/webfuse/tests/integration/provider.cc index b1fa44d..e635c9b 100644 --- a/test/webfuse/tests/integration/provider.cc +++ b/test/webfuse/tests/integration/provider.cc @@ -19,6 +19,9 @@ public: : is_shutdown_requested(false) { config = wfp_client_config_create(); + wfp_client_config_set_certpath(config, "client-cert.pem"); + wfp_client_config_set_keypath(config, "client-key.pem"); + wfp_client_config_set_ca_filepath(config, "server-cert.pem"); fs = wfp_static_filesystem_create(config); wfp_static_filesystem_add_text(fs, "hello.txt", 0444, "Hello, World"); diff --git a/test/webfuse/tests/integration/server.cc b/test/webfuse/tests/integration/server.cc index 931f932..8f15161 100644 --- a/test/webfuse/tests/integration/server.cc +++ b/test/webfuse/tests/integration/server.cc @@ -63,6 +63,8 @@ public: wf_server_config_set_mountpoint_factory(config, &webfuse_test_server_create_mountpoint, reinterpret_cast(base_dir)); + wf_server_config_set_keypath(config, "server-key.pem"); + wf_server_config_set_certpath(config, "server-cert.pem"); server = wf_server_create(config); diff --git a/test/webfuse/tests/integration/test_integration.cc b/test/webfuse/tests/integration/test_integration.cc index 4cc2844..57c1a91 100644 --- a/test/webfuse/tests/integration/test_integration.cc +++ b/test/webfuse/tests/integration/test_integration.cc @@ -38,7 +38,7 @@ namespace void SetUp() { server = new Server(); - provider = new Provider("ws://localhost:8080/"); + provider = new Provider("wss://localhost:8080/"); } void TearDown() From 06c01995feb5553486df37caf3fce9121d377910 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Thu, 2 Apr 2020 19:34:52 +0200 Subject: [PATCH 25/43] removed unnecessary NULL check --- lib/webfuse/adapter/impl/session_manager.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/webfuse/adapter/impl/session_manager.c b/lib/webfuse/adapter/impl/session_manager.c index cc41fa0..a872d54 100644 --- a/lib/webfuse/adapter/impl/session_manager.c +++ b/lib/webfuse/adapter/impl/session_manager.c @@ -33,10 +33,7 @@ struct wf_impl_session * wf_impl_session_manager_add( { struct wf_impl_session * session = wf_impl_session_create( wsi, authenticators, timer_manager, server, mountpoint_factory); - if (NULL != session) - { - wf_slist_append(&manager->sessions, &session->item); - } + wf_slist_append(&manager->sessions, &session->item); return session; } From 48e3575d6d95b2ea1fd52073cd4800be80ee3ce7 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Thu, 2 Apr 2020 22:00:01 +0200 Subject: [PATCH 26/43] added integrative test of low level api --- cmake/unit_tests.cmake | 1 + lib/webfuse/adapter/impl/server_protocol.c | 7 +- .../tests/integration/test_lowlevel.cc | 112 ++++++++++++++++++ 3 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 test/webfuse/tests/integration/test_lowlevel.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 31d3c12..619afbe 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -53,6 +53,7 @@ add_executable(alltests test/webfuse/tests/provider/operation/test_open.cc test/webfuse/tests/provider/operation/test_read.cc test/webfuse/tests/provider/operation/test_readdir.cc + test/webfuse/tests/integration/test_lowlevel.cc test/webfuse/tests/integration/test_integration.cc test/webfuse/tests/integration/server.cc test/webfuse/tests/integration/provider.cc diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index 7caf0bc..d97c9a8 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -23,13 +23,10 @@ static int wf_impl_server_protocol_callback( size_t len) { struct lws_protocols const * ws_protocol = lws_get_protocol(wsi); - if (NULL == ws_protocol) - { - return 0; - } + if (NULL == ws_protocol) { return 0; } + if (ws_protocol->callback != &wf_impl_server_protocol_callback) { return 0; } struct wf_server_protocol * protocol = ws_protocol->user; - wf_timer_manager_check(protocol->timer_manager); struct wf_impl_session * session = wf_impl_session_manager_get(&protocol->session_manager, wsi); diff --git a/test/webfuse/tests/integration/test_lowlevel.cc b/test/webfuse/tests/integration/test_lowlevel.cc new file mode 100644 index 0000000..050b23a --- /dev/null +++ b/test/webfuse/tests/integration/test_lowlevel.cc @@ -0,0 +1,112 @@ +#include "webfuse_adapter.h" +#include "webfuse_provider.h" +#include + +#include "webfuse/utils/tempdir.hpp" + +#include + +using ::webfuse_test::TempDir; + +extern "C" +{ + +wf_mountpoint * +wf_test_integration_lowlevel_create_mountpoint( + char const *, void * user_data) +{ + auto * tempDir = reinterpret_cast(user_data); + return wf_mountpoint_create(tempDir->path()); +} + +void +wf_test_integration_lowlevel_on_connected( + void * user_data) +{ + int * state = reinterpret_cast(user_data); + *state = 1; +} + +void +wf_test_integration_lowlevel_on_disconnected( + void * user_data) +{ + int * state = reinterpret_cast(user_data); + *state = -1; +} + +bool +wf_test_integration_lowlevel_authenticate( + struct wf_credentials * credentials, + void * ) +{ + char const * username = wf_credentials_get(credentials, "username"); + char const * password = wf_credentials_get(credentials, "password"); + + return ((0 == strcmp(username, "bob")) && (0 == strcmp(password, "secret"))); +} + +void +wf_test_integration_lowlevel_get_credentials( + struct wfp_credentials * credentials, + void * ) +{ + wfp_credentials_set_type(credentials, "username"); + wfp_credentials_add(credentials, "username", "bob"); + wfp_credentials_add(credentials, "password", "secret"); +} + +} + +TEST(integration, lowlevel) +{ + TempDir dir("wf_test"); + + wf_server_protocol * server_protocol = wf_server_protocol_create( + &wf_test_integration_lowlevel_create_mountpoint, + reinterpret_cast(&dir)); + ASSERT_NE(nullptr, server_protocol); + wf_server_protocol_add_authenticator(server_protocol, "username", + &wf_test_integration_lowlevel_authenticate, nullptr); + + int state = 0; + wfp_client_config * client_config = wfp_client_config_create(); + ASSERT_NE(nullptr, client_config); + wfp_client_config_set_userdata(client_config, reinterpret_cast(&state)); + wfp_client_config_set_onconnected(client_config, &wf_test_integration_lowlevel_on_connected); + wfp_client_config_set_ondisconnected(client_config, &wf_test_integration_lowlevel_on_disconnected); + wfp_client_config_enable_authentication(client_config, &wf_test_integration_lowlevel_get_credentials); + + wfp_client_protocol * client_protocol = wfp_client_protocol_create(client_config); + ASSERT_NE(nullptr, client_protocol); + + lws_protocols protocols[3]; + memset(protocols, 0, 3 * sizeof(lws_protocols)); + wf_server_protocol_init_lws(server_protocol, &protocols[0]); + wfp_client_protocol_init_lws(client_protocol, &protocols[1]); + + lws_context_creation_info info; + memset(&info, 0, sizeof(info)); + info.port = 8080; + info.protocols = protocols; + info.vhost_name = "localhost"; + info.ws_ping_pong_interval = 10; + info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; + + struct lws_context * context = lws_create_context(&info); + ASSERT_NE(nullptr, context); + + wfp_client_protocol_connect(client_protocol, context, "ws://localhost:8080/"); + while (0 == state) + { + lws_service(context, 0); + } + + EXPECT_EQ(1, state); + + lws_context_destroy(context); + + wfp_client_protocol_dispose(client_protocol); + wfp_client_config_dispose(client_config); + wf_server_protocol_dispose(server_protocol); +} \ No newline at end of file From d56bbcbd3965af19554338085d1772ee13b3c5a6 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Fri, 3 Apr 2020 22:46:47 +0200 Subject: [PATCH 27/43] added test for open (adapter) --- cmake/unit_tests.cmake | 5 ++++ lib/webfuse/adapter/impl/operation/open.c | 2 +- test/webfuse/mocks/mock_fuse.cc | 28 +++++++++++++++++++ test/webfuse/mocks/mock_fuse.hpp | 19 +++++++++++++ .../tests/adapter/operation/test_open.cc | 28 +++++++++++++++++++ 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 test/webfuse/mocks/mock_fuse.cc create mode 100644 test/webfuse/mocks/mock_fuse.hpp create mode 100644 test/webfuse/tests/adapter/operation/test_open.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 619afbe..06d510d 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -30,6 +30,7 @@ add_executable(alltests test/webfuse/mocks/mock_request.cc test/webfuse/mocks/mock_provider_client.cc test/webfuse/mocks/mock_provider.cc + test/webfuse/mocks/mock_fuse.cc test/webfuse//tests/core/test_util.cc test/webfuse/tests/core/test_container_of.cc test/webfuse/tests/core/test_string.cc @@ -45,6 +46,7 @@ add_executable(alltests test/webfuse/tests/adapter/test_authenticators.cc 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/provider/test_url.cc test/webfuse/tests/provider/test_client_protocol.cc test/webfuse/tests/provider/operation/test_close.cc @@ -67,6 +69,9 @@ target_link_libraries(alltests PUBLIC -Wl,--wrap=wf_timer_dispose -Wl,--wrap=wf_timer_start -Wl,--wrap=wf_timer_cancel + -Wl,--wrap=fuse_req_userdata + -Wl,--wrap=fuse_reply_open + -Wl,--wrap=fuse_reply_err webfuse-adapter-static webfuse-provider-static diff --git a/lib/webfuse/adapter/impl/operation/open.c b/lib/webfuse/adapter/impl/operation/open.c index 8e21100..07d8ea9 100644 --- a/lib/webfuse/adapter/impl/operation/open.c +++ b/lib/webfuse/adapter/impl/operation/open.c @@ -22,7 +22,7 @@ static void wf_impl_operation_open_finished( if (NULL != result) { json_t * handle_holder = json_object_get(result, "handle"); - if ((NULL != handle_holder) && (json_is_integer(handle_holder))) + if (json_is_integer(handle_holder)) { file_info.fh = json_integer_value(handle_holder); } diff --git a/test/webfuse/mocks/mock_fuse.cc b/test/webfuse/mocks/mock_fuse.cc new file mode 100644 index 0000000..fa2f981 --- /dev/null +++ b/test/webfuse/mocks/mock_fuse.cc @@ -0,0 +1,28 @@ +#include "webfuse/mocks/mock_fuse.hpp" +#include "webfuse/utils/wrap.hpp" + +extern "C" +{ +static webfuse_test::FuseMock * webfuse_test_FuseMock = nullptr; + +WF_WRAP_FUNC1(webfuse_test_FuseMock, void*, fuse_req_userdata, fuse_req_t); +WF_WRAP_FUNC2(webfuse_test_FuseMock, int, fuse_reply_open, fuse_req_t, const struct fuse_file_info *); +WF_WRAP_FUNC2(webfuse_test_FuseMock, int, fuse_reply_err, fuse_req_t, int); + +} + +namespace webfuse_test +{ + +FuseMock::FuseMock() +{ + webfuse_test_FuseMock = this; +} + +FuseMock::~FuseMock() +{ + webfuse_test_FuseMock = nullptr; +} + + +} \ No newline at end of file diff --git a/test/webfuse/mocks/mock_fuse.hpp b/test/webfuse/mocks/mock_fuse.hpp new file mode 100644 index 0000000..ed6e6ff --- /dev/null +++ b/test/webfuse/mocks/mock_fuse.hpp @@ -0,0 +1,19 @@ +#include "webfuse/adapter/impl/fuse_wrapper.h" +#include + +namespace webfuse_test +{ + +class FuseMock +{ +public: + FuseMock(); + virtual ~FuseMock(); + + MOCK_METHOD1(fuse_req_userdata, void *(fuse_req_t req)); + MOCK_METHOD2(fuse_reply_open, int (fuse_req_t req, const struct fuse_file_info *fi)); + MOCK_METHOD2(fuse_reply_err, int (fuse_req_t req, int err)); +}; + + +} \ No newline at end of file diff --git a/test/webfuse/tests/adapter/operation/test_open.cc b/test/webfuse/tests/adapter/operation/test_open.cc new file mode 100644 index 0000000..d1b5960 --- /dev/null +++ b/test/webfuse/tests/adapter/operation/test_open.cc @@ -0,0 +1,28 @@ +#include "webfuse/adapter/impl/operations.h" +#include "webfuse/mocks/mock_fuse.hpp" +#include "webfuse/adapter/impl/session.h" + +#include + +using webfuse_test::FuseMock; +using testing::_; +using testing::Return; + +TEST(wf_impl_operation_open, fail_rpc_null) +{ + wf_impl_session session; + memset(&session, 0, sizeof(session)); + wf_impl_operations_context context = + {&session, 1.0f, nullptr }; + + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1) + .WillOnce(Return(reinterpret_cast(&context))); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1) + .WillOnce(Return(0)); + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + fuse_file_info * file_info = nullptr; + wf_impl_operation_open(request, inode, file_info); +} \ No newline at end of file From 77a870b9b78fed97627c92a56190202a225c3580 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 08:32:26 +0200 Subject: [PATCH 28/43] added unit tests for open (adapter) --- cmake/unit_tests.cmake | 4 + cmake/webfuse_core.cmake | 1 + lib/webfuse/adapter/impl/filesystem.c | 1 + lib/webfuse/adapter/impl/operation/open.c | 10 +- lib/webfuse/adapter/impl/operation/open.h | 26 ++++++ lib/webfuse/adapter/impl/operations.h | 5 - lib/webfuse/core/jsonrpc/proxy.c | 8 +- lib/webfuse/core/jsonrpc/proxy_intern.h | 8 ++ lib/webfuse/core/jsonrpc/proxy_invoke.c | 15 +++ test/webfuse/mocks/mock_fuse.hpp | 6 +- test/webfuse/mocks/mock_jsonrpc_proxy.cc | 30 ++++++ test/webfuse/mocks/mock_jsonrpc_proxy.hpp | 27 ++++++ test/webfuse/mocks/mock_operations_context.cc | 27 ++++++ .../webfuse/mocks/mock_operations_context.hpp | 22 +++++ .../tests/adapter/operation/test_open.cc | 93 +++++++++++++++++-- test/webfuse/utils/wrap.hpp | 28 ++++++ 16 files changed, 284 insertions(+), 27 deletions(-) create mode 100644 lib/webfuse/adapter/impl/operation/open.h create mode 100644 lib/webfuse/core/jsonrpc/proxy_invoke.c create mode 100644 test/webfuse/mocks/mock_jsonrpc_proxy.cc create mode 100644 test/webfuse/mocks/mock_jsonrpc_proxy.hpp create mode 100644 test/webfuse/mocks/mock_operations_context.cc create mode 100644 test/webfuse/mocks/mock_operations_context.hpp diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 06d510d..4934a05 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -31,6 +31,8 @@ add_executable(alltests test/webfuse/mocks/mock_provider_client.cc test/webfuse/mocks/mock_provider.cc test/webfuse/mocks/mock_fuse.cc + test/webfuse/mocks/mock_operations_context.cc + test/webfuse/mocks/mock_jsonrpc_proxy.cc test/webfuse//tests/core/test_util.cc test/webfuse/tests/core/test_container_of.cc test/webfuse/tests/core/test_string.cc @@ -69,6 +71,8 @@ target_link_libraries(alltests PUBLIC -Wl,--wrap=wf_timer_dispose -Wl,--wrap=wf_timer_start -Wl,--wrap=wf_timer_cancel + -Wl,--wrap=wf_impl_operations_context_get_proxy + -Wl,--wrap=wf_jsonrpc_proxy_vinvoke -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 fb25b75..3dfa958 100644 --- a/cmake/webfuse_core.cmake +++ b/cmake/webfuse_core.cmake @@ -13,6 +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/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 b7966a1..67fef92 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -1,5 +1,6 @@ #include "webfuse/adapter/impl/filesystem.h" #include "webfuse/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operation/open.h" #include "webfuse/adapter/impl/session.h" #include "webfuse/adapter/impl/mountpoint.h" diff --git a/lib/webfuse/adapter/impl/operation/open.c b/lib/webfuse/adapter/impl/operation/open.c index 07d8ea9..630e9c8 100644 --- a/lib/webfuse/adapter/impl/operation/open.c +++ b/lib/webfuse/adapter/impl/operation/open.c @@ -1,15 +1,15 @@ +#include "webfuse/adapter/impl/operation/open.h" #include "webfuse/adapter/impl/operations.h" -#include -#include -#include - #include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/util.h" #include "webfuse/core/status.h" #include "webfuse/core/json_util.h" -static void wf_impl_operation_open_finished( +#include +#include + +void wf_impl_operation_open_finished( void * user_data, json_t const * result, json_t const * error) diff --git a/lib/webfuse/adapter/impl/operation/open.h b/lib/webfuse/adapter/impl/operation/open.h new file mode 100644 index 0000000..eb40490 --- /dev/null +++ b/lib/webfuse/adapter/impl/operation/open.h @@ -0,0 +1,26 @@ +#ifndef WF_ADAPTER_IMPL_OPERATION_OPEN_H +#define WF_ADAPTER_IMPL_OPERATION_OPEN_H + +#include "webfuse/adapter/impl/fuse_wrapper.h" +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wf_impl_operation_open( + fuse_req_t request, + fuse_ino_t inode, + struct fuse_file_info * file_info); + +extern void wf_impl_operation_open_finished( + void * user_data, + json_t const * result, + json_t const * error); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/webfuse/adapter/impl/operations.h b/lib/webfuse/adapter/impl/operations.h index 4d23db2..162ee15 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_open( - fuse_req_t request, - fuse_ino_t inode, - struct fuse_file_info * file_info); - extern void wf_impl_operation_close( fuse_req_t request, fuse_ino_t inode, diff --git a/lib/webfuse/core/jsonrpc/proxy.c b/lib/webfuse/core/jsonrpc/proxy.c index 67fd6d8..90a9d56 100644 --- a/lib/webfuse/core/jsonrpc/proxy.c +++ b/lib/webfuse/core/jsonrpc/proxy.c @@ -133,14 +133,13 @@ void wf_jsonrpc_proxy_cleanup( wf_timer_dispose(proxy->request.timer); } -void wf_jsonrpc_proxy_invoke( +void wf_jsonrpc_proxy_vinvoke( struct wf_jsonrpc_proxy * proxy, wf_jsonrpc_proxy_finished_fn * finished, void * user_data, char const * method_name, char const * param_info, - ... -) + va_list args) { if (!proxy->request.is_pending) { @@ -150,10 +149,7 @@ void wf_jsonrpc_proxy_invoke( proxy->request.id = 42; wf_timer_start(proxy->request.timer, proxy->timeout); - va_list args; - va_start(args, param_info); json_t * request = wf_jsonrpc_request_create(method_name, proxy->request.id, param_info, args); - va_end(args); bool const is_send = ((NULL != request) && (proxy->send(request, proxy->user_data))); if (!is_send) diff --git a/lib/webfuse/core/jsonrpc/proxy_intern.h b/lib/webfuse/core/jsonrpc/proxy_intern.h index 3186e14..920bd56 100644 --- a/lib/webfuse/core/jsonrpc/proxy_intern.h +++ b/lib/webfuse/core/jsonrpc/proxy_intern.h @@ -41,6 +41,14 @@ extern void wf_jsonrpc_proxy_cleanup( struct wf_jsonrpc_proxy * proxy); +extern void wf_jsonrpc_proxy_vinvoke( + struct wf_jsonrpc_proxy * proxy, + wf_jsonrpc_proxy_finished_fn * finished, + void * user_data, + 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_invoke.c new file mode 100644 index 0000000..ada6b9e --- /dev/null +++ b/lib/webfuse/core/jsonrpc/proxy_invoke.c @@ -0,0 +1,15 @@ +#include "webfuse/core/jsonrpc/proxy_intern.h" + +void wf_jsonrpc_proxy_invoke( + struct wf_jsonrpc_proxy * proxy, + wf_jsonrpc_proxy_finished_fn * finished, + void * user_data, + char const * method_name, + char const * param_info, + ...) +{ + va_list args; + va_start(args, param_info); + wf_jsonrpc_proxy_vinvoke(proxy, finished, user_data, method_name, param_info, args); + va_end(args); +} diff --git a/test/webfuse/mocks/mock_fuse.hpp b/test/webfuse/mocks/mock_fuse.hpp index ed6e6ff..07bcb60 100644 --- a/test/webfuse/mocks/mock_fuse.hpp +++ b/test/webfuse/mocks/mock_fuse.hpp @@ -1,3 +1,6 @@ +#ifndef MOCK_FUSE_HPP +#define MOCK_FUSE_HPP + #include "webfuse/adapter/impl/fuse_wrapper.h" #include @@ -15,5 +18,6 @@ public: MOCK_METHOD2(fuse_reply_err, int (fuse_req_t req, int err)); }; +} -} \ No newline at end of file +#endif diff --git a/test/webfuse/mocks/mock_jsonrpc_proxy.cc b/test/webfuse/mocks/mock_jsonrpc_proxy.cc new file mode 100644 index 0000000..569dfa8 --- /dev/null +++ b/test/webfuse/mocks/mock_jsonrpc_proxy.cc @@ -0,0 +1,30 @@ +#include "webfuse/mocks/mock_jsonrpc_proxy.hpp" +#include "webfuse/utils/wrap.hpp" + +extern "C" +{ +static webfuse_test::MockJsonRpcProxy * webfuse_test_MockJsonRpcProxy = nullptr; + +WF_WRAP_FUNC6(webfuse_test_MockJsonRpcProxy, void, wf_jsonrpc_proxy_vinvoke, + struct wf_jsonrpc_proxy *, + wf_jsonrpc_proxy_finished_fn *, + void *, + char const *, + char const *, + va_list); +} + +namespace webfuse_test +{ + +MockJsonRpcProxy::MockJsonRpcProxy() +{ + webfuse_test_MockJsonRpcProxy = this; +} + +MockJsonRpcProxy::~MockJsonRpcProxy() +{ + webfuse_test_MockJsonRpcProxy = nullptr; +} + +} \ No newline at end of file diff --git a/test/webfuse/mocks/mock_jsonrpc_proxy.hpp b/test/webfuse/mocks/mock_jsonrpc_proxy.hpp new file mode 100644 index 0000000..97a1b1b --- /dev/null +++ b/test/webfuse/mocks/mock_jsonrpc_proxy.hpp @@ -0,0 +1,27 @@ +#ifndef MOCK_JSONRPC_PROXY_HPP +#define MOCK_JSONRPC_PROXY_HPP + +#include "webfuse/core/jsonrpc/proxy_intern.h" +#include + +namespace webfuse_test +{ + +class MockJsonRpcProxy +{ +public: + MockJsonRpcProxy(); + virtual ~MockJsonRpcProxy(); + MOCK_METHOD6(wf_jsonrpc_proxy_vinvoke, void ( + struct wf_jsonrpc_proxy * proxy, + wf_jsonrpc_proxy_finished_fn * finished, + void * user_data, + char const * method_name, + char const * param_info, + va_list args)); + +}; + +} + +#endif diff --git a/test/webfuse/mocks/mock_operations_context.cc b/test/webfuse/mocks/mock_operations_context.cc new file mode 100644 index 0000000..89498f7 --- /dev/null +++ b/test/webfuse/mocks/mock_operations_context.cc @@ -0,0 +1,27 @@ +#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/utils/wrap.hpp" + +extern "C" +{ +static webfuse_test::MockOperationsContext * webfuse_test_MockOperationsContext = nullptr; + +WF_WRAP_FUNC1(webfuse_test_MockOperationsContext, + struct wf_jsonrpc_proxy *, wf_impl_operations_context_get_proxy, + struct wf_impl_operations_context *); + +} + +namespace webfuse_test +{ + +MockOperationsContext::MockOperationsContext() +{ + webfuse_test_MockOperationsContext = this; +} + +MockOperationsContext::~MockOperationsContext() +{ + webfuse_test_MockOperationsContext = nullptr; +} + +} \ No newline at end of file diff --git a/test/webfuse/mocks/mock_operations_context.hpp b/test/webfuse/mocks/mock_operations_context.hpp new file mode 100644 index 0000000..a12aa7b --- /dev/null +++ b/test/webfuse/mocks/mock_operations_context.hpp @@ -0,0 +1,22 @@ +#ifndef MOCK_OPERATIONS_CONTEXT_HPP +#define MOCK_OPERATIONS_CONTEXT_HPP + +#include "webfuse/adapter/impl/operations.h" +#include + +namespace webfuse_test +{ + +class MockOperationsContext +{ +public: + MockOperationsContext(); + virtual ~MockOperationsContext(); + MOCK_METHOD1(wf_impl_operations_context_get_proxy, wf_jsonrpc_proxy * ( + struct wf_impl_operations_context * context)); + +}; + +} + +#endif diff --git a/test/webfuse/tests/adapter/operation/test_open.cc b/test/webfuse/tests/adapter/operation/test_open.cc index d1b5960..e7e5ca4 100644 --- a/test/webfuse/tests/adapter/operation/test_open.cc +++ b/test/webfuse/tests/adapter/operation/test_open.cc @@ -1,28 +1,101 @@ +#include "webfuse/adapter/impl/operation/open.h" #include "webfuse/adapter/impl/operations.h" + +#include "webfuse/core/status.h" + #include "webfuse/mocks/mock_fuse.hpp" -#include "webfuse/adapter/impl/session.h" +#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_open, invoke_proxy) +{ + MockJsonRpcProxy proxy; + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("open"),StrEq("sii"),_)).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)); + + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + fuse_file_info file_info; + file_info.flags = 0; + wf_impl_operation_open(request, inode, &file_info); +} TEST(wf_impl_operation_open, fail_rpc_null) { - wf_impl_session session; - memset(&session, 0, sizeof(session)); - wf_impl_operations_context context = - {&session, 1.0f, nullptr }; + 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(reinterpret_cast(&context))); - EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1) - .WillOnce(Return(0)); + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(nullptr)); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); fuse_req_t request = nullptr; fuse_ino_t inode = 1; fuse_file_info * file_info = nullptr; wf_impl_operation_open(request, inode, file_info); -} \ No newline at end of file +} + +TEST(wf_impl_operation_open, finished) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "handle", json_integer(42)); + wf_impl_operation_open_finished(nullptr, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_open, finished_fail_error) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * error = json_object(); + json_object_set_new(error, "code", json_integer(WF_BAD)); + wf_impl_operation_open_finished(nullptr, nullptr, error); + json_decref(error); +} + +TEST(wf_impl_operation_open, finished_fail_no_handle) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + wf_impl_operation_open_finished(nullptr, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_open, finished_fail_invalid_handle_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "handle", json_string("42")); + wf_impl_operation_open_finished(nullptr, result, nullptr); + json_decref(result); +} diff --git a/test/webfuse/utils/wrap.hpp b/test/webfuse/utils/wrap.hpp index 9d062d8..4402598 100644 --- a/test/webfuse/utils/wrap.hpp +++ b/test/webfuse/utils/wrap.hpp @@ -71,4 +71,32 @@ } \ } +#define WF_WRAP_FUNC5( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE ) \ + extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE); \ + RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3, ARG4_TYPE arg4, ARG5_TYPE arg5) \ + { \ + if (nullptr == GLOBAL_VAR ) \ + { \ + return __real_ ## FUNC_NAME (arg1, arg2, arg3, arg4, arg5); \ + } \ + else \ + { \ + return GLOBAL_VAR -> FUNC_NAME(arg1, arg2, arg3, arg4, arg5); \ + } \ + } + +#define WF_WRAP_FUNC6( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE, ARG6_TYPE ) \ + extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE, ARG6_TYPE); \ + RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3, ARG4_TYPE arg4, ARG5_TYPE arg5, ARG6_TYPE arg6) \ + { \ + if (nullptr == GLOBAL_VAR ) \ + { \ + return __real_ ## FUNC_NAME (arg1, arg2, arg3, arg4, arg5, arg6); \ + } \ + else \ + { \ + return GLOBAL_VAR -> FUNC_NAME(arg1, arg2, arg3, arg4, arg5, arg6); \ + } \ + } + #endif From 289264e2691f39ddb20afc75cd386551eb715741 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 08:55:59 +0200 Subject: [PATCH 29/43] 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); +} From bfd4d43dee6358f11cba44cf0554371524c34fd7 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 12:49:02 +0200 Subject: [PATCH 30/43] fix: compile error on arm targets --- test/webfuse/mocks/mock_jsonrpc_proxy.cc | 10 +++---- test/webfuse/mocks/mock_jsonrpc_proxy.hpp | 10 +++---- .../tests/adapter/operation/test_close.cc | 4 +-- .../tests/adapter/operation/test_open.cc | 2 +- test/webfuse/utils/wrap.hpp | 30 +++++++++++++++++++ 5 files changed, 41 insertions(+), 15 deletions(-) diff --git a/test/webfuse/mocks/mock_jsonrpc_proxy.cc b/test/webfuse/mocks/mock_jsonrpc_proxy.cc index 3cb0a8e..3fb243e 100644 --- a/test/webfuse/mocks/mock_jsonrpc_proxy.cc +++ b/test/webfuse/mocks/mock_jsonrpc_proxy.cc @@ -5,19 +5,17 @@ extern "C" { static webfuse_test::MockJsonRpcProxy * webfuse_test_MockJsonRpcProxy = nullptr; -WF_WRAP_FUNC6(webfuse_test_MockJsonRpcProxy, void, wf_jsonrpc_proxy_vinvoke, +WF_WRAP_VFUNC5(webfuse_test_MockJsonRpcProxy, void, wf_jsonrpc_proxy_vinvoke, struct wf_jsonrpc_proxy *, wf_jsonrpc_proxy_finished_fn *, void *, char const *, - char const *, - va_list); + char const *); -WF_WRAP_FUNC4(webfuse_test_MockJsonRpcProxy, void, wf_jsonrpc_proxy_vnotify, +WF_WRAP_VFUNC3(webfuse_test_MockJsonRpcProxy, void, wf_jsonrpc_proxy_vnotify, struct wf_jsonrpc_proxy *, char const *, - char const *, - va_list); + char const *); } namespace webfuse_test diff --git a/test/webfuse/mocks/mock_jsonrpc_proxy.hpp b/test/webfuse/mocks/mock_jsonrpc_proxy.hpp index fc39e1f..74d61af 100644 --- a/test/webfuse/mocks/mock_jsonrpc_proxy.hpp +++ b/test/webfuse/mocks/mock_jsonrpc_proxy.hpp @@ -12,18 +12,16 @@ class MockJsonRpcProxy public: MockJsonRpcProxy(); virtual ~MockJsonRpcProxy(); - MOCK_METHOD6(wf_jsonrpc_proxy_vinvoke, void ( + MOCK_METHOD5(wf_jsonrpc_proxy_vinvoke, void ( struct wf_jsonrpc_proxy * proxy, wf_jsonrpc_proxy_finished_fn * finished, void * user_data, char const * method_name, - char const * param_info, - va_list args)); - MOCK_METHOD4(wf_jsonrpc_proxy_vnotify, void ( + char const * param_info)); + MOCK_METHOD3(wf_jsonrpc_proxy_vnotify, void ( struct wf_jsonrpc_proxy * proxy, char const * method_name, - char const * param_info, - va_list args)); + char const * param_info)); }; diff --git a/test/webfuse/tests/adapter/operation/test_close.cc b/test/webfuse/tests/adapter/operation/test_close.cc index b7a7a9b..885e3bb 100644 --- a/test/webfuse/tests/adapter/operation/test_close.cc +++ b/test/webfuse/tests/adapter/operation/test_close.cc @@ -17,7 +17,7 @@ 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); + 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) @@ -39,7 +39,7 @@ TEST(wf_impl_operation_close, notify_proxy) TEST(wf_impl_operation_close, fail_rpc_null) { MockJsonRpcProxy proxy; - EXPECT_CALL(proxy, wf_jsonrpc_proxy_vnotify(_,_,_,_)).Times(0); + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vnotify(_,_,_)).Times(0); MockOperationsContext context; EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) diff --git a/test/webfuse/tests/adapter/operation/test_open.cc b/test/webfuse/tests/adapter/operation/test_open.cc index e7e5ca4..f82e81e 100644 --- a/test/webfuse/tests/adapter/operation/test_open.cc +++ b/test/webfuse/tests/adapter/operation/test_open.cc @@ -19,7 +19,7 @@ using testing::StrEq; TEST(wf_impl_operation_open, invoke_proxy) { MockJsonRpcProxy proxy; - EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("open"),StrEq("sii"),_)).Times(1); + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("open"),StrEq("sii"))).Times(1); MockOperationsContext context; EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) diff --git a/test/webfuse/utils/wrap.hpp b/test/webfuse/utils/wrap.hpp index 4402598..30694de 100644 --- a/test/webfuse/utils/wrap.hpp +++ b/test/webfuse/utils/wrap.hpp @@ -99,4 +99,34 @@ } \ } + +#define WF_WRAP_VFUNC3( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE ) \ + extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, va_list); \ + RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3, va_list args) \ + { \ + if (nullptr == GLOBAL_VAR ) \ + { \ + return __real_ ## FUNC_NAME (arg1, arg2, arg3, args); \ + } \ + else \ + { \ + return GLOBAL_VAR -> FUNC_NAME(arg1, arg2, arg3); \ + } \ + } + +#define WF_WRAP_VFUNC5( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE ) \ + extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE, ARG5_TYPE, va_list); \ + RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3, ARG4_TYPE arg4, ARG5_TYPE arg5, va_list args) \ + { \ + if (nullptr == GLOBAL_VAR ) \ + { \ + return __real_ ## FUNC_NAME (arg1, arg2, arg3, arg4, arg5, args); \ + } \ + else \ + { \ + return GLOBAL_VAR -> FUNC_NAME(arg1, arg2, arg3, arg4, arg5); \ + } \ + } + + #endif From ac09ee9c2fc23a4a8f57092b865b26dd26dbeb63 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 12:51:26 +0200 Subject: [PATCH 31/43] disabled build of libfuse examples --- build/amd64-ubuntu-builder.dockerfile | 1 + build/arm32v7-ubuntu-builder.dockerfile | 1 + 2 files changed, 2 insertions(+) diff --git a/build/amd64-ubuntu-builder.dockerfile b/build/amd64-ubuntu-builder.dockerfile index 7f5cc46..cbdc241 100644 --- a/build/amd64-ubuntu-builder.dockerfile +++ b/build/amd64-ubuntu-builder.dockerfile @@ -58,6 +58,7 @@ RUN set -x \ && mkdir -p "$builddir" \ && cd "$builddir" \ && meson "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ + && meson configure -Dexamples=false \ && ninja \ && ninja install \ && pip3 uninstall -y meson \ diff --git a/build/arm32v7-ubuntu-builder.dockerfile b/build/arm32v7-ubuntu-builder.dockerfile index a84a8e3..a9da298 100644 --- a/build/arm32v7-ubuntu-builder.dockerfile +++ b/build/arm32v7-ubuntu-builder.dockerfile @@ -61,6 +61,7 @@ RUN set -x \ && mkdir -p "$builddir" \ && cd "$builddir" \ && meson "/usr/local/src/libfuse-fuse-$FUSE_VERSION" \ + && meson configure -Dexamples=false \ && ninja \ && ninja install \ && pip3 uninstall -y meson \ From e00050073549038c6a50885a7581d19f25c89ac2 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 15:41:33 +0200 Subject: [PATCH 32/43] added unit tests for read operation (adapter); did some hardening --- cmake/unit_tests.cmake | 2 + lib/webfuse/adapter/impl/filesystem.c | 1 + lib/webfuse/adapter/impl/operation/read.c | 30 ++- lib/webfuse/adapter/impl/operation/read.h | 36 +++ lib/webfuse/adapter/impl/operations.h | 5 - test/webfuse/mocks/mock_fuse.cc | 1 + test/webfuse/mocks/mock_fuse.hpp | 1 + .../tests/adapter/operation/test_read.cc | 237 ++++++++++++++++++ 8 files changed, 303 insertions(+), 10 deletions(-) create mode 100644 lib/webfuse/adapter/impl/operation/read.h create mode 100644 test/webfuse/tests/adapter/operation/test_read.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 1ba7e5a..2b2d445 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -50,6 +50,7 @@ add_executable(alltests 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/adapter/operation/test_read.cc test/webfuse/tests/provider/test_url.cc test/webfuse/tests/provider/test_client_protocol.cc test/webfuse/tests/provider/operation/test_close.cc @@ -78,6 +79,7 @@ target_link_libraries(alltests PUBLIC -Wl,--wrap=fuse_req_userdata -Wl,--wrap=fuse_reply_open -Wl,--wrap=fuse_reply_err + -Wl,--wrap=fuse_reply_buf webfuse-adapter-static webfuse-provider-static diff --git a/lib/webfuse/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c index da9c87b..66ee76c 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -2,6 +2,7 @@ #include "webfuse/adapter/impl/operations.h" #include "webfuse/adapter/impl/operation/open.h" #include "webfuse/adapter/impl/operation/close.h" +#include "webfuse/adapter/impl/operation/read.h" #include "webfuse/adapter/impl/session.h" #include "webfuse/adapter/impl/mountpoint.h" diff --git a/lib/webfuse/adapter/impl/operation/read.c b/lib/webfuse/adapter/impl/operation/read.c index 7896b30..59c3180 100644 --- a/lib/webfuse/adapter/impl/operation/read.c +++ b/lib/webfuse/adapter/impl/operation/read.c @@ -1,3 +1,4 @@ +#include "webfuse/adapter/impl/operation/read.h" #include "webfuse/adapter/impl/operations.h" #include @@ -11,8 +12,9 @@ #define WF_MAX_READ_LENGTH 4096 -static char * wf_impl_fill_buffer( +char * wf_impl_fill_buffer( char const * data, + size_t data_size, char const * format, size_t count, wf_status * status) @@ -24,11 +26,22 @@ static char * wf_impl_fill_buffer( { if (0 == strcmp("identity", format)) { - memcpy(buffer, data, count); + if (count == data_size) + { + memcpy(buffer, data, count); + } + else + { + *status = WF_BAD; + } } else if (0 == strcmp("base64", format)) { - wf_base64_decode(data, strlen(data), (uint8_t *) buffer, count); + size_t result = wf_base64_decode(data, data_size, (uint8_t *) buffer, count); + if (result != count) + { + *status = WF_BAD; + } } else { @@ -36,10 +49,16 @@ static char * wf_impl_fill_buffer( } } + if (WF_GOOD != *status) + { + free(buffer); + buffer = NULL; + } + return buffer; } -static void wf_impl_operation_read_finished( +void wf_impl_operation_read_finished( void * user_data, json_t const * result, json_t const * error) @@ -60,10 +79,11 @@ static void wf_impl_operation_read_finished( json_is_integer(count_holder)) { char const * const data = json_string_value(data_holder); + size_t const data_size = json_string_length(data_holder); char const * const format = json_string_value(format_holder); length = (size_t) json_integer_value(count_holder); - buffer = wf_impl_fill_buffer(data, format, length, &status); + buffer = wf_impl_fill_buffer(data, data_size, format, length, &status); } else { diff --git a/lib/webfuse/adapter/impl/operation/read.h b/lib/webfuse/adapter/impl/operation/read.h new file mode 100644 index 0000000..89228b0 --- /dev/null +++ b/lib/webfuse/adapter/impl/operation/read.h @@ -0,0 +1,36 @@ +#ifndef WF_ADAPTER_IMPL_OPERATION_READ_H +#define WF_ADAPTER_IMPL_OPERATION_READ_H + +#include "webfuse/adapter/impl/fuse_wrapper.h" +#include "webfuse/core/status.h" + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern void wf_impl_operation_read( + fuse_req_t request, + fuse_ino_t ino, size_t size, off_t off, + struct fuse_file_info *fi); + +extern char * wf_impl_fill_buffer( + char const * data, + size_t data_size, + char const * format, + size_t count, + wf_status * status); + +extern void wf_impl_operation_read_finished( + void * user_data, + json_t const * result, + json_t const * error); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/webfuse/adapter/impl/operations.h b/lib/webfuse/adapter/impl/operations.h index 01808bc..6217de7 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_read( - fuse_req_t request, - fuse_ino_t ino, size_t size, off_t off, - struct fuse_file_info *fi); - extern struct wf_jsonrpc_proxy * wf_impl_operations_context_get_proxy( struct wf_impl_operations_context * context); diff --git a/test/webfuse/mocks/mock_fuse.cc b/test/webfuse/mocks/mock_fuse.cc index fa2f981..1cf6aa1 100644 --- a/test/webfuse/mocks/mock_fuse.cc +++ b/test/webfuse/mocks/mock_fuse.cc @@ -8,6 +8,7 @@ static webfuse_test::FuseMock * webfuse_test_FuseMock = nullptr; WF_WRAP_FUNC1(webfuse_test_FuseMock, void*, fuse_req_userdata, fuse_req_t); WF_WRAP_FUNC2(webfuse_test_FuseMock, int, fuse_reply_open, fuse_req_t, const struct fuse_file_info *); WF_WRAP_FUNC2(webfuse_test_FuseMock, int, fuse_reply_err, fuse_req_t, int); +WF_WRAP_FUNC3(webfuse_test_FuseMock, int, fuse_reply_buf, fuse_req_t, const char *, size_t); } diff --git a/test/webfuse/mocks/mock_fuse.hpp b/test/webfuse/mocks/mock_fuse.hpp index 07bcb60..1b81e71 100644 --- a/test/webfuse/mocks/mock_fuse.hpp +++ b/test/webfuse/mocks/mock_fuse.hpp @@ -16,6 +16,7 @@ public: MOCK_METHOD1(fuse_req_userdata, void *(fuse_req_t req)); MOCK_METHOD2(fuse_reply_open, int (fuse_req_t req, const struct fuse_file_info *fi)); MOCK_METHOD2(fuse_reply_err, int (fuse_req_t req, int err)); + MOCK_METHOD3(fuse_reply_buf, int (fuse_req_t req, const char *buf, size_t size)); }; } diff --git a/test/webfuse/tests/adapter/operation/test_read.cc b/test/webfuse/tests/adapter/operation/test_read.cc new file mode 100644 index 0000000..85fcf34 --- /dev/null +++ b/test/webfuse/tests/adapter/operation/test_read.cc @@ -0,0 +1,237 @@ +#include "webfuse/adapter/impl/operation/read.h" +#include "webfuse/adapter/impl/operations.h" + +#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_read, invoke_proxy) +{ + MockJsonRpcProxy proxy; + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("read"),StrEq("siiii"))).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)); + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + size_t size = 42; + off_t offset = 0; + fuse_file_info file_info; + file_info.fh = 1; + wf_impl_operation_read(request, inode, size, offset, &file_info); +} + +TEST(wf_impl_operation_read, invoke_proxy_limit_size) +{ + MockJsonRpcProxy proxy; + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("read"),StrEq("siiii"))).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)); + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + size_t size = 100 * 1024 * 1024; + off_t offset = 0; + fuse_file_info file_info; + file_info.fh = 1; + wf_impl_operation_read(request, inode, size, offset, &file_info); +} + +TEST(wf_impl_operation_read, fail_rpc_null) +{ + 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(_, ENOENT)).Times(1).WillOnce(Return(0)); + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + size_t size = 42; + off_t offset = 0; + fuse_file_info * file_info = nullptr; + wf_impl_operation_read(request, inode, size, offset, file_info); +} + +TEST(wf_impl_operation_read, fill_buffer_identity) +{ + wf_status status; + char * buffer = wf_impl_fill_buffer("brummni", 8, "identity", 8, &status); + ASSERT_EQ(WF_GOOD, status); + ASSERT_STREQ("brummni", buffer); + free(buffer); +} + +TEST(wf_impl_operation_read, fill_buffer_identity_fail_inconsistent_size) +{ + wf_status status; + char * buffer = wf_impl_fill_buffer("brummni", 8, "identity", 7, &status); + ASSERT_NE(WF_GOOD, status); + ASSERT_EQ(nullptr, buffer); +} + +TEST(wf_impl_operation_read, fill_buffer_base64) +{ + wf_status status; + char * buffer = wf_impl_fill_buffer("YnJ1bW1uaQ==", 12, "base64", 7, &status); + + ASSERT_EQ(WF_GOOD, status); + ASSERT_EQ(0, strncmp("brummni", buffer, 7)); + free(buffer); +} + +TEST(wf_impl_operation_read, fill_buffer_base64_fail_invalid_data) +{ + wf_status status; + char * buffer = wf_impl_fill_buffer("YnJ1bW1uaQ=A", 12, "base64", 8, &status); + ASSERT_NE(WF_GOOD, status); + ASSERT_EQ(nullptr, buffer); +} + +TEST(wf_impl_operation_read, fill_buffer_empty) +{ + wf_status status; + char * buffer = wf_impl_fill_buffer(nullptr, 0, "identity", 0, &status); + + ASSERT_EQ(WF_GOOD, status); + free(buffer); +} + +TEST(wf_impl_operation_read, fill_buffer_fail_invalid_format) +{ + wf_status status; + char * buffer = wf_impl_fill_buffer("some data", 9, "unknown", 9, &status); + ASSERT_NE(WF_GOOD, status); + ASSERT_EQ(nullptr, buffer); +} + +TEST(wf_impl_operation_read, finished) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,7)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "data", json_string("brummni")); + json_object_set_new(result, "format", json_string("identity")); + json_object_set_new(result, "count", json_integer(7)); + wf_impl_operation_read_finished(nullptr, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_read, finished_fail_no_data) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "format", json_string("identity")); + json_object_set_new(result, "count", json_integer(7)); + wf_impl_operation_read_finished(nullptr, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_read, finished_fail_invalid_data_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "data", json_integer(42)); + json_object_set_new(result, "format", json_string("identity")); + json_object_set_new(result, "count", json_integer(7)); + wf_impl_operation_read_finished(nullptr, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_read, finished_fail_no_format) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "data", json_string("brummni")); + json_object_set_new(result, "count", json_integer(7)); + wf_impl_operation_read_finished(nullptr, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_read, finished_fail_invalid_format_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "data", json_string("brummni")); + json_object_set_new(result, "format", json_integer(42)); + json_object_set_new(result, "count", json_integer(7)); + wf_impl_operation_read_finished(nullptr, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_read, finished_fail_no_count) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "data", json_string("brummni")); + json_object_set_new(result, "format", json_string("identity")); + wf_impl_operation_read_finished(nullptr, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_read, finished_fail_invalid_count_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "data", json_string("brummni")); + json_object_set_new(result, "format", json_string("identity")); + json_object_set_new(result, "count", json_string("7")); + wf_impl_operation_read_finished(nullptr, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_read, finished_fail_error) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0)); + + json_t * error = json_object(); + json_object_set_new(error, "code", json_integer(WF_BAD)); + wf_impl_operation_read_finished(nullptr, nullptr, error); + json_decref(error); +} From a532197e245657454177703c9525fb4b45536a2d Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 16:56:20 +0200 Subject: [PATCH 33/43] added alpine build --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index ceddb6c..1af60eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,7 @@ env: - BUILDTYPE=Release MARCH=amd64 CHECK_TARGET=memcheck - BUILDTYPE=Debug MARCH=arm32v7 CHECK_TARGET=check - BUILDTYPE=MinSizeRel MARCH=arm32v7 CHECK_TARGET=check + - BUILDTYPE=Debug MARCH=amd54 CHECK_TARGET=check DISTRO=alpine before_script: - make BUILDTYPE=$BUILDTYPE MARCH=$MARCH script: From 7b78194cb3aaee49860138042cfdd690183be3e2 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 17:18:24 +0200 Subject: [PATCH 34/43] specify distro for make --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1af60eb..cff549d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,6 @@ env: before_script: - make BUILDTYPE=$BUILDTYPE MARCH=$MARCH script: -- make BUILDTYPE=$BUILDTYPE MARCH=$MARCH $CHECK_TARGET +- make DISTRO=$DISTRO BUILDTYPE=$BUILDTYPE MARCH=$MARCH $CHECK_TARGET after_success: - bash <(curl -s https://codecov.io/bash) From 9095fbc1b7a1e978185d4c51a41c26fb66f5c14f Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 17:45:48 +0200 Subject: [PATCH 35/43] fixed alpine build --- .travis.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index cff549d..ae18a7a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,16 +12,15 @@ addons: - qemu-user-static env: global: - - DISTRO=ubuntu - PARALLELMFLAGS="-j4" - PORTABLE_WORSPACE=1 matrix: - - BUILDTYPE=Debug MARCH=amd64 CHECK_TARGET=memcheck - - BUILDTYPE=Coverage MARCH=amd64 CHECK_TARGET=check - - BUILDTYPE=Release MARCH=amd64 CHECK_TARGET=memcheck - - BUILDTYPE=Debug MARCH=arm32v7 CHECK_TARGET=check - - BUILDTYPE=MinSizeRel MARCH=arm32v7 CHECK_TARGET=check - - BUILDTYPE=Debug MARCH=amd54 CHECK_TARGET=check DISTRO=alpine + - DISTRO=ubuntu BUILDTYPE=Debug MARCH=amd64 CHECK_TARGET=memcheck + - DISTRO=ubuntu BUILDTYPE=Coverage MARCH=amd64 CHECK_TARGET=check + - DISTRO=ubuntu BUILDTYPE=Release MARCH=amd64 CHECK_TARGET=memcheck + - DISTRO=ubuntu BUILDTYPE=Debug MARCH=arm32v7 CHECK_TARGET=check + - DISTRO=ubuntu BUILDTYPE=MinSizeRel MARCH=arm32v7 CHECK_TARGET=check + - DISTRO=alpine BUILDTYPE=Debug MARCH=amd64 CHECK_TARGET=check before_script: - make BUILDTYPE=$BUILDTYPE MARCH=$MARCH script: From 98e02240e9d01b9f6f359a2123505b19189e005e Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 18:20:45 +0200 Subject: [PATCH 36/43] fixed memory leak --- test/webfuse/tests/provider/operation/test_open.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/webfuse/tests/provider/operation/test_open.cc b/test/webfuse/tests/provider/operation/test_open.cc index 68a53f0..4c52b02 100644 --- a/test/webfuse/tests/provider/operation/test_open.cc +++ b/test/webfuse/tests/provider/operation/test_open.cc @@ -41,6 +41,7 @@ TEST(wfp_impl_open, invoke_provider) json_array_append_new(params, json_integer(flags)); wfp_impl_open(&context, params, 42); + json_decref(params); } TEST(wfp_impl_open, fail_invalid_param_count) @@ -56,6 +57,7 @@ TEST(wfp_impl_open, fail_invalid_param_count) json_array_append_new(params, json_integer(23)); wfp_impl_open(&context, params, 42); + json_decref(params); } TEST(wfp_impl_open, fail_invalid_inode_type) @@ -72,6 +74,7 @@ TEST(wfp_impl_open, fail_invalid_inode_type) json_array_append_new(params, json_integer(0)); wfp_impl_open(&context, params, 42); + json_decref(params); } TEST(wfp_impl_open, fail_invalid_flags_type) @@ -88,6 +91,7 @@ TEST(wfp_impl_open, fail_invalid_flags_type) json_array_append_new(params, json_string("")); wfp_impl_open(&context, params, 42); + json_decref(params); } TEST(wfp_impl_open, default_responds_error) From c769c02c55e63a82e3a8a2fcec10c95308c6901f Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 20:23:50 +0200 Subject: [PATCH 37/43] added unit tests for readdir operation (adapter) --- cmake/unit_tests.cmake | 1 + lib/webfuse/adapter/impl/filesystem.c | 1 + lib/webfuse/adapter/impl/operation/readdir.c | 53 ++-- lib/webfuse/adapter/impl/operation/readdir.h | 35 +++ .../tests/adapter/operation/test_readdir.cc | 266 ++++++++++++++++++ 5 files changed, 331 insertions(+), 25 deletions(-) create mode 100644 lib/webfuse/adapter/impl/operation/readdir.h create mode 100644 test/webfuse/tests/adapter/operation/test_readdir.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 2b2d445..1444ee5 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -51,6 +51,7 @@ add_executable(alltests test/webfuse/tests/adapter/operation/test_open.cc test/webfuse/tests/adapter/operation/test_close.cc test/webfuse/tests/adapter/operation/test_read.cc + test/webfuse/tests/adapter/operation/test_readdir.cc test/webfuse/tests/provider/test_url.cc test/webfuse/tests/provider/test_client_protocol.cc test/webfuse/tests/provider/operation/test_close.cc diff --git a/lib/webfuse/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c index 66ee76c..2573753 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -3,6 +3,7 @@ #include "webfuse/adapter/impl/operation/open.h" #include "webfuse/adapter/impl/operation/close.h" #include "webfuse/adapter/impl/operation/read.h" +#include "webfuse/adapter/impl/operation/readdir.h" #include "webfuse/adapter/impl/session.h" #include "webfuse/adapter/impl/mountpoint.h" diff --git a/lib/webfuse/adapter/impl/operation/readdir.c b/lib/webfuse/adapter/impl/operation/readdir.c index 804a80e..d82fc62 100644 --- a/lib/webfuse/adapter/impl/operation/readdir.c +++ b/lib/webfuse/adapter/impl/operation/readdir.c @@ -1,3 +1,4 @@ +#include "webfuse/adapter/impl/operation/readdir.h" #include "webfuse/adapter/impl/operations.h" #include @@ -15,13 +16,6 @@ #define WF_DIRBUFFER_INITIAL_SIZE 1024 -struct wf_impl_operation_readdir_context -{ - fuse_req_t request; - size_t size; - off_t offset; -}; - struct wf_impl_dirbuffer { char * data; @@ -72,7 +66,7 @@ static size_t wf_impl_min(size_t a, size_t b) return (a < b) ? a : b; } -static void wf_impl_operation_readdir_finished( +void wf_impl_operation_readdir_finished( void * user_data, json_t const * result, json_t const * error) @@ -83,31 +77,40 @@ static void wf_impl_operation_readdir_finished( struct wf_impl_dirbuffer buffer; wf_impl_dirbuffer_init(&buffer); - if (NULL != result) + if (json_is_array(result)) { - if (json_is_array(result)) + size_t const count = json_array_size(result); + for(size_t i = 0; i < count; i++) { - bool buffer_full = false; - size_t const count = json_array_size(result); - for(size_t i = 0; (!buffer_full) && (i < count); i++) + json_t * entry =json_array_get(result, i); + if (json_is_object(entry)) { - json_t * entry =json_array_get(result, i); - if (json_is_object(entry)) - { - json_t * name_holder = json_object_get(entry, "name"); - json_t * inode_holder = json_object_get(entry, "inode"); + json_t * name_holder = json_object_get(entry, "name"); + json_t * inode_holder = json_object_get(entry, "inode"); - if ((NULL != name_holder) && (json_is_string(name_holder)) && - (NULL != inode_holder) && (json_is_integer(inode_holder))) - { - char const * name = json_string_value(name_holder); - fuse_ino_t entry_inode = (fuse_ino_t) json_integer_value(inode_holder); - wf_impl_dirbuffer_add(context->request, &buffer, name, entry_inode); - } + if ((json_is_string(name_holder)) && (json_is_integer(inode_holder))) + { + char const * name = json_string_value(name_holder); + fuse_ino_t entry_inode = (fuse_ino_t) json_integer_value(inode_holder); + wf_impl_dirbuffer_add(context->request, &buffer, name, entry_inode); + } + else + { + status = WF_BAD_FORMAT; + break; } } + else + { + status = WF_BAD_FORMAT; + break; + } } } + else if (WF_GOOD == status) + { + status = WF_BAD_FORMAT; + } if (WF_GOOD == status) { diff --git a/lib/webfuse/adapter/impl/operation/readdir.h b/lib/webfuse/adapter/impl/operation/readdir.h new file mode 100644 index 0000000..40eb09e --- /dev/null +++ b/lib/webfuse/adapter/impl/operation/readdir.h @@ -0,0 +1,35 @@ +#ifndef WF_ADAPTER_IMPL_OPERATION_READDIR_H +#define WF_ADAPTER_IMPL_OPERATION_READDIR_H + +#include "webfuse/adapter/impl/fuse_wrapper.h" +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_impl_operation_readdir_context +{ + fuse_req_t request; + size_t size; + off_t offset; +}; + +extern void wf_impl_operation_readdir ( + fuse_req_t request, + fuse_ino_t inode, + size_t size, + off_t offset, + struct fuse_file_info *file_info); + +extern void wf_impl_operation_readdir_finished( + void * user_data, + json_t const * result, + json_t const * error); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/test/webfuse/tests/adapter/operation/test_readdir.cc b/test/webfuse/tests/adapter/operation/test_readdir.cc new file mode 100644 index 0000000..3ae9df2 --- /dev/null +++ b/test/webfuse/tests/adapter/operation/test_readdir.cc @@ -0,0 +1,266 @@ +#include "webfuse/adapter/impl/operation/readdir.h" +#include "webfuse/adapter/impl/operations.h" + +#include "webfuse/core/status.h" + +#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::Invoke; +using testing::StrEq; + +namespace +{ + +void free_context( + struct wf_jsonrpc_proxy * , + wf_jsonrpc_proxy_finished_fn * , + void * user_data, + char const * , + char const *) +{ + free(user_data); +} + +} + +TEST(wf_impl_operation_readdir, invoke_proxy) +{ + MockJsonRpcProxy proxy; + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("readdir"),StrEq("si"))) + .Times(1).WillOnce(Invoke(free_context)); + + 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)); + + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + size_t size = 10; + size_t offset = 0; + fuse_file_info file_info; + file_info.flags = 0; + wf_impl_operation_readdir(request, inode, size, offset, &file_info); +} + +TEST(wf_impl_operation_readdir, fail_rpc_null) +{ + 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(_, ENOENT)).Times(1).WillOnce(Return(0)); + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + size_t size = 10; + size_t offset = 0; + fuse_file_info file_info; + file_info.flags = 0; + wf_impl_operation_readdir(request, inode, size, offset, &file_info); +} + +TEST(wf_impl_operation_readdir, finished) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_array(); + json_t * item = json_object(); + json_object_set_new(item, "name", json_string("a.file")); + json_object_set_new(item, "inode", json_integer(42)); + json_array_append_new(result, item); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 1; + context->offset = 0; + wf_impl_operation_readdir_finished(reinterpret_cast(context), result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_readdir, finished_many_items) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_array(); + for(int i = 0; i < 100; i++) + { + json_t * item = json_object(); + json_object_set_new(item, "name", json_sprintf("file_%d.txt", i)); + json_object_set_new(item, "inode", json_integer(1 + i)); + json_array_append_new(result, item); + } + + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 100; + context->offset = 0; + wf_impl_operation_readdir_finished(reinterpret_cast(context), result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_readdir, finished_read_after_end) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_array(); + json_t * item = json_object(); + json_object_set_new(item, "name", json_string("a.file")); + json_object_set_new(item, "inode", json_integer(42)); + json_array_append_new(result, item); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 10; + context->offset = 2; + wf_impl_operation_readdir_finished(reinterpret_cast(context), result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_readdir, finished_fail_error) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * error = json_array(); + json_object_set_new(error, "code", json_integer(WF_BAD)); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 1; + context->offset = 0; + wf_impl_operation_readdir_finished(reinterpret_cast(context), nullptr, error); + json_decref(error); +} + +TEST(wf_impl_operation_readdir, finished_fail_invalid_result_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 1; + context->offset = 0; + wf_impl_operation_readdir_finished(reinterpret_cast(context), result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_readdir, finished_fail_missing_name) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_array(); + json_t * item = json_object(); + json_object_set_new(item, "inode", json_integer(42)); + json_array_append_new(result, item); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 1; + context->offset = 0; + wf_impl_operation_readdir_finished(reinterpret_cast(context), result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_readdir, finished_fail_invalid_name_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_array(); + json_t * item = json_object(); + json_object_set_new(item, "name", json_integer(42)); + json_object_set_new(item, "inode", json_integer(42)); + json_array_append_new(result, item); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 1; + context->offset = 0; + wf_impl_operation_readdir_finished(reinterpret_cast(context), result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_readdir, finished_fail_missing_inode) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_array(); + json_t * item = json_object(); + json_object_set_new(item, "name", json_string("a.file")); + json_array_append_new(result, item); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 1; + context->offset = 0; + wf_impl_operation_readdir_finished(reinterpret_cast(context), result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_readdir, finished_fail_invalid_inode_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_array(); + json_t * item = json_object(); + json_object_set_new(item, "name", json_string("a.file")); + json_object_set_new(item, "inode", json_string("42")); + json_array_append_new(result, item); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 1; + context->offset = 0; + wf_impl_operation_readdir_finished(reinterpret_cast(context), result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_readdir, finished_fail_invalid_item_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_array(); + json_array_append_new(result, json_string("item")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_readdir_context))); + context->request = nullptr; + context->size = 1; + context->offset = 0; + wf_impl_operation_readdir_finished(reinterpret_cast(context), result, nullptr); + json_decref(result); +} From 654015c95c4b55ccdca1b680aa4dc9c8f31b4ddf Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 22:26:15 +0200 Subject: [PATCH 38/43] added unit tests for getattr operation (adapter) --- cmake/unit_tests.cmake | 3 + lib/webfuse/adapter/impl/filesystem.c | 1 + lib/webfuse/adapter/impl/operation/getattr.c | 15 +- lib/webfuse/adapter/impl/operation/getattr.h | 37 +++ lib/webfuse/adapter/impl/operations.h | 12 - test/webfuse/mocks/mock_fuse.cc | 2 + test/webfuse/mocks/mock_fuse.hpp | 2 + .../tests/adapter/operation/test_getattr.cc | 214 ++++++++++++++++++ 8 files changed, 262 insertions(+), 24 deletions(-) create mode 100644 lib/webfuse/adapter/impl/operation/getattr.h create mode 100644 test/webfuse/tests/adapter/operation/test_getattr.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 1444ee5..0e3f8dd 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -52,6 +52,7 @@ add_executable(alltests test/webfuse/tests/adapter/operation/test_close.cc test/webfuse/tests/adapter/operation/test_read.cc test/webfuse/tests/adapter/operation/test_readdir.cc + test/webfuse/tests/adapter/operation/test_getattr.cc test/webfuse/tests/provider/test_url.cc test/webfuse/tests/provider/test_client_protocol.cc test/webfuse/tests/provider/operation/test_close.cc @@ -81,6 +82,8 @@ target_link_libraries(alltests PUBLIC -Wl,--wrap=fuse_reply_open -Wl,--wrap=fuse_reply_err -Wl,--wrap=fuse_reply_buf + -Wl,--wrap=fuse_reply_attr + -Wl,--wrap=fuse_req_ctx webfuse-adapter-static webfuse-provider-static diff --git a/lib/webfuse/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c index 2573753..d614cd4 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -4,6 +4,7 @@ #include "webfuse/adapter/impl/operation/close.h" #include "webfuse/adapter/impl/operation/read.h" #include "webfuse/adapter/impl/operation/readdir.h" +#include "webfuse/adapter/impl/operation/getattr.h" #include "webfuse/adapter/impl/session.h" #include "webfuse/adapter/impl/mountpoint.h" diff --git a/lib/webfuse/adapter/impl/operation/getattr.c b/lib/webfuse/adapter/impl/operation/getattr.c index ae64a25..6185044 100644 --- a/lib/webfuse/adapter/impl/operation/getattr.c +++ b/lib/webfuse/adapter/impl/operation/getattr.c @@ -1,3 +1,4 @@ +#include "webfuse/adapter/impl/operation/getattr.h" #include "webfuse/adapter/impl/operations.h" #include @@ -11,16 +12,7 @@ #include "webfuse/core/json_util.h" #include "webfuse/core/util.h" -struct wf_impl_operation_getattr_context -{ - fuse_req_t request; - fuse_ino_t inode; - double timeout; - uid_t uid; - gid_t gid; -}; - -static void wf_impl_operation_getattr_finished( +void wf_impl_operation_getattr_finished( void * user_data, json_t const * result, json_t const * error) @@ -33,8 +25,7 @@ static void wf_impl_operation_getattr_finished( { json_t * mode_holder = json_object_get(result, "mode"); json_t * type_holder = json_object_get(result, "type"); - if ((NULL != mode_holder) && (json_is_integer(mode_holder)) && - (NULL != type_holder) && (json_is_string(type_holder))) + if ((json_is_integer(mode_holder)) && (json_is_string(type_holder))) { memset(&buffer, 0, sizeof(struct stat)); diff --git a/lib/webfuse/adapter/impl/operation/getattr.h b/lib/webfuse/adapter/impl/operation/getattr.h new file mode 100644 index 0000000..3908922 --- /dev/null +++ b/lib/webfuse/adapter/impl/operation/getattr.h @@ -0,0 +1,37 @@ +#ifndef WF_ADAPTER_IMPL_OPERATION_GETATTR_H +#define WF_ADAPTER_IMPL_OPERATION_GETATTR_H + +#include "webfuse/adapter/impl/fuse_wrapper.h" + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_impl_operation_getattr_context +{ + fuse_req_t request; + fuse_ino_t inode; + double timeout; + uid_t uid; + gid_t gid; +}; + +extern void wf_impl_operation_getattr_finished( + void * user_data, + json_t const * result, + json_t const * error); + +extern void wf_impl_operation_getattr ( + 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 6217de7..e52d09e 100644 --- a/lib/webfuse/adapter/impl/operations.h +++ b/lib/webfuse/adapter/impl/operations.h @@ -22,18 +22,6 @@ extern void wf_impl_operation_lookup ( fuse_ino_t parent, char const * name); -extern void wf_impl_operation_getattr ( - fuse_req_t request, - fuse_ino_t inode, - struct fuse_file_info *file_info); - -extern void wf_impl_operation_readdir ( - fuse_req_t request, - fuse_ino_t inode, - size_t size, - off_t offset, - struct fuse_file_info *file_info); - extern struct wf_jsonrpc_proxy * wf_impl_operations_context_get_proxy( struct wf_impl_operations_context * context); diff --git a/test/webfuse/mocks/mock_fuse.cc b/test/webfuse/mocks/mock_fuse.cc index 1cf6aa1..96eb6fa 100644 --- a/test/webfuse/mocks/mock_fuse.cc +++ b/test/webfuse/mocks/mock_fuse.cc @@ -9,6 +9,8 @@ WF_WRAP_FUNC1(webfuse_test_FuseMock, void*, fuse_req_userdata, fuse_req_t); WF_WRAP_FUNC2(webfuse_test_FuseMock, int, fuse_reply_open, fuse_req_t, const struct fuse_file_info *); WF_WRAP_FUNC2(webfuse_test_FuseMock, int, fuse_reply_err, fuse_req_t, int); WF_WRAP_FUNC3(webfuse_test_FuseMock, int, fuse_reply_buf, fuse_req_t, const char *, size_t); +WF_WRAP_FUNC3(webfuse_test_FuseMock, int, fuse_reply_attr, fuse_req_t, const struct stat *, double); +WF_WRAP_FUNC1(webfuse_test_FuseMock, const struct fuse_ctx *, fuse_req_ctx, fuse_req_t); } diff --git a/test/webfuse/mocks/mock_fuse.hpp b/test/webfuse/mocks/mock_fuse.hpp index 1b81e71..02f6e75 100644 --- a/test/webfuse/mocks/mock_fuse.hpp +++ b/test/webfuse/mocks/mock_fuse.hpp @@ -17,6 +17,8 @@ public: MOCK_METHOD2(fuse_reply_open, int (fuse_req_t req, const struct fuse_file_info *fi)); MOCK_METHOD2(fuse_reply_err, int (fuse_req_t req, int err)); MOCK_METHOD3(fuse_reply_buf, int (fuse_req_t req, const char *buf, size_t size)); + MOCK_METHOD3(fuse_reply_attr, int (fuse_req_t req, const struct stat *attr, double attr_timeout)); + MOCK_METHOD1(fuse_req_ctx, const struct fuse_ctx *(fuse_req_t req)); }; } diff --git a/test/webfuse/tests/adapter/operation/test_getattr.cc b/test/webfuse/tests/adapter/operation/test_getattr.cc new file mode 100644 index 0000000..cced583 --- /dev/null +++ b/test/webfuse/tests/adapter/operation/test_getattr.cc @@ -0,0 +1,214 @@ +#include "webfuse/adapter/impl/operation/getattr.h" +#include "webfuse/adapter/impl/operations.h" + +#include "webfuse/core/status.h" + +#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::Invoke; +using testing::StrEq; + +namespace +{ + +void free_context( + struct wf_jsonrpc_proxy * , + wf_jsonrpc_proxy_finished_fn * , + void * user_data, + char const * , + char const *) +{ + free(user_data); +} + +} + +TEST(wf_impl_operation_getattr, invoke_proxy) +{ + MockJsonRpcProxy proxy; + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("getattr"),StrEq("si"))).Times(1) + .WillOnce(Invoke(free_context)); + + 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; + fuse_ctx fuse_context; + fuse_context.gid = 0; + fuse_context.uid = 0; + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_ctx(_)).Times(1).WillOnce(Return(&fuse_context)); + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); + + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + fuse_file_info * file_info = nullptr; + wf_impl_operation_getattr(request, inode, file_info); +} + +TEST(wf_impl_operation_getattr, fail_rpc_null) +{ + MockOperationsContext context; + EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + .WillOnce(Return(nullptr)); + + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_ctx(_)).Times(1).WillOnce(Return(nullptr)); + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(nullptr)); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + fuse_file_info * file_info = nullptr; + wf_impl_operation_getattr(request, inode, file_info); +} + +TEST(wf_impl_operation_getattr, finished_file) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_attr(_,_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "mode", json_integer(0755)); + json_object_set_new(result, "type", json_string("file")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_getattr_context))); + context->inode = 1; + context->gid = 0; + context->uid = 0; + wf_impl_operation_getattr_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_getattr, finished_dir) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_attr(_,_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "mode", json_integer(0755)); + json_object_set_new(result, "type", json_string("dir")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_getattr_context))); + context->inode = 1; + context->gid = 0; + context->uid = 0; + wf_impl_operation_getattr_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_getattr, finished_unknown_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_attr(_,_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "mode", json_integer(0755)); + json_object_set_new(result, "type", json_string("unknown")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_getattr_context))); + context->inode = 1; + context->gid = 0; + context->uid = 0; + wf_impl_operation_getattr_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_getattr, finished_fail_missing_mode) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "type", json_string("file")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_getattr_context))); + context->inode = 1; + context->gid = 0; + context->uid = 0; + wf_impl_operation_getattr_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_getattr, finished_fail_invalid_mode_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "mode", json_string("0755")); + json_object_set_new(result, "type", json_string("file")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_getattr_context))); + context->inode = 1; + context->gid = 0; + context->uid = 0; + wf_impl_operation_getattr_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_getattr, finished_fail_type_mode) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "mode", json_integer(0755)); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_getattr_context))); + context->inode = 1; + context->gid = 0; + context->uid = 0; + wf_impl_operation_getattr_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_getattr, finished_fail_invalid_type_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "mode", json_integer(0755)); + json_object_set_new(result, "type", json_integer(42)); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_getattr_context))); + context->inode = 1; + context->gid = 0; + context->uid = 0; + wf_impl_operation_getattr_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_getattr, finished_error) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * error = json_object(); + json_object_set_new(error, "code", json_integer(WF_BAD)); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_getattr_context))); + context->inode = 1; + context->gid = 0; + context->uid = 0; + wf_impl_operation_getattr_finished(context, nullptr, error); + json_decref(error); +} From 745d47bb30a8746059cb41b43fc8961af29b75df Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 23:16:25 +0200 Subject: [PATCH 39/43] added unit tests for lookup operation (adapter) --- cmake/unit_tests.cmake | 3 + cmake/webfuse_adapter.cmake | 2 +- lib/webfuse/adapter/impl/filesystem.c | 3 +- lib/webfuse/adapter/impl/filesystem.h | 2 +- lib/webfuse/adapter/impl/operation/close.c | 3 +- .../{operations.c => operation/context.c} | 2 +- .../{operations.h => operation/context.h} | 9 +- lib/webfuse/adapter/impl/operation/getattr.c | 2 +- lib/webfuse/adapter/impl/operation/lookup.c | 19 +- lib/webfuse/adapter/impl/operation/lookup.h | 36 +++ lib/webfuse/adapter/impl/operation/open.c | 2 +- lib/webfuse/adapter/impl/operation/read.c | 2 +- lib/webfuse/adapter/impl/operation/readdir.c | 2 +- test/webfuse/mocks/mock_fuse.cc | 2 +- test/webfuse/mocks/mock_fuse.hpp | 1 + .../webfuse/mocks/mock_operations_context.hpp | 2 +- .../tests/adapter/operation/test_context.cc | 23 ++ .../tests/adapter/operation/test_getattr.cc | 1 - .../tests/adapter/operation/test_lookup.cc | 255 ++++++++++++++++++ .../tests/adapter/operation/test_open.cc | 1 - .../tests/adapter/operation/test_read.cc | 1 - .../tests/adapter/operation/test_readdir.cc | 1 - 22 files changed, 339 insertions(+), 35 deletions(-) rename lib/webfuse/adapter/impl/{operations.c => operation/context.c} (88%) rename lib/webfuse/adapter/impl/{operations.h => operation/context.h} (69%) create mode 100644 lib/webfuse/adapter/impl/operation/lookup.h create mode 100644 test/webfuse/tests/adapter/operation/test_context.cc create mode 100644 test/webfuse/tests/adapter/operation/test_lookup.cc diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 0e3f8dd..eaa8427 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -48,11 +48,13 @@ add_executable(alltests test/webfuse/tests/adapter/test_authenticators.cc test/webfuse/tests/adapter/test_mountpoint.cc test/webfuse/tests/adapter/test_fuse_req.cc + test/webfuse/tests/adapter/operation/test_context.cc test/webfuse/tests/adapter/operation/test_open.cc test/webfuse/tests/adapter/operation/test_close.cc test/webfuse/tests/adapter/operation/test_read.cc test/webfuse/tests/adapter/operation/test_readdir.cc test/webfuse/tests/adapter/operation/test_getattr.cc + test/webfuse/tests/adapter/operation/test_lookup.cc test/webfuse/tests/provider/test_url.cc test/webfuse/tests/provider/test_client_protocol.cc test/webfuse/tests/provider/operation/test_close.cc @@ -83,6 +85,7 @@ target_link_libraries(alltests PUBLIC -Wl,--wrap=fuse_reply_err -Wl,--wrap=fuse_reply_buf -Wl,--wrap=fuse_reply_attr + -Wl,--wrap=fuse_reply_entry -Wl,--wrap=fuse_req_ctx webfuse-adapter-static diff --git a/cmake/webfuse_adapter.cmake b/cmake/webfuse_adapter.cmake index fab0f55..b15b655 100644 --- a/cmake/webfuse_adapter.cmake +++ b/cmake/webfuse_adapter.cmake @@ -13,9 +13,9 @@ add_library(webfuse-adapter-static STATIC lib/webfuse/adapter/impl/authenticator.c lib/webfuse/adapter/impl/authenticators.c lib/webfuse/adapter/impl/credentials.c - lib/webfuse/adapter/impl/operations.c lib/webfuse/adapter/impl/mountpoint.c lib/webfuse/adapter/impl/mountpoint_factory.c + lib/webfuse/adapter/impl/operation/context.c lib/webfuse/adapter/impl/operation/lookup.c lib/webfuse/adapter/impl/operation/getattr.c lib/webfuse/adapter/impl/operation/readdir.c diff --git a/lib/webfuse/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c index d614cd4..0c321e9 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -1,10 +1,11 @@ #include "webfuse/adapter/impl/filesystem.h" -#include "webfuse/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operation/context.h" #include "webfuse/adapter/impl/operation/open.h" #include "webfuse/adapter/impl/operation/close.h" #include "webfuse/adapter/impl/operation/read.h" #include "webfuse/adapter/impl/operation/readdir.h" #include "webfuse/adapter/impl/operation/getattr.h" +#include "webfuse/adapter/impl/operation/lookup.h" #include "webfuse/adapter/impl/session.h" #include "webfuse/adapter/impl/mountpoint.h" diff --git a/lib/webfuse/adapter/impl/filesystem.h b/lib/webfuse/adapter/impl/filesystem.h index 83660d8..9ea6406 100644 --- a/lib/webfuse/adapter/impl/filesystem.h +++ b/lib/webfuse/adapter/impl/filesystem.h @@ -6,7 +6,7 @@ #endif #include "webfuse/adapter/impl/fuse_wrapper.h" -#include "webfuse/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operation/context.h" #include "webfuse/core/slist.h" #ifdef __cplusplus diff --git a/lib/webfuse/adapter/impl/operation/close.c b/lib/webfuse/adapter/impl/operation/close.c index 5f6e49b..5e3c4e8 100644 --- a/lib/webfuse/adapter/impl/operation/close.c +++ b/lib/webfuse/adapter/impl/operation/close.c @@ -1,4 +1,5 @@ -#include "webfuse/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operation/close.h" +#include "webfuse/adapter/impl/operation/context.h" #include #include diff --git a/lib/webfuse/adapter/impl/operations.c b/lib/webfuse/adapter/impl/operation/context.c similarity index 88% rename from lib/webfuse/adapter/impl/operations.c rename to lib/webfuse/adapter/impl/operation/context.c index 9ddad3e..1bde8b1 100644 --- a/lib/webfuse/adapter/impl/operations.c +++ b/lib/webfuse/adapter/impl/operation/context.c @@ -1,4 +1,4 @@ -#include "webfuse/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operation/context.h" #include "webfuse/adapter/impl/session_manager.h" #include "webfuse/adapter/impl/session.h" #include diff --git a/lib/webfuse/adapter/impl/operations.h b/lib/webfuse/adapter/impl/operation/context.h similarity index 69% rename from lib/webfuse/adapter/impl/operations.h rename to lib/webfuse/adapter/impl/operation/context.h index e52d09e..17f5f81 100644 --- a/lib/webfuse/adapter/impl/operations.h +++ b/lib/webfuse/adapter/impl/operation/context.h @@ -1,5 +1,5 @@ -#ifndef WF_ADAPTER_IMPL_OPERATIONS_H -#define WF_ADAPTER_IMPL_OPERATIONS_H +#ifndef WF_ADAPTER_IMPL_OPERATION_CONTEXT_H +#define WF_ADAPTER_IMPL_OPERATION_CONTEXT_H #include "webfuse/adapter/impl/fuse_wrapper.h" @@ -17,11 +17,6 @@ struct wf_impl_operations_context char * name; }; -extern void wf_impl_operation_lookup ( - fuse_req_t req, - fuse_ino_t parent, - char const * name); - extern struct wf_jsonrpc_proxy * wf_impl_operations_context_get_proxy( struct wf_impl_operations_context * context); diff --git a/lib/webfuse/adapter/impl/operation/getattr.c b/lib/webfuse/adapter/impl/operation/getattr.c index 6185044..3c00840 100644 --- a/lib/webfuse/adapter/impl/operation/getattr.c +++ b/lib/webfuse/adapter/impl/operation/getattr.c @@ -1,5 +1,5 @@ #include "webfuse/adapter/impl/operation/getattr.h" -#include "webfuse/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operation/context.h" #include #include diff --git a/lib/webfuse/adapter/impl/operation/lookup.c b/lib/webfuse/adapter/impl/operation/lookup.c index 4b64320..ca778cd 100644 --- a/lib/webfuse/adapter/impl/operation/lookup.c +++ b/lib/webfuse/adapter/impl/operation/lookup.c @@ -1,4 +1,5 @@ -#include "webfuse/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operation/lookup.h" +#include "webfuse/adapter/impl/operation/context.h" #include #include @@ -14,15 +15,7 @@ #include "webfuse/core/json_util.h" #include "webfuse/core/util.h" -struct wf_impl_operation_lookup_context -{ - fuse_req_t request; - double timeout; - uid_t uid; - gid_t gid; -}; - -static void wf_impl_operation_lookup_finished( +void wf_impl_operation_lookup_finished( void * user_data, json_t const * result, json_t const * error @@ -37,9 +30,9 @@ static void wf_impl_operation_lookup_finished( json_t * inode_holder = json_object_get(result, "inode"); json_t * mode_holder = json_object_get(result, "mode"); json_t * type_holder = json_object_get(result, "type"); - if ((NULL != inode_holder) && (json_is_integer(inode_holder)) && - (NULL != mode_holder) && (json_is_integer(mode_holder)) && - (NULL != type_holder) && (json_is_string(type_holder))) + if ((json_is_integer(inode_holder)) && + (json_is_integer(mode_holder)) && + (json_is_string(type_holder))) { memset(&buffer, 0, sizeof(struct stat)); diff --git a/lib/webfuse/adapter/impl/operation/lookup.h b/lib/webfuse/adapter/impl/operation/lookup.h new file mode 100644 index 0000000..c43e864 --- /dev/null +++ b/lib/webfuse/adapter/impl/operation/lookup.h @@ -0,0 +1,36 @@ +#ifndef WF_ADAPTER_IMPL_OPERATION_LOOKUP_H +#define WF_ADAPTER_IMPL_OPERATION_LOOKUP_H + +#include "webfuse/adapter/impl/fuse_wrapper.h" + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wf_impl_operation_lookup_context +{ + fuse_req_t request; + double timeout; + uid_t uid; + gid_t gid; +}; + +extern void wf_impl_operation_lookup_finished( + void * user_data, + json_t const * result, + json_t const * error); + +extern void wf_impl_operation_lookup ( + fuse_req_t req, + fuse_ino_t parent, + char const * name); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/webfuse/adapter/impl/operation/open.c b/lib/webfuse/adapter/impl/operation/open.c index 630e9c8..712f240 100644 --- a/lib/webfuse/adapter/impl/operation/open.c +++ b/lib/webfuse/adapter/impl/operation/open.c @@ -1,5 +1,5 @@ #include "webfuse/adapter/impl/operation/open.h" -#include "webfuse/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operation/context.h" #include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/util.h" diff --git a/lib/webfuse/adapter/impl/operation/read.c b/lib/webfuse/adapter/impl/operation/read.c index 59c3180..81b6928 100644 --- a/lib/webfuse/adapter/impl/operation/read.c +++ b/lib/webfuse/adapter/impl/operation/read.c @@ -1,5 +1,5 @@ #include "webfuse/adapter/impl/operation/read.h" -#include "webfuse/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operation/context.h" #include #include diff --git a/lib/webfuse/adapter/impl/operation/readdir.c b/lib/webfuse/adapter/impl/operation/readdir.c index d82fc62..8022440 100644 --- a/lib/webfuse/adapter/impl/operation/readdir.c +++ b/lib/webfuse/adapter/impl/operation/readdir.c @@ -1,5 +1,5 @@ #include "webfuse/adapter/impl/operation/readdir.h" -#include "webfuse/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operation/context.h" #include #include diff --git a/test/webfuse/mocks/mock_fuse.cc b/test/webfuse/mocks/mock_fuse.cc index 96eb6fa..486c8ed 100644 --- a/test/webfuse/mocks/mock_fuse.cc +++ b/test/webfuse/mocks/mock_fuse.cc @@ -11,7 +11,7 @@ WF_WRAP_FUNC2(webfuse_test_FuseMock, int, fuse_reply_err, fuse_req_t, int); WF_WRAP_FUNC3(webfuse_test_FuseMock, int, fuse_reply_buf, fuse_req_t, const char *, size_t); WF_WRAP_FUNC3(webfuse_test_FuseMock, int, fuse_reply_attr, fuse_req_t, const struct stat *, double); WF_WRAP_FUNC1(webfuse_test_FuseMock, const struct fuse_ctx *, fuse_req_ctx, fuse_req_t); - +WF_WRAP_FUNC2(webfuse_test_FuseMock, int, fuse_reply_entry, fuse_req_t, const struct fuse_entry_param *); } namespace webfuse_test diff --git a/test/webfuse/mocks/mock_fuse.hpp b/test/webfuse/mocks/mock_fuse.hpp index 02f6e75..cc3fb71 100644 --- a/test/webfuse/mocks/mock_fuse.hpp +++ b/test/webfuse/mocks/mock_fuse.hpp @@ -19,6 +19,7 @@ public: MOCK_METHOD3(fuse_reply_buf, int (fuse_req_t req, const char *buf, size_t size)); MOCK_METHOD3(fuse_reply_attr, int (fuse_req_t req, const struct stat *attr, double attr_timeout)); MOCK_METHOD1(fuse_req_ctx, const struct fuse_ctx *(fuse_req_t req)); + MOCK_METHOD2(fuse_reply_entry, int (fuse_req_t req, const struct fuse_entry_param *e)); }; } diff --git a/test/webfuse/mocks/mock_operations_context.hpp b/test/webfuse/mocks/mock_operations_context.hpp index a12aa7b..1dee54c 100644 --- a/test/webfuse/mocks/mock_operations_context.hpp +++ b/test/webfuse/mocks/mock_operations_context.hpp @@ -1,7 +1,7 @@ #ifndef MOCK_OPERATIONS_CONTEXT_HPP #define MOCK_OPERATIONS_CONTEXT_HPP -#include "webfuse/adapter/impl/operations.h" +#include "webfuse/adapter/impl/operation/context.h" #include namespace webfuse_test diff --git a/test/webfuse/tests/adapter/operation/test_context.cc b/test/webfuse/tests/adapter/operation/test_context.cc new file mode 100644 index 0000000..bd53241 --- /dev/null +++ b/test/webfuse/tests/adapter/operation/test_context.cc @@ -0,0 +1,23 @@ +#include "webfuse/adapter/impl/operation/context.h" +#include "webfuse/adapter/impl/session.h" +#include + +TEST(wf_impl_operation_context, get_proxy) +{ + wf_jsonrpc_proxy * proxy = reinterpret_cast(42); + wf_impl_session session; + session.rpc = proxy; + wf_impl_operations_context context; + context.session = &session; + + ASSERT_EQ(proxy, wf_impl_operations_context_get_proxy(&context)); +} + +TEST(wf_impl_operation_context, get_proxy_fail_no_session) +{ + wf_impl_operations_context context; + context.session = nullptr; + + ASSERT_EQ(nullptr, wf_impl_operations_context_get_proxy(&context)); + +} \ No newline at end of file diff --git a/test/webfuse/tests/adapter/operation/test_getattr.cc b/test/webfuse/tests/adapter/operation/test_getattr.cc index cced583..4dc0081 100644 --- a/test/webfuse/tests/adapter/operation/test_getattr.cc +++ b/test/webfuse/tests/adapter/operation/test_getattr.cc @@ -1,5 +1,4 @@ #include "webfuse/adapter/impl/operation/getattr.h" -#include "webfuse/adapter/impl/operations.h" #include "webfuse/core/status.h" diff --git a/test/webfuse/tests/adapter/operation/test_lookup.cc b/test/webfuse/tests/adapter/operation/test_lookup.cc new file mode 100644 index 0000000..73c5774 --- /dev/null +++ b/test/webfuse/tests/adapter/operation/test_lookup.cc @@ -0,0 +1,255 @@ +#include "webfuse/adapter/impl/operation/lookup.h" + +#include "webfuse/core/status.h" + +#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::Invoke; +using testing::StrEq; + +namespace +{ + +void free_context( + struct wf_jsonrpc_proxy * , + wf_jsonrpc_proxy_finished_fn * , + void * user_data, + char const * , + char const *) +{ + free(user_data); +} + +} + +TEST(wf_impl_operation_lookup, invoke_proxy) +{ + MockJsonRpcProxy proxy; + EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("lookup"),StrEq("sis"))).Times(1) + .WillOnce(Invoke(free_context)); + + 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; + fuse_ctx fuse_context; + fuse_context.gid = 0; + fuse_context.uid = 0; + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_ctx(_)).Times(1).WillOnce(Return(&fuse_context)); + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); + + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + wf_impl_operation_lookup(request, inode, "some.file"); +} + +TEST(wf_impl_operation_lookup, fail_rpc_null) +{ + MockOperationsContext context; + EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + .WillOnce(Return(nullptr)); + + FuseMock fuse; + EXPECT_CALL(fuse, fuse_req_ctx(_)).Times(1).WillOnce(Return(nullptr)); + EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(nullptr)); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + fuse_req_t request = nullptr; + fuse_ino_t inode = 1; + wf_impl_operation_lookup(request, inode, "some.file"); +} + +TEST(wf_impl_operation_lookup, finished_file) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_entry(_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "inode", json_integer(42)); + json_object_set_new(result, "mode", json_integer(0755)); + json_object_set_new(result, "type", json_string("file")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_lookup, finished_dir) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_entry(_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "inode", json_integer(42)); + json_object_set_new(result, "mode", json_integer(0755)); + json_object_set_new(result, "type", json_string("dir")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_lookup, finished_unknown_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_entry(_,_)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "inode", json_integer(42)); + json_object_set_new(result, "mode", json_integer(0755)); + json_object_set_new(result, "type", json_string("unknown")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_lookup, finished_fail_missing_inode) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "mode", json_integer(0755)); + json_object_set_new(result, "type", json_string("file")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_lookup, finished_fail_invalid_inode_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "inode", json_string("42")); + json_object_set_new(result, "mode", json_string("0755")); + json_object_set_new(result, "type", json_string("file")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_lookup, finished_fail_missing_mode) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "inode", json_integer(42)); + json_object_set_new(result, "type", json_string("file")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_lookup, finished_fail_invalid_mode_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "inode", json_integer(42)); + json_object_set_new(result, "mode", json_string("0755")); + json_object_set_new(result, "type", json_string("file")); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_lookup, finished_fail_type_mode) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "inode", json_integer(42)); + json_object_set_new(result, "mode", json_integer(0755)); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_lookup, finished_fail_invalid_type_type) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * result = json_object(); + json_object_set_new(result, "inode", json_integer(42)); + json_object_set_new(result, "mode", json_integer(0755)); + json_object_set_new(result, "type", json_integer(42)); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, result, nullptr); + json_decref(result); +} + +TEST(wf_impl_operation_lookup, finished_error) +{ + FuseMock fuse; + EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0); + EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0)); + + json_t * error = json_object(); + json_object_set_new(error, "code", json_integer(WF_BAD)); + + auto * context = reinterpret_cast(malloc(sizeof(wf_impl_operation_lookup_context))); + context->timeout = 1.0; + context->gid = 0; + context->uid = 0; + wf_impl_operation_lookup_finished(context, nullptr, error); + json_decref(error); +} diff --git a/test/webfuse/tests/adapter/operation/test_open.cc b/test/webfuse/tests/adapter/operation/test_open.cc index f82e81e..9670985 100644 --- a/test/webfuse/tests/adapter/operation/test_open.cc +++ b/test/webfuse/tests/adapter/operation/test_open.cc @@ -1,5 +1,4 @@ #include "webfuse/adapter/impl/operation/open.h" -#include "webfuse/adapter/impl/operations.h" #include "webfuse/core/status.h" diff --git a/test/webfuse/tests/adapter/operation/test_read.cc b/test/webfuse/tests/adapter/operation/test_read.cc index 85fcf34..934d060 100644 --- a/test/webfuse/tests/adapter/operation/test_read.cc +++ b/test/webfuse/tests/adapter/operation/test_read.cc @@ -1,5 +1,4 @@ #include "webfuse/adapter/impl/operation/read.h" -#include "webfuse/adapter/impl/operations.h" #include "webfuse/mocks/mock_fuse.hpp" #include "webfuse/mocks/mock_operations_context.hpp" diff --git a/test/webfuse/tests/adapter/operation/test_readdir.cc b/test/webfuse/tests/adapter/operation/test_readdir.cc index 3ae9df2..2875eca 100644 --- a/test/webfuse/tests/adapter/operation/test_readdir.cc +++ b/test/webfuse/tests/adapter/operation/test_readdir.cc @@ -1,5 +1,4 @@ #include "webfuse/adapter/impl/operation/readdir.h" -#include "webfuse/adapter/impl/operations.h" #include "webfuse/core/status.h" From 49469c73e30183b7d3cff0892619fe6ef8d4331a Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 4 Apr 2020 23:27:34 +0200 Subject: [PATCH 40/43] renamed operation_context --- cmake/unit_tests.cmake | 4 +-- lib/webfuse/adapter/impl/filesystem.h | 2 +- lib/webfuse/adapter/impl/operation/close.c | 4 +-- lib/webfuse/adapter/impl/operation/context.c | 4 +-- lib/webfuse/adapter/impl/operation/context.h | 6 ++--- lib/webfuse/adapter/impl/operation/getattr.c | 4 +-- lib/webfuse/adapter/impl/operation/lookup.c | 4 +-- lib/webfuse/adapter/impl/operation/open.c | 4 +-- lib/webfuse/adapter/impl/operation/read.c | 4 +-- lib/webfuse/adapter/impl/operation/readdir.c | 4 +-- test/webfuse/mocks/mock_operation_context.cc | 27 +++++++++++++++++++ test/webfuse/mocks/mock_operation_context.hpp | 22 +++++++++++++++ test/webfuse/mocks/mock_operations_context.cc | 27 ------------------- .../webfuse/mocks/mock_operations_context.hpp | 22 --------------- .../tests/adapter/operation/test_close.cc | 14 +++++----- .../tests/adapter/operation/test_context.cc | 8 +++--- .../tests/adapter/operation/test_getattr.cc | 14 +++++----- .../tests/adapter/operation/test_lookup.cc | 14 +++++----- .../tests/adapter/operation/test_open.cc | 14 +++++----- .../tests/adapter/operation/test_read.cc | 20 +++++++------- .../tests/adapter/operation/test_readdir.cc | 14 +++++----- 21 files changed, 118 insertions(+), 118 deletions(-) create mode 100644 test/webfuse/mocks/mock_operation_context.cc create mode 100644 test/webfuse/mocks/mock_operation_context.hpp delete mode 100644 test/webfuse/mocks/mock_operations_context.cc delete mode 100644 test/webfuse/mocks/mock_operations_context.hpp diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index eaa8427..43b9598 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -31,7 +31,7 @@ add_executable(alltests test/webfuse/mocks/mock_provider_client.cc test/webfuse/mocks/mock_provider.cc test/webfuse/mocks/mock_fuse.cc - test/webfuse/mocks/mock_operations_context.cc + test/webfuse/mocks/mock_operation_context.cc test/webfuse/mocks/mock_jsonrpc_proxy.cc test/webfuse//tests/core/test_util.cc test/webfuse/tests/core/test_container_of.cc @@ -77,7 +77,7 @@ target_link_libraries(alltests PUBLIC -Wl,--wrap=wf_timer_dispose -Wl,--wrap=wf_timer_start -Wl,--wrap=wf_timer_cancel - -Wl,--wrap=wf_impl_operations_context_get_proxy + -Wl,--wrap=wf_impl_operation_context_get_proxy -Wl,--wrap=wf_jsonrpc_proxy_vinvoke -Wl,--wrap=wf_jsonrpc_proxy_vnotify -Wl,--wrap=fuse_req_userdata diff --git a/lib/webfuse/adapter/impl/filesystem.h b/lib/webfuse/adapter/impl/filesystem.h index 9ea6406..791170a 100644 --- a/lib/webfuse/adapter/impl/filesystem.h +++ b/lib/webfuse/adapter/impl/filesystem.h @@ -24,7 +24,7 @@ struct wf_impl_filesystem struct fuse_args args; struct fuse_session * session; struct fuse_buf buffer; - struct wf_impl_operations_context user_data; + struct wf_impl_operation_context user_data; struct lws * wsi; struct wf_mountpoint * mountpoint; }; diff --git a/lib/webfuse/adapter/impl/operation/close.c b/lib/webfuse/adapter/impl/operation/close.c index 5e3c4e8..62d1ec3 100644 --- a/lib/webfuse/adapter/impl/operation/close.c +++ b/lib/webfuse/adapter/impl/operation/close.c @@ -13,8 +13,8 @@ void wf_impl_operation_close( fuse_ino_t inode, struct fuse_file_info * file_info) { - struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct wf_impl_operation_context * user_data = fuse_req_userdata(request); + struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data); if (NULL != rpc) { diff --git a/lib/webfuse/adapter/impl/operation/context.c b/lib/webfuse/adapter/impl/operation/context.c index 1bde8b1..a39978f 100644 --- a/lib/webfuse/adapter/impl/operation/context.c +++ b/lib/webfuse/adapter/impl/operation/context.c @@ -3,8 +3,8 @@ #include "webfuse/adapter/impl/session.h" #include -struct wf_jsonrpc_proxy * wf_impl_operations_context_get_proxy( - struct wf_impl_operations_context * context) +struct wf_jsonrpc_proxy * wf_impl_operation_context_get_proxy( + struct wf_impl_operation_context * context) { struct wf_jsonrpc_proxy * proxy = NULL; diff --git a/lib/webfuse/adapter/impl/operation/context.h b/lib/webfuse/adapter/impl/operation/context.h index 17f5f81..51d886f 100644 --- a/lib/webfuse/adapter/impl/operation/context.h +++ b/lib/webfuse/adapter/impl/operation/context.h @@ -10,15 +10,15 @@ extern "C" { struct wf_impl_session; struct wf_jsonrpc_proxy; -struct wf_impl_operations_context +struct wf_impl_operation_context { struct wf_impl_session * session; double timeout; char * name; }; -extern struct wf_jsonrpc_proxy * wf_impl_operations_context_get_proxy( - struct wf_impl_operations_context * context); +extern struct wf_jsonrpc_proxy * wf_impl_operation_context_get_proxy( + struct wf_impl_operation_context * context); #ifdef __cplusplus } diff --git a/lib/webfuse/adapter/impl/operation/getattr.c b/lib/webfuse/adapter/impl/operation/getattr.c index 3c00840..8318dc2 100644 --- a/lib/webfuse/adapter/impl/operation/getattr.c +++ b/lib/webfuse/adapter/impl/operation/getattr.c @@ -73,8 +73,8 @@ void wf_impl_operation_getattr ( struct fuse_file_info * WF_UNUSED_PARAM(file_info)) { struct fuse_ctx const * context = fuse_req_ctx(request); - struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct wf_impl_operation_context * user_data = fuse_req_userdata(request); + struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data); if (NULL != rpc) { diff --git a/lib/webfuse/adapter/impl/operation/lookup.c b/lib/webfuse/adapter/impl/operation/lookup.c index ca778cd..4ebbe3c 100644 --- a/lib/webfuse/adapter/impl/operation/lookup.c +++ b/lib/webfuse/adapter/impl/operation/lookup.c @@ -84,8 +84,8 @@ void wf_impl_operation_lookup ( char const * name) { struct fuse_ctx const * context = fuse_req_ctx(request); - struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct wf_impl_operation_context * user_data = fuse_req_userdata(request); + struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data); if (NULL != rpc) { diff --git a/lib/webfuse/adapter/impl/operation/open.c b/lib/webfuse/adapter/impl/operation/open.c index 712f240..1b25d99 100644 --- a/lib/webfuse/adapter/impl/operation/open.c +++ b/lib/webfuse/adapter/impl/operation/open.c @@ -48,8 +48,8 @@ void wf_impl_operation_open( fuse_ino_t inode, struct fuse_file_info * file_info) { - struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct wf_impl_operation_context * user_data = fuse_req_userdata(request); + struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data); if (NULL != rpc) { diff --git a/lib/webfuse/adapter/impl/operation/read.c b/lib/webfuse/adapter/impl/operation/read.c index 81b6928..7e2e0f4 100644 --- a/lib/webfuse/adapter/impl/operation/read.c +++ b/lib/webfuse/adapter/impl/operation/read.c @@ -111,8 +111,8 @@ void wf_impl_operation_read( off_t offset, struct fuse_file_info * file_info) { - struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct wf_impl_operation_context * user_data = fuse_req_userdata(request); + struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data); if (NULL != rpc) { diff --git a/lib/webfuse/adapter/impl/operation/readdir.c b/lib/webfuse/adapter/impl/operation/readdir.c index 8022440..6d54636 100644 --- a/lib/webfuse/adapter/impl/operation/readdir.c +++ b/lib/webfuse/adapter/impl/operation/readdir.c @@ -141,8 +141,8 @@ void wf_impl_operation_readdir ( off_t offset, struct fuse_file_info * WF_UNUSED_PARAM(file_info)) { - struct wf_impl_operations_context * user_data = fuse_req_userdata(request); - struct wf_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data); + struct wf_impl_operation_context * user_data = fuse_req_userdata(request); + struct wf_jsonrpc_proxy * rpc = wf_impl_operation_context_get_proxy(user_data); if (NULL != rpc) { diff --git a/test/webfuse/mocks/mock_operation_context.cc b/test/webfuse/mocks/mock_operation_context.cc new file mode 100644 index 0000000..9537533 --- /dev/null +++ b/test/webfuse/mocks/mock_operation_context.cc @@ -0,0 +1,27 @@ +#include "webfuse/mocks/mock_operation_context.hpp" +#include "webfuse/utils/wrap.hpp" + +extern "C" +{ +static webfuse_test::MockOperationContext * webfuse_test_MockOperationContext = nullptr; + +WF_WRAP_FUNC1(webfuse_test_MockOperationContext, + struct wf_jsonrpc_proxy *, wf_impl_operation_context_get_proxy, + struct wf_impl_operation_context *); + +} + +namespace webfuse_test +{ + +MockOperationContext::MockOperationContext() +{ + webfuse_test_MockOperationContext = this; +} + +MockOperationContext::~MockOperationContext() +{ + webfuse_test_MockOperationContext = nullptr; +} + +} \ No newline at end of file diff --git a/test/webfuse/mocks/mock_operation_context.hpp b/test/webfuse/mocks/mock_operation_context.hpp new file mode 100644 index 0000000..e692e76 --- /dev/null +++ b/test/webfuse/mocks/mock_operation_context.hpp @@ -0,0 +1,22 @@ +#ifndef MOCK_OPERATIONS_CONTEXT_HPP +#define MOCK_OPERATIONS_CONTEXT_HPP + +#include "webfuse/adapter/impl/operation/context.h" +#include + +namespace webfuse_test +{ + +class MockOperationContext +{ +public: + MockOperationContext(); + virtual ~MockOperationContext(); + MOCK_METHOD1(wf_impl_operation_context_get_proxy, wf_jsonrpc_proxy * ( + struct wf_impl_operation_context * context)); + +}; + +} + +#endif diff --git a/test/webfuse/mocks/mock_operations_context.cc b/test/webfuse/mocks/mock_operations_context.cc deleted file mode 100644 index 89498f7..0000000 --- a/test/webfuse/mocks/mock_operations_context.cc +++ /dev/null @@ -1,27 +0,0 @@ -#include "webfuse/mocks/mock_operations_context.hpp" -#include "webfuse/utils/wrap.hpp" - -extern "C" -{ -static webfuse_test::MockOperationsContext * webfuse_test_MockOperationsContext = nullptr; - -WF_WRAP_FUNC1(webfuse_test_MockOperationsContext, - struct wf_jsonrpc_proxy *, wf_impl_operations_context_get_proxy, - struct wf_impl_operations_context *); - -} - -namespace webfuse_test -{ - -MockOperationsContext::MockOperationsContext() -{ - webfuse_test_MockOperationsContext = this; -} - -MockOperationsContext::~MockOperationsContext() -{ - webfuse_test_MockOperationsContext = nullptr; -} - -} \ No newline at end of file diff --git a/test/webfuse/mocks/mock_operations_context.hpp b/test/webfuse/mocks/mock_operations_context.hpp deleted file mode 100644 index 1dee54c..0000000 --- a/test/webfuse/mocks/mock_operations_context.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef MOCK_OPERATIONS_CONTEXT_HPP -#define MOCK_OPERATIONS_CONTEXT_HPP - -#include "webfuse/adapter/impl/operation/context.h" -#include - -namespace webfuse_test -{ - -class MockOperationsContext -{ -public: - MockOperationsContext(); - virtual ~MockOperationsContext(); - MOCK_METHOD1(wf_impl_operations_context_get_proxy, wf_jsonrpc_proxy * ( - struct wf_impl_operations_context * context)); - -}; - -} - -#endif diff --git a/test/webfuse/tests/adapter/operation/test_close.cc b/test/webfuse/tests/adapter/operation/test_close.cc index 885e3bb..00e4763 100644 --- a/test/webfuse/tests/adapter/operation/test_close.cc +++ b/test/webfuse/tests/adapter/operation/test_close.cc @@ -2,13 +2,13 @@ #include #include "webfuse/mocks/mock_fuse.hpp" -#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/mocks/mock_operation_context.hpp" #include "webfuse/mocks/mock_jsonrpc_proxy.hpp" #include using webfuse_test::MockJsonRpcProxy; -using webfuse_test::MockOperationsContext; +using webfuse_test::MockOperationContext; using webfuse_test::FuseMock; using testing::_; using testing::Return; @@ -19,11 +19,11 @@ 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) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(reinterpret_cast(&proxy))); - wf_impl_operations_context op_context; + wf_impl_operation_context op_context; op_context.name = nullptr; FuseMock fuse; EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); @@ -41,8 +41,8 @@ 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) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(nullptr)); FuseMock fuse; diff --git a/test/webfuse/tests/adapter/operation/test_context.cc b/test/webfuse/tests/adapter/operation/test_context.cc index bd53241..77aa287 100644 --- a/test/webfuse/tests/adapter/operation/test_context.cc +++ b/test/webfuse/tests/adapter/operation/test_context.cc @@ -7,17 +7,17 @@ TEST(wf_impl_operation_context, get_proxy) wf_jsonrpc_proxy * proxy = reinterpret_cast(42); wf_impl_session session; session.rpc = proxy; - wf_impl_operations_context context; + wf_impl_operation_context context; context.session = &session; - ASSERT_EQ(proxy, wf_impl_operations_context_get_proxy(&context)); + ASSERT_EQ(proxy, wf_impl_operation_context_get_proxy(&context)); } TEST(wf_impl_operation_context, get_proxy_fail_no_session) { - wf_impl_operations_context context; + wf_impl_operation_context context; context.session = nullptr; - ASSERT_EQ(nullptr, wf_impl_operations_context_get_proxy(&context)); + ASSERT_EQ(nullptr, wf_impl_operation_context_get_proxy(&context)); } \ No newline at end of file diff --git a/test/webfuse/tests/adapter/operation/test_getattr.cc b/test/webfuse/tests/adapter/operation/test_getattr.cc index 4dc0081..8249692 100644 --- a/test/webfuse/tests/adapter/operation/test_getattr.cc +++ b/test/webfuse/tests/adapter/operation/test_getattr.cc @@ -3,13 +3,13 @@ #include "webfuse/core/status.h" #include "webfuse/mocks/mock_fuse.hpp" -#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/mocks/mock_operation_context.hpp" #include "webfuse/mocks/mock_jsonrpc_proxy.hpp" #include using webfuse_test::MockJsonRpcProxy; -using webfuse_test::MockOperationsContext; +using webfuse_test::MockOperationContext; using webfuse_test::FuseMock; using testing::_; using testing::Return; @@ -37,11 +37,11 @@ TEST(wf_impl_operation_getattr, invoke_proxy) EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("getattr"),StrEq("si"))).Times(1) .WillOnce(Invoke(free_context)); - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(reinterpret_cast(&proxy))); - wf_impl_operations_context op_context; + wf_impl_operation_context op_context; op_context.name = nullptr; fuse_ctx fuse_context; fuse_context.gid = 0; @@ -59,8 +59,8 @@ TEST(wf_impl_operation_getattr, invoke_proxy) TEST(wf_impl_operation_getattr, fail_rpc_null) { - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(nullptr)); FuseMock fuse; diff --git a/test/webfuse/tests/adapter/operation/test_lookup.cc b/test/webfuse/tests/adapter/operation/test_lookup.cc index 73c5774..002fc30 100644 --- a/test/webfuse/tests/adapter/operation/test_lookup.cc +++ b/test/webfuse/tests/adapter/operation/test_lookup.cc @@ -3,13 +3,13 @@ #include "webfuse/core/status.h" #include "webfuse/mocks/mock_fuse.hpp" -#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/mocks/mock_operation_context.hpp" #include "webfuse/mocks/mock_jsonrpc_proxy.hpp" #include using webfuse_test::MockJsonRpcProxy; -using webfuse_test::MockOperationsContext; +using webfuse_test::MockOperationContext; using webfuse_test::FuseMock; using testing::_; using testing::Return; @@ -37,11 +37,11 @@ TEST(wf_impl_operation_lookup, invoke_proxy) EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("lookup"),StrEq("sis"))).Times(1) .WillOnce(Invoke(free_context)); - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(reinterpret_cast(&proxy))); - wf_impl_operations_context op_context; + wf_impl_operation_context op_context; op_context.name = nullptr; fuse_ctx fuse_context; fuse_context.gid = 0; @@ -58,8 +58,8 @@ TEST(wf_impl_operation_lookup, invoke_proxy) TEST(wf_impl_operation_lookup, fail_rpc_null) { - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(nullptr)); FuseMock fuse; diff --git a/test/webfuse/tests/adapter/operation/test_open.cc b/test/webfuse/tests/adapter/operation/test_open.cc index 9670985..e3d89bc 100644 --- a/test/webfuse/tests/adapter/operation/test_open.cc +++ b/test/webfuse/tests/adapter/operation/test_open.cc @@ -3,13 +3,13 @@ #include "webfuse/core/status.h" #include "webfuse/mocks/mock_fuse.hpp" -#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/mocks/mock_operation_context.hpp" #include "webfuse/mocks/mock_jsonrpc_proxy.hpp" #include using webfuse_test::MockJsonRpcProxy; -using webfuse_test::MockOperationsContext; +using webfuse_test::MockOperationContext; using webfuse_test::FuseMock; using testing::_; using testing::Return; @@ -20,11 +20,11 @@ TEST(wf_impl_operation_open, invoke_proxy) MockJsonRpcProxy proxy; EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("open"),StrEq("sii"))).Times(1); - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(reinterpret_cast(&proxy))); - wf_impl_operations_context op_context; + wf_impl_operation_context op_context; op_context.name = nullptr; FuseMock fuse; EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); @@ -39,8 +39,8 @@ TEST(wf_impl_operation_open, invoke_proxy) TEST(wf_impl_operation_open, fail_rpc_null) { - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(nullptr)); FuseMock fuse; diff --git a/test/webfuse/tests/adapter/operation/test_read.cc b/test/webfuse/tests/adapter/operation/test_read.cc index 934d060..15b9f9c 100644 --- a/test/webfuse/tests/adapter/operation/test_read.cc +++ b/test/webfuse/tests/adapter/operation/test_read.cc @@ -1,13 +1,13 @@ #include "webfuse/adapter/impl/operation/read.h" #include "webfuse/mocks/mock_fuse.hpp" -#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/mocks/mock_operation_context.hpp" #include "webfuse/mocks/mock_jsonrpc_proxy.hpp" #include using webfuse_test::MockJsonRpcProxy; -using webfuse_test::MockOperationsContext; +using webfuse_test::MockOperationContext; using webfuse_test::FuseMock; using testing::_; using testing::Return; @@ -18,11 +18,11 @@ TEST(wf_impl_operation_read, invoke_proxy) MockJsonRpcProxy proxy; EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("read"),StrEq("siiii"))).Times(1); - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(reinterpret_cast(&proxy))); - wf_impl_operations_context op_context; + wf_impl_operation_context op_context; op_context.name = nullptr; FuseMock fuse; EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); @@ -41,11 +41,11 @@ TEST(wf_impl_operation_read, invoke_proxy_limit_size) MockJsonRpcProxy proxy; EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("read"),StrEq("siiii"))).Times(1); - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(reinterpret_cast(&proxy))); - wf_impl_operations_context op_context; + wf_impl_operation_context op_context; op_context.name = nullptr; FuseMock fuse; EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); @@ -61,8 +61,8 @@ TEST(wf_impl_operation_read, invoke_proxy_limit_size) TEST(wf_impl_operation_read, fail_rpc_null) { - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(nullptr)); FuseMock fuse; diff --git a/test/webfuse/tests/adapter/operation/test_readdir.cc b/test/webfuse/tests/adapter/operation/test_readdir.cc index 2875eca..c020c3d 100644 --- a/test/webfuse/tests/adapter/operation/test_readdir.cc +++ b/test/webfuse/tests/adapter/operation/test_readdir.cc @@ -3,13 +3,13 @@ #include "webfuse/core/status.h" #include "webfuse/mocks/mock_fuse.hpp" -#include "webfuse/mocks/mock_operations_context.hpp" +#include "webfuse/mocks/mock_operation_context.hpp" #include "webfuse/mocks/mock_jsonrpc_proxy.hpp" #include using webfuse_test::MockJsonRpcProxy; -using webfuse_test::MockOperationsContext; +using webfuse_test::MockOperationContext; using webfuse_test::FuseMock; using testing::_; using testing::Return; @@ -37,11 +37,11 @@ TEST(wf_impl_operation_readdir, invoke_proxy) EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("readdir"),StrEq("si"))) .Times(1).WillOnce(Invoke(free_context)); - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(reinterpret_cast(&proxy))); - wf_impl_operations_context op_context; + wf_impl_operation_context op_context; op_context.name = nullptr; FuseMock fuse; EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context)); @@ -58,8 +58,8 @@ TEST(wf_impl_operation_readdir, invoke_proxy) TEST(wf_impl_operation_readdir, fail_rpc_null) { - MockOperationsContext context; - EXPECT_CALL(context, wf_impl_operations_context_get_proxy(_)).Times(1) + MockOperationContext context; + EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1) .WillOnce(Return(nullptr)); FuseMock fuse; From 810702c5a71f95fd1cc81a2374917010a3c4be55 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 5 Apr 2020 15:09:15 +0200 Subject: [PATCH 41/43] fixed memory leak --- lib/webfuse/provider/impl/client.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/webfuse/provider/impl/client.c b/lib/webfuse/provider/impl/client.c index f10450f..9f45a5a 100644 --- a/lib/webfuse/provider/impl/client.c +++ b/lib/webfuse/provider/impl/client.c @@ -43,14 +43,21 @@ struct wfp_client * wfp_impl_client_create( if ((NULL != config->cert_path) && (NULL != config->key_path)) { + client->info.options |= LWS_SERVER_OPTION_EXPLICIT_VHOSTS; + } + + client->context = lws_create_context(&client->info); + + if ((NULL != config->cert_path) && (NULL != config->key_path)) + { + struct lws_vhost * vhost = lws_create_vhost(client->context, &client->info); client->info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; client->info.client_ssl_cert_filepath = config->cert_path; client->info.client_ssl_private_key_filepath = config->key_path; client->info.client_ssl_ca_filepath = config->ca_filepath; + lws_init_vhost_client_ssl(&client->info, vhost); } - client->context = lws_create_context(&client->info); - return client; } From ac855a73c8651b18b37402b2ec2755dec9c103e2 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 5 Apr 2020 17:08:33 +0200 Subject: [PATCH 42/43] fix: make ctest fail on memcheck errors --- cmake/unit_tests.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 43b9598..00870d9 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -1,5 +1,6 @@ if(NOT WITHOUT_TESTS AND NOT WITHOUT_ADAPTER AND NOT WITHOUT_PROVIDER) +set(MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --error-exitcode=1") include (CTest) pkg_check_modules(GTEST gtest_main) From 7cea9828cb05be7b2e9a40ddca4b15338cbcac2f Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 5 Apr 2020 20:11:07 +0200 Subject: [PATCH 43/43] replaces death tests by popen --- cmake/unit_tests.cmake | 6 +- test/webfuse/tests/integration/file.cc | 85 ++++++ test/webfuse/tests/integration/file.hpp | 26 ++ test/webfuse/tests/integration/fs_check.c | 288 ++++++++++++++++++ .../tests/integration/test_integration.cc | 87 +----- test/webfuse/utils/die_if.cc | 15 - test/webfuse/utils/die_if.hpp | 11 - 7 files changed, 418 insertions(+), 100 deletions(-) create mode 100644 test/webfuse/tests/integration/file.cc create mode 100644 test/webfuse/tests/integration/file.hpp create mode 100644 test/webfuse/tests/integration/fs_check.c delete mode 100644 test/webfuse/utils/die_if.cc delete mode 100644 test/webfuse/utils/die_if.hpp diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 00870d9..60023ee 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -3,6 +3,10 @@ if(NOT WITHOUT_TESTS AND NOT WITHOUT_ADAPTER AND NOT WITHOUT_PROVIDER) set(MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --error-exitcode=1") include (CTest) +add_executable(fs_check + test/webfuse/tests/integration/fs_check.c +) + pkg_check_modules(GTEST gtest_main) include(GoogleTest) pkg_check_modules(GMOCK gmock) @@ -21,7 +25,6 @@ add_executable(alltests test/webfuse/tests/core/timer/test_timer.cc test/webfuse/utils/tempdir.cc test/webfuse/utils/file_utils.cc - test/webfuse/utils/die_if.cc test/webfuse/utils/timeout_watcher.cc test/webfuse/utils/path.c test/webfuse/utils/static_filesystem.c @@ -66,6 +69,7 @@ add_executable(alltests test/webfuse/tests/provider/operation/test_readdir.cc test/webfuse/tests/integration/test_lowlevel.cc test/webfuse/tests/integration/test_integration.cc + test/webfuse/tests/integration/file.cc test/webfuse/tests/integration/server.cc test/webfuse/tests/integration/provider.cc ) diff --git a/test/webfuse/tests/integration/file.cc b/test/webfuse/tests/integration/file.cc new file mode 100644 index 0000000..5719382 --- /dev/null +++ b/test/webfuse/tests/integration/file.cc @@ -0,0 +1,85 @@ +#include "webfuse/tests/integration/file.hpp" +#include +#include + +namespace +{ + +bool invoke(std::string const & command) +{ + int exit_code = -1; + + FILE * file = ::popen(command.c_str(), "r"); + if (nullptr != file) + { + exit_code = ::pclose(file); + } + + return (0 == exit_code); +} + +} + +namespace webfuse_test +{ + +File::File(std::string const& path) +: path_(path) +{ + +} + +File::~File() +{ + +} + +bool File::isFile() +{ + std::stringstream command; + command << "./fs_check -c is_file -f " << path_; + + return invoke(command.str()); +} + +bool File::isDirectory() +{ + std::stringstream command; + command << "./fs_check -c is_dir -f " << path_; + + return invoke(command.str()); +} + +bool File::hasAccessRights(int accessRights) +{ + std::stringstream command; + command << "./fs_check -c has_mode -f " << path_ << " -a " << accessRights; + + return invoke(command.str()); +} + +bool File::hasSize(size_t size) +{ + std::stringstream command; + command << "./fs_check -c has_size -f " << path_ << " -a " << size; + + return invoke(command.str()); +} + +bool File::hasSubdirectory(std::string const & subdir) +{ + std::stringstream command; + command << "./fs_check -c has_subdir -f " << path_ << " -a " << subdir; + + return invoke(command.str()); +} + +bool File::hasContents(std::string const & contents) +{ + std::stringstream command; + command << "./fs_check -c has_contents -f " << path_ << " -a " << contents; + + return invoke(command.str()); +} + +} \ No newline at end of file diff --git a/test/webfuse/tests/integration/file.hpp b/test/webfuse/tests/integration/file.hpp new file mode 100644 index 0000000..e36e6ce --- /dev/null +++ b/test/webfuse/tests/integration/file.hpp @@ -0,0 +1,26 @@ +#ifndef WF_TEST_INTEGRATION_FILE_HPP +#define WF_TEST_INTEGRATION_FILE_HPP + +#include + +namespace webfuse_test +{ + +class File final +{ +public: + explicit File(std::string const& path); + ~File(); + bool isFile(); + bool isDirectory(); + bool hasAccessRights(int accessRights); + bool hasSize(size_t size); + bool hasSubdirectory(std::string const & subdir); + bool hasContents(std::string const & contents); +private: + std::string path_; +}; + +} + +#endif diff --git a/test/webfuse/tests/integration/fs_check.c b/test/webfuse/tests/integration/fs_check.c new file mode 100644 index 0000000..55d24c4 --- /dev/null +++ b/test/webfuse/tests/integration/fs_check.c @@ -0,0 +1,288 @@ +/* Why this tool is used: + * + * In order to test webfuse as a fuse filesystem, file system operations should be made. + * To check for memory leaks, valgind (memcheck) is used. + * + * Early tests discovered some ugly behavior of valgrind: + * - valgrind intercepts syscalls like open, read and write + * - valgrind does not expect that syscalls are handled within the process to be checked + * + * There is a more or less (un-) documented switch, which changes valgrind's bevahior, but + * this caused other problems. + * + * The second approach used GTests's death tests. Death tests were used quite a while, + * until we discovered a configuration bug when running CTest: + * - memory leaks did not lead to test error + * + * After fixing CTest configuration, memory leaks within the death tests were shown. + * Which is correct, since death tests pematurely exits the program an therefore no + * cleanup is done. + * + * Finally, it was decided to use good old popen together with this tool. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +struct command; + +typedef bool +command_invoke_fn( + struct command * command); + +struct command +{ + command_invoke_fn * invoke; + char * file; + char * arg; + bool success; + bool has_arg; +}; + +static bool print_usage( + struct command * command) +{ + printf( + "fs_check, (c) 2020 by Webfuse authors (https://github.com/falk-werner/webfuse)\n" + "Checks file information\n" + "\n" + "Usage:\n" + "\t./fs_check --command --file [--arg ]\n" + "\n" + "Options:\n" + "\t-c, --command - Check to perform (see below)\n" + "\t-f, --file - Path to file to check\n" + "\t-a, --arg - Argument, depending on command\n" + "\n" + "Commands:\n" + "\tis_file - checks, if is a regular file; no arg\n" + "\tis_dir - checks, if is a directory; no arg\n" + "\thas_mode - checks, if has the mode given in \n" + "\thas_size - checks, if has the size given in \n" + "\thas_subdir - checks, if contains the sub directory given in \n" + "\thas_contents - checks, if has the contents given in \n" + ); + + return command->success; +} + +static bool is_file( + struct command * command) +{ + struct stat buffer; + int rc = stat(command->file, &buffer); + + return ((0 == rc) && (S_ISREG(buffer.st_mode))); +} + +static bool is_dir( + struct command * command) +{ + struct stat buffer; + int rc = stat(command->file, &buffer); + + return ((0 == rc) && (S_ISDIR(buffer.st_mode))); +} + +static bool has_mode( + struct command * command) +{ + mode_t mode = (mode_t) atoi(command->arg); + struct stat buffer; + int rc = stat(command->file, &buffer); + + return ((0 == rc) && (mode == (buffer.st_mode & 0777))); +} + +static bool has_size( + struct command * command) +{ + int size = atoi(command->arg); + struct stat buffer; + int rc = stat(command->file, &buffer); + + return ((0 == rc) && (size == (buffer.st_size))); +} + +static bool has_subdir( + struct command * command) +{ + bool result = false; + char const * subdir = command->arg; + DIR * dir = opendir(command->file); + if (NULL != dir) + { + struct dirent * entry = readdir(dir); + while (NULL != entry) + { + if (0 == strcmp(subdir, entry->d_name)) + { + result = true; + break; + } + + entry = readdir(dir); + } + + closedir(dir); + } + + return result; +} + +static bool has_contents( + struct command * command) +{ + bool result = false; + char const * contents = command->arg; + size_t length = strlen(contents); + + char * buffer = malloc(length); + FILE * file = fopen(command->file, "rb"); + { + ssize_t count = fread(buffer, 1, length, file); + fclose(file); + + result = (count == (ssize_t) length) && (0 == strncmp(buffer, contents, length)); + } + + free(buffer); + return result; +} + +static bool get_command( + struct command * command, + char const * name) +{ + static struct { + char const * name; + command_invoke_fn * invoke; + bool has_arg; + } commands[] = + { + {"is_file" , &is_file , false}, + {"is_dir" , &is_dir , false}, + {"has_mode" , &has_mode , true}, + {"has_size" , &has_size , true}, + {"has_subdir" , &has_subdir , true}, + {"has_contents", &has_contents, true}, + {NULL, NULL, false} + }; + + for (int i = 0; NULL != commands[i].name; i++) + { + if (0 == strcmp(commands[i].name, name)) + { + command->invoke = commands[i].invoke; + command->has_arg = commands[i].has_arg; + return true; + } + } + + return false; +} + +static void command_init( + struct command * command, + int argc, + char * argv[]) +{ + static struct option const options[] = + { + {"file" , required_argument, NULL, 'f'}, + {"command", required_argument, NULL, 'c'}, + {"arg" , required_argument, NULL, 'a'}, + {"help" , no_argument , NULL, 'h'}, + {NULL, 0, NULL, 0} + }; + + command->invoke = &print_usage; + command->file = NULL; + command->arg = NULL; + command->success = true; + command->has_arg = false; + + optind = 0; + bool is_finished = false; + while (!is_finished) + { + int option_index = 0; + int const c = getopt_long(argc, argv, "f:c:a:h", options, &option_index); + + switch(c) + { + case -1: + is_finished = true; + break; + case 'c': + if (!get_command(command, optarg)) + { + fprintf(stderr, "error: unknown command\n"); + command->invoke = &print_usage; + command->success = false; + is_finished = true; + } + break; + case 'f': + free(command->file); + command->file = strdup(optarg); + break; + case 'a': + free(command->arg); + command->arg = strdup(optarg); + break; + case 'h': + command->invoke = &print_usage; + break; + default: + fprintf(stderr, "error: unknown argument\n"); + command->invoke = &print_usage; + command->success = false; + is_finished = true; + break; + } + } + + if (command->success) + { + if (NULL == command->file) + { + fprintf(stderr, "error: missing required arg: -f\n"); + command->invoke = &print_usage; + command->success = false; + } + else if ((command->has_arg) && (NULL == command->arg)) + { + fprintf(stderr, "error: missing required arg: -a\n"); + command->invoke = &print_usage; + command->success = false; + } + } +} + +static void command_cleanup( + struct command * command) +{ + free(command->file); + free(command->arg); +} + +int main(int argc, char* argv[]) +{ + struct command command; + command_init(&command, argc, argv); + + bool success = command.invoke(&command); + + command_cleanup(&command); + return success ? EXIT_SUCCESS : EXIT_FAILURE; +} \ No newline at end of file diff --git a/test/webfuse/tests/integration/test_integration.cc b/test/webfuse/tests/integration/test_integration.cc index 57c1a91..e7e8215 100644 --- a/test/webfuse/tests/integration/test_integration.cc +++ b/test/webfuse/tests/integration/test_integration.cc @@ -1,6 +1,7 @@ #include #include "webfuse/tests/integration/server.hpp" #include "webfuse/tests/integration/provider.hpp" +#include "webfuse/tests/integration/file.hpp" #include #include @@ -15,11 +16,10 @@ #include #include "webfuse/core/lws_log.h" -#include "webfuse/utils/die_if.hpp" using webfuse_test::Server; using webfuse_test::Provider; -using webfuse_test::die_if; +using webfuse_test::File; namespace { @@ -70,87 +70,28 @@ TEST_F(IntegrationTest, ProvidesTextFile) { std::string file_name = std::string(GetBaseDir()) + "/cprovider/hello.txt"; - ASSERT_EXIT({ - struct stat buffer; - int rc = stat(file_name.c_str(), &buffer); - - die_if(0 != rc); - die_if(!S_ISREG(buffer.st_mode)); - die_if(0444 != (buffer.st_mode & 0777)); - die_if(12 != buffer.st_size); - - exit(0); - }, ::testing::ExitedWithCode(0), ".*"); + File file(file_name); + ASSERT_TRUE(file.isFile()); + ASSERT_TRUE(file.hasAccessRights(0444)); + ASSERT_TRUE(file.hasSize(12)); } TEST_F(IntegrationTest, ReadTextFile) { std::string file_name = std::string(GetBaseDir()) + "/cprovider/hello.txt"; - ASSERT_EXIT({ - FILE * file = fopen(file_name.c_str(), "rb"); - die_if(nullptr == file); - - char buffer[13]; - ssize_t count = fread(buffer, 1, 12, file); - int rc = fclose(file); - - die_if(12 != count); - die_if(0 != strncmp("Hello, World", buffer, 12)); - die_if(0 != rc); - - exit(0); - }, ::testing::ExitedWithCode(0), ".*"); - + File file(file_name); + ASSERT_TRUE(file.hasContents("Hello, World")); } TEST_F(IntegrationTest, ReadDir) { std::string dir_name = std::string(GetBaseDir()) + "/cprovider"; - ASSERT_EXIT({ - - DIR * dir = opendir(dir_name.c_str()); - die_if(nullptr == dir); - - bool found_self = false; - bool found_parent = false; - bool found_hello_txt = false; - bool found_other = false; - - dirent * entry = readdir(dir); - while (NULL != entry) - { - if (0 == strcmp(".", entry->d_name)) - { - found_self = true; - } - else if (0 == strcmp("..", entry->d_name)) - { - found_parent = true; - } - else if (0 == strcmp("hello.txt", entry->d_name)) - { - found_hello_txt = true; - } - else - { - found_other = true; - } - - - entry = readdir(dir); - } - - closedir(dir); - - die_if(!found_self); - die_if(!found_parent); - die_if(!found_hello_txt); - - die_if(found_other); - - exit(0); - }, ::testing::ExitedWithCode(0), ".*"); - + File dir(dir_name); + ASSERT_TRUE(dir.isDirectory()); + ASSERT_TRUE(dir.hasSubdirectory(".")); + ASSERT_TRUE(dir.hasSubdirectory("..")); + ASSERT_TRUE(dir.hasSubdirectory("hello.txt")); + ASSERT_FALSE(dir.hasSubdirectory("other")); } \ No newline at end of file diff --git a/test/webfuse/utils/die_if.cc b/test/webfuse/utils/die_if.cc deleted file mode 100644 index bd8dd70..0000000 --- a/test/webfuse/utils/die_if.cc +++ /dev/null @@ -1,15 +0,0 @@ -#include "webfuse/utils/die_if.hpp" -#include - -namespace webfuse_test -{ - -void die_if(bool expression) -{ - if (expression) - { - exit(EXIT_FAILURE); - } -} - -} \ No newline at end of file diff --git a/test/webfuse/utils/die_if.hpp b/test/webfuse/utils/die_if.hpp deleted file mode 100644 index 95d3ff2..0000000 --- a/test/webfuse/utils/die_if.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef WF_TEST_DIE_IF_HPP -#define WF_TEST_DIE_IF_HPP - -namespace webfuse_test -{ - -extern void die_if(bool expression); - -} - -#endif