Skip to content

Commit

Permalink
Fix a couple of iterators over gChanLists. Add some test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdude42 committed Jul 8, 2020
1 parent f157b2b commit bed9f7a
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 23 deletions.
12 changes: 5 additions & 7 deletions mythtv/libs/libmythtv/frequencytables.cpp
Expand Up @@ -706,18 +706,16 @@ static void init_freq_tables(freq_table_map_t &fmap)
}

// create old school frequency tables...
for (const auto & ptr : gChanLists)
for (const auto & [name, list] : gChanLists)
{
QString tbl_name = ptr.name;
for (uint i = 0; i < (uint)ptr.list.size(); i++)
for (uint i = 0; i < (uint)list.size(); i++)
{
uint64_t freq = (ptr.list[i].freq * 1000LL) + 1750000;
fmap[QString("analog_analog_%1%2").arg(tbl_name).arg(i)] =
uint64_t freq = (list[i].freq * 1000LL) + 1750000;
fmap[QString("analog_analog_%1%2").arg(name).arg(i)] =
new FrequencyTable(
QString("%1 %2").arg(tbl_name).arg(ptr.list[i].name), i+2,
QString("%1 %2").arg(name).arg(list[i].name), i+2,
freq, freq + 3000000,
6000000, DTVModulation::kModulationAnalog);
}
}

}
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/frequencytables.h
Expand Up @@ -27,13 +27,13 @@ using freq_table_list_t = vector<const FrequencyTable*>;

bool teardown_frequency_tables(void);

