From 4d8243bf6e17f306e88cd9469abca078e7115299 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Fri, 20 Oct 2023 09:24:26 +0200 Subject: [PATCH] Add test for QgsVirtualLayerProvider --- tests/src/providers/CMakeLists.txt | 2 + .../providers/testqgsvirtuallayerprovider.cpp | 91 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 tests/src/providers/testqgsvirtuallayerprovider.cpp diff --git a/tests/src/providers/CMakeLists.txt b/tests/src/providers/CMakeLists.txt index b2a9be5a78b9..3504e817ac3f 100644 --- a/tests/src/providers/CMakeLists.txt +++ b/tests/src/providers/CMakeLists.txt @@ -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 @@ -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) diff --git a/tests/src/providers/testqgsvirtuallayerprovider.cpp b/tests/src/providers/testqgsvirtuallayerprovider.cpp new file mode 100644 index 000000000000..5471e39b83a0 --- /dev/null +++ b/tests/src/providers/testqgsvirtuallayerprovider.cpp @@ -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 + +#include "qgstest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//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 prov( new QgsVirtualLayerProvider( uri, opts ) ); + + const QgsRectangle rectNull = QgsRectangle::createNull(); + QCOMPARE( prov->sourceExtent(), rectNull ); +} + +QGSTEST_MAIN( TestQgsVirtualLayerProvider ) +#include "testqgsvirtuallayerprovider.moc"