From 899b007e73e64e724f2785acafddd2d3fc6f893e Mon Sep 17 00:00:00 2001 From: Paul Colby Date: Fri, 11 Oct 2024 20:19:38 +1100 Subject: [PATCH] Round command line options correctly Squashed commit of the following: commit 4c35b8a7400ce21312da3d6ea54a977b6c672851 Author: Paul Colby Date: Fri Oct 11 20:01:32 2024 +1100 Update i18n files commit 9dd685658f1f88d3ea39dfddc3bc15f72e4e2a77 Author: Paul Colby Date: Fri Oct 11 19:55:24 2024 +1100 Restore all other build configurations commit 279f81e68fd2c9388aa0ac77d748d6f22878efab Author: Paul Colby Date: Fri Oct 11 19:48:06 2024 +1100 Use std::llround() commit f5945c1329daa4b673e13f36e1ff82033851fcca Author: Paul Colby Date: Fri Oct 11 19:27:15 2024 +1100 Try std::llround() commit e172d761ccfae231d432a51996d2416130a1ee92 Author: Paul Colby Date: Fri Oct 11 19:14:54 2024 +1100 Add more debugging commit 5b9cdbc1429f3f18dfdb334ef39f227bc6823a48 Author: Paul Colby Date: Fri Oct 11 19:02:20 2024 +1100 Add more debugging commit 53f255e3bb880db9ead33f7e9e89e905f2f4a0c9 Author: Paul Colby Date: Fri Oct 11 18:43:13 2024 +1100 Add some debugging commit c4143c0dd3be440b29104626026313229f69cc51 Author: Paul Colby Date: Fri Oct 11 17:03:57 2024 +1100 Correct Workflow syntax commit a70947ada3b22feb407d62366d094414f553811e Author: Paul Colby Date: Fri Oct 11 17:02:42 2024 +1100 Strip down to just the 32-bit MinGW builds So we explore this rounding error. --- src/cli/abstractcommand.cpp | 3 ++- src/cli/i18n/en_AU.ts | 14 +++++++------- src/cli/i18n/en_GB.ts | 14 +++++++------- src/cli/i18n/en_US.ts | 14 +++++++------- test/unit/cli/testabstractcommand.cpp | 19 ++----------------- 5 files changed, 25 insertions(+), 39 deletions(-) diff --git a/src/cli/abstractcommand.cpp b/src/cli/abstractcommand.cpp index fa40bfed9..2c293b515 100644 --- a/src/cli/abstractcommand.cpp +++ b/src/cli/abstractcommand.cpp @@ -9,6 +9,7 @@ #include #include +#include #include /*! @@ -211,7 +212,7 @@ quint32 AbstractCommand::parseNumber(const QString &value, const QString &unit, if (!ratio.isValid()) { for (ratio = makeRatio(); 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. diff --git a/src/cli/i18n/en_AU.ts b/src/cli/i18n/en_AU.ts index b4861e589..fa72343d2 100644 --- a/src/cli/i18n/en_AU.ts +++ b/src/cli/i18n/en_AU.ts @@ -4,37 +4,37 @@ AbstractCommand - + Bluetooth discovery error: - + Ignoring option: %1 - + Unknown output format: %1 - + Invalid timeout: %1 - + Platform does not support Bluetooth scan timeout - + Set scan timeout to %1 - + Missing required option: %1 diff --git a/src/cli/i18n/en_GB.ts b/src/cli/i18n/en_GB.ts index 5fcb8658a..c9e2998d3 100644 --- a/src/cli/i18n/en_GB.ts +++ b/src/cli/i18n/en_GB.ts @@ -4,37 +4,37 @@ AbstractCommand - + Bluetooth discovery error: - + Ignoring option: %1 - + Unknown output format: %1 - + Invalid timeout: %1 - + Platform does not support Bluetooth scan timeout - + Set scan timeout to %1 - + Missing required option: %1 diff --git a/src/cli/i18n/en_US.ts b/src/cli/i18n/en_US.ts index 9563094ac..76c48eb28 100644 --- a/src/cli/i18n/en_US.ts +++ b/src/cli/i18n/en_US.ts @@ -4,37 +4,37 @@ AbstractCommand - + Bluetooth discovery error: - + Ignoring option: %1 - + Unknown output format: %1 - + Invalid timeout: %1 - + Platform does not support Bluetooth scan timeout - + Set scan timeout to %1 - + Missing required option: %1 diff --git a/test/unit/cli/testabstractcommand.cpp b/test/unit/cli/testabstractcommand.cpp index 6efa0b0d4..5670567b5 100644 --- a/test/unit/cli/testabstractcommand.cpp +++ b/test/unit/cli/testabstractcommand.cpp @@ -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; @@ -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; @@ -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;