1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2011-01-12
7 * Description : Test for the GeoCoordinates class
8 *
9 * Copyright (C) 2011 by Michael G. Hansen <mike at mghansen dot de>
10 *
11 * This program is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU General
13 * Public License as published by the Free Software Foundation;
14 * either version 2, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * ============================================================ */
23
24 #include "geocoordinates_utest.h"
25
26 // Local includes
27
28 #include "geocoordinates.h"
29
30 using namespace Digikam;
31
testNoOp()32 void TestGeoCoordinates::testNoOp()
33 {
34 }
35
testGeoCoordinates()36 void TestGeoCoordinates::testGeoCoordinates()
37 {
38 GeoCoordinates coord1(52.0, 6.0);
39 QVERIFY(coord1.hasCoordinates());
40 QCOMPARE(coord1.geoUrl(), QLatin1String("geo:52,6"));
41
42 GeoCoordinates coord2(52.0, 6.0);
43 GeoCoordinates coord3(53.0, 6.0);
44 QVERIFY(coord1==coord2);
45 QVERIFY(!(coord1==coord3));
46
47 GeoCoordinates coord4 = GeoCoordinates(52.0, 6.0);
48 QVERIFY(coord1 == coord4);
49 }
50
51 /**
52 * GeoCoordinates are declared as Q_MOVABLE_TYPE, here we test whether the class still
53 * works with Qt's container classes.
54 */
testMovable()55 void TestGeoCoordinates::testMovable()
56 {
57 GeoCoordinates::List startList;
58
59 startList
60 << GeoCoordinates()
61 << GeoCoordinates(5.0, 10.0)
62 << GeoCoordinates(5.0, 10.0, 15.0);
63
64 GeoCoordinates::List copiedList = startList;
65
66 // force a deep copy to occur
67 copiedList << GeoCoordinates();
68
69 QCOMPARE(copiedList.at(0), GeoCoordinates());
70 QCOMPARE(copiedList.at(1), GeoCoordinates(5.0, 10.0));
71 QCOMPARE(copiedList.at(2), GeoCoordinates(5.0, 10.0, 15.0));
72
73 // optional code for benchmarks, but I could not detect any difference
74 // with and without Q_MOVABLE_TYPE here, looks like QList does not gain
75 // any speed from Q_MOVABLE_TYPE
76 // QBENCHMARK
77 // {
78 // const int benchSize = 100;
79 // GeoCoordinates::List benchList;
80 // for (int i=0; i<benchSize; ++i)
81 // {
82 // for (int j=0; j<benchSize; ++j)
83 // {
84 // benchList << GeoCoordinates(double(i)/50.0, double(j)/50.0);
85 // }
86 // }
87 //
88 // // QBENCHMARK
89 // {
90 // for (int i=0; i<benchSize*10; ++i)
91 // {
92 // GeoCoordinates::List benchListCopied = benchList;
93 //
94 // // force a deep copy to occur:
95 // benchListCopied[0] = GeoCoordinates();
96 // benchListCopied << GeoCoordinates();
97 // }
98 // }
99 // }
100 }
101
102 QTEST_GUILESS_MAIN(TestGeoCoordinates)
103