Skip to content

Commit

Permalink
Fixed interval parser, fixes #325.
Browse files Browse the repository at this point in the history
  • Loading branch information
hmatuschek committed Apr 6, 2023
1 parent 44f9ea5 commit 9fe1db2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/interval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Interval::format(Format f) const {

bool
Interval::parse(const QString &value) {
QRegularExpression ex("\\w*([0-9])+\\w*(|min|s|ms)\\w*");
QRegularExpression ex(R"(\s*([0-9]+)\s*(min|s|ms|)\s*)");
QRegularExpressionMatch match = ex.match(value);
if (! match.isValid())
return false;
Expand All @@ -53,7 +53,7 @@ Interval::parse(const QString &value) {

if (hasUnit && ("s"==unit))
_duration = dur.toULongLong()*1000ULL;
else if (hasUnit && ("s"==unit))
else if (hasUnit && ("min"==unit))
_duration = dur.toULongLong()*60000ULL;
else
_duration = dur.toULongLong();
Expand Down
42 changes: 42 additions & 0 deletions test/d868uve_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,47 @@ D868UVETest::testAutoRepeaterOffset() {
QCOMPARE(ext->uhfRef()->as<AnytoneAutoRepeaterOffset>(), ext->offsets()->get(1)->as<AnytoneAutoRepeaterOffset>());
}

void
D868UVETest::testHangTime() {
ErrorStack err;

// Load config from file
Config config;
if (! config.readYAML(":/data/anytone_call_hangtime.yaml", err)) {
QFAIL(QString("Cannot open codeplug file: %1")
.arg(err.format()).toStdString().c_str());
}

// Check config
QVERIFY2(config.settings()->anytoneExtension(), "Expected AnyTone settings extension.");
AnytoneDMRSettingsExtension *ext = config.settings()->anytoneExtension()->dmrSettings();

QCOMPARE(ext->privateCallHangTime().seconds(), 4ULL);
QCOMPARE(ext->groupCallHangTime().seconds(), 5ULL);

// Encode
D868UVCodeplug codeplug;
Codeplug::Flags flags; flags.updateCodePlug=false;
if (! codeplug.encode(&config, flags, err)) {
QFAIL(QString("Cannot encode codeplug for AnyTone AT-D868UVE: %1")
.arg(err.format()).toStdString().c_str());
}

// Decode
Config comp_config;
if (! codeplug.decode(&comp_config, err)) {
QFAIL(QString("Cannot decode codeplug for AnyTone AT-D878UVII: %1")
.arg(err.format()).toStdString().c_str());
}

// Check config
QVERIFY2(comp_config.settings()->anytoneExtension(), "Expected AnyTone settings extension.");
ext = comp_config.settings()->anytoneExtension()->dmrSettings();

QCOMPARE(ext->privateCallHangTime().seconds(), 4ULL);
QCOMPARE(ext->groupCallHangTime().seconds(), 5ULL);

}

QTEST_GUILESS_MAIN(D868UVETest)

1 change: 1 addition & 0 deletions test/d868uve_test.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ private slots:
void testBasicConfigDecoding();

void testAutoRepeaterOffset();
void testHangTime();

protected:
Config _basicConfig;
Expand Down
1 change: 1 addition & 0 deletions test/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<file>data/anytone_auto_repeater_extension.yaml</file>
<file>data/anytone_audio_settings_extension.yaml</file>
<file>data/roaming_channel_test.yaml</file>
<file>data/anytone_call_hangtime.yaml</file>
</qresource>
</RCC>

0 comments on commit 9fe1db2

Please sign in to comment.