diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2014-12-17 20:26:42 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-06-13 17:29:36 +0100 |
commit | 45c2eba650bb7f9eba43b4f7fcdd3bbccc03747a (patch) | |
tree | be3ac84326db99a484695af53ba70abe848e1b19 /p2pvr/daemon | |
parent | Add tool for creating samples of SI data (diff) | |
download | p2pvr-45c2eba650bb7f9eba43b4f7fcdd3bbccc03747a.tar.bz2 p2pvr-45c2eba650bb7f9eba43b4f7fcdd3bbccc03747a.tar.xz p2pvr-45c2eba650bb7f9eba43b4f7fcdd3bbccc03747a.zip |
Add mock tuner with sample SI data
Add test suite for running maintenance jobs
Diffstat (limited to 'p2pvr/daemon')
-rw-r--r-- | p2pvr/daemon/Jamfile.jam | 3 | ||||
-rw-r--r-- | p2pvr/daemon/maintenance.cpp | 4 | ||||
-rw-r--r-- | p2pvr/daemon/si.cpp | 2 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/Jamfile.jam | 22 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/datasources/postgres.xml | 4 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/testMaint.cpp | 106 |
6 files changed, 139 insertions, 2 deletions
diff --git a/p2pvr/daemon/Jamfile.jam b/p2pvr/daemon/Jamfile.jam index 43465df..ac3ed58 100644 --- a/p2pvr/daemon/Jamfile.jam +++ b/p2pvr/daemon/Jamfile.jam @@ -21,6 +21,9 @@ lib p2pvrdaemon : <library>../devices//p2pvrdevices <library>../daemonbase//p2pvrdaemonbase <implicit-dependency>../../libtmdb//tmdb + : : + <include>. + <library>../ice//p2pvrice ; unit-test testEmbedding : diff --git a/p2pvr/daemon/maintenance.cpp b/p2pvr/daemon/maintenance.cpp index 8e204f7..05c4094 100644 --- a/p2pvr/daemon/maintenance.cpp +++ b/p2pvr/daemon/maintenance.cpp @@ -29,7 +29,9 @@ Maintenance::Maintenance(Ice::ObjectAdapterPtr a, IceUtil::TimerPtr t) : lastUpdateEvents(0), updateRunning(false) { - timer->scheduleRepeated(clientCheck, IceUtil::Time::seconds(5 * 60)); + if (timer) { + timer->scheduleRepeated(clientCheck, IceUtil::Time::seconds(5 * 60)); + } #ifdef NDEBUG ScheduledUpdate(); #endif diff --git a/p2pvr/daemon/si.cpp b/p2pvr/daemon/si.cpp index 3259888..571c6b0 100644 --- a/p2pvr/daemon/si.cpp +++ b/p2pvr/daemon/si.cpp @@ -65,7 +65,7 @@ SI::GetDeliveryForSi(const Ice::Current&) P2PVR::Deliveries rtn; SqlContainerCreator<P2PVR::Deliveries, DVBSI::TerrestrialDelivery> cct(rtn); cct.populate(Select(SI_serviceNextUsed).second); - return rtn.front(); + return rtn.empty() ? DVBSI::DeliveryPtr() : rtn.front(); } DVBSI::DeliveryPtr diff --git a/p2pvr/daemon/unittests/Jamfile.jam b/p2pvr/daemon/unittests/Jamfile.jam index 794248a..d0d704d 100644 --- a/p2pvr/daemon/unittests/Jamfile.jam +++ b/p2pvr/daemon/unittests/Jamfile.jam @@ -2,6 +2,8 @@ import testing ; lib boost_system ; lib boost_filesystem ; +lib IceUtil ; +lib Ice ; path-constant me : . ; @@ -21,4 +23,24 @@ unit-test testp2ice : <define>ROOT=\"$(me)\" ; +unit-test testMaint : + testMaint.cpp + : + <define>BOOST_TEST_DYN_LINK + <library>../..//p2common + <library>../..//p2basics + <library>../..//p2lib + <library>../..//p2ice + <library>../..//p2xml + <library>../..//p2ut + <library>..//p2pvrdaemon + <library>../../devices//p2pvrMockTuner + <library>IceUtil + <library>Ice + <library>boost_system + <library>boost_filesystem + <library>../..//boost_utf + <define>ROOT=\"$(me)\" + ; + diff --git a/p2pvr/daemon/unittests/datasources/postgres.xml b/p2pvr/daemon/unittests/datasources/postgres.xml new file mode 100644 index 0000000..c538a8c --- /dev/null +++ b/p2pvr/daemon/unittests/datasources/postgres.xml @@ -0,0 +1,4 @@ +<?xml version="1.0"?> +<project2:rdbmsdatasource xmlns:project2="http://project2.randomdan.homeip.net" name="postgres"> + <masterdsn provider="postgresql" dsn="user=gentoo dbname=p2pvr" /> +</project2:rdbmsdatasource> diff --git a/p2pvr/daemon/unittests/testMaint.cpp b/p2pvr/daemon/unittests/testMaint.cpp new file mode 100644 index 0000000..139284c --- /dev/null +++ b/p2pvr/daemon/unittests/testMaint.cpp @@ -0,0 +1,106 @@ +#define BOOST_TEST_MODULE Maintenance +#include <boost/test/unit_test.hpp> +#include <boost/filesystem/operations.hpp> +#include <testOptionsSource.h> +#include <Ice/ObjectAdapter.h> +#include <Ice/Service.h> +#include <scopeObject.h> +#include <maintenance.h> +#include <mockTuner.h> +#include <si.h> +#include <linux/dvb/frontend.h> + +#define XSTR(s) STR(s) +#define STR(s) #s +const auto bindir = boost::filesystem::canonical("/proc/self/exe").parent_path(); +const auto componentdir = bindir.parent_path() / "component"; +const boost::filesystem::path root(XSTR(ROOT)); + +class MockDevices : public P2PVR::Devices { + public: + P2PVR::TunerPrx GetTunerSpecific(const DVBSI::DeliveryPtr&, const Ice::Current & ice) override + { + return P2PVR::PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(new MockTuner())); + } + P2PVR::TunerPrx GetTunerAny(Ice::Short, const DVBSI::DeliveryPtr&, const Ice::Current & ice) override + { + return P2PVR::PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(new MockTuner())); + } + P2PVR::PrivateTunerPrx GetPrivateTuner(Ice::Short, const Ice::Current & ice) override + { + return P2PVR::PrivateTunerPrx::checkedCast(ice.adapter->addWithUUID(new MockTuner())); + } + void ReleaseTuner(const P2PVR::TunerPrx & tuner, const Ice::Current & ice) override + { + ice.adapter->remove(tuner->ice_getIdentity()); + } + Ice::Int TunerCount(const Ice::Current&) override + { + return 1; + } +}; + +class MockScheduler : public P2PVR::Schedules { + public: + void DoReschedule(const ::Ice::Current&) { } + void DeleteSchedule(Ice::Int, const Ice::Current&) { } + P2PVR::SchedulePtr GetSchedule(::Ice::Int, const ::Ice::Current&) { return P2PVR::SchedulePtr(); } + P2PVR::ScheduleList GetSchedules(const ::Ice::Current&) { return P2PVR::ScheduleList(); } + P2PVR::ScheduledToRecordList GetScheduledToRecord(const ::Ice::Current&) { return P2PVR::ScheduledToRecordList(); } + Ice::Int UpdateSchedule(const ::P2PVR::SchedulePtr&, const ::Ice::Current&) { return 0; } +}; + +static +Ice::CommunicatorPtr +standardConfig() +{ + int paramCount = 0; + Ice::CommunicatorPtr ic = Ice::initialize(paramCount, NULL); + auto adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12000"); + TestOptionsSource::LoadTestOptions({ + { "common.datasourceRoot", (root / "datasources").string() }, + }); + adapter->add(new MockDevices(), ic->stringToIdentity("GlobalDevices")); + adapter->add(new MockScheduler(), ic->stringToIdentity("Schedules")); + adapter->add(new SI(), ic->stringToIdentity("SI")); + adapter->add(new Maintenance(adapter, NULL), ic->stringToIdentity("Maintenance")); + adapter->activate(); + return ic; +} + +BOOST_AUTO_TEST_CASE( update_network ) +{ + auto ic = standardConfig(); + ScopeObject _([&ic]{ ic->destroy(); }); + + auto m = P2PVR::MaintenancePrx::checkedCast(ic->stringToProxy("Maintenance")); + BOOST_REQUIRE(m); + m->ice_ping(); + + m->UpdateNetwork(FE_OFDM); +} + +BOOST_AUTO_TEST_CASE( update_services ) +{ + auto ic = standardConfig(); + ScopeObject _([&ic]{ ic->destroy(); }); + + auto m = P2PVR::MaintenancePrx::checkedCast(ic->stringToProxy("Maintenance")); + BOOST_REQUIRE(m); + m->ice_ping(); + + m->UpdateServices(FE_OFDM); +} + +BOOST_AUTO_TEST_CASE( update_events ) +{ + auto ic = standardConfig(); + ScopeObject _([&ic]{ ic->destroy(); }); + + auto m = P2PVR::MaintenancePrx::checkedCast(ic->stringToProxy("Maintenance")); + BOOST_REQUIRE(m); + m->ice_ping(); + + m->UpdateEvents(FE_OFDM); +} + |