Skip to content

Commit f55da4a

Browse files
committed
Update unit tests
1 parent 670858d commit f55da4a

File tree

2 files changed

+71
-22
lines changed

2 files changed

+71
-22
lines changed

tests/src/core/testqgscoordinatetransform.cpp

+17-19
Original file line numberDiff line numberDiff line change
@@ -183,36 +183,34 @@ void TestQgsCoordinateTransform::isShortCircuited()
183183

184184
void TestQgsCoordinateTransform::contextShared()
185185
{
186-
#ifdef singlesourcedest
187186
//test implicit sharing of QgsCoordinateTransformContext
188187
QgsCoordinateTransformContext original;
189-
original.addDestinationDatumTransform( QgsCoordinateReferenceSystem( 3111 ), 1 );
188+
original.addSourceDestinationDatumTransform( QgsCoordinateReferenceSystem( 3111 ), QgsCoordinateReferenceSystem( 3113 ), 1, 2 );
190189

191190
QgsCoordinateTransformContext copy( original );
192-
QMap< QString, int > expected;
193-
expected.insert( "EPSG:3111", 1 );
194-
QCOMPARE( original.destinationDatumTransforms(), expected );
195-
QCOMPARE( copy.destinationDatumTransforms(), expected );
191+
QMap< QPair< QString, QString >, QPair< int, int > > expected;
192+
expected.insert( qMakePair( QStringLiteral( "EPSG:3111" ), QStringLiteral( "EPSG:3113" ) ), qMakePair( 1, 2 ) );
193+
QCOMPARE( original.sourceDestinationDatumTransforms(), expected );
194+
QCOMPARE( copy.sourceDestinationDatumTransforms(), expected );
196195

197196
// trigger detach
198-
copy.addDestinationDatumTransform( QgsCoordinateReferenceSystem( 3111 ), 2 );
199-
QCOMPARE( original.destinationDatumTransforms(), expected );
197+
copy.addSourceDestinationDatumTransform( QgsCoordinateReferenceSystem( 3111 ), QgsCoordinateReferenceSystem( 3113 ), 3, 4 );
198+
QCOMPARE( original.sourceDestinationDatumTransforms(), expected );
200199

201-
expected.insert( "EPSG:3111", 2 );
202-
QCOMPARE( copy.destinationDatumTransforms(), expected );
200+
expected.insert( qMakePair( QStringLiteral( "EPSG:3111" ), QStringLiteral( "EPSG:3113" ) ), qMakePair( 3, 4 ) );
201+
QCOMPARE( copy.sourceDestinationDatumTransforms(), expected );
203202

204203
// copy via assignment
205204
QgsCoordinateTransformContext copy2;
206205
copy2 = original;
207-
expected.insert( "EPSG:3111", 1 );
208-
QCOMPARE( original.destinationDatumTransforms(), expected );
209-
QCOMPARE( copy2.destinationDatumTransforms(), expected );
210-
211-
copy2.addDestinationDatumTransform( QgsCoordinateReferenceSystem( 3111 ), 3 );
212-
QCOMPARE( original.destinationDatumTransforms(), expected );
213-
expected.insert( "EPSG:3111", 3 );
214-
QCOMPARE( copy2.destinationDatumTransforms(), expected );
215-
#endif
206+
expected.insert( qMakePair( QStringLiteral( "EPSG:3111" ), QStringLiteral( "EPSG:3113" ) ), qMakePair( 1, 2 ) );
207+
QCOMPARE( original.sourceDestinationDatumTransforms(), expected );
208+
QCOMPARE( copy2.sourceDestinationDatumTransforms(), expected );
209+
210+
copy2.addSourceDestinationDatumTransform( QgsCoordinateReferenceSystem( 3111 ), QgsCoordinateReferenceSystem( 3113 ), 3, 4 );
211+
QCOMPARE( original.sourceDestinationDatumTransforms(), expected );
212+
expected.insert( qMakePair( QStringLiteral( "EPSG:3111" ), QStringLiteral( "EPSG:3113" ) ), qMakePair( 3, 4 ) );
213+
QCOMPARE( copy2.sourceDestinationDatumTransforms(), expected );
216214
}
217215

218216

tests/src/python/test_qgscoordinatetransformcontext.py

+54-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
class TestQgsCoordinateTransformContext(unittest.TestCase):
2929

30+
@unittest.skip('ifdefed out in c++ until required')
3031
def testSourceDatumTransforms(self):
3132
context = QgsCoordinateTransformContext()
3233
self.assertEqual(context.sourceDatumTransforms(), {})
@@ -58,6 +59,7 @@ def testSourceDatumTransforms(self):
5859
context.clear()
5960
self.assertEqual(context.sourceDatumTransforms(), {})
6061

