From 14faa916d5091fa4f9e7790de6f9912e7be439fb Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 18 Jan 2015 18:42:05 +0000 Subject: Fix exception spec on tuner interfaces and add covering tests --- p2pvr/daemon/unittests/Jamfile.jam | 20 ++++ p2pvr/daemon/unittests/testErrorHandling.cpp | 131 +++++++++++++++++++++++++++ p2pvr/ice/dvb.ice | 12 +-- 3 files changed, 157 insertions(+), 6 deletions(-) create mode 100644 p2pvr/daemon/unittests/testErrorHandling.cpp diff --git a/p2pvr/daemon/unittests/Jamfile.jam b/p2pvr/daemon/unittests/Jamfile.jam index d3f0d1c..a505ed0 100644 --- a/p2pvr/daemon/unittests/Jamfile.jam +++ b/p2pvr/daemon/unittests/Jamfile.jam @@ -52,6 +52,26 @@ run ROOT=\"$(me)\" : testMaint ; +run + testErrorHandling.cpp mockDevices.cpp mockScheduler.cpp + : : : + BOOST_TEST_DYN_LINK + ../..//p2common + ../..//p2basics + ../..//p2lib + ../..//p2xml + ../..//p2ut + ..//p2pvrdaemon + ../../devices//p2pvrMockTuner + ../../dvb//p2pvrdvb + IceUtil + Ice + boost_system + boost_filesystem + ../..//boost_utf + ROOT=\"$(me)\" + : testErrorHandling ; + run testRecordings.cpp : : : diff --git a/p2pvr/daemon/unittests/testErrorHandling.cpp b/p2pvr/daemon/unittests/testErrorHandling.cpp new file mode 100644 index 0000000..eba8fdc --- /dev/null +++ b/p2pvr/daemon/unittests/testErrorHandling.cpp @@ -0,0 +1,131 @@ +#define BOOST_TEST_MODULE ErrorHandling +#include +#include +#include +#include +#include +#include +#include +#include +#include "mockDevices.h" +#include "mockScheduler.h" +#include +#include +#include +#include +#include +#include + +class Core { + public: + Core() + { + int paramCount = 0; + ic = Ice::initialize(paramCount, NULL); + adapter = ic->createObjectAdapterWithEndpoints("Adp", "tcp -p 12006"); + TestOptionsSource::LoadTestOptions({ + { "common.datasourceRoot", (RootDir / "datasources").string() }, + }); + adapter->add(new MockDevices(), ic->stringToIdentity("GlobalDevices")); + adapter->add(new SI(), ic->stringToIdentity("SI")); + adapter->activate(); + + s = P2PVR::SIPrx::checkedCast(ic->stringToProxy("SI")); + BOOST_REQUIRE(s); + s->ice_ping(); + + d = P2PVR::DevicesPrx::checkedCast(ic->stringToProxy("GlobalDevices")); + BOOST_REQUIRE(d); + d->ice_ping(); + } + + ~Core() + { + ic->destroy(); + } + + P2PVR::DevicesPrx d; + P2PVR::SIPrx s; + + protected: + Ice::ObjectAdapterPtr adapter; + private: + Ice::CommunicatorPtr ic; +}; + +class TestClient : public P2PVR::RawDataClient { + public: + virtual bool NewData(const P2PVR::Data &, const Ice::Current &) override + { + return false; + } +}; + +class FailingTestClient : public P2PVR::RawDataClient { + public: + bool NewData(const P2PVR::Data &, const Ice::Current &) override + { + throw P2PVR::DataHandlingException(); + } +}; + +class TestNetworkParser : public SiNetworkInformationParser { + public: + bool HandleTable(DVBSI::NetworkPtr) override + { + return false; + } +}; + +class FailingTestNetworkParser : public SiNetworkInformationParser { + public: + bool HandleTable(DVBSI::NetworkPtr) override + { + throw P2PVR::DataHandlingException(); + } +}; + +BOOST_FIXTURE_TEST_SUITE(ErrorHandling, Core) + +BOOST_AUTO_TEST_CASE(TestRawDataClient) +{ + BOOST_CHECKPOINT("Setup"); + auto del = s->GetDeliveryForSi(); + auto gd = d->GetTunerAny(FE_OFDM, del); + TemporarayIceAdapterObject a(adapter, new TestClient()); + BOOST_CHECKPOINT("Make successful call"); + gd->SendNetworkInformation(a); +} + +BOOST_AUTO_TEST_CASE(TestParser) +{ + BOOST_CHECKPOINT("Setup"); + auto del = s->GetDeliveryForSi(); + auto gd = d->GetTunerAny(FE_OFDM, del); + TemporarayIceAdapterObject a(adapter, new TestNetworkParser()); + BOOST_CHECKPOINT("Make successful call"); + gd->SendNetworkInformation(a); +} + +BOOST_AUTO_TEST_CASE(TestRawDataClientWithError) +{ + BOOST_CHECKPOINT("Setup"); + auto del = s->GetDeliveryForSi(); + auto gd = d->GetTunerAny(FE_OFDM, del); + TemporarayIceAdapterObject a(adapter, new FailingTestClient()); + BOOST_CHECKPOINT("Make failing call"); + BOOST_REQUIRE_THROW(gd->SendNetworkInformation(a), P2PVR::DataHandlingException); +} + +BOOST_AUTO_TEST_CASE(TestParserWithError) +{ + BOOST_CHECKPOINT("Setup"); + auto del = s->GetDeliveryForSi(); + auto gd = d->GetTunerAny(FE_OFDM, del); + TemporarayIceAdapterObject a(adapter, new FailingTestNetworkParser()); + BOOST_CHECKPOINT("Make failing call"); + BOOST_REQUIRE_THROW(gd->SendNetworkInformation(a), P2PVR::DataHandlingException); +} + +BOOST_AUTO_TEST_SUITE_END() + diff --git a/p2pvr/ice/dvb.ice b/p2pvr/ice/dvb.ice index 00ba64b..6b88720 100644 --- a/p2pvr/ice/dvb.ice +++ b/p2pvr/ice/dvb.ice @@ -25,11 +25,11 @@ module P2PVR { idempotent int GetStatus(); idempotent long GetLastUsedTime(); - idempotent void SendNetworkInformation(RawDataClient * client) throws DeviceError; - idempotent void SendBouquetAssociations(RawDataClient * client) throws DeviceError; - idempotent void SendServiceDescriptions(RawDataClient * client) throws DeviceError; - idempotent void SendProgramAssociationTable(RawDataClient * client) throws DeviceError; - idempotent void SendProgramMap(int pid, RawDataClient * client) throws DeviceError; + idempotent void SendNetworkInformation(RawDataClient * client) throws DeviceError, DataHandlingException; + idempotent void SendBouquetAssociations(RawDataClient * client) throws DeviceError, DataHandlingException; + idempotent void SendServiceDescriptions(RawDataClient * client) throws DeviceError, DataHandlingException; + idempotent void SendProgramAssociationTable(RawDataClient * client) throws DeviceError, DataHandlingException; + idempotent void SendProgramMap(int pid, RawDataClient * client) throws DeviceError, DataHandlingException; idempotent void SendEventInformation(RawDataClient * client) throws DeviceError; int StartSendingTS(PacketIds pids, RawDataClient * client); @@ -39,7 +39,7 @@ module P2PVR { interface PrivateTuner extends Tuner { idempotent void TuneTo(DVBSI::Delivery d) throws DeviceError; - idempotent void ScanAndSendNetworkInformation(RawDataClient * client) throws DeviceError; + idempotent void ScanAndSendNetworkInformation(RawDataClient * client) throws DeviceError, DataHandlingException; }; exception NoSuitableDeviceAvailable { }; -- cgit v1.2.3