Skip to content

Commit

Permalink
Round command line options correctly
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 4c35b8a
Author: Paul Colby <git@colby.id.au>
Date:   Fri Oct 11 20:01:32 2024 +1100

    Update i18n files

commit 9dd6856
Author: Paul Colby <git@colby.id.au>
Date:   Fri Oct 11 19:55:24 2024 +1100

    Restore all other build configurations

commit 279f81e
Author: Paul Colby <git@colby.id.au>
Date:   Fri Oct 11 19:48:06 2024 +1100

    Use std::llround()

commit f5945c1
Author: Paul Colby <git@colby.id.au>
Date:   Fri Oct 11 19:27:15 2024 +1100

    Try std::llround()

commit e172d76
Author: Paul Colby <git@colby.id.au>
Date:   Fri Oct 11 19:14:54 2024 +1100

    Add more debugging

commit 5b9cdbc
Author: Paul Colby <git@colby.id.au>
Date:   Fri Oct 11 19:02:20 2024 +1100

    Add more debugging

commit 53f255e
Author: Paul Colby <git@colby.id.au>
Date:   Fri Oct 11 18:43:13 2024 +1100

    Add some debugging

commit c4143c0
Author: Paul Colby <git@colby.id.au>
Date:   Fri Oct 11 17:03:57 2024 +1100

    Correct Workflow syntax

commit a70947a
Author: Paul Colby <git@colby.id.au>
Date:   Fri Oct 11 17:02:42 2024 +1100

    Strip down to just the 32-bit MinGW builds

    So we explore this rounding error.
  • Loading branch information
pcolby committed Oct 11, 2024
1 parent 44106ac commit 899b007
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 39 deletions.
3 changes: 2 additions & 1 deletion src/cli/abstractcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QLocale>
#include <QTimer>

#include <cmath>
#include <ratio>

