30
30
#include < qgsapplication.h>
31
31
#include < qgsgeometry.h>
32
32
#include < qgspoint.h>
33
+ #include " qgspointv2.h"
33
34
34
35
// qgs unit test utility class
35
36
#include " qgsrenderchecker.h"
@@ -50,6 +51,9 @@ class TestQgsGeometry : public QObject
50
51
void init ();// will be called before each testfunction is executed.
51
52
void cleanup ();// will be called after every testfunction.
52
53
54
+ void copy ();
55
+ void assignment ();
56
+
53
57
void fromQgsPoint ();
54
58
void fromQPoint ();
55
59
void fromQPolygonF ();
@@ -207,6 +211,51 @@ void TestQgsGeometry::cleanup()
207
211
delete mpPainter;
208
212
}
209
213
214
+ void TestQgsGeometry::copy ()
215
+ {
216
+ // create a point geometry
217
+ QgsGeometry original ( new QgsPointV2 ( 1.0 , 2.0 ) );
218
+ QCOMPARE ( original.geometry ()->vertexAt ( QgsVertexId ( 0 , 0 , 0 ) ).x (), 1.0 );
219
+ QCOMPARE ( original.geometry ()->vertexAt ( QgsVertexId ( 0 , 0 , 0 ) ).y (), 2.0 );
220
+
221
+ // implicitly shared copy
222
+ QgsGeometry copy ( original );
223
+ QCOMPARE ( copy.geometry ()->vertexAt ( QgsVertexId ( 0 , 0 , 0 ) ).x (), 1.0 );
224
+ QCOMPARE ( copy.geometry ()->vertexAt ( QgsVertexId ( 0 , 0 , 0 ) ).y (), 2.0 );
225
+
226
+ // trigger a detach
227
+ copy.setGeometry ( new QgsPointV2 ( 3.0 , 4.0 ) );
228
+ QCOMPARE ( copy.geometry ()->vertexAt ( QgsVertexId ( 0 , 0 , 0 ) ).x (), 3.0 );
229
+ QCOMPARE ( copy.geometry ()->vertexAt ( QgsVertexId ( 0 , 0 , 0 ) ).y (), 4.0 );
230
+
231
+ // make sure original was untouched
232
+ QCOMPARE ( original.geometry ()->vertexAt ( QgsVertexId ( 0 , 0 , 0 ) ).x (), 1.0 );
233
+ QCOMPARE ( original.geometry ()->vertexAt ( QgsVertexId ( 0 , 0 , 0 ) ).y (), 2.0 );
234
+ }
235
+
236
+ void TestQgsGeometry::assignment ()
237
+ {
238
+ // create a point geometry
239
+ QgsGeometry original ( new QgsPointV2 ( 1.0 , 2.0 ) );
240
+ QCOMPARE ( original.geometry ()->vertexAt ( QgsVertexId ( 0 , 0 , 0 ) ).x (), 1.0 );
241
+ QCOMPARE ( original.geometry ()->vertexAt ( QgsVertexId ( 0 , 0 , 0 ) ).y (), 2.0 );
242
+
243
+ // assign to implicitly shared copy
244
+ QgsGeometry copy;
245
+ copy = original;
246
+ QCOMPARE ( copy.geometry ()->vertexAt ( QgsVertexId ( 0 , 0 , 0 ) ).x (), 1.0 );
247
+ QCOMPARE ( copy.geometry ()->vertexAt ( QgsVertexId ( 0 , 0 , 0 ) ).y (), 2.0 );
248
+
249
+ // trigger a detach
250
+ copy.setGeometry ( new QgsPointV2 ( 3.0 , 4.0 ) );
251
+ QCOMPARE ( copy.geometry ()->vertexAt ( QgsVertexId ( 0 , 0 , 0 ) ).x (), 3.0 );
252
+ QCOMPARE ( copy.geometry ()->vertexAt ( QgsVertexId ( 0 , 0 , 0 ) ).y (), 4.0 );
253
+
254
+ // make sure original was untouched
255
+ QCOMPARE ( original.geometry ()->vertexAt ( QgsVertexId ( 0 , 0 , 0 ) ).x (), 1.0 );
256
+ QCOMPARE ( original.geometry ()->vertexAt ( QgsVertexId ( 0 , 0 , 0 ) ).y (), 2.0 );
257
+ }
258
+
210
259
void TestQgsGeometry::fromQgsPoint ()
211
260
{
212
261
QgsPoint point ( 1.0 , 2.0 );
0 commit comments