summaryrefslogtreecommitdiff
path: root/p2pvr/daemon
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-01-21 15:27:32 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-06-13 17:29:48 +0100
commitfdddf1b3176a610d60c775bf06386c6d26462e0d (patch)
tree64d0ab3dd807aa1846eefb4278ec375451faa27c /p2pvr/daemon
parentThrow specific exception (NoRowsFound) when a row is required but none are re... (diff)
downloadp2pvr-fdddf1b3176a610d60c775bf06386c6d26462e0d.tar.bz2
p2pvr-fdddf1b3176a610d60c775bf06386c6d26462e0d.tar.xz
p2pvr-fdddf1b3176a610d60c775bf06386c6d26462e0d.zip
Fix up and fully UT the setup from empty and maintenance process
Diffstat (limited to 'p2pvr/daemon')
-rw-r--r--p2pvr/daemon/si.cpp42
-rw-r--r--p2pvr/daemon/si.h1
-rw-r--r--p2pvr/daemon/sql/SI_allNetworks.sql3
-rw-r--r--p2pvr/daemon/unittests/testMaint.cpp142
4 files changed, 170 insertions, 18 deletions
diff --git a/p2pvr/daemon/si.cpp b/p2pvr/daemon/si.cpp
index 0b93bc4..9164a62 100644
--- a/p2pvr/daemon/si.cpp
+++ b/p2pvr/daemon/si.cpp
@@ -6,6 +6,7 @@
#include <slicer/slicer.h>
#include <logger.h>
+ResourceString(SI_allNetworks, sql_SI_allNetworks);
ResourceString(SI_allDeliveries, sql_SI_allDeliveries);
ResourceString(SI_deliveryForTransport, sql_SI_deliveryForTransport);
ResourceString(SI_deliveryForService, sql_SI_deliveryForService);
@@ -20,6 +21,14 @@ ResourceString(SI_eventsInSchedules, sql_SI_eventsInSchedules);
ResourceString(SI_eventsInRange, sql_SI_eventsInRange);
ResourceString(SI_eventSearch, sql_SI_eventSearch);
+DVBSI::Networks
+SI::GetNetworks(const Ice::Current &)
+{
+ Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__);
+ return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::Networks>(
+ *Select(SI_allNetworks).second);
+}
+
P2PVR::Deliveries
SI::GetAllDeliveries(const Ice::Current &)
{
@@ -33,25 +42,40 @@ SI::GetAllDeliveries(const Ice::Current &)
DVBSI::DeliveryPtr
SI::GetDeliveryForTransport(int id, const Ice::Current&)
{
- Logger()->messagef(LOG_DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id);
- return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::DeliveryPtr>(
- *Select(SI_deliveryForTransport, id).second, "delivery_type");
+ try {
+ Logger()->messagef(LOG_DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id);
+ return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::DeliveryPtr>(
+ *Select(SI_deliveryForTransport, id).second, "delivery_type");
+ }
+ catch (const NoRowsReturned &) {
+ throw P2PVR::NotFound();
+ }
}
DVBSI::DeliveryPtr
SI::GetDeliveryForSi(const Ice::Current&)
{
- Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__);
- return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::DeliveryPtr>(
- *Select(SI_serviceNextUsed).second, "delivery_type");
+ try {
+ Logger()->message(LOG_DEBUG, __PRETTY_FUNCTION__);
+ return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::DeliveryPtr>(
+ *Select(SI_serviceNextUsed).second, "delivery_type");
+ }
+ catch (const NoRowsReturned &) {
+ return NULL;
+ }
}
DVBSI::DeliveryPtr
SI::GetDeliveryForService(int id, const Ice::Current&)
{
- Logger()->messagef(LOG_DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id);
- return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::DeliveryPtr>(
- *Select(SI_deliveryForService, id).second, "delivery_type");
+ try {
+ Logger()->messagef(LOG_DEBUG, "%s(%d)", __PRETTY_FUNCTION__, id);
+ return Slicer::DeserializeAny<SqlSelectDeserializer, DVBSI::DeliveryPtr>(
+ *Select(SI_deliveryForService, id).second, "delivery_type");
+ }
+ catch (const NoRowsReturned &) {
+ throw P2PVR::NotFound();
+ }
}
DVBSI::ServiceList
diff --git a/p2pvr/daemon/si.h b/p2pvr/daemon/si.h
index d87b3b5..c57a018 100644
--- a/p2pvr/daemon/si.h
+++ b/p2pvr/daemon/si.h
@@ -6,6 +6,7 @@
class SI : public P2PVR::SI, public DatabaseClient {
public:
+ DVBSI::Networks GetNetworks(const Ice::Current &);
P2PVR::Deliveries GetAllDeliveries(const Ice::Current &);
DVBSI::DeliveryPtr GetDeliveryForService(int id, const Ice::Current &);
DVBSI::DeliveryPtr GetDeliveryForTransport(int id, const Ice::Current &);
diff --git a/p2pvr/daemon/sql/SI_allNetworks.sql b/p2pvr/daemon/sql/SI_allNetworks.sql
new file mode 100644
index 0000000..37d7e64
--- /dev/null
+++ b/p2pvr/daemon/sql/SI_allNetworks.sql
@@ -0,0 +1,3 @@
+SELECT *
+FROM networks
+ORDER BY networkId
diff --git a/p2pvr/daemon/unittests/testMaint.cpp b/p2pvr/daemon/unittests/testMaint.cpp
index ae8e15c..b399951 100644
--- a/p2pvr/daemon/unittests/testMaint.cpp
+++ b/p2pvr/daemon/unittests/testMaint.cpp
@@ -58,30 +58,154 @@ class Core {
Ice::CommunicatorPtr ic;
};
-BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
+BOOST_GLOBAL_FIXTURE( SchemaOnlyMockDatabase );
-BOOST_FIXTURE_TEST_SUITE( MaintCore, Core )
+BOOST_FIXTURE_TEST_SUITE( MaintCore, Core );
+
+const int serviceId = 4170;
+const int transportId = 20544;
+const int eventId1 = 31;
+const int eventId2 = 915;
+
+//
+// Run all these tests when there's no data
+// This tests behaviour from clean startup/fresh install
+//
+BOOST_AUTO_TEST_CASE( GetNetworks_emptySet )
+{
+ BOOST_REQUIRE(s->GetNetworks().empty());
+}
+
+BOOST_AUTO_TEST_CASE( GetAllDeliveries_emptySet )
+{
+ BOOST_REQUIRE(s->GetAllDeliveries().empty());
+}
+
+BOOST_AUTO_TEST_CASE( GetDeliveryForService_notFound )
+{
+ BOOST_REQUIRE_THROW(s->GetDeliveryForService(serviceId), P2PVR::NotFound);
+}
+
+BOOST_AUTO_TEST_CASE( GetDeliveryForTransport_notFound )
+{
+ BOOST_REQUIRE_THROW(s->GetDeliveryForTransport(transportId), P2PVR::NotFound);
+}
+
+BOOST_AUTO_TEST_CASE( GetDeliveryForSi_null )
+{
+ BOOST_REQUIRE_EQUAL(s->GetDeliveryForSi(), DVBSI::DeliveryPtr());
+}
+
+BOOST_AUTO_TEST_CASE( GetServices_emptySet )
+{
+ BOOST_REQUIRE(s->GetServices().empty());
+}
+
+BOOST_AUTO_TEST_CASE( GetService_notFound )
+{
+ BOOST_REQUIRE_THROW(s->GetService(serviceId), P2PVR::NotFound);
+}
+
+BOOST_AUTO_TEST_CASE( GetSpecificEvents_notFound )
+{
+ BOOST_REQUIRE_THROW(s->GetEvents({ eventId1, eventId2 }), P2PVR::NotFound);
+}
+
+//
+// Now scan for and configure a network
+//
BOOST_AUTO_TEST_CASE( update_network )
{
m->UpdateNetwork(FE_OFDM);
}
+BOOST_AUTO_TEST_CASE( GetNetworks )
+{
+ auto ns = s->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 = s->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 = s->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 = s->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 = s->GetService(serviceId);
+ BOOST_REQUIRE_EQUAL(service->ServiceId, serviceId);
+ // Definitely a stub
+ BOOST_REQUIRE(!service->Name);
+}
+
+BOOST_AUTO_TEST_CASE( GetDeliveryForSi_any )
+{
+ auto del = s->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)
+ m->UpdateNetwork(FE_OFDM);
+}
+
+//
+// Load in the service details
+// Should give things names etc, but not add/remove
+//
BOOST_AUTO_TEST_CASE( update_services )
{
m->UpdateServices(FE_OFDM);
}
-BOOST_AUTO_TEST_CASE( update_events )
+BOOST_AUTO_TEST_CASE( GetServices )
{
- BOOST_CHECKPOINT("Get existing recordings");
- auto recs = r->GetRecordings();
+ auto services = s->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_CHECKPOINT("Delete existing recordings");
- for (const auto & rec : recs) {
- r->DeleteRecording(rec->RecordingId);
- }
+BOOST_AUTO_TEST_CASE( GetService )
+{
+ auto service = s->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_CHECKPOINT("Write first events");
MockTuner::SetEventsSet(0);
m->UpdateEvents(FE_OFDM);