Skip to content
Permalink
Browse files
Add basic vector tiles utils test class, inc. zoom level test
  • Loading branch information
nirvn authored and nyalldawson committed Nov 23, 2021
1 parent 372ae04 commit 601e2caf9c2dfc0df11023b3f990f557ef5048b5
Showing with 81 additions and 0 deletions.
  1. +1 −0 tests/src/core/CMakeLists.txt
  2. +80 −0 tests/src/core/testqgsvectortileutils.cpp
@@ -192,6 +192,7 @@ set(TESTS
testqgsvectorlayerjoinbuffer.cpp
testqgsvectorlayerutils.cpp
testqgsvectortilelayer.cpp
testqgsvectortileutils.cpp
testqgsvectortilewriter.cpp
testqgstiles.cpp
testqgsweakrelation.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 601e2ca

Please sign in to comment.