diff --git a/core/tests/geolocation/editor/test_simpletreemodel.cpp b/core/tests/geolocation/editor/test_simpletreemodel.cpp index 0c76470874..c4751a1cde 100644 --- a/core/tests/geolocation/editor/test_simpletreemodel.cpp +++ b/core/tests/geolocation/editor/test_simpletreemodel.cpp @@ -1,124 +1,149 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2010-06-21 * Description : Test for SimpleTreeModel. * - * Copyright (C) 2010 by Michael G. Hansen + * Copyright (C) 2010 by Michael G. Hansen + * Copyright (C) 2017-2020 by Gilles Caulier * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #include "test_simpletreemodel.h" // Qt includes #include #include // local includes #include "simpletreemodel.h" #include "modeltest.h" using namespace Digikam; /** * Description : Dummy test that does nothing */ void TestSimpleTreeModel::testNoOp() { } void TestSimpleTreeModel::testModel1() { SimpleTreeModel* const treeModel = new SimpleTreeModel(1, this); + new ModelTest(treeModel, this); + Q_ASSERT(!treeModel->index(0, 0).isValid()); Q_ASSERT(treeModel->indexToItem(QModelIndex()) == treeModel->rootItem()); Q_ASSERT(!treeModel->itemToIndex(treeModel->rootItem()).isValid()); Q_ASSERT(!treeModel->itemToIndex(nullptr).isValid()); Q_ASSERT(!treeModel->parent(QModelIndex()).isValid()); + // --- + SimpleTreeModel::Item* const item1 = treeModel->addItem(); - Q_ASSERT(item1 != nullptr); + + Q_ASSERT(item1 != nullptr); + const QPersistentModelIndex item1Index = treeModel->itemToIndex(item1); + Q_ASSERT(item1Index.isValid()); Q_ASSERT(treeModel->indexToItem(item1Index) == item1); Q_ASSERT(!treeModel->parent(item1Index).isValid()); + // --- + SimpleTreeModel::Item* const item2 = treeModel->addItem(); - Q_ASSERT(item2 != nullptr); + + Q_ASSERT(item2 != nullptr); + const QModelIndex item2Index = treeModel->itemToIndex(item2); + Q_ASSERT(item2Index.isValid()); Q_ASSERT(treeModel->indexToItem(item2Index) == item2); Q_ASSERT(!treeModel->parent(item2Index).isValid()); + // --- + SimpleTreeModel::Item* const item21 = treeModel->addItem(item2); - Q_ASSERT(item21 != nullptr); + + Q_ASSERT(item21 != nullptr); + const QModelIndex item21Index = treeModel->itemToIndex(item21); + Q_ASSERT(item21Index.isValid()); Q_ASSERT(treeModel->indexToItem(item21Index) == item21); - Q_ASSERT(treeModel->parent(item21Index) == item2Index); - Q_ASSERT(treeModel->index(0, 0, item2Index) == item21Index); + Q_ASSERT(treeModel->parent(item21Index) == item2Index); + Q_ASSERT(treeModel->index(0, 0, item2Index) == item21Index); // just make sure another modeltest will test things for consistency in case a signal went missing new ModelTest(treeModel, this); - Q_ASSERT(treeModel->rootItem() == treeModel->indexToItem(QModelIndex())); - Q_ASSERT(treeModel->indexToItem(treeModel->itemToIndex(item1))==item1); - Q_ASSERT(treeModel->hasIndex(0, 0) == true); + Q_ASSERT(treeModel->rootItem() == treeModel->indexToItem(QModelIndex())); + Q_ASSERT(treeModel->indexToItem(treeModel->itemToIndex(item1)) == item1); + Q_ASSERT(treeModel->hasIndex(0, 0) == true); QModelIndex topIndex = treeModel->index(0, 0, QModelIndex()); if (treeModel->rowCount(topIndex) > 0) { QModelIndex childIndex = treeModel->index(0, 0, topIndex); qDebug() << childIndex; qDebug() << treeModel->parent(childIndex); + Q_ASSERT(treeModel->parent(childIndex) == topIndex); } // add another few items { SimpleTreeModel::Item* const item22 = treeModel->addItem(item2, 0); - Q_ASSERT(item22 != nullptr); - const QModelIndex item22Index = treeModel->itemToIndex(item21); + + Q_ASSERT(item22 != nullptr); + + const QModelIndex item22Index = treeModel->itemToIndex(item22); + Q_ASSERT(item22Index.isValid()); Q_ASSERT(treeModel->indexToItem(item22Index) == item22); - Q_ASSERT(treeModel->parent(item22Index) == item2Index); - Q_ASSERT(treeModel->index(0, 0, item2Index) == item22Index); - Q_ASSERT(item22Index.row() == 0); + Q_ASSERT(treeModel->parent(item22Index) == item2Index); + Q_ASSERT(treeModel->index(0, 0, item2Index) == item22Index); + Q_ASSERT(item22Index.row() == 0); } // add another few items { SimpleTreeModel::Item* const item23 = treeModel->addItem(item2, 1); - Q_ASSERT(item23 != nullptr); + + Q_ASSERT(item23 != nullptr); + const QModelIndex item23Index = treeModel->itemToIndex(item23); + Q_ASSERT(item23Index.isValid()); Q_ASSERT(treeModel->indexToItem(item23Index) == item23); - Q_ASSERT(treeModel->parent(item23Index) == item2Index); - Q_ASSERT(treeModel->index(1, 0, item2Index) == item23Index); - Q_ASSERT(item23Index.row() == 1); + Q_ASSERT(treeModel->parent(item23Index) == item2Index); + Q_ASSERT(treeModel->index(1, 0, item2Index) == item23Index); + Q_ASSERT(item23Index.row() == 1); } new ModelTest(treeModel, this); } QTEST_GUILESS_MAIN(TestSimpleTreeModel) diff --git a/core/tests/geolocation/editor/test_simpletreemodel.h b/core/tests/geolocation/editor/test_simpletreemodel.h index 016107c9cf..b5cf81c3f8 100644 --- a/core/tests/geolocation/editor/test_simpletreemodel.h +++ b/core/tests/geolocation/editor/test_simpletreemodel.h @@ -1,42 +1,43 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2010-06-21 * Description : Test for SimpleTreeModel. * - * Copyright (C) 2010 by Michael G. Hansen + * Copyright (C) 2010 by Michael G. Hansen + * Copyright (C) 2017-2020 by Gilles Caulier * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #ifndef DIGIKAM_TEST_SIMPLETREEMODEL_H #define DIGIKAM_TEST_SIMPLETREEMODEL_H // Qt includes #include class TestSimpleTreeModel : public QObject { Q_OBJECT private Q_SLOTS: void testNoOp(); void testModel1(); }; #endif // DIGIKAM_TEST_SIMPLETREEMODEL_H diff --git a/core/tests/geolocation/kmlexport/test_geoparsing.cpp b/core/tests/geolocation/kmlexport/test_geoparsing.cpp index a81953ca09..4173b2d1b7 100644 --- a/core/tests/geolocation/kmlexport/test_geoparsing.cpp +++ b/core/tests/geolocation/kmlexport/test_geoparsing.cpp @@ -1,117 +1,130 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2010-01-17 * Description : test parsing gpx data * - * Copyright (C) 2010 by Michael G. Hansen + * Copyright (C) 2010 by Michael G. Hansen * Copyright (C) 2017-2020 by Gilles Caulier * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #include "test_geoparsing.h" // Qt includes #include #include // Local includes #include "geodataparser_time.h" using namespace DigikamGenericGeolocationEditPlugin; QTEST_GUILESS_MAIN(TestGPXParsing) /** * @brief Test how well QDateTime deals with various string representations * * The behavior of QDateTime::fromString changed in some Qt version, so here * we can test what the current behavior is and quickly detect if Qt changes * again. */ void TestGPXParsing::testQDateTimeParsing() { { // strings ending with a 'Z' are taken to be in UTC, regardless of milliseconds + QDateTime time1 = QDateTime::fromString(QLatin1String("2009-03-11T13:39:55.622Z"), Qt::ISODate); QCOMPARE(time1.timeSpec(), Qt::UTC); QDateTime time2 = QDateTime::fromString(QLatin1String("2009-03-11T13:39:55Z"), Qt::ISODate); QCOMPARE(time2.timeSpec(), Qt::UTC); } { // eCoach in N900 records GPX files with this kind of date format: // 2010-01-14T09:26:02.287+02:00 + QDateTime time1 = QDateTime::fromString(QLatin1String("2010-01-14T09:26:02.287+02:00"), Qt::ISODate); #if QT_VERSION>=0x040700 + // Qt >= 4.7: both date and time are parsed fine /// @todo What about the timezone? + QCOMPARE(time1.date(), QDate(2010, 01, 14)); QCOMPARE(time1.time(), QTime(9, 26, 2, 287)); + #else + // Qt < 4.7: the date is parsed fine, but the time fails: + QCOMPARE(time1.date(), QDate(2010, 01, 14)); QCOMPARE(time1.time(), QTime(0, 0, 0)); + #endif // when we omit the time zone data, parsing succeeds // time is interpreted as local time + QDateTime time2 = QDateTime::fromString(QLatin1String("2010-01-14T09:26:02.287")/*"+02:00"*/, Qt::ISODate); QCOMPARE(time2.date(), QDate(2010, 01, 14)); QCOMPARE(time2.time(), QTime(9, 26, 2, 287)); QCOMPARE(time2.timeSpec(), Qt::LocalTime); } } /** * @brief Test our custom parsing function */ void TestGPXParsing::testCustomParsing() { { // this should work as usual: + const QDateTime time1 = GeoDataParserParseTime(QLatin1String("2009-03-11T13:39:55.622Z")); QCOMPARE(time1.timeSpec(), Qt::UTC); QCOMPARE(time1.date(), QDate(2009, 03, 11)); QCOMPARE(time1.time(), QTime(13, 39, 55, 622)); } { // eCoach in N900: 2010-01-14T09:26:02.287+02:00 + const QDateTime time1 = GeoDataParserParseTime(QLatin1String("2010-01-14T09:26:02.287+02:00")); QCOMPARE(time1.timeSpec(), Qt::UTC); QCOMPARE(time1.date(), QDate(2010, 01, 14)); QCOMPARE(time1.time(), QTime(7, 26, 02, 287)); } { // test negative time zone offset: 2010-01-14T09:26:02.287+02:00 + const QDateTime time1 = GeoDataParserParseTime(QLatin1String("2010-01-14T09:26:02.287-02:00")); QCOMPARE(time1.timeSpec(), Qt::UTC); QCOMPARE(time1.date(), QDate(2010, 01, 14)); QCOMPARE(time1.time(), QTime(11, 26, 02, 287)); } { // test negative time zone offset with minutes: 2010-01-14T09:26:02.287+03:15 + const QDateTime time1 = GeoDataParserParseTime(QLatin1String("2010-01-14T09:26:02.287-03:15")); QCOMPARE(time1.timeSpec(), Qt::UTC); QCOMPARE(time1.date(), QDate(2010, 01, 14)); QCOMPARE(time1.time(), QTime(12, 41, 02, 287)); } } diff --git a/core/tests/geolocation/kmlexport/test_geoparsing.h b/core/tests/geolocation/kmlexport/test_geoparsing.h index f28390527a..6cf65ef3f3 100644 --- a/core/tests/geolocation/kmlexport/test_geoparsing.h +++ b/core/tests/geolocation/kmlexport/test_geoparsing.h @@ -1,41 +1,41 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2010-01-17 * Description : test parsing gpx data * - * Copyright (C) 2010 by Michael G. Hansen + * Copyright (C) 2010 by Michael G. Hansen * Copyright (C) 2017-2020 by Gilles Caulier * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #ifndef DIGIKAM_TEST_GEOPARSING_H #define DIGIKAM_TEST_GEOPARSING_H // Qt includes #include class TestGPXParsing : public QObject { Q_OBJECT private Q_SLOTS: void testQDateTimeParsing(); void testCustomParsing(); }; #endif // DIGIKAM_TEST_GEOPARSING_H