Skip to content
Permalink
Browse files

Add test units for special columns in QgsExpression

  • Loading branch information
Hugo Mercier
Hugo Mercier committed Sep 26, 2012
1 parent 9a671f9 commit 17b6f04455ff596564b5bc692d273579dd896af7
Showing with 27 additions and 0 deletions.
  1. +27 −0 tests/src/core/testqgsexpression.cpp
@@ -541,6 +541,33 @@ class TestQgsExpression: public QObject
QVariant vPerimeter = exp3.evaluate( &fPolygon );
QCOMPARE( vPerimeter.toDouble(), 20. );
}

void eval_special_columns()
{
QTest::addColumn<QString>( "string" );
QTest::addColumn<QVariant>( "result" );

QgsExpression::setSpecialColumn( "$var1", QVariant((int)42) );

QgsExpression exp( "$var1 + 1" );
QVariant v1 = exp.evaluate();
QCOMPARE( v1.toInt(), 43 );

QgsExpression::setSpecialColumn( "$var1", QVariant((int)100) );
QVariant v2 = exp.evaluate();
QCOMPARE( v2.toInt(), 101 );

QgsExpression exp2( "_specialcol_('$var1')+1" );
QVariant v3 = exp2.evaluate();
QCOMPARE( v3.toInt(), 101 );

QgsExpression exp3( "_specialcol_('undefined')");
QVariant v4 = exp3.evaluate();
QCOMPARE( v4, QVariant() );

QgsExpression::unsetSpecialColumn( "$var1" );
}

};

QTEST_MAIN( TestQgsExpression )

0 comments on commit 17b6f04

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