Skip to content

Commit

Permalink
Added initial unit test + test data
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Mar 27, 2020
1 parent 8d24e17 commit 6a107c8
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/src/core/CMakeLists.txt
Expand Up @@ -31,6 +31,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src/core/symbology
${CMAKE_SOURCE_DIR}/src/core/classification
${CMAKE_SOURCE_DIR}/src/core/mesh
${CMAKE_SOURCE_DIR}/src/core/vectortile
${CMAKE_SOURCE_DIR}/src/test

${CMAKE_BINARY_DIR}/src/core
Expand Down Expand Up @@ -237,6 +238,7 @@ SET(TESTS
testqgsvectorlayerjoinbuffer.cpp
testqgsvectorlayer.cpp
testqgsvectorlayerutils.cpp
testqgsvectortilelayer.cpp
testqgsziputils.cpp
testziplayer.cpp
testqgslayerdefinition.cpp
Expand Down
88 changes: 88 additions & 0 deletions tests/src/core/testqgsvectortilelayer.cpp
@@ -0,0 +1,88 @@
/***************************************************************************
testqgsvectortilelayer.cpp
--------------------------------------
Date : March 2020
Copyright : (C) 2020 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgstest.h"
#include <QObject>
#include <QString>

//qgis includes...
#include "qgsapplication.h"
#include "qgsproject.h"
#include "qgstiles.h"
#include "qgsvectortilelayer.h"

/**
* \ingroup UnitTests
* This is a unit test for a vector tile layer
*/
class TestQgsVectorTileLayer : public QObject
{
Q_OBJECT

public:
TestQgsVectorTileLayer() = default;

private:
QString mDataDir;
QgsVectorTileLayer *mLayer = nullptr;

private slots:
void initTestCase();// will be called before the first testfunction is executed.
void cleanupTestCase();// will be called after the last testfunction was executed.
void init() {} // will be called before each testfunction is executed.
void cleanup() {} // will be called after every testfunction.

void test_basic();
};


void TestQgsVectorTileLayer::initTestCase()
{
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::init();
QgsApplication::initQgis();
QgsApplication::showSettings();
mDataDir = QString( TEST_DATA_DIR ); //defined in CmakeLists.txt
mDataDir += "/vector_tile";

QgsDataSourceUri ds;
ds.setParam( "type", "xyz" );
ds.setParam( "url", QString( "file://%1/{z}-{x}-{y}.pbf" ).arg( mDataDir ) );
ds.setParam( "zmax", "1" );
mLayer = new QgsVectorTileLayer( ds.encodedUri(), "Vector Tiles Test" );
QVERIFY( mLayer->isValid() );

QgsProject::instance()->addMapLayer( mLayer );

}

void TestQgsVectorTileLayer::cleanupTestCase()
{
QgsApplication::exitQgis();
}

void TestQgsVectorTileLayer::test_basic()
{
// tile fetch test
QByteArray tile0rawData = mLayer->getRawTile( QgsTileXYZ( 0, 0, 0 ) );
QCOMPARE( tile0rawData.length(), 64822 );

QByteArray invalidTileRawData = mLayer->getRawTile( QgsTileXYZ( 0, 0, 99 ) );
QCOMPARE( invalidTileRawData.length(), 0 );
}


QGSTEST_MAIN( TestQgsVectorTileLayer )
#include "testqgsvectortilelayer.moc"
Binary file added tests/testdata/vector_tile/0-0-0.pbf
Binary file not shown.
Binary file added tests/testdata/vector_tile/1-0-0.pbf
Binary file not shown.
Binary file added tests/testdata/vector_tile/1-0-1.pbf
Binary file not shown.
Binary file added tests/testdata/vector_tile/1-1-0.pbf
Binary file not shown.
Binary file added tests/testdata/vector_tile/1-1-1.pbf
Binary file not shown.
15 changes: 15 additions & 0 deletions tests/testdata/vector_tile/README.md
@@ -0,0 +1,15 @@

# Vector Tiles Test Data

Downloaded from https://api.maptiler.com/tiles/v3/{z}/{x}/{y}.pbf?key=XXX
(where XXX stands for a key that can be obtained when registered at MapTiler: https://www.maptiler.com/)

## License

These tiles are coming from OpenMapTiles project, under the "Free data" terms of use: https://openmaptiles.com/terms/

The FREE tiles are legally usable for:

- open-source and open-data community project websites
- non-commercial personal projects
- evaluation and education purposes

0 comments on commit 6a107c8

Please sign in to comment.