diff options
Diffstat (limited to 'p2pvr/daemon/unittests/testSi.cpp')
-rw-r--r-- | p2pvr/daemon/unittests/testSi.cpp | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/p2pvr/daemon/unittests/testSi.cpp b/p2pvr/daemon/unittests/testSi.cpp new file mode 100644 index 0000000..6cc810b --- /dev/null +++ b/p2pvr/daemon/unittests/testSi.cpp @@ -0,0 +1,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() + |