Skip to content

Commit ce0eb2b

Browse files
committedAug 8, 2015
Cleanup QgsVectorLayer tests
1 parent dabe7d3 commit ce0eb2b

File tree

1 file changed

+217
-332
lines changed

1 file changed

+217
-332
lines changed
 

‎tests/src/core/testqgsvectorlayer.cpp

Lines changed: 217 additions & 332 deletions
Original file line numberDiff line numberDiff line change
@@ -91,341 +91,226 @@ class TestQgsVectorLayer : public QObject
9191

9292
private slots:
9393

94-
95-
// will be called before the first testfunction is executed.
96-
void initTestCase()
97-
{
98-
mTestHasError = false;
99-
QgsApplication::init();
100-
QgsApplication::initQgis();
101-
QgsApplication::showSettings();
102-
103-
//create some objects that will be used in all tests...
104-
105-
//
106-
//create a non spatial layer that will be used in all tests...
107-
//
108-
QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
109-
mTestDataDir = myDataDir + "/";
110-
QString myDbfFileName = mTestDataDir + "nonspatial.dbf";
111-
QFileInfo myDbfFileInfo( myDbfFileName );
112-
mpNonSpatialLayer = new QgsVectorLayer( myDbfFileInfo.filePath(),
113-
myDbfFileInfo.completeBaseName(), "ogr" );
114-
// Register the layer with the registry
115-
QgsMapLayerRegistry::instance()->addMapLayers(
116-
QList<QgsMapLayer *>() << mpNonSpatialLayer );
117-
//
118-
//create a point layer that will be used in all tests...
119-
//
120-
QString myPointsFileName = mTestDataDir + "points.shp";
121-
QFileInfo myPointFileInfo( myPointsFileName );
122-
mpPointsLayer = new QgsVectorLayer( myPointFileInfo.filePath(),
123-
myPointFileInfo.completeBaseName(), "ogr" );
124-
// Register the layer with the registry
125-
QgsMapLayerRegistry::instance()->addMapLayers(
126-
QList<QgsMapLayer *>() << mpPointsLayer );
127-
128-
//
129-
//create a poly layer that will be used in all tests...
130-
//
131-
QString myPolysFileName = mTestDataDir + "polys.shp";
132-
QFileInfo myPolyFileInfo( myPolysFileName );
133-
mpPolysLayer = new QgsVectorLayer( myPolyFileInfo.filePath(),
134-
myPolyFileInfo.completeBaseName(), "ogr" );
135-
// Register the layer with the registry
136-
QgsMapLayerRegistry::instance()->addMapLayers(
137-
QList<QgsMapLayer *>() << mpPolysLayer );
138-
139-
140-
//
141-
// Create a line layer that will be used in all tests...
142-
//
143-
QString myLinesFileName = mTestDataDir + "lines.shp";
144-
QFileInfo myLineFileInfo( myLinesFileName );
145-
mpLinesLayer = new QgsVectorLayer( myLineFileInfo.filePath(),
146-
myLineFileInfo.completeBaseName(), "ogr" );
147-
// Register the layer with the registry
148-
QgsMapLayerRegistry::instance()->addMapLayers(
149-
QList<QgsMapLayer *>() << mpLinesLayer );
150-
//
151-
// We only need maprender instead of mapcanvas
152-
// since maprender does not require a qui
153-
// and is more light weight
154-
//
155-
mpMapRenderer = new QgsMapRenderer();
156-
QStringList myLayers;
157-
myLayers << mpPointsLayer->id();
158-
myLayers << mpPolysLayer->id();
159-
myLayers << mpLinesLayer->id();
160-
mpMapRenderer->setLayerSet( myLayers );
161-
mReport += "<h1>Vector Renderer Tests</h1>\n";
162-
}
163-
// will be called after the last testfunction was executed.
164-
void cleanupTestCase()
165-
{
166-
QString myReportFile = QDir::tempPath() + "/qgistest.html";
167-
QFile myFile( myReportFile );
168-
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
169-
{
170-
QTextStream myQTextStream( &myFile );
171-
myQTextStream << mReport;
172-
myFile.close();
173-
//QDesktopServices::openUrl( "file:///" + myReportFile );
174-
}
175-
QgsApplication::exitQgis();
176-
177-
}
178-
void init() {} // will be called before each testfunction is executed.
94+
void initTestCase(); // will be called before the first testfunction is executed.
95+
void cleanupTestCase(); // will be called after the last testfunction was executed.
96+
void init() {} // will be called before each testfunction is executed.
17997
void cleanup() {} // will be called after every testfunction.
18098

