[Marble-commits] KDE/kdeedu/marble
Andrew Manson
g.real.ate at gmail.com
Sat Aug 8 21:50:57 CEST 2009
SVN commit 1008970 by mansona:
more tests for GeoDataWriter and adding a way to do recursive document writing
from a tree of geodata.
M +2 -2 src/lib/geodata/writer/GeoTagWriter.h
M +24 -9 src/lib/geodata/writer/GeoWriter.cpp
M +4 -0 src/lib/geodata/writer/GeoWriter.h
A src/lib/geodata/writers/kml/KmlDocumentTagWriter.cpp [License: LGPL]
A src/lib/geodata/writers/kml/KmlDocumentTagWriter.h [License: LGPL]
M +2 -1 src/lib/geodata/writers/kml/KmlPlacemarkTagWriter.cpp
M +1 -1 src/lib/geodata/writers/kml/KmlPlacemarkTagWriter.h
M +74 -0 tests/TestGeoDataWriter.cpp
M +13 -13 tests/data/NewYorkDocument.kml
--- trunk/KDE/kdeedu/marble/src/lib/geodata/writer/GeoTagWriter.h #1008969:1008970
@@ -18,7 +18,7 @@
namespace Marble
{
-class GeoNode;
+class GeoDataObject;
class GeoWriter;
/**
@@ -30,7 +30,7 @@
class GeoTagWriter
{
public:
- virtual bool write( GeoNode &node, GeoWriter& writer ) const = 0;
+ virtual bool write( const GeoDataObject &node, GeoWriter& writer ) const = 0;
/**
* @brief Object Name and Namespace Pair
--- trunk/KDE/kdeedu/marble/src/lib/geodata/writer/GeoWriter.cpp #1008969:1008970
@@ -13,6 +13,8 @@
#include "GeoTagWriter.h"
#include "KmlElementDictionary.h"
+#include <QtCore/QDebug>
+
namespace Marble
{
@@ -32,16 +34,8 @@
while ( it.hasNext() ) {
GeoDataFeature f = it.next();
- GeoTagWriter::QualifiedName name( f.nodeType(), m_documentType );
- const GeoTagWriter* writer = GeoTagWriter::recognizes( name );
- if( writer ) {
- if(!writer->write( f, (*this) ) ) {
- //something went wrong while writing
- return false;
- }
- } else {
- //do not have a handler for this element
+ if( ! writeElement( f ) ) {
return false;
}
}
@@ -55,6 +49,27 @@
return write(device, list);
}
+bool GeoWriter::writeElement(const GeoDataObject &object)
+{
+ //Add checks to see that everything is ok here
+ //
+
+ GeoTagWriter::QualifiedName name( object.nodeType(), m_documentType );
+ const GeoTagWriter* writer = GeoTagWriter::recognizes( name );
+
+ if( writer ) {
+ if( ! writer->write( object, *this ) ) {
+ qDebug() << "An error has been reported by the GeoWriter for: "
+ << name;
+ return false;
+ }
+ } else {
+ qDebug() << "There is no GeoWriter registered for: " << name;
+ return false;
+ }
+ return true;
+}
+
void GeoWriter::setDocumentType( const QString &documentType )
{
m_documentType = documentType;
--- trunk/KDE/kdeedu/marble/src/lib/geodata/writer/GeoWriter.h #1008969:1008970
@@ -57,6 +57,10 @@
*/
void setDocumentType( const QString& documentType );
private:
+ friend class GeoTagWriter;
+ bool writeElement( const GeoDataObject& object );
+
+private:
QString m_documentType;
};
--- trunk/KDE/kdeedu/marble/src/lib/geodata/writers/kml/KmlPlacemarkTagWriter.cpp #1008969:1008970
@@ -25,7 +25,8 @@
new KmlPlacemarkTagWriter() );
-bool KmlPlacemarkTagWriter::write( GeoNode &node, GeoWriter& writer ) const
+bool KmlPlacemarkTagWriter::write( const GeoDataObject &node,
+ GeoWriter& writer ) const
{
writer.writeStartElement( kml::kmlTag_Placemark );
//Write the actual important stuff!
--- trunk/KDE/kdeedu/marble/src/lib/geodata/writers/kml/KmlPlacemarkTagWriter.h #1008969:1008970
@@ -18,7 +18,7 @@
class KmlPlacemarkTagWriter : public GeoTagWriter
{
public:
- virtual bool write( GeoNode &node, GeoWriter& writer ) const;
+ virtual bool write( const GeoDataObject &node, GeoWriter& writer ) const;
};
}
--- trunk/KDE/kdeedu/marble/tests/TestGeoDataWriter.cpp #1008969:1008970
@@ -1,3 +1,13 @@
+//
+// This file is part of the Marble Desktop Globe.
+//
+// This program is free software licensed under the GNU LGPL. You can
+// find a copy of this license in LICENSE.txt in the top directory of
+// the source code.
+//
+// Copyright 2009 Andrew Manson <g.real.ate at gmail.com>
+//
+
#include <QtCore/QObject>
#include <QtTest/QtTest>
@@ -19,6 +29,9 @@
void countFeatures();
void saveFile_data();
void saveFile();
+ void saveAndLoad_data();
+ void saveAndLoad();
+ void saveAndCompare_data();
void saveAndCompare();
void cleanupTestCase();
private:
@@ -120,9 +133,70 @@
}
+void TestGeoDataWriter::saveAndLoad_data()
+{
+ QTest::addColumn<QSharedPointer<GeoDataParser> >("parser");
+
+ QTest::newRow("NewYork") << parsers.value( "NewYork.kml" ) ;
+ QTest::newRow("NewYorkDocument") << parsers.value( "NewYorkDocument.kml" );
+}
+
+void TestGeoDataWriter::saveAndLoad()
+{
+ //Save the file and then verify loading it again
+ QFETCH( QSharedPointer<GeoDataParser>, parser );
+
+ QTemporaryFile tempFile;
+ GeoWriter writer;
+ //FIXME: a better way to do this?
+ writer.setDocumentType( "http://earth.google.com/kml/2.2" );
+
+ // Open file in right mode
+ QVERIFY( tempFile.open() );
+
+ QVERIFY( writer.write( &tempFile,
+ *dynamic_cast<GeoDataFeature*>(parser->activeDocument() ) ) );
+
+ GeoDataParser resultParser( GeoData_KML );
+
+ QVERIFY( resultParser.read( &tempFile ) );
+}
+
+void TestGeoDataWriter::saveAndCompare_data()
+{
+ QTest::addColumn<QSharedPointer<GeoDataParser> >("parser");
+ QTest::addColumn<QString>("origional");
+
+ QTest::newRow("NewYork") << parsers.value( "NewYork.kml" ) << "NewYork.kml";
+ QTest::newRow("NewYorkDocument") << parsers.value( "NewYorkDocument.kml" ) << "NewYorkDocument.kml";
+}
+
void TestGeoDataWriter::saveAndCompare()
{
//save the file and compare it to the origional
+ QFETCH( QSharedPointer<GeoDataParser>, parser );
+ QFETCH( QString, origional );
+
+ //attempt to save a file using the GeoWriter
+ QTemporaryFile tempFile;
+
+ GeoWriter writer;
+ //FIXME: a better way to do this?
+ writer.setDocumentType( "http://earth.google.com/kml/2.2" );
+
+ // Open file in right mode
+ QVERIFY( tempFile.open() );
+
+ QVERIFY( writer.write( &tempFile,
+ *dynamic_cast<GeoDataFeature*>(parser->activeDocument() ) ) );
+
+ QFile file( dataDir.filePath( origional ) );
+ QVERIFY( file.open( QIODevice::ReadOnly ) );
+ QVERIFY( tempFile.reset() );
+ QTextStream oldFile( &file );
+ QTextStream newFile( &tempFile );
+
+ QCOMPARE( newFile.readAll(), oldFile.readAll() );
}
void TestGeoDataWriter::cleanupTestCase()
--- trunk/KDE/kdeedu/marble/tests/data/NewYorkDocument.kml #1008969:1008970
@@ -4,18 +4,18 @@
<name></name>
<description><![CDATA[]]></description>
<Placemark>
- <name>New York City</name>
- <description>New York City</description>
- <Point>
- <coordinates>-74.006393,40.714172,0</coordinates>
- </Point>
-</Placemark>
-<Placemark>
- <name>New York City 2</name>
- <description>New York City</description>
- <Point>
- <coordinates>-74.006,40.714,0</coordinates>
- </Point>
-</Placemark>
+ <name>New York City</name>
+ <description>New York City</description>
+ <Point>
+ <coordinates>-74.006393,40.714172,0</coordinates>
+ </Point>
+ </Placemark>
+ <Placemark>
+ <name>New York City 2</name>
+ <description>New York City</description>
+ <Point>
+ <coordinates>-74.006,40.714,0</coordinates>
+ </Point>
+ </Placemark>
</Document>
</kml>
More information about the Marble-commits
mailing list