[Marble-devel] [marble] /: Fix TileId with test cases
Christoph Feck
christoph at maxiom.de
Tue Dec 11 22:56:20 UTC 2012
On Tuesday 11 December 2012 21:31:52 Thibaut Gridel wrote:
> Git commit 057f729955ffb149e7691fd38fc737078e0a434d by Thibaut
> Gridel. Committed on 11/12/2012 at 20:57.
> Pushed by tgridel into branch 'master'.
>
> Fix TileId with test cases
>
> M +3 -3 src/lib/TileId.cpp
> M +1 -0 tests/CMakeLists.txt
> A +102 -0 tests/TileIdTest.cpp [License: LGPL]
Compilation fails for this test. It looks like the TileIdTest.cpp does
not link to lib/TileId.cpp:
-- Build files have been written to: /local/build/KDE/edu/marble
CMakeFiles/TileIdTest.dir/TileIdTest.o: In function
`Marble::TileIdTest::testFromCoordinates()':
/local/git/KDE/edu/marble/tests/TileIdTest.cpp:91: undefined reference
to `Marble::TileId::fromCoordinates(Marble::GeoDataCoordinates const&,
int)'
collect2: error: ld returned 1 exit status
make[2]: *** [tests/TileIdTest] Error 1
make[2]: Target `tests/CMakeFiles/TileIdTest.dir/build' not remade
because of errors.
make[1]: *** [tests/CMakeFiles/TileIdTest.dir/all] Error 2
make[1]: Target `all' not remade because of errors.
make: *** [all] Error 2
make: Target `default_target' not remade because of errors.
-- Failed: KDE/edu/marble
--
Christoph Feck
http://kdepepo.wordpress.com/
KDE Quality Team
>
>
http://commits.kde.org/marble/057f729955ffb149e7691fd38fc737078e0a4
> 34d
>
> diff --git a/src/lib/TileId.cpp b/src/lib/TileId.cpp
> index de258c3..6ccce5b 100644
> --- a/src/lib/TileId.cpp
> +++ b/src/lib/TileId.cpp
> @@ -58,13 +58,13 @@ TileId TileId::fromCoordinates(const
> GeoDataCoordinates &coords, int zoomLevel) }
> const int maxLat = 90000000;
> const int maxLon = 180000000;
> - int lat = coords.latitude( GeoDataCoordinates::Degree ) *
> 1000000; - int lon = coords.longitude(
> GeoDataCoordinates::Degree ) * 1000000; + int lat =
> GeoDataCoordinates::normalizeLat( coords.latitude(),
> GeoDataCoordinates::Degree ) * 1000000; + int lon =
> GeoDataCoordinates::normalizeLon( coords.longitude(),
> GeoDataCoordinates::Degree ) * 1000000; int x = 0;
> int y = 0;
> for( int i=0; i<zoomLevel; ++i ) {
> const int deltaLat = maxLat >> i;
> - if( lat < ( maxLat - deltaLat )) {
> + if( lat <= ( maxLat - deltaLat )) {
> y += 1<<(zoomLevel-i-1);
> lat += deltaLat;
> }
> diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
> index 49111ac..4c58beb 100644
> --- a/tests/CMakeLists.txt
> +++ b/tests/CMakeLists.txt
> @@ -69,6 +69,7 @@ add_definitions(
> -
DDGML_PATH="\\\"${CMAKE_CURRENT_SOURCE_DIR}/../data/maps/earth
> marble_add_qtonly_test( TestGeoSceneWriter )
>
> marble_add_test( QuaternionTest ) # Check Quaternion
> arithmetic +marble_add_test( TileIdTest ) # Check
> TileId arithmetic marble_add_test( ProjectionTest ) #
> Check LineString projection marble_add_test( PluginManagerTest )
> # Check plugin loading marble_add_test(
> MarbleRunnerManagerTest ) # Check RunnerManager signals diff
> --git a/tests/TileIdTest.cpp b/tests/TileIdTest.cpp
> new file mode 100644
> index 0000000..cd8eacc
> --- /dev/null
> +++ b/tests/TileIdTest.cpp
> @@ -0,0 +1,102 @@
> +//
> +// This file is part of the Marble Virtual 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 2012 Thibaut Gridel <tgridel at free.fr>
> +
> +
> +#include <QtCore/QMetaType>
> +#include <QtTest/QtTest>
> +#include "TileId.h"
> +#include "GeoDataCoordinates.h"
> +
> +namespace QTest
> +{
> +
> +}
> +
> +#define addRow() QTest::newRow( QString("line %1").arg( __LINE__
> ).toAscii().data() ) +
> +namespace Marble
> +{
> +
> +class TileIdTest : public QObject
> +{
> + Q_OBJECT
> +
> + private slots:
> + void testFromCoordinates_data();
> + void testFromCoordinates();
> +
> +};
> +
> +
> +void TileIdTest::testFromCoordinates_data()
> +{
> + QTest::addColumn<qreal>( "lon" );
> + QTest::addColumn<qreal>( "lat" );
> + QTest::addColumn<int>( "zoom" );
> + QTest::addColumn<int>( "x" );
> + QTest::addColumn<int>( "y" );
> +
> + for ( int zoom = 1; zoom < 19; ++zoom) {
> + int last = (2 << (zoom-1)) -1;
> + int quarter = qRound(last/4.0);
> + int mid = qRound(last/2.0);
> + int three = mid + quarter;
> +
> + addRow() << -180.0 << 0.0 << zoom << 0 << mid;
> + addRow() << -90.0 << 0.0 << zoom << quarter << mid;
> + addRow() << 0.0 << 0.0 << zoom << mid << mid;
> + addRow() << 90.0 << 0.0 << zoom << three << mid;
> + addRow() << 180.0 << 0.0 << zoom << last << mid;
> +
> + addRow() << -180.0 << -89.9999 << zoom << 0 << last;
> + addRow() << -90.0 << -89.9999 << zoom << quarter << last;
> + addRow() << 0.0 << -89.9999 << zoom << mid << last;
> + addRow() << 90.0 << -89.9999 << zoom << three << last;
> + addRow() << 180.0 << -89.9999 << zoom << last << last;
> +
> + addRow() << -180.0 << 89.9999 << zoom << 0 << 0;
> + addRow() << -90.0 << 89.9999 << zoom << quarter << 0;
> + addRow() << 0.0 << 89.9999 << zoom << mid << 0;
> + addRow() << 90.0 << 89.9999 << zoom << three << 0;
> + addRow() << 180.0 << 89.9999 << zoom << last << 0;
> +
> + addRow() << -180.0 << -179.9999 << zoom << 0 << mid;
> + addRow() << -90.0 << -179.9999 << zoom << quarter << mid;
> + addRow() << 0.0 << -179.9999 << zoom << mid << mid;
> + addRow() << 90.0 << -179.9999 << zoom << three << mid;
> + addRow() << 180.0 << -179.9999 << zoom << last << mid;
> +
> + addRow() << -180.0 << 179.9999 << zoom << 0 << mid-1;
> + addRow() << -90.0 << 179.9999 << zoom << quarter <<
> mid-1; + addRow() << 0.0 << 179.9999 << zoom << mid <<
> mid-1; + addRow() << 90.0 << 179.9999 << zoom << three <<
> mid-1; + addRow() << 180.0 << 179.9999 << zoom << last <<
> mid-1; + }
> +}
> +
> +void TileIdTest::testFromCoordinates()
> +{
> + QFETCH( qreal, lon );
> + QFETCH( qreal, lat );
> + QFETCH( int, zoom);
> + QFETCH( int, x);
> + QFETCH( int, y);
> +
> + const TileId tile =
> TileId::fromCoordinates(GeoDataCoordinates( lon , lat,
> GeoDataCoordinates::Degree), zoom ); + qDebug() << "zoom " <<
> zoom;
> +
> + QCOMPARE( tile.x(), x );
> + QCOMPARE( tile.y(), y );
> +}
> +
> +}
> +
> +QTEST_MAIN( Marble::TileIdTest )
> +
> +#include "TileIdTest.moc"
More information about the Marble-devel
mailing list