added basic unit test

pull/1/head
Falk Werner 4 years ago
parent 207f18f4fd
commit 141c857d4e

@ -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)

@ -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

@ -0,0 +1,13 @@
#include <gtest/gtest.h>
#include <libconfig.h>
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);
}
Loading…
Cancel
Save