summaryrefslogtreecommitdiff
path: root/p2pvr/daemon/unittests/testMaint.cpp
blob: 10f365e06591d86cf565b27abe8f1f5d64510fc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#define BOOST_TEST_MODULE Maintenance
#include <boost/test/unit_test.hpp>
#include <boost/filesystem/operations.hpp>
#include <testOptionsSource.h>
#include <Ice/ObjectAdapter.h>
#include <Ice/Service.h>
#include <scopeObject.h>
#include <maintenance.h>
#include <mockTuner.h>
#include "mockDevices.h"
#include "mockScheduler.h"
#include <si.h>
#include <recordings.h>
#include <linux/dvb/frontend.h>
#include <definedDirs.h>

class Core {
	public:
		Core()
		{
			int paramCount = 0;
			ic = Ice::initialize(paramCount, NULL);
			auto adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12000");
			TestOptionsSource::LoadTestOptions({
					{ "common.datasourceRoot", (RootDir / "datasources").string() },
				});
			adapter->add(new MockDevices(), ic->stringToIdentity("GlobalDevices"));
			adapter->add(new MockScheduler(), ic->stringToIdentity("Schedules"));
			adapter->add(new SI(), ic->stringToIdentity("SI"));
			adapter->add(new Recordings(), ic->stringToIdentity("Recordings"));
			adapter->add(new Maintenance(adapter, NULL), ic->stringToIdentity("Maintenance"));
			adapter->activate();

			r = P2PVR::RecordingsPrx::checkedCast(ic->stringToProxy("Recordings"));
			BOOST_REQUIRE(r);
			r->ice_ping();

			s = P2PVR::SIPrx::checkedCast(ic->stringToProxy("SI"));
			BOOST_REQUIRE(s);
			s->ice_ping();
	
			m = P2PVR::MaintenancePrx::checkedCast(ic->stringToProxy("Maintenance"));
			BOOST_REQUIRE(m);
			m->ice_ping();
		}

		~Core()
		{
			ic->destroy();
		}

		P2PVR::MaintenancePrx m;
		P2PVR::RecordingsPrx r;
		P2PVR::SIPrx s;

	private:
		Ice::CommunicatorPtr ic;
};

BOOST_FIXTURE_TEST_SUITE( MaintCore, Core )

BOOST_AUTO_TEST_CASE( update_network )
{
	m->UpdateNetwork(FE_OFDM);
}

BOOST_AUTO_TEST_CASE( update_services )
{
	m->UpdateServices(FE_OFDM);
}

BOOST_AUTO_TEST_CASE( update_events )
{
	BOOST_CHECKPOINT("Get existing recordings");
	auto recs = r->GetRecordings();

	BOOST_CHECKPOINT("Delete existing recordings");
	BOOST_FOREACH(const auto & rec, recs) {
		r->DeleteRecording(rec->RecordingId);
	}

	BOOST_CHECKPOINT("Write first events");
	MockTuner::SetEventsSet(0);
	m->UpdateEvents(FE_OFDM);
	BOOST_REQUIRE(s->GetEvent(14448, 27052));
	BOOST_REQUIRE_THROW(s->GetEvent(15856, 3591), P2PVR::NotFound);

	BOOST_CHECKPOINT("Write second events");
	MockTuner::SetEventsSet(1);
	m->UpdateEvents(FE_OFDM);
	BOOST_REQUIRE_THROW(s->GetEvent(14448, 27052), P2PVR::NotFound);
	BOOST_REQUIRE(s->GetEvent(15856, 3591));
}

BOOST_AUTO_TEST_SUITE_END()