From c9eb703da1960740d4c04fcee39d75382124760d Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Mon, 6 May 2019 22:24:01 +0200 Subject: [PATCH] adds some integration tests --- CMakeLists.txt | 1 + test/die_if.cc | 15 +++++ test/die_if.hpp | 11 ++++ test/integration/provider.cc | 2 +- test/integration/test_integration.cc | 92 ++++++++++++++++++++++++++-- 5 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 test/die_if.cc create mode 100644 test/die_if.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index bd617ec..5ce597b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -292,6 +292,7 @@ pkg_check_modules(GMOCK gmock) add_executable(alltests test/msleep.cc + test/die_if.cc test/mock_authenticator.cc test/mock_request.cc test/core/test_container_of.cc diff --git a/test/die_if.cc b/test/die_if.cc new file mode 100644 index 0000000..3eff5ae --- /dev/null +++ b/test/die_if.cc @@ -0,0 +1,15 @@ +#include "die_if.hpp" +#include + +namespace webfuse_test +{ + +void die_if(bool expression) +{ + if (expression) + { + exit(EXIT_FAILURE); + } +} + +} \ No newline at end of file diff --git a/test/die_if.hpp b/test/die_if.hpp new file mode 100644 index 0000000..95d3ff2 --- /dev/null +++ b/test/die_if.hpp @@ -0,0 +1,11 @@ +#ifndef WF_TEST_DIE_IF_HPP +#define WF_TEST_DIE_IF_HPP + +namespace webfuse_test +{ + +extern void die_if(bool expression); + +} + +#endif diff --git a/test/integration/provider.cc b/test/integration/provider.cc index 0fe3456..19e95cc 100644 --- a/test/integration/provider.cc +++ b/test/integration/provider.cc @@ -18,7 +18,7 @@ public: config = wfp_client_config_create(); fs = wfp_static_filesystem_create(config); - wfp_static_filesystem_add_text(fs, "hello.txt", 0x444, "Hello, World"); + wfp_static_filesystem_add_text(fs, "hello.txt", 0444, "Hello, World"); client = wfp_client_create(config); wfp_client_connect(client, url); diff --git a/test/integration/test_integration.cc b/test/integration/test_integration.cc index d045691..5994516 100644 --- a/test/integration/test_integration.cc +++ b/test/integration/test_integration.cc @@ -2,20 +2,25 @@ #include "integration/server.hpp" #include "integration/provider.hpp" +#include #include +#include #include #include #include #include +#include #include #include "webfuse/core/lws_log.h" #include "msleep.hpp" +#include "die_if.hpp" using webfuse_test::Server; using webfuse_test::Provider; +using webfuse_test::die_if; namespace { @@ -69,10 +74,85 @@ TEST_F(IntegrationTest, ProvidesTextFile) struct stat buffer; int rc = stat(file_name.c_str(), &buffer); - exit(rc); - }, ::testing::ExitedWithCode(0), ".*"); - - // ASSERT_TRUE(S_ISREG(buffer.st_mode)); - // ASSERT_EQ(0444, (buffer.st_mode & 0777)); - // ASSERT_EQ(12, buffer.st_size); + die_if(0 != rc); + die_if(!S_ISREG(buffer.st_mode)); + die_if(0444 != (buffer.st_mode & 0777)); + die_if(12 != buffer.st_size); + + exit(0); + }, ::testing::ExitedWithCode(0), ".*"); +} + +TEST_F(IntegrationTest, ReadTextFile) +{ + webfuse_test::msleep(200); + std::string file_name = std::string(GetBaseDir()) + "/cprovider/default/hello.txt"; + + ASSERT_EXIT({ + FILE * file = fopen(file_name.c_str(), "rb"); + die_if(nullptr == file); + + char buffer[13]; + ssize_t count = fread(buffer, 1, 12, file); + int rc = fclose(file); + + die_if(12 != count); + die_if(0 != strncmp("Hello, World", buffer, 12)); + die_if(0 != rc); + + exit(0); + }, ::testing::ExitedWithCode(0), ".*"); + +} + +TEST_F(IntegrationTest, ReadDir) +{ + webfuse_test::msleep(200); + std::string dir_name = std::string(GetBaseDir()) + "/cprovider/default"; + + ASSERT_EXIT({ + + DIR * dir = opendir(dir_name.c_str()); + die_if(nullptr == dir); + + bool found_self = false; + bool found_parent = false; + bool found_hello_txt = false; + bool found_other = false; + + dirent * entry = readdir(dir); + while (NULL != entry) + { + if (0 == strcmp(".", entry->d_name)) + { + found_self = true; + } + else if (0 == strcmp("..", entry->d_name)) + { + found_parent = true; + } + else if (0 == strcmp("hello.txt", entry->d_name)) + { + found_hello_txt = true; + } + else + { + found_other = true; + } + + + entry = readdir(dir); + } + + closedir(dir); + + die_if(!found_self); + die_if(!found_parent); + die_if(!found_hello_txt); + + die_if(found_other); + + exit(0); + }, ::testing::ExitedWithCode(0), ".*"); + } \ No newline at end of file