From 5e5701363c0bea958e20497d736e144c17685780 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 9 Aug 2020 00:20:04 +1000 Subject: [PATCH] [libcalamares] Test the spot-patch for Johannesburg - Add a note about notation, degrees-minutes --- src/libcalamares/locale/Tests.cpp | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/libcalamares/locale/Tests.cpp b/src/libcalamares/locale/Tests.cpp index d9bfb9133..b755a61a5 100644 --- a/src/libcalamares/locale/Tests.cpp +++ b/src/libcalamares/locale/Tests.cpp @@ -54,6 +54,7 @@ private Q_SLOTS: void testTZIterator(); void testLocationLookup_data(); void testLocationLookup(); + void testLocationLookup2(); }; LocaleTests::LocaleTests() {} @@ -423,6 +424,37 @@ LocaleTests::testLocationLookup() QCOMPARE( zone->zone(), name ); } +void +LocaleTests::testLocationLookup2() +{ + // Official + // ZA -2615+02800 Africa/Johannesburg + // Spot patch + // "ZA -3230+02259 Africa/Johannesburg\n"; + + const CalamaresUtils::Locale::ZonesModel zones; + const auto* zone = zones.find( -26.15, 28.00 ); + QCOMPARE( zone->zone(), QString( "Johannesburg" ) ); + // The TZ data sources use minutes-and-seconds notation, + // so "2615" is 26 degrees, 15 minutes, and 15 minutes is + // one-quarter of a degree. + QCOMPARE( zone->latitude(), -26.25 ); + QCOMPARE( zone->longitude(), 28.00 ); + + // Elsewhere in South Africa + const auto* altzone = zones.find( -32.0, 22.0 ); + QCOMPARE( altzone, zone ); // same pointer + QCOMPARE( altzone->zone(), QString( "Johannesburg" ) ); + QCOMPARE( altzone->latitude(), -26.25 ); + QCOMPARE( altzone->longitude(), 28.00 ); + + altzone = zones.find( -29.0, 27.0 ); + QCOMPARE( altzone->zone(), QString( "Maseru" ) ); + // -2928, that's -29 and 28/60 of a degree, is almost half, but we don't want + // to fall foul of variations in double-precision + QCOMPARE( trunc( altzone->latitude() * 1000.0 ), -29466 ); +} + QTEST_GUILESS_MAIN( LocaleTests )