Skip to content

Commit

Permalink
Add basic vector tiles utils test class, inc. zoom level test
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn authored and github-actions[bot] committed Nov 22, 2021
1 parent be95bd7 commit 00627c7
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/src/core/CMakeLists.txt
Expand Up @@ -192,6 +192,7 @@ set(TESTS
testqgsvectorlayerjoinbuffer.cpp
testqgsvectorlayerutils.cpp
testqgsvectortilelayer.cpp
testqgsvectortileutils.cpp
testqgsvectortilewriter.cpp
testqgstiles.cpp
testqgsweakrelation.cpp
Expand Down
80 changes: 80 additions & 0 deletions tests/src/core/testqgsvectortileutils.cpp
@@ -0,0 +1,80 @@
/***************************************************************************
testqgsvectortileutils.cpp
--------------------------------------
Date : November 2021
Copyright : (C) 2021 by Mathieu Pellerin
Email : nirvn dot asia 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 "qgsvectortileutils.h"

/**
* \ingroup UnitTests
* This is a unit test for the vector tile utils class
*/
class TestQgsVectorTileUtils : public QObject
{
Q_OBJECT

public:
TestQgsVectorTileUtils() = default;

private:
QString mReport;

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_scaleToZoomLevel();
};


void TestQgsVectorTileUtils::initTestCase()
{
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::init();
QgsApplication::initQgis();
QgsApplication::showSettings();
mReport += QLatin1String( "<h1>Vector Tile Utils Tests</h1>\n" );
}

void TestQgsVectorTileUtils::cleanupTestCase()
{
const QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
{
QTextStream myQTextStream( &myFile );
myQTextStream << mReport;
myFile.close();
}

QgsApplication::exitQgis();
}

void TestQgsVectorTileUtils::test_scaleToZoomLevel()
{
// test zoom level logic
int zoomLevel = QgsVectorTileUtils::scaleToZoomLevel( 288896, 0, 20 );
QCOMPARE( zoomLevel, 10 );
}


QGSTEST_MAIN( TestQgsVectorTileUtils )
#include "testqgsvectortileutils.moc"

0 comments on commit 00627c7

Please sign in to comment.