Skip to content

Commit

Permalink
Fix and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed May 15, 2020
1 parent d10b2e8 commit 4a78523
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion tests/src/core/testqgstemporalnavigationobject.cpp
Expand Up @@ -41,6 +41,7 @@ class TestQgsTemporalNavigationObject : public QObject
void animationState();
void temporalExtents();
void frameSettings();
void navigationMode();
void expressionContext();

private:
Expand All @@ -65,6 +66,7 @@ void TestQgsTemporalNavigationObject::init()
//create a temporal object that will be used in all tests...

navigationObject = new QgsTemporalNavigationObject();
navigationObject->setNavigationMode( QgsTemporalNavigationObject::Animated );
}

void TestQgsTemporalNavigationObject::cleanup()
Expand Down Expand Up @@ -138,6 +140,41 @@ void TestQgsTemporalNavigationObject::temporalExtents()
QCOMPARE( navigationObject->temporalExtents(), QgsDateTimeRange() );
}

void TestQgsTemporalNavigationObject::navigationMode()
{
QgsDateTimeRange range = QgsDateTimeRange(
QDateTime( QDate( 2010, 1, 1 ) ),
QDateTime( QDate( 2020, 1, 1 ) ) );

QgsDateTimeRange range2 = QgsDateTimeRange(
QDateTime( QDate( 2015, 1, 1 ) ),
QDateTime( QDate( 2020, 1, 1 ) ) );

QgsDateTimeRange check;
auto checkUpdateTemporalRange = [&check]( const QgsDateTimeRange range )
{
QCOMPARE( range, check );
};
QObject *context = new QObject( this );
connect( navigationObject, &QgsTemporalNavigationObject::updateTemporalRange, context, checkUpdateTemporalRange );

// Changing navigation mode emits an updateTemporalRange, in this case it should be an empty range
navigationObject->setNavigationMode( QgsTemporalNavigationObject::NavigationOff );
// Setting temporal extents also triggers an updateTemporalRange with an empty range
navigationObject->setTemporalExtents( range );

// Changing navigation mode emits an updateTemporalRange, in this case it should be the last range
// we used in setTemporalExtents.
check = range;
navigationObject->setNavigationMode( QgsTemporalNavigationObject::FixedRange );
check = range2;
navigationObject->setTemporalExtents( range2 );

// Delete context to disconnect the signal to the lambda function
delete context;
navigationObject->setNavigationMode( QgsTemporalNavigationObject::Animated );
}

void TestQgsTemporalNavigationObject::frameSettings()
{
qRegisterMetaType<QgsDateTimeRange>( "QgsDateTimeRange" );
Expand Down Expand Up @@ -175,7 +212,6 @@ void TestQgsTemporalNavigationObject::frameSettings()

navigationObject->setTemporalRangeCumulative( true );
QCOMPARE( navigationObject->dateTimeRangeForFrameNumber( 4 ), range );

}

void TestQgsTemporalNavigationObject::expressionContext()
Expand Down

0 comments on commit 4a78523

Please sign in to comment.