diff options
-rw-r--r-- | p2pvr/daemon/unittests/Jamfile.jam | 20 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/testErrorHandling.cpp | 131 | ||||
-rw-r--r-- | p2pvr/ice/dvb.ice | 12 |
3 files changed, 157 insertions, 6 deletions
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 @@ -53,6 +53,26 @@ run : testMaint ; run + testErrorHandling.cpp mockDevices.cpp mockScheduler.cpp + : : : + <define>BOOST_TEST_DYN_LINK + <library>../..//p2common + <library>../..//p2basics + <library>../..//p2lib + <library>../..//p2xml + <library>../..//p2ut + <library>..//p2pvrdaemon + <library>../../devices//p2pvrMockTuner + <library>../../dvb//p2pvrdvb + <library>IceUtil + <library>Ice + <library>boost_system + <library>boost_filesystem + <library>../..//boost_utf + <define>ROOT=\"$(me)\" + : testErrorHandling ; + +run testRecordings.cpp : : : <define>BOOST_TEST_DYN_LINK 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 <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 "mockDevices.h" +#include "mockScheduler.h" +#include <si.h> +#include <recordings.h> +#include <linux/dvb/frontend.h> +#include <definedDirs.h> +#include <siParsers/network.h> +#include <temporaryIceAdapterObject.h> + +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<P2PVR::RawDataClient> 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<P2PVR::RawDataClient> 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<P2PVR::RawDataClient> 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<P2PVR::RawDataClient> 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 { }; |