mirror of
https://github.com/falk-werner/webfused
synced 2024-10-27 20:44:08 +00:00
added daemon test
This commit is contained in:
parent
1223363c6c
commit
35122136fd
@ -126,6 +126,7 @@ add_executable(alltests
|
||||
test/mock_pam.cc
|
||||
test/mock_libconfig.cc
|
||||
test/mock_linux.cc
|
||||
test/mock_server.cc
|
||||
test/test_config_factory.cc
|
||||
test/test_config.cc
|
||||
test/test_settings.cc
|
||||
@ -153,6 +154,8 @@ target_link_libraries(alltests PRIVATE
|
||||
-Wl,--wrap=wf_credentials_type
|
||||
-Wl,--wrap=wf_credentials_get
|
||||
|
||||
-Wl,--wrap=wf_server_create
|
||||
|
||||
-Wl,--wrap=wfd_settings_get_string
|
||||
-Wl,--wrap=wfd_settings_get_string_or_default
|
||||
-Wl,--wrap=wfd_settings_get_bool
|
||||
|
25
test/mock_server.cc
Normal file
25
test/mock_server.cc
Normal file
@ -0,0 +1,25 @@
|
||||
#include "mock_server.hpp"
|
||||
#include "wrap_utils.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
static webfused_test::IServer * wfd_MockServer = nullptr;
|
||||
|
||||
WFD_WRAP_FUNC1(wfd_MockServer, struct wf_server *, wf_server_create, struct wf_server_config *);
|
||||
|
||||
}
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
MockServer::MockServer()
|
||||
{
|
||||
wfd_MockServer = this;
|
||||
}
|
||||
|
||||
MockServer::~MockServer()
|
||||
{
|
||||
wfd_MockServer = nullptr;
|
||||
}
|
||||
|
||||
}
|
28
test/mock_server.hpp
Normal file
28
test/mock_server.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef WFD_MOCK_SERVER_HPP
|
||||
#define WFD_MOCK_SERVER_HPP
|
||||
|
||||
#include <webfuse/adapter/server.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
class IServer
|
||||
{
|
||||
public:
|
||||
virtual ~IServer() = default;
|
||||
virtual struct wf_server * wf_server_create(struct wf_server_config * config) = 0;
|
||||
};
|
||||
|
||||
class MockServer: public IServer
|
||||
{
|
||||
public:
|
||||
MockServer();
|
||||
~MockServer() override;
|
||||
MOCK_METHOD1(wf_server_create, struct wf_server * (struct wf_server_config * config));
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,10 +1,16 @@
|
||||
#include "webfused/daemon.h"
|
||||
|
||||
#include "mock_server.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstdlib>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
using ::webfused_test::MockServer;
|
||||
using ::testing::_;
|
||||
using ::testing::Return;
|
||||
|
||||
TEST(daemon, print_usage)
|
||||
{
|
||||
char argv0[] = "daemon";
|
||||
@ -66,3 +72,17 @@ TEST(daemon, run)
|
||||
|
||||
thread.join();
|
||||
}
|
||||
|
||||
TEST(daemon, run_failed_to_create_server)
|
||||
{
|
||||
MockServer server;
|
||||
EXPECT_CALL(server, wf_server_create(_)).Times(1).WillOnce(Return(nullptr));
|
||||
|
||||
char argv0[] = "daemon";
|
||||
char argv1[] = "-f";
|
||||
char argv2[] = "webfused.conf";
|
||||
char * argv[] = { argv0, argv1, argv2, NULL};
|
||||
|
||||
int exit_code = wfd_daemon_run(3, argv);
|
||||
ASSERT_EQ(EXIT_FAILURE, exit_code);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user