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