freq_table_list_t get_matching_freq_tables(
MTV_PUBLIC freq_table_list_t get_matching_freq_tables(
const QString &format, const QString &modulation, const QString &country);

MTV_PUBLIC long long get_center_frequency(
const QString& format, const QString& modulation, const QString& country, int freqid);

int get_closest_freqid(
MTV_PUBLIC int get_closest_freqid(
const QString& format, QString modulation, const QString& country, long long centerfreq);

class FrequencyTable
Expand Down
14 changes: 5 additions & 9 deletions mythtv/libs/libmythtv/recorders/v4lchannel.cpp
Expand Up @@ -299,23 +299,21 @@ int V4LChannel::SetDefaultFreqTable(const QString &name)
void V4LChannel::SetFreqTable(const int index)
{
m_curList = gChanLists[index].list;
m_totalChannels = m_curList.size();
}

int V4LChannel::SetFreqTable(const QString &tablename)
{
const QString& name = tablename;
bool use_default = (name.toLower() == "default" || name.isEmpty());

int i = 0;
char *listname = (char *)gChanLists[i].name;

m_curList.clear();
while (listname != nullptr)
for (size_t i = 0; i < gChanLists.size(); i++)
{
char *listname = (char *)gChanLists[i].name;

if (use_default)
{
if (i == m_defaultFreqTable)
if (i == static_cast<size_t>(m_defaultFreqTable))
{
SetFreqTable(i);
return i;
Expand All @@ -326,8 +324,6 @@ int V4LChannel::SetFreqTable(const QString &tablename)
SetFreqTable(i);
return i;
}
i++;
listname = (char *)gChanLists[i].name;
}

LOG(VB_CHANNEL, LOG_ERR,
Expand All @@ -340,7 +336,7 @@ int V4LChannel::SetFreqTable(const QString &tablename)

int V4LChannel::GetCurrentChannelNum(const QString &channame)
{
for (int i = 0; i < m_totalChannels; i++)
for (size_t i = 0; i < m_curList.size(); i++)
{
if (channame == m_curList[i].name)
return i;
Expand Down
1 change: 0 additions & 1 deletion mythtv/libs/libmythtv/recorders/v4lchannel.h
Expand Up @@ -103,7 +103,6 @@ class V4LChannel : public DTVChannel
QMap<QString,int> m_pictAttrDefault;

CHANLIST_vec m_curList {};
int m_totalChannels {0};

bool m_hasStreamIO {false};
bool m_hasStdIO {false};
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythtv/test/test_frequencies/.gitignore
@@ -0,0 +1 @@
test_frequencies
154 changes: 154 additions & 0 deletions mythtv/libs/libmythtv/test/test_frequencies/test_frequencies.cpp
@@ -0,0 +1,154 @@
/*
* Class TestFrequencies
*
* Copyright (c) David Hampton 2020
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <iostream>
#include <string>
#include "test_frequencies.h"

void TestFrequencies::initTestCase()
{
}

void TestFrequencies::test_gchanlists_data(void)
{
QTest::addColumn<QString>("country");
QTest::addColumn<bool>("expected");

QTest::newRow("us-bcast") << "us-bcast" << true;
QTest::newRow("france") << "france" << true;
QTest::newRow("bogus") << "bogus" << false;
}

void TestFrequencies::test_gchanlists(void)
{
QFETCH(QString, country);
QFETCH(bool, expected);

std::string country2 = country.toStdString();
auto it = std::find_if(gChanLists.cbegin(),gChanLists.cend(),
[country2] (const CHANLISTS &chanlist) -> bool
{ return country2.compare(chanlist.name) == 0; });
QCOMPARE(it != gChanLists.end(), expected);
}

void TestFrequencies::test_get_tables_data(void)
{
QTest::addColumn<QString>("format");
QTest::addColumn<QString>("modulation");
QTest::addColumn<QString>("country");
QTest::addColumn<int>("count");
QTest::addColumn<int>("freqid");
QTest::addColumn<int>("center");
QTest::addColumn<int>("frequency");

// Entries build directly
QTest::newRow("dbvt_ofdm_gb") << "dvbt" << "ofdm" << "gb" << 1 << 21 << 474000000;
QTest::newRow("dbvt_ofdm_au") << "dvbt" << "ofdm" << "au" << 2 << 68 << 809500000;
QTest::newRow("dbvc_qam_de") << "dvbc" << "qam" << "de" << 5 << 22 << 314000000;

// Entries build in a loop
QTest::newRow("atsc uscable") << "atsc" << "vsb8" << "uscable" << 8 << 3 << 63000000;
QTest::newRow("qam256 uscable") << "atsc" << "qam256" << "uscable" << 8 << 98 << 111000000;

// Entries build from old tables
QTest::newRow("us bcast") << "analog" << "analog" << "us-bcast" << 50 << 12 << 207000000;
QTest::newRow("us cable hrc") << "analog" << "analog" << "us-cable-hrc" << 125 << 99 << 109755000;
QTest::newRow("france") << "analog" << "analog" << "france" << 94 << 28 << 305000000;

// Invalid
QTest::newRow("dbvc_qam_xx") << "dvbc" << "qam" << "xx" << 0 << 0 << 0;
}

void TestFrequencies::test_get_tables(void)
{
QFETCH(QString, format);
QFETCH(QString, modulation);
QFETCH(QString, country);
QFETCH(int, count);
QFETCH(int, freqid);
QFETCH(int, center);

auto tables = get_matching_freq_tables(format, modulation, country);
// std::cerr << "Data: " << qPrintable(QString("%1_%2_%3").arg(format)
// .arg(modulation).arg(country)) << std::endl;
// std::cerr << "Count: " << count << std::endl;
// std::cerr << "Actual: " << tables.size() << std::endl;
QCOMPARE(tables.size(), (size_t)count);
if (count > 0)
{
long long actual_center = get_center_frequency(format, modulation, country, freqid);
// std::cerr << "Center: " << center << std::endl;
// std::cerr << "Actual: " << actual_center << std::endl;
QCOMPARE(actual_center, center);

int actual_freq = get_closest_freqid(format, modulation, country, center);
// std::cerr << "FreqId: " << freqid << std::endl;
// std::cerr << "Actual: " << actual_freq << std::endl;
QCOMPARE(actual_freq, freqid);
}
}

void TestFrequencies::test_get_closest_data(void)
{
QTest::addColumn<QString>("format");
QTest::addColumn<QString>("modulation");
QTest::addColumn<QString>("country");
QTest::addColumn<int>("frequency");
QTest::addColumn<int>("freqid");

// Entries build directly
QTest::newRow("dbvt_ofdm_gb 1") << "dvbt" << "ofdm" << "gb" << 473999999 << -1;
QTest::newRow("dbvt_ofdm_gb 2") << "dvbt" << "ofdm" << "gb" << 474000000 << 21;
QTest::newRow("dbvt_ofdm_au 1") << "dvbt" << "ofdm" << "au" << 809499999 << 67;
QTest::newRow("dbvt_ofdm_au 2") << "dvbt" << "ofdm" << "au" << 809500000 << 68;
QTest::newRow("dbvc_qam_de 1") << "dvbc" << "qam" << "de" << 313999999 << 21;
QTest::newRow("dbvc_qam_de 2") << "dvbc" << "qam" << "de" << 314000000 << 22;

// Entries build in a loop
QTest::newRow("atsc uscable 1") << "atsc" << "vsb8" << "uscable" << 62999999 << 2;
QTest::newRow("atsc uscable 2") << "atsc" << "vsb8" << "uscable" << 63000000 << 3;
QTest::newRow("qam256 uscable 1") << "atsc" << "qam256" << "uscable" << 110999999 << 97;
QTest::newRow("qam256 uscable 2") << "atsc" << "qam256" << "uscable" << 111000000 << 98;

// Entries build from old tables
QTest::newRow("us bcast 1") << "analog" << "analog" << "us-bcast" << 206999999 << 11;
QTest::newRow("us bcast 2") << "analog" << "analog" << "us-bcast" << 207000000 << 12;
QTest::newRow("us cable hrc 1") << "analog" << "analog" << "us-cable-hrc" << 109754999 << 98;
QTest::newRow("us cable hrc 2") << "analog" << "analog" << "us-cable-hrc" << 109755000 << 99;
}

void TestFrequencies::test_get_closest(void)
{
QFETCH(QString, format);
QFETCH(QString, modulation);
QFETCH(QString, country);
QFETCH(int, frequency);
QFETCH(int, freqid);

int actual_freq = get_closest_freqid(format, modulation, country, frequency);
// std::cerr << "FreqId: " << freqid << std::endl;
// std::cerr << "Actual: " << actual_freq << std::endl;
QCOMPARE(actual_freq, freqid);
}

void TestFrequencies::cleanupTestCase()
{
}

QTEST_APPLESS_MAIN(TestFrequencies)
40 changes: 40 additions & 0 deletions mythtv/libs/libmythtv/test/test_frequencies/test_frequencies.h
@@ -0,0 +1,40 @@
/*
* Class TestFrequencies
*
* Copyright (c) David Hampton 2020
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include <QtTest/QtTest>
#include <iostream>

#include "frequencies.h"
#include "frequencytables.h"

class TestFrequencies : public QObject
{
Q_OBJECT

private slots:
static void initTestCase();
static void test_gchanlists_data(void);
static void test_gchanlists(void);
static void test_get_tables_data(void);
static void test_get_tables(void);
static void test_get_closest_data(void);
static void test_get_closest(void);
static void cleanupTestCase();
};
62 changes: 62 additions & 0 deletions mythtv/libs/libmythtv/test/test_frequencies/test_frequencies.pro
@@ -0,0 +1,62 @@
include ( ../../../../settings.pro )

QT += xml sql network testlib widgets

TEMPLATE = app
TARGET = test_frequencies
DEPENDPATH += . ../..
INCLUDEPATH += . ../.. ../../../libmyth ../../../libmythbase

# Directly add objects w/non-exported functions
LIBS += ../../$(OBJECTS_DIR)dsmccbiop.o
LIBS += ../../$(OBJECTS_DIR)dsmcccache.o
LIBS += ../../$(OBJECTS_DIR)dsmcc.o
LIBS += ../../$(OBJECTS_DIR)dsmccobjcarousel.o

# Add all the necessary libraries
LIBS += -L../../../libmythbase -lmythbase-$$LIBVERSION
LIBS += -L../../../libmythui -lmythui-$$LIBVERSION
LIBS += -L../../../libmythupnp -lmythupnp-$$LIBVERSION
LIBS += -L../../../libmythservicecontracts -lmythservicecontracts-$$LIBVERSION
LIBS += -L../../../libmyth -lmyth-$$LIBVERSION
LIBS += -L../../../../external/FFmpeg/libavcodec -lmythavcodec
LIBS += -L../../../../external/FFmpeg/libswscale -lmythswscale
LIBS += -L../../../../external/FFmpeg/libavformat -lmythavformat
LIBS += -L../../../../external/FFmpeg/libavutil -lmythavutil
LIBS += -L../../../../external/FFmpeg/libswresample -lmythswresample
LIBS += -L../../../../external/FFmpeg/libavfilter -lmythavfilter
LIBS += -L../../../../external/FFmpeg/libpostproc -lmythpostproc
using_mheg:LIBS += -L../../../libmythfreemheg -lmythfreemheg-$$LIBVERSION
LIBS += -L../.. -lmythtv-$$LIBVERSION

contains(QMAKE_CXX, "g++") {
QMAKE_CXXFLAGS += -O0 -fprofile-arcs -ftest-coverage
QMAKE_LFLAGS += -fprofile-arcs
}

QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../external/FFmpeg/libavutil
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../external/FFmpeg/libswscale
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../external/FFmpeg/libavformat
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../external/FFmpeg/libavcodec
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../external/FFmpeg/libavfilter
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../external/FFmpeg/libpostproc
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../../external/FFmpeg/libswresample
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../libmythbase
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../libmyth
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../libmythui
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../libmythupnp
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../libmythservicecontracts
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../../../libmythfreemheg
QMAKE_LFLAGS += -Wl,$$_RPATH_$(PWD)/../..

# Input
HEADERS += test_frequencies.h
SOURCES += test_frequencies.cpp

QMAKE_CLEAN += $(TARGET)
QMAKE_CLEAN += ; ( cd $(OBJECTS_DIR) && rm -f *.gcov *.gcda *.gcno )

LIBS += $$EXTRA_LIBS $$LATE_LIBS

# Fix runtime linking
linux:QMAKE_LFLAGS += -Wl,--disable-new-dtags
4 changes: 2 additions & 2 deletions mythtv/programs/mythbackend/mythsettings.cpp
Expand Up @@ -84,8 +84,8 @@ static void fill_setting(
else if (MythSetting::kFrequencyTable == setting->m_dtype)
{
setting->m_data_list.clear();
for (uint i = 0; gChanLists[i].name; i++)
setting->m_data_list.push_back(gChanLists[i].name);
for (const auto &list : gChanLists)
setting->m_data_list.push_back(list.name);
setting->m_display_list = setting->m_data_list;
do_option_check = true;
}
Expand Down
4 changes: 2 additions & 2 deletions mythtv/programs/mythtv-setup/backendsettings.cpp
Expand Up @@ -242,8 +242,8 @@ static GlobalComboBoxSetting *FreqTable()
auto *gc = new GlobalComboBoxSetting("FreqTable");
gc->setLabel(QObject::tr("Channel frequency table"));

for (uint i = 0; gChanLists[i].name; i++)
gc->addSelection(gChanLists[i].name);
for (const auto &list : gChanLists)
gc->addSelection(list.name);

gc->setHelpText(QObject::tr("Select the appropriate frequency table for "
"your system. If you have an antenna, use a \"-bcast\" "
Expand Down

0 comments on commit bed9f7a

Please sign in to comment.