Skip to content

Commit f3e3e0d

Browse files
committedOct 21, 2023
Add test for QgsVirtualLayerProvider
1 parent ec90b80 commit f3e3e0d

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed
 

‎tests/src/providers/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ include_directories(
1212
${CMAKE_SOURCE_DIR}/src/providers/mssql
1313
${CMAKE_SOURCE_DIR}/src/providers/ogr
1414
${CMAKE_SOURCE_DIR}/src/providers/virtualraster
15+
${CMAKE_SOURCE_DIR}/src/providers/virtual
1516
${CMAKE_SOURCE_DIR}/src/test
1617
)
1718
include_directories(SYSTEM
@@ -35,6 +36,7 @@ set_target_properties(test_provider_wcsprovider PROPERTIES
3536
add_qgis_test(testqgswmscapabilities.cpp MODULE provider LINKEDLIBRARIES provider_wms_a qgis_core)
3637
add_qgis_test(testqgswmsccapabilities.cpp MODULE provider LINKEDLIBRARIES provider_wms_a qgis_core)
3738
add_qgis_test(testqgswmsprovider.cpp MODULE provider LINKEDLIBRARIES provider_wms_a qgis_core)
39+
add_qgis_test(testqgsvirtuallayerprovider.cpp MODULE provider LINKEDLIBRARIES provider_virtuallayer_a qgis_core)
3840

3941
if (POSTGRES_FOUND)
4042
add_qgis_test(testqgspostgresexpressioncompiler.cpp MODULE provider LINKEDLIBRARIES provider_postgres_a qgis_core)
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/***************************************************************************
2+
testqgsvirtuallayerprovider.cpp
3+
------------------------------------
4+
Date : October 2023
5+
Copyright : (C) 2023 by Sandro Santilli
6+
Email : strk at kbt dot net
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include <limits>
17+
18+
#include "qgstest.h"
19+
#include <QObject>
20+
#include <QString>
21+
#include <QStringList>
22+
#include <QApplication>
23+
#include <QFileInfo>
24+
#include <QDir>
25+
#include <fstream>
26+
#include <QVector>
27+
#include <QTest>
28+
#include <QStandardPaths>
29+
#include <QQueue>
30+
31+
//qgis includes...
32+
#include "qgis.h"
33+
#include "qgsapplication.h"
34+
//#include "qgsproviderregistry.h"
35+
#include "qgsvirtuallayerprovider.h"
36+
//#include "qgsgeometry.h"
37+
//#include "qgsfeedback.h"
38+
//#include "qgsprovidermetadata.h"
39+
40+
/**
41+
* \ingroup UnitTests
42+
* This is a unit test for the Virtual Layer provider
43+
*/
44+
class TestQgsVirtualLayerProvider : public QgsTest
45+
{
46+
Q_OBJECT
47+
48+
public:
49+
50+
TestQgsVirtualLayerProvider() : QgsTest( QStringLiteral( "Virtual Layer Provider Tests" ) ) {}
51+
52+
private slots:
53+
void initTestCase();// will be called before the first testfunction is executed.
54+
void cleanupTestCase();// will be called after the last testfunction was executed.
55+
void init() {}// will be called before each testfunction is executed.
56+
void cleanup() {}// will be called after every testfunction.
57+
58+
void testConstructor();
59+
60+
private:
61+
QString mTestDataDir;
62+
};
63+
64+
//runs before all tests
65+
void TestQgsVirtualLayerProvider::initTestCase()
66+
{
67+
// init QGIS's paths - true means that all path will be inited from prefix
68+
QgsApplication::init();
69+
QgsApplication::initQgis();
70+
71+
mTestDataDir = QStringLiteral( TEST_DATA_DIR ) + '/'; //defined in CmakeLists.txt
72+
}
73+
74+
//runs after all tests
75+
void TestQgsVirtualLayerProvider::cleanupTestCase()
76+
{
77+
QgsApplication::exitQgis();
78+
}
79+
80+
void TestQgsVirtualLayerProvider::testConstructor()
81+
{
82+
QgsDataProvider::ProviderOptions opts;
83+
QString uri;
84+
std::unique_ptr<QgsVectorDataProvider> prov( new QgsVirtualLayerProvider( uri, opts ) );
85+
86+
const QgsRectangle rectNull = QgsRectangle::createNull();
87+
QCOMPARE( prov->sourceExtent(), rectNull );
88+
}
89+
90+
QGSTEST_MAIN( TestQgsVirtualLayerProvider )
91+
#include "testqgsvirtuallayerprovider.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.