Skip to content
Permalink
Browse files
Fixes to unit tests
  • Loading branch information
wonder-sk committed May 13, 2017
1 parent 3e18cc1 commit bbe59969b7c6b16b143d12474101972c81a8a406
@@ -25,6 +25,7 @@
#include <qgsmaplayer.h>
#include <qgsvectorlayer.h>
#include <qgsapplication.h>
#include <qgspathresolver.h>
#include <qgsproviderregistry.h>
#include <qgsproject.h>
#include <qgssymbol.h>
@@ -98,8 +99,10 @@ void TestQgsSvgMarkerSymbol::initTestCase()
QgsProject::instance()->addMapLayers(
QList<QgsMapLayer *>() << mpPointsLayer );

QString defaultSvgPath = QgsSymbolLayerUtils::svgSymbolNameToPath( QStringLiteral( "/crosses/Star1.svg" ), QgsPathResolver() );

//setup symbol
mSvgMarkerLayer = new QgsSvgMarkerSymbolLayer( QStringLiteral( "/crosses/Star1.svg" ) );
mSvgMarkerLayer = new QgsSvgMarkerSymbolLayer( defaultSvgPath );
mMarkerSymbol = new QgsMarkerSymbol();
mMarkerSymbol->changeSymbolLayer( 0, mSvgMarkerLayer );
mSymbolRenderer = new QgsSingleSymbolRenderer( mMarkerSymbol );
@@ -131,7 +134,9 @@ void TestQgsSvgMarkerSymbol::svgMarkerSymbol()
{
mReport += QLatin1String( "<h2>SVG marker symbol layer test</h2>\n" );

mSvgMarkerLayer->setPath( QStringLiteral( "/transport/transport_airport.svg" ) );
QString svgPath = QgsSymbolLayerUtils::svgSymbolNameToPath( QStringLiteral( "/transport/transport_airport.svg" ), QgsPathResolver() );

mSvgMarkerLayer->setPath( svgPath );
mSvgMarkerLayer->setStrokeColor( Qt::black );
mSvgMarkerLayer->setColor( Qt::blue );
mSvgMarkerLayer->setSize( 10 );
@@ -23,6 +23,7 @@
QgsVectorLayer,
QgsFeature,
QgsGeometry,
QgsPathResolver,
QgsPoint,
QgsRenderContext
)
@@ -372,8 +373,8 @@ def testQgsGraduatedSymbolRenderer_2(self):
# Check save and reload from Dom works

doc = QDomDocument()
element = renderer.save(doc)
renderer2 = QgsGraduatedSymbolRenderer.create(element)
element = renderer.save(doc, QgsPathResolver())
renderer2 = QgsGraduatedSymbolRenderer.create(element, QgsPathResolver())
self.assertEqual(
dumpGraduatedRenderer(renderer),
dumpGraduatedRenderer(renderer2),
@@ -38,6 +38,7 @@
QgsMapUnitScale,
QgsMarkerSymbol,
QgsSingleSymbolRenderer,
QgsPathResolver,
QgsPointDisplacementRenderer,
QgsMapSettings,
QgsProperty,
@@ -114,8 +115,8 @@ def testSaveCreate(self):
r = QgsPointClusterRenderer()
self._setProperties(r)
doc = QDomDocument("testdoc")
elem = r.save(doc)
c = QgsPointClusterRenderer.create(elem)
elem = r.save(doc, QgsPathResolver())
c = QgsPointClusterRenderer.create(elem, QgsPathResolver())
self._checkProperties(c)

def testConvert(self):
@@ -43,6 +43,7 @@
QgsSingleSymbolRenderer,
QgsPointClusterRenderer,
QgsMapSettings,
QgsPathResolver,
QgsProperty,
QgsSymbolLayer
)
@@ -138,8 +139,8 @@ def testSaveCreate(self):
r = QgsPointDisplacementRenderer()
self._setProperties(r)
doc = QDomDocument("testdoc")
elem = r.save(doc)
c = QgsPointDisplacementRenderer.create(elem)
elem = r.save(doc, QgsPathResolver())
c = QgsPointDisplacementRenderer.create(elem, QgsPathResolver())
self._checkProperties(c)

