Skip to content

Commit

Permalink
Minor rewrite to the recording extender test code.
Browse files Browse the repository at this point in the history
The current code violates the C++ One Definition Rule where only a
single declaration of a class is allowed in a translation unit.  It
was originally written that way to try and minimize the amount of the
backend code that had to be linked in to make it compile.

Rewrite the code to use a derived class of "Scheduler" instead of a
second class named "Scheduler".  This satisfies the One Definition
Rule while also not requiring a cascading list of object files that
need to be linked in to the test code.
  • Loading branch information
linuxdude42 committed Dec 30, 2024
1 parent 4a33abb commit b061ec2
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 13 deletions.
2 changes: 1 addition & 1 deletion mythtv/programs/mythbackend/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Scheduler : public MThread, public MythScheduler
bool GetAllPending(ProgramList &retList, int recRuleId = 0) const;
void GetAllPending(QStringList &strList) const override; // MythScheduler
QMap<QString,ProgramInfo*> GetRecording(void) const override; // MythScheduler
RecordingInfo* GetRecording(uint recordedid) const;
virtual RecordingInfo* GetRecording(uint recordedid) const;

enum SchedSortColumn : std::uint8_t
{ kSortTitle, kSortLastRecorded, kSortNextRecording,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ if(NOT TARGET SQLite::SQLite3)
endif()

add_executable(
test_recordingextender ../../recordingextender.cpp dummyscheduler.cpp
test_recordingextender.cpp test_recordingextender.h)
test_recordingextender
../../recordingextender.cpp dummyscheduler.cpp dummyscheduler.h
test_recordingextender.cpp test_recordingextender.h)

target_include_directories(test_recordingextender PRIVATE . ../..)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
#include "libmythbase/mthread.h"
#include "libmythbase/mythscheduler.h"
#include "libmythtv/recordinginfo.h"
#include "dummyscheduler.h"

QMap<uint,RecordingInfo*> gFakeRecordings;

class Scheduler : public MThread, public MythScheduler
// Dummy functions so we don't have to link against scheduler.o, which
// pulls in a ton of other requirements.
Scheduler::Scheduler([[maybe_unused]] bool runthread,
[[maybe_unused]] QMap<int, EncoderLink *> *_tvList,
[[maybe_unused]] const QString& tmptable,
[[maybe_unused]] Scheduler *master_sched) :
MThread("Scheduler")
{}
Scheduler::~Scheduler()
{
// These have to match the signatures of the real scheduler.
QMap<QString,ProgramInfo*> GetRecording(void) const override;
RecordingInfo* GetRecording(uint recordedid) const;
}
void Scheduler::GetAllPending([[maybe_unused]] QStringList &strList) const
{
}
QMap<QString,ProgramInfo*> Scheduler::GetRecording(void) const
{
return {};
};
RecordingInfo* Scheduler::GetRecording([[maybe_unused]] uint recordedid) const
{
return nullptr;
};
void Scheduler::run(void)
{
}

QMap<QString,ProgramInfo*> Scheduler::GetRecording(void) const
//
// Our test functions.
//
QMap<QString,ProgramInfo*> TestScheduler::GetRecording(void) const
{
return {};
}

// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
RecordingInfo* Scheduler::GetRecording(uint recordedid) const
RecordingInfo* TestScheduler::GetRecording(uint recordedid) const
{
if (recordedid == 0)
return nullptr;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "libmythbase/mthread.h"
#include "../../scheduler.h"
#include "libmythtv/recordinginfo.h"

class TestScheduler : public Scheduler
{
public:
TestScheduler() : Scheduler(false, nullptr) {};

// These have to match the signatures of the real scheduler.
QMap<QString,ProgramInfo*> GetRecording(void) const override;
RecordingInfo* GetRecording(uint recordedid) const override;
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "libmythbase/mythcorecontext.h"
#include "libmythbase/mythdb.h"
#include "libmythtv/dbcheck.h"
#include "scheduler.h"
#include "dummyscheduler.h"
#include "test_recordingextender.h"

static constexpr char const * const TESTNAME = "test_recordingextender";
Expand Down Expand Up @@ -144,6 +144,11 @@ RecExtDataPage* TestRecExtMlbDataSource::newPage(const QJsonDocument& doc)

//////////////////////////////////////////////////

TestRecordingExtender::TestRecordingExtender()
{
m_scheduler = new TestScheduler;
}

// Before all test cases
void TestRecordingExtender::initTestCase()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class TestRecordingExtender : public RecordingExtender
Q_OBJECT

public:
TestRecordingExtender();
QDateTime getNow() {return m_nowForTest; }

private:
Expand Down

0 comments on commit b061ec2

Please sign in to comment.