Skip to content

Commit

Permalink
added temporal capabilities tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Samweli authored and nyalldawson committed Mar 5, 2020
1 parent 2517b56 commit c42f162
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 6 deletions.
38 changes: 32 additions & 6 deletions src/providers/wms/qgswmscapabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ QgsDateTimeRange QgsWmsSettings::parseTemporalExtent( QgsWmstDimensionExtent dim
QgsWmstResolution QgsWmsSettings::parseWmstResolution( QString item )
{
QgsWmstResolution resolution;
bool found = false;

for ( char datesSymbol : { 'Y', 'M', 'D' } )
{
Expand All @@ -282,17 +283,32 @@ QgsWmstResolution QgsWmsSettings::parseWmstResolution( QString item )
if ( datesSymbol == 'Y' && item.contains( 'Y' ) )
{
resolution.year = resolutionValue;
item = item.remove( number );
found = true;

}
if ( datesSymbol == 'M' && item.contains( 'M' ) )
{
// Symbol M is used to both represent either month or minutes
// The check below is for determing whether it means month or minutes
if ( item.contains( 'T' ) &&
item.indexOf( 'T' ) < item.indexOf( 'M' ) )
continue;
resolution.month = resolutionValue;
item = item.remove( number );
found = true;
}
if ( datesSymbol == 'D' && item.contains( 'D' ) )
{
resolution.day = resolutionValue;
item = item.remove( number );
found = true;
}

if ( found )
{
int symbolIndex = item.indexOf( datesSymbol );
item.remove( symbolIndex, 1 );
item.remove( symbolIndex - number.length(),
number.length() );
found = false;
}

}
Expand All @@ -301,6 +317,8 @@ QgsWmstResolution QgsWmsSettings::parseWmstResolution( QString item )
else
item.remove( 'T' );

bool foundTime = false;

for ( char timeSymbol : { 'H', 'M', 'S' } )
{
QString number = item.left( item.indexOf( timeSymbol ) );
Expand All @@ -309,19 +327,27 @@ QgsWmstResolution QgsWmsSettings::parseWmstResolution( QString item )
if ( timeSymbol == 'H' && item.contains( 'H' ) )
{
resolution.hour = resolutionValue;
item = item.remove( number );
foundTime = true;
}
if ( timeSymbol == 'M' && item.contains( 'M' ) )
{
resolution.minutes = resolutionValue;
item = item.remove( number );
foundTime = true;
}
if ( timeSymbol == 'S' && item.contains( 'S' ) )
{
resolution.seconds = resolutionValue;
item = item.remove( number );
foundTime = true;
}

if ( foundTime )
{
int symbolIndex = item.indexOf( timeSymbol );
item.remove( symbolIndex, 1 );
item.remove( symbolIndex - number.length(),
number.length() );
foundTime = false;
}
}
return resolution;
}
Expand Down
71 changes: 71 additions & 0 deletions src/providers/wms/qgswmscapabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,20 @@ struct QgsWmsLayerProperty
*/
struct QgsWmstDates
{
QgsWmstDates( QList< QDateTime > dates )
{
dateTimes = dates;
}
QgsWmstDates()
{

}

bool operator== ( const QgsWmstDates &other )
{
return dateTimes == other.dateTimes;
}

QList< QDateTime > dateTimes;
};

Expand All @@ -398,6 +412,57 @@ struct QgsWmstResolution
hour != -1 && minutes != -1 && seconds != -1;
}

QString text()
{
QString text( "P" );

if ( year != -1 )
{
text.append( QString::number( year ) );
text.append( 'Y' );
}
if ( month != -1 )
{
text.append( QString::number( month ) );
text.append( 'M' );
}
if ( day != -1 )
{
text.append( QString::number( day ) );
text.append( 'D' );
}

if ( hour != -1 )
{
if ( !text.contains( 'T' ) )
text.append( 'T' );
text.append( QString::number( hour ) );
text.append( 'H' );
}
if ( minutes != -1 )
{
if ( !text.contains( 'T' ) )
text.append( 'T' );
text.append( QString::number( minutes ) );
text.append( 'M' );
}
if ( seconds != -1 )
{
if ( !text.contains( 'T' ) )
text.append( 'T' );
text.append( QString::number( seconds ) );
text.append( 'S' );
}
return text;
}

bool operator== ( const QgsWmstResolution &other )
{
return year == other.year && month == other.month &&
day == other.day && hour == other.hour &&
minutes == other.minutes && seconds == other.seconds;
}

};


Expand All @@ -416,6 +481,12 @@ struct QgsWmstExtentPair
resolution = otherResolution;
}

bool operator ==( const QgsWmstExtentPair &other )
{
return dates == other.dates &&
resolution == other.resolution;
}