181-
void QgsVectorLayerNonSpatialIterator()
182-
{
183-
QgsFeature f;
184-
QgsAttributeList myList;
185-
myList << 0 << 1 << 2 << 3;
186-
int myCount = 0;
187-
QgsFeatureIterator fit = mpNonSpatialLayer->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( myList ) );
188-
while ( fit.nextFeature( f ) )
189-
{
190-
qDebug( "Getting non-spatial feature from layer" );
191-
myCount++;
192-
}
193-
QVERIFY( myCount == 3 );
194-
}
195-
196-
void QgsVectorLayerGetValues()
197-
{
198-
QgsVectorLayer* layer = new QgsVectorLayer( "Point?field=col1:real", "layer", "memory" );
199-
QVERIFY( layer->isValid() );
200-
QgsFeature f1( layer->dataProvider()->fields(), 1 );
201-
f1.setAttribute( "col1", 1 );
202-
QgsFeature f2( layer->dataProvider()->fields(), 2 );
203-
f2.setAttribute( "col1", 2 );
204-
QgsFeature f3( layer->dataProvider()->fields(), 3 );
205-
f3.setAttribute( "col1", 3 );
206-
QgsFeature f4( layer->dataProvider()->fields(), 4 );
207-
f4.setAttribute( "col1", QVariant() );
208-
layer->dataProvider()->addFeatures( QgsFeatureList() << f1 << f2 << f3 << f4 );
209-
210-
//make a selection
211-
QgsFeatureIds ids;
212-
ids << f2.id() << f3.id();
213-
layer->setSelectedFeatures( ids );
214-
215-
bool ok;
216-
QList<QVariant> varList = layer->getValues( "col1", ok );
217-
QVERIFY( ok );
218-
QCOMPARE( varList.length(), 4 );
219-
QCOMPARE( varList.at( 0 ), QVariant( 1 ) );
220-
QCOMPARE( varList.at( 1 ), QVariant( 2 ) );
221-
QCOMPARE( varList.at( 2 ), QVariant( 3 ) );
222-
QCOMPARE( varList.at( 3 ), QVariant() );
223-
224-
//check with selected features
225-
varList = layer->getValues( "col1", ok, true );
226-
QVERIFY( ok );
227-
QCOMPARE( varList.length(), 2 );
228-
QCOMPARE( varList.at( 0 ), QVariant( 2 ) );
229-
QCOMPARE( varList.at( 1 ), QVariant( 3 ) );
230-
231-
int nulls = 0;
232-
QList<double> doubleList = layer->getDoubleValues( "col1", ok, false, &nulls );
233-
QVERIFY( ok );
234-
QCOMPARE( doubleList.length(), 3 );
235-
QCOMPARE( doubleList.at( 0 ), 1.0 );
236-
QCOMPARE( doubleList.at( 1 ), 2.0 );
237-
QCOMPARE( doubleList.at( 2 ), 3.0 );
238-
QCOMPARE( nulls, 1 );
239-
240-
//check with selected features
241-
doubleList = layer->getDoubleValues( "col1", ok, true, &nulls );
242-
QVERIFY( ok );
243-
QCOMPARE( doubleList.length(), 2 );
244-
QCOMPARE( doubleList.at( 0 ), 2.0 );
245-
QCOMPARE( doubleList.at( 1 ), 3.0 );
246-
QCOMPARE( nulls, 0 );
247-
248-
QList<QVariant> expVarList = layer->getValues( "tostring(col1) || ' '", ok );
249-
QVERIFY( ok );
250-
QCOMPARE( expVarList.length(), 4 );
251-
QCOMPARE( expVarList.at( 0 ).toString(), QString( "1 " ) );
252-
QCOMPARE( expVarList.at( 1 ).toString(), QString( "2 " ) );
253-
QCOMPARE( expVarList.at( 2 ).toString(), QString( "3 " ) );
254-
QCOMPARE( expVarList.at( 3 ), QVariant() );
255-
256-
QList<double> expDoubleList = layer->getDoubleValues( "col1 * 2", ok, false, &nulls );
257-
QVERIFY( ok );
258-
QCOMPARE( expDoubleList.length(), 3 );
259-
QCOMPARE( expDoubleList.at( 0 ), 2.0 );
260-
QCOMPARE( expDoubleList.at( 1 ), 4.0 );
261-
QCOMPARE( expDoubleList.at( 2 ), 6.0 );
262-
QCOMPARE( nulls, 1 );
263-
264-
delete layer;
265-
}
266-
267-
void QgsVectorLayerstorageType() {}
268-
void QgsVectorLayercapabilitiesString() {}
269-
void QgsVectorLayerdataComment() {}
270-
void QgsVectorLayerproviderType() {}
271-
void QgsVectorLayersetDisplayField() {}
272-
void QgsVectorLayerdrawLabels() {}
273-
void QgsVectorLayerdrawLineString() {}
274-
void QgsVectorLayerdrawPolygon() {}
275-
void QgsVectorLayerdrawRendererV2() {}
276-
void QgsVectorLayerdrawRendererV2Levels() {}
277-
void QgsVectorLayerreload() {}
278-
void QgsVectorLayerdraw() {}
279-
void QgsVectorLayerdeleteCachedGeometries() {}
280-
void QgsVectorLayerdrawVertexMarker() {}
281-
void QgsVectorLayerselect() {}
282-
void QgsVectorLayerinvertSelection() {}
283-
void QgsVectorLayerinvertSelectionInRectangle() {}
284-
void QgsVectorLayerremoveSelection() {}
285-
void QgsVectorLayertriggerRepaint() {}
286-
void QgsVectorLayerdataProvider() {}
287-
void QgsVectorLayersetProviderEncoding() {}
288-
void QgsVectorLayerrenderer() {}
289-
void QgsVectorLayersetRenderer() {}
290-
void QgsVectorLayergeometryType() {}
291-
void QgsVectorLayerwkbType() {}
292-
void QgsVectorLayerboundingBoxOfSelected() {}
293-
void QgsVectorLayerfeatureCount() {}
294-
void QgsVectorLayerupdateFeatureCount() {}
295-
void QgsVectorLayerupdateExtents() {}
296-
void QgsVectorLayersubsetString() {}
297-
void QgsVectorLayersetSubsetString() {}
298-
void QgsVectorLayerupdateFeatureAttributes() {}
299-
void QgsVectorLayerupdateFeatureGeometry() {}
300-
void QgsVectorLayernextFeature() {}
301-
void QgsVectorLayerfeatureAtId() {}
302-
void QgsVectorLayeraddFeature() {}
303-
void QgsVectorLayerinsertVertex() {}
304-
void QgsVectorLayermoveVertex() {}
305-
void QgsVectorLayerdeleteVertex() {}
306-
void QgsVectorLayerdeleteSelectedFeatures() {}
307-
void QgsVectorLayeraddRing() {}
308-
void QgsVectorLayeraddIsland() {}
309-
void QgsVectorLayertranslateFeature() {}
310-
void QgsVectorLayersplitFeatures() {}
311-
void QgsVectorLayerremovePolygonIntersections() {}
312-
void QgsVectorLayeraddTopologicalPoints() {}
313-
void QgsVectorLayerlabel() {}
314-
void QgsVectorLayerenableLabels() {}
315-
void QgsVectorLayerhasLabelsEnabled() {}
316-
void QgsVectorLayerstartEditing() {}
317-
void QgsVectorLayerreadXml() {}
318-
void QgsVectorLayersetDataProvider() {}
319-
void QgsVectorLayerwriteXml() {}
320-
void QgsVectorLayerreadSymbology() {}
321-
void QgsVectorLayerwriteSymbology() {}
322-
void QgsVectorLayerchangeGeometry() {}
323-
void QgsVectorLayerchangeAttributeValue() {}
324-
void QgsVectorLayeraddAttribute() {}
325-
void QgsVectorLayeraddAttributeAlias() {}
326-
void QgsVectorLayerattributeAlias() {}
327-
void QgsVectorLayerattributeDisplayName() {}
328-
void QgsVectorLayerdeleteAttribute() {}
329-
void QgsVectorLayerdeleteFeature() {}
330-
void QgsVectorLayerpendingFields() {}
331-
void QgsVectorLayerpendingAllAttributesList() {}
332-
void QgsVectorLayerpendingFeatureCount() {}
333-
void QgsVectorLayercommitChanges() {}
334-
void QgsVectorLayercommitErrors() {}
335-
void QgsVectorLayerrollBack() {}
336-
void QgsVectorLayersetSelectedFeatures() {}
337-
void QgsVectorLayerselectedFeatureCount() {}
338-
void QgsVectorLayerselectedFeaturesIds() {}
339-
void QgsVectorLayerselectedFeatures() {}
340-
void QgsVectorLayeraddFeatures() {}
341-
void QgsVectorLayercopySymbologySettings() {}
342-
void QgsVectorLayerhasCompatibleSymbology() {}
343-
void QgsVectorLayersnapPoint() {}
344-
void QgsVectorLayersnapWithContext() {}
345-
void QgsVectorLayersnapToGeometry() {}
346-
void QgsVectorLayerinsertSegmentVerticesForSnap() {}
347-
void QgsVectorLayerboundingBoxFromPointList() {}
348-
void QgsVectorLayercurrentVertexMarkerType() {}
349-
void QgsVectorLayercurrentVertexMarkerSize() {}
350-
void QgsVectorLayerdrawFeature() {}
351-
void QgsVectorLayersetCoordinateSystem() {}
352-
void QgsVectorLayertransformPoint() {}
353-
void QgsVectorLayertransformPoints() {}
354-
void QgsVectorLayerdisplayField() {}
355-
void QgsVectorLayerisEditable() {}
356-
void QgsVectorLayerisModified() {}
357-
void QgsVectorLayersetModified() {}
358-
void QgsVectorLayereditType() {}
359-
void QgsVectorLayersetEditType() {}
360-
void QgsVectorLayereditForm() {}
361-
void QgsVectorLayersetEditForm() {}
362-
void QgsVectorLayersetAnnotationForm() {}
363-
void QgsVectorLayereditFormInit() {}
364-
void QgsVectorLayersetEditFormInit() {}
365-
void QgsVectorLayervalueMap() {}
366-
void QgsVectorLayerrange() {}
367-
void QgsVectorLayeraddOverlay() {}
368-
void QgsVectorLayerremoveOverlay() {}
369-
void QgsVectorLayervectorOverlays() {}
370-
void QgsVectorLayerfindOverlayByType() {}
371-
void QgsVectorLayerrendererV2() {}
372-
373-
void QgsVectorLayersetRendererV2()
374-
{
375-
QgsVectorLayer* vLayer = static_cast< QgsVectorLayer * >( mpPointsLayer );
376-
TestSignalReceiver receiver;
377-
QObject::connect( vLayer, SIGNAL( rendererChanged() ),
378-
&receiver, SLOT( onRendererChanged() ) );
379-
QgsSingleSymbolRendererV2* symbolRenderer = new QgsSingleSymbolRendererV2( QgsSymbolV2::defaultSymbol( QGis::Point ) );
380-
381-
QCOMPARE( receiver.rendererChanged, false );
382-
vLayer->setRendererV2( symbolRenderer );
383-
QCOMPARE( receiver.rendererChanged, true );
384-
QCOMPARE( vLayer->rendererV2(), symbolRenderer );
385-
}
386-
387-
void QgsVectorLayerisUsingRendererV2() {}
388-
void QgsVectorLayersetUsingRendererV2() {}
389-
void QgsVectorLayereditGeometryChange() {}
390-
void QgsVectorLayereditFeatureAdd() {}
391-
void QgsVectorLayereditFeatureDelete() {}
392-
void QgsVectorLayereditAttributeChange() {}
393-
void QgsVectorLayerbeginEditCommand() {}
394-
void QgsVectorLayerendEditCommand() {}
395-
void QgsVectorLayerdestroyEditCommand() {}
396-
void QgsVectorLayerredoEditCommand() {}
397-
void QgsVectorLayerundoEditCommand() {}
398-
void QgsVectorLayersetCheckedState() {}
399-
void QgsVectorLayercheckedState() {}
400-
void QgsVectorLayerfieldNameIndex() {}
401-
void QgsVectorLayerstopRendererV2() {}
402-
403-
void QgsVectorLayersetFeatureBlendMode()
404-
{
405-
QgsVectorLayer *vLayer = static_cast< QgsVectorLayer * >( mpPointsLayer );
406-
TestSignalReceiver receiver;
407-
QObject::connect( vLayer, SIGNAL( featureBlendModeChanged( const QPainter::CompositionMode ) ),
408-
&receiver, SLOT( onFeatureBlendModeChanged( const QPainter::CompositionMode ) ) );
409-
410-
QCOMPARE( int( receiver.featureBlendMode ), 0 );
411-
vLayer->setFeatureBlendMode( QPainter::CompositionMode_Screen );
412-
QCOMPARE( receiver.featureBlendMode, QPainter::CompositionMode_Screen );
413-
QCOMPARE( vLayer->featureBlendMode(), QPainter::CompositionMode_Screen );
414-
}
415-
416-
void QgsVectorLayersetLayerTransparency()
417-
{
418-
QgsVectorLayer* vLayer = static_cast< QgsVectorLayer * >( mpPointsLayer );
419-
TestSignalReceiver receiver;
420-
QObject::connect( vLayer, SIGNAL( layerTransparencyChanged( int ) ),
421-
&receiver, SLOT( onLayerTransparencyChanged( int ) ) );
422-
423-
QCOMPARE( receiver.transparency, 0 );
424-
vLayer->setLayerTransparency( 50 );
425-
QCOMPARE( receiver.transparency, 50 );
426-
QCOMPARE( vLayer->layerTransparency(), 50 );
427-
}
99+
void QgsVectorLayerNonSpatialIterator();
100+
void QgsVectorLayerGetValues();
101+
void QgsVectorLayersetRendererV2();
102+
void QgsVectorLayersetFeatureBlendMode();
103+
void QgsVectorLayersetLayerTransparency();
428104
};
429105

