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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
// SPDX-License-Identifier: LGPL-2.1-or-later
//
// SPDX-FileCopyrightText: 2008 Patrick Spendrin <ps_ml@gmx.de>
//
#include "GeoDataDocument.h"
#include "GeoDataGeometry.h"
#include "GeoDataParser.h"
#include "GeoDataPlacemark.h"
#include "GeoDataTypes.h"
#include "GeoWriter.h"
#include "MarbleDirs.h"
#include <QBuffer>
#include <QByteArray>
#include <QCoreApplication>
#include <QDebug>
#include <QString>
#include <QTest>
namespace Marble
{
class TestGeoDataPack : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void saveKMLToCache();
void loadKMLFromCache();
void saveCitiesToCache();
void loadCitiesFromCache();
private:
QString content;
QElapsedTimer timer;
};
void TestGeoDataPack::initTestCase()
{
MarbleDirs::setMarbleDataPath(DATA_PATH);
MarbleDirs::setMarblePluginPath(PLUGIN_PATH);
timer.start();
content = QString(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n"
" <Document>\n"
" <Placemark>\n"
" <name>Empty</name>\n"
" </Placemark>\n"
" <Placemark>\n"
" <name>LinearRingTest.kml</name>\n"
" <Polygon>\n"
" <outerBoundaryIs>\n"
" <LinearRing>\n"
" <coordinates>\n"
" -122.365662,37.826988,0\n"
" -122.365202,37.826302,0\n"
" -122.364581,37.82655,0\n"
" -122.365038,37.827237,0\n"
" -122.365662,37.826988,0\n"
" </coordinates>\n"
" </LinearRing>\n"
" </outerBoundaryIs>\n"
" </Polygon>\n"
" </Placemark>\n"
" </Document>\n"
"</kml>");
}
void TestGeoDataPack::saveKMLToCache()
{
GeoDataParser parser(GeoData_KML);
QByteArray array(content.toUtf8());
QBuffer buffer(&array);
buffer.open(QIODevice::ReadOnly);
if (!parser.read(&buffer)) {
qWarning("Could not parse data!");
QFAIL("Could not parse data!");
return;
}
GeoDocument *document = parser.releaseDocument();
QVERIFY(document);
qDebug() << " parse Timer " << timer.elapsed();
GeoDataDocument *dataDocument = static_cast<GeoDataDocument *>(document);
QString path = QString("%1/%2.cache");
path = path.arg(QCoreApplication::applicationDirPath());
path = path.arg(QString("KMLTest"));
QFile cacheFile(path);
if (cacheFile.open(QIODevice::WriteOnly)) {
QDataStream stream(&cacheFile);
dataDocument->pack(stream);
cacheFile.close();
qDebug("Saved kml document to cache: %s", path.toLatin1().data());
}
qDebug() << "write Timer " << timer.elapsed();
delete document;
}
void TestGeoDataPack::loadKMLFromCache()
{
GeoDataDocument *cacheDocument = new GeoDataDocument();
QString path = QString("%1/%2.cache");
path = path.arg(QCoreApplication::applicationDirPath());
path = path.arg(QString("KMLTest"));
QFile cacheFile(path);
if (cacheFile.open(QIODevice::ReadOnly)) {
QDataStream stream(&cacheFile);
cacheDocument->unpack(stream);
cacheFile.close();
qDebug("Loaded kml document from cache: %s", path.toLatin1().data());
}
QVERIFY(cacheDocument);
qDebug() << "read Timer " << timer.elapsed();
GeoDataParser parser(GeoData_KML);
QByteArray array(content.toUtf8());
QBuffer buffer(&array);
buffer.open(QIODevice::ReadOnly);
if (!parser.read(&buffer)) {
qWarning("Could not parse data!");
QFAIL("Could not parse data!");
return;
}
GeoDocument *document = parser.releaseDocument();
QVERIFY(document);
qDebug() << "parse Timer " << timer.elapsed();
GeoDataDocument *dataDocument = static_cast<GeoDataDocument *>(document);
QCOMPARE(*cacheDocument, *dataDocument);
qDebug() << "compare Timer " << timer.elapsed();
delete document;
delete cacheDocument;
}
void TestGeoDataPack::saveCitiesToCache()
{
GeoDataParser parser(GeoData_KML);
QFile citiesFile(CITIES_PATH);
citiesFile.open(QIODevice::ReadOnly);
if (!parser.read(&citiesFile)) {
qWarning("Could not parse data!");
QFAIL("Could not parse data!");
return;
}
GeoDocument *document = parser.releaseDocument();
QVERIFY(document);
qDebug() << "read Timer " << timer.elapsed();
GeoDataDocument *dataDocument = static_cast<GeoDataDocument *>(document);
QString path = QString("%1/%2.cache");
path = path.arg(QCoreApplication::applicationDirPath());
path = path.arg(QString("CitiesTest"));
QFile cacheFile(path);
if (cacheFile.open(QIODevice::WriteOnly)) {
QDataStream stream(&cacheFile);
dataDocument->pack(stream);
cacheFile.close();
qDebug("Saved kml document to cache: %s", path.toLatin1().data());
}
QVERIFY(cacheFile.size() > 0);
qDebug() << "write Timer " << timer.elapsed();
delete document;
}
void TestGeoDataPack::loadCitiesFromCache()
{
GeoDataDocument *cacheDocument = new GeoDataDocument();
QString path = QString("%1/%2.cache");
path = path.arg(QCoreApplication::applicationDirPath());
path = path.arg(QString("CitiesTest"));
QFile cacheFile(path);
if (cacheFile.open(QIODevice::ReadOnly)) {
QDataStream stream(&cacheFile);
cacheDocument->unpack(stream);
cacheFile.close();
qDebug("Loaded kml document from cache: %s", path.toLatin1().data());
}
QVERIFY(cacheDocument);
qDebug() << "read Timer " << timer.elapsed();
GeoDataParser parser(GeoData_KML);
QFile citiesFile(CITIES_PATH);
citiesFile.open(QIODevice::ReadOnly);
if (!parser.read(&citiesFile)) {
qWarning("Could not parse data!");
QFAIL("Could not parse data!");
return;
}
GeoDocument *document = parser.releaseDocument();
QVERIFY(document);
qDebug() << "parse Timer " << timer.elapsed();
// commented out as it timeouts the test on build.kde.org
// GeoDataDocument *dataDocument = static_cast<GeoDataDocument*>( document );
// QVERIFY( compareDocuments( cacheDocument, dataDocument ) );
// qDebug() << "compare Timer " << timer.elapsed();
delete cacheDocument;
// delete dataDocument;
}
}
QTEST_MAIN(Marble::TestGeoDataPack)
#include "TestGeoDataPack.moc"
|