def testConvert(self):
@@ -42,6 +42,7 @@
QgsLineSymbolLayer,
QgsMarkerLineSymbolLayer,
QgsMarkerSymbolLayer,
QgsPathResolver,
QgsPointPatternFillSymbolLayer,
QgsSimpleFillSymbolLayer,
QgsSimpleLineSymbolLayer,
@@ -323,9 +324,9 @@ def testSaveRestore(self):
symbol.changeSymbolLayer(0, layer)

doc = QDomDocument("testdoc")
elem = QgsSymbolLayerUtils.saveSymbol('test', symbol, doc)
elem = QgsSymbolLayerUtils.saveSymbol('test', symbol, doc, QgsPathResolver())

restored_symbol = QgsSymbolLayerUtils.loadSymbol(elem)
restored_symbol = QgsSymbolLayerUtils.loadSymbol(elem, QgsPathResolver())
restored_layer = restored_symbol.symbolLayer(0)
self.assertFalse(restored_layer.enabled())
self.assertTrue(restored_layer.isLocked())
@@ -846,7 +847,7 @@ def testQgsSVGFillSymbolLayer(self):
mSymbolLayer = QgsSVGFillSymbolLayer.createFromSld(
mDoc.elementsByTagName('PolygonSymbolizer').item(0).toElement())

mExpectedValue = type(QgsSVGFillSymbolLayer())
mExpectedValue = type(QgsSVGFillSymbolLayer(""))
mValue = type(mSymbolLayer)
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
@@ -1058,7 +1059,7 @@ def testQgsSvgMarkerSymbolLayer(self):
mFile.close()
mSymbolLayer = QgsSvgMarkerSymbolLayer.createFromSld(mDoc.elementsByTagName('PointSymbolizer').item(0).toElement())

mExpectedValue = type(QgsSvgMarkerSymbolLayer())
mExpectedValue = type(QgsSvgMarkerSymbolLayer(""))
mValue = type(mSymbolLayer)
mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
assert mExpectedValue == mValue, mMessage
@@ -34,6 +34,7 @@
QgsSymbol,
QgsSingleSymbolRenderer,
QgsCoordinateReferenceSystem,
QgsPathResolver,
QgsProject,
QgsUnitTypes,
QgsAggregateCalculator,
@@ -1772,10 +1773,10 @@ def testSaveRestoreAliases(self):
# no default expressions
doc = QDomDocument("testdoc")
elem = doc.createElement("maplayer")
self.assertTrue(layer.writeXml(elem, doc))
self.assertTrue(layer.writeXml(elem, doc, QgsPathResolver()))

layer2 = createLayerWithOnePoint()
self.assertTrue(layer2.readXml(elem))
self.assertTrue(layer2.readXml(elem, QgsPathResolver()))
self.assertFalse(layer2.attributeAlias(0))
self.assertFalse(layer2.attributeAlias(1))

@@ -1785,10 +1786,10 @@ def testSaveRestoreAliases(self):

doc = QDomDocument("testdoc")
elem = doc.createElement("maplayer")
self.assertTrue(layer.writeXml(elem, doc))
self.assertTrue(layer.writeXml(elem, doc, QgsPathResolver()))

layer3 = createLayerWithOnePoint()
self.assertTrue(layer3.readXml(elem))
self.assertTrue(layer3.readXml(elem, QgsPathResolver()))
self.assertEqual(layer3.attributeAlias(0), "test")
self.assertEqual(layer3.attributeAlias(1), "test2")
self.assertEqual(layer3.fields().at(0).alias(), "test")
@@ -1822,10 +1823,10 @@ def testSaveRestoreDefaults(self):
# no default expressions
doc = QDomDocument("testdoc")
elem = doc.createElement("maplayer")
self.assertTrue(layer.writeXml(elem, doc))
self.assertTrue(layer.writeXml(elem, doc, QgsPathResolver()))

