diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-01-26 18:18:59 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-06-13 17:29:48 +0100 |
commit | 157d8a5b433cf138a3203b017b12f7321e10cd0c (patch) | |
tree | e3d9990c18c2df5dd7d822801c06a856b9c94940 /p2pvr/daemon | |
parent | Add mock helper SQL for bringing test data into upcoming 7 days (diff) | |
download | p2pvr-157d8a5b433cf138a3203b017b12f7321e10cd0c.tar.bz2 p2pvr-157d8a5b433cf138a3203b017b12f7321e10cd0c.tar.xz p2pvr-157d8a5b433cf138a3203b017b12f7321e10cd0c.zip |
Move record data into slice, switch data field to matching enumeration, increase test coverage
Diffstat (limited to 'p2pvr/daemon')
-rw-r--r-- | p2pvr/daemon/schedules.cpp | 54 | ||||
-rw-r--r-- | p2pvr/daemon/sql/SI_serviceNextUsed.sql | 2 | ||||
-rw-r--r-- | p2pvr/daemon/sql/Schedules_scheduledToRecord.sql | 5 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/datasources/data.sql | 14 | ||||
-rw-r--r-- | p2pvr/daemon/unittests/testSched.cpp | 12 |
5 files changed, 21 insertions, 66 deletions
diff --git a/p2pvr/daemon/schedules.cpp b/p2pvr/daemon/schedules.cpp index 5b0b5cd..267e1dd 100644 --- a/p2pvr/daemon/schedules.cpp +++ b/p2pvr/daemon/schedules.cpp @@ -30,48 +30,6 @@ DECLARE_OPTIONS(Schedules, "P2PVR Scheduler options") "Implementation of episode group scheduler problem solver") END_OPTIONS() -enum RecordStatuses { - Record_WillRecordThisShowing = 0, - Record_WillRecordOtherShowing = 1, - Record_CannotRecordAnyShowing = 2 -}; - -class Record { - public: - Record() { }; - Record(int e, RecordStatuses rs, int sc) : - EventUid(e), - RecordStatus(rs), - ScheduleId(sc) - { - } - - int EventUid; - RecordStatuses RecordStatus; - int ScheduleId; -}; -typedef boost::shared_ptr<Record> RecordPtr; -typedef std::vector<RecordPtr> Records; - -template<> -SelectedColumns -CreateColumns<RecordPtr>(const ColumnCreator & cc) -{ - cc("eventuid", true); - cc("recordstatus", false); - cc("scheduleid", false); - return {true, true, true}; -} - -template<> -void -BindColumns(RowState & rs, const SelectedColumns &, RecordPtr const & s) -{ - rs.fields[0] << s->EventUid; - rs.fields[1] << (int)s->RecordStatus; - rs.fields[2] << s->ScheduleId; -} - Showing::Showing(unsigned int e, unsigned int t, unsigned int sc, datetime start, datetime stop, int p, const Episode * ep) : episode(ep), eventUid(e), @@ -261,7 +219,7 @@ Schedules::DoReschedule(const Ice::Current & ice) e->priority /= e->showings.size(); } - Records records; + P2PVR::ScheduledToRecordList records; // Solve while (!scheduleList.empty()) { auto work = scheduleList.begin(); @@ -315,10 +273,10 @@ Schedules::DoReschedule(const Ice::Current & ice) } for (const auto & i : c->showings) { if (i) { - records.push_back(RecordPtr(new Record(i->eventUid, + records.push_back(new P2PVR::ScheduledToRecord(i->eventUid, found ? - selected.find(i) != selected.end() ? Record_WillRecordThisShowing : Record_WillRecordOtherShowing : - Record_CannotRecordAnyShowing, i->scheduleId))); + selected.find(i) != selected.end() ? P2PVR::WillRecordThisShowing : P2PVR::WillRecordOtherShowing : + P2PVR::CannotRecordAnyShowing, i->scheduleId)); } } } @@ -326,8 +284,8 @@ Schedules::DoReschedule(const Ice::Current & ice) TxHelper tx(this); SqlMergeTask mergeRecords("postgres", "record"); - auto rcs = CreateColumns<RecordPtr>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeRecords, _1, _2)); - mergeRecords.sources.insert(new ContainerIterator<Records>(&records, rcs)); + auto rcs = CreateColumns<P2PVR::ScheduledToRecordPtr>(boost::bind(&DatabaseClient::SqlMergeColumnsInserter, &mergeRecords, _1, _2)); + mergeRecords.sources.insert(new ContainerIterator<P2PVR::ScheduledToRecordList>(&records, rcs)); mergeRecords.loadComplete(this); mergeRecords.execute(NULL); tx.Commit(); diff --git a/p2pvr/daemon/sql/SI_serviceNextUsed.sql b/p2pvr/daemon/sql/SI_serviceNextUsed.sql index 385462d..e5fbbf1 100644 --- a/p2pvr/daemon/sql/SI_serviceNextUsed.sql +++ b/p2pvr/daemon/sql/SI_serviceNextUsed.sql @@ -7,6 +7,6 @@ FROM allDeliveries d AND e.starttime > NOW() LEFT OUTER JOIN record r ON r.eventuid = e.eventuid - AND r.recordstatus = 0 + AND r.recordstatus = 'WillRecordThisShowing' ORDER BY e.starttime, s.serviceid LIMIT 1 diff --git a/p2pvr/daemon/sql/Schedules_scheduledToRecord.sql b/p2pvr/daemon/sql/Schedules_scheduledToRecord.sql index 09e9b4c..3695bb5 100644 --- a/p2pvr/daemon/sql/Schedules_scheduledToRecord.sql +++ b/p2pvr/daemon/sql/Schedules_scheduledToRecord.sql @@ -1,7 +1,6 @@ -SELECT e.serviceid, e.eventid, r.scheduleid +SELECT e.eventuid, r.recordstatus, s.scheduleid FROM record r, events e, schedules s -WHERE recordstatus = 0 -AND r.eventuid = e.eventuid +WHERE r.eventuid = e.eventuid AND r.scheduleid = s.scheduleid AND e.stoptime + s.late > NOW() ORDER BY e.starttime, e.serviceid diff --git a/p2pvr/daemon/unittests/datasources/data.sql b/p2pvr/daemon/unittests/datasources/data.sql index 85ad68b..25ae269 100644 --- a/p2pvr/daemon/unittests/datasources/data.sql +++ b/p2pvr/daemon/unittests/datasources/data.sql @@ -25089,16 +25089,8 @@ COPY services (serviceid, name, providername, type, defaultauthority, runningsta -- COPY schedules (scheduleid, serviceid, eventuid, title, search, priority, early, late, repeats) FROM stdin; -1 \N \N \N Top Gear 1 63:00:00 -18233:11:00 f -2 \N \N \N Top Gear 1 00:00:00 13277:04:00 f -3 \N \N \N Top Gear 1 00:00:00 13277:04:00 f -4 \N \N \N Top Gear 1 00:00:00 2185:45:00 f -5 \N \N \N Top Gear 1 63:00:00 -18233:11:00 f -6 \N \N \N Top Gear 1 00:00:00 00:00:00 f -7 \N \N \N Top Gear 1 00:00:00 00:00:00 f -8 \N \N \N Top Gear Special 0 00:00:00 00:00:00 f -9 \N \N \N Top Gear Special 0 00:00:00 00:00:00 f -10 \N \N \N Top Gear Special 0 00:00:00 00:00:00 f +7 \N \N \N Top Gear 1 00:03:00 00:10:00 t +8 \N \N \N Top Gear Special 0 00:05:00 00:15:00 t \. @@ -25106,7 +25098,7 @@ COPY schedules (scheduleid, serviceid, eventuid, title, search, priority, early, -- Data for Name: record; Type: TABLE DATA; Schema: public; Owner: p2pvr -- -COPY record (eventuid, recordstatus, recordingstatus, scheduleid) FROM stdin; +COPY record (eventuid, recordstatus, scheduleid) FROM stdin; \. diff --git a/p2pvr/daemon/unittests/testSched.cpp b/p2pvr/daemon/unittests/testSched.cpp index 1726e74..5293bfa 100644 --- a/p2pvr/daemon/unittests/testSched.cpp +++ b/p2pvr/daemon/unittests/testSched.cpp @@ -48,13 +48,18 @@ class Core { Ice::CommunicatorPtr ic; }; -BOOST_GLOBAL_FIXTURE( StandardMockDatabase ); +BOOST_GLOBAL_FIXTURE( StandardMockDatabasePlusOffset ); BOOST_FIXTURE_TEST_SUITE( ScCore, Core ) BOOST_AUTO_TEST_CASE( sc_getSchedules ) { - sc->GetSchedules(); + auto ss = sc->GetSchedules(); + BOOST_REQUIRE_EQUAL(ss.size(), 2); + BOOST_REQUIRE(ss[0]->Search); + BOOST_REQUIRE_EQUAL(*ss[0]->Search, "Top Gear"); + BOOST_REQUIRE(ss[1]->Search); + BOOST_REQUIRE_EQUAL(*ss[1]->Search, "Top Gear Special"); } BOOST_AUTO_TEST_CASE( sc_doReschedule ) @@ -64,7 +69,8 @@ BOOST_AUTO_TEST_CASE( sc_doReschedule ) BOOST_AUTO_TEST_CASE( sc_getScheduled ) { - sc->GetScheduledToRecord(); + auto str = sc->GetScheduledToRecord(); + BOOST_REQUIRE_EQUAL(str.size(), 49); } BOOST_AUTO_TEST_CASE( sc_crud ) |