-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for CTCSS/DCS encoding/decoding. Addresses #414.
- Loading branch information
1 parent
122fd63
commit b8cbe8d
Showing
2 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
#include "gd73_test.hh" | ||
#include "config.hh" | ||
#include "gd73.hh" | ||
#include "gd73_codeplug.hh" | ||
#include "errorstack.hh" | ||
#include <iostream> | ||
#include <QTest> | ||
|
||
GD73Test::GD73Test(QObject *parent) | ||
: UnitTestBase(parent) | ||
{ | ||
// pass... | ||
} | ||
|
||
void | ||
GD73Test::testBasicConfigEncoding() { | ||
ErrorStack err; | ||
GD73Codeplug codeplug; | ||
if (! codeplug.encode(&_basicConfig, Codeplug::Flags(), err)) { | ||
QFAIL(QString("Cannot encode codeplug for Radioddity GD77: %1") | ||
.arg(err.format()).toStdString().c_str()); | ||
} | ||
} | ||
|
||
void | ||
GD73Test::testBasicConfigDecoding() { | ||
ErrorStack err; | ||
GD73Codeplug codeplug; | ||
if (! codeplug.encode(&_basicConfig, Codeplug::Flags(), err)) { | ||
QFAIL(QString("Cannot encode codeplug for Radioddity GD77: %1") | ||
.arg(err.format()).toStdString().c_str()); | ||
} | ||
|
||
Config config; | ||
if (! codeplug.decode(&config, err)) { | ||
QFAIL(QString("Cannot decode codeplug for Radioddity GD77: %1") | ||
.arg(err.format()).toStdString().c_str()); | ||
} | ||
} | ||
|
||
void | ||
GD73Test::testChannelFrequency() { | ||
ErrorStack err; | ||
GD73Codeplug codeplug; | ||
if (! codeplug.encode(&_channelFrequencyConfig, Codeplug::Flags(), err)) { | ||
QFAIL(QString("Cannot encode codeplug for Radioddity GD77: {}") | ||
.arg(err.format()).toStdString().c_str()); | ||
} | ||
|
||
Config config; | ||
if (! codeplug.decode(&config, err)) { | ||
QFAIL(QString("Cannot decode codeplug for Radioddity GD77: {}") | ||
.arg(err.format()).toStdString().c_str()); | ||
} | ||
|
||
QCOMPARE(config.channelList()->channel(0)->rxFrequency(), | ||
Frequency::fromHz(123456780ULL)); | ||
QCOMPARE(config.channelList()->channel(0)->txFrequency(), | ||
Frequency::fromHz(999999990ULL)); | ||
} | ||
|
||
|
||
void | ||
GD73Test::testFMSignaling() { | ||
|
||
Config config; | ||
config.radioIDs()->add(new DMRRadioID("ID", 1234567)); | ||
|
||
{ | ||
FMChannel *ch = new FMChannel(); | ||
ch->setName("Channel 1"); | ||
ch->setRXFrequency(Frequency::fromMHz(144.0)); | ||
ch->setTXFrequency(Frequency::fromMHz(144.6)); | ||
ch->setRXTone(Signaling::CTCSS_67_0Hz); | ||
ch->setTXTone(Signaling::SIGNALING_NONE); | ||
config.channelList()->add(ch); | ||
} | ||
|
||
{ | ||
FMChannel *ch = new FMChannel(); | ||
ch->setName("Channel 2"); | ||
ch->setRXFrequency(Frequency::fromMHz(144.0)); | ||
ch->setTXFrequency(Frequency::fromMHz(144.6)); | ||
ch->setRXTone(Signaling::SIGNALING_NONE); | ||
ch->setTXTone(Signaling::CTCSS_67_0Hz); | ||
config.channelList()->add(ch); | ||
} | ||
|
||
{ | ||
FMChannel *ch = new FMChannel(); | ||
ch->setName("Channel 3"); | ||
ch->setRXFrequency(Frequency::fromMHz(144.0)); | ||
ch->setTXFrequency(Frequency::fromMHz(144.6)); | ||
ch->setRXTone(Signaling::DCS_023N); | ||
ch->setTXTone(Signaling::SIGNALING_NONE); | ||
config.channelList()->add(ch); | ||
} | ||
|
||
{ | ||
FMChannel *ch = new FMChannel(); | ||
ch->setName("Channel 4"); | ||
ch->setRXFrequency(Frequency::fromMHz(144.0)); | ||
ch->setTXFrequency(Frequency::fromMHz(144.6)); | ||
ch->setRXTone(Signaling::SIGNALING_NONE); | ||
ch->setTXTone(Signaling::DCS_023N); | ||
config.channelList()->add(ch); | ||
} | ||
|
||
{ | ||
FMChannel *ch = new FMChannel(); | ||
ch->setName("Channel 5"); | ||
ch->setRXFrequency(Frequency::fromMHz(144.0)); | ||
ch->setTXFrequency(Frequency::fromMHz(144.6)); | ||
ch->setRXTone(Signaling::DCS_023I); | ||
ch->setTXTone(Signaling::SIGNALING_NONE); | ||
config.channelList()->add(ch); | ||
} | ||
|
||
{ | ||
FMChannel *ch = new FMChannel(); | ||
ch->setName("Channel 6"); | ||
ch->setRXFrequency(Frequency::fromMHz(144.0)); | ||
ch->setTXFrequency(Frequency::fromMHz(144.6)); | ||
ch->setRXTone(Signaling::SIGNALING_NONE); | ||
ch->setTXTone(Signaling::DCS_023I); | ||
config.channelList()->add(ch); | ||
} | ||
|
||
ErrorStack err; | ||
GD73Codeplug codeplug; | ||
if (! codeplug.encode(&config, Codeplug::Flags(), err)) { | ||
QFAIL(QString("Cannot encode codeplug for Radioddity GD73: {}") | ||
.arg(err.format()).toStdString().c_str()); | ||
} | ||
|
||
Config compare; | ||
if (! codeplug.decode(&compare, err)) { | ||
QFAIL(QString("Cannot decode codeplug for Radioddity GD73: {}") | ||
.arg(err.format()).toStdString().c_str()); | ||
} | ||
|
||
QCOMPARE(compare.channelList()->count(), 6); | ||
for (int i=0; i<compare.channelList()->count(); i++) { | ||
QVERIFY(compare.channelList()->channel(i)->is<FMChannel>()); | ||
QCOMPARE((unsigned int)compare.channelList()->channel(i)->as<FMChannel>()->rxTone(), | ||
(unsigned int)config.channelList()->channel(i)->as<FMChannel>()->rxTone()); | ||
QCOMPARE((unsigned int)compare.channelList()->channel(i)->as<FMChannel>()->txTone(), | ||
(unsigned int)config.channelList()->channel(i)->as<FMChannel>()->txTone()); | ||
} | ||
} | ||
|
||
|
||
QTEST_GUILESS_MAIN(GD73Test) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef GD73TEST_HH | ||
#define GD73TEST_HH | ||
|
||
|
||
#include "libdmrconfigtest.hh" | ||
|
||
class GD73Test : public UnitTestBase | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit GD73Test(QObject *parent = nullptr); | ||
|
||
private slots: | ||
void testBasicConfigEncoding(); | ||
void testBasicConfigDecoding(); | ||
void testChannelFrequency(); | ||
|
||
void testFMSignaling(); | ||
}; | ||
|
||
#endif // GD73TEST_HH |