Skip to content
Permalink
Browse files

check interval type

  • Loading branch information
jef-n committed Jun 30, 2012
1 parent c467e79 commit 778f20beb93810c01936d690062b8d4b94120b58
Showing with 19 additions and 11 deletions.
  1. +6 −6 src/core/qgsexpression.h
  2. +13 −5 tests/src/core/testqgsexpression.cpp
@@ -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();
@@ -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 );
@@ -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;
@@ -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:

0 comments on commit 778f20b

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