Skip to content

Commit

Permalink
check interval type
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Jun 30, 2012
1 parent c467e79 commit 778f20b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/core/qgsexpression.h
Expand Up @@ -261,12 +261,12 @@ class CORE_EXPORT QgsExpression
{
// YEAR const value taken from postgres query
// SELECT EXTRACT(EPOCH FROM interval '1 year')
static const double YEARS = ( 31557600 );
static const double MONTHS = ( 60 * 60 * 24 * 30 );
static const double WEEKS = ( 60 * 60 * 24 * 7 );
static const double DAY = ( 60 * 60 * 24 );
static const double HOUR = ( 60 * 60 );
static const double MINUTE = ( 60 );
static const double YEARS = 31557600;
static const double MONTHS = 60 * 60 * 24 * 30;
static const double WEEKS = 60 * 60 * 24 * 7;
static const double DAY = 60 * 60 * 24;
static const double HOUR = 60 * 60;
static const double MINUTE = 60;
public:
Interval( double seconds = 0 ) { mSeconds = seconds; }
~Interval();
Expand Down
18 changes: 13 additions & 5 deletions tests/src/core/testqgsexpression.cpp
Expand Up @@ -272,7 +272,7 @@ class TestQgsExpression: public QObject
QTest::newRow( "condition 2 when" ) << "case when 2>3 then 23 when 3>2 then 32 else 0 end" << false << QVariant( 32 );

// Datetime functions
QTest::newRow( "to date" ) << "todate('2012-06-28')" << false << QVariant( QDate( 2012, 06, 28 ) );
QTest::newRow( "to date" ) << "todate('2012-06-28')" << false << QVariant( QDate( 2012, 6, 28 ) );
QTest::newRow( "to interval" ) << "tointerval('1 Year 1 Month 1 Week 1 Hour 1 Minute')" << false << QVariant::fromValue( QgsExpression::Interval( 34758060 ) );
QTest::newRow( "day with date" ) << "day('2012-06-28')" << false << QVariant( 28 );
QTest::newRow( "day with interval" ) << "day(tointerval('28 days'))" << false << QVariant( 28.0 );
Expand Down Expand Up @@ -309,7 +309,8 @@ class TestQgsExpression: public QObject
QCOMPARE( res.type(), result.type() );
switch ( res.type() )
{
case QVariant::Invalid: break; // nothing more to check
case QVariant::Invalid:
break; // nothing more to check
case QVariant::Int:
QCOMPARE( res.toInt(), result.toInt() );
break;
Expand All @@ -330,9 +331,16 @@ class TestQgsExpression: public QObject
break;
case QVariant::UserType:
{
QgsExpression::Interval inter = res.value<QgsExpression::Interval>();
QgsExpression::Interval gotinter = result.value<QgsExpression::Interval>();
QCOMPARE( inter.seconds(), gotinter.seconds() );
if ( res.userType() == qMetaTypeId<QgsExpression::Interval>() )
{
QgsExpression::Interval inter = res.value<QgsExpression::Interval>();
QgsExpression::Interval gotinter = result.value<QgsExpression::Interval>();
QCOMPARE( inter.seconds(), gotinter.seconds() );
}
else
{
QFAIL( "unexpected user type" );
}
break;
}
default:
Expand Down

0 comments on commit 778f20b

Please sign in to comment.