Skip to content

Commit

Permalink
Add test for QgsVirtualLayerProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
strk committed Oct 21, 2023
1 parent ec90b80 commit f3e3e0d
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/src/providers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ include_directories(
${CMAKE_SOURCE_DIR}/src/providers/mssql
${CMAKE_SOURCE_DIR}/src/providers/ogr
${CMAKE_SOURCE_DIR}/src/providers/virtualraster
${CMAKE_SOURCE_DIR}/src/providers/virtual
${CMAKE_SOURCE_DIR}/src/test
)
include_directories(SYSTEM
Expand All @@ -35,6 +36,7 @@ set_target_properties(test_provider_wcsprovider PROPERTIES
add_qgis_test(testqgswmscapabilities.cpp MODULE provider LINKEDLIBRARIES provider_wms_a qgis_core)
add_qgis_test(testqgswmsccapabilities.cpp MODULE provider LINKEDLIBRARIES provider_wms_a qgis_core)
add_qgis_test(testqgswmsprovider.cpp MODULE provider LINKEDLIBRARIES provider_wms_a qgis_core)
add_qgis_test(testqgsvirtuallayerprovider.cpp MODULE provider LINKEDLIBRARIES provider_virtuallayer_a qgis_core)

if (POSTGRES_FOUND)
add_qgis_test(testqgspostgresexpressioncompiler.cpp MODULE provider LINKEDLIBRARIES provider_postgres_a qgis_core)
Expand Down
91 changes: 91 additions & 0 deletions tests/src/providers/testqgsvirtuallayerprovider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/***************************************************************************
testqgsvirtuallayerprovider.cpp
------------------------------------
Date : October 2023
Copyright : (C) 2023 by Sandro Santilli
Email : strk at kbt dot net
***************************************************************************
* *
* 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 <limits>

#include "qgstest.h"
#include <QObject>
#include <QString>
#include <QStringList>
#include <QApplication>
#include <QFileInfo>
#include <QDir>
#include <fstream>
#include <QVector>
#include <QTest>
#include <QStandardPaths>
#include <QQueue>

//qgis includes...
#include "qgis.h"
#include "qgsapplication.h"
//#include "qgsproviderregistry.h"
#include "qgsvirtuallayerprovider.h"
//#include "qgsgeometry.h"
//#include "qgsfeedback.h"
//#include "qgsprovidermetadata.h"

/**
* \ingroup UnitTests
* This is a unit test for the Virtual Layer provider
*/
class TestQgsVirtualLayerProvider : public QgsTest
{
Q_OBJECT

public:

TestQgsVirtualLayerProvider() : QgsTest( QStringLiteral( "Virtual Layer Provider Tests" ) ) {}

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 testConstructor();

private:
QString mTestDataDir;
};

//runs before all tests
void TestQgsVirtualLayerProvider::initTestCase()
{
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::init();
QgsApplication::initQgis();

mTestDataDir = QStringLiteral( TEST_DATA_DIR ) + '/'; //defined in CmakeLists.txt
}

//runs after all tests
void TestQgsVirtualLayerProvider::cleanupTestCase()
{
QgsApplication::exitQgis();
}

void TestQgsVirtualLayerProvider::testConstructor()
{
QgsDataProvider::ProviderOptions opts;
QString uri;
std::unique_ptr<QgsVectorDataProvider> prov( new QgsVirtualLayerProvider( uri, opts ) );

const QgsRectangle rectNull = QgsRectangle::createNull();
QCOMPARE( prov->sourceExtent(), rectNull );
}

QGSTEST_MAIN( TestQgsVirtualLayerProvider )
#include "testqgsvirtuallayerprovider.moc"

0 comments on commit f3e3e0d

Please sign in to comment.