From c69e5c1dba8f50b471bfa7389961eaa9b77bed70 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Wed, 8 May 2013 16:41:45 +0200 Subject: [PATCH] Use xmleql in the KML tests This also involves some modifications to the xmleql functionality now that it was tested with a real-life case (KML). Also, some of the input KML files needed to be changed since we currently cannot roundtrip 100% of the input. --- test/expect-0.2.0-ol3/expect.js | 48 ++++++----- test/spec/ol/parser/kml.test.js | 98 +++++------------------ test/spec/ol/parser/kml/iconstyle.kml | 7 +- test/spec/ol/parser/kml/linestring.kml | 13 --- test/spec/ol/parser/kml/multigeometry.kml | 1 - test/spec/ol/parser/kml/point.kml | 18 +++-- test/spec/ol/parser/kml/polygon.kml | 4 +- 7 files changed, 62 insertions(+), 127 deletions(-) diff --git a/test/expect-0.2.0-ol3/expect.js b/test/expect-0.2.0-ol3/expect.js index 595eedf312..229d496c7a 100644 --- a/test/expect-0.2.0-ol3/expect.js +++ b/test/expect-0.2.0-ol3/expect.js @@ -250,9 +250,10 @@ // for text nodes compare value if (node1.nodeType === 3) { try { - expect(node1.nodeValue).to.equal(node2.nodeValue); + // TODO should we make this optional? + expect(node1.nodeValue.replace(/\s/g, '')).to.equal(node2.nodeValue.replace(/\s/g, '')); } catch(e) { - errors.push('nodeValue test failed for: ' + node1.nodeName + ' | ' + e.message); + errors.push('nodeValue test failed | ' + e.message); } } // for element type nodes compare namespace, attributes, and children @@ -281,23 +282,27 @@ var node2Attr = {}; var ga, ea, gn, en; var i, ii; - for (i=0, ii=node1.attributes.length; iPolygon.kml0' + - 'hollow box' + - '-122.366278,37.818844,30 ' + - '-122.365248,37.819267,30 ' + - '-122.36564,37.819861,30 ' + - '-122.366669,37.819429,30 ' + - '-122.366278,37.818844,30' + - '' + - '-122.366212,37.818977,30 ' + - '-122.365424,37.819294,30 ' + - '-122.365704,37.819731,30 ' + - '-122.366488,37.819402,30 ' + - '-122.366212,37.818977,30' + - ''; - expect(output).to.eql(expected); + expect(xml).to.xmleql(goog.dom.xml.loadXml(output)); expect(obj.features.length).to.eql(1); var geom = obj.features[0].getGeometry(); expect(geom instanceof ol.geom.Polygon).to.be.ok(); @@ -37,14 +22,7 @@ describe('ol.parser.kml', function() { afterLoadXml(url, function(xml) { var obj = parser.read(xml); var output = parser.write(obj); - var expected = '' + - 'LineString.kml1' + - 'unextruded-122.364383,' + - '37.824664,0 -122.364152,37.824322,0' + - 'extruded' + - '-122.364167,37.824787,50 -122.363917,37.824423,50' + - ''; - expect(output).to.eql(expected); + expect(xml).to.xmleql(goog.dom.xml.loadXml(output)); expect(obj.features.length).to.eql(2); var geom = obj.features[0].getGeometry(); expect(geom instanceof ol.geom.LineString).to.be.ok(); @@ -58,13 +36,7 @@ describe('ol.parser.kml', function() { afterLoadXml(url, function(xml) { var obj = parser.read(xml); var output = parser.write(obj); - var expected = '' + - 'Simple placemark' + - 'Attached to the ground. Intelligently places itself \n' + - ' at the height of the underlying terrain.' + - '-122.0822035425683,37.42228990140251,0' + - ''; - expect(output).to.eql(expected); + expect(xml).to.xmleql(goog.dom.xml.loadXml(output)); expect(obj.features.length).to.eql(1); var geom = obj.features[0].getGeometry(); expect(geom instanceof ol.geom.Point).to.be.ok(); @@ -131,17 +103,8 @@ describe('ol.parser.kml', function() { afterLoadXml(url, function(xml) { var obj = parser.read(xml); var geom = obj.features[0].getGeometry(); - var expected = '' + - 'Polygon.kml0' + - 'SF Marina Harbor Master' + - '-122.4425587930444,37.80666418607323,0 ' + - '-122.4428379594768,37.80663578323093,0' + - '-122.4425509770566,' + - '37.80662588061205,0 -122.4428340530617,37.8065999493009,0' + - '' + - ''; var output = parser.write(obj); - expect(output).to.eql(expected); + expect(xml).to.xmleql(goog.dom.xml.loadXml(output)); expect(geom instanceof ol.geom.MultiLineString).to.be.ok(); }); }); @@ -193,20 +156,16 @@ describe('ol.parser.kml', function() { expect(obj.features[0].get('name')).to.eql('Pezinok'); }); it('Test line style', function() { - var test_style = ' ' + - ' ' + ' -112,36 -113,37 ' + - ''; + ''; var p = new ol.parser.KML({extractStyles: true}); var obj = p.read(test_style); var output = p.write(obj); - var expected = '' + - '' + - '-112,36 -113,37' + - ''; - expect(output).to.eql(expected); + expect(goog.dom.xml.loadXml(test_style)).to.xmleql( + goog.dom.xml.loadXml(output)); var symbolizer = obj.features[0].getSymbolizerLiterals()[0]; expect(symbolizer instanceof ol.style.LineLiteral).to.be.ok(); expect(symbolizer.strokeColor).to.eql('#ff0000'); @@ -214,8 +173,8 @@ describe('ol.parser.kml', function() { expect(symbolizer.strokeWidth).to.eql(10); }); it('Test style fill', function() { - var test_style_fill = ' ' + - ' ' + '' + '5.001370157823406,49.26855713824488 8.214706453896161,' + @@ -228,25 +187,20 @@ describe('ol.parser.kml', function() { '5.001370157823406,49.26855713824488 8.214706453896161,' + '49.630662409673505 8.397385910100951,48.45172350357396 ' + '5.001370157823406,49.26855713824488' + - ''; - var p = new ol.parser.KML({extractStyles: true}); - var obj = p.read(test_style_fill); - var output = p.write(obj); - var expected = '' + - '' + - '5.001370157823406,' + - '49.26855713824488 8.214706453896161,49.630662409673505 ' + - '8.397385910100951,48.45172350357396 5.001370157823406,' + - '49.26855713824488' + - '' + + ''; + var style_fill_write = ' ' + + ' ' + '' + '5.001370157823406,49.26855713824488 8.214706453896161,' + '49.630662409673505 8.397385910100951,48.45172350357396 ' + '5.001370157823406,49.26855713824488' + ''; - expect(output).to.eql(expected); + var p = new ol.parser.KML({extractStyles: true}); + var obj = p.read(test_style_fill); + var output = p.write(p.read(style_fill_write)); + expect(goog.dom.xml.loadXml(style_fill_write)).to.xmleql( + goog.dom.xml.loadXml(output)); var symbolizer1 = obj.features[0].getSymbolizerLiterals()[0]; var symbolizer2 = obj.features[1].getSymbolizerLiterals()[0]; expect(symbolizer1.fillColor).to.eql('#ff0000'); @@ -258,15 +212,7 @@ describe('ol.parser.kml', function() { var p = new ol.parser.KML({extractStyles: true}); var obj = p.read(xml); var output = p.write(obj); - var expected = '' + - '' + - 'Pin on a mountaintop' + - '#pushpin170.1435558771009,' + - '-43.60505741890396,0' + - ''; - expect(output).to.eql(expected); + expect(xml).to.xmleql(goog.dom.xml.loadXml(output)); var symbolizer = obj.features[0].getSymbolizerLiterals()[0]; var url = 'http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png'; expect(symbolizer.url).to.eql(url); @@ -277,7 +223,7 @@ describe('ol.parser.kml', function() { }); }); -goog.require('goog.net.XhrIo'); +goog.require('goog.dom.xml'); goog.require('ol.Feature'); goog.require('ol.geom.GeometryCollection'); diff --git a/test/spec/ol/parser/kml/iconstyle.kml b/test/spec/ol/parser/kml/iconstyle.kml index 493ac02094..6f507e7615 100644 --- a/test/spec/ol/parser/kml/iconstyle.kml +++ b/test/spec/ol/parser/kml/iconstyle.kml @@ -2,17 +2,12 @@ - + Pin on a mountaintop #pushpin diff --git a/test/spec/ol/parser/kml/linestring.kml b/test/spec/ol/parser/kml/linestring.kml index 01a941a07b..0b18e18ece 100644 --- a/test/spec/ol/parser/kml/linestring.kml +++ b/test/spec/ol/parser/kml/linestring.kml @@ -3,19 +3,9 @@ LineString.kml 1 - - -122.36415 - 37.824553 - 0 - 150 - 50 - 0 - unextruded - 1 - 1 -122.364383,37.824664,0 -122.364152,37.824322,0 @@ -24,9 +14,6 @@ extruded - 1 - 1 - relativeToGround -122.364167,37.824787,50 -122.363917,37.824423,50 diff --git a/test/spec/ol/parser/kml/multigeometry.kml b/test/spec/ol/parser/kml/multigeometry.kml index d24379886f..c821787c6f 100644 --- a/test/spec/ol/parser/kml/multigeometry.kml +++ b/test/spec/ol/parser/kml/multigeometry.kml @@ -5,7 +5,6 @@ 0 SF Marina Harbor Master - 0 diff --git a/test/spec/ol/parser/kml/point.kml b/test/spec/ol/parser/kml/point.kml index f95894ff73..81a8ff193c 100644 --- a/test/spec/ol/parser/kml/point.kml +++ b/test/spec/ol/parser/kml/point.kml @@ -1,11 +1,13 @@ - - Simple placemark - Attached to the ground. Intelligently places itself - at the height of the underlying terrain. - - -122.0822035425683,37.42228990140251,0 - - + + + Simple placemark + Attached to the ground. Intelligently places itself + at the height of the underlying terrain. + + -122.0822035425683,37.42228990140251,0 + + + diff --git a/test/spec/ol/parser/kml/polygon.kml b/test/spec/ol/parser/kml/polygon.kml index 68c44eb176..91a6ad2beb 100644 --- a/test/spec/ol/parser/kml/polygon.kml +++ b/test/spec/ol/parser/kml/polygon.kml @@ -6,14 +6,12 @@ hollow box - 1 - relativeToGround -122.366278,37.818844,30 -122.365248,37.819267,30 - -122.365640,37.819861,30 + -122.36564,37.819861,30 -122.366669,37.819429,30 -122.366278,37.818844,30