106+
void TestQgsVectorLayer::initTestCase()
107+
{
108+
mTestHasError = false;
109+
QgsApplication::init();
110+
QgsApplication::initQgis();
111+
QgsApplication::showSettings();
112+
113+
//create some objects that will be used in all tests...
114+
115+
//
116+
//create a non spatial layer that will be used in all tests...
117+
//
118+
QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
119+
mTestDataDir = myDataDir + "/";
120+
QString myDbfFileName = mTestDataDir + "nonspatial.dbf";
121+
QFileInfo myDbfFileInfo( myDbfFileName );
122+
mpNonSpatialLayer = new QgsVectorLayer( myDbfFileInfo.filePath(),
123+
myDbfFileInfo.completeBaseName(), "ogr" );
124+
// Register the layer with the registry
125+
QgsMapLayerRegistry::instance()->addMapLayers(
126+
QList<QgsMapLayer *>() << mpNonSpatialLayer );
127+
//
128+
//create a point layer that will be used in all tests...
129+
//
130+
QString myPointsFileName = mTestDataDir + "points.shp";
131+
QFileInfo myPointFileInfo( myPointsFileName );
132+
mpPointsLayer = new QgsVectorLayer( myPointFileInfo.filePath(),
133+
myPointFileInfo.completeBaseName(), "ogr" );
134+
// Register the layer with the registry
135+
QgsMapLayerRegistry::instance()->addMapLayers(
136+
QList<QgsMapLayer *>() << mpPointsLayer );
137+
138+
//
139+
//create a poly layer that will be used in all tests...
140+
//
141+
QString myPolysFileName = mTestDataDir + "polys.shp";
142+
QFileInfo myPolyFileInfo( myPolysFileName );
143+
mpPolysLayer = new QgsVectorLayer( myPolyFileInfo.filePath(),
144+
myPolyFileInfo.completeBaseName(), "ogr" );
145+
// Register the layer with the registry
146+
QgsMapLayerRegistry::instance()->addMapLayers(
147+
QList<QgsMapLayer *>() << mpPolysLayer );
148+
149+
150+
//
151+
// Create a line layer that will be used in all tests...
152+
//
153+
QString myLinesFileName = mTestDataDir + "lines.shp";
154+
QFileInfo myLineFileInfo( myLinesFileName );
155+
mpLinesLayer = new QgsVectorLayer( myLineFileInfo.filePath(),
156+
myLineFileInfo.completeBaseName(), "ogr" );
157+
// Register the layer with the registry
158+
QgsMapLayerRegistry::instance()->addMapLayers(
159+
QList<QgsMapLayer *>() << mpLinesLayer );
160+
//
161+
// We only need maprender instead of mapcanvas
162+
// since maprender does not require a qui
163+
// and is more light weight
164+
//
165+
mpMapRenderer = new QgsMapRenderer();
166+
QStringList myLayers;
167+
myLayers << mpPointsLayer->id();
168+
myLayers << mpPolysLayer->id();
169+
myLayers << mpLinesLayer->id();
170+
mpMapRenderer->setLayerSet( myLayers );
171+
mReport += "<h1>Vector Renderer Tests</h1>\n";
172+
}
173+
174+
void TestQgsVectorLayer::cleanupTestCase()
175+
{
176+
QString myReportFile = QDir::tempPath() + "/qgistest.html";
177+
QFile myFile( myReportFile );
178+
if ( myFile.open( QIODevice::WriteOnly | QIODevice::Append ) )
179+
{
180+
QTextStream myQTextStream( &myFile );
181+
myQTextStream << mReport;
182+
myFile.close();
183+
//QDesktopServices::openUrl( "file:///" + myReportFile );
184+
}
185+
QgsApplication::exitQgis();
186+
187+
}
188+
189+
void TestQgsVectorLayer::QgsVectorLayerNonSpatialIterator()
190+
{
191+
QgsFeature f;
192+
QgsAttributeList myList;
193+
myList << 0 << 1 << 2 << 3;
194+
int myCount = 0;
195+
QgsFeatureIterator fit = mpNonSpatialLayer->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( myList ) );
196+
while ( fit.nextFeature( f ) )
197+
{
198+
qDebug( "Getting non-spatial feature from layer" );
199+
myCount++;
200+
}
201+
QVERIFY( myCount == 3 );
202+
}
203+
204+
void TestQgsVectorLayer::QgsVectorLayerGetValues()
205+
{
206+
QgsVectorLayer* layer = new QgsVectorLayer( "Point?field=col1:real", "layer", "memory" );
207+
QVERIFY( layer->isValid() );
208+
QgsFeature f1( layer->dataProvider()->fields(), 1 );
209+
f1.setAttribute( "col1", 1 );
210+
QgsFeature f2( layer->dataProvider()->fields(), 2 );
211+
f2.setAttribute( "col1", 2 );
212+
QgsFeature f3( layer->dataProvider()->fields(), 3 );
213+
f3.setAttribute( "col1", 3 );
214+
QgsFeature f4( layer->dataProvider()->fields(), 4 );
215+
f4.setAttribute( "col1", QVariant() );
216+
layer->dataProvider()->addFeatures( QgsFeatureList() << f1 << f2 << f3 << f4 );
217+
218+
//make a selection
219+
QgsFeatureIds ids;
220+
ids << f2.id() << f3.id();
221+
layer->setSelectedFeatures( ids );
222+
223+
bool ok;
224+
QList<QVariant> varList = layer->getValues( "col1", ok );
225+
QVERIFY( ok );
226+
QCOMPARE( varList.length(), 4 );
227+
QCOMPARE( varList.at( 0 ), QVariant( 1 ) );
228+
QCOMPARE( varList.at( 1 ), QVariant( 2 ) );
229+
QCOMPARE( varList.at( 2 ), QVariant( 3 ) );
230+
QCOMPARE( varList.at( 3 ), QVariant() );
231+
232+
//check with selected features
233+
varList = layer->getValues( "col1", ok, true );
234+
QVERIFY( ok );
235+
QCOMPARE( varList.length(), 2 );
236+
QCOMPARE( varList.at( 0 ), QVariant( 2 ) );
237+
QCOMPARE( varList.at( 1 ), QVariant( 3 ) );
238+
239+
int nulls = 0;
240+
QList<double> doubleList = layer->getDoubleValues( "col1", ok, false, &nulls );
241+
QVERIFY( ok );
242+
QCOMPARE( doubleList.length(), 3 );
243+
QCOMPARE( doubleList.at( 0 ), 1.0 );
244+
QCOMPARE( doubleList.at( 1 ), 2.0 );
245+
QCOMPARE( doubleList.at( 2 ), 3.0 );
246+
QCOMPARE( nulls, 1 );
247+
248+
//check with selected features
249+
doubleList = layer->getDoubleValues( "col1", ok, true, &nulls );
250+
QVERIFY( ok );
251+
QCOMPARE( doubleList.length(), 2 );
252+
QCOMPARE( doubleList.at( 0 ), 2.0 );
253+
QCOMPARE( doubleList.at( 1 ), 3.0 );
254+
QCOMPARE( nulls, 0 );
255+
256+
QList<QVariant> expVarList = layer->getValues( "tostring(col1) || ' '", ok );
257+
QVERIFY( ok );
258+
QCOMPARE( expVarList.length(), 4 );
259+
QCOMPARE( expVarList.at( 0 ).toString(), QString( "1 " ) );
260+
QCOMPARE( expVarList.at( 1 ).toString(), QString( "2 " ) );
261+
QCOMPARE( expVarList.at( 2 ).toString(), QString( "3 " ) );
262+
QCOMPARE( expVarList.at( 3 ), QVariant() );
263+
264+
QList<double> expDoubleList = layer->getDoubleValues( "col1 * 2", ok, false, &nulls );
265+
QVERIFY( ok );
266+
QCOMPARE( expDoubleList.length(), 3 );
267+
QCOMPARE( expDoubleList.at( 0 ), 2.0 );
268+
QCOMPARE( expDoubleList.at( 1 ), 4.0 );
269+
QCOMPARE( expDoubleList.at( 2 ), 6.0 );
270+
QCOMPARE( nulls, 1 );
271+
272+
delete layer;
273+
}
274+
275+
void TestQgsVectorLayer::QgsVectorLayersetRendererV2()
276+
{
277+
QgsVectorLayer* vLayer = static_cast< QgsVectorLayer * >( mpPointsLayer );
278+
TestSignalReceiver receiver;
279+
QObject::connect( vLayer, SIGNAL( rendererChanged() ),
280+
&receiver, SLOT( onRendererChanged() ) );
281+
QgsSingleSymbolRendererV2* symbolRenderer = new QgsSingleSymbolRendererV2( QgsSymbolV2::defaultSymbol( QGis::Point ) );
282+
283+
QCOMPARE( receiver.rendererChanged, false );
284+
vLayer->setRendererV2( symbolRenderer );
285+
QCOMPARE( receiver.rendererChanged, true );
286+
QCOMPARE( vLayer->rendererV2(), symbolRenderer );
287+
}
288+
289+
void TestQgsVectorLayer::QgsVectorLayersetFeatureBlendMode()
290+
{
291+
QgsVectorLayer *vLayer = static_cast< QgsVectorLayer * >( mpPointsLayer );
292+
TestSignalReceiver receiver;
293+
QObject::connect( vLayer, SIGNAL( featureBlendModeChanged( const QPainter::CompositionMode ) ),
294+
&receiver, SLOT( onFeatureBlendModeChanged( const QPainter::CompositionMode ) ) );
295+
296+
QCOMPARE( int( receiver.featureBlendMode ), 0 );
297+
vLayer->setFeatureBlendMode( QPainter::CompositionMode_Screen );
298+
QCOMPARE( receiver.featureBlendMode, QPainter::CompositionMode_Screen );
299+
QCOMPARE( vLayer->featureBlendMode(), QPainter::CompositionMode_Screen );
300+
}
301+
302+
void TestQgsVectorLayer::QgsVectorLayersetLayerTransparency()
303+
{
304+
QgsVectorLayer* vLayer = static_cast< QgsVectorLayer * >( mpPointsLayer );
305+
TestSignalReceiver receiver;
306+
QObject::connect( vLayer, SIGNAL( layerTransparencyChanged( int ) ),
307+
&receiver, SLOT( onLayerTransparencyChanged( int ) ) );
308+
309+
QCOMPARE( receiver.transparency, 0 );
310+
vLayer->setLayerTransparency( 50 );
311+
QCOMPARE( receiver.transparency, 50 );
312+
QCOMPARE( vLayer->layerTransparency(), 50 );
313+
}
314+
430315
QTEST_MAIN( TestQgsVectorLayer )
431316
#include "testqgsvectorlayer.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.