File indexing completed on 2025-01-19 03:57:45
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2010-01-17 0007 * Description : test parsing gpx data 0008 * 0009 * SPDX-FileCopyrightText: 2010 by Michael G. Hansen <mike at mghansen dot de> 0010 * SPDX-FileCopyrightText: 2017-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "geoparsing_utest.h" 0017 0018 // Qt includes 0019 0020 #include <QDateTime> 0021 0022 // Local includes 0023 0024 #include "geodataparser_time.h" 0025 0026 using namespace DigikamGenericGeolocationEditPlugin; 0027 0028 QTEST_GUILESS_MAIN(TestGPXParsing) 0029 0030 /** 0031 * @brief Test how well QDateTime deals with various string representations 0032 * 0033 * The behavior of QDateTime::fromString changed in some Qt version, so here 0034 * we can test what the current behavior is and quickly detect if Qt changes 0035 * again. 0036 */ 0037 void TestGPXParsing::testQDateTimeParsing() 0038 { 0039 { 0040 // strings ending with a 'Z' are taken to be in UTC, regardless of milliseconds 0041 0042 QDateTime time1 = QDateTime::fromString(QLatin1String("2009-03-11T13:39:55.622Z"), Qt::ISODate); 0043 QCOMPARE(time1.timeSpec(), Qt::UTC); 0044 QDateTime time2 = QDateTime::fromString(QLatin1String("2009-03-11T13:39:55Z"), Qt::ISODate); 0045 QCOMPARE(time2.timeSpec(), Qt::UTC); 0046 } 0047 0048 { 0049 // eCoach in N900 records GPX files with this kind of date format: 0050 // 2010-01-14T09:26:02.287+02:00 0051 0052 QDateTime time1 = QDateTime::fromString(QLatin1String("2010-01-14T09:26:02.287+02:00"), Qt::ISODate); 0053 0054 /// @todo What about the timezone? 0055 0056 QCOMPARE(time1.date(), QDate(2010, 01, 14)); 0057 QCOMPARE(time1.time(), QTime(9, 26, 2, 287)); 0058 0059 // when we omit the time zone data, parsing succeeds 0060 // time is interpreted as local time 0061 0062 QDateTime time2 = QDateTime::fromString(QLatin1String("2010-01-14T09:26:02.287")/*"+02:00"*/, Qt::ISODate); 0063 QCOMPARE(time2.date(), QDate(2010, 01, 14)); 0064 QCOMPARE(time2.time(), QTime(9, 26, 2, 287)); 0065 QCOMPARE(time2.timeSpec(), Qt::LocalTime); 0066 } 0067 } 0068 0069 /** 0070 * @brief Test our custom parsing function 0071 */ 0072 void TestGPXParsing::testCustomParsing() 0073 { 0074 { 0075 // this should work as usual: 0076 0077 const QDateTime time1 = GeoDataParserParseTime(QLatin1String("2009-03-11T13:39:55.622Z")); 0078 QCOMPARE(time1.timeSpec(), Qt::UTC); 0079 QCOMPARE(time1.date(), QDate(2009, 03, 11)); 0080 QCOMPARE(time1.time(), QTime(13, 39, 55, 622)); 0081 } 0082 0083 { 0084 // eCoach in N900: 2010-01-14T09:26:02.287+02:00 0085 0086 const QDateTime time1 = GeoDataParserParseTime(QLatin1String("2010-01-14T09:26:02.287+02:00")); 0087 QCOMPARE(time1.timeSpec(), Qt::UTC); 0088 QCOMPARE(time1.date(), QDate(2010, 01, 14)); 0089 QCOMPARE(time1.time(), QTime(7, 26, 02, 287)); 0090 } 0091 0092 { 0093 // test negative time zone offset: 2010-01-14T09:26:02.287+02:00 0094 0095 const QDateTime time1 = GeoDataParserParseTime(QLatin1String("2010-01-14T09:26:02.287-02:00")); 0096 QCOMPARE(time1.timeSpec(), Qt::UTC); 0097 QCOMPARE(time1.date(), QDate(2010, 01, 14)); 0098 QCOMPARE(time1.time(), QTime(11, 26, 02, 287)); 0099 } 0100 0101 { 0102 // test negative time zone offset with minutes: 2010-01-14T09:26:02.287+03:15 0103 0104 const QDateTime time1 = GeoDataParserParseTime(QLatin1String("2010-01-14T09:26:02.287-03:15")); 0105 QCOMPARE(time1.timeSpec(), Qt::UTC); 0106 QCOMPARE(time1.date(), QDate(2010, 01, 14)); 0107 QCOMPARE(time1.time(), QTime(12, 41, 02, 287)); 0108 } 0109 } 0110 0111 #include "moc_geoparsing_utest.cpp"