| 1 |
<html> |
|---|
| 2 |
<head> |
|---|
| 3 |
<script src="../lib/OpenLayers.js"></script> |
|---|
| 4 |
<script type="text/javascript"> |
|---|
| 5 |
var map; |
|---|
| 6 |
|
|---|
| 7 |
function test_01_Geometry_constructor (t) { |
|---|
| 8 |
t.plan( 2 ); |
|---|
| 9 |
|
|---|
| 10 |
var g = new OpenLayers.Geometry(); |
|---|
| 11 |
|
|---|
| 12 |
t.eq(g.CLASS_NAME, "OpenLayers.Geometry", "correct CLASS_NAME") |
|---|
| 13 |
t.ok(OpenLayers.String.startsWith(g.id, "OpenLayers.Geometry_"), |
|---|
| 14 |
"id correctly set"); |
|---|
| 15 |
} |
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
function test_Geometry_clone(t) { |
|---|
| 19 |
t.plan(2); |
|---|
| 20 |
var geometry = new OpenLayers.Geometry(); |
|---|
| 21 |
var clone = geometry.clone(); |
|---|
| 22 |
|
|---|
| 23 |
t.eq(clone.CLASS_NAME, "OpenLayers.Geometry", "correct CLASS_NAME") |
|---|
| 24 |
t.ok(OpenLayers.String.startsWith(clone.id, "OpenLayers.Geometry_"), |
|---|
| 25 |
"id correctly set"); |
|---|
| 26 |
} |
|---|
| 27 |
|
|---|
| 28 |
function test_02_Geometry_setBounds(t) { |
|---|
| 29 |
t.plan( 2 ); |
|---|
| 30 |
|
|---|
| 31 |
var g = new OpenLayers.Geometry(); |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
g.setBounds(null); |
|---|
| 35 |
t.ok(g.bounds == null, "setbounds with null value does not crash or set bounds"); |
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
g_clone = {}; |
|---|
| 39 |
var object = { |
|---|
| 40 |
'clone': function() { return g_clone; } |
|---|
| 41 |
}; |
|---|
| 42 |
g.setBounds(object); |
|---|
| 43 |
t.ok(g.bounds == g_clone, "setbounds with valid object sets bounds, calls clone"); |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
function test_03_Geometry_extendBounds(t) { |
|---|
| 47 |
t.plan(9); |
|---|
| 48 |
|
|---|
| 49 |
OpenLayers.Bounds.prototype._extend = |
|---|
| 50 |
OpenLayers.Bounds.prototype.extend; |
|---|
| 51 |
OpenLayers.Bounds.prototype.extend = function(b) { |
|---|
| 52 |
g_extendBounds = b; |
|---|
| 53 |
}; |
|---|
| 54 |
|
|---|
| 55 |
var g = new OpenLayers.Geometry(); |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
g.setBounds = function(b) { g_setBounds = b; }; |
|---|
| 59 |
g.calculateBounds = function() { g_calculateBounds = {}; }; |
|---|
| 60 |
var object = {}; |
|---|
| 61 |
g_setBounds = null; |
|---|
| 62 |
g_calculateBounds = null; |
|---|
| 63 |
g_extendBounds = null; |
|---|
| 64 |
g.extendBounds(object); |
|---|
| 65 |
t.ok(g_calculateBounds != null, "calculateBounds() called when this.bounds is null"); |
|---|
| 66 |
t.ok(g_setBounds == object, "setBounds() called when this.bounds is null and calculateBounds() is null too"); |
|---|
| 67 |
t.ok(g_extendBounds != object, "this.bounds.extend() not called when this.bounds is null and calculateBounds() is null too"); |
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
g_calcBounds = new OpenLayers.Bounds(1,2,3,4); |
|---|
| 73 |
g.calculateBounds = function() { |
|---|
| 74 |
g_calculateBounds = {}; |
|---|
| 75 |
this.bounds = g_calcBounds; |
|---|
| 76 |
}; |
|---|
| 77 |
var object = {}; |
|---|
| 78 |
|
|---|
| 79 |
g_setBounds = null; |
|---|
| 80 |
g_calculateBounds = null; |
|---|
| 81 |
g_extendBounds = null; |
|---|
| 82 |
g.extendBounds(object); |
|---|
| 83 |
t.ok(g_calculateBounds != null, "calculateBounds() called when this.bounds is null"); |
|---|
| 84 |
t.ok(g_setBounds == null, "setBounds() not called when this.bounds is null and calculateBounds() sets this.bounds"); |
|---|
| 85 |
t.ok(g_extendBounds == object, "this.bounds.extend() called when this.bounds is null and calculateBounds() sets this.bounds"); |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
g_setBounds = null; |
|---|
| 92 |
g_calculateBounds = null; |
|---|
| 93 |
g_extendBounds = null; |
|---|
| 94 |
g.extendBounds(object); |
|---|
| 95 |
t.ok(g_calculateBounds == null, "calculateBounds() not called when this.bounds is non null"); |
|---|
| 96 |
t.ok(g_setBounds == null, "setBounds() not called when this.bounds is nonnull"); |
|---|
| 97 |
t.ok(g_extendBounds == object, "this.bounds.extend() called when this.bounds is non-null"); |
|---|
| 98 |
|
|---|
| 99 |
OpenLayers.Bounds.prototype.extend = |
|---|
| 100 |
OpenLayers.Bounds.prototype._extend; |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
} |
|---|
| 104 |
|
|---|
| 105 |
function test_04_Geometry_getBounds(t) { |
|---|
| 106 |
t.plan(1); |
|---|
| 107 |
|
|---|
| 108 |
var g = new OpenLayers.Geometry(); |
|---|
| 109 |
|
|---|
| 110 |
var testBounds = new OpenLayers.Bounds(1,2,3,4); |
|---|
| 111 |
g.bounds = testBounds.clone(); |
|---|
| 112 |
|
|---|
| 113 |
t.ok(g.getBounds().equals(testBounds), "getBounds works"); |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|
| 116 |
function test_05_Geometry_atPoint(t) { |
|---|
| 117 |
t.plan(6); |
|---|
| 118 |
|
|---|
| 119 |
var g = new OpenLayers.Geometry(); |
|---|
| 120 |
|
|---|
| 121 |
var lonlat = null; |
|---|
| 122 |
var lon = 5; |
|---|
| 123 |
var lat = 10; |
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
g.bounds = new OpenLayers.Bounds(); |
|---|
| 127 |
|
|---|
| 128 |
var atPoint = g.atPoint(lonlat, lon, lat); |
|---|
| 129 |
t.ok(!atPoint, "null lonlat") |
|---|
| 130 |
|
|---|
| 131 |
|
|---|
| 132 |
g.bounds = null; |
|---|
| 133 |
lonlat = new OpenLayers.LonLat(1,2); |
|---|
| 134 |
|
|---|
| 135 |
atPoint = g.atPoint(lonlat, lon, lat); |
|---|
| 136 |
t.ok(!atPoint, "null this.bounds") |
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
OpenLayers.Bounds.prototype._containsLonLat = OpenLayers.Bounds.prototype.containsLonLat; |
|---|
| 142 |
g_Return = {}; |
|---|
| 143 |
OpenLayers.Bounds.prototype.containsLonLat = function(ll) { |
|---|
| 144 |
g_bounds = this; |
|---|
| 145 |
return g_Return; |
|---|
| 146 |
} |
|---|
| 147 |
|
|---|
| 148 |
var testBounds = new OpenLayers.Bounds(10,20,30,40); |
|---|
| 149 |
g.bounds = testBounds.clone(); |
|---|
| 150 |
lonlat = new OpenLayers.LonLat(20,30); |
|---|
| 151 |
|
|---|
| 152 |
g_bounds = null; |
|---|
| 153 |
atPoint = g.atPoint(lonlat); |
|---|
| 154 |
t.ok(g_bounds.equals(testBounds), "default toleranceLon/Lat are 0"); |
|---|
| 155 |
t.ok(atPoint == g_Return, "default toleranceLon/Lat returns correctly"); |
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
var testBounds = new OpenLayers.Bounds(10,20,30,40); |
|---|
| 159 |
g.bounds = testBounds.clone(); |
|---|
| 160 |
lonlat = new OpenLayers.LonLat(20,30); |
|---|
| 161 |
|
|---|
| 162 |
g_bounds = null; |
|---|
| 163 |
atPoint = g.atPoint(lonlat, lon, lat); |
|---|
| 164 |
testBounds.left -= lon; |
|---|
| 165 |
testBounds.bottom -= lat; |
|---|
| 166 |
testBounds.right += lon; |
|---|
| 167 |
testBounds.top += lat; |
|---|
| 168 |
t.ok(g_bounds.equals(testBounds), "real toleranceLon/Lat are 0"); |
|---|
| 169 |
t.ok(atPoint == g_Return, "real toleranceLon/Lat returns correctly"); |
|---|
| 170 |
|
|---|
| 171 |
OpenLayers.Bounds.prototype.containsLonLat = OpenLayers.Bounds.prototype._containsLonLat; |
|---|
| 172 |
|
|---|
| 173 |
} |
|---|
| 174 |
|
|---|
| 175 |
function test_06_Geometry_getLength(t) { |
|---|
| 176 |
t.plan(1); |
|---|
| 177 |
|
|---|
| 178 |
var g = new OpenLayers.Geometry(); |
|---|
| 179 |
|
|---|
| 180 |
t.eq(g.getLength(), 0, "getLength is 0"); |
|---|
| 181 |
} |
|---|
| 182 |
|
|---|
| 183 |
function test_07_Geometry_getArea(t) { |
|---|
| 184 |
t.plan(1); |
|---|
| 185 |
|
|---|
| 186 |
var g = new OpenLayers.Geometry(); |
|---|
| 187 |
|
|---|
| 188 |
t.eq(g.getArea(), 0, "getArea is 0"); |
|---|
| 189 |
} |
|---|
| 190 |
|
|---|
| 191 |
function test_08_Geometry_clearBounds(t) { |
|---|
| 192 |
t.plan(2); |
|---|
| 193 |
|
|---|
| 194 |
var g = new OpenLayers.Geometry(); |
|---|
| 195 |
g.parent = new OpenLayers.Geometry(); |
|---|
| 196 |
|
|---|
| 197 |
g.bounds = "foo"; |
|---|
| 198 |
g.parent.bounds = "bar"; |
|---|
| 199 |
|
|---|
| 200 |
g.clearBounds(); |
|---|
| 201 |
t.ok(g.bounds == null, "bounds is correctly cleared"); |
|---|
| 202 |
t.ok(g.parent.bounds == null, "parent geometry bounds is correctly cleared"); |
|---|
| 203 |
} |
|---|
| 204 |
|
|---|
| 205 |
function test_99_Geometry_destroy(t) { |
|---|
| 206 |
t.plan( 2 ); |
|---|
| 207 |
|
|---|
| 208 |
var g = new OpenLayers.Geometry(); |
|---|
| 209 |
g.bounds = new OpenLayers.Bounds(); |
|---|
| 210 |
|
|---|
| 211 |
g_style_destroy = null; |
|---|
| 212 |
g.destroy(); |
|---|
| 213 |
|
|---|
| 214 |
t.eq(g.id, null, "id nullified"); |
|---|
| 215 |
|
|---|
| 216 |
t.eq(g.bounds, null, "bounds nullified"); |
|---|
| 217 |
|
|---|
| 218 |
} |
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
</script> |
|---|
| 223 |
</head> |
|---|
| 224 |
<body> |
|---|
| 225 |
<div id="map" style="width: 1024px; height: 512px;"/> |
|---|
| 226 |
</body> |
|---|
| 227 |
</html> |
|---|