PageRenderTime 22ms CodeModel.GetById 10ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/test/unit/testDaemon.cpp

https://github.com/deltaforge/nebu-app-framework-cpp
C++ | 81 lines | 59 code | 18 blank | 4 comment | 0 complexity | d15c339e47c26cff0dab877af22485f5 MD5 | raw file
 1
 2#include "nebu-app-framework/daemon.h"
 3
 4#include "log4cxx/basicconfigurator.h"
 5
 6#include "gtest/gtest.h"
 7#include "gmock/gmock.h"
 8
 9// Using declarations - standard library
10using std::make_shared;
11using std::shared_ptr;
12using std::string;
13// Using declarations - nebu-common
14using nebu::common::VirtualMachine;
15// Using declarations - nebu-app-framework
16using nebu::app::framework::Daemon;
17using nebu::app::framework::DaemonType;
18// Using declarations - gtest/gmock
19using testing::Eq;
20
21class StubDaemon : public Daemon
22{
23public:
24	StubDaemon(shared_ptr<VirtualMachine> vm) : Daemon(vm) { }
25	virtual ~StubDaemon() { }
26
27	virtual bool launch() { return false; }
28	virtual DaemonType getType() const { return 0; }
29
30	void clearLaunched() { this->launched = false; }
31	void setLaunched() { this->launched = true; }
32};
33
34TEST(DaemonTest, testConstructorSetsVM) {
35	shared_ptr<VirtualMachine> vm = make_shared<VirtualMachine>("Some VM");
36	StubDaemon daemon(vm);
37
38	EXPECT_THAT(daemon.getHostVM(), Eq(vm));
39}
40
41TEST(DaemonTest, testConstructorDefaultsLaunchedToFalse) {
42	shared_ptr<VirtualMachine> vm = make_shared<VirtualMachine>("Some VM");
43	StubDaemon daemon(vm);
44
45	EXPECT_THAT(daemon.hasLaunched(), Eq(false));
46}
47
48TEST(DaemonTest, testGetHostname) {
49	string hostname = "Some Hostname";
50	string altHostname = "Updated Hostname";
51	shared_ptr<VirtualMachine> vm = make_shared<VirtualMachine>("Some VM");
52	StubDaemon daemon(vm);
53
54	vm->setHostname(hostname);
55	EXPECT_THAT(daemon.getHostname(), Eq(hostname));
56	vm->setHostname(altHostname);
57	EXPECT_THAT(daemon.getHostname(), Eq(altHostname));
58}
59
60TEST(DaemonTest, testHasLaunchedFalse) {
61	shared_ptr<VirtualMachine> vm = make_shared<VirtualMachine>("Some VM");
62	StubDaemon daemon(vm);
63
64	daemon.clearLaunched();
65	EXPECT_THAT(daemon.hasLaunched(), Eq(false));
66}
67
68TEST(DaemonTest, testHasLaunchedTrue) {
69	shared_ptr<VirtualMachine> vm = make_shared<VirtualMachine>("Some VM");
70	StubDaemon daemon(vm);
71
72	daemon.setLaunched();
73	EXPECT_THAT(daemon.hasLaunched(), Eq(true));
74}
75
76int main(int argc, char **argv) {
77	log4cxx::BasicConfigurator::configure();
78	log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getOff());
79	testing::InitGoogleMock(&argc, argv);
80	return RUN_ALL_TESTS();
81}