@@ -120,38 +120,44 @@ class TestQgsExpression: public QObject
120
120
QgsProject::instance ()->addMapLayer ( mMemoryLayer );
121
121
122
122
// test layer for aggregates
123
- mAggregatesLayer = new QgsVectorLayer ( QStringLiteral ( " Point?field=col1:integer&field=col2:string&field=col3:integer" ), QStringLiteral ( " aggregate_layer" ), QStringLiteral ( " memory" ) );
123
+ mAggregatesLayer = new QgsVectorLayer ( QStringLiteral ( " Point?field=col1:integer&field=col2:string&field=col3:integer&field=col4:string " ), QStringLiteral ( " aggregate_layer" ), QStringLiteral ( " memory" ) );
124
124
QVERIFY ( mAggregatesLayer ->isValid () );
125
125
QgsFeature af1 ( mAggregatesLayer ->dataProvider ()->fields (), 1 );
126
126
af1.setGeometry ( QgsGeometry::fromPoint ( QgsPoint ( 0 , 0 ) ) );
127
127
af1.setAttribute ( QStringLiteral ( " col1" ), 4 );
128
128
af1.setAttribute ( QStringLiteral ( " col2" ), " test" );
129
129
af1.setAttribute ( QStringLiteral ( " col3" ), 2 );
130
+ af1.setAttribute ( QStringLiteral ( " col4" ), QVariant ( QVariant::String ) );
130
131
QgsFeature af2 ( mAggregatesLayer ->dataProvider ()->fields (), 2 );
131
132
af2.setGeometry ( QgsGeometry::fromPoint ( QgsPoint ( 1 , 0 ) ) );
132
133
af2.setAttribute ( QStringLiteral ( " col1" ), 2 );
133
134
af2.setAttribute ( QStringLiteral ( " col2" ), QVariant ( QVariant::String ) );
134
135
af2.setAttribute ( QStringLiteral ( " col3" ), 1 );
136
+ af2.setAttribute ( QStringLiteral ( " col4" ), QVariant ( QVariant::String ) );
135
137
QgsFeature af3 ( mAggregatesLayer ->dataProvider ()->fields (), 3 );
136
138
af3.setGeometry ( QgsGeometry::fromPoint ( QgsPoint ( 2 , 0 ) ) );
137
139
af3.setAttribute ( QStringLiteral ( " col1" ), 3 );
138
140
af3.setAttribute ( QStringLiteral ( " col2" ), " test333" );
139
141
af3.setAttribute ( QStringLiteral ( " col3" ), 2 );
142
+ af3.setAttribute ( QStringLiteral ( " col4" ), QVariant ( QVariant::String ) );
140
143
QgsFeature af4 ( mAggregatesLayer ->dataProvider ()->fields (), 4 );
141
144
af4.setGeometry ( QgsGeometry::fromPoint ( QgsPoint ( 3 , 0 ) ) );
142
145
af4.setAttribute ( QStringLiteral ( " col1" ), 2 );
143
146
af4.setAttribute ( QStringLiteral ( " col2" ), " test4" );
144
147
af4.setAttribute ( QStringLiteral ( " col3" ), 2 );
148
+ af4.setAttribute ( QStringLiteral ( " col4" ), " " );
145
149
QgsFeature af5 ( mAggregatesLayer ->dataProvider ()->fields (), 5 );
146
150
af5.setGeometry ( QgsGeometry::fromPoint ( QgsPoint ( 4 , 0 ) ) );
147
151
af5.setAttribute ( QStringLiteral ( " col1" ), 5 );
148
152
af5.setAttribute ( QStringLiteral ( " col2" ), QVariant ( QVariant::String ) );
149
153
af5.setAttribute ( QStringLiteral ( " col3" ), 3 );
154
+ af5.setAttribute ( QStringLiteral ( " col4" ), " test" );
150
155
QgsFeature af6 ( mAggregatesLayer ->dataProvider ()->fields (), 6 );
151
156
af6.setGeometry ( QgsGeometry::fromPoint ( QgsPoint ( 5 , 0 ) ) );
152
157
af6.setAttribute ( QStringLiteral ( " col1" ), 8 );
153
158
af6.setAttribute ( QStringLiteral ( " col2" ), " test4" );
154
159
af6.setAttribute ( QStringLiteral ( " col3" ), 3 );
160
+ af6.setAttribute ( QStringLiteral ( " col4" ), " test" );
155
161
mAggregatesLayer ->dataProvider ()->addFeatures ( QgsFeatureList () << af1 << af2 << af3 << af4 << af5 << af6 );
156
162
QgsProject::instance ()->addMapLayer ( mAggregatesLayer );
157
163
@@ -1417,12 +1423,13 @@ class TestQgsExpression: public QObject
1417
1423
QTest::newRow ( " filter" ) << " sum(\" col1\" , NULL, \" col1\" >= 5)" << false << QVariant ( 13 );
1418
1424
QTest::newRow ( " filter named" ) << " sum(expression:=\" col1\" , filter:=\" col1\" >= 5)" << false << QVariant ( 13 );
1419
1425
QTest::newRow ( " filter no matching" ) << " sum(expression:=\" col1\" , filter:=\" col1\" <= -5)" << false << QVariant ( 0 );
1420
- QTest::newRow ( " filter no matching max" ) << " maximum('test', \" xcvxcv \" * 2 )" << false << QVariant ();
1426
+ QTest::newRow ( " filter no matching max" ) << " maximum(\" col1 \" , filter:= \" col1 \" <= -5 )" << false << QVariant ();
1421
1427
1422
1428
QTest::newRow ( " group by" ) << " sum(\" col1\" , \" col3\" )" << false << QVariant ( 9 );
1423
1429
QTest::newRow ( " group by and filter" ) << " sum(\" col1\" , \" col3\" , \" col1\" >=3)" << false << QVariant ( 7 );
1424
1430
QTest::newRow ( " group by and filter named" ) << " sum(expression:=\" col1\" , group_by:=\" col3\" , filter:=\" col1\" >=3)" << false << QVariant ( 7 );
1425
1431
QTest::newRow ( " group by expression" ) << " sum(\" col1\" , \" col1\" % 2)" << false << QVariant ( 16 );
1432
+ QTest::newRow ( " group by with null value" ) << " sum(\" col1\" , \" col4\" )" << false << QVariant ( 9 );
1426
1433
}
1427
1434
1428
1435
void selection ()
@@ -1483,6 +1490,7 @@ class TestQgsExpression: public QObject
1483
1490
af1.setAttribute ( QStringLiteral ( " col1" ), 4 );
1484
1491
af1.setAttribute ( QStringLiteral ( " col2" ), " test" );
1485
1492
af1.setAttribute ( QStringLiteral ( " col3" ), 2 );
1493
+ af1.setAttribute ( QStringLiteral ( " col4" ), QVariant () );
1486
1494
context.setFeature ( af1 );
1487
1495
1488
1496
QFETCH ( QString, string );
0 commit comments