62+
@unittest.skip('ifdefed out in c++ until required')
6163
def testDestDatumTransforms(self):
6264
context = QgsCoordinateTransformContext()
6365
self.assertEqual(context.destinationDatumTransforms(), {})
@@ -171,6 +173,7 @@ def testSourceDestinationDatumTransforms(self):
171173
context.clear()
172174
self.assertEqual(context.sourceDestinationDatumTransforms(), {})
173175

176+
@unittest.skip('ifdefed out in c++ until required')
174177
def testCalculate(self):
175178
context = QgsCoordinateTransformContext()
176179

@@ -217,7 +220,30 @@ def testCalculate(self):
217220
QgsCoordinateReferenceSystem('EPSG:3111')),
218221
(1, -1))
219222

220-
def testWriteReadXml(self):
223+
def testCalculateSourceDest(self):
224+
context = QgsCoordinateTransformContext()
225+
226+
#empty context
227+
self.assertEqual(context.calculateDatumTransforms(QgsCoordinateReferenceSystem('EPSG:3111'),
228+
QgsCoordinateReferenceSystem('EPSG:4283')),
229+
(-1, -1))
230+
231+
#add specific source/dest pair - should take precedence
232+
context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:28356'),
233+
QgsCoordinateReferenceSystem('EPSG:4283'),
234+
3, 4)
235+
self.assertEqual(context.calculateDatumTransforms(QgsCoordinateReferenceSystem('EPSG:28356'),
236+
QgsCoordinateReferenceSystem('EPSG:4283')),
237+
(3, 4))
238+
self.assertEqual(context.calculateDatumTransforms(QgsCoordinateReferenceSystem('EPSG:3111'),
239+
QgsCoordinateReferenceSystem('EPSG:4283')),
240+
(-1, -1))
241+
self.assertEqual(context.calculateDatumTransforms(QgsCoordinateReferenceSystem('EPSG:28356'),
242+
QgsCoordinateReferenceSystem('EPSG:3111')),
243+
(-1, -1))
244+
245+
@unittest.skip('ifdefed out in c++ until required')
246+
def testWriteReadXmlSingleVariant(self):
221247
# setup a context
222248
context = QgsCoordinateTransformContext()
223249
self.assertTrue(context.addSourceDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'), 1))
@@ -249,17 +275,42 @@ def testWriteReadXml(self):
249275
self.assertEqual(context2.sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): (1, 2),
250276
('EPSG:28356', 'EPSG:4283'): (3, 4)})
251277

278+
def testWriteReadXml(self):
279+
# setup a context
280+
context = QgsCoordinateTransformContext()
281+
self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
282+
QgsCoordinateReferenceSystem('EPSG:4283'), 1, 2))
283+
self.assertTrue(context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:28356'),
284+
QgsCoordinateReferenceSystem(4283), 3, 4))
285+
286+
self.assertEqual(context.sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): (1, 2),
287+
('EPSG:28356', 'EPSG:4283'): (3, 4)})
288+
289+
# save to xml
290+
doc = QDomDocument("testdoc")
291+
elem = doc.createElement("test")
292+
context.writeXml(elem, doc, QgsReadWriteContext())
293+
294+
# restore from xml
295+
context2 = QgsCoordinateTransformContext()
296+
context2.readXml(elem, doc, QgsReadWriteContext())
297+
298+
# check result
299+
self.assertEqual(context2.sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): (1, 2),
300+
('EPSG:28356', 'EPSG:4283'): (3, 4)})
301+
252302
def testProject(self):
253303
"""
254304
Test project's transform context
255305
"""
256306
project = QgsProject()
257307
context_changed_spy = QSignalSpy(project.transformContextChanged)
258308
context = project.transformContext()
259-
context.addSourceDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'), 1)
309+
context.addSourceDestinationDatumTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
310+
QgsCoordinateReferenceSystem('EPSG:4283'), 1, 2)
260311
project.setTransformContext(context)
261312
self.assertEqual(len(context_changed_spy), 1)
262-
self.assertEqual(project.transformContext().sourceDatumTransforms(), {'EPSG:3111': 1})
313+
self.assertEqual(project.transformContext().sourceDestinationDatumTransforms(), {('EPSG:3111', 'EPSG:4283'): (1, 2)})
263314

264315

265316
if __name__ == '__main__':

0 commit comments

Comments
 (0)