@@ -93,12 +93,126 @@ void TestQgsOgcUtils::testGeometryFromGML()
9393 QVERIFY ( geomBox->wkbType () == QGis::WKBPolygon );
9494}
9595
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+
96206void TestQgsOgcUtils::testGeometryToGML ()
97207{
98208 QDomDocument doc;
99209 QSharedPointer<QgsGeometry> geomPoint ( QgsGeometry::fromPoint ( QgsPoint ( 111 , 222 ) ) );
100210 QSharedPointer<QgsGeometry> geomLine ( QgsGeometry::fromWkt ( " LINESTRING(111 222, 222 222)" ) );
101211
212+ // Elements to compare
213+ QDomElement xmlElem;
214+ QDomElement ogcElem;
215+
102216 // Test GML2
103217 QDomElement elemInvalid = QgsOgcUtils::geometryToGML ( 0 , doc );
104218 QVERIFY ( elemInvalid.isNull () );
@@ -107,14 +221,18 @@ void TestQgsOgcUtils::testGeometryToGML()
107221 QVERIFY ( !elemPoint.isNull () );
108222
109223 doc.appendChild ( elemPoint );
110- QCOMPARE ( doc.toString ( -1 ), QString ( " <gml:Point><gml:coordinates cs=\" ,\" ts=\" \" >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 ) );
111227 doc.removeChild ( elemPoint );
112228
113229 QDomElement elemLine = QgsOgcUtils::geometryToGML ( geomLine.data (), doc );
114230 QVERIFY ( !elemLine.isNull () );
115231
116232 doc.appendChild ( elemLine );
117- QCOMPARE ( doc.toString ( -1 ), QString ( " <gml:LineString><gml:coordinates cs=\" ,\" ts=\" \" >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 ) );
118236 doc.removeChild ( elemLine );
119237
120238 // Test GML3
@@ -125,14 +243,18 @@ void TestQgsOgcUtils::testGeometryToGML()
125243 QVERIFY ( !elemPoint.isNull () );
126244
127245 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 ) );
129249 doc.removeChild ( elemPoint );
130250
131251 elemLine = QgsOgcUtils::geometryToGML ( geomLine.data (), doc, " GML3" );
132252 QVERIFY ( !elemLine.isNull () );
133253
134254 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 ) );
136258 doc.removeChild ( elemLine );
137259}
138260
@@ -287,7 +409,10 @@ void TestQgsOgcUtils::testExpressionToOgcFilter()
287409 qDebug ( " EXPR: %s" , exp.expression ().toAscii ().data () );
288410 qDebug ( " OGC : %s" , doc.toString ( -1 ).toAscii ().data () );
289411
290- QCOMPARE ( xmlText, doc.toString ( -1 ) );
412+
413+ QDomElement xmlElem = comparableElement ( xmlText );
414+ QDomElement ogcElem = comparableElement ( doc.toString ( -1 ) );
415+ QVERIFY ( compareElements ( xmlElem, ogcElem ) );
291416}
292417
293418void TestQgsOgcUtils::testExpressionToOgcFilter_data ()
@@ -449,7 +574,10 @@ void TestQgsOgcUtils::testExpressionToOgcFilterWFS11()
449574 qDebug ( " SRSNAME: %s" , srsName.toAscii ().data () );
450575 qDebug ( " OGC : %s" , doc.toString ( -1 ).toAscii ().data () );
451576
452- QCOMPARE ( xmlText, doc.toString ( -1 ) );
577+
578+ QDomElement xmlElem = comparableElement ( xmlText );
579+ QDomElement ogcElem = comparableElement ( doc.toString ( -1 ) );
580+ QVERIFY ( compareElements ( xmlElem, ogcElem ) );
453581}
454582
455583void TestQgsOgcUtils::testExpressionToOgcFilterWFS11_data ()
@@ -473,14 +601,6 @@ void TestQgsOgcUtils::testExpressionToOgcFilterWFS11_data()
473601 " </ogc:Filter>" );
474602}
475603
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-
484604void TestQgsOgcUtils::testExpressionToOgcFilterWFS20 ()
485605{
486606 QFETCH ( QString, exprText );
@@ -506,15 +626,9 @@ void TestQgsOgcUtils::testExpressionToOgcFilterWFS20()
506626 qDebug ( " SRSNAME: %s" , srsName.toAscii ().data () );
507627 qDebug ( " OGC : %s" , doc.toString ( -1 ).toAscii ().data () );
508628
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 ) );
518632}
519633
520634void TestQgsOgcUtils::testExpressionToOgcFilterWFS20_data ()
@@ -614,15 +728,9 @@ void TestQgsOgcUtils::testSQLStatementToOgcFilter()
614728 filterVersion == QgsOgcUtils::FILTER_FES_2_0 ? " FES 2.0" : " unknown" );
615729 qDebug ( " OGC : %s" , doc.toString ( -1 ).toAscii ().data () );
616730
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 ) );
626734}
627735
628736void TestQgsOgcUtils::testSQLStatementToOgcFilter_data ()
0 commit comments