[OpenLayers-Dev] OpenLayers.Format.KML.write()

Christopher Schmidt crschmidt at metacarta.com
Tue Sep 4 11:54:45 EDT 2007


On Tue, Sep 04, 2007 at 05:21:53PM +0200, Damien Corpataux wrote:
> Thanks!
> 
> I think you mean unit tests... Glurp, I never played around with
> testanotherway. Although I'm interested in doing it when I get to have a
> little time, here is the test code I ran in firebug, using the
> openlayers/examples/vector-features.html example:

Okay, I've put together a stub for you in the tests/Format/test_KML.html
file. What I would do here is very similar to what you have below: 
 * Create a KML parser.
 * Create a feature -- point, line, polygon, whatever.
 * In Firebug or elsewhere, create a text string which you can copy
   paste with the expected output KML: set that as the expectedOut
   variable. 
 * Create kmlOut against that feature: 
   kmlOut = kml.write([myFeature]);
 * Test that expectedOut matches KML Out:
    t.eq(expectedOut, kmlOut, "KML output matches given point feature");
 * If you feel up to it, add a test to write, which reads the output
   KML (as below) and test things like:
    t.eq(outputFeatures.length, 1, "Got correct number of features
                                    back");
    t.eq(outputFeatures[0].geometry.CLASS_NAME, "OpenLayers.Geometry.Point", 
                      "Correct geom type returned.");                                

etc.

If you don't get a chance, I'll bang something out soon, since we're
trying not to shove things in without at least some tests -- but thanks
for the patch regardless!

> ---8<-------------------------------------------------------------------
> var kml = new OpenLayers.Format.KML();
> var kmlOut = kml.write(map.layers[1].features);
> 
> map.layers[1].eraseFeatures(map.layers[1].features);
> map.layers[1].features = [];
> 
> var features = kml.read(kmlOut);
> 
> features;
> 
> map.layers[1].addFeatures(features);
> ---8<-------------------------------------------------------------------



-- 
Christopher Schmidt
MetaCarta



More information about the Dev mailing list