/*!
Expand Down Expand Up @@ -211,7 +212,7 @@ quint32 AbstractCommand::parseNumber(const QString &value, const QString &unit,
if (!ratio.isValid()) {
for (ratio = makeRatio<R>(); DOKIT_RESULT(dbl) < sensibleMinimum; ratio.num *= 1000);
}
return (quint32)DOKIT_RESULT(dbl);
return std::llround(DOKIT_RESULT(dbl));
}
#undef DOKIT_RESULT
return 0; // Failed to parse as either integer, or float.
Expand Down
14 changes: 7 additions & 7 deletions src/cli/i18n/en_AU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@
<context>
<name>AbstractCommand</name>
<message>
<location filename="../abstractcommand.cpp" line="37"/>
<location filename="../abstractcommand.cpp" line="38"/>
<source>Bluetooth discovery error:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../abstractcommand.cpp" line="272"/>
<location filename="../abstractcommand.cpp" line="273"/>
<source>Ignoring option: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../abstractcommand.cpp" line="294"/>
<location filename="../abstractcommand.cpp" line="295"/>
<source>Unknown output format: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../abstractcommand.cpp" line="302"/>
<location filename="../abstractcommand.cpp" line="303"/>
<source>Invalid timeout: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../abstractcommand.cpp" line="304"/>
<location filename="../abstractcommand.cpp" line="305"/>
<source>Platform does not support Bluetooth scan timeout</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../abstractcommand.cpp" line="307"/>
<location filename="../abstractcommand.cpp" line="308"/>
<source>Set scan timeout to %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../abstractcommand.cpp" line="316"/>
<location filename="../abstractcommand.cpp" line="317"/>
<source>Missing required option: %1</source>
<translation type="unfinished"></translation>
</message>
Expand Down
14 changes: 7 additions & 7 deletions src/cli/i18n/en_GB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@
<context>
<name>AbstractCommand</name>
<message>
<location filename="../abstractcommand.cpp" line="37"/>
<location filename="../abstractcommand.cpp" line="38"/>
<source>Bluetooth discovery error:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../abstractcommand.cpp" line="272"/>
<location filename="../abstractcommand.cpp" line="273"/>
<source>Ignoring option: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../abstractcommand.cpp" line="294"/>
<location filename="../abstractcommand.cpp" line="295"/>
<source>Unknown output format: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../abstractcommand.cpp" line="302"/>
<location filename="../abstractcommand.cpp" line="303"/>
<source>Invalid timeout: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../abstractcommand.cpp" line="304"/>
<location filename="../abstractcommand.cpp" line="305"/>
<source>Platform does not support Bluetooth scan timeout</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../abstractcommand.cpp" line="307"/>
<location filename="../abstractcommand.cpp" line="308"/>
<source>Set scan timeout to %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../abstractcommand.cpp" line="316"/>
<location filename="../abstractcommand.cpp" line="317"/>
<source>Missing required option: %1</source>
<translation type="unfinished"></translation>
</message>
Expand Down
14 changes: 7 additions & 7 deletions src/cli/i18n/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@
<context>
<name>AbstractCommand</name>
<message>
<location filename="../abstractcommand.cpp" line="37"/>
<location filename="../abstractcommand.cpp" line="38"/>
<source>Bluetooth discovery error:</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../abstractcommand.cpp" line="272"/>
<location filename="../abstractcommand.cpp" line="273"/>
<source>Ignoring option: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../abstractcommand.cpp" line="294"/>
<location filename="../abstractcommand.cpp" line="295"/>
<source>Unknown output format: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../abstractcommand.cpp" line="302"/>
<location filename="../abstractcommand.cpp" line="303"/>
<source>Invalid timeout: %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../abstractcommand.cpp" line="304"/>
<location filename="../abstractcommand.cpp" line="305"/>
<source>Platform does not support Bluetooth scan timeout</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../abstractcommand.cpp" line="307"/>
<location filename="../abstractcommand.cpp" line="308"/>
<source>Set scan timeout to %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../abstractcommand.cpp" line="316"/>
<location filename="../abstractcommand.cpp" line="317"/>
<source>Missing required option: %1</source>
<translation type="unfinished"></translation>
</message>
Expand Down
19 changes: 2 additions & 17 deletions test/unit/cli/testabstractcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,9 @@ void TestAbstractCommand::parseMicroValue_data()

// Floats work the same.
QTest::addRow("123.0") << QStringLiteral("123.0") << QString() << (quint32)100 << (quint32)123;
QTest::addRow("123.0s") << QStringLiteral("123.0s") << QStringLiteral("s") << (quint32)100 << (quint32)123000000;
#if defined(Q_CC_MINGW) && !defined(__MINGW64__) // 32-bit MinGW has a persistent rounding error.
QTest::addRow("1.230") << QStringLiteral("1.230") << QString() << (quint32)100 << (quint32)1229;
QTest::addRow("1.230s") << QStringLiteral("1.230s") << QStringLiteral("s") << (quint32)100 << (quint32)1229999;
#else
QTest::addRow("1.230") << QStringLiteral("1.230") << QString() << (quint32)100 << (quint32)1230;
QTest::addRow("123.0s") << QStringLiteral("123.0s") << QStringLiteral("s") << (quint32)100 << (quint32)123000000;
QTest::addRow("1.230s") << QStringLiteral("1.230s") << QStringLiteral("s") << (quint32)100 << (quint32)1230000;
#endif

// Invalid numbers return 0.
QTest::addRow("xxx") << QStringLiteral("xxx") << QString() << (quint32)100 << (quint32)0;
Expand Down Expand Up @@ -134,14 +129,9 @@ void TestAbstractCommand::parseMilliValue_data()

// Floats work the same.
QTest::addRow("123.0") << QStringLiteral("123.0") << QString() << (quint32)100 << (quint32)123;
QTest::addRow("123.0s") << QStringLiteral("123.0s") << QStringLiteral("s") << (quint32)100 << (quint32)123000;
#if defined(Q_CC_MINGW) && !defined(__MINGW64__) // 32-bit MinGW has a persistent rounding error.
QTest::addRow("1.230") << QStringLiteral("1.230") << QString() << (quint32)100 << (quint32)1229;
QTest::addRow("1.230s") << QStringLiteral("1.230s") << QStringLiteral("s") << (quint32)100 << (quint32)1229;
#else
QTest::addRow("1.230") << QStringLiteral("1.230") << QString() << (quint32)100 << (quint32)1230;
QTest::addRow("123.0s") << QStringLiteral("123.0s") << QStringLiteral("s") << (quint32)100 << (quint32)123000;
QTest::addRow("1.230s") << QStringLiteral("1.230s") << QStringLiteral("s") << (quint32)100 << (quint32)1230;
#endif

// Invalid numbers return 0.
QTest::addRow("xxx") << QStringLiteral("xxx") << QString() << (quint32)100 << (quint32)0;
Expand Down Expand Up @@ -179,13 +169,8 @@ void TestAbstractCommand::parseWholeValue_data()

// Floats work the same.
QTest::addRow("123.0") << QStringLiteral("123.0") << QString() << (quint32)123;
#if defined(Q_CC_MINGW) && !defined(__MINGW64__) // 32-bit MinGW has a persistent rounding error.
QTest::addRow("1.23K") << QStringLiteral("1.23K") << QString() << (quint32)1229;
QTest::addRow("1.23M") << QStringLiteral("1.23M") << QString() << (quint32)1229999;
#else
QTest::addRow("1.23K") << QStringLiteral("1.23K") << QString() << (quint32)1230;
QTest::addRow("1.23M") << QStringLiteral("1.23M") << QString() << (quint32)1230000;
#endif

// Invalid numbers return 0.
QTest::addRow("xxx") << QStringLiteral("xxx") << QString() << (quint32)0;
Expand Down

0 comments on commit 899b007

Please sign in to comment.