Skip to content
Permalink
Browse files

Implement QgsProviderMetadata::filters() for EPT provider, start some

basic tests for ept provider
  • Loading branch information
nyalldawson committed Nov 4, 2020
1 parent f7b0a2d commit 8ebab9444d730174ec9c61e3f242391b559ffec3
@@ -98,6 +98,22 @@ QVariantMap QgsEptProviderMetadata::decodeUri( const QString &uri )
return uriComponents;
}

QString QgsEptProviderMetadata::filters( QgsProviderMetadata::FilterType type )
{
switch ( type )
{
case QgsProviderMetadata::FilterType::FilterVector:
case QgsProviderMetadata::FilterType::FilterRaster:
case QgsProviderMetadata::FilterType::FilterMesh:
case QgsProviderMetadata::FilterType::FilterMeshDataset:
return QString();

case QgsProviderMetadata::FilterType::FilterPointCloud:
return QObject::tr( "Entwine Point Clouds" ) + QStringLiteral( " (ept.json EPT.JSON)" );
}
return QString();
}

QString QgsEptProviderMetadata::encodeUri( const QVariantMap &parts )
{
const QString path = parts.value( QStringLiteral( "path" ) ).toString();
@@ -65,6 +65,7 @@ class QgsEptProviderMetadata : public QgsProviderMetadata
QList< QgsDataItemProvider * > dataItemProviders() const override;
QString encodeUri( const QVariantMap &parts ) override;
QVariantMap decodeUri( const QString &uri ) override;
QString filters( FilterType type ) override;
};

///@endcond
@@ -13,6 +13,8 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src/core/mesh
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/core/pal
${CMAKE_SOURCE_DIR}/src/core/pointcloud
${CMAKE_SOURCE_DIR}/src/core/providers/ept
${CMAKE_SOURCE_DIR}/src/core/raster
${CMAKE_SOURCE_DIR}/src/core/symbology
${CMAKE_SOURCE_DIR}/src/core/effects
@@ -22,6 +24,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src/providers/arcgisrest
${CMAKE_SOURCE_DIR}/src/providers/mdal
${CMAKE_SOURCE_DIR}/src/providers/ogr
${CMAKE_SOURCE_DIR}/src/providers/ept
${CMAKE_SOURCE_DIR}/src/test
${CMAKE_SOURCE_DIR}/external
${CMAKE_SOURCE_DIR}/external/nlohmann
@@ -103,6 +106,7 @@ ADD_QGIS_TEST(postgresconntest testqgspostgresconn.cpp)
TARGET_LINK_LIBRARIES(qgis_postgresconntest postgresprovider_a qgis_core)

IF (NOT FORCE_STATIC_PROVIDERS)
ADD_QGIS_TEST(eptprovidertest testqgseptprovider.cpp)
ADD_QGIS_TEST(mdalprovidertest testqgsmdalprovider.cpp)
ENDIF (NOT FORCE_STATIC_PROVIDERS)

@@ -0,0 +1,89 @@
/***************************************************************************
testqgseptprovider.cpp
--------------------------------------
Date : November 2020
Copyright : (C) 2020 by Nyall Dawson
Email : nyall dot dawson 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 <limits>

#include "qgstest.h"
#include <QObject>
#include <QString>
#include <QStringList>
#include <QApplication>
#include <QFileInfo>
#include <QDir>

//qgis includes...
#include "qgis.h"
#include "qgsapplication.h"
#include "qgsproviderregistry.h"
#include "qgseptprovider.h"

/**
* \ingroup UnitTests
* This is a unit test for the EPT provider
*/
class TestQgsEptProvider : public QObject
{
Q_OBJECT

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

private:
QString mTestDataDir;
QString mReport;
};

//runs before all tests
void TestQgsEptProvider::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
mReport = QStringLiteral( "<h1>EPT Provider Tests</h1>\n" );
}

//runs after all tests
void TestQgsEptProvider::cleanupTestCase()
{
QgsApplication::exitQgis();
QString myReportFile = QDir::tempPath() + "/qgistest.html";
QFile myFile( myReportFile );
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
{
QTextStream myQTextStream( &myFile );
myQTextStream << mReport;
myFile.close();
}
}

void TestQgsEptProvider::filters()
{
QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata( QStringLiteral( "ept" ) );
QVERIFY( metadata );

QCOMPARE( metadata->filters( QgsProviderMetadata::FilterType::FilterPointCloud ), QStringLiteral( "Entwine Point Clouds (ept.json EPT.JSON)" ) );
QCOMPARE( metadata->filters( QgsProviderMetadata::FilterType::FilterVector ), QString() );
}


QGSTEST_MAIN( TestQgsEptProvider )
#include "testqgseptprovider.moc"

0 comments on commit 8ebab94

Please sign in to comment.
You can’t perform that action at this time.