1
0
mirror of https://github.com/falk-werner/webfused synced 2024-10-27 20:44:08 +00:00

added basic tests for daemon

This commit is contained in:
Falk Werner 2020-03-18 18:00:53 +01:00
parent adbfd45951
commit 1cd1b1ddff
3 changed files with 72 additions and 0 deletions

View File

@ -129,6 +129,7 @@ add_executable(alltests
test/test_log_manager.cc
test/test_stderr_logger.cc
test/test_syslog_logger.cc
test/test_daemon.cc
)
target_include_directories(alltests PRIVATE
@ -180,6 +181,7 @@ add_custom_target(coverage
COMMAND lcov -a coverage/lcov_base.info -a coverage/lcov.info --output-file coverage/lcov.info --rc lcov_branch_coverage=1
COMMAND lcov --remove coverage/lcov.info '/usr/*' --output-file coverage/lcov.info --rc lcov_branch_coverage=1
COMMAND lcov --remove coverage/lcov.info '*/test/*' --output-file coverage/lcov.info --rc lcov_branch_coverage=1
COMMAND lcov --remove coverage/lcov.info '*/main.c' --output-file coverage/lcov.info --rc lcov_branch_coverage=1
)
add_dependencies(coverage alltests)

View File

@ -56,6 +56,7 @@ static int parse_arguments(int argc, char * argv[], struct args * args)
bool result = EXIT_SUCCESS;
bool finished = false;
optind = 0;
while ((!finished) && (EXIT_SUCCESS == result))
{
int option_index = 0;
@ -144,6 +145,7 @@ int wfd_daemon_run(int argc, char * argv[])
wfd_logger_close();
free(args.config_file);
shutdown_requested = false;
return result;
}

68
test/test_daemon.cc Normal file
View File

@ -0,0 +1,68 @@
#include "webfused/daemon.h"
#include <gtest/gtest.h>
#include <cstdlib>
#include <chrono>
#include <thread>
TEST(daemon, print_usage)
{
char argv0[] = "daemon";
char argv1[] = "--help";
char * argv[] = { argv0, argv1, NULL};
int exit_code = wfd_daemon_run(2, argv);
ASSERT_EQ(EXIT_SUCCESS, exit_code);
}
TEST(daemon, print_usage_short)
{
char argv0[] = "daemon";
char argv1[] = "-h";
char * argv[] = { argv0, argv1, NULL};
int exit_code = wfd_daemon_run(2, argv);
ASSERT_EQ(EXIT_SUCCESS, exit_code);
}
TEST(daemon, fail_invalid_argument)
{
char argv0[] = "daemon";
char argv1[] = "-x";
char * argv[] = { argv0, argv1, NULL};
int exit_code = wfd_daemon_run(2, argv);
ASSERT_EQ(EXIT_FAILURE, exit_code);
}
TEST(daemon, fail_invalid_config_file)
{
char argv0[] = "daemon";
char argv1[] = "-f";
char argv2[] = "invalid.conf";
char * argv[] = { argv0, argv1, argv2, NULL};
int exit_code = wfd_daemon_run(3, argv);
ASSERT_EQ(EXIT_FAILURE, exit_code);
}
void defered_raise()
{
std::this_thread::sleep_for(std::chrono::milliseconds(50));
raise(SIGINT);
}
TEST(daemon, run)
{
char argv0[] = "daemon";
char argv1[] = "-f";
char argv2[] = "webfused.conf";
char * argv[] = { argv0, argv1, argv2, NULL};
std::thread thread(defered_raise);
int exit_code = wfd_daemon_run(3, argv);
ASSERT_EQ(EXIT_SUCCESS, exit_code);
thread.join();
}