fix for #746 - add console.error()s when wrong number of argumetns passed to add()
git-svn-id: http://svn.openlayers.org/trunk/openlayers@3731 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -191,6 +191,11 @@ OpenLayers.Bounds.prototype = {
|
||||
* x and y values
|
||||
*/
|
||||
add:function(x, y) {
|
||||
if ( (x == null) || (y == null) ) {
|
||||
var msg = "You must pass both x and y values to the add function.";
|
||||
OpenLayers.Console.error(msg);
|
||||
return null;
|
||||
}
|
||||
return new OpenLayers.Bounds(this.left + x, this.bottom + y,
|
||||
this.right + x, this.top + y);
|
||||
},
|
||||
|
||||
@@ -84,6 +84,12 @@ OpenLayers.LonLat.prototype = {
|
||||
* lat passed-in added to this's.
|
||||
*/
|
||||
add:function(lon, lat) {
|
||||
if ( (lon == null) || (lat == null) ) {
|
||||
var msg = "You must pass both lon and lat values " +
|
||||
"to the add function.";
|
||||
OpenLayers.Console.error(msg);
|
||||
return null;
|
||||
}
|
||||
return new OpenLayers.LonLat(this.lon + lon, this.lat + lat);
|
||||
},
|
||||
|
||||
|
||||
@@ -91,6 +91,11 @@ OpenLayers.Pixel.prototype = {
|
||||
* values passed in.
|
||||
*/
|
||||
add:function(x, y) {
|
||||
if ( (x == null) || (y == null) ) {
|
||||
var msg = "You must pass both x and y values to the add function.";
|
||||
OpenLayers.Console.error(msg);
|
||||
return null;
|
||||
}
|
||||
return new OpenLayers.Pixel(this.x + x, this.y + y);
|
||||
},
|
||||
|
||||
|
||||
@@ -472,6 +472,33 @@
|
||||
|
||||
}
|
||||
|
||||
function test_17_Bounds_add(t) {
|
||||
t.plan( 8 );
|
||||
|
||||
origBounds = new OpenLayers.Bounds(1,2,3,4);
|
||||
testBounds = origBounds.clone();
|
||||
|
||||
var bounds = testBounds.add(5, 50);
|
||||
t.ok( testBounds.equals(origBounds), "testBounds is not modified by add operation");
|
||||
|
||||
var b = new OpenLayers.Bounds(6,52,8,54);
|
||||
t.ok( bounds.equals(b), "bounds is set correctly");
|
||||
|
||||
//null values
|
||||
var desiredMsg = "You must pass both x and y values to the add function.";
|
||||
OpenLayers.Console.error = function(msg) {
|
||||
t.eq(msg, desiredMsg, "error correctly reported");
|
||||
}
|
||||
|
||||
bounds = testBounds.add(null, 50);
|
||||
t.ok( testBounds.equals(origBounds), "testBounds is not modified by erroneous add operation (null x)");
|
||||
t.ok(bounds == null, "returns null on erroneous add operation (null x)");
|
||||
|
||||
bounds = testBounds.add(5, null);
|
||||
t.ok( testBounds.equals(origBounds), "testBounds is not modified by erroneous add operation (null y)");
|
||||
t.ok(bounds == null, "returns null on erroneous add operation (null y)");
|
||||
}
|
||||
|
||||
// -->
|
||||
</script>
|
||||
</head>
|
||||
|
||||
@@ -47,16 +47,30 @@
|
||||
}
|
||||
|
||||
function test_04_LonLat_add(t) {
|
||||
t.plan( 2 );
|
||||
t.plan( 8 );
|
||||
|
||||
lonlatA = new OpenLayers.LonLat(10,100);
|
||||
origLL = new OpenLayers.LonLat(10,100);
|
||||
lonlatA = origLL.clone();
|
||||
|
||||
addpx = lonlatA.add(5, 50);
|
||||
var ll = new OpenLayers.LonLat(10,100);
|
||||
t.ok( lonlatA.equals(ll), "lonlatA is not modified by add operation");
|
||||
t.ok( lonlatA.equals(origLL), "lonlatA is not modified by add operation");
|
||||
|
||||
var ll = new OpenLayers.LonLat(15,150);
|
||||
t.ok( addpx.equals(ll), "addpx is set correctly");
|
||||
|
||||
//null values
|
||||
var desiredMsg = "You must pass both lon and lat values to the add function.";
|
||||
OpenLayers.Console.error = function(msg) {
|
||||
t.eq(msg, desiredMsg, "error correctly reported");
|
||||
}
|
||||
|
||||
addpx = lonlatA.add(null, 50);
|
||||
t.ok( lonlatA.equals(origLL), "lonlatA is not modified by erroneous add operation (null lon)");
|
||||
t.ok(addpx == null, "returns null on erroneous add operation (null lon)");
|
||||
|
||||
addpx = lonlatA.add(5, null);
|
||||
t.ok( lonlatA.equals(origLL), "lonlatA is not modified by erroneous add operation (null lat)");
|
||||
t.ok(addpx == null, "returns null on erroneous add operation (null lat)");
|
||||
}
|
||||
|
||||
function test_06_LonLat_equals(t) {
|
||||
|
||||
@@ -61,16 +61,31 @@
|
||||
}
|
||||
|
||||
function test_07_Pixel_add(t) {
|
||||
t.plan( 4 );
|
||||
oldPixel = new OpenLayers.Pixel(5,6);
|
||||
t.plan( 8 );
|
||||
|
||||
pixel = oldPixel.add(10,20);
|
||||
var origPX = new OpenLayers.Pixel(5,6);
|
||||
var oldPixel = origPX.clone();
|
||||
|
||||
t.eq( oldPixel.x, 5, "oldPixel.x not modified by add operation");
|
||||
t.eq( oldPixel.y, 6, "oldPixel.y not modified by add operation");
|
||||
var pixel = oldPixel.add(10,20);
|
||||
|
||||
t.ok( oldPixel.equals(origPX), "oldPixel not modified by add operation");
|
||||
|
||||
var px = new OpenLayers.Pixel(15,26);
|
||||
t.ok( pixel.equals(px), "returned pixel is correct");
|
||||
|
||||
t.eq( pixel.x, 15, "pixel.x is set correctly");
|
||||
t.eq( pixel.y, 26, "pixel.y is set correctly");
|
||||
//null values
|
||||
var desiredMsg = "You must pass both x and y values to the add function.";
|
||||
OpenLayers.Console.error = function(msg) {
|
||||
t.eq(msg, desiredMsg, "error correctly reported");
|
||||
}
|
||||
|
||||
pixel = oldPixel.add(null, 50);
|
||||
t.ok( oldPixel.equals(origPX), "oldPixel is not modified by erroneous add operation (null x)");
|
||||
t.ok(pixel == null, "returns null on erroneous add operation (null x)");
|
||||
|
||||
addpx = oldPixel.add(5, null);
|
||||
t.ok( oldPixel.equals(origPX), "oldPixel is not modified by erroneous add operation (null y)");
|
||||
t.ok(pixel == null, "returns null on erroneous add operation (null y)");
|
||||
}
|
||||
|
||||
function test_08_Pixel_offset(t) {
|
||||
|
||||
Reference in New Issue
Block a user