summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2021-07-29 11:34:16 +0200
committerIvan Solovev <ivan.solovev@qt.io>2021-07-29 12:10:55 +0200
commit15f06eca6a5085ce14d2eb0b743c5a06365068ea (patch)
tree016bce28f409a99306bb4e7271e62b60f4700eae /tests
parentf7938b238d9634e93662013750568eb86ce2a0e2 (diff)
downloadqtlocation-15f06eca6a5085ce14d2eb0b743c5a06365068ea.tar.gz
QGeoCoordinate: fix toString() conversion
Applying qRound() to check if the minutes/seconds should overflow was not the right solution in some cases. It could lead to incorrect overflows, and so - to wrong conversion results. The actual logic of overflow is related to the behavior of QString::number. This patch fixes the logic and also introduces some minor optimizations. After overflow, the minutes or seconds value is always 0.0, because the actual minutes/seconds value is always in range [0; 60). This allows us to get rid of some checks. Fixes: QTBUG-95221 Pick-to: 6.2 5.15 Change-Id: Ie3dcb6cef226b04c43dd973c09c4ae297c583f3b Reviewed-by: Alex Blasche <alexander.blasche@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qgeocoordinate/tst_qgeocoordinate.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/tests/auto/qgeocoordinate/tst_qgeocoordinate.cpp b/tests/auto/qgeocoordinate/tst_qgeocoordinate.cpp
index 820d904d..828b2ef4 100644
--- a/tests/auto/qgeocoordinate/tst_qgeocoordinate.cpp
+++ b/tests/auto/qgeocoordinate/tst_qgeocoordinate.cpp
@@ -875,13 +875,29 @@ private slots:
<< QString( "2%1 0.000', 2%1 0.000'").arg(DEGREES_SYMB);
QTest::newRow("Wrap seconds to minutes to Degrees DM -> above valid long/lat values")
- << QGeoCoordinate(89.9999, 179.9999) << QGeoCoordinate::DegreesMinutesSeconds
+ << QGeoCoordinate(89.999999, 179.999999) << QGeoCoordinate::DegreesMinutesSeconds
<< QString( "90%1 0' 0.0\", 180%1 0' 0.0\"").arg(DEGREES_SYMB);
+ QTest::newRow("Seconds and minutes near valid long/lat values border")
+ << QGeoCoordinate(89.9999, 179.9999) << QGeoCoordinate::DegreesMinutesSeconds
+ << QString("89%1 59' 59.6\", 179%1 59' 59.6\"").arg(DEGREES_SYMB);
+
QTest::newRow("Wrap minutes to Degrees DM ->above valid long/lat values")
- << QGeoCoordinate(89.9999, 179.9999) << QGeoCoordinate::DegreesMinutes
+ << QGeoCoordinate(89.999999, 179.999999) << QGeoCoordinate::DegreesMinutes
<< QString( "90%1 0.000', 180%1 0.000'").arg(DEGREES_SYMB);
+ QTest::newRow("Minutes near valid long/lat values border")
+ << QGeoCoordinate(89.9999, 179.9999) << QGeoCoordinate::DegreesMinutes
+ << QString("89%1 59.994', 179%1 59.994'").arg(DEGREES_SYMB);
+
+ QTest::newRow("Fix incorrect wrap minutes to degrees")
+ << QGeoCoordinate(0.995833, 0.995833) << QGeoCoordinate::DegreesMinutes
+ << QString("0%1 59.750', 0%1 59.750'").arg(DEGREES_SYMB);
+
+ QTest::newRow("Fix incorrect wrap seconds to minutes")
+ << QGeoCoordinate(0.9832222, 0.9832222) << QGeoCoordinate::DegreesMinutesSeconds
+ << QString("0%1 58' 59.6\", 0%1 58' 59.6\"").arg(DEGREES_SYMB);
+
}
void datastream()