Merge vector-2.4 branch back to trunk.
svn merge sandbox/vector-2.4/@2307 sandbox/vector-2.4/@HEAD trunk/openlayers/ git-svn-id: http://svn.openlayers.org/trunk/openlayers@2803 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
389
tests/BaseTypes/test_Bounds.html
Normal file
389
tests/BaseTypes/test_Bounds.html
Normal file
@@ -0,0 +1,389 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript"><!--
|
||||
var bounds;
|
||||
function test_01_Bounds_constructor (t) {
|
||||
t.plan( 11 );
|
||||
bounds = new OpenLayers.Bounds(0,2,10,4);
|
||||
t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" );
|
||||
t.eq( bounds.CLASS_NAME, "OpenLayers.Bounds", "bounds.CLASS_NAME is set correctly" );
|
||||
t.eq( bounds.left, 0, "bounds.left is set correctly" );
|
||||
t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" );
|
||||
t.eq( bounds.right, 10, "bounds.right is set correctly" );
|
||||
t.eq( bounds.top, 4, "bounds.top is set correctly" );
|
||||
t.eq( bounds.getWidth(), 10, "bounds.getWidth() returns correct value" );
|
||||
t.eq( bounds.getHeight(), 2, "bounds.getHeight() returns correct value" );
|
||||
|
||||
var sz = bounds.getSize();
|
||||
var size = new OpenLayers.Size(10,2);
|
||||
t.ok(sz.equals(size),"bounds.getSize() has correct value" );
|
||||
|
||||
var center = new OpenLayers.Pixel(5,3);
|
||||
var boundsCenter = bounds.getCenterPixel();
|
||||
t.ok( boundsCenter.equals(center), "bounds.getCenterLonLat() has correct value" );
|
||||
|
||||
var center = new OpenLayers.LonLat(5,3);
|
||||
var boundsCenter = bounds.getCenterLonLat();
|
||||
t.ok( boundsCenter.equals(center), "bounds.getCenterLonLat() has correct value" );
|
||||
}
|
||||
|
||||
function test_01a_Bounds_constructorFromStrings(t) {
|
||||
t.plan( 6 );
|
||||
bounds = new OpenLayers.Bounds("0","2","10","4");
|
||||
t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" );
|
||||
t.eq( bounds.CLASS_NAME, "OpenLayers.Bounds", "bounds.CLASS_NAME is set correctly" );
|
||||
t.eq( bounds.left, 0, "bounds.left is set correctly" );
|
||||
t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" );
|
||||
t.eq( bounds.right, 10, "bounds.right is set correctly" );
|
||||
t.eq( bounds.top, 4, "bounds.top is set correctly" );
|
||||
|
||||
}
|
||||
|
||||
function test_02_Bounds_toBBOX(t) {
|
||||
t.plan( 5 );
|
||||
bounds = new OpenLayers.Bounds(1,2,3,4);
|
||||
t.eq( bounds.toBBOX(), "1,2,3,4", "toBBOX() returns correct value." );
|
||||
bounds = new OpenLayers.Bounds(1.00000001,2,3,4);
|
||||
t.eq( bounds.toBBOX(), "1,2,3,4", "toBBOX() rounds off small differences." );
|
||||
bounds = new OpenLayers.Bounds(1.00000001,2.5,3,4);
|
||||
t.eq( bounds.toBBOX(), "1,2.5,3,4", "toBBOX() returns correct value. for a half number" );
|
||||
bounds = new OpenLayers.Bounds(1,2.5555555,3,4);
|
||||
t.eq( bounds.toBBOX(), "1,2.555556,3,4", "toBBOX() rounds to correct value." );
|
||||
bounds = new OpenLayers.Bounds(1,2.5555555,3,4);
|
||||
t.eq( bounds.toBBOX(1), "1,2.6,3,4", "toBBOX() rounds to correct value with power provided." );
|
||||
bounds = new OpenLayers.Bounds(1,2.5555555,3,4);
|
||||
}
|
||||
|
||||
function test_03_Bounds_toString(t) {
|
||||
t.plan( 1 );
|
||||
bounds = new OpenLayers.Bounds(1,2,3,4);
|
||||
t.eq( bounds.toString(), "left-bottom=(1,2) right-top=(3,4)", "toString() returns correct value." );
|
||||
}
|
||||
|
||||
function test_04_Bounds_contains(t) {
|
||||
t.plan( 6 );
|
||||
bounds = new OpenLayers.Bounds(10,10,40,40);
|
||||
t.eq( bounds.contains(20,20), true, "bounds(10,10,40,40) correctly contains LonLat(20,20)" );
|
||||
t.eq( bounds.contains(0,0), false, "bounds(10,10,40,40) correctly does not contain LonLat(0,0)" );
|
||||
t.eq( bounds.contains(40,40), true, "bounds(10,10,40,40) correctly contains LonLat(40,40) with inclusive set to true" );
|
||||
t.eq( bounds.contains(40,40, false), false, "bounds(10,10,40,40) correctly does not contain LonLat(40,40) with inclusive set to false" );
|
||||
|
||||
var px = new OpenLayers.Pixel(15,30);
|
||||
t.eq( bounds.containsPixel(px), bounds.contains(px.x, px.y), "containsPixel works");
|
||||
|
||||
var ll = new OpenLayers.LonLat(15,30);
|
||||
t.eq( bounds.containsLonLat(ll), bounds.contains(ll.lon, ll.lat), "containsLonLat works");
|
||||
|
||||
}
|
||||
|
||||
function test_05_Bounds_fromString(t) {
|
||||
t.plan( 10 );
|
||||
bounds = OpenLayers.Bounds.fromString("1,2,3,4");
|
||||
t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" );
|
||||
t.eq( bounds.left, 1, "bounds.left is set correctly" );
|
||||
t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" );
|
||||
t.eq( bounds.right, 3, "bounds.right is set correctly" );
|
||||
t.eq( bounds.top, 4, "bounds.top is set correctly" );
|
||||
|
||||
bounds = OpenLayers.Bounds.fromString("1.1,2.2,3.3,4.4");
|
||||
t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" );
|
||||
t.eq( bounds.left, 1.1, "bounds.left is set correctly" );
|
||||
t.eq( bounds.bottom, 2.2, "bounds.bottom is set correctly" );
|
||||
t.eq( bounds.right, 3.3, "bounds.right is set correctly" );
|
||||
t.eq( bounds.top, 4.4, "bounds.top is set correctly" );
|
||||
|
||||
}
|
||||
|
||||
function test_06_Bounds_getSize(t) {
|
||||
t.plan( 1 );
|
||||
var bounds = new OpenLayers.Bounds(0,10,100,120);
|
||||
|
||||
t.ok( bounds.getSize().equals(new OpenLayers.Size(100, 110)), "getCenterPixel() works correctly");
|
||||
}
|
||||
|
||||
function test_07_Bounds_clone(t) {
|
||||
t.plan( 6 );
|
||||
var oldBounds = new OpenLayers.Bounds(1,2,3,4);
|
||||
var bounds = oldBounds.clone();
|
||||
t.ok( bounds instanceof OpenLayers.Bounds, "clone returns new OpenLayers.Bounds object" );
|
||||
t.eq( bounds.left, 1, "bounds.left is set correctly" );
|
||||
t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" );
|
||||
t.eq( bounds.right, 3, "bounds.right is set correctly" );
|
||||
t.eq( bounds.top, 4, "bounds.top is set correctly" );
|
||||
|
||||
oldBounds.left = 100;
|
||||
t.eq( bounds.left, 1, "changing olBounds.left does not change bounds.left" );
|
||||
}
|
||||
|
||||
function test_08a_Bounds_intersectsBounds(t) {
|
||||
t.plan( 17 );
|
||||
|
||||
var aBounds = new OpenLayers.Bounds(-180, -90, 180, 90);
|
||||
|
||||
//inside
|
||||
var bBounds = new OpenLayers.Bounds(-20, -10, 20, 10);
|
||||
var cBounds = new OpenLayers.Bounds(-181,-90,180,90);
|
||||
t.eq( aBounds.intersectsBounds(bBounds), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" );
|
||||
t.eq( aBounds.intersectsBounds(bBounds, true), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" );
|
||||
t.eq( aBounds.intersectsBounds(bBounds, false), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is false" );
|
||||
t.eq( aBounds.intersectsBounds(cBounds, false), true, "aBounds with cBounds adjusted one degree left passes intersect bounds. (3 sides match, 1 side different)." );
|
||||
t.eq( cBounds.intersectsBounds(aBounds, false), true, "cBounds with aBounds adjusted one degree left passes intersect bounds. (3 sides match, 1 side different)." );
|
||||
|
||||
//outside
|
||||
bBounds = new OpenLayers.Bounds(-181, -91, 181, 91);
|
||||
t.eq( aBounds.intersectsBounds(bBounds), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" );
|
||||
t.eq( aBounds.intersectsBounds(bBounds, true), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" );
|
||||
t.eq( aBounds.intersectsBounds(bBounds, false), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is false" );
|
||||
|
||||
//total intersect
|
||||
bBounds = new OpenLayers.Bounds(-185, -100, 20, 50);
|
||||
t.eq( aBounds.intersectsBounds(bBounds), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" );
|
||||
t.eq( aBounds.intersectsBounds(bBounds, true), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" );
|
||||
t.eq( aBounds.intersectsBounds(bBounds, false), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is false" );
|
||||
|
||||
//border intersect
|
||||
bBounds = new OpenLayers.Bounds(-360, -180, -180, -90);
|
||||
t.eq( aBounds.intersectsBounds(bBounds), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + ")" );
|
||||
t.eq( aBounds.intersectsBounds(bBounds, true), true, "(" + aBounds.toBBOX() + ") correctly intersects (" + bBounds.toBBOX() + "), inclusive is true" );
|
||||
t.eq( aBounds.intersectsBounds(bBounds, false), false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + "), inclusive is false" );
|
||||
|
||||
//no intersect
|
||||
bBounds = new OpenLayers.Bounds(-360, -180, -185, -95);
|
||||
t.eq( aBounds.intersectsBounds(bBounds), false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + ")" );
|
||||
t.eq( aBounds.intersectsBounds(bBounds, true), false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + "), inclusive is true" );
|
||||
t.eq( aBounds.intersectsBounds(bBounds, false), false, "(" + aBounds.toBBOX() + ") does not intersect (" + bBounds.toBBOX() + "), inclusive is false" );
|
||||
|
||||
}
|
||||
|
||||
function test_08b_Bounds_containsBounds(t) {
|
||||
t.plan( 35 );
|
||||
containerBounds = new OpenLayers.Bounds(10,10,40,40);
|
||||
|
||||
//totally outside
|
||||
bounds = new OpenLayers.Bounds(0,0,5,5);
|
||||
t.eq( containerBounds.containsBounds(bounds) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ")");
|
||||
t.eq( containerBounds.containsBounds(bounds, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false" );
|
||||
t.eq( containerBounds.containsBounds(bounds, false, true) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is true" );
|
||||
t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" );
|
||||
t.eq( containerBounds.containsBounds(bounds, true) , false , "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true" );
|
||||
t.eq( containerBounds.containsBounds(bounds, true, true) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true, inclusive is true" );
|
||||
t.eq( containerBounds.containsBounds(bounds, true, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true, inclusive is false" );
|
||||
|
||||
//totally outside on border
|
||||
bounds = new OpenLayers.Bounds(15,0,30,10);
|
||||
t.eq( containerBounds.containsBounds(bounds) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ")");
|
||||
t.eq( containerBounds.containsBounds(bounds, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false" );
|
||||
t.eq( containerBounds.containsBounds(bounds, false, true) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is true" );
|
||||
t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" );
|
||||
t.eq( containerBounds.containsBounds(bounds, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" );
|
||||
t.eq( containerBounds.containsBounds(bounds, true, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" );
|
||||
t.eq( containerBounds.containsBounds(bounds, true, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true, inclusive is false" );
|
||||
|
||||
//partially inside
|
||||
bounds = new OpenLayers.Bounds(20,20,50,30);
|
||||
t.eq( containerBounds.containsBounds(bounds) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ")");
|
||||
t.eq( containerBounds.containsBounds(bounds, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false" );
|
||||
t.eq( containerBounds.containsBounds(bounds, false, true) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is true" );
|
||||
t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" );
|
||||
t.eq( containerBounds.containsBounds(bounds, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" );
|
||||
t.eq( containerBounds.containsBounds(bounds, true, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" );
|
||||
t.eq( containerBounds.containsBounds(bounds, true, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is false" );
|
||||
|
||||
//totally inside on border
|
||||
bounds = new OpenLayers.Bounds(10,20,30,30);
|
||||
t.eq( containerBounds.containsBounds(bounds) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ")");
|
||||
t.eq( containerBounds.containsBounds(bounds, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false" );
|
||||
t.eq( containerBounds.containsBounds(bounds, false, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false, inclusive is true" );
|
||||
t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" );
|
||||
t.eq( containerBounds.containsBounds(bounds, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" );
|
||||
t.eq( containerBounds.containsBounds(bounds, true, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" );
|
||||
t.eq( containerBounds.containsBounds(bounds, true, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is false" );
|
||||
|
||||
//totally inside
|
||||
bounds = new OpenLayers.Bounds(20,20,30,30);
|
||||
t.eq( containerBounds.containsBounds(bounds) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ")");
|
||||
t.eq( containerBounds.containsBounds(bounds, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false" );
|
||||
t.eq( containerBounds.containsBounds(bounds, false, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false, inclusive is true" );
|
||||
t.eq( containerBounds.containsBounds(bounds, false, false), true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false, inclusive is false" );
|
||||
t.eq( containerBounds.containsBounds(bounds, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" );
|
||||
t.eq( containerBounds.containsBounds(bounds, true, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" );
|
||||
t.eq( containerBounds.containsBounds(bounds, true, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is false" );
|
||||
}
|
||||
|
||||
function test_09_Bounds_determineQuadrant(t) {
|
||||
|
||||
t.plan( 4 );
|
||||
var bounds = new OpenLayers.Bounds(0,0,100,100);
|
||||
|
||||
var tl = new OpenLayers.LonLat(25, 75);
|
||||
var tr = new OpenLayers.LonLat(75, 75);
|
||||
var bl = new OpenLayers.LonLat(25, 25);
|
||||
var br = new OpenLayers.LonLat(75, 25);
|
||||
|
||||
t.eq( bounds.determineQuadrant(tl), "tl", "bounds.determineQuadrant correctly identifies a coordinate in the top left quadrant");
|
||||
t.eq( bounds.determineQuadrant(tr), "tr", "bounds.determineQuadrant correctly identifies a coordinate in the top right quadrant");
|
||||
t.eq( bounds.determineQuadrant(bl), "bl", "bounds.determineQuadrant correctly identifies a coordinate in the bottom left quadrant");
|
||||
t.eq( bounds.determineQuadrant(br), "br", "bounds.determineQuadrant correctly identifies a coordinate in the bottom right quadrant");
|
||||
}
|
||||
|
||||
function test_10_Bounds_oppositeQuadrant(t) {
|
||||
|
||||
t.plan( 4 );
|
||||
|
||||
t.eq( OpenLayers.Bounds.oppositeQuadrant("tl"), "br", "OpenLayers.Bounds.oppositeQuadrant returns 'br' for 'tl'");
|
||||
t.eq( OpenLayers.Bounds.oppositeQuadrant("tr"), "bl", "OpenLayers.Bounds.oppositeQuadrant returns 'bl' for 'tr'");
|
||||
t.eq( OpenLayers.Bounds.oppositeQuadrant("bl"), "tr", "OpenLayers.Bounds.oppositeQuadrant returns 'tr' for 'bl'");
|
||||
t.eq( OpenLayers.Bounds.oppositeQuadrant("br"), "tl", "OpenLayers.Bounds.oppositeQuadrant returns 'tl' for 'br'");
|
||||
}
|
||||
|
||||
function test_11_Bounds_equals(t) {
|
||||
t.plan( 3 );
|
||||
var boundsA = new OpenLayers.Bounds(1,2,3,4);
|
||||
var boundsB = new OpenLayers.Bounds(1,2,3,4);
|
||||
var boundsC = new OpenLayers.Bounds(1,5,3,4);
|
||||
|
||||
t.ok( boundsA.equals(boundsB), "equals() returns true on two equal bounds." );
|
||||
t.ok( !boundsA.equals(boundsC), "equals() returns false on two different bounds." );
|
||||
t.ok( !boundsA.equals(null), "equals() returns false on comparison to null");
|
||||
}
|
||||
|
||||
function test_12_Bounds_getHeight_getWidth(t) {
|
||||
t.plan( 2 );
|
||||
var bounds = new OpenLayers.Bounds(10,20,100,120);
|
||||
|
||||
t.eq( bounds.getWidth(), 90, "getWidth() works" );
|
||||
t.eq( bounds.getHeight(), 100, "getHeight() works" );
|
||||
|
||||
}
|
||||
|
||||
function test_13_Bounds_getCenters(t) {
|
||||
t.plan( 2 );
|
||||
var bounds = new OpenLayers.Bounds(0,20,100,120);
|
||||
|
||||
t.ok( bounds.getCenterPixel().equals(new OpenLayers.Pixel(50, 70)), "getCenterPixel() works correctly");
|
||||
t.ok( bounds.getCenterLonLat().equals(new OpenLayers.LonLat(50, 70)), "getCenterLonLat() works correctly");
|
||||
}
|
||||
|
||||
function test_14_Bounds_fromArray(t) {
|
||||
t.plan( 5 );
|
||||
|
||||
var bbox = [1,2,3,4];
|
||||
bounds = OpenLayers.Bounds.fromArray(bbox);
|
||||
t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" );
|
||||
t.eq( bounds.left, 1, "bounds.left is set correctly" );
|
||||
t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" );
|
||||
t.eq( bounds.right, 3, "bounds.right is set correctly" );
|
||||
t.eq( bounds.top, 4, "bounds.top is set correctly" );
|
||||
}
|
||||
|
||||
function test_15_Bounds_fromSize(t) {
|
||||
t.plan( 5 );
|
||||
|
||||
var height = 15;
|
||||
var width = 16;
|
||||
var size = new OpenLayers.Size(width, height);
|
||||
bounds = OpenLayers.Bounds.fromSize(size);
|
||||
t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" );
|
||||
t.eq( bounds.left, 0, "bounds.left is set correctly" );
|
||||
t.eq( bounds.bottom, height, "bounds.bottom is set correctly" );
|
||||
t.eq( bounds.right, width, "bounds.right is set correctly" );
|
||||
t.eq( bounds.top, 0, "bounds.top is set correctly" );
|
||||
}
|
||||
|
||||
|
||||
function test_16_Bounds_extend(t) {
|
||||
t.plan( 8 );
|
||||
|
||||
var originalBounds = new OpenLayers.Bounds(10,20,50,80);
|
||||
|
||||
var bounds = originalBounds.clone();
|
||||
|
||||
//null obj
|
||||
bounds.extend(null);
|
||||
t.ok(bounds.equals(originalBounds), "null to extend does not crash or change original bounds");
|
||||
|
||||
//obj with no classname
|
||||
var object = new Object();
|
||||
bounds.extend(object);
|
||||
t.ok(bounds.equals(originalBounds), "extend() passing object with no classname does not crash or change original bounds")
|
||||
|
||||
//obj is bounds
|
||||
|
||||
//pushing all limits with bounds obj
|
||||
var testBounds = new OpenLayers.Bounds(5, 10, 60, 90);
|
||||
object = testBounds.clone();
|
||||
|
||||
bounds.extend(object);
|
||||
t.ok(bounds.equals(testBounds), "extend by valid bounds, pushing all limits, correctly extends bounds");
|
||||
|
||||
//pushing no limits with bounds obj
|
||||
bounds = originalBounds.clone();
|
||||
|
||||
testBounds = new OpenLayers.Bounds(15, 30, 40, 70);
|
||||
object = testBounds.clone();
|
||||
|
||||
bounds.extend(object);
|
||||
t.ok(bounds.equals(originalBounds), "extend by valid bounds, pushing no limits, correctly does not extend bounds");
|
||||
|
||||
// obj is lonlat
|
||||
|
||||
//left, bottom
|
||||
bounds = originalBounds.clone();
|
||||
|
||||
object = new OpenLayers.LonLat(5, 10);
|
||||
|
||||
bounds.extend(object);
|
||||
|
||||
t.ok( ((bounds.left == object.lon) &&
|
||||
(bounds.bottom == object.lat) &&
|
||||
(bounds.right == originalBounds.right) &&
|
||||
(bounds.top == originalBounds.top)), "obj lonlat to extends correclty modifies left and bottom");
|
||||
|
||||
//right, top
|
||||
bounds = originalBounds.clone();
|
||||
|
||||
object = new OpenLayers.LonLat(60,90);
|
||||
|
||||
bounds.extend(object);
|
||||
|
||||
t.ok( ((bounds.left == originalBounds.left) &&
|
||||
(bounds.bottom == originalBounds.bottom) &&
|
||||
(bounds.right == object.lon) &&
|
||||
(bounds.top == object.lat)), "obj lonlat to extends correclty modifies right and top");
|
||||
|
||||
// obj is point
|
||||
|
||||
//left, bottom
|
||||
bounds = originalBounds.clone();
|
||||
|
||||
object = new OpenLayers.Geometry.Point(5, 10);
|
||||
|
||||
bounds.extend(object);
|
||||
|
||||
t.ok( ((bounds.left == object.lon) &&
|
||||
(bounds.bottom == object.lat) &&
|
||||
(bounds.right == originalBounds.right) &&
|
||||
(bounds.top == originalBounds.top)), "obj Point to extends correclty modifies left and bottom");
|
||||
|
||||
//right, top
|
||||
bounds = originalBounds.clone();
|
||||
|
||||
object = new OpenLayers.Geometry.Point(60,90);
|
||||
|
||||
bounds.extend(object);
|
||||
|
||||
t.ok( ((bounds.left == originalBounds.left) &&
|
||||
(bounds.bottom == originalBounds.bottom) &&
|
||||
(bounds.right == object.lon) &&
|
||||
(bounds.top == object.lat)), "obj Point to extends correclty modifies right and top");
|
||||
|
||||
}
|
||||
|
||||
// -->
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
106
tests/BaseTypes/test_Class.html
Normal file
106
tests/BaseTypes/test_Class.html
Normal file
@@ -0,0 +1,106 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript"><!--
|
||||
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
|
||||
|
||||
function test_01_Class_create (t) {
|
||||
t.plan( 3 );
|
||||
var cls = OpenLayers.Class.create();
|
||||
cls.prototype = {
|
||||
initialize: function () {
|
||||
if (isMozilla)
|
||||
t.ok(this instanceof cls,
|
||||
"initialize is called on the right class");
|
||||
else
|
||||
t.ok(true, "initialize is called");
|
||||
}
|
||||
};
|
||||
var obj = new cls();
|
||||
t.eq(typeof obj, "object", "obj is an object");
|
||||
if (isMozilla)
|
||||
t.ok(obj instanceof cls,
|
||||
"object is of the right class");
|
||||
else
|
||||
t.ok(true, "this test doesn't work in IE");
|
||||
}
|
||||
|
||||
function test_02_Class_inherit (t) {
|
||||
t.plan( 20 );
|
||||
var A = OpenLayers.Class.create();
|
||||
var initA = 0;
|
||||
A.prototype = {
|
||||
count: 0,
|
||||
initialize: function () {
|
||||
initA++;
|
||||
this.count++;
|
||||
}
|
||||
};
|
||||
|
||||
var B = OpenLayers.Class.create();
|
||||
var initB = 0;
|
||||
B.prototype = OpenLayers.Class.inherit( A, {
|
||||
initialize: function () {
|
||||
A.prototype.initialize.apply(this, arguments);
|
||||
initB++;
|
||||
this.count++;
|
||||
}
|
||||
});
|
||||
|
||||
var mixin = OpenLayers.Class.create()
|
||||
mixin.prototype = {
|
||||
mixed: true
|
||||
};
|
||||
|
||||
t.eq( initA, 0, "class A not inited" );
|
||||
t.eq( initB, 0, "class B not inited" );
|
||||
|
||||
var objA = new A();
|
||||
t.eq( objA.count, 1, "object A init" );
|
||||
t.eq( initA, 1, "class A init" );
|
||||
if (isMozilla)
|
||||
t.ok( objA instanceof A, "obj A isa A" );
|
||||
else
|
||||
t.ok( true, "IE sucks" );
|
||||
|
||||
var objB = new B();
|
||||
t.eq( initA, 2, "class A init" );
|
||||
t.eq( initB, 1, "class B init" );
|
||||
t.eq( objB.count, 2, "object B init twice" );
|
||||
if (isMozilla) {
|
||||
t.ok( objB instanceof A, "obj B isa A" );
|
||||
t.ok( objB instanceof B, "obj B isa B" );
|
||||
} else {
|
||||
t.ok( true, "IE sucks" );
|
||||
t.ok( true, "IE sucks" );
|
||||
}
|
||||
|
||||
var C = OpenLayers.Class.create();
|
||||
C.prototype = OpenLayers.Class.inherit( B, mixin, {count: 0} );
|
||||
t.eq( initA, 2, "class A init unchanged" );
|
||||
t.eq( initB, 1, "class B init unchanged" );
|
||||
|
||||
var objC = new C();
|
||||
t.eq( initA, 3, "class A init changed" );
|
||||
t.eq( initB, 2, "class B init changed" );
|
||||
t.eq( objC.count, 2, "object C init changed" );
|
||||
if (isMozilla) {
|
||||
t.ok( objC instanceof A, "obj C isa A" );
|
||||
t.ok( objC instanceof B, "obj C isa B" );
|
||||
t.ok( objC instanceof C, "obj C isa C" );
|
||||
t.ok( !(objC instanceof mixin), "obj C isn'ta mixin" );
|
||||
} else {
|
||||
t.ok( true, "IE sucks" );
|
||||
t.ok( true, "IE sucks" );
|
||||
t.ok( true, "IE sucks" );
|
||||
t.ok( true, "IE sucks" );
|
||||
}
|
||||
t.eq( objC.mixed, true, "class C mixes has mixin properties" );
|
||||
}
|
||||
|
||||
// -->
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
96
tests/BaseTypes/test_LonLat.html
Normal file
96
tests/BaseTypes/test_LonLat.html
Normal file
@@ -0,0 +1,96 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript"><!--
|
||||
|
||||
var lonlat;
|
||||
|
||||
function test_01_LonLat_constructor (t) {
|
||||
t.plan( 4 );
|
||||
lonlat = new OpenLayers.LonLat(6, 5);
|
||||
t.ok( lonlat instanceof OpenLayers.LonLat, "new OpenLayers.LonLat returns LonLat object" );
|
||||
t.eq( lonlat.CLASS_NAME, "OpenLayers.LonLat", "lonlat.CLASS_NAME is set correctly");
|
||||
t.eq( lonlat.lon, 6, "lonlat.lon is set correctly");
|
||||
t.eq( lonlat.lat, 5, "lonlat.lat is set correctly");
|
||||
}
|
||||
|
||||
function test_01a_LonLat_constructorFromStrings (t) {
|
||||
t.plan( 4 );
|
||||
lonlat = new OpenLayers.LonLat("6", "5");
|
||||
t.ok( lonlat instanceof OpenLayers.LonLat, "new OpenLayers.LonLat returns LonLat object" );
|
||||
t.eq( lonlat.CLASS_NAME, "OpenLayers.LonLat", "lonlat.CLASS_NAME is set correctly");
|
||||
t.eq( lonlat.lon, 6, "lonlat.lon is set correctly");
|
||||
t.eq( lonlat.lat, 5, "lonlat.lat is set correctly");
|
||||
}
|
||||
|
||||
function test_02_LonLat_toString(t) {
|
||||
t.plan( 1 );
|
||||
lonlat = new OpenLayers.LonLat(5,6);
|
||||
t.eq( lonlat.toString(), "lon=5,lat=6", "lonlat.toString() returns correctly");
|
||||
}
|
||||
|
||||
function test_02A_LonLat_toShortString(t) {
|
||||
t.plan( 1 );
|
||||
lonlat = new OpenLayers.LonLat(5,6);
|
||||
t.eq( lonlat.toShortString(), "5, 6", "lonlat.toShortString() returns correctly");
|
||||
}
|
||||
|
||||
function test_03_LonLat_clone(t) {
|
||||
t.plan( 3 );
|
||||
oldLonLat = new OpenLayers.LonLat(5,6);
|
||||
lonlat = oldLonLat.clone();
|
||||
t.ok( lonlat instanceof OpenLayers.LonLat, "clone returns new OpenLayers.LonLat object" );
|
||||
t.ok( lonlat.equals(oldLonLat), "lonlat is set correctly");
|
||||
|
||||
oldLonLat.lon = 100;
|
||||
t.eq( lonlat.lon, 5, "changing oldLonLat.lon doesn't change lonlat.lon");
|
||||
}
|
||||
|
||||
function test_04_LonLat_add(t) {
|
||||
t.plan( 2 );
|
||||
|
||||
lonlatA = new OpenLayers.LonLat(10,100);
|
||||
|
||||
addpx = lonlatA.add(5, 50);
|
||||
var ll = new OpenLayers.LonLat(10,100);
|
||||
t.ok( lonlatA.equals(ll), "lonlatA is not modified by add operation");
|
||||
|
||||
var ll = new OpenLayers.LonLat(15,150);
|
||||
t.ok( addpx.equals(ll), "addpx is set correctly");
|
||||
}
|
||||
|
||||
function test_06_LonLat_equals(t) {
|
||||
t.plan( 5 );
|
||||
lonlat = new OpenLayers.LonLat(5,6);
|
||||
|
||||
ll = new OpenLayers.LonLat(5,6);
|
||||
t.eq( lonlat.equals(ll), true, "(5,6) equals (5,6)");
|
||||
|
||||
ll = new OpenLayers.LonLat(1,6);
|
||||
t.eq( lonlat.equals(ll), false, "(5,6) does not equal (1,6)");
|
||||
|
||||
ll = new OpenLayers.LonLat(5,2);
|
||||
t.eq( lonlat.equals(ll), false, "(5,6) does not equal (5,2)");
|
||||
|
||||
ll = new OpenLayers.LonLat(1,2);
|
||||
t.eq( lonlat.equals(ll), false, "(5,6) does not equal (1,2)");
|
||||
|
||||
t.ok( !lonlat.equals(null), "equals() returns false on comparison to null");
|
||||
|
||||
}
|
||||
|
||||
function test_07_LonLat_fromString(t) {
|
||||
t.plan( 2 );
|
||||
lonlat = OpenLayers.LonLat.fromString("6,5");
|
||||
t.ok( lonlat instanceof OpenLayers.LonLat, "new OpenLayers.LonLat returns LonLat object" );
|
||||
|
||||
var ll = new OpenLayers.LonLat(6, 5);
|
||||
t.ok( lonlat.equals(ll), "lonlat is set correctly");
|
||||
}
|
||||
|
||||
// -->
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
96
tests/BaseTypes/test_Pixel.html
Normal file
96
tests/BaseTypes/test_Pixel.html
Normal file
@@ -0,0 +1,96 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript"><!--
|
||||
var pixel;
|
||||
|
||||
function test_01_Pixel_constructor (t) {
|
||||
t.plan( 4 );
|
||||
pixel = new OpenLayers.Pixel(5,6);
|
||||
t.ok( pixel instanceof OpenLayers.Pixel, "new OpenLayers.Pixel returns Pixel object" );
|
||||
t.eq( pixel.CLASS_NAME, "OpenLayers.Pixel", "pixel.CLASS_NAME is set correctly");
|
||||
t.eq( pixel.x, 5, "pixel.x is set correctly");
|
||||
t.eq( pixel.y, 6, "pixel.y is set correctly");
|
||||
}
|
||||
|
||||
function test_01a_Pixel_constructorFromString (t) {
|
||||
t.plan( 4 );
|
||||
pixel = new OpenLayers.Pixel("5","6");
|
||||
t.ok( pixel instanceof OpenLayers.Pixel, "new OpenLayers.Pixel returns Pixel object" );
|
||||
t.eq( pixel.CLASS_NAME, "OpenLayers.Pixel", "pixel.CLASS_NAME is set correctly");
|
||||
t.eq( pixel.x, 5, "pixel.x is set correctly");
|
||||
t.eq( pixel.y, 6, "pixel.y is set correctly");
|
||||
}
|
||||
|
||||
function test_02_Pixel_toString(t) {
|
||||
t.plan( 1 );
|
||||
pixel = new OpenLayers.Pixel(5,6);
|
||||
t.eq( pixel.toString(), "x=5,y=6", "pixel.toString() returns correctly");
|
||||
}
|
||||
|
||||
function test_03_Pixel_clone(t) {
|
||||
t.plan( 4 );
|
||||
oldPixel = new OpenLayers.Pixel(5,6);
|
||||
pixel = oldPixel.clone();
|
||||
t.ok( pixel instanceof OpenLayers.Pixel, "clone returns new OpenLayers.Pixel object" );
|
||||
t.eq( pixel.x, 5, "pixel.x is set correctly");
|
||||
t.eq( pixel.y, 6, "pixel.y is set correctly");
|
||||
|
||||
oldPixel.x = 100;
|
||||
t.eq( pixel.x, 5, "changing oldPixel.x doesn't change pixel.x");
|
||||
}
|
||||
|
||||
function test_06_Pixel_equals(t) {
|
||||
t.plan( 5 );
|
||||
pixel = new OpenLayers.Pixel(5,6);
|
||||
|
||||
px = new OpenLayers.Pixel(5,6);
|
||||
t.eq( pixel.equals(px), true, "(5,6) equals (5,6)");
|
||||
|
||||
px = new OpenLayers.Pixel(1,6);
|
||||
t.eq( pixel.equals(px), false, "(5,6) does not equal (1,6)");
|
||||
|
||||
px = new OpenLayers.Pixel(5,2);
|
||||
t.eq( pixel.equals(px), false, "(5,6) does not equal (5,2)");
|
||||
|
||||
px = new OpenLayers.Pixel(1,2);
|
||||
t.eq( pixel.equals(px), false, "(5,6) does not equal (1,2)");
|
||||
|
||||
t.ok( !pixel.equals(null), "equals() returns false on comparison to null");
|
||||
|
||||
}
|
||||
|
||||
function test_07_Pixel_add(t) {
|
||||
t.plan( 4 );
|
||||
oldPixel = new OpenLayers.Pixel(5,6);
|
||||
|
||||
pixel = oldPixel.add(10,20);
|
||||
|
||||
t.eq( oldPixel.x, 5, "oldPixel.x not modified by add operation");
|
||||
t.eq( oldPixel.y, 6, "oldPixel.y not modified by add operation");
|
||||
|
||||
t.eq( pixel.x, 15, "pixel.x is set correctly");
|
||||
t.eq( pixel.y, 26, "pixel.y is set correctly");
|
||||
}
|
||||
|
||||
function test_08_Pixel_offset(t) {
|
||||
t.plan( 4 );
|
||||
|
||||
var oldPixel = new OpenLayers.Pixel(5,6);
|
||||
var offset = new OpenLayers.Pixel(10,20);
|
||||
|
||||
pixel = oldPixel.offset(offset);
|
||||
|
||||
t.eq( oldPixel.x, 5, "oldPixel.x not modified by offset operation");
|
||||
t.eq( oldPixel.y, 6, "oldPixel.y not modified by offset operation");
|
||||
|
||||
t.eq( pixel.x, 15, "pixel.x is set correctly");
|
||||
t.eq( pixel.y, 26, "pixel.y is set correctly");
|
||||
}
|
||||
|
||||
// -->
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
67
tests/BaseTypes/test_Size.html
Normal file
67
tests/BaseTypes/test_Size.html
Normal file
@@ -0,0 +1,67 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript"><!--
|
||||
var Size;
|
||||
|
||||
function test_01_Size_constructor (t) {
|
||||
t.plan( 4 );
|
||||
size = new OpenLayers.Size(5,6);
|
||||
t.ok( size instanceof OpenLayers.Size, "new OpenLayers.Size returns size object" );
|
||||
t.eq( size.CLASS_NAME, "OpenLayers.Size", "size.CLASS_NAME is set correctly");
|
||||
t.eq( size.w, 5, "size.w is set correctly");
|
||||
t.eq( size.h, 6, "size.h is set correctly");
|
||||
}
|
||||
|
||||
function test_01a_Size_constructorFromString (t) {
|
||||
t.plan( 4 );
|
||||
size = new OpenLayers.Size("5","6");
|
||||
t.ok( size instanceof OpenLayers.Size, "new OpenLayers.Size returns size object" );
|
||||
t.eq( size.CLASS_NAME, "OpenLayers.Size", "size.CLASS_NAME is set correctly");
|
||||
t.eq( size.w, 5, "size.w is set correctly");
|
||||
t.eq( size.h, 6, "size.h is set correctly");
|
||||
}
|
||||
|
||||
function test_02_Size_toString(t) {
|
||||
t.plan( 1 );
|
||||
size = new OpenLayers.Size(5,6);
|
||||
t.eq( size.toString(), "w=5,h=6", "size.toString() returns correctly");
|
||||
}
|
||||
|
||||
function test_03_Size_clone(t) {
|
||||
t.plan( 3 );
|
||||
|
||||
oldSize = new OpenLayers.Size(5,6);
|
||||
size = oldSize.clone();
|
||||
t.ok( size instanceof OpenLayers.Size, "clone returns new OpenLayers.Size object" );
|
||||
t.ok( size.equals(oldSize), "new size is equal to old size correctly");
|
||||
|
||||
oldSize.w = 100;
|
||||
t.eq( size.w, 5, "changing oldSize.w doesn't change size.w");
|
||||
}
|
||||
|
||||
function test_04_Size_equals(t) {
|
||||
t.plan( 5 );
|
||||
size = new OpenLayers.Size(5,6);
|
||||
|
||||
sz = new OpenLayers.Size(5,6);
|
||||
t.eq( size.equals(sz), true, "(5,6) equals (5,6)");
|
||||
|
||||
sz = new OpenLayers.Size(1,6);
|
||||
t.eq( size.equals(sz), false, "(5,6) does not equal (1,6)");
|
||||
|
||||
sz = new OpenLayers.Size(5,2);
|
||||
t.eq( size.equals(sz), false, "(5,6) does not equal (5,2)");
|
||||
|
||||
sz = new OpenLayers.Size(1,2);
|
||||
t.eq( size.equals(sz), false, "(5,6) does not equal (1,2)");
|
||||
|
||||
t.ok( !size.equals(null), "equals() returns false on comparison to null");
|
||||
}
|
||||
|
||||
// -->
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user