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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
#define BOOST_TEST_MODULE Maintenance
#include <boost/test/unit_test.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <options.h>
#include <Ice/ObjectAdapter.h>
#include <Ice/Service.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>
#include "mockDefs.h"
#include <slicer/db/sqlSelectDeserializer.h>
#include "commonHelpers.h"
#include <slicer/slicer.h>
using namespace P2PVR;
using namespace P2PVR::Testing;
namespace P2PVR {
namespace Testing {
class TestService : public SchemaOnlyMockDatabase {
public:
TestService()
{
replace("GlobalDevices", new MockDevices());
replace("Schedules", new MockScheduler());
}
};
}
}
BOOST_GLOBAL_FIXTURE( TestService );
BOOST_FIXTURE_TEST_SUITE( MaintCore, TestClient );
const int serviceId = 4170;
const int transportId = 20544;
const int eventId1 = 31;
const int eventId2 = 915;
//
// Run all these tests when there'si no data
// This tests behaviour from clean startup/fresh install
//
BOOST_AUTO_TEST_CASE( GetNetworks_emptySet )
{
BOOST_REQUIRE(si->GetNetworks().empty());
}
BOOST_AUTO_TEST_CASE( GetAllDeliveries_emptySet )
{
BOOST_REQUIRE(si->GetAllDeliveries().empty());
}
BOOST_AUTO_TEST_CASE( GetDeliveryForService_notFound )
{
BOOST_REQUIRE_THROW(si->GetDeliveryForService(serviceId), P2PVR::NotFound);
}
BOOST_AUTO_TEST_CASE( GetDeliveryForTransport_notFound )
{
BOOST_REQUIRE_THROW(si->GetDeliveryForTransport(transportId), P2PVR::NotFound);
}
BOOST_AUTO_TEST_CASE( GetDeliveryForSi_null )
{
BOOST_REQUIRE_EQUAL(si->GetDeliveryForSi(), DVBSI::DeliveryPtr());
}
BOOST_AUTO_TEST_CASE( GetServices_emptySet )
{
BOOST_REQUIRE(si->GetServices().empty());
}
BOOST_AUTO_TEST_CASE( GetService_notFound )
{
BOOST_REQUIRE_THROW(si->GetService(serviceId), P2PVR::NotFound);
}
BOOST_AUTO_TEST_CASE( GetSpecificEvents_notFound )
{
BOOST_REQUIRE_THROW(si->GetEvents({ eventId1, eventId2 }), P2PVR::NotFound);
}
//
// Now scan for and configure a network
//
BOOST_AUTO_TEST_CASE( update_network )
{
maint->UpdateNetwork(FE_OFDM);
}
BOOST_AUTO_TEST_CASE( GetNetworks )
{
auto ns = si->GetNetworks();
BOOST_REQUIRE_EQUAL(ns.size(), 1);
BOOST_REQUIRE_EQUAL(ns[0]->NetworkId, 12333);
BOOST_REQUIRE_EQUAL(ns[0]->Name, "Yorkshire");
}
BOOST_AUTO_TEST_CASE( GetDeliveryForService )
{
auto del = si->GetDeliveryForService(serviceId);
BOOST_REQUIRE(del);
BOOST_REQUIRE_EQUAL(del->ice_id(), "::DVBSI::TerrestrialDelivery");
BOOST_REQUIRE_EQUAL(del->Frequency, 682000000);
}
BOOST_AUTO_TEST_CASE( GetDeliveryForTransport )
{
auto del = si->GetDeliveryForTransport(transportId);
BOOST_REQUIRE(del);
BOOST_REQUIRE_EQUAL(del->ice_id(), "::DVBSI::TerrestrialDelivery");
BOOST_REQUIRE_EQUAL(del->Frequency, 722000000);
}
BOOST_AUTO_TEST_CASE( GetServices_stubs )
{
auto services = si->GetServices();
BOOST_REQUIRE_EQUAL(services.size(), 145);
BOOST_REQUIRE_EQUAL(services[0]->ServiceId, 4170);
BOOST_REQUIRE_EQUAL(services[0]->TransportStreamId, 4170);
// Definitely a stub
BOOST_REQUIRE(!services[0]->Name);
}
BOOST_AUTO_TEST_CASE( GetService_stubs )
{
auto service = si->GetService(serviceId);
BOOST_REQUIRE_EQUAL(service->ServiceId, serviceId);
// Definitely a stub
BOOST_REQUIRE(!service->Name);
}
BOOST_AUTO_TEST_CASE( GetDeliveryForSi_any )
{
auto del = si->GetDeliveryForSi();
BOOST_REQUIRE(del);
// Any yes, but is our case it should be DVB-T
BOOST_REQUIRE_EQUAL(del->ice_id(), "::DVBSI::TerrestrialDelivery");
}
BOOST_AUTO_TEST_CASE( UpdateNetwork_prepopulated )
{
// This should now run using existing transport data (although this test doesn't prove that)
maint->UpdateNetwork(FE_OFDM);
}
//
// Load in the service details
// Should give things names etc, but not add/remove
//
BOOST_AUTO_TEST_CASE( update_services )
{
maint->UpdateServices();
}
BOOST_AUTO_TEST_CASE( GetServices )
{
auto services = si->GetServices();
BOOST_REQUIRE_EQUAL(services.size(), 145);
BOOST_REQUIRE_EQUAL(services[0]->ServiceId, 4170);
BOOST_REQUIRE_EQUAL(services[0]->TransportStreamId, 4170);
BOOST_REQUIRE_EQUAL(services[0]->Name, "BBC ONE Yorks");
BOOST_REQUIRE_EQUAL(services[0]->DefaultAuthority, "fp.bbc.co.uk");
}
BOOST_AUTO_TEST_CASE( GetService )
{
auto service = si->GetService(serviceId);
BOOST_REQUIRE_EQUAL(service->ServiceId, serviceId);
BOOST_REQUIRE_EQUAL(service->TransportStreamId, 4170);
BOOST_REQUIRE_EQUAL(service->Name, "BBC ONE Yorks");
BOOST_REQUIRE_EQUAL(service->DefaultAuthority, "fp.bbc.co.uk");
}
BOOST_AUTO_TEST_CASE( update_events )
{
BOOST_TEST_CHECKPOINT("Get a DB connection for faking stuff");
auto db = DB::ConnectionPtr(DB::MockDatabase::openConnectionTo("postgres"));
BOOST_TEST_CHECKPOINT("Write first events");
MockTuner::SetEventsSet(0);
maint->UpdateEvents();
auto dayOneEvents = si->EventSearch(IceUtil::Optional<std::string>(), IceUtil::Optional<int>(),
Common::DateTime {2014, 12, 18, 3, 0}, Common::DateTime {2014, 12, 19, 3, 0});
BOOST_REQUIRE_EQUAL(dayOneEvents.size(), 3345);
BOOST_REQUIRE(si->GetEvent(14448, 27052));
BOOST_REQUIRE_THROW(si->GetEvent(15856, 3591), P2PVR::NotFound);
BOOST_TEST_CHECKPOINT("Fake some recorded stuff");
auto keyEvent1 = si->GetEvent(25664, 55689);
auto keyEvent2 = si->GetEvent(24256, 1014);
db->execute("INSERT INTO schedules(repeats) VALUES(false)");
auto irecorded = boost::shared_ptr<DB::ModifyCommand>(
db->newModifyCommand("INSERT INTO recorded(scheduleId, eventUid) VALUES(?, ?)"));
irecorded->bindParamI(0, 1);
irecorded->bindParamI(1, keyEvent1->EventUid);
irecorded->execute();
auto irecordings = boost::shared_ptr<DB::ModifyCommand>(
db->newModifyCommand("INSERT INTO recordings(scheduleId, eventUid) VALUES(?, ?)"));
irecordings->bindParamI(0, 1);
irecordings->bindParamI(1, keyEvent2->EventUid);
irecordings->execute();
BOOST_REQUIRE(keyEvent1);
BOOST_REQUIRE(keyEvent2);
BOOST_REQUIRE(keyEvent1->Current);
BOOST_REQUIRE_EQUAL(keyEvent1->StartTime, Common::DateTime({2014, 12, 18, 21, 0}));
BOOST_REQUIRE(keyEvent2->Current);
BOOST_REQUIRE_EQUAL(keyEvent2->StartTime, Common::DateTime({2014, 12, 17, 5, 30}));
BOOST_TEST_CHECKPOINT("Write second events");
MockTuner::SetEventsSet(1);
maint->UpdateEvents();
BOOST_REQUIRE_THROW(si->GetEvent(14448, 27052), P2PVR::NotFound);
BOOST_REQUIRE(si->GetEvent(15856, 3591));
BOOST_TEST_CHECKPOINT("Check our faked stuff is still there and right");
auto dayOneEventsOnDayTwo = si->EventSearch(IceUtil::Optional<std::string>(), IceUtil::Optional<int>(),
Common::DateTime {2014, 12, 18, 3, 0}, Common::DateTime {2014, 12, 19, 3, 0});
// Some datetime range overlap, but most are gone
BOOST_REQUIRE_EQUAL(dayOneEventsOnDayTwo.size(), 373);
BOOST_REQUIRE_EQUAL(std::count_if(dayOneEventsOnDayTwo.begin(), dayOneEventsOnDayTwo.end(),
[](const P2PVR::EventPtr & e) {
return (e->ServiceId == 25664 && e->EventId == 55689)
|| (e->ServiceId == 24256 && e->EventId == 1014); }), 0);
auto keyEventsOnDayTwo = si->GetEvents({keyEvent1->EventUid, keyEvent2->EventUid});
BOOST_REQUIRE_EQUAL(keyEventsOnDayTwo.size(), 2);
BOOST_REQUIRE(!keyEventsOnDayTwo[0]->Current);
BOOST_REQUIRE(!keyEventsOnDayTwo[1]->Current);
BOOST_REQUIRE_EQUAL(keyEvent1->Title, keyEventsOnDayTwo[0]->Title);
BOOST_REQUIRE_EQUAL(keyEvent2->Title, keyEventsOnDayTwo[1]->Title);
}
BOOST_AUTO_TEST_CASE( test_titleFiltering )
{
auto thingsWithNew = si->EventSearch("new", IceUtil::Optional<int>(),
IceUtil::Optional<Common::DateTime>(), IceUtil::Optional<Common::DateTime>());
BOOST_REQUIRE_EQUAL(0, std::count_if(thingsWithNew.begin(), thingsWithNew.end(), [](auto e) {
return boost::algorithm::starts_with(e->Title, "New:");
}));
}
BOOST_AUTO_TEST_SUITE_END()
|