diff options
| -rw-r--r-- | p2pvr/daemon/si.cpp | 42 | ||||
| -rw-r--r-- | p2pvr/daemon/si.h | 1 | ||||
| -rw-r--r-- | p2pvr/daemon/sql/SI_allNetworks.sql | 3 | ||||
| -rw-r--r-- | p2pvr/daemon/unittests/testMaint.cpp | 142 | ||||
| -rw-r--r-- | p2pvr/ice/dvbsi.ice | 1 | ||||
| -rw-r--r-- | p2pvr/ice/p2pvr.ice | 6 | 
6 files changed, 175 insertions, 20 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); diff --git a/p2pvr/ice/dvbsi.ice b/p2pvr/ice/dvbsi.ice index 9c3d74b..6144455 100644 --- a/p2pvr/ice/dvbsi.ice +++ b/p2pvr/ice/dvbsi.ice @@ -80,6 +80,7 @@ module DVBSI {  		[ "slicer:merge:omit" ]  		NetworkTransportStreams TransportStreams;  	}; +	sequence<Network> Networks;  	class BouquetTransportStream {  		[ "slicer:merge:key" ] diff --git a/p2pvr/ice/p2pvr.ice b/p2pvr/ice/p2pvr.ice index c384651..f120b95 100644 --- a/p2pvr/ice/p2pvr.ice +++ b/p2pvr/ice/p2pvr.ice @@ -107,10 +107,12 @@ module P2PVR {  	sequence<DVBSI::Delivery> Deliveries;  	sequence<int> IntSequence;  	interface SI { +		// Get networks +		idempotent DVBSI::Networks GetNetworks();  		// Get delivery methods  		idempotent Deliveries GetAllDeliveries(); -		idempotent DVBSI::Delivery GetDeliveryForService(int id); -		idempotent DVBSI::Delivery GetDeliveryForTransport(int id); +		idempotent DVBSI::Delivery GetDeliveryForService(int id) throws NotFound; +		idempotent DVBSI::Delivery GetDeliveryForTransport(int id) throws NotFound;  		idempotent DVBSI::Delivery GetDeliveryForSi();  		// Get services  		["project2:rows"] | 
