[OpenLayers-Commits] r2361 - sandbox/vector-2.4/tests
commits at openlayers.org
commits at openlayers.org
Mon Mar 5 19:32:38 EST 2007
Author: euzuro
Date: 2007-03-05 19:32:38 -0500 (Mon, 05 Mar 2007)
New Revision: 2361
Added:
sandbox/vector-2.4/tests/test_Geometry.html
Modified:
sandbox/vector-2.4/tests/list-tests.html
Log:
add tests code for Geometry
Modified: sandbox/vector-2.4/tests/list-tests.html
===================================================================
--- sandbox/vector-2.4/tests/list-tests.html 2007-03-06 00:31:18 UTC (rev 2360)
+++ sandbox/vector-2.4/tests/list-tests.html 2007-03-06 00:32:38 UTC (rev 2361)
@@ -4,6 +4,7 @@
<li>BaseTypes/test_Size.html</li>
<li>BaseTypes/test_LonLat.html</li>
<li>BaseTypes/test_Bounds.html</li>
+ <li>test_Geometry.html</li>
<li>Geometry/test_Point.html</li>
<li>Geometry/test_MultiPoint.html</li>
<li>Geometry/test_Curve.html</li>
Added: sandbox/vector-2.4/tests/test_Geometry.html
===================================================================
--- sandbox/vector-2.4/tests/test_Geometry.html (rev 0)
+++ sandbox/vector-2.4/tests/test_Geometry.html 2007-03-06 00:32:38 UTC (rev 2361)
@@ -0,0 +1,205 @@
+<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(5);
+
+ 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
+ var object = new Object();
+
+ g.setBounds(object);
+ t.ok(g.bounds == null, "setbounds with object sans classname does not crash or set bounds");
+
+ //lonlat object
+ var testLonLat = new OpenLayers.LonLat(5,12);
+ object = testLonLat.clone();
+
+ g.setBounds(object);
+
+ var testBounds = new OpenLayers.Bounds(testLonLat.lon, testLonLat.lat,
+ testLonLat.lon, testLonLat.lat);
+ t.ok(g.bounds.equals(testBounds), "setbounds() lonlat object correct");
+
+ //point object
+ var testPoint = new OpenLayers.Geometry.Point(5,12);
+ object = testPoint.clone();
+
+ g.setBounds(object);
+
+ var testBounds = new OpenLayers.Bounds(testPoint.lon, testPoint.lat,
+ testPoint.lon, testPoint.lat);
+ t.ok(g.bounds.equals(testBounds), "setbounds() point object correct");
+
+ //bounds object
+ var testBounds = new OpenLayers.Bounds(1,2,3,4);
+ object = testBounds.clone();
+
+ g.setBounds(object);
+
+ t.ok(g.bounds.equals(testBounds), "setbounds() bounds object correct");
+
+
+ }
+
+ function test_03_Geometry_extendBounds(t) {
+ t.plan(2);
+
+ var g = new OpenLayers.Geometry();
+
+ //this.bounds null (setBounds() called)
+ g.setBounds = function(b) { g_Bounds = b; };
+
+ var object = {};
+ g_Bounds = null;
+ g.extendBounds(object);
+ t.ok(g_Bounds == object, "setBounds() called when this.bounds is null");
+
+ //this.bounds non-null thus extend()
+ g.bounds = {
+ 'extend': function(b) { g_Bounds = b; }
+ };
+
+ var object = {};
+ g_Bounds = null;
+ g.extendBounds(object);
+ t.ok(g_Bounds == object, "setBounds() called when this.bounds is non-null");
+ }
+
+ 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");
+ }
+
+/**
+ * Add tests for these later if we decide to keep them in
+ *
+ *
+
+ setEvents: function() {
+ if (this.id != null) {
+ var domElement = $(this.id);
+ if (domElement != null) {
+ this.events = new OpenLayers.Events(this, domElement, null);
+ }
+ }
+ },
+
+ registerEventCallback: function(type, obj, callback) {
+ if (this.events != null) {
+ this.events.register(type, obj, callback);
+ }
+ },
+
+*
+******/
+
+
+
+
+ // -->
+ </script>
+</head>
+<body>
+ <div id="map" style="width: 1024px; height: 512px;"/>
+</body>
+</html>
More information about the Commits
mailing list