@@ -147,7 +147,7 @@ class TestQgsExpression: public QObject
147
147
af4.setAttribute ( QStringLiteral ( " col3" ), 2 );
148
148
af4.setAttribute ( QStringLiteral ( " col4" ), " " );
149
149
QgsFeature af5 ( mAggregatesLayer ->dataProvider ()->fields (), 5 );
150
- af5.setGeometry ( QgsGeometry::fromPoint ( QgsPoint ( 4 , 0 ) ) );
150
+ af5.setGeometry ( QgsGeometry ( ) );
151
151
af5.setAttribute ( QStringLiteral ( " col1" ), 5 );
152
152
af5.setAttribute ( QStringLiteral ( " col2" ), QVariant ( QVariant::String ) );
153
153
af5.setAttribute ( QStringLiteral ( " col3" ), 3 );
@@ -1327,7 +1327,7 @@ class TestQgsExpression: public QObject
1327
1327
QTest::newRow ( " string aggregate 2" ) << " aggregate('test','min_length',\" col2\" )" << false << QVariant ( 5 );
1328
1328
QTest::newRow ( " string concatenate" ) << " aggregate('test','concatenate',\" col2\" ,concatenator:=' , ')" << false << QVariant ( " test1 , test2 , test3 , test4" );
1329
1329
1330
- QTest::newRow ( " geometry collect" ) << " geom_to_wkt(aggregate('aggregate_layer','collect',$geometry))" << false << QVariant ( QStringLiteral ( " MultiPoint ((0 0),(1 0),(2 0),(3 0),(4 0),( 5 0))" ) );
1330
+ QTest::newRow ( " geometry collect" ) << " geom_to_wkt(aggregate('aggregate_layer','collect',$geometry))" << false << QVariant ( QStringLiteral ( " MultiPoint ((0 0),(1 0),(2 0),(3 0),(5 0))" ) );
1331
1331
1332
1332
QTest::newRow ( " sub expression" ) << " aggregate('test','sum',\" col1\" * 2)" << false << QVariant ( 65 * 2 );
1333
1333
QTest::newRow ( " bad sub expression" ) << " aggregate('test','sum',\" xcvxcv\" * 2)" << true << QVariant ();
@@ -1411,7 +1411,8 @@ class TestQgsExpression: public QObject
1411
1411
QTest::newRow ( " max_length" ) << " max_length(\" col2\" )" << false << QVariant ( 7 );
1412
1412
QTest::newRow ( " concatenate" ) << " concatenate(\" col2\" ,concatenator:=',')" << false << QVariant ( " test,,test333,test4,,test4" );
1413
1413
1414
- QTest::newRow ( " geometry collect" ) << " geom_to_wkt(collect($geometry))" << false << QVariant ( QStringLiteral ( " MultiPoint ((0 0),(1 0),(2 0),(3 0),(4 0),(5 0))" ) );
1414
+ QTest::newRow ( " geometry collect" ) << " geom_to_wkt(collect($geometry))" << false << QVariant ( QStringLiteral ( " MultiPoint ((0 0),(1 0),(2 0),(3 0),(5 0))" ) );
1415
+ QTest::newRow ( " geometry collect with null geometry first" ) << " geom_to_wkt(collect($geometry, filter:=\" col3\" =3))" << false << QVariant ( QStringLiteral ( " MultiPoint ((5 0))" ) );
1415
1416
1416
1417
QTest::newRow ( " bad expression" ) << " sum(\" xcvxcvcol1\" )" << true << QVariant ();
1417
1418
QTest::newRow ( " aggregate named" ) << " sum(expression:=\" col1\" )" << false << QVariant ( 24.0 );
@@ -1707,24 +1708,25 @@ class TestQgsExpression: public QObject
1707
1708
QTest::addColumn<QString>( " string" );
1708
1709
QTest::addColumn<QgsGeometry>( " geom" );
1709
1710
QTest::addColumn<bool >( " evalError" );
1710
- QTest::addColumn<double >( " result" );
1711
+ QTest::addColumn<QVariant >( " result" );
1711
1712
1712
1713
QgsPoint point ( 123 , 456 );
1713
1714
QgsPolyline line;
1714
1715
line << QgsPoint ( 1 , 1 ) << QgsPoint ( 4 , 2 ) << QgsPoint ( 3 , 1 );
1715
1716
1716
- QTest::newRow ( " geom x" ) << " $x" << QgsGeometry::fromPoint ( point ) << false << 123 .;
1717
- QTest::newRow ( " geom y" ) << " $y" << QgsGeometry::fromPoint ( point ) << false << 456 .;
1718
- QTest::newRow ( " geom xat" ) << " xat(-1)" << QgsGeometry::fromPolyline ( line ) << false << 3 .;
1719
- QTest::newRow ( " geom yat" ) << " yat(1)" << QgsGeometry::fromPolyline ( line ) << false << 2 .;
1717
+ QTest::newRow ( " geom x" ) << " $x" << QgsGeometry::fromPoint ( point ) << false << QVariant ( 123 . );
1718
+ QTest::newRow ( " geom y" ) << " $y" << QgsGeometry::fromPoint ( point ) << false << QVariant ( 456 . );
1719
+ QTest::newRow ( " geom xat" ) << " xat(-1)" << QgsGeometry::fromPolyline ( line ) << false << QVariant ( 3 . );
1720
+ QTest::newRow ( " geom yat" ) << " yat(1)" << QgsGeometry::fromPolyline ( line ) << false << QVariant ( 2 . );
1721
+ QTest::newRow ( " null geometry" ) << " $geometry" << QgsGeometry () << false << QVariant ( QVariant::UserType );
1720
1722
}
1721
1723
1722
1724
void eval_geometry ()
1723
1725
{
1724
1726
QFETCH ( QString, string );
1725
1727
QFETCH ( QgsGeometry, geom );
1726
1728
QFETCH ( bool , evalError );
1727
- QFETCH ( double , result );
1729
+ QFETCH ( QVariant , result );
1728
1730
1729
1731
QgsFeature f;
1730
1732
f.setGeometry ( geom );
@@ -1736,7 +1738,7 @@ class TestQgsExpression: public QObject
1736
1738
QgsExpressionContext context = QgsExpressionContextUtils::createFeatureBasedContext ( f, QgsFields () );
1737
1739
QVariant out = exp .evaluate ( &context );
1738
1740
QCOMPARE ( exp .hasEvalError (), evalError );
1739
- QCOMPARE ( out. toDouble () , result );
1741
+ QCOMPARE ( out, result );
1740
1742
}
1741
1743
1742
1744
void eval_geometry_calc ()
0 commit comments