1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
// SPDX-License-Identifier: LGPL-2.1-or-later
//
// SPDX-FileCopyrightText: 2009 Bastian Holst <bastianholst@gmx.de>
//
#include "GeoDataCoordinates.h"
#include "GeoDataDocument.h"
#include "GeoDataFolder.h"
#include "GeoDataIconStyle.h"
#include "GeoDataLatLonAltBox.h"
#include "GeoDataLineString.h"
#include "GeoDataLinearRing.h"
#include "GeoDataPlacemark.h"
#include "GeoDataStyle.h"
#include "GeoDataStyleMap.h"
#include "GeoDataTypes.h"
#include "MarbleDebug.h"
#include <QDebug>
#include <QTest>
namespace Marble
{
class TestGeoData : public QObject
{
Q_OBJECT
private Q_SLOTS:
void nodeTypeTest();
void parentingTest();
void testCast();
};
/// test the nodeType function through various construction tests
void TestGeoData::nodeTypeTest()
{
/// basic testing of nodeType
auto folder = new GeoDataFolder;
const char *folderType = GeoDataTypes::GeoDataFolderType;
QCOMPARE(folder->nodeType(), folderType);
/// testing the nodeType of an object appended to a container
GeoDataDocument document;
document.append(folder);
GeoDataFeature &featureRef = document.last();
QVERIFY(geodata_cast<GeoDataFolder>(&featureRef));
}
void TestGeoData::parentingTest()
{
auto document = new GeoDataDocument;
auto folder = new GeoDataFolder;
/// simple parenting test
auto placemark = new GeoDataPlacemark;
placemark->setParent(document);
QCOMPARE(placemark->parent(), document);
/// simple append and child count test
document->append(placemark);
/// appending folder to document before feeding folder
document->append(folder);
QCOMPARE(document->size(), 2);
auto placemark2 = new GeoDataPlacemark;
folder->append(placemark2);
QCOMPARE(folder->size(), 1);
/// retrieve child and check it matches placemark
GeoDataPlacemark *placemarkPtr;
QVERIFY(geodata_cast<GeoDataPlacemark>(document->child(0)));
placemarkPtr = static_cast<GeoDataPlacemark *>(document->child(0));
QCOMPARE(placemarkPtr, placemark);
/// check retrieved placemark matches intented child
int position = document->childPosition(placemarkPtr);
QCOMPARE(position, 0);
/// retrieve child two and check it matches folder
GeoDataFolder *folderPtr;
QVERIFY(geodata_cast<GeoDataFolder>(document->child(1)));
folderPtr = static_cast<GeoDataFolder *>(document->child(1));
QCOMPARE(folderPtr, folder);
/// check retrieved folder matches intended child
position = document->childPosition(folderPtr);
QCOMPARE(position, 1);
/// retrieve child three and check it matches placemark
QCOMPARE(folderPtr->size(), 1);
placemarkPtr = static_cast<GeoDataPlacemark *>(folderPtr->child(0));
QCOMPARE(placemarkPtr->nodeType(), placemark2->nodeType());
QCOMPARE(placemarkPtr, placemark2);
/// check retrieved placemark matches intended child
QCOMPARE(folderPtr->childPosition(placemarkPtr), 0);
/// Set a style
GeoDataIconStyle iconStyle;
iconStyle.setIconPath("myicon.png");
GeoDataStyle::Ptr style(new GeoDataStyle);
style->setId("mystyle");
style->setIconStyle(iconStyle);
GeoDataObject *noParent = nullptr;
QCOMPARE(style->parent(), noParent);
QCOMPARE(iconStyle.parent(), noParent);
document->setStyle(style);
QCOMPARE(style->parent(), document); // Parent should be assigned now
QCOMPARE(style->iconStyle().parent(), style.data());
QCOMPARE(iconStyle.parent(), noParent); // setIconStyle copies
QCOMPARE(placemark->style()->parent(), noParent);
placemark->setStyle(style);
QCOMPARE(placemark->style()->parent(), placemark); // Parent should be assigned now
/// Set a style map
auto styleMap = new GeoDataStyleMap;
styleMap->setId("mystylemap");
styleMap->insert("normal", "#mystyle");
styleMap->insert("highlight", "#mystyle");
document->addStyle(style);
document->setStyleMap(styleMap);
QCOMPARE(placemark2->style()->parent(), noParent);
placemark2->setStyleUrl("#mystyle");
QCOMPARE(placemark2->style()->parent(), document); // Parent is document, not placemark2
QCOMPARE(iconStyle.iconPath(), QString("myicon.png"));
QCOMPARE(placemark2->style()->iconStyle().iconPath(), QString("myicon.png"));
}
void TestGeoData::testCast()
{
GeoDataLineString obj;
GeoDataObject *base = &obj;
QCOMPARE(geodata_cast<GeoDataObject>(base), nullptr);
QCOMPARE(geodata_cast<GeoDataGeometry>(base), nullptr);
QCOMPARE(geodata_cast<GeoDataLineString>(base), &obj);
QCOMPARE(geodata_cast<GeoDataLinearRing>(base), nullptr);
QCOMPARE(geodata_cast<GeoDataPlacemark>(base), nullptr);
const GeoDataObject *cbase = &obj;
QCOMPARE(geodata_cast<GeoDataObject>(cbase), nullptr);
QCOMPARE(geodata_cast<GeoDataGeometry>(cbase), nullptr);
QCOMPARE(geodata_cast<GeoDataLineString>(cbase), &obj);
QCOMPARE(geodata_cast<GeoDataLinearRing>(cbase), nullptr);
QCOMPARE(geodata_cast<GeoDataPlacemark>(cbase), nullptr);
QCOMPARE(geodata_cast<GeoDataPlacemark>(static_cast<GeoDataObject *>(nullptr)), nullptr);
}
}
QTEST_MAIN(Marble::TestGeoData)
#include "TestGeoData.moc"
|