summaryrefslogtreecommitdiff
path: root/p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp')
-rw-r--r--p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp b/p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp
new file mode 100644
index 0000000..2608fd8
--- /dev/null
+++ b/p2pvr/daemon/unittests/testSqlSelectDeserializer.cpp
@@ -0,0 +1,86 @@
+#define BOOST_TEST_MODULE SqlSelectDeserializer
+#include <boost/test/unit_test.hpp>
+#include <sqlSelectDeserializer.h>
+#include <slicer/slicer.h>
+#include <connection.h>
+#include <p2pvr.h>
+#include <rdbmsDataSource.h>
+#include <commonObjects.h>
+#include <testOptionsSource.h>
+#include <boost/filesystem/operations.hpp>
+#include <definedDirs.h>
+#include <commonHelpers.h>
+#include "mockDefs.h"
+#include <testAppInstance.h>
+
+typedef boost::shared_ptr<DB::SelectCommand> SelectPtr;
+
+class TestCommonObjects : public CommonObjects, public TestAppInstance {
+ public:
+ TestCommonObjects()
+ {
+ TestOptionsSource::LoadTestOptions({
+ { "common.datasourceRoot", (RootDir / "datasources").string() },
+ });
+ }
+};
+
+BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
+
+BOOST_FIXTURE_TEST_SUITE ( Sql, TestCommonObjects );
+
+BOOST_AUTO_TEST_CASE( listOfEvents )
+{
+ auto db = dataSource<RdbmsDataSource>("postgres")->getReadonly();
+ auto sel = SelectPtr(db->newSelectCommand("SELECT * FROM events ORDER BY serviceId, eventId LIMIT 100"));
+ auto res = Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::Events>(*sel);
+ BOOST_REQUIRE_EQUAL(res.size(), 100);
+ BOOST_REQUIRE_EQUAL(res[0]->ServiceId, 4166);
+ BOOST_REQUIRE_EQUAL(res[0]->EventId, 49741);
+ BOOST_REQUIRE_EQUAL(res[0]->Title, "Skiing Weatherview");
+ BOOST_REQUIRE(!res[0]->Subtitle);
+ BOOST_REQUIRE_EQUAL(res[0]->Description, "Detailed weather forecast.");
+ BOOST_REQUIRE_EQUAL(res[0]->StartTime, Common::DateTime({2014, 12, 19, 0, 25}));
+ BOOST_REQUIRE_EQUAL(res[0]->StopTime, Common::DateTime({2014, 12, 19, 0, 30}));
+ BOOST_REQUIRE(res[0]->Current);
+ BOOST_REQUIRE_EQUAL(res[99]->ServiceId, 4166);
+ BOOST_REQUIRE_EQUAL(res[99]->EventId, 52448);
+ BOOST_REQUIRE_EQUAL(res[99]->Title, "East Midlands Today");
+}
+
+BOOST_AUTO_TEST_CASE( singleField )
+{
+ auto db = dataSource<RdbmsDataSource>("postgres")->getReadonly();
+ auto sel = SelectPtr(db->newSelectCommand("SELECT EventId FROM events ORDER BY serviceId, eventId LIMIT 1"));
+ auto res = Slicer::DeserializeAny<SqlSelectDeserializer, int>(*sel);
+ BOOST_REQUIRE_EQUAL(res, 49741);
+}
+
+BOOST_AUTO_TEST_CASE( singleEvent )
+{
+ auto db = dataSource<RdbmsDataSource>("postgres")->getReadonly();
+ auto sel = SelectPtr(db->newSelectCommand("SELECT * FROM events ORDER BY serviceId, eventId LIMIT 1"));
+ auto res = Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::EventPtr>(*sel);
+ BOOST_REQUIRE_EQUAL(res->ServiceId, 4166);
+ BOOST_REQUIRE_EQUAL(res->EventId, 49741);
+ BOOST_REQUIRE_EQUAL(res->Title, "Skiing Weatherview");
+ BOOST_REQUIRE(!res->Subtitle);
+ BOOST_REQUIRE_EQUAL(res->Description, "Detailed weather forecast.");
+ BOOST_REQUIRE_EQUAL(res->StartTime, Common::DateTime({2014, 12, 19, 0, 25}));
+ BOOST_REQUIRE_EQUAL(res->StopTime, Common::DateTime({2014, 12, 19, 0, 30}));
+}
+
+BOOST_AUTO_TEST_CASE( dynamicTypes )
+{
+ auto db = dataSource<RdbmsDataSource>("postgres")->getReadonly();
+ auto sel = SelectPtr(db->newSelectCommand("SELECT d.*, '::DVBSI::TerrestrialDelivery' \"typeid\" FROM delivery_dvbt d ORDER BY TransportStreamId"));
+ auto res = Slicer::DeserializeAny<SqlSelectDeserializer, P2PVR::Deliveries>(*sel, "typeid");
+ BOOST_REQUIRE_EQUAL(res.size(), 6);
+ auto dvbt = DVBSI::TerrestrialDeliveryPtr::dynamicCast(res[0]);
+ BOOST_REQUIRE_EQUAL(dvbt->Frequency, 682000000);
+ BOOST_REQUIRE_EQUAL(dvbt->TransportStreamId, 4170);
+ BOOST_REQUIRE_EQUAL(dvbt->CodeRateHP, 2);
+}
+
+BOOST_AUTO_TEST_SUITE_END();
+