@@ -93,12 +93,126 @@ void TestQgsOgcUtils::testGeometryFromGML()
93
93
QVERIFY ( geomBox.wkbType () == QgsWkbTypes::Polygon );
94
94
}
95
95
96
+ static bool compareElements ( QDomElement& element1, QDomElement& element2 )
97
+ {
98
+ QString tag1 = element1.tagName ();
99
+ tag1.replace ( QRegExp ( " .*:" ), " " );
100
+ QString tag2 = element2.tagName ();
101
+ tag2.replace ( QRegExp ( " .*:" ), " " );
102
+ if ( tag1 != tag2 )
103
+ {
104
+ qDebug ( " Different tag names: %s, %s" , tag1.toAscii ().data (), tag2.toAscii ().data () );
105
+ return false ;
106
+ }
107
+
108
+ if ( element1.hasAttributes () != element2.hasAttributes () )
109
+ {
110
+ qDebug ( " Different hasAttributes: %s, %s" , tag1.toAscii ().data (), tag2.toAscii ().data () );
111
+ return false ;
112
+ }
113
+
114
+ if ( element1.hasAttributes () )
115
+ {
116
+ QDomNamedNodeMap attrs1 = element1.attributes ();
117
+ QDomNamedNodeMap attrs2 = element2.attributes ();
118
+
119
+ if ( attrs1.size () != attrs2.size () )
120
+ {
121
+ qDebug ( " Different attributes size: %s, %s" , tag1.toAscii ().data (), tag2.toAscii ().data () );
122
+ return false ;
123
+ }
124
+
125
+ for ( int i = 0 ; i < attrs1.size () ; ++i )
126
+ {
127
+ QDomNode node1 = attrs1.item ( i );
128
+ QDomAttr attr1 = node1.toAttr ();
129
+
130
+ if ( !element2.hasAttribute ( attr1.name () ) )
131
+ {
132
+ qDebug ( " Element2 has not attribute: %s, %s, %s" , tag1.toAscii ().data (), tag2.toAscii ().data (), attr1.name ().toAscii ().data () );
133
+ return false ;
134
+ }
135
+
136
+ if ( element2.attribute ( attr1.name () ) != attr1.value () )
137
+ {
138
+ qDebug ( " Element2 attribute has not the same value: %s, %s, %s" , tag1.toAscii ().data (), tag2.toAscii ().data (), attr1.name ().toAscii ().data () );
139
+ return false ;
140
+ }
141
+ }
142
+ }
143
+
144
+ if ( element1.hasChildNodes () != element2.hasChildNodes () )
145
+ {
146
+ qDebug ( " Different childNodes: %s, %s" , tag1.toAscii ().data (), tag2.toAscii ().data () );
147
+ return false ;
148
+ }
149
+
150
+ if ( element1.hasChildNodes () )
151
+ {
152
+ QDomNodeList nodes1 = element1.childNodes ();
153
+ QDomNodeList nodes2 = element2.childNodes ();
154
+
155
+ if ( nodes1.size () != nodes2.size () )
156
+ {
157
+ qDebug ( " Different childNodes size: %s, %s" , tag1.toAscii ().data (), tag2.toAscii ().data () );
158
+ return false ;
159
+ }
160
+
161
+ for ( int i = 0 ; i < nodes1.size () ; ++i )
162
+ {
163
+ QDomNode node1 = nodes1.at ( i );
164
+ QDomNode node2 = nodes2.at ( i );
165
+ if ( node1.isElement () && node2.isElement () )
166
+ {
167
+ QDomElement elt1 = node1.toElement ();
168
+ QDomElement elt2 = node2.toElement ();
169
+
170
+ if ( !compareElements ( elt1, elt2 ) )
171
+ return false ;
172
+ }
173
+ else if ( node1.isText () && node2.isText () )
174
+ {
175
+ QDomText txt1 = node1.toText ();
176
+ QDomText txt2 = node2.toText ();
177
+
178
+ if ( txt1.data () != txt2.data () )
179
+ {
180
+ qDebug ( " Different text data: %s %s" , tag1.toAscii ().data (), txt1.data ().toAscii ().data () );
181
+ qDebug ( " Different text data: %s %s" , tag2.toAscii ().data (), txt2.data ().toAscii ().data () );
182
+ return false ;
183
+ }
184
+ }
185
+ }
186
+ }
187
+
188
+ if ( element1.text () != element2.text () )
189
+ {
190
+ qDebug ( " Different text: %s %s" , tag1.toAscii ().data (), element1.text ().toAscii ().data () );
191
+ qDebug ( " Different text: %s %s" , tag2.toAscii ().data (), element2.text ().toAscii ().data () );
192
+ return false ;
193
+ }
194
+
195
+ return true ;
196
+ }
197
+ static QDomElement comparableElement ( const QString& xmlText )
198
+ {
199
+ QDomDocument doc;
200
+ if ( !doc.setContent ( xmlText ) )
201
+ return QDomElement ();
202
+ return doc.documentElement ();
203
+ }
204
+
205
+
96
206
void TestQgsOgcUtils::testGeometryToGML ()
97
207
{
98
208
QDomDocument doc;
99
209
QgsGeometry geomPoint ( QgsGeometry::fromPoint ( QgsPoint ( 111 , 222 ) ) );
100
210
QgsGeometry geomLine ( QgsGeometry::fromWkt ( " LINESTRING(111 222, 222 222)" ) );
101
211
212
+ // Elements to compare
213
+ QDomElement xmlElem;
214
+ QDomElement ogcElem;
215
+
102
216
// Test GML2
103
217
QDomElement elemInvalid = QgsOgcUtils::geometryToGML ( 0 , doc );
104
218
QVERIFY ( elemInvalid.isNull () );
@@ -107,14 +221,18 @@ void TestQgsOgcUtils::testGeometryToGML()
107
221
QVERIFY ( !elemPoint.isNull () );
108
222
109
223
doc.appendChild ( elemPoint );
110
- QCOMPARE ( doc.toString ( -1 ), QString ( " <gml:Point><gml:coordinates ts=\" \" cs=\" ,\" >111,222</gml:coordinates></gml:Point>" ) );
224
+ xmlElem = comparableElement ( QString ( " <gml:Point><gml:coordinates ts=\" \" cs=\" ,\" >111,222</gml:coordinates></gml:Point>" ) );
225
+ ogcElem = comparableElement ( doc.toString ( -1 ) );
226
+ QVERIFY ( compareElements ( xmlElem, ogcElem ) );
111
227
doc.removeChild ( elemPoint );
112
228
113
229
QDomElement elemLine = QgsOgcUtils::geometryToGML ( &geomLine, doc );
114
230
QVERIFY ( !elemLine.isNull () );
115
231
116
232
doc.appendChild ( elemLine );
117
- QCOMPARE ( doc.toString ( -1 ), QString ( " <gml:LineString><gml:coordinates ts=\" \" cs=\" ,\" >111,222 222,222</gml:coordinates></gml:LineString>" ) );
233
+ xmlElem = comparableElement ( QString ( " <gml:LineString><gml:coordinates ts=\" \" cs=\" ,\" >111,222 222,222</gml:coordinates></gml:LineString>" ) );
234
+ ogcElem = comparableElement ( doc.toString ( -1 ) );
235
+ QVERIFY ( compareElements ( xmlElem, ogcElem ) );
118
236
doc.removeChild ( elemLine );
119
237
120
238
// Test GML3
@@ -125,14 +243,18 @@ void TestQgsOgcUtils::testGeometryToGML()
125
243
QVERIFY ( !elemPoint.isNull () );
126
244
127
245
doc.appendChild ( elemPoint );
128
- QCOMPARE ( doc.toString ( -1 ), QString ( " <gml:Point><gml:pos srsDimension=\" 2\" >111 222</gml:pos></gml:Point>" ) );
246
+ xmlElem = comparableElement ( QString ( " <gml:Point><gml:pos srsDimension=\" 2\" >111 222</gml:pos></gml:Point>" ) );
247
+ ogcElem = comparableElement ( doc.toString ( -1 ) );
248
+ QVERIFY ( compareElements ( xmlElem, ogcElem ) );
129
249
doc.removeChild ( elemPoint );
130
250
131
251
elemLine = QgsOgcUtils::geometryToGML ( &geomLine, doc, " GML3" );
132
252
QVERIFY ( !elemLine.isNull () );
133
253
134
254
doc.appendChild ( elemLine );
135
- QCOMPARE ( doc.toString ( -1 ), QString ( " <gml:LineString><gml:posList srsDimension=\" 2\" >111 222 222 222</gml:posList></gml:LineString>" ) );
255
+ xmlElem = comparableElement ( QString ( " <gml:LineString><gml:posList srsDimension=\" 2\" >111 222 222 222</gml:posList></gml:LineString>" ) );
256
+ ogcElem = comparableElement ( doc.toString ( -1 ) );
257
+ QVERIFY ( compareElements ( xmlElem, ogcElem ) );
136
258
doc.removeChild ( elemLine );
137
259
}
138
260
@@ -287,7 +409,10 @@ void TestQgsOgcUtils::testExpressionToOgcFilter()
287
409
qDebug ( " EXPR: %s" , exp.expression ().toAscii ().data () );
288
410
qDebug ( " OGC : %s" , doc.toString ( -1 ).toAscii ().data () );
289
411
290
- QCOMPARE ( xmlText, doc.toString ( -1 ) );
412
+
413
+ QDomElement xmlElem = comparableElement ( xmlText );
414
+ QDomElement ogcElem = comparableElement ( doc.toString ( -1 ) );
415
+ QVERIFY ( compareElements ( xmlElem, ogcElem ) );
291
416
}
292
417
293
418
void TestQgsOgcUtils::testExpressionToOgcFilter_data ()
@@ -449,7 +574,10 @@ void TestQgsOgcUtils::testExpressionToOgcFilterWFS11()
449
574
qDebug ( " SRSNAME: %s" , srsName.toAscii ().data () );
450
575
qDebug ( " OGC : %s" , doc.toString ( -1 ).toAscii ().data () );
451
576
452
- QCOMPARE ( xmlText, doc.toString ( -1 ) );
577
+
578
+ QDomElement xmlElem = comparableElement ( xmlText );
579
+ QDomElement ogcElem = comparableElement ( doc.toString ( -1 ) );
580
+ QVERIFY ( compareElements ( xmlElem, ogcElem ) );
453
581
}
454
582
455
583
void TestQgsOgcUtils::testExpressionToOgcFilterWFS11_data ()
@@ -473,14 +601,6 @@ void TestQgsOgcUtils::testExpressionToOgcFilterWFS11_data()
473
601
" </ogc:Filter>" );
474
602
}
475
603
476
- static QString normalizeXML ( const QString& xmlText )
477
- {
478
- QDomDocument doc;
479
- if ( !doc.setContent ( xmlText, true ) )
480
- return QString ();
481
- return doc.toString ( -1 );
482
- }
483
-
484
604
void TestQgsOgcUtils::testExpressionToOgcFilterWFS20 ()
485
605
{
486
606
QFETCH ( QString, exprText );
@@ -506,15 +626,9 @@ void TestQgsOgcUtils::testExpressionToOgcFilterWFS20()
506
626
qDebug ( " SRSNAME: %s" , srsName.toAscii ().data () );
507
627
qDebug ( " OGC : %s" , doc.toString ( -1 ).toAscii ().data () );
508
628
509
- QString normalizedExpected ( normalizeXML ( xmlText ) );
510
- QString normalizedGot ( normalizeXML ( doc.toString ( -1 ) ) );
511
-
512
- if ( normalizedExpected != normalizedGot )
513
- {
514
- qDebug ( " Normalized expected: %s" , normalizedExpected.toAscii ().data () );
515
- qDebug ( " Normalized got: %s" , normalizedGot.toAscii ().data () );
516
- }
517
- QCOMPARE ( normalizedExpected, normalizedGot );
629
+ QDomElement xmlElem = comparableElement ( xmlText );
630
+ QDomElement ogcElem = comparableElement ( doc.toString ( -1 ) );
631
+ QVERIFY ( compareElements ( xmlElem, ogcElem ) );
518
632
}
519
633
520
634
void TestQgsOgcUtils::testExpressionToOgcFilterWFS20_data ()
@@ -614,15 +728,9 @@ void TestQgsOgcUtils::testSQLStatementToOgcFilter()
614
728
filterVersion == QgsOgcUtils::FILTER_FES_2_0 ? " FES 2.0" : " unknown" );
615
729
qDebug ( " OGC : %s" , doc.toString ( -1 ).toAscii ().data () );
616
730
617
- QString normalizedExpected ( normalizeXML ( xmlText ) );
618
- QString normalizedGot ( normalizeXML ( doc.toString ( -1 ) ) );
619
-
620
- if ( normalizedExpected != normalizedGot )
621
- {
622
- qDebug ( " Normalized expected: %s" , normalizedExpected.toAscii ().data () );
623
- qDebug ( " Normalized got: %s" , normalizedGot.toAscii ().data () );
624
- }
625
- QCOMPARE ( normalizedExpected, normalizedGot );
731
+ QDomElement xmlElem = comparableElement ( xmlText );
732
+ QDomElement ogcElem = comparableElement ( doc.toString ( -1 ) );
733
+ QVERIFY ( compareElements ( xmlElem, ogcElem ) );
626
734
}
627
735
628
736
void TestQgsOgcUtils::testSQLStatementToOgcFilter_data ()
0 commit comments