Skip to content
Permalink
Browse files

Regression test to similate crash that occurs when setting a raster l…

…ayer renderer a second time
  • Loading branch information
timlinux committed Sep 12, 2012
1 parent 6873b31 commit 05fb39419d8c436813c76d0eb8d75660b310d375
Showing with 55 additions and 1 deletion.
  1. +55 −1 tests/src/python/test_qgsrasterlayer.py
@@ -1,8 +1,20 @@
import os
import unittest

from qgis.core import QgsRasterLayer, QgsPoint, QgsMapLayerRegistry, QgsMapRenderer, QgsSingleBandGrayRenderer, QgsContrastEnhancement, QgsRasterTransparency, QgsRenderChecker
from PyQt4.QtCore import QFileInfo, QString, QStringList
from PyQt4 import QtGui

from qgis.core import (QgsRasterLayer,
QgsColorRampShader,
QgsContrastEnhancement,
QgsMapLayerRegistry,
QgsMapRenderer,
QgsPoint,
QgsRasterShader,
QgsRasterTransparency,
QgsRenderChecker,
QgsSingleBandGrayRenderer,
QgsSingleBandPseudoColorRenderer)

# Convenience instances in case you may need them
# not used in this test
@@ -104,5 +116,47 @@ def testTransparency(self):
myResultFlag = myChecker.runTest( "raster_transparency_python" );
assert myResultFlag, "Raster transparency rendering test failed"

def testShaderCrash(self):
"""Check if we assign a shader and then reassign it no crash occurs."""
myPath = os.path.abspath(os.path.join(__file__, '..', '..', '..', 'testdata', 'raster', 'band1_float32_noct_epsg4326.tif'))
myFileInfo = QFileInfo(myPath)
myBaseName = myFileInfo.baseName()
myRasterLayer = QgsRasterLayer(myPath, myBaseName)
myMessage = 'Raster not loaded: %s' % myPath
assert myRasterLayer.isValid(), myMessage

myRasterShader = QgsRasterShader()
myColorRampShader = QgsColorRampShader()
myColorRampShader.setColorRampType(QgsColorRampShader.INTERPOLATED)
myItems = []
myItem = QgsColorRampShader.ColorRampItem(10, QtGui.QColor('#ffff00'), 'foo')
myItems.append(myItem)
myItem = QgsColorRampShader.ColorRampItem(100, QtGui.QColor('#ff00ff'), 'bar')
myItems.append(myItem)
myItem = QgsColorRampShader.ColorRampItem(1000, QtGui.QColor('#00ff00'), 'kazam')
myItems.append(myItem)
myColorRampShader.setColorRampItemList(myItems)
myRasterShader.setRasterShaderFunction(myColorRampShader)
myPseudoRenderer = QgsSingleBandPseudoColorRenderer(myRasterLayer.dataProvider(), 1, myRasterShader)
myRasterLayer.setRenderer(myPseudoRenderer)

######## works first time #############

myRasterShader = QgsRasterShader()
myColorRampShader = QgsColorRampShader()
myColorRampShader.setColorRampType(QgsColorRampShader.INTERPOLATED)
myItems = []
myItem = QgsColorRampShader.ColorRampItem(10, QtGui.QColor('#ffff00'), 'foo')
myItems.append(myItem)
myItem = QgsColorRampShader.ColorRampItem(100, QtGui.QColor('#ff00ff'), 'bar')
myItems.append(myItem)
myItem = QgsColorRampShader.ColorRampItem(1000, QtGui.QColor('#00ff00'), 'kazam')
myItems.append(myItem)
myColorRampShader.setColorRampItemList(myItems)
myRasterShader.setRasterShaderFunction(myColorRampShader)
######## crash on next line ##################
myPseudoRenderer = QgsSingleBandPseudoColorRenderer(myRasterLayer.dataProvider(), 1, myRasterShader)
myRasterLayer.setRenderer(myPseudoRenderer)

if __name__ == '__main__':
unittest.main()

0 comments on commit 05fb394

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