File indexing completed on 2023-05-30 10:49:16
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2009 Patrick Spendrin <ps_ml@gmx.de> 0004 // 0005 0006 #include "MarbleDebug.h" 0007 #include "MarbleDirs.h" 0008 0009 // Feature: 0010 #include "GeoDataFolder.h" 0011 #include "GeoDataDocument.h" 0012 #include "GeoDataPlacemark.h" 0013 0014 // Geometry: 0015 #include "GeoDataPolygon.h" 0016 #include "GeoDataMultiGeometry.h" 0017 #include "GeoDataLineString.h" 0018 #include "GeoDataLinearRing.h" 0019 #include "GeoDataPoint.h" 0020 0021 // StyleSelector: 0022 #include "GeoDataStyle.h" 0023 #include "GeoDataIconStyle.h" 0024 #include "GeoDataLabelStyle.h" 0025 #include "GeoDataLineStyle.h" 0026 #include "GeoDataPolyStyle.h" 0027 #include "GeoDataStyleMap.h" 0028 0029 // misc: 0030 #include "GeoDataHotSpot.h" 0031 #include "GeoDataLatLonBox.h" 0032 #include "GeoDataLatLonAltBox.h" 0033 #include "GeoDataCoordinates.h" 0034 0035 #include <QPointF> 0036 #include <QString> 0037 #include <QStringList> 0038 #include <QTest> 0039 0040 namespace Marble 0041 { 0042 0043 class TestGeoDataCopy : public QObject 0044 { 0045 Q_OBJECT 0046 0047 public: 0048 TestGeoDataCopy(); 0049 0050 private Q_SLOTS: 0051 void initTestCase(); 0052 // misc.: 0053 void copyCoordinates(); 0054 void copyHotSpot(); 0055 void copyLatLonBox(); 0056 0057 // GeoDataGeometry: 0058 void copyLineString(); 0059 void copyLinearRing(); 0060 void copyPoint(); 0061 void copyPolygon(); 0062 void copyMultiGeometry(); 0063 0064 // GeoDataFeature: 0065 void copyDocument(); 0066 void copyFolder(); 0067 void copyPlacemark(); 0068 0069 // StyleSelector: 0070 void copyStyle(); 0071 void copyIconStyle(); 0072 void copyLabelStyle(); 0073 void copyLineStyle(); 0074 void copyPolyStyle(); 0075 void copyStyleMap(); 0076 0077 private: 0078 const GeoDataCoordinates coord1; 0079 const GeoDataCoordinates coord2; 0080 const GeoDataCoordinates coord3; 0081 }; 0082 0083 TestGeoDataCopy::TestGeoDataCopy() : 0084 coord1(13.7107, 51.0235, 123.4, GeoDataCoordinates::Degree, 2), 0085 coord2(14.7107, 52.0235, 133.4, GeoDataCoordinates::Degree, 3), 0086 coord3(15.7107, 53.0235, 143.4, GeoDataCoordinates::Degree, 4) 0087 { 0088 } 0089 0090 void TestGeoDataCopy::initTestCase() 0091 { 0092 MarbleDirs::setMarbleDataPath( DATA_PATH ); 0093 MarbleDirs::setMarblePluginPath( PLUGIN_PATH ); 0094 } 0095 0096 void TestGeoDataCopy::copyCoordinates() 0097 { 0098 GeoDataCoordinates other = coord1; 0099 0100 // make sure that the coordinate contains the right values 0101 QCOMPARE(other, coord1); 0102 QCOMPARE(other.detail(), coord1.detail()); 0103 0104 QVERIFY(coord1 == other); 0105 } 0106 0107 void TestGeoDataCopy::copyPoint() 0108 { 0109 GeoDataPoint point; 0110 0111 point.setCoordinates(coord1); 0112 point.setExtrude( true ); 0113 0114 // make sure that the coordinate contains the right values 0115 QCOMPARE(point.coordinates(), coord1); 0116 QCOMPARE(point.coordinates().detail(), coord1.detail()); 0117 QCOMPARE(point.extrude(), true); 0118 0119 GeoDataPoint other = point; 0120 0121 // make sure that the coordinate contains the right values 0122 QCOMPARE(other.coordinates(), coord1); 0123 QCOMPARE(other.coordinates().detail(), coord1.detail()); 0124 QCOMPARE(other.extrude(), true); 0125 0126 QVERIFY(point.coordinates() == other.coordinates()); 0127 0128 point = GeoDataPoint( GeoDataCoordinates(13.7107, 51.0235, 123.4, GeoDataCoordinates::Degree, 17) ); 0129 point.setExtrude(false); 0130 QCOMPARE(other.coordinates().detail(), quint8(2)); 0131 QCOMPARE(point.coordinates().detail(), quint8(17)); 0132 QCOMPARE(other.extrude(), true); 0133 QCOMPARE(point.extrude(), false); 0134 } 0135 0136 void TestGeoDataCopy::copyLineString() 0137 { 0138 GeoDataLineString lineString; 0139 lineString.setTessellate(true); 0140 0141 lineString.append(coord1); 0142 lineString.append(coord2); 0143 lineString.append(coord3); 0144 QVERIFY(lineString.size() == 3); 0145 0146 GeoDataLineString other = lineString; 0147 QVERIFY(other.size() == 3); 0148 0149 QCOMPARE(lineString.at(0), coord1); 0150 QCOMPARE(lineString.at(0).detail(), coord1.detail()); 0151 QCOMPARE(other.at(2), coord3); 0152 QCOMPARE(other.at(2).detail(), coord3.detail()); 0153 0154 QVERIFY(other.at(2) == coord3); 0155 QVERIFY(other.tessellate()); 0156 } 0157 0158 void TestGeoDataCopy::copyLinearRing() 0159 { 0160 GeoDataLinearRing linearRing; 0161 0162 linearRing.setTessellate(true); 0163 0164 0165 linearRing.append(coord1); 0166 linearRing.append(coord2); 0167 linearRing.append(coord3); 0168 QVERIFY(linearRing.size() == 3); 0169 0170 GeoDataLinearRing other = linearRing; 0171 QVERIFY(other.size() == 3); 0172 0173 QCOMPARE(linearRing.at(0), coord1); 0174 QCOMPARE(linearRing.at(0).detail(), coord1.detail()); 0175 QCOMPARE(other.at(2), coord3); 0176 QCOMPARE(other.at(2).detail(), coord3.detail()); 0177 0178 QVERIFY(other.at(2) == coord3); 0179 QVERIFY(other.tessellate()); 0180 } 0181 0182 void TestGeoDataCopy::copyPolygon() 0183 { 0184 GeoDataLinearRing linearRing1; 0185 GeoDataLinearRing linearRing2; 0186 GeoDataLinearRing linearRing3; 0187 GeoDataLinearRing linearRing4; 0188 0189 linearRing1.append(coord1); linearRing1.append(coord2); linearRing1.append(coord3); 0190 linearRing2.append(coord3); linearRing2.append(coord2); linearRing2.append(coord1); 0191 linearRing3.append(coord1); linearRing3.append(coord2); linearRing3.append(coord3); 0192 linearRing3.append(coord3); linearRing3.append(coord2); linearRing3.append(coord1); 0193 linearRing4.append(coord3); linearRing4.append(coord2); linearRing4.append(coord1); 0194 linearRing4.append(coord1); linearRing4.append(coord2); linearRing4.append(coord3); 0195 0196 GeoDataPolygon polygon; 0197 polygon.appendInnerBoundary(linearRing1); 0198 polygon.appendInnerBoundary(linearRing2); 0199 polygon.appendInnerBoundary(linearRing3); 0200 polygon.setOuterBoundary(linearRing4); 0201 polygon.setTessellate(true); 0202 0203 QCOMPARE(polygon.innerBoundaries().size(), 3); 0204 0205 GeoDataPolygon other = polygon; 0206 QCOMPARE(other.innerBoundaries().size(), 3); 0207 QVERIFY(other.innerBoundaries()[0][0] == coord1); 0208 QVERIFY(other.innerBoundaries()[0][1] == coord2); 0209 QVERIFY(other.innerBoundaries()[0][2] == coord3); 0210 QVERIFY(other.innerBoundaries()[1][0] == coord3); 0211 QVERIFY(other.innerBoundaries()[1][1] == coord2); 0212 QVERIFY(other.innerBoundaries()[1][2] == coord1); 0213 QVERIFY(other.innerBoundaries()[2][0] == coord1); 0214 QVERIFY(other.innerBoundaries()[2][1] == coord2); 0215 QVERIFY(other.innerBoundaries()[2][2] == coord3); 0216 QVERIFY(other.innerBoundaries()[2][3] == coord3); 0217 QVERIFY(other.innerBoundaries()[2][4] == coord2); 0218 QVERIFY(other.innerBoundaries()[2][5] == coord1); 0219 0220 QCOMPARE(other.outerBoundary().size(), 6); 0221 0222 QVERIFY(other.outerBoundary()[0] == coord3); 0223 QVERIFY(other.outerBoundary()[1] == coord2); 0224 QVERIFY(other.outerBoundary()[2] == coord1); 0225 QVERIFY(other.outerBoundary()[3] == coord1); 0226 QVERIFY(other.outerBoundary()[4] == coord2); 0227 QVERIFY(other.outerBoundary()[5] == coord3); 0228 0229 QVERIFY(other.tessellate()); 0230 } 0231 0232 void TestGeoDataCopy::copyMultiGeometry() 0233 { 0234 GeoDataLinearRing linearRing1; 0235 GeoDataLinearRing linearRing2; 0236 GeoDataLinearRing linearRing3; 0237 GeoDataLinearRing linearRing4; 0238 0239 linearRing1.append(coord1); linearRing1.append(coord2); linearRing1.append(coord3); 0240 linearRing2.append(coord3); linearRing2.append(coord2); linearRing2.append(coord1); 0241 linearRing3.append(coord1); linearRing3.append(coord2); linearRing3.append(coord3); 0242 linearRing3.append(coord3); linearRing3.append(coord2); linearRing3.append(coord1); 0243 linearRing4.append(coord3); linearRing4.append(coord2); linearRing4.append(coord1); 0244 linearRing4.append(coord1); linearRing4.append(coord2); linearRing4.append(coord3); 0245 0246 GeoDataPolygon *polygon = new GeoDataPolygon; 0247 polygon->appendInnerBoundary(linearRing1); 0248 polygon->appendInnerBoundary(linearRing2); 0249 polygon->appendInnerBoundary(linearRing3); 0250 polygon->setOuterBoundary(linearRing4); 0251 polygon->setTessellate(true); 0252 0253 GeoDataMultiGeometry multiGeometry; 0254 multiGeometry.append(polygon); 0255 multiGeometry.append(new GeoDataLinearRing(linearRing1)); 0256 multiGeometry.append(new GeoDataLinearRing(linearRing2)); 0257 multiGeometry.append(new GeoDataLinearRing(linearRing3)); 0258 multiGeometry.append(new GeoDataLinearRing(linearRing4)); 0259 0260 GeoDataMultiGeometry other = multiGeometry; 0261 0262 QCOMPARE(other.size(), 5); 0263 QCOMPARE(static_cast<GeoDataPolygon*>(other.child(0))->innerBoundaries().size(), 3); 0264 QVERIFY(static_cast<GeoDataPolygon*>(other.child(0))->innerBoundaries()[0][0] == coord1); 0265 QVERIFY(static_cast<GeoDataPolygon*>(other.child(0))->innerBoundaries()[0][1] == coord2); 0266 QVERIFY(static_cast<GeoDataPolygon*>(other.child(0))->innerBoundaries()[0][2] == coord3); 0267 QVERIFY(static_cast<GeoDataPolygon*>(other.child(0))->innerBoundaries()[1][0] == coord3); 0268 QVERIFY(static_cast<GeoDataPolygon*>(other.child(0))->innerBoundaries()[1][1] == coord2); 0269 QVERIFY(static_cast<GeoDataPolygon*>(other.child(0))->innerBoundaries()[1][2] == coord1); 0270 QVERIFY(static_cast<GeoDataPolygon*>(other.child(0))->innerBoundaries()[2][0] == coord1); 0271 QVERIFY(static_cast<GeoDataPolygon*>(other.child(0))->innerBoundaries()[2][1] == coord2); 0272 QVERIFY(static_cast<GeoDataPolygon*>(other.child(0))->innerBoundaries()[2][2] == coord3); 0273 QVERIFY(static_cast<GeoDataPolygon*>(other.child(0))->innerBoundaries()[2][3] == coord3); 0274 QVERIFY(static_cast<GeoDataPolygon*>(other.child(0))->innerBoundaries()[2][4] == coord2); 0275 QVERIFY(static_cast<GeoDataPolygon*>(other.child(0))->innerBoundaries()[2][5] == coord1); 0276 0277 QCOMPARE(static_cast<GeoDataPolygon*>(other.child(0))->outerBoundary().size(), 6); 0278 0279 QVERIFY(static_cast<GeoDataPolygon*>(other.child(0))->outerBoundary()[0] == coord3); 0280 QVERIFY(static_cast<GeoDataPolygon*>(other.child(0))->outerBoundary()[1] == coord2); 0281 QVERIFY(static_cast<GeoDataPolygon*>(other.child(0))->outerBoundary()[2] == coord1); 0282 QVERIFY(static_cast<GeoDataPolygon*>(other.child(0))->outerBoundary()[3] == coord1); 0283 QVERIFY(static_cast<GeoDataPolygon*>(other.child(0))->outerBoundary()[4] == coord2); 0284 QVERIFY(static_cast<GeoDataPolygon*>(other.child(0))->outerBoundary()[5] == coord3); 0285 0286 QVERIFY(static_cast<GeoDataLinearRing*>(other.child(1))->at(0) == coord1); 0287 QVERIFY(static_cast<GeoDataLinearRing*>(other.child(1))->at(1) == coord2); 0288 QVERIFY(static_cast<GeoDataLinearRing*>(other.child(1))->at(2) == coord3); 0289 QVERIFY(static_cast<GeoDataLinearRing*>(other.child(2))->at(0) == coord3); 0290 QVERIFY(static_cast<GeoDataLinearRing*>(other.child(2))->at(1) == coord2); 0291 QVERIFY(static_cast<GeoDataLinearRing*>(other.child(2))->at(2) == coord1); 0292 QVERIFY(static_cast<GeoDataLinearRing*>(other.child(3))->at(0) == coord1); 0293 QVERIFY(static_cast<GeoDataLinearRing*>(other.child(3))->at(1) == coord2); 0294 QVERIFY(static_cast<GeoDataLinearRing*>(other.child(3))->at(2) == coord3); 0295 QVERIFY(static_cast<GeoDataLinearRing*>(other.child(3))->at(3) == coord3); 0296 QVERIFY(static_cast<GeoDataLinearRing*>(other.child(3))->at(4) == coord2); 0297 QVERIFY(static_cast<GeoDataLinearRing*>(other.child(3))->at(5) == coord1); 0298 QVERIFY(static_cast<GeoDataLinearRing*>(other.child(4))->at(0) == coord3); 0299 QVERIFY(static_cast<GeoDataLinearRing*>(other.child(4))->at(1) == coord2); 0300 QVERIFY(static_cast<GeoDataLinearRing*>(other.child(4))->at(2) == coord1); 0301 QVERIFY(static_cast<GeoDataLinearRing*>(other.child(4))->at(3) == coord1); 0302 QVERIFY(static_cast<GeoDataLinearRing*>(other.child(4))->at(4) == coord2); 0303 QVERIFY(static_cast<GeoDataLinearRing*>(other.child(4))->at(5) == coord3); 0304 0305 } 0306 0307 void TestGeoDataCopy::copyDocument() 0308 { 0309 QWARN("add more document specific data"); 0310 GeoDataPlacemark pl1; 0311 GeoDataPlacemark pl2; 0312 GeoDataPlacemark pl3; 0313 0314 pl1.setCoordinate(coord1); 0315 pl2.setCoordinate(coord2); 0316 pl3.setCoordinate(coord3); 0317 0318 GeoDataFolder *folder = new GeoDataFolder; 0319 folder->append(new GeoDataPlacemark(pl1)); 0320 folder->append(new GeoDataPlacemark(pl2)); 0321 folder->append(new GeoDataPlacemark(pl3)); 0322 0323 GeoDataDocument document; 0324 document.append(new GeoDataPlacemark(pl3)); 0325 document.append(folder); 0326 document.append(new GeoDataPlacemark(pl1)); 0327 0328 GeoDataDocument other = document; 0329 0330 QCOMPARE(document.size(), 3); 0331 QCOMPARE(other.size(), 3); 0332 0333 QCOMPARE(static_cast<GeoDataPlacemark*>(other.child(0))->coordinate(), coord3); 0334 QCOMPARE(static_cast<GeoDataPlacemark*>(other.child(2))->coordinate(), coord1); 0335 0336 GeoDataFolder *otherFolder = static_cast<GeoDataFolder*>(other.child(1)); 0337 QCOMPARE(static_cast<GeoDataPlacemark*>(otherFolder->child(0))->coordinate(), coord1); 0338 QCOMPARE(static_cast<GeoDataPlacemark*>(otherFolder->child(1))->coordinate(), coord2); 0339 QCOMPARE(static_cast<GeoDataPlacemark*>(otherFolder->child(2))->coordinate(), coord3); 0340 0341 other.append(new GeoDataPlacemark(pl1)); 0342 0343 QCOMPARE(document.size(), 3); 0344 QCOMPARE(other.size(), 4); 0345 QCOMPARE(static_cast<GeoDataPlacemark*>(other.child(3))->coordinate(), coord1); 0346 } 0347 0348 void TestGeoDataCopy::copyFolder() 0349 { 0350 GeoDataPlacemark pl1, pl2, pl3; 0351 pl1.setCoordinate(coord1); 0352 pl2.setCoordinate(coord2); 0353 pl3.setCoordinate(coord3); 0354 0355 GeoDataFolder folder; 0356 folder.append(new GeoDataPlacemark(pl1)); 0357 folder.append(new GeoDataPlacemark(pl2)); 0358 folder.append(new GeoDataPlacemark(pl3)); 0359 0360 QCOMPARE(folder.size(), 3); 0361 QCOMPARE(folder.child(0)->parent(), &folder); 0362 QCOMPARE(folder.child(1)->parent(), &folder); 0363 QCOMPARE(folder.child(2)->parent(), &folder); 0364 0365 GeoDataFolder other = folder; 0366 QCOMPARE(other.size(), 3); 0367 QCOMPARE(other.child(0)->parent(), &other); 0368 QCOMPARE(other.child(1)->parent(), &other); 0369 QCOMPARE(other.child(2)->parent(), &other); 0370 QCOMPARE(static_cast<GeoDataPlacemark*>(other.child(0))->coordinate(), coord1); 0371 QCOMPARE(static_cast<GeoDataPlacemark*>(other.child(1))->coordinate(), coord2); 0372 QCOMPARE(static_cast<GeoDataPlacemark*>(other.child(2))->coordinate(), coord3); 0373 0374 other.append(new GeoDataPlacemark(pl1)); 0375 0376 QCOMPARE(folder.size(), 3); 0377 QCOMPARE(other.size(), 4); 0378 QCOMPARE(static_cast<GeoDataPlacemark*>(other.child(3))->coordinate(), coord1); 0379 } 0380 0381 void TestGeoDataCopy::copyPlacemark() 0382 { 0383 GeoDataPoint *point = new GeoDataPoint(coord1); 0384 point->setExtrude( true ); 0385 0386 // make sure that the coordinate contains the right values 0387 QCOMPARE(point->coordinates(), coord1); 0388 QCOMPARE(point->coordinates().detail(), coord1.detail()); 0389 QCOMPARE(point->extrude(), true); 0390 0391 GeoDataFolder folder; 0392 GeoDataPlacemark placemark; 0393 placemark.setName("Patrick Spendrin"); 0394 placemark.setGeometry(point); 0395 placemark.setArea(12345678.0); 0396 placemark.setPopulation(123456789); 0397 placemark.setId("281012"); 0398 placemark.setParent(&folder); 0399 0400 QCOMPARE(placemark.coordinate(), coord1); 0401 QCOMPARE(static_cast<GeoDataPoint*>(placemark.geometry())->coordinates(), coord1); 0402 QCOMPARE(static_cast<GeoDataPoint*>(placemark.geometry())->coordinates().detail(), coord1.detail()); 0403 QCOMPARE(placemark.area(), 12345678.0); 0404 QCOMPARE(placemark.population(), (qint64)123456789); 0405 QCOMPARE(placemark.id(), QString("281012")); 0406 QCOMPARE(placemark.name(), QString::fromLatin1("Patrick Spendrin")); 0407 QCOMPARE(placemark.geometry()->parent(), &placemark); 0408 QCOMPARE(placemark.parent(), &folder); 0409 0410 { 0411 GeoDataPlacemark other(placemark); 0412 0413 QCOMPARE(other.id(), QString()); 0414 QCOMPARE(other.parent(), static_cast<GeoDataObject *>(nullptr)); 0415 QCOMPARE(other.coordinate(), coord1); 0416 QCOMPARE(static_cast<GeoDataPoint*>(other.geometry())->coordinates(), coord1); 0417 QCOMPARE(static_cast<GeoDataPoint*>(other.geometry())->coordinates().detail(), coord1.detail()); 0418 QCOMPARE(other.area(), 12345678.0); 0419 QCOMPARE(other.population(), (qint64)123456789); 0420 QCOMPARE(other.name(), QString::fromLatin1("Patrick Spendrin")); 0421 QCOMPARE(other.geometry()->parent(), &other); 0422 0423 other.setPopulation(987654321); 0424 0425 QCOMPARE(other.coordinate(), coord1); 0426 QCOMPARE(static_cast<GeoDataPoint*>(other.geometry())->coordinates(), coord1); 0427 QCOMPARE(static_cast<GeoDataPoint*>(other.geometry())->coordinates().detail(), coord1.detail()); 0428 QCOMPARE(other.area(), 12345678.0); 0429 QCOMPARE(other.population(), (qint64)987654321); 0430 QCOMPARE(placemark.population(), (qint64)123456789); 0431 QCOMPARE(placemark.name(), QString::fromLatin1("Patrick Spendrin")); 0432 QCOMPARE(other.name(), QString::fromLatin1("Patrick Spendrin")); 0433 } 0434 0435 { 0436 GeoDataPlacemark other; 0437 0438 QCOMPARE(other.parent(), static_cast<GeoDataObject *>(nullptr)); // add a check before assignment to avoid compiler optimizing to copy c'tor 0439 0440 other = placemark; 0441 0442 QCOMPARE(other.id(), QString()); 0443 QCOMPARE(other.parent(), static_cast<GeoDataObject *>(nullptr)); 0444 QCOMPARE(other.coordinate(), coord1); 0445 QCOMPARE(static_cast<GeoDataPoint*>(other.geometry())->coordinates(), coord1); 0446 QCOMPARE(static_cast<GeoDataPoint*>(other.geometry())->coordinates().detail(), coord1.detail()); 0447 QCOMPARE(other.area(), 12345678.0); 0448 QCOMPARE(other.population(), (qint64)123456789); 0449 QCOMPARE(other.name(), QString::fromLatin1("Patrick Spendrin")); 0450 QCOMPARE(other.geometry()->parent(), &other); 0451 0452 other.setPopulation(987654321); 0453 0454 QCOMPARE(other.coordinate(), coord1); 0455 QCOMPARE(static_cast<GeoDataPoint*>(other.geometry())->coordinates(), coord1); 0456 QCOMPARE(static_cast<GeoDataPoint*>(other.geometry())->coordinates().detail(), coord1.detail()); 0457 QCOMPARE(other.area(), 12345678.0); 0458 QCOMPARE(other.population(), (qint64)987654321); 0459 QCOMPARE(placemark.population(), (qint64)123456789); 0460 QCOMPARE(placemark.name(), QString::fromLatin1("Patrick Spendrin")); 0461 QCOMPARE(other.name(), QString::fromLatin1("Patrick Spendrin")); 0462 } 0463 0464 { 0465 GeoDataFolder otherFolder; 0466 GeoDataPlacemark other; 0467 other.setParent(&otherFolder); 0468 0469 QCOMPARE(other.parent(), &otherFolder); 0470 0471 other = placemark; 0472 0473 QCOMPARE(other.parent(), &otherFolder); 0474 } 0475 0476 { 0477 const GeoDataPlacemark other(placemark); 0478 const GeoDataPlacemark other2(other); 0479 0480 QCOMPARE(placemark.geometry()->parent(), &placemark); 0481 QCOMPARE(other.geometry()->parent(), &other); 0482 QCOMPARE(other2.geometry()->parent(), &other2); 0483 } 0484 0485 { 0486 GeoDataPlacemark other; 0487 GeoDataPlacemark other2; 0488 0489 QCOMPARE(placemark.geometry()->parent(), &placemark); 0490 QCOMPARE(other.geometry()->parent(), &other); 0491 QCOMPARE(other2.geometry()->parent(), &other2); 0492 0493 other = placemark; 0494 other2 = other; 0495 0496 QCOMPARE(placemark.geometry()->parent(), &placemark); 0497 QCOMPARE(other.geometry()->parent(), &other); 0498 QCOMPARE(other2.geometry()->parent(), &other2); 0499 } 0500 } 0501 0502 void TestGeoDataCopy::copyHotSpot() 0503 { 0504 QPointF point(0.25, 0.75); 0505 0506 0507 GeoDataHotSpot first(point); 0508 GeoDataHotSpot::Units xunits; 0509 GeoDataHotSpot::Units yunits; 0510 GeoDataHotSpot second = first; 0511 0512 QVERIFY(first.hotSpot(xunits, yunits) == QPointF(0.25, 0.75)); 0513 QVERIFY(second.hotSpot(xunits, yunits) == QPointF(0.25, 0.75)); 0514 0515 first.setHotSpot(QPointF(0.3333333, 0.666666)); 0516 0517 QVERIFY(first.hotSpot(xunits, yunits) == QPointF(0.3333333, 0.666666)); 0518 QVERIFY(second.hotSpot(xunits, yunits) == QPointF(0.25, 0.75)); 0519 } 0520 0521 void TestGeoDataCopy::copyLatLonBox() 0522 { 0523 // north south east west 0524 GeoDataLatLonBox llbox(30.1, 12.2, 110.0, 44.9, GeoDataCoordinates::Degree); 0525 QCOMPARE(llbox.north(GeoDataCoordinates::Degree), 30.1); 0526 QCOMPARE(llbox.south(GeoDataCoordinates::Degree), 12.2); 0527 QCOMPARE(llbox.east(GeoDataCoordinates::Degree), 110.0); 0528 QCOMPARE(llbox.west(GeoDataCoordinates::Degree), 44.9); 0529 0530 GeoDataLatLonBox other = llbox; 0531 0532 QCOMPARE(other.north(GeoDataCoordinates::Degree), 30.1); 0533 QCOMPARE(other.south(GeoDataCoordinates::Degree), 12.2); 0534 QCOMPARE(other.east(GeoDataCoordinates::Degree), 110.0); 0535 QCOMPARE(other.west(GeoDataCoordinates::Degree), 44.9); 0536 0537 llbox.setNorth(0.1); 0538 other.setSouth(1.4); 0539 0540 QCOMPARE(llbox.north(), 0.1); 0541 QCOMPARE(llbox.south(GeoDataCoordinates::Degree), 12.2); 0542 QCOMPARE(other.north(GeoDataCoordinates::Degree), 30.1); 0543 QCOMPARE(other.south(), 1.4); 0544 } 0545 0546 void TestGeoDataCopy::copyStyle() 0547 { 0548 GeoDataLineStyle line(Qt::green); 0549 line.setWidth(2.0); 0550 0551 GeoDataStyle style; 0552 0553 style.setLineStyle( line ); 0554 0555 QCOMPARE(style.lineStyle().width(), (float)2.0); 0556 QVERIFY(style.lineStyle().color() == Qt::green); 0557 } 0558 0559 void TestGeoDataCopy::copyIconStyle() 0560 { 0561 // hotspottesting is not implemented as I am not sure how it should work 0562 GeoDataIconStyle icon; 0563 icon.setScale(2.0); 0564 0565 QCOMPARE(icon.scale(), (float)2.0); 0566 0567 GeoDataIconStyle other = icon; 0568 0569 QCOMPARE(other.scale(), (float)2.0); 0570 0571 icon.setScale(5.0); 0572 0573 QCOMPARE(icon.scale(), (float)5.0); 0574 QCOMPARE(other.scale(), (float)2.0); 0575 } 0576 0577 void TestGeoDataCopy::copyLabelStyle() 0578 { 0579 QFont testFont(QFont(QStringLiteral("Sans Serif")).family(), 12, 10, false); 0580 GeoDataLabelStyle label(testFont, Qt::red); 0581 label.setScale(2.0); 0582 0583 QCOMPARE(label.scale(), (float)2.0); 0584 QVERIFY(label.color() == Qt::red); 0585 QVERIFY(label.font() == testFont); 0586 0587 GeoDataLabelStyle other = label; 0588 0589 QCOMPARE(other.scale(), (float)2.0); 0590 QVERIFY(other.color() == Qt::red); 0591 QVERIFY(other.font() == testFont); 0592 0593 other.setColor(Qt::darkRed); 0594 label.setScale(5.0); 0595 0596 QCOMPARE(label.scale(), (float)5.0); 0597 QCOMPARE(other.scale(), (float)2.0); 0598 QVERIFY(label.color() == Qt::red); 0599 QVERIFY(other.color() == Qt::darkRed); 0600 } 0601 0602 void TestGeoDataCopy::copyLineStyle() 0603 { 0604 GeoDataLineStyle line(Qt::green); 0605 line.setWidth(2.0); 0606 0607 QCOMPARE(line.width(), (float)2.0); 0608 QVERIFY(line.color() == Qt::green); 0609 0610 GeoDataLineStyle other = line; 0611 0612 QCOMPARE(other.width(), (float)2.0); 0613 QVERIFY(other.color() == Qt::green); 0614 0615 other.setColor(Qt::darkGreen); 0616 line.setWidth(5.0); 0617 0618 QCOMPARE(line.width(), (float)5.0); 0619 QCOMPARE(other.width(), (float)2.0); 0620 QVERIFY(line.color() == Qt::green); 0621 QVERIFY(other.color() == Qt::darkGreen); 0622 } 0623 0624 void TestGeoDataCopy::copyPolyStyle() 0625 { 0626 GeoDataPolyStyle poly(Qt::blue); 0627 poly.setFill(true); 0628 poly.setOutline(false); 0629 0630 QCOMPARE(poly.fill(), true); 0631 QCOMPARE(poly.outline(), false); 0632 QVERIFY(poly.color() == Qt::blue); 0633 0634 GeoDataPolyStyle other = poly; 0635 0636 QCOMPARE(other.fill(), true); 0637 QCOMPARE(other.outline(), false); 0638 QVERIFY(other.color() == Qt::blue); 0639 0640 other.setOutline(true); 0641 poly.setColor( Qt::cyan ); 0642 0643 QCOMPARE(poly.outline(), false); 0644 QCOMPARE(other.outline(), true); 0645 QVERIFY(poly.color() == Qt::cyan); 0646 QVERIFY(other.color() == Qt::blue); 0647 } 0648 0649 void TestGeoDataCopy::copyStyleMap() 0650 { 0651 GeoDataStyleMap styleMap; 0652 styleMap["germany"] = "gst1"; 0653 styleMap["germany"] = "gst2"; 0654 styleMap["germany"] = "gst3"; 0655 styleMap["poland"] = "pst1"; 0656 styleMap["poland"] = "pst2"; 0657 styleMap["poland"] = "pst3"; 0658 styleMap.setLastKey("poland"); 0659 0660 QCOMPARE(styleMap.lastKey(), QLatin1String("poland")); 0661 0662 GeoDataStyleMap testMap = styleMap; 0663 0664 QVERIFY( styleMap == testMap ); 0665 0666 testMap.insert("Romania", "rst1"); 0667 testMap.insert("Romania", "rst2"); 0668 testMap.insert("Romania", "rst3"); 0669 testMap.setLastKey("Romania"); 0670 0671 QCOMPARE(testMap.lastKey(), QLatin1String("Romania")); 0672 QCOMPARE(styleMap.lastKey(), QLatin1String("poland")); 0673 } 0674 0675 } 0676 0677 QTEST_MAIN( Marble::TestGeoDataCopy ) 0678 0679 #include "TestGeoDataCopy.moc" 0680