summaryrefslogtreecommitdiff
path: root/p2pvr/daemon/unittests/testSi.cpp
blob: 9e42e74ed39ac7a87141187575d70bea50ba3781 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#define BOOST_TEST_MODULE SI
#include <boost/test/unit_test.hpp>
#include <boost/filesystem/operations.hpp>
#include <testOptionsSource.h>
#include <Ice/ObjectAdapter.h>
#include <Ice/Service.h>
#include <maintenance.h>
#include <mockTuner.h>
#include <si.h>
#include <linux/dvb/frontend.h>
#include <definedDirs.h>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/lexical_cast.hpp>
#include "mockDefs.h"
#include <testAppInstance.h>

class Core : public TestAppInstance {
	public:
		Core()
		{
			int paramCount = 0;
			ic = Ice::initialize(paramCount, NULL);
			auto adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12002");
			TestOptionsSource::LoadTestOptions({
					{ "common.datasourceRoot", (rootDir / "datasources").string() },
				});
			adapter->add(new SI(), ic->stringToIdentity("SI"));
			adapter->activate();

			si = P2PVR::SIPrx::checkedCast(ic->stringToProxy("SI"));
			BOOST_REQUIRE(si);
			si->ice_ping();
		}

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

		P2PVR::SIPrx si;

	private:
		Ice::CommunicatorPtr ic;
};

BOOST_GLOBAL_FIXTURE( StandardMockDatabase );

BOOST_FIXTURE_TEST_SUITE( SiCore, Core )

BOOST_AUTO_TEST_CASE ( si_getEvents )
{
	// Get an event known to exist so we can use its uid
	auto event = si->GetEvent(23968, 4378);
	BOOST_REQUIRE(event);

	auto events = si->GetEvents({ event->EventUid });
	BOOST_REQUIRE_EQUAL(events.size(), 1);
	BOOST_REQUIRE_EQUAL(events.front()->ServiceId, 23968);
	BOOST_REQUIRE_EQUAL(events.front()->EventId, 4378);
}

BOOST_AUTO_TEST_CASE ( si_getEvents_missing )
{
	BOOST_REQUIRE_THROW(si->GetEvents({ 0 }), P2PVR::NotFound);
}

BOOST_AUTO_TEST_CASE( si_getEvent )
{
	auto event = si->GetEvent(23968, 4378);
	BOOST_REQUIRE(event);
	BOOST_REQUIRE_EQUAL(event->Title, "Timothy Goes to School");
	BOOST_REQUIRE_EQUAL(event->Current, true);
}

BOOST_AUTO_TEST_CASE( si_getEvent_missing )
{
	BOOST_REQUIRE_THROW(si->GetEvent(0, 0), P2PVR::NotFound);
}

BOOST_AUTO_TEST_CASE( si_getEventsOnNow )
{
	si->EventsOnNow();
}

BOOST_AUTO_TEST_CASE( si_getEventsInSched )
{
	si->EventsInSchedule(0);
}

BOOST_AUTO_TEST_CASE( si_getEventsInScheds )
{
	si->EventsInSchedules();
}

BOOST_AUTO_TEST_CASE( si_getEventsInRange )
{
	si->EventsInRange(Common::DateTime {2014, 12, 19, 3, 0}, Common::DateTime {2014, 12, 20, 3, 0});
}

BOOST_AUTO_TEST_CASE( si_getEventSearch )
{
	si->EventSearch("Top Gear", IceUtil::Optional< ::Ice::Int >(),
			IceUtil::Optional<Common::DateTime>(), IceUtil::Optional<Common::DateTime>());
	si->EventSearch("Top Gear", 22272,
			IceUtil::Optional<Common::DateTime>(), IceUtil::Optional<Common::DateTime>());
	si->EventSearch("Top Gear", 22272,
			Common::DateTime {2014, 12, 19, 3, 0}, IceUtil::Optional<Common::DateTime>());
	si->EventSearch("Top Gear", 22272,
			Common::DateTime {2014, 12, 19, 3, 0}, Common::DateTime {2014, 12, 20, 3, 0});
}

BOOST_AUTO_TEST_CASE( si_getAllDeliveries )
{
	auto dels = si->GetAllDeliveries();
	BOOST_REQUIRE_EQUAL(dels.size(), 6);
}

BOOST_AUTO_TEST_CASE( si_getDeliveryForTransport )
{
	auto del = si->GetDeliveryForTransport(4170);
	BOOST_REQUIRE(del);
	auto dvbt = DVBSI::TerrestrialDeliveryPtr::dynamicCast(del);
	BOOST_REQUIRE(dvbt);
	BOOST_REQUIRE_EQUAL(dvbt->TransportStreamId, 4170);
}

BOOST_AUTO_TEST_CASE( si_getDeliveryForSI )
{
	auto del = si->GetDeliveryForSi();
	BOOST_REQUIRE(del);
	auto dvbt = DVBSI::TerrestrialDeliveryPtr::dynamicCast(del);
	BOOST_REQUIRE(dvbt);
}

BOOST_AUTO_TEST_CASE( si_getDeliveryForService )
{
	auto del = si->GetDeliveryForService(4170);
	BOOST_REQUIRE(del);
	auto dvbt = DVBSI::TerrestrialDeliveryPtr::dynamicCast(del);
	BOOST_REQUIRE(dvbt);
	BOOST_REQUIRE_EQUAL(dvbt->TransportStreamId, 4170);
}

BOOST_AUTO_TEST_CASE( si_getServices )
{
	auto services = si->GetServices();
	BOOST_REQUIRE_EQUAL(services.size(), 145);
	BOOST_REQUIRE_EQUAL(services[0]->Name, "BBC ONE Yorks");
	BOOST_REQUIRE_EQUAL(services[0]->DefaultAuthority, "fp.bbc.co.uk");
	BOOST_REQUIRE_EQUAL(services[0]->EitSchedule, true);
	BOOST_REQUIRE_EQUAL(services[0]->EitPresentFollowing, true);
}

BOOST_AUTO_TEST_CASE( si_getService )
{
	auto service = si->GetService(4170);
	BOOST_REQUIRE_EQUAL(service->Name, "BBC ONE Yorks");
	BOOST_REQUIRE_EQUAL(service->DefaultAuthority, "fp.bbc.co.uk");
	BOOST_REQUIRE_EQUAL(service->EitSchedule, true);
	BOOST_REQUIRE_EQUAL(service->EitPresentFollowing, true);
}

BOOST_AUTO_TEST_CASE( si_getServiceMissing )
{
	BOOST_REQUIRE_THROW(si->GetService(0), P2PVR::NotFound);
}

BOOST_AUTO_TEST_SUITE_END()