diff --git a/CMakeLists.txt b/CMakeLists.txt index 22eb7f6..c97bb44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required (VERSION 3.10) project(webfused VERSION 0.1.0 DESCRIPTION "Webfuse daemon") +option(WITHOUT_TESTS "disable unit tests" OFF) + set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) @@ -78,3 +80,43 @@ target_include_directories(webfuse-passwd PUBLIC target_compile_options(webfuse-passwd PUBLIC ${OPENSSL_CFLAGS_OTHER}) install(TARGETS webfuse-passwd DESTINATION bin) + +if(NOT WITHOUT_TESTS) + + +set(THREADS_PREFER_PTHREAD_FLAG ON) +find_package(Threads REQUIRED) + + +include (CTest) + +pkg_check_modules(GTEST gtest_main) +include(GoogleTest) +pkg_check_modules(GMOCK gmock) + +add_executable(alltests + test/test_config.cc +) + +target_include_directories(alltests PRIVATE + src + ${GMOCK_INCLUDE_DIRS} + ${GTEST_INCLUDE_DIRS} +) + +target_compile_options(alltests PRIVATE ${GMOCK_CFLAGS} ${GTEST_CFLAGS} "-pthread") + +target_link_libraries(alltests PRIVATE + ${LIBCONFIG_LIBRARIES} + ${GMOCK_LIBRARIES} + ${GTEST_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} +) + +# copy test data +configure_file(etc/webfused.conf webfused.conf COPYONLY) + +enable_testing() +gtest_discover_tests(alltests TEST_PREFIX alltests:) + +endif(NOT WITHOUT_TESTS) diff --git a/README.md b/README.md index ab50b1e..8ce0f5f 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ To install dependecies, see below. - [jansson](https://github.com/akheron/jansson) - [openssl](https://www.openssl.org/) - [libconfig](https://hyperrealm.github.io/libconfig/) +- [Google Test](https://github.com/google/googletest) *(Test only)* ### Installing dependencies @@ -82,3 +83,16 @@ To install libfuse, meson is needed. Please refer to [meson quick guide](https:/ sudo apt update sudo apt install libconfig-dev + +#### GoogleTest + +Installation of GoogleTest is optional webfuse library, but required to compile tests. + + wget -O gtest-1.10.0.tar.gz https://github.com/google/googletest/archive/release-1.10.0.tar.gz + tar -xf gtest-1.10.0.tar.gz + cd googletest-release-1.10.0 + mkdir .build + cd .build + cmake .. + make + sudo make install diff --git a/test/test_config.cc b/test/test_config.cc new file mode 100644 index 0000000..55d8e56 --- /dev/null +++ b/test/test_config.cc @@ -0,0 +1,13 @@ +#include +#include + +TEST(config, is_loadable) +{ + config_t config; + config_init(&config); + + int result = config_read_file(&config, "webfused.conf"); + ASSERT_EQ(CONFIG_TRUE, result); + + config_destroy(&config); +} \ No newline at end of file