From a27e68f5a60d605d5bbe46b42bb5b634225564bc Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Thu, 20 Feb 2020 17:15:13 +0100 Subject: [PATCH 01/16] organized unit tests --- cmake/unit_tests.cmake | 82 +++++++++---------- .../fakes}/fake_adapter_server.cc | 4 +- .../fakes}/fake_adapter_server.hpp | 0 .../{ => webfuse/mocks}/mock_authenticator.cc | 2 +- .../mocks}/mock_authenticator.hpp | 0 test/{ => webfuse/mocks}/mock_request.cc | 2 +- test/{ => webfuse/mocks}/mock_request.hpp | 0 .../tests}/adapter/jsonrpc/test_is_request.cc | 0 .../adapter/jsonrpc/test_is_response.cc | 0 .../tests}/adapter/jsonrpc/test_proxy.cc | 2 +- .../tests}/adapter/jsonrpc/test_request.cc | 0 .../tests}/adapter/jsonrpc/test_response.cc | 0 .../tests}/adapter/jsonrpc/test_server.cc | 0 .../tests}/adapter/jsonrpc/test_util.cc | 0 .../tests}/adapter/test_authenticator.cc | 2 +- .../tests}/adapter/test_authenticators.cc | 2 +- .../tests}/adapter/test_credentials.cc | 0 .../tests}/adapter/test_fuse_req.cc | 0 .../tests}/adapter/test_mountpoint.cc | 0 .../tests}/adapter/test_response_parser.cc | 0 .../tests}/adapter/test_server.cc | 0 .../tests}/adapter/test_server_config.cc | 2 +- .../tests}/adapter/test_timepoint.cc | 2 +- .../{ => webfuse/tests}/adapter/test_timer.cc | 2 +- .../tests}/adapter/test_uuid_mountpoint.cc | 4 +- .../adapter/test_uuid_mountpoint_factory.cc | 4 +- test/{ => webfuse/tests}/core/test_base64.cc | 0 .../tests}/core/test_container_of.cc | 0 test/{ => webfuse/tests}/core/test_message.cc | 0 .../tests}/core/test_message_queue.cc | 0 test/{ => webfuse/tests}/core/test_path.cc | 0 test/{ => webfuse/tests}/core/test_slist.cc | 0 test/{ => webfuse/tests}/core/test_status.cc | 0 test/{ => webfuse/tests}/core/test_string.cc | 0 .../tests}/integration/provider.cc | 4 +- .../tests}/integration/provider.hpp | 0 .../{ => webfuse/tests}/integration/server.cc | 4 +- .../tests}/integration/server.hpp | 0 .../tests}/integration/test_integration.cc | 6 +- .../tests}/provider/test_client_protocol.cc | 2 +- .../tests}/provider/test_static_filesystem.cc | 2 +- test/{ => webfuse/tests}/provider/test_url.cc | 0 test/{ => webfuse/utils}/die_if.cc | 2 +- test/{ => webfuse/utils}/die_if.hpp | 0 test/{ => webfuse/utils}/file_utils.cc | 2 +- test/{ => webfuse/utils}/file_utils.hpp | 0 test/{ => webfuse/utils}/msleep.cc | 2 +- test/{ => webfuse/utils}/msleep.hpp | 0 test/{ => webfuse/utils}/tempdir.cc | 2 +- test/{ => webfuse/utils}/tempdir.hpp | 0 test/{ => webfuse/utils}/timeout_watcher.cc | 2 +- test/{ => webfuse/utils}/timeout_watcher.hpp | 0 52 files changed, 69 insertions(+), 69 deletions(-) rename test/{ => webfuse/fakes}/fake_adapter_server.cc (97%) rename test/{ => webfuse/fakes}/fake_adapter_server.hpp (100%) rename test/{ => webfuse/mocks}/mock_authenticator.cc (94%) rename test/{ => webfuse/mocks}/mock_authenticator.hpp (100%) rename test/{ => webfuse/mocks}/mock_request.cc (95%) rename test/{ => webfuse/mocks}/mock_request.hpp (100%) rename test/{ => webfuse/tests}/adapter/jsonrpc/test_is_request.cc (100%) rename test/{ => webfuse/tests}/adapter/jsonrpc/test_is_response.cc (100%) rename test/{ => webfuse/tests}/adapter/jsonrpc/test_proxy.cc (99%) rename test/{ => webfuse/tests}/adapter/jsonrpc/test_request.cc (100%) rename test/{ => webfuse/tests}/adapter/jsonrpc/test_response.cc (100%) rename test/{ => webfuse/tests}/adapter/jsonrpc/test_server.cc (100%) rename test/{ => webfuse/tests}/adapter/jsonrpc/test_util.cc (100%) rename test/{ => webfuse/tests}/adapter/test_authenticator.cc (97%) rename test/{ => webfuse/tests}/adapter/test_authenticators.cc (99%) rename test/{ => webfuse/tests}/adapter/test_credentials.cc (100%) rename test/{ => webfuse/tests}/adapter/test_fuse_req.cc (100%) rename test/{ => webfuse/tests}/adapter/test_mountpoint.cc (100%) rename test/{ => webfuse/tests}/adapter/test_response_parser.cc (100%) rename test/{ => webfuse/tests}/adapter/test_server.cc (100%) rename test/{ => webfuse/tests}/adapter/test_server_config.cc (99%) rename test/{ => webfuse/tests}/adapter/test_timepoint.cc (95%) rename test/{ => webfuse/tests}/adapter/test_timer.cc (99%) rename test/{ => webfuse/tests}/adapter/test_uuid_mountpoint.cc (96%) rename test/{ => webfuse/tests}/adapter/test_uuid_mountpoint_factory.cc (96%) rename test/{ => webfuse/tests}/core/test_base64.cc (100%) rename test/{ => webfuse/tests}/core/test_container_of.cc (100%) rename test/{ => webfuse/tests}/core/test_message.cc (100%) rename test/{ => webfuse/tests}/core/test_message_queue.cc (100%) rename test/{ => webfuse/tests}/core/test_path.cc (100%) rename test/{ => webfuse/tests}/core/test_slist.cc (100%) rename test/{ => webfuse/tests}/core/test_status.cc (100%) rename test/{ => webfuse/tests}/core/test_string.cc (100%) rename test/{ => webfuse/tests}/integration/provider.cc (95%) rename test/{ => webfuse/tests}/integration/provider.hpp (100%) rename test/{ => webfuse/tests}/integration/server.cc (95%) rename test/{ => webfuse/tests}/integration/server.hpp (100%) rename test/{ => webfuse/tests}/integration/test_integration.cc (96%) rename test/{ => webfuse/tests}/provider/test_client_protocol.cc (96%) rename test/{ => webfuse/tests}/provider/test_static_filesystem.cc (98%) rename test/{ => webfuse/tests}/provider/test_url.cc (100%) rename test/{ => webfuse/utils}/die_if.cc (79%) rename test/{ => webfuse/utils}/die_if.hpp (100%) rename test/{ => webfuse/utils}/file_utils.cc (94%) rename test/{ => webfuse/utils}/file_utils.hpp (100%) rename test/{ => webfuse/utils}/msleep.cc (90%) rename test/{ => webfuse/utils}/msleep.hpp (100%) rename test/{ => webfuse/utils}/tempdir.cc (92%) rename test/{ => webfuse/utils}/tempdir.hpp (100%) rename test/{ => webfuse/utils}/timeout_watcher.cc (93%) rename test/{ => webfuse/utils}/timeout_watcher.hpp (100%) diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index c4f779e..14ff04d 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -7,47 +7,47 @@ include(GoogleTest) pkg_check_modules(GMOCK gmock) add_executable(alltests - test/tempdir.cc - test/file_utils.cc - test/msleep.cc - test/die_if.cc - test/timeout_watcher.cc - test/fake_adapter_server.cc - test/mock_authenticator.cc - test/mock_request.cc - test/core/test_container_of.cc - test/core/test_string.cc - test/core/test_slist.cc - test/core/test_path.cc - test/core/test_base64.cc - test/core/test_status.cc - test/core/test_message.cc - test/core/test_message_queue.cc - test/adapter/test_response_parser.cc - test/adapter/test_server.cc - test/adapter/test_server_config.cc - test/adapter/test_timepoint.cc - test/adapter/test_timer.cc - test/adapter/test_credentials.cc - test/adapter/test_authenticator.cc - test/adapter/test_authenticators.cc - test/adapter/test_mountpoint.cc - test/adapter/test_uuid_mountpoint.cc - test/adapter/test_uuid_mountpoint_factory.cc - test/adapter/test_fuse_req.cc - test/adapter/jsonrpc/test_util.cc - test/adapter/jsonrpc/test_is_request.cc - test/adapter/jsonrpc/test_request.cc - test/adapter/jsonrpc/test_is_response.cc - test/adapter/jsonrpc/test_response.cc - test/adapter/jsonrpc/test_server.cc - test/adapter/jsonrpc/test_proxy.cc - test/provider/test_url.cc - test/provider/test_static_filesystem.cc - test/provider/test_client_protocol.cc - test/integration/test_integration.cc - test/integration/server.cc - test/integration/provider.cc + test/webfuse/utils/tempdir.cc + test/webfuse/utils/file_utils.cc + test/webfuse/utils/msleep.cc + test/webfuse/utils/die_if.cc + test/webfuse/utils/timeout_watcher.cc + test/webfuse/fakes/fake_adapter_server.cc + test/webfuse/mocks/mock_authenticator.cc + test/webfuse/mocks/mock_request.cc + test/webfuse/tests/core/test_container_of.cc + test/webfuse/tests/core/test_string.cc + test/webfuse/tests/core/test_slist.cc + test/webfuse/tests/core/test_path.cc + test/webfuse/tests/core/test_base64.cc + test/webfuse/tests/core/test_status.cc + test/webfuse/tests/core/test_message.cc + test/webfuse/tests/core/test_message_queue.cc + test/webfuse/tests/adapter/test_response_parser.cc + test/webfuse/tests/adapter/test_server.cc + test/webfuse/tests/adapter/test_server_config.cc + test/webfuse/tests/adapter/test_timepoint.cc + test/webfuse/tests/adapter/test_timer.cc + test/webfuse/tests/adapter/test_credentials.cc + test/webfuse/tests/adapter/test_authenticator.cc + test/webfuse/tests/adapter/test_authenticators.cc + test/webfuse/tests/adapter/test_mountpoint.cc + test/webfuse/tests/adapter/test_uuid_mountpoint.cc + test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc + test/webfuse/tests/adapter/test_fuse_req.cc + test/webfuse/tests/adapter/jsonrpc/test_util.cc + test/webfuse/tests/adapter/jsonrpc/test_is_request.cc + test/webfuse/tests/adapter/jsonrpc/test_request.cc + test/webfuse/tests/adapter/jsonrpc/test_is_response.cc + test/webfuse/tests/adapter/jsonrpc/test_response.cc + test/webfuse/tests/adapter/jsonrpc/test_server.cc + test/webfuse/tests/adapter/jsonrpc/test_proxy.cc + test/webfuse/tests/provider/test_url.cc + test/webfuse/tests/provider/test_static_filesystem.cc + test/webfuse/tests/provider/test_client_protocol.cc + test/webfuse/tests/integration/test_integration.cc + test/webfuse/tests/integration/server.cc + test/webfuse/tests/integration/provider.cc ) target_include_directories(alltests PRIVATE diff --git a/test/fake_adapter_server.cc b/test/webfuse/fakes/fake_adapter_server.cc similarity index 97% rename from test/fake_adapter_server.cc rename to test/webfuse/fakes/fake_adapter_server.cc index 72a1831..bebd3d9 100644 --- a/test/fake_adapter_server.cc +++ b/test/webfuse/fakes/fake_adapter_server.cc @@ -1,5 +1,5 @@ -#include "fake_adapter_server.hpp" -#include "timeout_watcher.hpp" +#include "webfuse/fakes/fake_adapter_server.hpp" +#include "webfuse/utils/timeout_watcher.hpp" #include "webfuse/core/util.h" #include diff --git a/test/fake_adapter_server.hpp b/test/webfuse/fakes/fake_adapter_server.hpp similarity index 100% rename from test/fake_adapter_server.hpp rename to test/webfuse/fakes/fake_adapter_server.hpp diff --git a/test/mock_authenticator.cc b/test/webfuse/mocks/mock_authenticator.cc similarity index 94% rename from test/mock_authenticator.cc rename to test/webfuse/mocks/mock_authenticator.cc index f2decab..35648ed 100644 --- a/test/mock_authenticator.cc +++ b/test/webfuse/mocks/mock_authenticator.cc @@ -1,4 +1,4 @@ -#include "mock_authenticator.hpp" +#include "webfuse/mocks/mock_authenticator.hpp" #define WF_AUTHENTICATOR_COUNT 3 diff --git a/test/mock_authenticator.hpp b/test/webfuse/mocks/mock_authenticator.hpp similarity index 100% rename from test/mock_authenticator.hpp rename to test/webfuse/mocks/mock_authenticator.hpp diff --git a/test/mock_request.cc b/test/webfuse/mocks/mock_request.cc similarity index 95% rename from test/mock_request.cc rename to test/webfuse/mocks/mock_request.cc index efd8334..c2dd441 100644 --- a/test/mock_request.cc +++ b/test/webfuse/mocks/mock_request.cc @@ -1,4 +1,4 @@ -#include "mock_request.hpp" +#include "webfuse/mocks/mock_request.hpp" #include namespace diff --git a/test/mock_request.hpp b/test/webfuse/mocks/mock_request.hpp similarity index 100% rename from test/mock_request.hpp rename to test/webfuse/mocks/mock_request.hpp diff --git a/test/adapter/jsonrpc/test_is_request.cc b/test/webfuse/tests/adapter/jsonrpc/test_is_request.cc similarity index 100% rename from test/adapter/jsonrpc/test_is_request.cc rename to test/webfuse/tests/adapter/jsonrpc/test_is_request.cc diff --git a/test/adapter/jsonrpc/test_is_response.cc b/test/webfuse/tests/adapter/jsonrpc/test_is_response.cc similarity index 100% rename from test/adapter/jsonrpc/test_is_response.cc rename to test/webfuse/tests/adapter/jsonrpc/test_is_response.cc diff --git a/test/adapter/jsonrpc/test_proxy.cc b/test/webfuse/tests/adapter/jsonrpc/test_proxy.cc similarity index 99% rename from test/adapter/jsonrpc/test_proxy.cc rename to test/webfuse/tests/adapter/jsonrpc/test_proxy.cc index 1355c4e..8f99312 100644 --- a/test/adapter/jsonrpc/test_proxy.cc +++ b/test/webfuse/tests/adapter/jsonrpc/test_proxy.cc @@ -1,7 +1,7 @@ #include #include "webfuse/adapter/impl/jsonrpc/proxy.h" #include "webfuse/adapter/impl/time/timeout_manager.h" -#include "msleep.hpp" +#include "webfuse/utils/msleep.hpp" using webfuse_test::msleep; diff --git a/test/adapter/jsonrpc/test_request.cc b/test/webfuse/tests/adapter/jsonrpc/test_request.cc similarity index 100% rename from test/adapter/jsonrpc/test_request.cc rename to test/webfuse/tests/adapter/jsonrpc/test_request.cc diff --git a/test/adapter/jsonrpc/test_response.cc b/test/webfuse/tests/adapter/jsonrpc/test_response.cc similarity index 100% rename from test/adapter/jsonrpc/test_response.cc rename to test/webfuse/tests/adapter/jsonrpc/test_response.cc diff --git a/test/adapter/jsonrpc/test_server.cc b/test/webfuse/tests/adapter/jsonrpc/test_server.cc similarity index 100% rename from test/adapter/jsonrpc/test_server.cc rename to test/webfuse/tests/adapter/jsonrpc/test_server.cc diff --git a/test/adapter/jsonrpc/test_util.cc b/test/webfuse/tests/adapter/jsonrpc/test_util.cc similarity index 100% rename from test/adapter/jsonrpc/test_util.cc rename to test/webfuse/tests/adapter/jsonrpc/test_util.cc diff --git a/test/adapter/test_authenticator.cc b/test/webfuse/tests/adapter/test_authenticator.cc similarity index 97% rename from test/adapter/test_authenticator.cc rename to test/webfuse/tests/adapter/test_authenticator.cc index 93505a9..07e06e5 100644 --- a/test/adapter/test_authenticator.cc +++ b/test/webfuse/tests/adapter/test_authenticator.cc @@ -1,7 +1,7 @@ #include #include -#include "mock_authenticator.hpp" +#include "webfuse/mocks/mock_authenticator.hpp" #include "webfuse/adapter/impl/authenticator.h" #include "webfuse/adapter/impl/credentials.h" diff --git a/test/adapter/test_authenticators.cc b/test/webfuse/tests/adapter/test_authenticators.cc similarity index 99% rename from test/adapter/test_authenticators.cc rename to test/webfuse/tests/adapter/test_authenticators.cc index 3227e57..6cb8064 100644 --- a/test/adapter/test_authenticators.cc +++ b/test/webfuse/tests/adapter/test_authenticators.cc @@ -3,7 +3,7 @@ #include "webfuse/adapter/impl/authenticators.h" #include "webfuse/adapter/impl/credentials.h" -#include "mock_authenticator.hpp" +#include "webfuse/mocks/mock_authenticator.hpp" using ::testing::_; using ::testing::Return; diff --git a/test/adapter/test_credentials.cc b/test/webfuse/tests/adapter/test_credentials.cc similarity index 100% rename from test/adapter/test_credentials.cc rename to test/webfuse/tests/adapter/test_credentials.cc diff --git a/test/adapter/test_fuse_req.cc b/test/webfuse/tests/adapter/test_fuse_req.cc similarity index 100% rename from test/adapter/test_fuse_req.cc rename to test/webfuse/tests/adapter/test_fuse_req.cc diff --git a/test/adapter/test_mountpoint.cc b/test/webfuse/tests/adapter/test_mountpoint.cc similarity index 100% rename from test/adapter/test_mountpoint.cc rename to test/webfuse/tests/adapter/test_mountpoint.cc diff --git a/test/adapter/test_response_parser.cc b/test/webfuse/tests/adapter/test_response_parser.cc similarity index 100% rename from test/adapter/test_response_parser.cc rename to test/webfuse/tests/adapter/test_response_parser.cc diff --git a/test/adapter/test_server.cc b/test/webfuse/tests/adapter/test_server.cc similarity index 100% rename from test/adapter/test_server.cc rename to test/webfuse/tests/adapter/test_server.cc diff --git a/test/adapter/test_server_config.cc b/test/webfuse/tests/adapter/test_server_config.cc similarity index 99% rename from test/adapter/test_server_config.cc rename to test/webfuse/tests/adapter/test_server_config.cc index cb176d6..f85aa92 100644 --- a/test/adapter/test_server_config.cc +++ b/test/webfuse/tests/adapter/test_server_config.cc @@ -2,7 +2,7 @@ #include "webfuse/adapter/server_config.h" #include "webfuse/adapter/impl/server_config.h" #include "webfuse/adapter/impl/authenticator.h" -#include "tempdir.hpp" +#include "webfuse/utils/tempdir.hpp" using webfuse_test::TempDir; diff --git a/test/adapter/test_timepoint.cc b/test/webfuse/tests/adapter/test_timepoint.cc similarity index 95% rename from test/adapter/test_timepoint.cc rename to test/webfuse/tests/adapter/test_timepoint.cc index 85de35d..8b0db97 100644 --- a/test/adapter/test_timepoint.cc +++ b/test/webfuse/tests/adapter/test_timepoint.cc @@ -1,6 +1,6 @@ #include -#include "msleep.hpp" +#include "webfuse/utils/msleep.hpp" #include "webfuse/adapter/impl/time/timepoint.h" using webfuse_test::msleep; diff --git a/test/adapter/test_timer.cc b/test/webfuse/tests/adapter/test_timer.cc similarity index 99% rename from test/adapter/test_timer.cc rename to test/webfuse/tests/adapter/test_timer.cc index b838147..d554f2d 100644 --- a/test/adapter/test_timer.cc +++ b/test/webfuse/tests/adapter/test_timer.cc @@ -2,7 +2,7 @@ #include -#include "msleep.hpp" +#include "webfuse/utils/msleep.hpp" #include "webfuse/adapter/impl/time/timer.h" #include "webfuse/adapter/impl/time/timeout_manager.h" diff --git a/test/adapter/test_uuid_mountpoint.cc b/test/webfuse/tests/adapter/test_uuid_mountpoint.cc similarity index 96% rename from test/adapter/test_uuid_mountpoint.cc rename to test/webfuse/tests/adapter/test_uuid_mountpoint.cc index 8bff760..7549b84 100644 --- a/test/adapter/test_uuid_mountpoint.cc +++ b/test/webfuse/tests/adapter/test_uuid_mountpoint.cc @@ -1,7 +1,7 @@ #include -#include "tempdir.hpp" -#include "file_utils.hpp" +#include "webfuse/utils/tempdir.hpp" +#include "webfuse/utils/file_utils.hpp" #include "webfuse_adapter.h" #include "webfuse/adapter/impl/uuid_mountpoint.h" diff --git a/test/adapter/test_uuid_mountpoint_factory.cc b/test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc similarity index 96% rename from test/adapter/test_uuid_mountpoint_factory.cc rename to test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc index b097ae0..dca941f 100644 --- a/test/adapter/test_uuid_mountpoint_factory.cc +++ b/test/webfuse/tests/adapter/test_uuid_mountpoint_factory.cc @@ -1,8 +1,8 @@ #include #include "webfuse_adapter.h" #include "webfuse/adapter/impl/uuid_mountpoint_factory.h" -#include "tempdir.hpp" -#include "file_utils.hpp" +#include "webfuse/utils/tempdir.hpp" +#include "webfuse/utils/file_utils.hpp" using webfuse_test::TempDir; using webfuse_test::is_dir; diff --git a/test/core/test_base64.cc b/test/webfuse/tests/core/test_base64.cc similarity index 100% rename from test/core/test_base64.cc rename to test/webfuse/tests/core/test_base64.cc diff --git a/test/core/test_container_of.cc b/test/webfuse/tests/core/test_container_of.cc similarity index 100% rename from test/core/test_container_of.cc rename to test/webfuse/tests/core/test_container_of.cc diff --git a/test/core/test_message.cc b/test/webfuse/tests/core/test_message.cc similarity index 100% rename from test/core/test_message.cc rename to test/webfuse/tests/core/test_message.cc diff --git a/test/core/test_message_queue.cc b/test/webfuse/tests/core/test_message_queue.cc similarity index 100% rename from test/core/test_message_queue.cc rename to test/webfuse/tests/core/test_message_queue.cc diff --git a/test/core/test_path.cc b/test/webfuse/tests/core/test_path.cc similarity index 100% rename from test/core/test_path.cc rename to test/webfuse/tests/core/test_path.cc diff --git a/test/core/test_slist.cc b/test/webfuse/tests/core/test_slist.cc similarity index 100% rename from test/core/test_slist.cc rename to test/webfuse/tests/core/test_slist.cc diff --git a/test/core/test_status.cc b/test/webfuse/tests/core/test_status.cc similarity index 100% rename from test/core/test_status.cc rename to test/webfuse/tests/core/test_status.cc diff --git a/test/core/test_string.cc b/test/webfuse/tests/core/test_string.cc similarity index 100% rename from test/core/test_string.cc rename to test/webfuse/tests/core/test_string.cc diff --git a/test/integration/provider.cc b/test/webfuse/tests/integration/provider.cc similarity index 95% rename from test/integration/provider.cc rename to test/webfuse/tests/integration/provider.cc index 3ee4285..49c334a 100644 --- a/test/integration/provider.cc +++ b/test/webfuse/tests/integration/provider.cc @@ -1,10 +1,10 @@ -#include "integration/provider.hpp" +#include "webfuse/tests/integration/provider.hpp" #include "webfuse_provider.h" #include "webfuse/provider/impl/client.h" #include #include #include -#include "msleep.hpp" +#include "webfuse/utils/msleep.hpp" namespace webfuse_test { diff --git a/test/integration/provider.hpp b/test/webfuse/tests/integration/provider.hpp similarity index 100% rename from test/integration/provider.hpp rename to test/webfuse/tests/integration/provider.hpp diff --git a/test/integration/server.cc b/test/webfuse/tests/integration/server.cc similarity index 95% rename from test/integration/server.cc rename to test/webfuse/tests/integration/server.cc index 0659efe..1360934 100644 --- a/test/integration/server.cc +++ b/test/webfuse/tests/integration/server.cc @@ -1,4 +1,4 @@ -#include "integration/server.hpp" +#include "webfuse/tests/integration/server.hpp" #include #include #include @@ -6,7 +6,7 @@ #include #include "webfuse_adapter.h" #include "webfuse/adapter/impl/server.h" -#include "msleep.hpp" +#include "webfuse/utils/msleep.hpp" #define WF_PATH_MAX (100) diff --git a/test/integration/server.hpp b/test/webfuse/tests/integration/server.hpp similarity index 100% rename from test/integration/server.hpp rename to test/webfuse/tests/integration/server.hpp diff --git a/test/integration/test_integration.cc b/test/webfuse/tests/integration/test_integration.cc similarity index 96% rename from test/integration/test_integration.cc rename to test/webfuse/tests/integration/test_integration.cc index 8bd21c6..203856c 100644 --- a/test/integration/test_integration.cc +++ b/test/webfuse/tests/integration/test_integration.cc @@ -1,6 +1,6 @@ #include -#include "integration/server.hpp" -#include "integration/provider.hpp" +#include "webfuse/tests/integration/server.hpp" +#include "webfuse/tests/integration/provider.hpp" #include #include @@ -15,7 +15,7 @@ #include #include "webfuse/core/lws_log.h" -#include "die_if.hpp" +#include "webfuse/utils/die_if.hpp" using webfuse_test::Server; using webfuse_test::Provider; diff --git a/test/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc similarity index 96% rename from test/provider/test_client_protocol.cc rename to test/webfuse/tests/provider/test_client_protocol.cc index 4e78f8e..ef058f7 100644 --- a/test/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -3,7 +3,7 @@ #include #include -#include "fake_adapter_server.hpp" +#include "webfuse/fakes/fake_adapter_server.hpp" #include #include diff --git a/test/provider/test_static_filesystem.cc b/test/webfuse/tests/provider/test_static_filesystem.cc similarity index 98% rename from test/provider/test_static_filesystem.cc rename to test/webfuse/tests/provider/test_static_filesystem.cc index e7db28e..64a2736 100644 --- a/test/provider/test_static_filesystem.cc +++ b/test/webfuse/tests/provider/test_static_filesystem.cc @@ -4,7 +4,7 @@ #include "webfuse/provider/client_config.h" #include "webfuse/provider/impl/client_config.h" -#include "mock_request.hpp" +#include "webfuse/mocks/mock_request.hpp" using webfuse_test::request_create; using webfuse_test::MockRequest; diff --git a/test/provider/test_url.cc b/test/webfuse/tests/provider/test_url.cc similarity index 100% rename from test/provider/test_url.cc rename to test/webfuse/tests/provider/test_url.cc diff --git a/test/die_if.cc b/test/webfuse/utils/die_if.cc similarity index 79% rename from test/die_if.cc rename to test/webfuse/utils/die_if.cc index 3eff5ae..bd8dd70 100644 --- a/test/die_if.cc +++ b/test/webfuse/utils/die_if.cc @@ -1,4 +1,4 @@ -#include "die_if.hpp" +#include "webfuse/utils/die_if.hpp" #include namespace webfuse_test diff --git a/test/die_if.hpp b/test/webfuse/utils/die_if.hpp similarity index 100% rename from test/die_if.hpp rename to test/webfuse/utils/die_if.hpp diff --git a/test/file_utils.cc b/test/webfuse/utils/file_utils.cc similarity index 94% rename from test/file_utils.cc rename to test/webfuse/utils/file_utils.cc index 0d3ff81..7a3d29c 100644 --- a/test/file_utils.cc +++ b/test/webfuse/utils/file_utils.cc @@ -1,4 +1,4 @@ -#include "file_utils.hpp" +#include "webfuse/utils/file_utils.hpp" #include #include diff --git a/test/file_utils.hpp b/test/webfuse/utils/file_utils.hpp similarity index 100% rename from test/file_utils.hpp rename to test/webfuse/utils/file_utils.hpp diff --git a/test/msleep.cc b/test/webfuse/utils/msleep.cc similarity index 90% rename from test/msleep.cc rename to test/webfuse/utils/msleep.cc index 5f76e49..659bb81 100644 --- a/test/msleep.cc +++ b/test/webfuse/utils/msleep.cc @@ -1,4 +1,4 @@ -#include "msleep.hpp" +#include "webfuse/utils/msleep.hpp" #include namespace webfuse_test diff --git a/test/msleep.hpp b/test/webfuse/utils/msleep.hpp similarity index 100% rename from test/msleep.hpp rename to test/webfuse/utils/msleep.hpp diff --git a/test/tempdir.cc b/test/webfuse/utils/tempdir.cc similarity index 92% rename from test/tempdir.cc rename to test/webfuse/utils/tempdir.cc index 040aed1..31dce25 100644 --- a/test/tempdir.cc +++ b/test/webfuse/utils/tempdir.cc @@ -1,5 +1,5 @@ #include "webfuse/core/string.h" -#include "tempdir.hpp" +#include "webfuse/utils/tempdir.hpp" #include #include diff --git a/test/tempdir.hpp b/test/webfuse/utils/tempdir.hpp similarity index 100% rename from test/tempdir.hpp rename to test/webfuse/utils/tempdir.hpp diff --git a/test/timeout_watcher.cc b/test/webfuse/utils/timeout_watcher.cc similarity index 93% rename from test/timeout_watcher.cc rename to test/webfuse/utils/timeout_watcher.cc index 7e3bb52..8d9add7 100644 --- a/test/timeout_watcher.cc +++ b/test/webfuse/utils/timeout_watcher.cc @@ -1,4 +1,4 @@ -#include "timeout_watcher.hpp" +#include "webfuse/utils/timeout_watcher.hpp" #include using std::chrono::milliseconds; diff --git a/test/timeout_watcher.hpp b/test/webfuse/utils/timeout_watcher.hpp similarity index 100% rename from test/timeout_watcher.hpp rename to test/webfuse/utils/timeout_watcher.hpp From 17fa84bc3871eec23edfcc1bcf2be15489499180 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Thu, 20 Feb 2020 18:54:29 +0100 Subject: [PATCH 02/16] made static_filesystem private (used for test purposes only) --- cmake/unit_tests.cmake | 4 +- cmake/webfuse_core.cmake | 1 - cmake/webfuse_provider.cmake | 1 - include/webfuse/provider/static_filesystem.h | 114 ------------------ include/webfuse_provider.h | 2 - lib/webfuse/provider/api.c | 58 --------- lib/webfuse/provider/impl/static_filesystem.h | 52 -------- test/webfuse/tests/core/test_path.cc | 58 --------- test/webfuse/tests/integration/provider.cc | 1 + .../tests/provider/test_static_filesystem.cc | 61 ---------- .../core => test/webfuse/utils}/path.c | 2 +- .../core => test/webfuse/utils}/path.h | 0 .../webfuse/utils}/static_filesystem.c | 104 ++++++++-------- test/webfuse/utils/static_filesystem.h | 77 ++++++++++++ 14 files changed, 133 insertions(+), 402 deletions(-) delete mode 100644 include/webfuse/provider/static_filesystem.h delete mode 100644 lib/webfuse/provider/impl/static_filesystem.h delete mode 100644 test/webfuse/tests/core/test_path.cc delete mode 100644 test/webfuse/tests/provider/test_static_filesystem.cc rename {lib/webfuse/core => test/webfuse/utils}/path.c (98%) rename {lib/webfuse/core => test/webfuse/utils}/path.h (100%) rename {lib/webfuse/provider/impl => test/webfuse/utils}/static_filesystem.c (75%) create mode 100644 test/webfuse/utils/static_filesystem.h diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 14ff04d..dfc804e 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -12,13 +12,14 @@ add_executable(alltests test/webfuse/utils/msleep.cc test/webfuse/utils/die_if.cc test/webfuse/utils/timeout_watcher.cc + test/webfuse/utils/path.c + test/webfuse/utils/static_filesystem.c test/webfuse/fakes/fake_adapter_server.cc test/webfuse/mocks/mock_authenticator.cc test/webfuse/mocks/mock_request.cc test/webfuse/tests/core/test_container_of.cc test/webfuse/tests/core/test_string.cc test/webfuse/tests/core/test_slist.cc - test/webfuse/tests/core/test_path.cc test/webfuse/tests/core/test_base64.cc test/webfuse/tests/core/test_status.cc test/webfuse/tests/core/test_message.cc @@ -43,7 +44,6 @@ add_executable(alltests test/webfuse/tests/adapter/jsonrpc/test_server.cc test/webfuse/tests/adapter/jsonrpc/test_proxy.cc test/webfuse/tests/provider/test_url.cc - test/webfuse/tests/provider/test_static_filesystem.cc test/webfuse/tests/provider/test_client_protocol.cc test/webfuse/tests/integration/test_integration.cc test/webfuse/tests/integration/server.cc diff --git a/cmake/webfuse_core.cmake b/cmake/webfuse_core.cmake index b162f40..52c7681 100644 --- a/cmake/webfuse_core.cmake +++ b/cmake/webfuse_core.cmake @@ -6,7 +6,6 @@ add_library(webfuse-core STATIC lib/webfuse/core/message_queue.c lib/webfuse/core/status.c lib/webfuse/core/string.c - lib/webfuse/core/path.c lib/webfuse/core/base64.c lib/webfuse/core/lws_log.c ) diff --git a/cmake/webfuse_provider.cmake b/cmake/webfuse_provider.cmake index b42f1f4..5079cb1 100644 --- a/cmake/webfuse_provider.cmake +++ b/cmake/webfuse_provider.cmake @@ -15,7 +15,6 @@ add_library(webfuse-provider-static STATIC lib/webfuse/provider/impl/operation/open.c lib/webfuse/provider/impl/operation/close.c lib/webfuse/provider/impl/operation/read.c - lib/webfuse/provider/impl/static_filesystem.c ) set_target_properties(webfuse-provider-static PROPERTIES OUTPUT_NAME webfuse-provider) diff --git a/include/webfuse/provider/static_filesystem.h b/include/webfuse/provider/static_filesystem.h deleted file mode 100644 index e736976..0000000 --- a/include/webfuse/provider/static_filesystem.h +++ /dev/null @@ -1,114 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -/// \file provider/static_filesystem.h -/// \brief Reference implementation of static filesystem. -/// -/// This header is used by integration tests. It may be removed from the -/// library. -/// -/// \todo Remove this header from library -//////////////////////////////////////////////////////////////////////////////// - -#ifndef WFP_STATIC_FILESYSTEM_H -#define WFP_STATIC_FILESYSTEM_H - -#ifndef __cplusplus -#include -#else -#include -using ::std::size_t; -#endif - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct wfp_client_config; - -//------------------------------------------------------------------------------ -/// \deprecated This will be removed. Dont use it. -//------------------------------------------------------------------------------ -struct wfp_static_filesystem; - -//------------------------------------------------------------------------------ -/// \deprecated This will be removed. Dont use it. -//------------------------------------------------------------------------------ -typedef size_t -wfp_static_filesystem_read_fn( - size_t offset, - char * buffer, - size_t buffer_size, - void * user_data); - -//------------------------------------------------------------------------------ -/// \deprecated This will be removed. Dont use it. -//------------------------------------------------------------------------------ -typedef void -wfp_static_filesystem_get_info_fn( - void * user_data, - int * result_mode, - size_t * result_size); - - -//------------------------------------------------------------------------------ -/// \deprecated This will be removed. Dont use it. -//------------------------------------------------------------------------------ -extern WFP_API struct wfp_static_filesystem * -wfp_static_filesystem_create( - struct wfp_client_config * config); - -//------------------------------------------------------------------------------ -/// \deprecated This will be removed. Dont use it. -//------------------------------------------------------------------------------ -extern WFP_API void -wfp_static_filesystem_dispose( - struct wfp_static_filesystem * filesystem); - -//------------------------------------------------------------------------------ -/// \deprecated This will be removed. Dont use it. -//------------------------------------------------------------------------------ -extern WFP_API void -wfp_static_filesystem_add( - struct wfp_static_filesystem * filesystem, - char const * path, - int mode, - char const * content, - size_t length); - -//------------------------------------------------------------------------------ -/// \deprecated This will be removed. Dont use it. -//------------------------------------------------------------------------------ -extern WFP_API void -wfp_static_filesystem_add_text( - struct wfp_static_filesystem * filesystem, - char const * path, - int mode, - char const * content); - -//------------------------------------------------------------------------------ -/// \deprecated This will be removed. Dont use it. -//------------------------------------------------------------------------------ -extern WFP_API void -wfp_static_filesystem_add_file( - struct wfp_static_filesystem * filesystem, - char const * path, - char const * filename); - -//------------------------------------------------------------------------------ -/// \deprecated This will be removed. Dont use it. -//------------------------------------------------------------------------------ -extern WFP_API void -wfp_static_filesystem_add_generic( - struct wfp_static_filesystem * filesystem, - char const * path, - wfp_static_filesystem_read_fn * read, - wfp_static_filesystem_get_info_fn * get_info, - void * user_data); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/webfuse_provider.h b/include/webfuse_provider.h index 5882c60..bd119ac 100644 --- a/include/webfuse_provider.h +++ b/include/webfuse_provider.h @@ -22,6 +22,4 @@ #include #include -#include - #endif diff --git a/lib/webfuse/provider/api.c b/lib/webfuse/provider/api.c index 933516b..0c0e88a 100644 --- a/lib/webfuse/provider/api.c +++ b/lib/webfuse/provider/api.c @@ -11,7 +11,6 @@ #include "webfuse/provider/impl/client_config.h" #include "webfuse/provider/impl/client.h" #include "webfuse/provider/impl/dirbuffer.h" -#include "webfuse/provider/impl/static_filesystem.h" // respond @@ -241,60 +240,3 @@ void wfp_dirbuffer_add( { wfp_impl_dirbuffer_add(buffer, name, inode); } - -// static_filesystem - -struct wfp_static_filesystem * -wfp_static_filesystem_create( - struct wfp_client_config * config) -{ - return wfp_impl_static_filesystem_create(config); -} - -void -wfp_static_filesystem_dispose( - struct wfp_static_filesystem * filesystem) -{ - wfp_impl_static_filesystem_dispose(filesystem); -} - -void -wfp_static_filesystem_add( - struct wfp_static_filesystem * filesystem, - char const * path, - int mode, - char const * content, - size_t length) -{ - wfp_impl_static_filesystem_add(filesystem, path, mode, content, length); -} - -void -wfp_static_filesystem_add_text( - struct wfp_static_filesystem * filesystem, - char const * path, - int mode, - char const * content) -{ - wfp_impl_static_filesystem_add_text(filesystem, path, mode, content); -} - -void -wfp_static_filesystem_add_file( - struct wfp_static_filesystem * filesystem, - char const * path, - char const * filename) -{ - wfp_impl_static_filesystem_add_file(filesystem, path, filename); -} - -void -wfp_static_filesystem_add_generic( - struct wfp_static_filesystem * filesystem, - char const * path, - wfp_static_filesystem_read_fn * read, - wfp_static_filesystem_get_info_fn * get_info, - void * user_data) -{ - wfp_impl_static_filesystem_add_generic(filesystem, path, read, get_info, user_data); -} diff --git a/lib/webfuse/provider/impl/static_filesystem.h b/lib/webfuse/provider/impl/static_filesystem.h deleted file mode 100644 index a18835d..0000000 --- a/lib/webfuse/provider/impl/static_filesystem.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef WFP_IMPL_STATIC_FILESYSTEM_H -#define WFP_IMPL_STATIC_FILESYSTEM_H - -#include "webfuse/provider/static_filesystem.h" - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern struct wfp_static_filesystem * -wfp_impl_static_filesystem_create( - struct wfp_client_config * config); - -extern void -wfp_impl_static_filesystem_dispose( - struct wfp_static_filesystem * filesystem); - -extern void -wfp_impl_static_filesystem_add( - struct wfp_static_filesystem * filesystem, - char const * path, - int mode, - char const * content, - size_t length); - -extern void -wfp_impl_static_filesystem_add_text( - struct wfp_static_filesystem * filesystem, - char const * path, - int mode, - char const * content); - -extern void -wfp_impl_static_filesystem_add_file( - struct wfp_static_filesystem * filesystem, - char const * path, - char const * filename); - -extern void -wfp_impl_static_filesystem_add_generic( - struct wfp_static_filesystem * filesystem, - char const * path, - wfp_static_filesystem_read_fn * read, - wfp_static_filesystem_get_info_fn * get_info, - void * user_data); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/test/webfuse/tests/core/test_path.cc b/test/webfuse/tests/core/test_path.cc deleted file mode 100644 index 93783ec..0000000 --- a/test/webfuse/tests/core/test_path.cc +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include "webfuse/core/path.h" - -TEST(wf_path, empty) -{ - struct wf_path * path = wf_path_create(""); - ASSERT_EQ(0, wf_path_element_count(path)); - ASSERT_EQ(nullptr, wf_path_get_element(path, 0)); - - wf_path_dispose(path); -} - -TEST(wf_path, relative_file) -{ - struct wf_path * path = wf_path_create("some.file"); - ASSERT_EQ(1, wf_path_element_count(path)); - ASSERT_STREQ("some.file", wf_path_get_element(path, 0)); - - wf_path_dispose(path); -} - -TEST(wf_path, absolute_file) -{ - struct wf_path * path = wf_path_create("/absolute.file"); - ASSERT_EQ(1, wf_path_element_count(path)); - ASSERT_STREQ("absolute.file", wf_path_get_element(path, 0)); - - wf_path_dispose(path); -} - -TEST(wf_path, nested_path) -{ - struct wf_path * path = wf_path_create("/a/nested/path"); - ASSERT_EQ(3, wf_path_element_count(path)); - ASSERT_STREQ("a", wf_path_get_element(path, 0)); - ASSERT_STREQ("nested", wf_path_get_element(path, 1)); - ASSERT_STREQ("path", wf_path_get_element(path, 2)); - - wf_path_dispose(path); -} - -TEST(wf_path, deep_nested_path) -{ - struct wf_path * path = wf_path_create("/this/is/a/very/deep/nested/path/to/some/file"); - ASSERT_EQ(10, wf_path_element_count(path)); - ASSERT_STREQ("this", wf_path_get_element(path, 0)); - ASSERT_STREQ("is", wf_path_get_element(path, 1)); - ASSERT_STREQ("a", wf_path_get_element(path, 2)); - ASSERT_STREQ("very", wf_path_get_element(path, 3)); - ASSERT_STREQ("deep", wf_path_get_element(path, 4)); - ASSERT_STREQ("nested", wf_path_get_element(path, 5)); - ASSERT_STREQ("path", wf_path_get_element(path, 6)); - ASSERT_STREQ("to", wf_path_get_element(path, 7)); - ASSERT_STREQ("some", wf_path_get_element(path, 8)); - ASSERT_STREQ("file", wf_path_get_element(path, 9)); - - wf_path_dispose(path); -} \ No newline at end of file diff --git a/test/webfuse/tests/integration/provider.cc b/test/webfuse/tests/integration/provider.cc index 49c334a..5142ca8 100644 --- a/test/webfuse/tests/integration/provider.cc +++ b/test/webfuse/tests/integration/provider.cc @@ -5,6 +5,7 @@ #include #include #include "webfuse/utils/msleep.hpp" +#include "webfuse/utils/static_filesystem.h" namespace webfuse_test { diff --git a/test/webfuse/tests/provider/test_static_filesystem.cc b/test/webfuse/tests/provider/test_static_filesystem.cc deleted file mode 100644 index 64a2736..0000000 --- a/test/webfuse/tests/provider/test_static_filesystem.cc +++ /dev/null @@ -1,61 +0,0 @@ -#include - -#include "webfuse/provider/impl/static_filesystem.h" -#include "webfuse/provider/client_config.h" -#include "webfuse/provider/impl/client_config.h" - -#include "webfuse/mocks/mock_request.hpp" - -using webfuse_test::request_create; -using webfuse_test::MockRequest; -using webfuse_test::GetAttrMatcher; -using webfuse_test::ReaddirMatcher; -using testing::_; - -TEST(wfp_static_filesystem, has_root_dir) -{ - struct wfp_client_config * config = wfp_client_config_create(); - struct wfp_static_filesystem * filesystem = wfp_impl_static_filesystem_create(config); - - MockRequest mock; - struct wfp_request * request = request_create(&mock, 42); - EXPECT_CALL(mock, respond(GetAttrMatcher(1, 0555, "dir"), 42)).Times(1); - - config->provider.getattr(request, 1, config->user_data); - - wfp_impl_static_filesystem_dispose(filesystem); - wfp_client_config_dispose(config); -} - -TEST(wfp_static_filesystem, contains_default_dirs) -{ - struct wfp_client_config * config = wfp_client_config_create(); - struct wfp_static_filesystem * filesystem = wfp_impl_static_filesystem_create(config); - - MockRequest mock; - struct wfp_request * request = request_create(&mock, 23); - char const * default_dirs[] = {".", "..", nullptr}; - EXPECT_CALL(mock, respond(ReaddirMatcher(default_dirs), 23)).Times(1); - - config->provider.readdir(request, 1, config->user_data); - - wfp_impl_static_filesystem_dispose(filesystem); - wfp_client_config_dispose(config); -} - -TEST(wfp_static_filesystem, add_text) -{ - struct wfp_client_config * config = wfp_client_config_create(); - struct wfp_static_filesystem * filesystem = wfp_impl_static_filesystem_create(config); - wfp_impl_static_filesystem_add_text(filesystem, "text.file", 666, "some text"); - - MockRequest mock; - struct wfp_request * request = request_create(&mock, 23); - char const * contained_elements[] = {"text.file", nullptr}; - EXPECT_CALL(mock, respond(ReaddirMatcher(contained_elements), 23)).Times(1); - - config->provider.readdir(request, 1, config->user_data); - - wfp_impl_static_filesystem_dispose(filesystem); - wfp_client_config_dispose(config); -} diff --git a/lib/webfuse/core/path.c b/test/webfuse/utils/path.c similarity index 98% rename from lib/webfuse/core/path.c rename to test/webfuse/utils/path.c index 36689f0..3cb222e 100644 --- a/lib/webfuse/core/path.c +++ b/test/webfuse/utils/path.c @@ -1,4 +1,4 @@ -#include "webfuse/core/path.h" +#include "webfuse/utils/path.h" #include #include diff --git a/lib/webfuse/core/path.h b/test/webfuse/utils/path.h similarity index 100% rename from lib/webfuse/core/path.h rename to test/webfuse/utils/path.h diff --git a/lib/webfuse/provider/impl/static_filesystem.c b/test/webfuse/utils/static_filesystem.c similarity index 75% rename from lib/webfuse/provider/impl/static_filesystem.c rename to test/webfuse/utils/static_filesystem.c index 83c3b92..7212e7a 100644 --- a/lib/webfuse/provider/impl/static_filesystem.c +++ b/test/webfuse/utils/static_filesystem.c @@ -1,9 +1,9 @@ -#include "webfuse/provider/impl/static_filesystem.h" +#include "webfuse/utils/static_filesystem.h" #include "webfuse/provider/client_config.h" #include "webfuse/provider/dirbuffer.h" #include "webfuse/provider/operation/error.h" -#include "webfuse/core/path.h" +#include "webfuse/utils/path.h" #include "webfuse/core/util.h" #include @@ -41,7 +41,7 @@ struct wfp_static_filesystem }; static struct wfp_static_filesystem_entry * -wfp_impl_static_filesystem_get_entry( +wfp_static_filesystem_get_entry( struct wfp_static_filesystem * filesystem, size_t inode) { @@ -56,7 +56,7 @@ wfp_impl_static_filesystem_get_entry( } static struct wfp_static_filesystem_entry * -wfp_impl_static_filesystem_get_entry_by_name( +wfp_static_filesystem_get_entry_by_name( struct wfp_static_filesystem * filesystem, size_t parent, char const * name) @@ -76,7 +76,7 @@ wfp_impl_static_filesystem_get_entry_by_name( } static struct wfp_static_filesystem_entry * -wfp_impl_static_filesystem_add_entry( +wfp_static_filesystem_add_entry( struct wfp_static_filesystem * filesystem) { struct wfp_static_filesystem_entry * entry = NULL; @@ -107,7 +107,7 @@ wfp_impl_static_filesystem_add_entry( } static size_t -wfp_impl_static_filesystem_entry_read( +wfp_static_filesystem_entry_read( size_t offset, char * buffer, size_t buffer_size, @@ -126,7 +126,7 @@ wfp_impl_static_filesystem_entry_read( } static void -wfp_impl_static_filesystem_entry_get_info( +wfp_static_filesystem_entry_get_info( void * user_data, int * result_mode, size_t * result_size) @@ -137,7 +137,7 @@ wfp_impl_static_filesystem_entry_get_info( } static size_t -wfp_impl_static_filesystem_file_read( +wfp_static_filesystem_file_read( size_t offset, char * buffer, size_t buffer_size, @@ -159,7 +159,7 @@ wfp_impl_static_filesystem_file_read( } static void -wfp_impl_static_filesystem_file_get_info( +wfp_static_filesystem_file_get_info( void * user_data, int * result_mode, size_t * result_size) @@ -176,23 +176,23 @@ wfp_impl_static_filesystem_file_get_info( static size_t -wfp_impl_static_filesystem_add_dir( +wfp_static_filesystem_add_dir( struct wfp_static_filesystem * filesystem, size_t parent, char const * name ) { - struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_get_entry_by_name(filesystem, parent, name); + struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry_by_name(filesystem, parent, name); if (NULL == entry) { - entry = wfp_impl_static_filesystem_add_entry(filesystem); + entry = wfp_static_filesystem_add_entry(filesystem); entry->parent = parent; entry->is_file = false; entry->mode = 0555; entry->name = strdup(name); entry->user_data = entry; - entry->read = &wfp_impl_static_filesystem_entry_read; - entry->get_info = &wfp_impl_static_filesystem_entry_get_info; + entry->read = &wfp_static_filesystem_entry_read; + entry->get_info = &wfp_static_filesystem_entry_get_info; entry->size = 0; entry->content = NULL; } @@ -201,7 +201,7 @@ wfp_impl_static_filesystem_add_dir( } static size_t -wfp_impl_static_filesystem_make_parent( +wfp_static_filesystem_make_parent( struct wfp_static_filesystem * filesystem, struct wf_path * path) { @@ -213,7 +213,7 @@ wfp_impl_static_filesystem_make_parent( for(size_t i = 0; i < (count - 1); i++) { char const * name = wf_path_get_element(path, i); - result = wfp_impl_static_filesystem_add_dir(filesystem, result, name); + result = wfp_static_filesystem_add_dir(filesystem, result, name); } } @@ -221,7 +221,7 @@ wfp_impl_static_filesystem_make_parent( } static void -wfp_impl_static_filesystem_stat( +wfp_static_filesystem_stat( struct wfp_static_filesystem_entry * entry, struct stat * stat ) @@ -238,19 +238,19 @@ wfp_impl_static_filesystem_stat( stat->st_mode |= (entry->is_file) ? S_IFREG: S_IFDIR; } -static void wfp_impl_static_filesystem_lookup( +static void wfp_static_filesystem_lookup( struct wfp_request * request, ino_t parent, char const * name, void * user_data) { struct wfp_static_filesystem * filesystem = user_data; - struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_get_entry_by_name(filesystem, parent, name); + struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry_by_name(filesystem, parent, name); if (NULL != entry) { struct stat stat; - wfp_impl_static_filesystem_stat(entry, &stat); + wfp_static_filesystem_stat(entry, &stat); wfp_respond_lookup(request, &stat); } else @@ -260,18 +260,18 @@ static void wfp_impl_static_filesystem_lookup( } -static void wfp_impl_static_filesystem_getattr( +static void wfp_static_filesystem_getattr( struct wfp_request * request, ino_t inode, void * user_data) { struct wfp_static_filesystem * filesystem = user_data; - struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_get_entry(filesystem, inode); + struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry(filesystem, inode); if (NULL != entry) { struct stat stat; - wfp_impl_static_filesystem_stat(entry, &stat); + wfp_static_filesystem_stat(entry, &stat); wfp_respond_getattr(request, &stat); } else @@ -280,13 +280,13 @@ static void wfp_impl_static_filesystem_getattr( } } -static void wfp_impl_static_filesystem_readdir( +static void wfp_static_filesystem_readdir( struct wfp_request * request, ino_t directory, void * user_data) { struct wfp_static_filesystem * filesystem = user_data; - struct wfp_static_filesystem_entry * dir = wfp_impl_static_filesystem_get_entry(filesystem, directory); + struct wfp_static_filesystem_entry * dir = wfp_static_filesystem_get_entry(filesystem, directory); if ((NULL != dir) && (!dir->is_file)) { @@ -312,14 +312,14 @@ static void wfp_impl_static_filesystem_readdir( } } -static void wfp_impl_static_filesystem_open( +static void wfp_static_filesystem_open( struct wfp_request * request, ino_t inode, int flags, void * user_data) { struct wfp_static_filesystem * filesystem = user_data; - struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_get_entry(filesystem, inode); + struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry(filesystem, inode); if ((NULL != entry) && (entry->is_file)) { @@ -338,7 +338,7 @@ static void wfp_impl_static_filesystem_open( } } -static void wfp_impl_static_filesystem_read( +static void wfp_static_filesystem_read( struct wfp_request * request, ino_t inode, uint32_t WF_UNUSED_PARAM(handle), @@ -347,7 +347,7 @@ static void wfp_impl_static_filesystem_read( void * user_data) { struct wfp_static_filesystem * filesystem = user_data; - struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_get_entry(filesystem, inode); + struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_get_entry(filesystem, inode); if ((NULL != entry) && (entry->is_file)) { @@ -365,7 +365,7 @@ static void wfp_impl_static_filesystem_read( struct wfp_static_filesystem * -wfp_impl_static_filesystem_create( +wfp_static_filesystem_create( struct wfp_client_config * config) { (void) config; @@ -377,21 +377,21 @@ wfp_impl_static_filesystem_create( filesystem->size = 0; filesystem->capacity = WFP_STATIC_FILESYSTEM_DEFAULT_CAPACITY; - wfp_impl_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_impl_static_filesystem_lookup); - wfp_client_config_set_ongetattr(config, &wfp_impl_static_filesystem_getattr); - wfp_client_config_set_onreaddir(config, &wfp_impl_static_filesystem_readdir); - wfp_client_config_set_onopen(config, &wfp_impl_static_filesystem_open); - wfp_client_config_set_onread(config, &wfp_impl_static_filesystem_read); + 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; } void -wfp_impl_static_filesystem_dispose( +wfp_static_filesystem_dispose( struct wfp_static_filesystem * filesystem) { for(size_t i = 0; i < filesystem->size; i++) @@ -406,7 +406,7 @@ wfp_impl_static_filesystem_dispose( } void -wfp_impl_static_filesystem_add( +wfp_static_filesystem_add( struct wfp_static_filesystem * filesystem, char const * path, int mode, @@ -416,15 +416,15 @@ wfp_impl_static_filesystem_add( struct wf_path * path_ = wf_path_create(path); if (NULL != path_) { - size_t parent = wfp_impl_static_filesystem_make_parent(filesystem, path_); - struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_add_entry(filesystem); + size_t parent = wfp_static_filesystem_make_parent(filesystem, path_); + struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_add_entry(filesystem); entry->parent = parent; entry->is_file = true; entry->name = strdup(wf_path_get_filename(path_)); entry->mode = mode; entry->size = length; - entry->get_info = &wfp_impl_static_filesystem_entry_get_info; - entry->read = &wfp_impl_static_filesystem_entry_read; + entry->get_info = &wfp_static_filesystem_entry_get_info; + entry->read = &wfp_static_filesystem_entry_read; entry->user_data = entry; entry->content = malloc(length); @@ -435,18 +435,18 @@ wfp_impl_static_filesystem_add( } void -wfp_impl_static_filesystem_add_text( +wfp_static_filesystem_add_text( struct wfp_static_filesystem * filesystem, char const * path, int mode, char const * content) { size_t length = strlen(content); - wfp_impl_static_filesystem_add(filesystem, path, mode, content, length); + wfp_static_filesystem_add(filesystem, path, mode, content, length); } void -wfp_impl_static_filesystem_add_file( +wfp_static_filesystem_add_file( struct wfp_static_filesystem * filesystem, char const * path, char const * filename) @@ -454,16 +454,16 @@ wfp_impl_static_filesystem_add_file( struct wf_path * path_ = wf_path_create(path); if (NULL != path_) { - size_t parent = wfp_impl_static_filesystem_make_parent(filesystem, path_); - struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_add_entry(filesystem); + size_t parent = wfp_static_filesystem_make_parent(filesystem, path_); + struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_add_entry(filesystem); entry->parent = parent; entry->is_file = true; entry->mode = 0; entry->content = strdup(filename); entry->size = 0; entry->name = strdup(wf_path_get_filename(path_)); - entry->get_info = &wfp_impl_static_filesystem_file_get_info; - entry->read = &wfp_impl_static_filesystem_file_read; + entry->get_info = &wfp_static_filesystem_file_get_info; + entry->read = &wfp_static_filesystem_file_read; entry->user_data = entry; wf_path_dispose(path_); @@ -471,7 +471,7 @@ wfp_impl_static_filesystem_add_file( } void -wfp_impl_static_filesystem_add_generic( +wfp_static_filesystem_add_generic( struct wfp_static_filesystem * filesystem, char const * path, wfp_static_filesystem_read_fn * read, @@ -481,8 +481,8 @@ wfp_impl_static_filesystem_add_generic( struct wf_path * path_ = wf_path_create(path); if (NULL != path_) { - size_t parent = wfp_impl_static_filesystem_make_parent(filesystem, path_); - struct wfp_static_filesystem_entry * entry = wfp_impl_static_filesystem_add_entry(filesystem); + size_t parent = wfp_static_filesystem_make_parent(filesystem, path_); + struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_add_entry(filesystem); entry->parent = parent; entry->is_file = true; entry->mode = 0; diff --git a/test/webfuse/utils/static_filesystem.h b/test/webfuse/utils/static_filesystem.h new file mode 100644 index 0000000..4f72b1b --- /dev/null +++ b/test/webfuse/utils/static_filesystem.h @@ -0,0 +1,77 @@ +#ifndef WFP_STATIC_FILESYSTEM_H +#define WFP_STATIC_FILESYSTEM_H + +#ifndef __cplusplus +#include +#else +#include +using ::std::size_t; +#endif + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct wfp_client_config; + +struct wfp_static_filesystem; + +typedef size_t +wfp_static_filesystem_read_fn( + size_t offset, + char * buffer, + size_t buffer_size, + void * user_data); + +typedef void +wfp_static_filesystem_get_info_fn( + void * user_data, + int * result_mode, + size_t * result_size); + + +extern WFP_API struct wfp_static_filesystem * +wfp_static_filesystem_create( + struct wfp_client_config * config); + +extern WFP_API void +wfp_static_filesystem_dispose( + struct wfp_static_filesystem * filesystem); + +extern WFP_API void +wfp_static_filesystem_add( + struct wfp_static_filesystem * filesystem, + char const * path, + int mode, + char const * content, + size_t length); + +extern WFP_API void +wfp_static_filesystem_add_text( + struct wfp_static_filesystem * filesystem, + char const * path, + int mode, + char const * content); + +extern WFP_API void +wfp_static_filesystem_add_file( + struct wfp_static_filesystem * filesystem, + char const * path, + char const * filename); + +extern WFP_API void +wfp_static_filesystem_add_generic( + struct wfp_static_filesystem * filesystem, + char const * path, + wfp_static_filesystem_read_fn * read, + wfp_static_filesystem_get_info_fn * get_info, + void * user_data); + +#ifdef __cplusplus +} +#endif + +#endif From 384de32bf5948f843dc32d0545f4dea40ad21e26 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Thu, 20 Feb 2020 19:06:38 +0100 Subject: [PATCH 03/16] removed some dead code --- test/webfuse/utils/static_filesystem.c | 91 -------------------------- test/webfuse/utils/static_filesystem.h | 14 ---- 2 files changed, 105 deletions(-) diff --git a/test/webfuse/utils/static_filesystem.c b/test/webfuse/utils/static_filesystem.c index 7212e7a..62b507a 100644 --- a/test/webfuse/utils/static_filesystem.c +++ b/test/webfuse/utils/static_filesystem.c @@ -136,45 +136,6 @@ wfp_static_filesystem_entry_get_info( *result_size = entry->size; } -static size_t -wfp_static_filesystem_file_read( - size_t offset, - char * buffer, - size_t buffer_size, - void * user_data) -{ - size_t result = 0; - struct wfp_static_filesystem_entry * entry = user_data; - char const * filename = entry->content; - - FILE * file = fopen(filename, "rb"); - if (NULL != file) - { - fseek(file, offset, SEEK_SET); - result = fread(buffer, buffer_size, 1, file); - fclose(file); - } - - return result; -} - -static void -wfp_static_filesystem_file_get_info( - void * user_data, - int * result_mode, - size_t * result_size) -{ - struct wfp_static_filesystem_entry * entry = user_data; - char const * filename = entry->content; - - struct stat buffer; - stat(filename, &buffer); - - *result_mode = (int) (buffer.st_mode & 0777); - *result_size = (size_t) buffer.st_size; -} - - static size_t wfp_static_filesystem_add_dir( struct wfp_static_filesystem * filesystem, @@ -444,55 +405,3 @@ wfp_static_filesystem_add_text( size_t length = strlen(content); wfp_static_filesystem_add(filesystem, path, mode, content, length); } - -void -wfp_static_filesystem_add_file( - struct wfp_static_filesystem * filesystem, - char const * path, - char const * filename) -{ - struct wf_path * path_ = wf_path_create(path); - if (NULL != path_) - { - size_t parent = wfp_static_filesystem_make_parent(filesystem, path_); - struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_add_entry(filesystem); - entry->parent = parent; - entry->is_file = true; - entry->mode = 0; - entry->content = strdup(filename); - entry->size = 0; - entry->name = strdup(wf_path_get_filename(path_)); - entry->get_info = &wfp_static_filesystem_file_get_info; - entry->read = &wfp_static_filesystem_file_read; - entry->user_data = entry; - - wf_path_dispose(path_); - } -} - -void -wfp_static_filesystem_add_generic( - struct wfp_static_filesystem * filesystem, - char const * path, - wfp_static_filesystem_read_fn * read, - wfp_static_filesystem_get_info_fn * get_info, - void * user_data) -{ - struct wf_path * path_ = wf_path_create(path); - if (NULL != path_) - { - size_t parent = wfp_static_filesystem_make_parent(filesystem, path_); - struct wfp_static_filesystem_entry * entry = wfp_static_filesystem_add_entry(filesystem); - entry->parent = parent; - entry->is_file = true; - entry->mode = 0; - entry->content = NULL; - entry->size = 0; - entry->name = strdup(wf_path_get_filename(path_)); - entry->get_info = get_info; - entry->read = read; - entry->user_data = user_data; - - wf_path_dispose(path_); - } -} diff --git a/test/webfuse/utils/static_filesystem.h b/test/webfuse/utils/static_filesystem.h index 4f72b1b..bf23b88 100644 --- a/test/webfuse/utils/static_filesystem.h +++ b/test/webfuse/utils/static_filesystem.h @@ -56,20 +56,6 @@ wfp_static_filesystem_add_text( int mode, char const * content); -extern WFP_API void -wfp_static_filesystem_add_file( - struct wfp_static_filesystem * filesystem, - char const * path, - char const * filename); - -extern WFP_API void -wfp_static_filesystem_add_generic( - struct wfp_static_filesystem * filesystem, - char const * path, - wfp_static_filesystem_read_fn * read, - wfp_static_filesystem_get_info_fn * get_info, - void * user_data); - #ifdef __cplusplus } #endif From 4b418a45d4b34938f5d1c13e968cb6ea75ddd8d9 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Thu, 20 Feb 2020 20:13:39 +0100 Subject: [PATCH 04/16] chore: refactored test --- .../tests/provider/test_client_protocol.cc | 92 +++++++++++-------- 1 file changed, 53 insertions(+), 39 deletions(-) diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index ef058f7..4faba4f 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -15,58 +15,72 @@ using testing::_; namespace { -struct Context +class ClientProtocolTest: public ::testing::Test { - lws_context * context; - std::atomic isShutdownRequested; -}; - -void run(Context * context) -{ - while (!context->isShutdownRequested) +protected: + void SetUp() { - lws_service(context->context, 100); + server = new FakeAdapterServer(54321); + + config = wfp_client_config_create(); + protocol = wfp_client_protocol_create(config); + + struct lws_protocols protocols[2]; + memset(protocols, 0, sizeof(struct lws_protocols) * 2); + protocols[0].name = "fs"; + wfp_client_protocol_init_lws(protocol, &protocols[0]); + + struct lws_context_creation_info info; + memset(&info, 0, sizeof(struct lws_context_creation_info)); + info.port = CONTEXT_PORT_NO_LISTEN; + info.protocols = protocols; + info.uid = -1; + info.gid = -1; + + context = lws_create_context(&info); + wfp_client_protocol_connect(protocol, context, "ws://localhost:54321/"); + + isShutdownRequested = false; + thread = std::thread(run, this); } -} + void TearDown() + { + isShutdownRequested = true; + thread.join(); -} + lws_context_destroy(context); + wfp_client_protocol_dispose(protocol); + wfp_client_config_dispose(config); -TEST(client_protocol, connect) -{ - FakeAdapterServer server(54321); + delete server; + } - wfp_client_config * config = wfp_client_config_create(); - wfp_client_protocol * protocol = wfp_client_protocol_create(config); + FakeAdapterServer * server; - struct lws_protocols protocols[2]; - memset(protocols, 0, sizeof(struct lws_protocols) * 2); - protocols[0].name = "fs"; - wfp_client_protocol_init_lws(protocol, &protocols[0]); +private: + static void run(ClientProtocolTest * self) + { + while (!self->isShutdownRequested) + { + lws_service(self->context, 100); + } + } - struct lws_context_creation_info info; - memset(&info, 0, sizeof(struct lws_context_creation_info)); - info.port = CONTEXT_PORT_NO_LISTEN; - info.protocols = protocols; - info.uid = -1; - info.gid = -1; + wfp_client_config * config; + wfp_client_protocol * protocol; + std::thread thread; + std::atomic isShutdownRequested; + lws_context * context; - struct lws_context * context = lws_create_context(&info); - wfp_client_protocol_connect(protocol, context, "ws://localhost:54321/"); +}; - Context ctx; - ctx.context = context; - ctx.isShutdownRequested = false; - std::thread client_thread(run, &ctx); - server.waitForConnection(); - - ctx.isShutdownRequested = true; - client_thread.join(); +} - lws_context_destroy(context); - wfp_client_protocol_dispose(protocol); - wfp_client_config_dispose(config); +TEST_F(ClientProtocolTest, connect) +{ + server->waitForConnection(); } \ No newline at end of file From 1a1367eae75cf9a403da1fb18b144e86c89b3798 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 22 Feb 2020 15:55:32 +0100 Subject: [PATCH 05/16] fixed typo --- doc/protocol.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/protocol.md b/doc/protocol.md index 5245b3d..32eaa9d 100644 --- a/doc/protocol.md +++ b/doc/protocol.md @@ -227,7 +227,7 @@ Read from an open file. Adds a filesystem. - fs provider: {"method": "add_filesytem", "params": [], "id": } + fs provider: {"method": "add_filesystem", "params": [], "id": } webfuse daemon: {"result": {"id": }, "id": } | Item | Data type | Description | From e21c716d348d8d71bf109f95f40b9c54a5411644 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 22 Feb 2020 16:46:21 +0100 Subject: [PATCH 06/16] refactored fake adapter server into ws server; added test for client protocol getattr --- cmake/unit_tests.cmake | 2 +- test/webfuse/fakes/fake_adapter_server.hpp | 24 ------ .../tests/provider/test_client_protocol.cc | 65 ++++++++++++++- .../ws_server.cc} | 83 ++++++++++++++----- test/webfuse/utils/ws_server.hpp | 27 ++++++ 5 files changed, 153 insertions(+), 48 deletions(-) delete mode 100644 test/webfuse/fakes/fake_adapter_server.hpp rename test/webfuse/{fakes/fake_adapter_server.cc => utils/ws_server.cc} (68%) create mode 100644 test/webfuse/utils/ws_server.hpp diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index dfc804e..3e445ed 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -14,7 +14,7 @@ add_executable(alltests test/webfuse/utils/timeout_watcher.cc test/webfuse/utils/path.c test/webfuse/utils/static_filesystem.c - test/webfuse/fakes/fake_adapter_server.cc + test/webfuse/utils/ws_server.cc test/webfuse/mocks/mock_authenticator.cc test/webfuse/mocks/mock_request.cc test/webfuse/tests/core/test_container_of.cc diff --git a/test/webfuse/fakes/fake_adapter_server.hpp b/test/webfuse/fakes/fake_adapter_server.hpp deleted file mode 100644 index 9cc51f0..0000000 --- a/test/webfuse/fakes/fake_adapter_server.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef WF_TEST_FAKE_SERVER_HPP -#define WF_TEST_FAKE_SERVER_HPP - -#include - -namespace webfuse_test -{ - -class FakeAdapterServer -{ - FakeAdapterServer(FakeAdapterServer const &) = delete; - FakeAdapterServer & operator=(FakeAdapterServer const &) = delete; -public: - explicit FakeAdapterServer(int port); - ~FakeAdapterServer(); - void waitForConnection(); -private: - class Private; - Private * d; -}; - -} - -#endif diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index 4faba4f..5212f45 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -3,13 +3,13 @@ #include #include -#include "webfuse/fakes/fake_adapter_server.hpp" +#include "webfuse/utils/ws_server.hpp" #include #include #include -using webfuse_test::FakeAdapterServer; +using webfuse_test::WebsocketServer; using testing::_; namespace @@ -20,7 +20,7 @@ class ClientProtocolTest: public ::testing::Test protected: void SetUp() { - server = new FakeAdapterServer(54321); + server = new WebsocketServer(54321); config = wfp_client_config_create(); protocol = wfp_client_protocol_create(config); @@ -57,7 +57,40 @@ protected: delete server; } - FakeAdapterServer * server; + void awaitAddFilesystem(std::string& filesystemName) + { + json_t * addFilesystemRequest = server->receiveMessage(); + ASSERT_NE(nullptr, addFilesystemRequest); + ASSERT_TRUE(json_is_object(addFilesystemRequest)); + + json_t * method = json_object_get(addFilesystemRequest, "method"); + ASSERT_TRUE(json_is_string(method)); + ASSERT_STREQ("add_filesystem", json_string_value(method)); + + json_t * params = json_object_get(addFilesystemRequest, "params"); + ASSERT_TRUE(json_is_array(params)); + ASSERT_EQ(1, json_array_size(params)); + + json_t * filesystem = json_array_get(params, 0); + ASSERT_TRUE(json_is_string(filesystem)); + filesystemName = json_string_value(filesystem); + + json_t * id = json_object_get(addFilesystemRequest, "id"); + ASSERT_TRUE(json_is_integer(id)); + + json_t * response = json_object(); + json_t * result = json_object(); + json_object_set(result, "id", filesystem); + json_object_set_new(response, "result", result); + json_object_set(response, "id", id); + + server->sendMessage(response); + + json_decref(addFilesystemRequest); + + } + + WebsocketServer * server; private: static void run(ClientProtocolTest * self) @@ -77,10 +110,34 @@ private: }; + } TEST_F(ClientProtocolTest, connect) { server->waitForConnection(); +} + +TEST_F(ClientProtocolTest, getattr) +{ + server->waitForConnection(); + + std::string filesystem; + awaitAddFilesystem(filesystem); + if (HasFatalFailure()) { return; } + + json_t * params = json_array(); + json_array_append_new(params, json_string(filesystem.c_str())); + json_array_append_new(params, json_integer(1)); + json_t * request = json_object(); + json_object_set_new(request, "method", json_string("getattr")); + json_object_set_new(request, "params", params); + json_object_set_new(request, "id", json_integer(42)); + + server->sendMessage(request); + json_t * response = server->receiveMessage(); + ASSERT_TRUE(json_is_object(response)); + + json_decref(response); } \ No newline at end of file diff --git a/test/webfuse/fakes/fake_adapter_server.cc b/test/webfuse/utils/ws_server.cc similarity index 68% rename from test/webfuse/fakes/fake_adapter_server.cc rename to test/webfuse/utils/ws_server.cc index bebd3d9..995d0b8 100644 --- a/test/webfuse/fakes/fake_adapter_server.cc +++ b/test/webfuse/utils/ws_server.cc @@ -1,4 +1,4 @@ -#include "webfuse/fakes/fake_adapter_server.hpp" +#include "webfuse/utils/ws_server.hpp" #include "webfuse/utils/timeout_watcher.hpp" #include "webfuse/core/util.h" @@ -30,7 +30,7 @@ public: extern "C" { -static int wf_test_fake_adapter_server_callback( +static int wf_test_utils_ws_server_callback( struct lws * wsi, enum lws_callback_reasons reason, void * WF_UNUSED_PARAM(user), @@ -65,7 +65,6 @@ static int wf_test_fake_adapter_server_callback( break; } - return 0; } @@ -74,16 +73,15 @@ static int wf_test_fake_adapter_server_callback( namespace webfuse_test { -class FakeAdapterServer::Private: public IServer +class WebsocketServer::Private: public IServer { public: explicit Private(int port) : client_wsi(nullptr) - , message_received(false) { memset(ws_protocols, 0, sizeof(struct lws_protocols) * 2); ws_protocols[0].name = "fs"; - ws_protocols[0].callback = &wf_test_fake_adapter_server_callback; + ws_protocols[0].callback = &wf_test_utils_ws_server_callback; ws_protocols[0].per_session_data_size = 0; ws_protocols[0].user = reinterpret_cast(this); @@ -114,6 +112,44 @@ public: } } + void sendMessage(json_t * message) + { + char* message_text = json_dumps(message, JSON_COMPACT); + writeQueue.push(message_text); + json_decref(message); + free(message_text); + + if (nullptr != client_wsi) + { + lws_callback_on_writable(client_wsi); + + TimeoutWatcher watcher(DEFAULT_TIMEOUT); + while (!writeQueue.empty()) + { + watcher.check(); + lws_service(context, 100); + } + } + + } + + json_t * receiveMessage() + { + TimeoutWatcher watcher(DEFAULT_TIMEOUT); + + while (recvQueue.empty()) + { + watcher.check(); + lws_service(context, 100); + } + + std::string const & message_text = recvQueue.front(); + json_t * message = json_loads(message_text.c_str(), JSON_DECODE_ANY, nullptr); + recvQueue.pop(); + + return message; + } + void onConnectionEstablished(struct lws * wsi) override { client_wsi = wsi; @@ -131,24 +167,23 @@ public: { if (wsi == client_wsi) { - last_message.assign(length, *data); - message_received = true; + recvQueue.push(std::string(data, length)); } } void onWritable(struct lws * wsi) override { - if (!queue.empty()) + if (!writeQueue.empty()) { - std::string const & message = queue.front(); + std::string const & message = writeQueue.front(); unsigned char * data = new unsigned char[LWS_PRE + message.size()]; memcpy(&data[LWS_PRE], message.c_str(), message.size()); lws_write(wsi, &data[LWS_PRE], message.size(), LWS_WRITE_TEXT); delete[] data; - queue.pop(); - if (!queue.empty()) + writeQueue.pop(); + if (!writeQueue.empty()) { lws_callback_on_writable(wsi); } @@ -161,36 +196,46 @@ private: { if (nullptr != client_wsi) { - queue.push(message); + writeQueue.push(message); lws_callback_on_writable(client_wsi); } } struct lws * client_wsi; - bool message_received; struct lws_protocols ws_protocols[2]; struct lws_context_creation_info info; struct lws_context * context; - std::vector last_message; - std::queue queue; + std::queue writeQueue; + std::queue recvQueue; }; -FakeAdapterServer::FakeAdapterServer(int port) +WebsocketServer::WebsocketServer(int port) : d(new Private(port)) { } -FakeAdapterServer::~FakeAdapterServer() +WebsocketServer::~WebsocketServer() { delete d; } -void FakeAdapterServer::waitForConnection() +void WebsocketServer::waitForConnection() { d->waitForConnection(); } +void WebsocketServer::sendMessage(json_t * message) +{ + d->sendMessage(message); +} + +json_t * WebsocketServer::receiveMessage() +{ + return d->receiveMessage(); +} + + } \ No newline at end of file diff --git a/test/webfuse/utils/ws_server.hpp b/test/webfuse/utils/ws_server.hpp new file mode 100644 index 0000000..bacab51 --- /dev/null +++ b/test/webfuse/utils/ws_server.hpp @@ -0,0 +1,27 @@ +#ifndef WF_TEST_UTILS_WS_SERVER_HPP +#define WF_TEST_UTILS_WS_SERVER_HPP + +#include +#include + +namespace webfuse_test +{ + +class WebsocketServer +{ + WebsocketServer(WebsocketServer const &) = delete; + WebsocketServer & operator=(WebsocketServer const &) = delete; +public: + explicit WebsocketServer(int port); + ~WebsocketServer(); + void waitForConnection(); + void sendMessage(json_t * message); + json_t * receiveMessage(); +private: + class Private; + Private * d; +}; + +} + +#endif From c6265aeaf74906c0c51cfe400dd6dba7692f3285 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 22 Feb 2020 16:49:56 +0100 Subject: [PATCH 07/16] chore: added default ctor for ClientProtocolTest (to initialize members properly) --- test/webfuse/tests/provider/test_client_protocol.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index 5212f45..409efc3 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -17,6 +17,15 @@ namespace class ClientProtocolTest: public ::testing::Test { +public: + ClientProtocolTest() + : server(nullptr) + , config(nullptr) + , protocol(nullptr) + { + // empty + } + protected: void SetUp() { From 77810168e04950e57872d66da51c1fb57ab55d73 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sat, 22 Feb 2020 16:58:11 +0100 Subject: [PATCH 08/16] fix: initialize context --- test/webfuse/tests/provider/test_client_protocol.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index 409efc3..beeaf52 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -22,6 +22,7 @@ public: : server(nullptr) , config(nullptr) , protocol(nullptr) + , context(nullptr) { // empty } From 8841ac40f82befdcced3fc2e61252b580c12b0cc Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 23 Feb 2020 21:01:05 +0100 Subject: [PATCH 09/16] add toString function for lws reasons (for debugging and logging purposes) --- cmake/webfuse_core.cmake | 1 + lib/webfuse/core/lws_utils.c | 210 +++++++++++++++++++++++++++++++++++ lib/webfuse/core/lws_utils.h | 19 ++++ 3 files changed, 230 insertions(+) create mode 100644 lib/webfuse/core/lws_utils.c create mode 100644 lib/webfuse/core/lws_utils.h diff --git a/cmake/webfuse_core.cmake b/cmake/webfuse_core.cmake index 52c7681..3daded5 100644 --- a/cmake/webfuse_core.cmake +++ b/cmake/webfuse_core.cmake @@ -8,6 +8,7 @@ add_library(webfuse-core STATIC lib/webfuse/core/string.c lib/webfuse/core/base64.c lib/webfuse/core/lws_log.c + lib/webfuse/core/lws_utils.c ) set_target_properties(webfuse-core PROPERTIES OUTPUT_NAME webfuse-core) diff --git a/lib/webfuse/core/lws_utils.c b/lib/webfuse/core/lws_utils.c new file mode 100644 index 0000000..700b084 --- /dev/null +++ b/lib/webfuse/core/lws_utils.c @@ -0,0 +1,210 @@ +#include "webfuse/core/lws_utils.h" + +extern char const * +wf_lws_reason_tostring( + enum lws_callback_reasons reason) +{ + switch (reason) + { + case LWS_CALLBACK_PROTOCOL_INIT: + return "protocol_init"; + case LWS_CALLBACK_PROTOCOL_DESTROY: + return "protcol_destory"; + case LWS_CALLBACK_WSI_CREATE: + return "wsi_create"; + case LWS_CALLBACK_WSI_DESTROY: + return "wsi_destroy"; + case LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS: + return "openssl_load_extra_client_verify_certs"; + case LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS: + return "openssl_load_extra_server_verify_certs"; + case LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION: + return "openssl_perform_client_cert_verification"; + case LWS_CALLBACK_OPENSSL_PERFORM_SERVER_CERT_VERIFICATION: + return "openssl_perform_server_cert_verification"; + case LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY: + return "openssl_context_required_private_key"; + case LWS_CALLBACK_SSL_INFO: + return "ssl_info"; + case LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED: + return "server_new_client_instantiated"; + case LWS_CALLBACK_HTTP: + return "http"; + case LWS_CALLBACK_HTTP_BODY: + return "http_body"; + case LWS_CALLBACK_HTTP_BODY_COMPLETION: + return "http_body_completion"; + case LWS_CALLBACK_HTTP_FILE_COMPLETION: + return "http_file_completion"; + case LWS_CALLBACK_HTTP_WRITEABLE: + return "http_writeable"; + case LWS_CALLBACK_CLOSED_HTTP: + return "closed_http"; + case LWS_CALLBACK_FILTER_HTTP_CONNECTION: + return "filter_http_connection"; + case LWS_CALLBACK_ADD_HEADERS: + return "add_headers"; + case LWS_CALLBACK_CHECK_ACCESS_RIGHTS: + return "check_access_rights"; + case LWS_CALLBACK_PROCESS_HTML: + return "process_html"; + case LWS_CALLBACK_HTTP_BIND_PROTOCOL: + return "http_bind_protocol"; + case LWS_CALLBACK_HTTP_DROP_PROTOCOL: + return "http_drop_protocol"; + case LWS_CALLBACK_HTTP_CONFIRM_UPGRADE: + return "http_confirm_upgrade"; + case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: + return "established_client_http"; + case LWS_CALLBACK_CLOSED_CLIENT_HTTP: + return "closed_http_client"; + case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ: + return "receive_client_http_read"; + case LWS_CALLBACK_COMPLETED_CLIENT_HTTP: + return "completed_client_http"; + case LWS_CALLBACK_CLIENT_HTTP_WRITEABLE: + return "client_http_writeable"; + case LWS_CALLBACK_CLIENT_HTTP_BIND_PROTOCOL: + return "client_http_bind_protocol"; + case LWS_CALLBACK_CLIENT_HTTP_DROP_PROTOCOL: + return "client_http_drop_protocol"; + case LWS_CALLBACK_ESTABLISHED: + return "established"; + case LWS_CALLBACK_CLOSED: + return "closed"; + case LWS_CALLBACK_SERVER_WRITEABLE: + return "server_writeable"; + case LWS_CALLBACK_RECEIVE: + return "receive"; + case LWS_CALLBACK_RECEIVE_PONG: + return "receive_pong"; + case LWS_CALLBACK_WS_PEER_INITIATED_CLOSE: + return "ws_peer_initiated_close"; + case LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION: + return "filter_protocol_connection"; + case LWS_CALLBACK_CONFIRM_EXTENSION_OKAY: + return "confirm_extension_okay"; + case LWS_CALLBACK_WS_SERVER_BIND_PROTOCOL: + return "ws_server_bind_protocol"; + case LWS_CALLBACK_WS_SERVER_DROP_PROTOCOL: + return "ws_server_drop_protocol"; + case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: + return "client_connection_error"; + case LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH: + return "client_filter_pre_establish"; + case LWS_CALLBACK_CLIENT_ESTABLISHED: + return "client_established"; + case LWS_CALLBACK_CLIENT_CLOSED: + return "client_closed"; + case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: + return "client_append_handshake_header"; + case LWS_CALLBACK_CLIENT_RECEIVE: + return "client_receive"; + case LWS_CALLBACK_CLIENT_RECEIVE_PONG: + return "client_receive_pong"; + case LWS_CALLBACK_CLIENT_WRITEABLE: + return "client_writeable"; + case LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED: + return "client_confirm_extension_supported"; + case LWS_CALLBACK_WS_EXT_DEFAULTS: + return "ws_ext_defaults"; + case LWS_CALLBACK_FILTER_NETWORK_CONNECTION: + return "filter_network_connection"; + case LWS_CALLBACK_WS_CLIENT_BIND_PROTOCOL: + return "ws_client_bind_protocol"; + case LWS_CALLBACK_WS_CLIENT_DROP_PROTOCOL: + return "ws_client_drop_protocol"; + case LWS_CALLBACK_GET_THREAD_ID: + return "get_thread_id"; + case LWS_CALLBACK_ADD_POLL_FD: + return "add_poll_fd"; + case LWS_CALLBACK_DEL_POLL_FD: + return "del_poll_fd"; + case LWS_CALLBACK_CHANGE_MODE_POLL_FD: + return "change_mode_poll_fd"; + case LWS_CALLBACK_LOCK_POLL: + return "lock_poll"; + case LWS_CALLBACK_UNLOCK_POLL: + return "unlock_poll"; + case LWS_CALLBACK_CGI: + return "cgi"; + case LWS_CALLBACK_CGI_TERMINATED: + return "cgi_terminated"; + case LWS_CALLBACK_CGI_STDIN_DATA: + return "cgi_stdin_data"; + case LWS_CALLBACK_CGI_STDIN_COMPLETED: + return "cgi_stdin_completed"; + case LWS_CALLBACK_CGI_PROCESS_ATTACH: + return "cgi_process_attach"; + case LWS_CALLBACK_SESSION_INFO: + return "session_info"; + case LWS_CALLBACK_GS_EVENT: + return "gs_event"; + case LWS_CALLBACK_HTTP_PMO: + return "http_pmo"; + case LWS_CALLBACK_RAW_PROXY_CLI_RX: + return "raw_proxy_cli_rx"; + case LWS_CALLBACK_RAW_PROXY_SRV_RX: + return "raw_proxy_srv_rx"; + case LWS_CALLBACK_RAW_PROXY_CLI_CLOSE: + return "raw_proxy_cli_close"; + case LWS_CALLBACK_RAW_PROXY_SRV_CLOSE: + return "raw_proxy_srv_close"; + case LWS_CALLBACK_RAW_PROXY_CLI_WRITEABLE: + return "raw_proxy_cli_writeable"; + case LWS_CALLBACK_RAW_PROXY_SRV_WRITEABLE: + return "raw_prxy_srv_wrtieable"; + case LWS_CALLBACK_RAW_PROXY_CLI_ADOPT: + return "raw_proxy_cli_adopt"; + case LWS_CALLBACK_RAW_PROXY_SRV_ADOPT: + return "raw_proxy_srv_adopt"; + case LWS_CALLBACK_RAW_PROXY_CLI_BIND_PROTOCOL: + return "raw_proxy_cli_bind_protocol"; + case LWS_CALLBACK_RAW_PROXY_SRV_BIND_PROTOCOL: + return "raw_proxy_srv_bind_protocol"; + case LWS_CALLBACK_RAW_PROXY_CLI_DROP_PROTOCOL: + return "raw_proxy_cli_drop_protocol"; + case LWS_CALLBACK_RAW_PROXY_SRV_DROP_PROTOCOL: + return "raw_proxy_srv_drop_protocol"; + case LWS_CALLBACK_RAW_RX: + return "raw_rx"; + case LWS_CALLBACK_RAW_CLOSE: + return "raw_close"; + case LWS_CALLBACK_RAW_WRITEABLE: + return "raw_writeable"; + case LWS_CALLBACK_RAW_ADOPT: + return "raw_adopt"; + case LWS_CALLBACK_RAW_CONNECTED: + return "raw_connected"; + case LWS_CALLBACK_RAW_SKT_BIND_PROTOCOL: + return "raw_skt_bind_protocol"; + case LWS_CALLBACK_RAW_SKT_DROP_PROTOCOL: + return "raw_skt_drop_protocol"; + case LWS_CALLBACK_RAW_ADOPT_FILE: + return "raw_adopt_file"; + case LWS_CALLBACK_RAW_RX_FILE: + return "raw_rx_file"; + case LWS_CALLBACK_RAW_WRITEABLE_FILE: + return "raw_writeable_file"; + case LWS_CALLBACK_RAW_CLOSE_FILE: + return "raw_close_file"; + case LWS_CALLBACK_RAW_FILE_BIND_PROTOCOL: + return "raw_file_bind_protocol"; + case LWS_CALLBACK_RAW_FILE_DROP_PROTOCOL: + return "raw_file_drop_protocol"; + case LWS_CALLBACK_TIMER: + return "timer"; + case LWS_CALLBACK_EVENT_WAIT_CANCELLED: + return "event_wait_cancelled"; + case LWS_CALLBACK_CHILD_CLOSING: + return "child_closing"; + case LWS_CALLBACK_VHOST_CERT_AGING: + return "vhost_cert_aging"; + case LWS_CALLBACK_VHOST_CERT_UPDATE: + return "vhost_cert_update"; + case LWS_CALLBACK_USER: + return "user"; + default: + return ""; + } +} diff --git a/lib/webfuse/core/lws_utils.h b/lib/webfuse/core/lws_utils.h new file mode 100644 index 0000000..d97ed69 --- /dev/null +++ b/lib/webfuse/core/lws_utils.h @@ -0,0 +1,19 @@ +#ifndef WF_LWS_UTILS_H +#define WF_LWS_UTILS_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern char const * +wf_lws_reason_tostring( + enum lws_callback_reasons reason); + +#ifdef __cplusplus +} +#endif + +#endif From 555058dbb578908576315b559a9c764325743814 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 23 Feb 2020 21:02:01 +0100 Subject: [PATCH 10/16] made client protocol test single threaded --- include/webfuse/core/protocol_names.h | 21 ++++++++ include/webfuse_adapter.h | 1 + include/webfuse_provider.h | 1 + lib/webfuse/adapter/impl/server.c | 1 - lib/webfuse/adapter/impl/server_protocol.c | 2 + lib/webfuse/provider/impl/client.c | 1 - lib/webfuse/provider/impl/client_protocol.c | 8 +-- lib/webfuse/provider/impl/client_protocol.h | 2 - .../tests/provider/test_client_protocol.cc | 53 ++++++------------- test/webfuse/utils/ws_server.cc | 37 ++++++++++--- test/webfuse/utils/ws_server.hpp | 2 + 11 files changed, 78 insertions(+), 51 deletions(-) create mode 100644 include/webfuse/core/protocol_names.h diff --git a/include/webfuse/core/protocol_names.h b/include/webfuse/core/protocol_names.h new file mode 100644 index 0000000..4de8c4a --- /dev/null +++ b/include/webfuse/core/protocol_names.h @@ -0,0 +1,21 @@ +//////////////////////////////////////////////////////////////////////////////// +/// \file protocol_names.h +/// \brief Names of websocket protocol. +//////////////////////////////////////////////////////////////////////////////// +#ifndef WF_PROTOCOL_NAMES_H +#define WF_PROTOCOL_NAMES_H + + +//------------------------------------------------------------------------------ +/// \def WF_PROTOCOL_NAME_ADAPTER_SERVER +/// \brief Name of the websocket protocol an adapter server is running. +//------------------------------------------------------------------------------ +#define WF_PROTOCOL_NAME_ADAPTER_SERVER ("webfuse-adapter-server") + +//------------------------------------------------------------------------------ +/// \def WF_PROTOCOL_NAME_PROVIDER_CLIENT +/// \brief Name of the websocket protocol an provider client is running. +//------------------------------------------------------------------------------ +#define WF_PROTOCOL_NAME_PROVIDER_CLIENT ("webfuse-provider-client") + +#endif diff --git a/include/webfuse_adapter.h b/include/webfuse_adapter.h index af37c14..1ff048f 100644 --- a/include/webfuse_adapter.h +++ b/include/webfuse_adapter.h @@ -7,6 +7,7 @@ #define WF_ADAPTER_H #include +#include #include #include diff --git a/include/webfuse_provider.h b/include/webfuse_provider.h index bd119ac..7af3934 100644 --- a/include/webfuse_provider.h +++ b/include/webfuse_provider.h @@ -7,6 +7,7 @@ #define WF_PROVIDER_H #include +#include #include #include diff --git a/lib/webfuse/adapter/impl/server.c b/lib/webfuse/adapter/impl/server.c index ad3e5c2..bf32b85 100644 --- a/lib/webfuse/adapter/impl/server.c +++ b/lib/webfuse/adapter/impl/server.c @@ -38,7 +38,6 @@ static struct lws_context * wf_impl_server_context_create( memset(server->ws_protocols, 0, sizeof(struct lws_protocols) * WF_SERVER_PROTOCOL_COUNT); server->ws_protocols[0].name = "http"; server->ws_protocols[0].callback = lws_callback_http_dummy; - server->ws_protocols[1].name = "fs"; wf_impl_server_protocol_init_lws(&server->protocol, &server->ws_protocols[1]); memset(&server->mount, 0, sizeof(struct lws_http_mount)); diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index 02efd80..74d4631 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -6,6 +6,7 @@ #include "webfuse/core/message.h" #include "webfuse/core/util.h" +#include "webfuse/core/protocol_names.h" #include "webfuse/adapter/impl/credentials.h" #include "webfuse/adapter/impl/jsonrpc/request.h" @@ -121,6 +122,7 @@ void wf_impl_server_protocol_init_lws( struct wf_server_protocol * protocol, struct lws_protocols * lws_protocol) { + lws_protocol->name = WF_PROTOCOL_NAME_ADAPTER_SERVER; lws_protocol->callback = &wf_impl_server_protocol_callback; lws_protocol->per_session_data_size = 0; lws_protocol->user = protocol; diff --git a/lib/webfuse/provider/impl/client.c b/lib/webfuse/provider/impl/client.c index 8b3c06b..4ddae92 100644 --- a/lib/webfuse/provider/impl/client.c +++ b/lib/webfuse/provider/impl/client.c @@ -35,7 +35,6 @@ struct wfp_client * wfp_impl_client_create( wfp_impl_client_protocol_init(&client->protocol, &config->provider, config->user_data); memset(client->protocols, 0, sizeof(struct lws_protocols) * WFP_CLIENT_PROTOCOL_COUNT); - client->protocols[0].name = WFP_CLIENT_PROTOCOL_NAME; wfp_impl_client_protocol_init_lws(&client->protocol, &client->protocols[0]); memset(&client->info, 0, sizeof(struct lws_context_creation_info)); diff --git a/lib/webfuse/provider/impl/client_protocol.c b/lib/webfuse/provider/impl/client_protocol.c index 6d5ba85..59945bd 100644 --- a/lib/webfuse/provider/impl/client_protocol.c +++ b/lib/webfuse/provider/impl/client_protocol.c @@ -6,7 +6,6 @@ #include #include - #include "webfuse/provider/impl/client_config.h" #include "webfuse/provider/impl/provider.h" #include "webfuse/core/util.h" @@ -14,6 +13,7 @@ #include "webfuse/core/message_queue.h" #include "webfuse/core/container_of.h" #include "webfuse/provider/impl/url.h" +#include "webfuse/core/protocol_names.h" static void wfp_impl_client_protocol_respond( json_t * response, @@ -112,7 +112,7 @@ static int wfp_impl_client_protocol_callback( // fall-through case LWS_CALLBACK_CLIENT_WRITEABLE: if ((wsi == protocol->wsi) && (!wf_slist_empty(&protocol->messages))) - { + { struct wf_slist_item * item = wf_slist_remove_first(&protocol->messages); struct wf_message * message = wf_container_of(item, struct wf_message, item); lws_write(wsi, (unsigned char*) message->data, message->length, LWS_WRITE_TEXT); @@ -180,6 +180,7 @@ void wfp_impl_client_protocol_init_lws( struct wfp_client_protocol * protocol, struct lws_protocols * lws_protocol) { + lws_protocol->name = WF_PROTOCOL_NAME_PROVIDER_CLIENT; lws_protocol->callback = &wfp_impl_client_protocol_callback; lws_protocol->per_session_data_size = 0; lws_protocol->user = protocol; @@ -203,7 +204,8 @@ void wfp_impl_client_protocol_connect( info.host = info.address; info.origin = info.address; info.ssl_connection = (url_data.use_tls) ? LCCSCF_USE_SSL : 0; - info.protocol = WFP_CLIENT_PROTOCOL_NAME; + info.protocol = WF_PROTOCOL_NAME_ADAPTER_SERVER; + info.local_protocol_name = WF_PROTOCOL_NAME_PROVIDER_CLIENT; info.pwsi = &protocol->wsi; lws_client_connect_via_info(&info); diff --git a/lib/webfuse/provider/impl/client_protocol.h b/lib/webfuse/provider/impl/client_protocol.h index d197559..d6f537d 100644 --- a/lib/webfuse/provider/impl/client_protocol.h +++ b/lib/webfuse/provider/impl/client_protocol.h @@ -11,8 +11,6 @@ extern "C" { #endif -#define WFP_CLIENT_PROTOCOL_NAME ("fs") - struct wfp_client_config; struct lws_protocols; struct lws_context; diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index beeaf52..b602e58 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -22,7 +22,6 @@ public: : server(nullptr) , config(nullptr) , protocol(nullptr) - , context(nullptr) { // empty } @@ -30,41 +29,29 @@ public: protected: void SetUp() { - server = new WebsocketServer(54321); - config = wfp_client_config_create(); protocol = wfp_client_protocol_create(config); - struct lws_protocols protocols[2]; - memset(protocols, 0, sizeof(struct lws_protocols) * 2); - protocols[0].name = "fs"; - wfp_client_protocol_init_lws(protocol, &protocols[0]); - - struct lws_context_creation_info info; - memset(&info, 0, sizeof(struct lws_context_creation_info)); - info.port = CONTEXT_PORT_NO_LISTEN; - info.protocols = protocols; - info.uid = -1; - info.gid = -1; + struct lws_protocols client_protocol; + memset(&client_protocol, 0, sizeof(struct lws_protocols)); + wfp_client_protocol_init_lws(protocol, &client_protocol); - context = lws_create_context(&info); - wfp_client_protocol_connect(protocol, context, "ws://localhost:54321/"); - - isShutdownRequested = false; - thread = std::thread(run, this); + server = new WebsocketServer(54321, &client_protocol, 1); } void TearDown() { - isShutdownRequested = true; - thread.join(); - - lws_context_destroy(context); + delete server; wfp_client_protocol_dispose(protocol); wfp_client_config_dispose(config); - delete server; + } + + void connect() + { + wfp_client_protocol_connect(protocol, server->getContext(), "ws://localhost:54321/"); + server->waitForConnection(); } void awaitAddFilesystem(std::string& filesystemName) @@ -103,20 +90,8 @@ protected: WebsocketServer * server; private: - static void run(ClientProtocolTest * self) - { - while (!self->isShutdownRequested) - { - lws_service(self->context, 100); - } - } - wfp_client_config * config; wfp_client_protocol * protocol; - std::thread thread; - std::atomic isShutdownRequested; - lws_context * context; - }; @@ -126,12 +101,14 @@ private: TEST_F(ClientProtocolTest, connect) { - server->waitForConnection(); + connect(); + if (HasFatalFailure()) { return; } } TEST_F(ClientProtocolTest, getattr) { - server->waitForConnection(); + connect(); + if (HasFatalFailure()) { return; } std::string filesystem; awaitAddFilesystem(filesystem); diff --git a/test/webfuse/utils/ws_server.cc b/test/webfuse/utils/ws_server.cc index 995d0b8..48e2588 100644 --- a/test/webfuse/utils/ws_server.cc +++ b/test/webfuse/utils/ws_server.cc @@ -2,6 +2,7 @@ #include "webfuse/utils/timeout_watcher.hpp" #include "webfuse/core/util.h" +#include "webfuse/core/protocol_names.h" #include #include #include @@ -76,15 +77,22 @@ namespace webfuse_test class WebsocketServer::Private: public IServer { public: - explicit Private(int port) + Private(int port, struct lws_protocols * additionalProtocols, size_t additionalProtocolsCount) : client_wsi(nullptr) { - memset(ws_protocols, 0, sizeof(struct lws_protocols) * 2); - ws_protocols[0].name = "fs"; + ws_protocols = new struct lws_protocols[2 + additionalProtocolsCount]; + memset(ws_protocols, 0, sizeof(struct lws_protocols) * (2 + additionalProtocolsCount)); + + ws_protocols[0].name = WF_PROTOCOL_NAME_ADAPTER_SERVER; ws_protocols[0].callback = &wf_test_utils_ws_server_callback; ws_protocols[0].per_session_data_size = 0; ws_protocols[0].user = reinterpret_cast(this); + if (0 < additionalProtocolsCount) + { + memcpy(&ws_protocols[additionalProtocolsCount], additionalProtocols, sizeof(struct lws_protocols) * additionalProtocolsCount); + } + memset(&info, 0, sizeof(struct lws_context_creation_info)); info.port = port; info.mounts = NULL; @@ -94,11 +102,18 @@ public: info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; context = lws_create_context(&info); + } virtual ~Private() { lws_context_destroy(context); + delete[] ws_protocols; + } + + struct lws_context * getContext() + { + return context; } void waitForConnection() @@ -130,7 +145,6 @@ public: lws_service(context, 100); } } - } json_t * receiveMessage() @@ -203,7 +217,7 @@ private: struct lws * client_wsi; - struct lws_protocols ws_protocols[2]; + struct lws_protocols * ws_protocols; struct lws_context_creation_info info; struct lws_context * context; std::queue writeQueue; @@ -212,7 +226,13 @@ private: }; WebsocketServer::WebsocketServer(int port) -: d(new Private(port)) +: d(new Private(port, nullptr, 0)) +{ + +} + +WebsocketServer::WebsocketServer(int port, struct lws_protocols * additionalProtocols, std::size_t additionalProtocolsCount) +: d(new Private(port, additionalProtocols, additionalProtocolsCount)) { } @@ -222,6 +242,11 @@ WebsocketServer::~WebsocketServer() delete d; } +struct lws_context * WebsocketServer::getContext() +{ + return d->getContext(); +} + void WebsocketServer::waitForConnection() { d->waitForConnection(); diff --git a/test/webfuse/utils/ws_server.hpp b/test/webfuse/utils/ws_server.hpp index bacab51..e9d825a 100644 --- a/test/webfuse/utils/ws_server.hpp +++ b/test/webfuse/utils/ws_server.hpp @@ -13,7 +13,9 @@ class WebsocketServer WebsocketServer & operator=(WebsocketServer const &) = delete; public: explicit WebsocketServer(int port); + WebsocketServer(int port, struct lws_protocols * additionalProtocols, std::size_t additionalProtocolsCount); ~WebsocketServer(); + struct lws_context * getContext(); void waitForConnection(); void sendMessage(json_t * message); json_t * receiveMessage(); From 391b5926b6387860cf370e82d379e891d5a9d793 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 23 Feb 2020 23:20:26 +0100 Subject: [PATCH 11/16] added mock for provider client --- cmake/unit_tests.cmake | 1 + test/webfuse/mocks/mock_provider_client.cc | 204 ++++++++++++++++++ test/webfuse/mocks/mock_provider_client.hpp | 55 +++++ .../tests/provider/test_client_protocol.cc | 55 ++++- 4 files changed, 306 insertions(+), 9 deletions(-) create mode 100644 test/webfuse/mocks/mock_provider_client.cc create mode 100644 test/webfuse/mocks/mock_provider_client.hpp diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 3e445ed..1ff1be5 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -17,6 +17,7 @@ add_executable(alltests test/webfuse/utils/ws_server.cc test/webfuse/mocks/mock_authenticator.cc test/webfuse/mocks/mock_request.cc + test/webfuse/mocks/mock_provider_client.cc test/webfuse/tests/core/test_container_of.cc test/webfuse/tests/core/test_string.cc test/webfuse/tests/core/test_slist.cc diff --git a/test/webfuse/mocks/mock_provider_client.cc b/test/webfuse/mocks/mock_provider_client.cc new file mode 100644 index 0000000..a906d95 --- /dev/null +++ b/test/webfuse/mocks/mock_provider_client.cc @@ -0,0 +1,204 @@ +#include "webfuse/mocks/mock_provider_client.hpp" +#include "webfuse/provider/operation/error.h" +#include "webfuse/provider/dirbuffer.h" + +extern "C" +{ +using webfuse_test::IProviderClient; +using webfuse_test::ProviderClientException; + +static void webfuse_test_iproviderclient_onconnected( + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + self->OnConnected(); +} + +static void webfuse_test_iproviderclient_ondisconnected( + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + self->OnDisconnected(); +} + +static void webfuse_test_iproviderclient_ontimer( + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + self->OnTimer(); +} + +static void webfuse_test_iproviderclient_onlookup( + struct wfp_request * request, + ino_t parent, + char const * name, + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + + try + { + struct stat buffer; + self->Lookup(parent, name, &buffer); + wfp_respond_lookup(request, &buffer); + } + catch (ProviderClientException ex) + { + wfp_respond_error(request, ex.GetErrorCode()); + } + catch (...) + { + wfp_respond_error(request, WF_BAD); + } +} + +static void webfuse_test_iproviderclient_ongetattr( + struct wfp_request * request, + ino_t inode, + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + + try + { + struct stat buffer; + memset(&buffer, 0, sizeof(struct stat)); + self->GetAttr(inode, &buffer); + wfp_respond_getattr(request,&buffer); + } + catch (ProviderClientException ex) + { + wfp_respond_error(request, ex.GetErrorCode()); + } + catch (...) + { + wfp_respond_error(request, WF_BAD); + } + +} + +static void webfuse_test_iproviderclient_onreaddir( + struct wfp_request * request, + ino_t directory, + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + wfp_dirbuffer * buffer = wfp_dirbuffer_create(); + + try + { + self->ReadDir(directory, buffer); + wfp_respond_readdir(request, buffer); + } + catch (ProviderClientException ex) + { + wfp_respond_error(request, ex.GetErrorCode()); + } + catch (...) + { + wfp_respond_error(request, WF_BAD); + } + + wfp_dirbuffer_dispose(buffer); + +} + +static void webfuse_test_iproviderclient_onopen( + struct wfp_request * request, + ino_t inode, + int flags, + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + + try + { + uint32_t handle = 0; + self->Open(inode, flags, &handle); + wfp_respond_open(request, handle); + } + catch (ProviderClientException ex) + { + wfp_respond_error(request, ex.GetErrorCode()); + } + catch (...) + { + wfp_respond_error(request, WF_BAD); + } + +} + +static void webfuse_test_iproviderclient_onclose( + ino_t inode, + uint32_t handle, + int flags, + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + self->Close(inode, handle, flags); +} + +static void webfuse_test_iproviderclient_onread( + struct wfp_request * request, + ino_t inode, + uint32_t handle, + size_t offset, + size_t length, + void * user_data) +{ + auto * self = reinterpret_cast(user_data); + char * data = new char[length]; + + try + { + size_t bytes_read = 0; + self->Read(inode, handle, offset, length, data, &bytes_read); + wfp_respond_read(request, data, bytes_read); + } + catch (ProviderClientException ex) + { + wfp_respond_error(request, ex.GetErrorCode()); + } + catch (...) + { + wfp_respond_error(request, WF_BAD); + } + + delete[] data; +} + +} + +namespace webfuse_test +{ + +ProviderClientException::ProviderClientException(wf_status error_code) +: runtime_error("ProviderClientException") +, error_code_(error_code) +{ + +} + +wf_status ProviderClientException::GetErrorCode() +{ + return error_code_; +} + + +void IProviderClient::AttachTo(wfp_client_config * config) +{ + void * self = reinterpret_cast(this); + wfp_client_config_set_userdata(config, self); + wfp_client_config_set_onconnected(config, &webfuse_test_iproviderclient_onconnected); + wfp_client_config_set_ondisconnected(config, &webfuse_test_iproviderclient_ondisconnected); + wfp_client_config_set_ontimer(config, &webfuse_test_iproviderclient_ontimer); + + wfp_client_config_set_onlookup(config, &webfuse_test_iproviderclient_onlookup); + wfp_client_config_set_ongetattr(config, &webfuse_test_iproviderclient_ongetattr); + wfp_client_config_set_onreaddir(config, &webfuse_test_iproviderclient_onreaddir); + wfp_client_config_set_onopen(config, &webfuse_test_iproviderclient_onopen); + wfp_client_config_set_onclose(config, &webfuse_test_iproviderclient_onclose); + wfp_client_config_set_onread(config, &webfuse_test_iproviderclient_onread); +} + +} \ No newline at end of file diff --git a/test/webfuse/mocks/mock_provider_client.hpp b/test/webfuse/mocks/mock_provider_client.hpp new file mode 100644 index 0000000..2db3127 --- /dev/null +++ b/test/webfuse/mocks/mock_provider_client.hpp @@ -0,0 +1,55 @@ +#ifndef WF_MOCK_PROVIDER_CLIENT_HPP +#define WF_MOCK_PROVIDER_CLIENT_HPP + +#include +#include "webfuse/provider/client_config.h" +#include "webfuse/core/status.h" +#include + +namespace webfuse_test +{ + class ProviderClientException: public std::runtime_error + { + public: + ProviderClientException(wf_status error_code); + wf_status GetErrorCode(); + private: + wf_status error_code_; + }; + + + + class IProviderClient + { + public: + virtual ~IProviderClient() = default; + virtual void OnConnected() = 0; + virtual void OnDisconnected() = 0; + virtual void OnTimer() = 0; + virtual void Lookup(ino_t parent, char const * name, struct stat * result) = 0; + virtual void GetAttr(ino_t inode, struct stat * buffer) = 0; + virtual void ReadDir(ino_t directory, wfp_dirbuffer * buffer) = 0; + virtual void Open(ino_t inode, int flags, uint32_t * handle) = 0; + virtual void Close(ino_t inode, uint32_t handle, int flags) = 0; + virtual void Read(ino_t inode, uint32_t handle, size_t offset, size_t length, char * buffer, size_t * bytes_read) = 0; + + void AttachTo(wfp_client_config * config); + }; + + class MockProviderClient: public IProviderClient + { + public: + ~MockProviderClient() override = default; + MOCK_METHOD0( OnConnected, void()); + MOCK_METHOD0( OnDisconnected, void()); + MOCK_METHOD0( OnTimer, void()); + MOCK_METHOD3( Lookup, void(ino_t parent, char const * name, struct stat * result)); + MOCK_METHOD2( GetAttr, void(ino_t inode, struct stat * buffer)); + MOCK_METHOD2( ReadDir, void(ino_t directory, wfp_dirbuffer * buffer)); + MOCK_METHOD3( Open, void(ino_t inode, int flags, uint32_t * handle)); + MOCK_METHOD3( Close, void(ino_t inode, uint32_t handle, int flags)); + MOCK_METHOD6( Read, void(ino_t inode, uint32_t handle, size_t offset, size_t length, char * buffer, size_t * bytes_read)); + }; +} + +#endif diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index b602e58..954a253 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -4,17 +4,20 @@ #include #include #include "webfuse/utils/ws_server.hpp" +#include "webfuse/mocks/mock_provider_client.hpp" #include #include #include using webfuse_test::WebsocketServer; +using webfuse_test::MockProviderClient; using testing::_; namespace { +// ToDo: Refactor Me class ClientProtocolTest: public ::testing::Test { public: @@ -30,6 +33,22 @@ protected: void SetUp() { config = wfp_client_config_create(); + + server = nullptr; + protocol = nullptr; + } + + void TearDown() + { + if (nullptr != server) + { + StopServer(); + } + + } + + void StartServer() + { protocol = wfp_client_protocol_create(config); struct lws_protocols client_protocol; @@ -39,22 +58,29 @@ protected: server = new WebsocketServer(54321, &client_protocol, 1); } - void TearDown() + void StopServer() { delete server; - wfp_client_protocol_dispose(protocol); wfp_client_config_dispose(config); + server = nullptr; + protocol = nullptr; + config = nullptr; } - void connect() + wfp_client_config * GetClientConfig() + { + return config; + } + + void Connect() { wfp_client_protocol_connect(protocol, server->getContext(), "ws://localhost:54321/"); server->waitForConnection(); } - void awaitAddFilesystem(std::string& filesystemName) + void AwaitAddFilesystem(std::string& filesystemName) { json_t * addFilesystemRequest = server->receiveMessage(); ASSERT_NE(nullptr, addFilesystemRequest); @@ -94,24 +120,33 @@ private: wfp_client_protocol * protocol; }; - - } TEST_F(ClientProtocolTest, connect) { - connect(); + StartServer(); + Connect(); if (HasFatalFailure()) { return; } + + StopServer(); } TEST_F(ClientProtocolTest, getattr) { - connect(); + MockProviderClient client; + client.AttachTo(GetClientConfig()); + + EXPECT_CALL(client, OnConnected()).Times(1); + EXPECT_CALL(client, OnDisconnected()).Times(1); + EXPECT_CALL(client, GetAttr(1, _)).Times(1); + + StartServer(); + Connect(); if (HasFatalFailure()) { return; } std::string filesystem; - awaitAddFilesystem(filesystem); + AwaitAddFilesystem(filesystem); if (HasFatalFailure()) { return; } json_t * params = json_array(); @@ -127,4 +162,6 @@ TEST_F(ClientProtocolTest, getattr) ASSERT_TRUE(json_is_object(response)); json_decref(response); + + StopServer(); } \ No newline at end of file From 7c02b12449a55c215e8409fc81e2a820b77629e3 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 23 Feb 2020 23:25:17 +0100 Subject: [PATCH 12/16] fix: don't copy exceptions --- test/webfuse/mocks/mock_provider_client.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/webfuse/mocks/mock_provider_client.cc b/test/webfuse/mocks/mock_provider_client.cc index a906d95..a624ba3 100644 --- a/test/webfuse/mocks/mock_provider_client.cc +++ b/test/webfuse/mocks/mock_provider_client.cc @@ -42,7 +42,7 @@ static void webfuse_test_iproviderclient_onlookup( self->Lookup(parent, name, &buffer); wfp_respond_lookup(request, &buffer); } - catch (ProviderClientException ex) + catch (ProviderClientException& ex) { wfp_respond_error(request, ex.GetErrorCode()); } @@ -66,7 +66,7 @@ static void webfuse_test_iproviderclient_ongetattr( self->GetAttr(inode, &buffer); wfp_respond_getattr(request,&buffer); } - catch (ProviderClientException ex) + catch (ProviderClientException& ex) { wfp_respond_error(request, ex.GetErrorCode()); } @@ -90,7 +90,7 @@ static void webfuse_test_iproviderclient_onreaddir( self->ReadDir(directory, buffer); wfp_respond_readdir(request, buffer); } - catch (ProviderClientException ex) + catch (ProviderClientException& ex) { wfp_respond_error(request, ex.GetErrorCode()); } @@ -117,7 +117,7 @@ static void webfuse_test_iproviderclient_onopen( self->Open(inode, flags, &handle); wfp_respond_open(request, handle); } - catch (ProviderClientException ex) + catch (ProviderClientException& ex) { wfp_respond_error(request, ex.GetErrorCode()); } @@ -155,7 +155,7 @@ static void webfuse_test_iproviderclient_onread( self->Read(inode, handle, offset, length, data, &bytes_read); wfp_respond_read(request, data, bytes_read); } - catch (ProviderClientException ex) + catch (ProviderClientException& ex) { wfp_respond_error(request, ex.GetErrorCode()); } From 7ed99088db32fa30a9d8c093f12133c14a7d09d1 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 23 Feb 2020 23:26:30 +0100 Subject: [PATCH 13/16] fix: make c'tor explicit --- test/webfuse/mocks/mock_provider_client.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/webfuse/mocks/mock_provider_client.hpp b/test/webfuse/mocks/mock_provider_client.hpp index 2db3127..45fdf91 100644 --- a/test/webfuse/mocks/mock_provider_client.hpp +++ b/test/webfuse/mocks/mock_provider_client.hpp @@ -11,7 +11,7 @@ namespace webfuse_test class ProviderClientException: public std::runtime_error { public: - ProviderClientException(wf_status error_code); + explicit ProviderClientException(wf_status error_code); wf_status GetErrorCode(); private: wf_status error_code_; From 5a80e0233c617d161a1166e0da0ac1cba87c71c2 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 24 Feb 2020 18:16:30 +0100 Subject: [PATCH 14/16] refactored test fixture --- .../tests/provider/test_client_protocol.cc | 93 ++++++++----------- 1 file changed, 38 insertions(+), 55 deletions(-) diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index 954a253..8aa3a81 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -12,43 +12,21 @@ using webfuse_test::WebsocketServer; using webfuse_test::MockProviderClient; +using webfuse_test::IProviderClient; using testing::_; +using testing::AtMost; namespace { -// ToDo: Refactor Me -class ClientProtocolTest: public ::testing::Test +class ClientProtocolFixture { public: - ClientProtocolTest() - : server(nullptr) - , config(nullptr) - , protocol(nullptr) - { - // empty - } - -protected: - void SetUp() + ClientProtocolFixture(IProviderClient& client) { config = wfp_client_config_create(); + client.AttachTo(config); - server = nullptr; - protocol = nullptr; - } - - void TearDown() - { - if (nullptr != server) - { - StopServer(); - } - - } - - void StartServer() - { protocol = wfp_client_protocol_create(config); struct lws_protocols client_protocol; @@ -58,26 +36,27 @@ protected: server = new WebsocketServer(54321, &client_protocol, 1); } - void StopServer() + ~ClientProtocolFixture() { delete server; wfp_client_protocol_dispose(protocol); wfp_client_config_dispose(config); + } - server = nullptr; - protocol = nullptr; - config = nullptr; + void Connect() + { + wfp_client_protocol_connect(protocol, server->getContext(), "ws://localhost:54321/"); + server->waitForConnection(); } - wfp_client_config * GetClientConfig() + void SendToClient(json_t * request) { - return config; + server->sendMessage(request); } - void Connect() + json_t * ReceiveMessageFromClient() { - wfp_client_protocol_connect(protocol, server->getContext(), "ws://localhost:54321/"); - server->waitForConnection(); + return server->receiveMessage(); } void AwaitAddFilesystem(std::string& filesystemName) @@ -113,40 +92,46 @@ protected: } - WebsocketServer * server; - private: + WebsocketServer * server; wfp_client_config * config; wfp_client_protocol * protocol; }; + } -TEST_F(ClientProtocolTest, connect) +TEST(client_protocol, connect) { - StartServer(); - Connect(); + MockProviderClient provider; + ClientProtocolFixture fixture(provider); + + EXPECT_CALL(provider, OnConnected()).Times(AtMost(1)); + EXPECT_CALL(provider, OnDisconnected()).Times(1); + + fixture.Connect(); if (HasFatalFailure()) { return; } - StopServer(); + std::string filesystem; + fixture.AwaitAddFilesystem(filesystem); + if (HasFatalFailure()) { return; } } -TEST_F(ClientProtocolTest, getattr) +TEST(client_protocol, getattr) { - MockProviderClient client; - client.AttachTo(GetClientConfig()); + MockProviderClient provider; + ClientProtocolFixture fixture(provider); - EXPECT_CALL(client, OnConnected()).Times(1); - EXPECT_CALL(client, OnDisconnected()).Times(1); - EXPECT_CALL(client, GetAttr(1, _)).Times(1); + EXPECT_CALL(provider, OnConnected()).Times(1); + EXPECT_CALL(provider, OnDisconnected()).Times(1); + EXPECT_CALL(provider, GetAttr(1, _)).Times(1); - StartServer(); - Connect(); + fixture.Connect(); if (HasFatalFailure()) { return; } std::string filesystem; - AwaitAddFilesystem(filesystem); + fixture.AwaitAddFilesystem(filesystem); if (HasFatalFailure()) { return; } json_t * params = json_array(); @@ -157,11 +142,9 @@ TEST_F(ClientProtocolTest, getattr) json_object_set_new(request, "params", params); json_object_set_new(request, "id", json_integer(42)); - server->sendMessage(request); - json_t * response = server->receiveMessage(); + fixture.SendToClient(request); + json_t * response = fixture.ReceiveMessageFromClient(); ASSERT_TRUE(json_is_object(response)); json_decref(response); - - StopServer(); } \ No newline at end of file From 85b283c1e319f54fae6026494d83a31874237e5f Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 24 Feb 2020 18:20:26 +0100 Subject: [PATCH 15/16] removed dead code --- cmake/webfuse_core.cmake | 1 - lib/webfuse/core/lws_utils.c | 210 ----------------------------------- lib/webfuse/core/lws_utils.h | 19 ---- 3 files changed, 230 deletions(-) delete mode 100644 lib/webfuse/core/lws_utils.c delete mode 100644 lib/webfuse/core/lws_utils.h diff --git a/cmake/webfuse_core.cmake b/cmake/webfuse_core.cmake index 3daded5..52c7681 100644 --- a/cmake/webfuse_core.cmake +++ b/cmake/webfuse_core.cmake @@ -8,7 +8,6 @@ add_library(webfuse-core STATIC lib/webfuse/core/string.c lib/webfuse/core/base64.c lib/webfuse/core/lws_log.c - lib/webfuse/core/lws_utils.c ) set_target_properties(webfuse-core PROPERTIES OUTPUT_NAME webfuse-core) diff --git a/lib/webfuse/core/lws_utils.c b/lib/webfuse/core/lws_utils.c deleted file mode 100644 index 700b084..0000000 --- a/lib/webfuse/core/lws_utils.c +++ /dev/null @@ -1,210 +0,0 @@ -#include "webfuse/core/lws_utils.h" - -extern char const * -wf_lws_reason_tostring( - enum lws_callback_reasons reason) -{ - switch (reason) - { - case LWS_CALLBACK_PROTOCOL_INIT: - return "protocol_init"; - case LWS_CALLBACK_PROTOCOL_DESTROY: - return "protcol_destory"; - case LWS_CALLBACK_WSI_CREATE: - return "wsi_create"; - case LWS_CALLBACK_WSI_DESTROY: - return "wsi_destroy"; - case LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS: - return "openssl_load_extra_client_verify_certs"; - case LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS: - return "openssl_load_extra_server_verify_certs"; - case LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION: - return "openssl_perform_client_cert_verification"; - case LWS_CALLBACK_OPENSSL_PERFORM_SERVER_CERT_VERIFICATION: - return "openssl_perform_server_cert_verification"; - case LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY: - return "openssl_context_required_private_key"; - case LWS_CALLBACK_SSL_INFO: - return "ssl_info"; - case LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED: - return "server_new_client_instantiated"; - case LWS_CALLBACK_HTTP: - return "http"; - case LWS_CALLBACK_HTTP_BODY: - return "http_body"; - case LWS_CALLBACK_HTTP_BODY_COMPLETION: - return "http_body_completion"; - case LWS_CALLBACK_HTTP_FILE_COMPLETION: - return "http_file_completion"; - case LWS_CALLBACK_HTTP_WRITEABLE: - return "http_writeable"; - case LWS_CALLBACK_CLOSED_HTTP: - return "closed_http"; - case LWS_CALLBACK_FILTER_HTTP_CONNECTION: - return "filter_http_connection"; - case LWS_CALLBACK_ADD_HEADERS: - return "add_headers"; - case LWS_CALLBACK_CHECK_ACCESS_RIGHTS: - return "check_access_rights"; - case LWS_CALLBACK_PROCESS_HTML: - return "process_html"; - case LWS_CALLBACK_HTTP_BIND_PROTOCOL: - return "http_bind_protocol"; - case LWS_CALLBACK_HTTP_DROP_PROTOCOL: - return "http_drop_protocol"; - case LWS_CALLBACK_HTTP_CONFIRM_UPGRADE: - return "http_confirm_upgrade"; - case LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP: - return "established_client_http"; - case LWS_CALLBACK_CLOSED_CLIENT_HTTP: - return "closed_http_client"; - case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ: - return "receive_client_http_read"; - case LWS_CALLBACK_COMPLETED_CLIENT_HTTP: - return "completed_client_http"; - case LWS_CALLBACK_CLIENT_HTTP_WRITEABLE: - return "client_http_writeable"; - case LWS_CALLBACK_CLIENT_HTTP_BIND_PROTOCOL: - return "client_http_bind_protocol"; - case LWS_CALLBACK_CLIENT_HTTP_DROP_PROTOCOL: - return "client_http_drop_protocol"; - case LWS_CALLBACK_ESTABLISHED: - return "established"; - case LWS_CALLBACK_CLOSED: - return "closed"; - case LWS_CALLBACK_SERVER_WRITEABLE: - return "server_writeable"; - case LWS_CALLBACK_RECEIVE: - return "receive"; - case LWS_CALLBACK_RECEIVE_PONG: - return "receive_pong"; - case LWS_CALLBACK_WS_PEER_INITIATED_CLOSE: - return "ws_peer_initiated_close"; - case LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION: - return "filter_protocol_connection"; - case LWS_CALLBACK_CONFIRM_EXTENSION_OKAY: - return "confirm_extension_okay"; - case LWS_CALLBACK_WS_SERVER_BIND_PROTOCOL: - return "ws_server_bind_protocol"; - case LWS_CALLBACK_WS_SERVER_DROP_PROTOCOL: - return "ws_server_drop_protocol"; - case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: - return "client_connection_error"; - case LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH: - return "client_filter_pre_establish"; - case LWS_CALLBACK_CLIENT_ESTABLISHED: - return "client_established"; - case LWS_CALLBACK_CLIENT_CLOSED: - return "client_closed"; - case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: - return "client_append_handshake_header"; - case LWS_CALLBACK_CLIENT_RECEIVE: - return "client_receive"; - case LWS_CALLBACK_CLIENT_RECEIVE_PONG: - return "client_receive_pong"; - case LWS_CALLBACK_CLIENT_WRITEABLE: - return "client_writeable"; - case LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED: - return "client_confirm_extension_supported"; - case LWS_CALLBACK_WS_EXT_DEFAULTS: - return "ws_ext_defaults"; - case LWS_CALLBACK_FILTER_NETWORK_CONNECTION: - return "filter_network_connection"; - case LWS_CALLBACK_WS_CLIENT_BIND_PROTOCOL: - return "ws_client_bind_protocol"; - case LWS_CALLBACK_WS_CLIENT_DROP_PROTOCOL: - return "ws_client_drop_protocol"; - case LWS_CALLBACK_GET_THREAD_ID: - return "get_thread_id"; - case LWS_CALLBACK_ADD_POLL_FD: - return "add_poll_fd"; - case LWS_CALLBACK_DEL_POLL_FD: - return "del_poll_fd"; - case LWS_CALLBACK_CHANGE_MODE_POLL_FD: - return "change_mode_poll_fd"; - case LWS_CALLBACK_LOCK_POLL: - return "lock_poll"; - case LWS_CALLBACK_UNLOCK_POLL: - return "unlock_poll"; - case LWS_CALLBACK_CGI: - return "cgi"; - case LWS_CALLBACK_CGI_TERMINATED: - return "cgi_terminated"; - case LWS_CALLBACK_CGI_STDIN_DATA: - return "cgi_stdin_data"; - case LWS_CALLBACK_CGI_STDIN_COMPLETED: - return "cgi_stdin_completed"; - case LWS_CALLBACK_CGI_PROCESS_ATTACH: - return "cgi_process_attach"; - case LWS_CALLBACK_SESSION_INFO: - return "session_info"; - case LWS_CALLBACK_GS_EVENT: - return "gs_event"; - case LWS_CALLBACK_HTTP_PMO: - return "http_pmo"; - case LWS_CALLBACK_RAW_PROXY_CLI_RX: - return "raw_proxy_cli_rx"; - case LWS_CALLBACK_RAW_PROXY_SRV_RX: - return "raw_proxy_srv_rx"; - case LWS_CALLBACK_RAW_PROXY_CLI_CLOSE: - return "raw_proxy_cli_close"; - case LWS_CALLBACK_RAW_PROXY_SRV_CLOSE: - return "raw_proxy_srv_close"; - case LWS_CALLBACK_RAW_PROXY_CLI_WRITEABLE: - return "raw_proxy_cli_writeable"; - case LWS_CALLBACK_RAW_PROXY_SRV_WRITEABLE: - return "raw_prxy_srv_wrtieable"; - case LWS_CALLBACK_RAW_PROXY_CLI_ADOPT: - return "raw_proxy_cli_adopt"; - case LWS_CALLBACK_RAW_PROXY_SRV_ADOPT: - return "raw_proxy_srv_adopt"; - case LWS_CALLBACK_RAW_PROXY_CLI_BIND_PROTOCOL: - return "raw_proxy_cli_bind_protocol"; - case LWS_CALLBACK_RAW_PROXY_SRV_BIND_PROTOCOL: - return "raw_proxy_srv_bind_protocol"; - case LWS_CALLBACK_RAW_PROXY_CLI_DROP_PROTOCOL: - return "raw_proxy_cli_drop_protocol"; - case LWS_CALLBACK_RAW_PROXY_SRV_DROP_PROTOCOL: - return "raw_proxy_srv_drop_protocol"; - case LWS_CALLBACK_RAW_RX: - return "raw_rx"; - case LWS_CALLBACK_RAW_CLOSE: - return "raw_close"; - case LWS_CALLBACK_RAW_WRITEABLE: - return "raw_writeable"; - case LWS_CALLBACK_RAW_ADOPT: - return "raw_adopt"; - case LWS_CALLBACK_RAW_CONNECTED: - return "raw_connected"; - case LWS_CALLBACK_RAW_SKT_BIND_PROTOCOL: - return "raw_skt_bind_protocol"; - case LWS_CALLBACK_RAW_SKT_DROP_PROTOCOL: - return "raw_skt_drop_protocol"; - case LWS_CALLBACK_RAW_ADOPT_FILE: - return "raw_adopt_file"; - case LWS_CALLBACK_RAW_RX_FILE: - return "raw_rx_file"; - case LWS_CALLBACK_RAW_WRITEABLE_FILE: - return "raw_writeable_file"; - case LWS_CALLBACK_RAW_CLOSE_FILE: - return "raw_close_file"; - case LWS_CALLBACK_RAW_FILE_BIND_PROTOCOL: - return "raw_file_bind_protocol"; - case LWS_CALLBACK_RAW_FILE_DROP_PROTOCOL: - return "raw_file_drop_protocol"; - case LWS_CALLBACK_TIMER: - return "timer"; - case LWS_CALLBACK_EVENT_WAIT_CANCELLED: - return "event_wait_cancelled"; - case LWS_CALLBACK_CHILD_CLOSING: - return "child_closing"; - case LWS_CALLBACK_VHOST_CERT_AGING: - return "vhost_cert_aging"; - case LWS_CALLBACK_VHOST_CERT_UPDATE: - return "vhost_cert_update"; - case LWS_CALLBACK_USER: - return "user"; - default: - return ""; - } -} diff --git a/lib/webfuse/core/lws_utils.h b/lib/webfuse/core/lws_utils.h deleted file mode 100644 index d97ed69..0000000 --- a/lib/webfuse/core/lws_utils.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef WF_LWS_UTILS_H -#define WF_LWS_UTILS_H - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -extern char const * -wf_lws_reason_tostring( - enum lws_callback_reasons reason); - -#ifdef __cplusplus -} -#endif - -#endif From afb9c528e7bd7cdef34f969a79a4498642c04331 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 24 Feb 2020 18:25:25 +0100 Subject: [PATCH 16/16] made c'tor explicit; disallow copy and assign --- test/webfuse/tests/provider/test_client_protocol.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index 8aa3a81..ff7be74 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -21,8 +21,10 @@ namespace class ClientProtocolFixture { + ClientProtocolFixture(ClientProtocolFixture const &) = delete; + ClientProtocolFixture& operator=(ClientProtocolFixture const &) = delete; public: - ClientProtocolFixture(IProviderClient& client) + explicit ClientProtocolFixture(IProviderClient& client) { config = wfp_client_config_create(); client.AttachTo(config);