File indexing completed on 2025-01-19 03:57:44
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2011-01-12 0007 * Description : Test for the GeoCoordinates class 0008 * 0009 * SPDX-FileCopyrightText: 2011 by Michael G. Hansen <mike at mghansen dot de> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "geocoordinates_utest.h" 0016 0017 // Local includes 0018 0019 #include "geocoordinates.h" 0020 0021 using namespace Digikam; 0022 0023 void TestGeoCoordinates::testNoOp() 0024 { 0025 } 0026 0027 void TestGeoCoordinates::testGeoCoordinates() 0028 { 0029 GeoCoordinates coord1(52.0, 6.0); 0030 QVERIFY(coord1.hasCoordinates()); 0031 QCOMPARE(coord1.geoUrl(), QLatin1String("geo:52,6")); 0032 0033 GeoCoordinates coord2(52.0, 6.0); 0034 GeoCoordinates coord3(53.0, 6.0); 0035 QVERIFY(coord1==coord2); 0036 QVERIFY(!(coord1==coord3)); 0037 0038 GeoCoordinates coord4 = GeoCoordinates(52.0, 6.0); 0039 QVERIFY(coord1 == coord4); 0040 } 0041 0042 /** 0043 * GeoCoordinates are declared as Q_MOVABLE_TYPE, here we test whether the class still 0044 * works with Qt's container classes. 0045 */ 0046 void TestGeoCoordinates::testMovable() 0047 { 0048 GeoCoordinates::List startList; 0049 0050 startList 0051 << GeoCoordinates() 0052 << GeoCoordinates(5.0, 10.0) 0053 << GeoCoordinates(5.0, 10.0, 15.0); 0054 0055 GeoCoordinates::List copiedList = startList; 0056 0057 // force a deep copy to occur 0058 copiedList << GeoCoordinates(); 0059 0060 QCOMPARE(copiedList.at(0), GeoCoordinates()); 0061 QCOMPARE(copiedList.at(1), GeoCoordinates(5.0, 10.0)); 0062 QCOMPARE(copiedList.at(2), GeoCoordinates(5.0, 10.0, 15.0)); 0063 0064 // optional code for benchmarks, but I could not detect any difference 0065 // with and without Q_MOVABLE_TYPE here, looks like QList does not gain 0066 // any speed from Q_MOVABLE_TYPE 0067 // QBENCHMARK 0068 // { 0069 // const int benchSize = 100; 0070 // GeoCoordinates::List benchList; 0071 // for (int i = 0 ; i < benchSize ; ++i) 0072 // { 0073 // for (int j = 0; j < benchSize ; ++j) 0074 // { 0075 // benchList << GeoCoordinates(double(i)/50.0, double(j)/50.0); 0076 // } 0077 // } 0078 // 0079 // // QBENCHMARK 0080 // { 0081 // for (int i = 0 ; i < benchSize * 10 ; ++i) 0082 // { 0083 // GeoCoordinates::List benchListCopied = benchList; 0084 // 0085 // // force a deep copy to occur: 0086 // benchListCopied[0] = GeoCoordinates(); 0087 // benchListCopied << GeoCoordinates(); 0088 // } 0089 // } 0090 // } 0091 } 0092 0093 QTEST_GUILESS_MAIN(TestGeoCoordinates) 0094 0095 #include "moc_geocoordinates_utest.cpp"