diff --git a/meson.build b/meson.build index 67e1121..f5c4f3f 100644 --- a/meson.build +++ b/meson.build @@ -125,11 +125,11 @@ alltests = executable('alltests', 'test/webfuse/timer/test_timepoint.cc', 'test/webfuse/timer/test_timer.cc', 'test/webfuse/test_util/tempdir.cc', - 'test/webfuse/test_util/file_utils.cc', 'test/webfuse/test_util/server.cc', 'test/webfuse/test_util/ws_server.cc', 'test/webfuse/test_util/ws_client.cc', 'test/webfuse/test_util/adapter_client.cc', + 'test/webfuse/test_util/file.cc', 'test/webfuse/test_util/jansson_test_environment.cc', 'test/webfuse/test_util/lws_test_environment.cc', 'test/webfuse/mocks/mock_authenticator.cc', @@ -159,7 +159,6 @@ alltests = executable('alltests', 'test/webfuse/operation/test_readdir.cc', 'test/webfuse/operation/test_getattr.cc', 'test/webfuse/operation/test_lookup.cc', - 'test/webfuse/integration/file.cc', 'test/webfuse/test_client.cc', 'test/webfuse/test_client_tlsconfig.cc', link_args: [ diff --git a/test/webfuse/integration/test_integration.cc b/test/webfuse/integration/test_integration.cc deleted file mode 100644 index 32746ba..0000000 --- a/test/webfuse/integration/test_integration.cc +++ /dev/null @@ -1,97 +0,0 @@ -#include -#include "webfuse/tests/integration/server.hpp" -#include "webfuse/tests/integration/provider.hpp" -#include "webfuse/tests/integration/file.hpp" - -#include -#include -#include - -#include - -#include -#include -#include -#include - -#include -#include "webfuse/impl/lws_log.h" - -using webfuse_test::Server; -using webfuse_test::Provider; -using webfuse_test::File; - -namespace -{ - class IntegrationTest: public ::testing::Test - { - public: - IntegrationTest() - : server(nullptr) - , provider(nullptr) - { - json_object_seed(0); - wf_lwslog_disable(); - } - - protected: - void SetUp() - { - server = new Server(); - provider = new Provider(server->GetUrl().c_str()); - } - - void TearDown() - { - delete provider; - delete server; - } - - char const * GetBaseDir() const - { - return server->GetBaseDir(); - } - private: - Server * server; - Provider * provider; - }; -} - -TEST_F(IntegrationTest, HasMountpoint) -{ - struct stat buffer; - int rc = stat(GetBaseDir(), &buffer); - - ASSERT_EQ(0, rc); - ASSERT_TRUE(S_ISDIR(buffer.st_mode)); -} - -TEST_F(IntegrationTest, ProvidesTextFile) -{ - std::string file_name = std::string(GetBaseDir()) + "/cprovider/hello.txt"; - - File file(file_name); - ASSERT_TRUE(file.isFile()); - ASSERT_TRUE(file.hasAccessRights(0444)); - ASSERT_TRUE(file.hasSize(12)); -} - -TEST_F(IntegrationTest, ReadTextFile) -{ - std::string file_name = std::string(GetBaseDir()) + "/cprovider/hello.txt"; - - File file(file_name); - ASSERT_TRUE(file.hasContents("Hello, World")); -} - -TEST_F(IntegrationTest, ReadDir) -{ - std::string dir_name = std::string(GetBaseDir()) + "/cprovider"; - - File dir(dir_name); - ASSERT_TRUE(dir.isDirectory()); - ASSERT_TRUE(dir.hasSubdirectory(".")); - ASSERT_TRUE(dir.hasSubdirectory("..")); - ASSERT_TRUE(dir.hasSubdirectory("hello.txt")); - ASSERT_FALSE(dir.hasSubdirectory("other")); -} \ No newline at end of file diff --git a/test/webfuse/integration/test_lowlevel.cc b/test/webfuse/integration/test_lowlevel.cc deleted file mode 100644 index 9155b16..0000000 --- a/test/webfuse/integration/test_lowlevel.cc +++ /dev/null @@ -1,112 +0,0 @@ -#include "webfuse/webfuse.h" -#include "webfuse_provider.h" -#include - -#include "webfuse/test_util/tempdir.hpp" - -#include - -using ::webfuse_test::TempDir; - -extern "C" -{ - -wf_mountpoint * -wf_test_integration_lowlevel_create_mountpoint( - char const *, void * user_data) -{ - auto * tempDir = reinterpret_cast(user_data); - return wf_mountpoint_create(tempDir->path()); -} - -void -wf_test_integration_lowlevel_on_connected( - void * user_data) -{ - int * state = reinterpret_cast(user_data); - *state = 1; -} - -void -wf_test_integration_lowlevel_on_disconnected( - void * user_data) -{ - int * state = reinterpret_cast(user_data); - *state = -1; -} - -bool -wf_test_integration_lowlevel_authenticate( - struct wf_credentials const * credentials, - void * ) -{ - char const * username = wf_credentials_get(credentials, "username"); - char const * password = wf_credentials_get(credentials, "password"); - - return ((0 == strcmp(username, "bob")) && (0 == strcmp(password, "secret"))); -} - -void -wf_test_integration_lowlevel_get_credentials( - struct wfp_credentials * credentials, - void * ) -{ - wfp_credentials_set_type(credentials, "username"); - wfp_credentials_add(credentials, "username", "bob"); - wfp_credentials_add(credentials, "password", "secret"); -} - -} - -TEST(integration, lowlevel) -{ - TempDir dir("wf_test"); - - wf_server_protocol * server_protocol = wf_server_protocol_create( - &wf_test_integration_lowlevel_create_mountpoint, - reinterpret_cast(&dir)); - ASSERT_NE(nullptr, server_protocol); - wf_server_protocol_add_authenticator(server_protocol, "username", - &wf_test_integration_lowlevel_authenticate, nullptr); - - int state = 0; - wfp_client_config * client_config = wfp_client_config_create(); - ASSERT_NE(nullptr, client_config); - wfp_client_config_set_userdata(client_config, reinterpret_cast(&state)); - wfp_client_config_set_onconnected(client_config, &wf_test_integration_lowlevel_on_connected); - wfp_client_config_set_ondisconnected(client_config, &wf_test_integration_lowlevel_on_disconnected); - wfp_client_config_enable_authentication(client_config, &wf_test_integration_lowlevel_get_credentials); - - wfp_client_protocol * client_protocol = wfp_client_protocol_create(client_config); - ASSERT_NE(nullptr, client_protocol); - - lws_protocols protocols[3]; - memset(protocols, 0, 3 * sizeof(lws_protocols)); - wf_server_protocol_init_lws(server_protocol, &protocols[0]); - wfp_client_protocol_init_lws(client_protocol, &protocols[1]); - - lws_context_creation_info info; - memset(&info, 0, sizeof(info)); - info.port = 8080; - info.protocols = protocols; - info.vhost_name = "localhost"; - info.ws_ping_pong_interval = 10; - info.options = LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE; - - struct lws_context * context = lws_create_context(&info); - ASSERT_NE(nullptr, context); - - wfp_client_protocol_connect(client_protocol, context, "ws://localhost:8080/"); - while (0 == state) - { - lws_service(context, 0); - } - - EXPECT_EQ(1, state); - - lws_context_destroy(context); - - wfp_client_protocol_dispose(client_protocol); - wfp_client_config_dispose(client_config); - wf_server_protocol_dispose(server_protocol); -} \ No newline at end of file diff --git a/test/webfuse/test_client.cc b/test/webfuse/test_client.cc index 899777f..a1ae12b 100644 --- a/test/webfuse/test_client.cc +++ b/test/webfuse/test_client.cc @@ -8,7 +8,7 @@ #include "webfuse/test_util/ws_server.hpp" #include "webfuse/mocks/mock_adapter_client_callback.hpp" #include "webfuse/mocks/mock_invokation_handler.hpp" -#include "webfuse/integration/file.hpp" +#include "webfuse/test_util/file.hpp" #include "webfuse/mocks/lookup_matcher.hpp" #include diff --git a/test/webfuse/test_server.cc b/test/webfuse/test_server.cc index f964eab..a36fa9b 100644 --- a/test/webfuse/test_server.cc +++ b/test/webfuse/test_server.cc @@ -6,7 +6,7 @@ #include "webfuse/server_config.h" #include "webfuse/test_util/server.hpp" #include "webfuse/test_util/ws_client.hpp" -#include "webfuse/integration/file.hpp" +#include "webfuse/test_util/file.hpp" #include "webfuse/mocks/mock_invokation_handler.hpp" #include "webfuse/protocol_names.h" #include "webfuse/mocks/open_matcher.hpp" diff --git a/test/webfuse/integration/file.cc b/test/webfuse/test_util/file.cc similarity index 97% rename from test/webfuse/integration/file.cc rename to test/webfuse/test_util/file.cc index 94d5608..1ec16b5 100644 --- a/test/webfuse/integration/file.cc +++ b/test/webfuse/test_util/file.cc @@ -1,4 +1,4 @@ -#include "webfuse/integration/file.hpp" +#include "webfuse/test_util/file.hpp" #include #include diff --git a/test/webfuse/integration/file.hpp b/test/webfuse/test_util/file.hpp similarity index 100% rename from test/webfuse/integration/file.hpp rename to test/webfuse/test_util/file.hpp diff --git a/test/webfuse/test_util/file_utils.cc b/test/webfuse/test_util/file_utils.cc deleted file mode 100644 index a5a62f7..0000000 --- a/test/webfuse/test_util/file_utils.cc +++ /dev/null @@ -1,38 +0,0 @@ -#include "webfuse/test_util/file_utils.hpp" - -#include -#include -#include - -namespace webfuse_test -{ - -bool is_dir(std::string const & path) -{ - struct stat info; - int rc = stat(path.c_str(), &info); - - return (0 == rc) && (S_ISDIR(info.st_mode)); -} - -bool is_symlink(std::string const & path) -{ - struct stat info; - int rc = lstat(path.c_str(), &info); - - return (0 == rc) && (S_ISLNK(info.st_mode)); -} - -bool is_same_path(std::string const & path, std::string const & other) -{ - struct stat info; - int rc = stat(path.c_str(), &info); - - struct stat info_other; - int rc_other = stat(other.c_str(), &info_other); - - return (0 == rc) && (0 == rc_other) && (info.st_ino == info_other.st_ino); -} - - -} \ No newline at end of file diff --git a/test/webfuse/test_util/file_utils.hpp b/test/webfuse/test_util/file_utils.hpp deleted file mode 100644 index adb81d5..0000000 --- a/test/webfuse/test_util/file_utils.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef WF_TEST_UTIL_FILE_UTILS_HPP -#define WF_TEST_UTIL_FILE_UTILS_HPP - -#include - -namespace webfuse_test -{ - -bool is_dir(std::string const & path); - -bool is_symlink(std::string const & path); - -bool is_same_path(std::string const & path, std::string const & other); - -} - -#endif