QgsWmstDates dates;
QgsWmstResolution resolution;
};
Expand Down
1 change: 1 addition & 0 deletions tests/src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ SET(TESTS
testqgsrastermarker.cpp
testqgsrasteriterator.cpp
testqgsrasterblock.cpp
testqgsrasterdataprovidertemporalcapabilities.cpp
testqgsrasterlayer.cpp
testqgsrasterlayertemporalproperties.cpp
testqgsrastersublayer.cpp
Expand Down
113 changes: 113 additions & 0 deletions tests/src/core/testqgsrasterdataprovidertemporalcapabilities.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/***************************************************************************
testqgsrasterdataprovidertemporalcapabilities.cpp
---------------
begin : February 2020
copyright : (C) 2020 by Samweli Mwakisambwe
email : samweli at kartoza 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>

//qgis includes...
#include <qgsrasterdataprovidertemporalcapabilities.h>

/**
* \ingroup UnitTests
* This is a unit test for the QgsRasterDataProviderTemporalCapabilities class.
*/
class TestQgsRasterDataProviderTemporalCapabilities : public QObject
{
Q_OBJECT

public:
TestQgsRasterDataProviderTemporalCapabilities() = default;

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 checkActiveStatus();
void checkTemporalRange();
void checkReferenceTemporalRange();

private:
QgsRasterDataProviderTemporalCapabilities *temporalCapabilities = nullptr;
};

void TestQgsRasterDataProviderTemporalCapabilities::initTestCase()
{
//
// Runs once before any tests are run
//
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::init();
QgsApplication::initQgis();
QgsApplication::showSettings();

}

void TestQgsRasterDataProviderTemporalCapabilities::init()
{
//create some objects that will be used in all tests...
//create a temporal object that will be used in all tests...

temporalCapabilities = new QgsRasterDataProviderTemporalCapabilities( true );
}

void TestQgsRasterDataProviderTemporalCapabilities::cleanup()
{
}

void TestQgsRasterDataProviderTemporalCapabilities::cleanupTestCase()
{
QgsApplication::exitQgis();
}

void TestQgsRasterDataProviderTemporalCapabilities::checkActiveStatus()
{
temporalCapabilities->setIsActive( false );
QCOMPARE( temporalCapabilities->isActive(), false );
}

void TestQgsRasterDataProviderTemporalCapabilities::checkTemporalRange()
{
QgsDateTimeRange fixedDateTimeRange = QgsDateTimeRange( QDateTime( QDate( 2020, 1, 1 ) ),
QDateTime( QDate( 2020, 12, 31 ) ) );
QgsDateTimeRange dateTimeRange = QgsDateTimeRange( QDateTime( QDate( 2020, 1, 1 ) ),
QDateTime( QDate( 2020, 3, 1 ) ) );

temporalCapabilities->setTemporalRange( dateTimeRange );
temporalCapabilities->setFixedTemporalRange( fixedDateTimeRange );

QCOMPARE( temporalCapabilities->temporalRange(), dateTimeRange );
QCOMPARE( temporalCapabilities->fixedTemporalRange(), fixedDateTimeRange );
}

void TestQgsRasterDataProviderTemporalCapabilities::checkReferenceTemporalRange()
{
QgsDateTimeRange fixedDateTimeRange = QgsDateTimeRange( QDateTime( QDate( 2020, 1, 1 ) ),
QDateTime( QDate( 2020, 12, 31 ) ) );
QgsDateTimeRange dateTimeRange = QgsDateTimeRange( QDateTime( QDate( 2020, 1, 1 ) ),
QDateTime( QDate( 2020, 3, 1 ) ) );

temporalCapabilities->setReferenceTemporalRange( dateTimeRange );
temporalCapabilities->setFixedReferenceTemporalRange( fixedDateTimeRange );

QCOMPARE( temporalCapabilities->referenceTemporalRange(), dateTimeRange );
QCOMPARE( temporalCapabilities->fixedReferenceTemporalRange(), fixedDateTimeRange );
}

QGSTEST_MAIN( TestQgsRasterDataProviderTemporalCapabilities )
#include "testqgsrasterdataprovidertemporalcapabilities.moc"
29 changes: 29 additions & 0 deletions tests/src/providers/testqgswmscapabilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,35 @@ class TestQgsWmsCapabilities: public QObject
QString( "http://www.example.com/fb.png" ) );
}

void wmstSettings()
{
QgsWmsSettings settings = QgsWmsSettings();

QMap<QString, QString> map = { { "2020-02-13T12:00:00Z", "yyyy-MM-ddThh:mm:ssZ" },
{ "2020-02-13", "yyyy-MM-dd" }
};
QMapIterator<QString, QString> iterator( map );

while ( iterator.hasNext() )
{
iterator.next();
QDateTime date = settings.parseWmstDateTimes( iterator.key() );
QCOMPARE( date.toString( iterator.value() ), iterator.key() );
}

QList<QString> resolutionList =
{
"P1D", "P1Y", "PT5M", "P1DT1H",
"P1Y1DT3S", "P1MT1M", "PT23H3M", "P26DT23H3M", "PT30S"
};

for ( QString resolutionText : resolutionList )
{
QgsWmstResolution resolution = settings.parseWmstResolution( resolutionText );
QCOMPARE( resolution.text(), resolutionText );
}
}

};

QGSTEST_MAIN( TestQgsWmsCapabilities )
Expand Down

0 comments on commit c42f162

Please sign in to comment.