Skip to content

Commit

Permalink
Fixes CSV parser reading frequencies (#429). (#432)
Browse files Browse the repository at this point in the history
* Fixed CSV reader parsing frequencies. (#429)
* Added unit tests.
  • Loading branch information
hmatuschek authored May 5, 2024
1 parent eddc554 commit 8715d77
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/csvreader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1981,8 +1981,8 @@ CSVReader::handleDigitalChannel(qint64 idx, const QString &name, double rx, doub

DMRChannel *chan = new DMRChannel();
chan->setName(name);
chan->setRXFrequency(Frequency::fromMHz(rx*1e6));
chan->setTXFrequency(Frequency::fromMHz(tx*1e6));
chan->setRXFrequency(Frequency::fromMHz(rx));
chan->setTXFrequency(Frequency::fromMHz(tx));
chan->setPower(power);
chan->setTimeout(tot);
chan->setRXOnly(ro);
Expand Down Expand Up @@ -2039,8 +2039,8 @@ CSVReader::handleAnalogChannel(qint64 idx, const QString &name, double rx, doubl

FMChannel *chan = new FMChannel();
chan->setName(name);
chan->setRXFrequency(Frequency::fromMHz(rx*1e6));
chan->setTXFrequency(Frequency::fromMHz(tx*1e6));
chan->setRXFrequency(Frequency::fromMHz(rx));
chan->setTXFrequency(Frequency::fromMHz(tx));
chan->setPower(power);
chan->setTimeout(tot);
chan->setRXOnly(ro);
Expand Down
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ qt5_wrap_cpp(configtest_MOC_SOURCES configtest.hh)
add_executable(configtest configtest.cc ${configtest_MOC_SOURCES} ${testlib_RCC_SOURCES})
target_link_libraries(configtest ${LIBS} libdmrconf libdmrconfigtest)

qt5_wrap_cpp(tableformattest_MOC_SOURCES tableformattest.hh)
add_executable(tableformattest tableformattest.cc ${tableformattest_MOC_SOURCES} ${testlib_RCC_SOURCES})
target_link_libraries(tableformattest ${LIBS} libdmrconf libdmrconfigtest)

qt5_wrap_cpp(copytest_MOC_SOURCES copytest.hh)
add_executable(copytest copytest.cc ${copytest_MOC_SOURCES} ${testlib_RCC_SOURCES})
target_link_libraries(copytest ${LIBS} libdmrconf libdmrconfigtest)
Expand Down
39 changes: 39 additions & 0 deletions test/tableformattest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "tableformattest.hh"
#include "config.hh"
#include "csvreader.hh"
#include <QTest>


TableFormatTest::TableFormatTest(QObject *parent)
: QObject{parent}
{
// pass...
}

void
TableFormatTest::testFrequencyParser() {
Config config;

QString data;
QTextStream stream(&data);

stream << "ID: 2621370" << Qt::endl
<< "Name: \"DM3MAT\"" << Qt::endl
<< "Digital Name Receive Transmit Power Scan TOT RO Admit CC TS RxGL TxC GPS Roam ID" << Qt::endl
<< "1 \"test 0\" 439.56250 -7.60000 High - - - Color 1 1 - - - + - # Local" << Qt::endl
<< "2 \"test 1\" 439.56250 +7.60000 High - - - Color 1 1 - - - + - # Sa/Th" << Qt::endl
<< "3 \"test 2\" 439.56250 439.56250 High - - - Color 1 2 - - - + - # Regional" << Qt::endl;

QString errMsg;
QVERIFY2(CSVReader::read(&config, stream, errMsg), errMsg.toStdString().c_str());

QCOMPARE(config.channelList()->count(), 3);
QCOMPARE(config.channelList()->channel(0)->rxFrequency(), Frequency::fromMHz(439.56250));
QCOMPARE(config.channelList()->channel(0)->txFrequency(), Frequency::fromMHz(431.96250));
QCOMPARE(config.channelList()->channel(1)->txFrequency(), Frequency::fromMHz(447.16250));
QCOMPARE(config.channelList()->channel(2)->txFrequency(), Frequency::fromMHz(439.56250));
}

QTEST_GUILESS_MAIN(TableFormatTest)


19 changes: 19 additions & 0 deletions test/tableformattest.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef TABLEFORMATTEST_HH
#define TABLEFORMATTEST_HH

#include <QObject>


class TableFormatTest : public QObject
{
Q_OBJECT

public:
explicit TableFormatTest(QObject *parent = nullptr);

private slots:
void testFrequencyParser();
};


#endif // TABLEFORMATTEST_HH

0 comments on commit 8715d77

Please sign in to comment.