OpenLayers OpenLayers

Changeset 3731

Show
Ignore:
Timestamp:
07/13/07 11:41:33 (1 year ago)
Author:
euzuro
Message:

fix for #746 - add console.error()s when wrong number of argumetns passed to add()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/BaseTypes/Bounds.js

    r3686 r3731  
    192192     */ 
    193193    add:function(x, y) { 
     194        if ( (x == null) || (y == null) ) { 
     195            var msg = "You must pass both x and y values to the add function."; 
     196            OpenLayers.Console.error(msg); 
     197            return null; 
     198        } 
    194199        return new OpenLayers.Bounds(this.left + x, this.bottom + y, 
    195200                                     this.right + x, this.top + y); 
  • trunk/openlayers/lib/OpenLayers/BaseTypes/LonLat.js

    r3708 r3731  
    8585     */ 
    8686    add:function(lon, lat) { 
     87        if ( (lon == null) || (lat == null) ) { 
     88            var msg = "You must pass both lon and lat values " + 
     89                      "to the add function."; 
     90            OpenLayers.Console.error(msg); 
     91            return null; 
     92        } 
    8793        return new OpenLayers.LonLat(this.lon + lon, this.lat + lat); 
    8894    }, 
  • trunk/openlayers/lib/OpenLayers/BaseTypes/Pixel.js

    r3601 r3731  
    9292     */ 
    9393    add:function(x, y) { 
     94        if ( (x == null) || (y == null) ) { 
     95            var msg = "You must pass both x and y values to the add function."; 
     96            OpenLayers.Console.error(msg); 
     97            return null; 
     98        } 
    9499        return new OpenLayers.Pixel(this.x + x, this.y + y); 
    95100    }, 
  • trunk/openlayers/tests/BaseTypes/test_Bounds.html

    r3323 r3731  
    473473      } 
    474474 
     475    function test_17_Bounds_add(t) { 
     476        t.plan( 8 ); 
     477 
     478        origBounds = new OpenLayers.Bounds(1,2,3,4); 
     479        testBounds = origBounds.clone(); 
     480 
     481        var bounds = testBounds.add(5, 50); 
     482        t.ok( testBounds.equals(origBounds), "testBounds is not modified by add operation"); 
     483 
     484        var b = new OpenLayers.Bounds(6,52,8,54); 
     485        t.ok( bounds.equals(b), "bounds is set correctly"); 
     486         
     487    //null values 
     488        var desiredMsg = "You must pass both x and y values to the add function."; 
     489        OpenLayers.Console.error = function(msg) { 
     490            t.eq(msg, desiredMsg, "error correctly reported"); 
     491        } 
     492     
     493        bounds = testBounds.add(null, 50); 
     494        t.ok( testBounds.equals(origBounds), "testBounds is not modified by erroneous add operation (null x)"); 
     495        t.ok(bounds == null, "returns null on erroneous add operation (null x)"); 
     496  
     497        bounds = testBounds.add(5, null); 
     498        t.ok( testBounds.equals(origBounds), "testBounds is not modified by erroneous add operation (null y)"); 
     499        t.ok(bounds == null, "returns null on erroneous add operation (null y)"); 
     500    } 
     501 
    475502  // --> 
    476503  </script> 
  • trunk/openlayers/tests/BaseTypes/test_LonLat.html

    r3323 r3731  
    4848 
    4949    function test_04_LonLat_add(t) { 
    50         t.plan( 2 ); 
     50        t.plan( 8 ); 
    5151 
    52         lonlatA = new OpenLayers.LonLat(10,100); 
     52        origLL = new OpenLayers.LonLat(10,100); 
     53        lonlatA = origLL.clone(); 
    5354 
    5455        addpx = lonlatA.add(5, 50); 
    55         var ll = new OpenLayers.LonLat(10,100); 
    56         t.ok( lonlatA.equals(ll), "lonlatA is not modified by add operation"); 
     56        t.ok( lonlatA.equals(origLL), "lonlatA is not modified by add operation"); 
    5757 
    5858        var ll = new OpenLayers.LonLat(15,150); 
    5959        t.ok( addpx.equals(ll), "addpx is set correctly"); 
     60         
     61    //null values 
     62        var desiredMsg = "You must pass both lon and lat values to the add function."; 
     63        OpenLayers.Console.error = function(msg) { 
     64            t.eq(msg, desiredMsg, "error correctly reported"); 
     65        } 
     66     
     67        addpx = lonlatA.add(null, 50); 
     68        t.ok( lonlatA.equals(origLL), "lonlatA is not modified by erroneous add operation (null lon)"); 
     69        t.ok(addpx == null, "returns null on erroneous add operation (null lon)"); 
     70  
     71        addpx = lonlatA.add(5, null); 
     72        t.ok( lonlatA.equals(origLL), "lonlatA is not modified by erroneous add operation (null lat)"); 
     73        t.ok(addpx == null, "returns null on erroneous add operation (null lat)"); 
    6074    } 
    6175     
  • trunk/openlayers/tests/BaseTypes/test_Pixel.html

    r2803 r3731  
    6262 
    6363    function test_07_Pixel_add(t) { 
    64         t.plan( 4 ); 
    65         oldPixel = new OpenLayers.Pixel(5,6); 
     64        t.plan( 8 ); 
    6665 
    67         pixel = oldPixel.add(10,20); 
     66        var origPX = new OpenLayers.Pixel(5,6); 
     67        var oldPixel = origPX.clone(); 
    6868 
    69         t.eq( oldPixel.x, 5, "oldPixel.x not modified by add operation"); 
    70         t.eq( oldPixel.y, 6, "oldPixel.y not modified by add operation"); 
     69        var pixel = oldPixel.add(10,20); 
     70         
     71        t.ok( oldPixel.equals(origPX), "oldPixel not modified by add operation"); 
     72         
     73        var px = new OpenLayers.Pixel(15,26); 
     74        t.ok( pixel.equals(px), "returned pixel is correct"); 
    7175 
    72         t.eq( pixel.x, 15, "pixel.x is set correctly"); 
    73         t.eq( pixel.y, 26, "pixel.y is set correctly"); 
     76    //null values 
     77        var desiredMsg = "You must pass both x and y values to the add function."; 
     78        OpenLayers.Console.error = function(msg) { 
     79            t.eq(msg, desiredMsg, "error correctly reported"); 
     80        } 
     81     
     82        pixel = oldPixel.add(null, 50); 
     83        t.ok( oldPixel.equals(origPX), "oldPixel is not modified by erroneous add operation (null x)"); 
     84        t.ok(pixel == null, "returns null on erroneous add operation (null x)"); 
     85  
     86        addpx = oldPixel.add(5, null); 
     87        t.ok( oldPixel.equals(origPX), "oldPixel is not modified by erroneous add operation (null y)"); 
     88        t.ok(pixel == null, "returns null on erroneous add operation (null y)"); 
    7489    } 
    7590