mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
Update unit tests
This commit is contained in:
parent
670858d81c
commit
f55da4affb
@ -183,36 +183,34 @@ void TestQgsCoordinateTransform::isShortCircuited()
|
|||||||
|
|
||||||
void TestQgsCoordinateTransform::contextShared()
|
void TestQgsCoordinateTransform::contextShared()
|
||||||
{
|
{
|
||||||
#ifdef singlesourcedest
|
|
||||||
//test implicit sharing of QgsCoordinateTransformContext
|
//test implicit sharing of QgsCoordinateTransformContext
|
||||||
QgsCoordinateTransformContext original;
|
QgsCoordinateTransformContext original;
|
||||||
original.addDestinationDatumTransform( QgsCoordinateReferenceSystem( 3111 ), 1 );
|
original.addSourceDestinationDatumTransform( QgsCoordinateReferenceSystem( 3111 ), QgsCoordinateReferenceSystem( 3113 ), 1, 2 );
|
||||||
|
|
||||||
QgsCoordinateTransformContext copy( original );
|
QgsCoordinateTransformContext copy( original );
|
||||||
QMap< QString, int > expected;
|
QMap< QPair< QString, QString >, QPair< int, int > > expected;
|
||||||
expected.insert( "EPSG:3111", 1 );
|
expected.insert( qMakePair( QStringLiteral( "EPSG:3111" ), QStringLiteral( "EPSG:3113" ) ), qMakePair( 1, 2 ) );
|
||||||
QCOMPARE( original.destinationDatumTransforms(), expected );
|
QCOMPARE( original.sourceDestinationDatumTransforms(), expected );
|
||||||
QCOMPARE( copy.destinationDatumTransforms(), expected );
|
QCOMPARE( copy.sourceDestinationDatumTransforms(), expected );
|
||||||
|
|
||||||
// trigger detach
|
// trigger detach
|
||||||
copy.addDestinationDatumTransform( QgsCoordinateReferenceSystem( 3111 ), 2 );
|
copy.addSourceDestinationDatumTransform( QgsCoordinateReferenceSystem( 3111 ), QgsCoordinateReferenceSystem( 3113 ), 3, 4 );
|
||||||
QCOMPARE( original.destinationDatumTransforms(), expected );
|
QCOMPARE( original.sourceDestinationDatumTransforms(), expected );
|
||||||
|
|
||||||
expected.insert( "EPSG:3111", 2 );
|
expected.insert( qMakePair( QStringLiteral( "EPSG:3111" ), QStringLiteral( "EPSG:3113" ) ), qMakePair( 3, 4 ) );
|
||||||
QCOMPARE( copy.destinationDatumTransforms(), expected );
|
QCOMPARE( copy.sourceDestinationDatumTransforms(), expected );
|
||||||
|
|
||||||
// copy via assignment
|
// copy via assignment
|
||||||
QgsCoordinateTransformContext copy2;
|
QgsCoordinateTransformContext copy2;
|
||||||
copy2 = original;
|
copy2 = original;
|
||||||
expected.insert( "EPSG:3111", 1 );
|
expected.insert( qMakePair( QStringLiteral( "EPSG:3111" ), QStringLiteral( "EPSG:3113" ) ), qMakePair( 1, 2 ) );
|
||||||
QCOMPARE( original.destinationDatumTransforms(), expected );
|
QCOMPARE( original.sourceDestinationDatumTransforms(), expected );
|
||||||
QCOMPARE( copy2.destinationDatumTransforms(), expected );
|
QCOMPARE( copy2.sourceDestinationDatumTransforms(), expected );
|
||||||
|
|
||||||
copy2.addDestinationDatumTransform( QgsCoordinateReferenceSystem( 3111 ), 3 );
|
copy2.addSourceDestinationDatumTransform( QgsCoordinateReferenceSystem( 3111 ), QgsCoordinateReferenceSystem( 3113 ), 3, 4 );
|
||||||
QCOMPARE( original.destinationDatumTransforms(), expected );
|
QCOMPARE( original.sourceDestinationDatumTransforms(), expected );
|
||||||
expected.insert( "EPSG:3111", 3 );
|
expected.insert( qMakePair( QStringLiteral( "EPSG:3111" ), QStringLiteral( "EPSG:3113" ) ), qMakePair( 3, 4 ) );
|
||||||
QCOMPARE( copy2.destinationDatumTransforms(), expected );
|
QCOMPARE( copy2.sourceDestinationDatumTransforms(), expected );
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ app = start_app()
|
|||||||
|
|
||||||
class TestQgsCoordinateTransformContext(unittest.TestCase):
|
class TestQgsCoordinateTransformContext(unittest.TestCase):
|
||||||
|
|
||||||
|
@unittest.skip('ifdefed out in c++ until required')
|
||||||
def testSourceDatumTransforms(self):
|
def testSourceDatumTransforms(self):
|
||||||
context = QgsCoordinateTransformContext()
|
context = QgsCoordinateTransformContext()
|
||||||
self.assertEqual(context.sourceDatumTransforms(), {})
|
self.assertEqual(context.sourceDatumTransforms(), {})
|
||||||
@ -58,6 +59,7 @@ class TestQgsCoordinateTransformContext(unittest.TestCase):
|
|||||||
context.clear()
|
context.clear()
|
||||||
self.assertEqual(context.sourceDatumTransforms(), {})
|
self.assertEqual(context.sourceDatumTransforms(), {})
|
||||||
|
|
||||||
|
@unittest.skip('ifdefed out in c++ until required')
|
||||||
def testDestDatumTransforms(self):
|
def testDestDatumTransforms(self):
|
||||||
context = QgsCoordinateTransformContext()
|
context = QgsCoordinateTransformContext()
|
||||||
self.assertEqual(context.destinationDatumTransforms(), {})
|
self.assertEqual(context.destinationDatumTransforms(), {})
|
||||||
@ -171,6 +173,7 @@ class TestQgsCoordinateTransformContext(unittest.TestCase):
|
|||||||
context.clear()
|
context.clear()
|
||||||
self.assertEqual(context.sourceDestinationDatumTransforms(), {})
|
self.assertEqual(context.sourceDestinationDatumTransforms(), {})
|
||||||
|
|
||||||
|
@unittest.skip('ifdefed out in c++ until required')
|
||||||
def testCalculate(self):
|
def testCalculate(self):
|
||||||
context = QgsCoordinateTransformContext()
|
context = QgsCoordinateTransformContext()
|
||||||
|
|
||||||
@ -217,7 +220,30 @@ class TestQgsCoordinateTransformContext(unittest.TestCase):
|
|||||||
QgsCoordinateReferenceSystem('EPSG:3111')),
|
QgsCoordinateReferenceSystem('EPSG:3111')),
|
||||||
(1, -1))
|
(1, -1))
|
||||||
|
|
||||||
def testWriteReadXml(self):
|
def testCalculateSourceDest(self):
|
||||||
|
context = QgsCoordinateTransformContext()
|
||||||
|
|
||||||
|
#empty context
|
||||||
|
self.assertEqual(context.calculateDatumTransforms(QgsCoordinateReferenceSystem('EPSG:3111'),
|
||||||
|
QgsCoordinateReferenceSystem('EPSG:4283')),
|
||||||
|
(-1, -1))
|
||||||
|
|
||||||
|
#add specific source/dest pair - should take precedence
|
||||||
|
context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:28356'),
|
||||||
|
QgsCoordinateReferenceSystem('EPSG:4283'),
|
||||||
|
3, 4)
|
||||||
|
self.assertEqual(context.calculateDatumTransforms(QgsCoordinateReferenceSystem('EPSG:28356'),
|
||||||
|
QgsCoordinateReferenceSystem('EPSG:4283')),
|
||||||
|
(3, 4))
|
||||||
|
self.assertEqual(context.calculateDatumTransforms(QgsCoordinateReferenceSystem('EPSG:3111'),
|
||||||
|
QgsCoordinateReferenceSystem('EPSG:4283')),
|
||||||
|
(-1, -1))
|
||||||
|
self.assertEqual(context.calculateDatumTransforms(QgsCoordinateReferenceSystem('EPSG:28356'),
|
||||||
|
QgsCoordinateReferenceSystem('EPSG:3111')),
|
||||||
|
(-1, -1))
|
||||||
|
|
||||||
|
@unittest.skip('ifdefed out in c++ until required')
|
||||||
|
def testWriteReadXmlSingleVariant(self):
|
||||||
# setup a context
|
# setup a context
|
||||||
context = QgsCoordinateTransformContext()
|
context = QgsCoordinateTransformContext()
|
||||||
self.assertTrue(context.addSourceDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'), 1))
|
self.assertTrue(context.addSourceDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'), 1))
|
||||||
@ -249,6 +275,30 @@ class TestQgsCoordinateTransformContext(unittest.TestCase):
|
|||||||
self.assertEqual(context2.sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): (1, 2),
|
self.assertEqual(context2.sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): (1, 2),
|
||||||
('EPSG:28356', 'EPSG:4283'): (3, 4)})
|
('EPSG:28356', 'EPSG:4283'): (3, 4)})
|
||||||
|
|
||||||
|
def testWriteReadXml(self):
|
||||||
|
# setup a context
|
||||||
|
context = QgsCoordinateTransformContext()
|
||||||
|
self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
|
||||||
|
QgsCoordinateReferenceSystem('EPSG:4283'), 1, 2))
|
||||||
|
self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:28356'),
|
||||||
|
QgsCoordinateReferenceSystem(4283), 3, 4))
|
||||||
|
|
||||||
|
self.assertEqual(context.sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): (1, 2),
|
||||||
|
('EPSG:28356', 'EPSG:4283'): (3, 4)})
|
||||||
|
|
||||||
|
# save to xml
|
||||||
|
doc = QDomDocument("testdoc")
|
||||||
|
elem = doc.createElement("test")
|
||||||
|
context.writeXml(elem, doc, QgsReadWriteContext())
|
||||||
|
|
||||||
|
# restore from xml
|
||||||
|
context2 = QgsCoordinateTransformContext()
|
||||||
|
context2.readXml(elem, doc, QgsReadWriteContext())
|
||||||
|
|
||||||
|
# check result
|
||||||
|
self.assertEqual(context2.sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): (1, 2),
|
||||||
|
('EPSG:28356', 'EPSG:4283'): (3, 4)})
|
||||||
|
|
||||||
def testProject(self):
|
def testProject(self):
|
||||||
"""
|
"""
|
||||||
Test project's transform context
|
Test project's transform context
|
||||||
@ -256,10 +306,11 @@ class TestQgsCoordinateTransformContext(unittest.TestCase):
|
|||||||
project = QgsProject()
|
project = QgsProject()
|
||||||
context_changed_spy = QSignalSpy(project.transformContextChanged)
|
context_changed_spy = QSignalSpy(project.transformContextChanged)
|
||||||
context = project.transformContext()
|
context = project.transformContext()
|
||||||
context.addSourceDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'), 1)
|
context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
|
||||||
|
QgsCoordinateReferenceSystem('EPSG:4283'), 1, 2)
|
||||||
project.setTransformContext(context)
|
project.setTransformContext(context)
|
||||||
self.assertEqual(len(context_changed_spy), 1)
|
self.assertEqual(len(context_changed_spy), 1)
|
||||||
self.assertEqual(project.transformContext().sourceDatumTransforms(), {'EPSG:3111': 1})
|
self.assertEqual(project.transformContext().sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): (1, 2)})
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user