layer2 = createLayerWithOnePoint()
self.assertTrue(layer2.readXml(elem))
self.assertTrue(layer2.readXml(elem, QgsPathResolver()))
self.assertFalse(layer2.defaultValueExpression(0))
self.assertFalse(layer2.defaultValueExpression(1))

@@ -1835,10 +1836,10 @@ def testSaveRestoreDefaults(self):

doc = QDomDocument("testdoc")
elem = doc.createElement("maplayer")
self.assertTrue(layer.writeXml(elem, doc))
self.assertTrue(layer.writeXml(elem, doc, QgsPathResolver()))

layer3 = createLayerWithOnePoint()
self.assertTrue(layer3.readXml(elem))
self.assertTrue(layer3.readXml(elem, QgsPathResolver()))
self.assertEqual(layer3.defaultValueExpression(0), "'test'")
self.assertEqual(layer3.defaultValueExpression(1), "2+2")
self.assertEqual(layer3.fields().at(0).defaultValueExpression(), "'test'")
@@ -1947,10 +1948,10 @@ def testSaveRestoreConstraints(self):
# no constraints
doc = QDomDocument("testdoc")
elem = doc.createElement("maplayer")
self.assertTrue(layer.writeXml(elem, doc))
self.assertTrue(layer.writeXml(elem, doc, QgsPathResolver()))

layer2 = createLayerWithOnePoint()
self.assertTrue(layer2.readXml(elem))
self.assertTrue(layer2.readXml(elem, QgsPathResolver()))
self.assertFalse(layer2.fieldConstraints(0))
self.assertFalse(layer2.fieldConstraints(1))

@@ -1961,10 +1962,10 @@ def testSaveRestoreConstraints(self):

doc = QDomDocument("testdoc")
elem = doc.createElement("maplayer")
self.assertTrue(layer.writeXml(elem, doc))
self.assertTrue(layer.writeXml(elem, doc, QgsPathResolver()))

layer3 = createLayerWithOnePoint()
self.assertTrue(layer3.readXml(elem))
self.assertTrue(layer3.readXml(elem, QgsPathResolver()))
self.assertEqual(layer3.fieldConstraints(0), QgsFieldConstraints.ConstraintNotNull)
self.assertEqual(layer3.fieldConstraints(1), QgsFieldConstraints.ConstraintNotNull | QgsFieldConstraints.ConstraintUnique)
self.assertEqual(layer3.fields().at(0).constraints().constraints(), QgsFieldConstraints.ConstraintNotNull)
@@ -2019,10 +2020,10 @@ def testSaveRestoreConstraintExpressions(self):
# no constraints
doc = QDomDocument("testdoc")
elem = doc.createElement("maplayer")
self.assertTrue(layer.writeXml(elem, doc))
self.assertTrue(layer.writeXml(elem, doc, QgsPathResolver()))

layer2 = createLayerWithOnePoint()
self.assertTrue(layer2.readXml(elem))
self.assertTrue(layer2.readXml(elem, QgsPathResolver()))
self.assertFalse(layer2.constraintExpression(0))
self.assertFalse(layer2.constraintExpression(1))

@@ -2032,10 +2033,10 @@ def testSaveRestoreConstraintExpressions(self):

doc = QDomDocument("testdoc")
elem = doc.createElement("maplayer")
self.assertTrue(layer.writeXml(elem, doc))
self.assertTrue(layer.writeXml(elem, doc, QgsPathResolver()))

layer3 = createLayerWithOnePoint()
self.assertTrue(layer3.readXml(elem))
self.assertTrue(layer3.readXml(elem, QgsPathResolver()))
self.assertEqual(layer3.constraintExpression(0), '1+2')
self.assertEqual(layer3.constraintExpression(1), '3+4')
self.assertEqual(layer3.constraintDescription(1), 'desc')

0 comments on commit bbe5996

Please sign in to comment.