Skip to content
Permalink
Browse files

added tests for the wmst match mode logic

  • Loading branch information
Samweli authored and nyalldawson committed Apr 13, 2020
1 parent df335f2 commit c70c33e2cdc63d4680c523f881604fee971088e6
@@ -279,38 +279,14 @@ QgsWmstDimensionExtent QgsWmsSettings::parseTemporalExtent( QString extent )
return dimensionExtent;
}

QList<QDateTime> QgsWmsSettings::dateTimesFromExtent( QgsWmstDimensionExtent dimensionExtent )
void QgsWmsSettings::setTimeDimensionExtent( QgsWmstDimensionExtent timeDimensionExtent )
{
QList<QDateTime> dates;

for ( QgsWmstExtentPair pair : dimensionExtent.datesResolutionList )
{
if ( !pair.dates.dateTimes.isEmpty() )
{
if ( pair.dates.dateTimes.size() < 2 )
dates.append( pair.dates.dateTimes.at( 0 ) );
else
{
QDateTime first = QDateTime( pair.dates.dateTimes.at( 0 ) );
QDateTime last = QDateTime( pair.dates.dateTimes.at( 1 ) );
dates.append( first );

while ( first < last )
{
if ( pair.resolution.active() )
first = addTime( first, pair.resolution );
else
break;

if ( first <= last )
dates.append( first );
}
}
}
}

return dates;
mTimeDimensionExtent = timeDimensionExtent;
}

QgsWmstDimensionExtent QgsWmsSettings::timeDimensionExtent() const
{
return mTimeDimensionExtent;
}

QDateTime QgsWmsSettings::addTime( QDateTime dateTime, QgsWmstResolution resolution )
@@ -788,6 +788,22 @@ class QgsWmsSettings
*/
QgsWmstDimensionExtent parseTemporalExtent( QString extent );

/**
* Sets the dimension extent property
*
* \see timeDimensionExtent()
* \since 3.14
*/
void setTimeDimensionExtent( QgsWmstDimensionExtent timeDimensionExtent );

/**
* Returns the dimension extent property.
*
* \see setTimeDimensionExtent()
* \since 3.14
*/
QgsWmstDimensionExtent timeDimensionExtent() const;

/**
* Parse the given string item into a resolution structure.
*
@@ -802,8 +818,11 @@ class QgsWmsSettings
*/
QDateTime parseWmstDateTimes( QString item );

QList<QDateTime> dateTimesFromExtent( QgsWmstDimensionExtent dimensionExtent );

/**
* Returns the datetime with the sum of passed \a dateTime and the \a resolution time.
*
* \since 3.14
*/
QDateTime addTime( QDateTime dateTime, QgsWmstResolution resolution );

/**
@@ -812,6 +831,7 @@ class QgsWmsSettings
*
* \note It works with wms-t capabilities that provide time dimension with temporal ranges only.
*
* \since 3.14
*/
QDateTime findLeastClosestDateTime( QDateTime dateTime, bool dateOnly = false ) const;

@@ -106,6 +106,54 @@ class TestQgsWmsCapabilities: public QObject
QgsWmstResolution resolution = settings.parseWmstResolution( resolutionText );
QCOMPARE( resolution.text(), resolutionText );
}

QgsWmstDimensionExtent extent = settings.parseTemporalExtent( QStringLiteral( "2020-01-02T00:00:00.000Z/2020-01-09T00:00:00.000Z/P1D" ) );
settings.setTimeDimensionExtent( extent );

QDateTime start = QDateTime( QDate( 2020, 1, 2 ), QTime( 0, 0, 0 ), Qt::UTC );
QDateTime end = QDateTime( QDate( 2020, 1, 9 ), QTime( 0, 0, 0 ), Qt::UTC );

QgsWmstResolution res;
res.day = 1;
QgsWmstResolution extentResolution = extent.datesResolutionList.at( 0 ).resolution;

QCOMPARE( extent.datesResolutionList.at( 0 ).dates.dateTimes.at( 0 ), start );
QCOMPARE( extent.datesResolutionList.at( 0 ).dates.dateTimes.at( 1 ), end );

QCOMPARE( extentResolution.text(), res.text() );

QDateTime firstClosest = settings.findLeastClosestDateTime( QDateTime( QDate( 2020, 1, 3 ), QTime( 16, 0, 0 ), Qt::UTC ) );
QDateTime firstExpected = QDateTime( QDate( 2020, 1, 3 ), QTime( 0, 0, 0 ), Qt::UTC );

QCOMPARE( firstClosest, firstExpected );

QDateTime secondClosest = settings.findLeastClosestDateTime( QDateTime( QDate( 2020, 1, 3 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QDateTime secondExpected = QDateTime( QDate( 2020, 1, 3 ), QTime( 0, 0, 0 ), Qt::UTC );

QCOMPARE( secondClosest, secondExpected );

QgsWmstDimensionExtent secondExtent = settings.parseTemporalExtent( QStringLiteral( "2020-01-02T00:00:00.000Z/2020-01-04T00:00:00.000Z/PT4H" ) );
settings.setTimeDimensionExtent( secondExtent );

QDateTime thirdClosest = settings.findLeastClosestDateTime( QDateTime( QDate( 2020, 1, 2 ), QTime( 5, 0, 0 ), Qt::UTC ) );
QDateTime thirdExpected = QDateTime( QDate( 2020, 1, 2 ), QTime( 4, 0, 0 ), Qt::UTC );

QCOMPARE( thirdClosest, thirdExpected );

QDateTime fourthClosest = settings.findLeastClosestDateTime( QDateTime( QDate( 2020, 1, 2 ), QTime( 3, 0, 0 ), Qt::UTC ) );
QDateTime fourthExpected = QDateTime( QDate( 2020, 1, 2 ), QTime( 0, 0, 0 ), Qt::UTC );

QCOMPARE( fourthClosest, fourthExpected );

QDateTime fifthClosest = settings.findLeastClosestDateTime( QDateTime( QDate( 2020, 1, 4 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QDateTime fifthExpected = QDateTime( QDate( 2020, 1, 4 ), QTime( 0, 0, 0 ), Qt::UTC );

QCOMPARE( fifthClosest, fifthExpected );

QDateTime outOfBoundsClosest = settings.findLeastClosestDateTime( QDateTime( QDate( 2020, 1, 5 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QDateTime outofBoundsExpected = QDateTime( QDate( 2020, 1, 5 ), QTime( 0, 0, 0 ), Qt::UTC );

QCOMPARE( outOfBoundsClosest, outofBoundsExpected );
}

};

0 comments on commit c70c33e

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