3 * Adds a xml_eq method to AnotherWay test objects.
10 * Function assertEqual
11 * Test two objects for equivalence (based on ==). Throw an exception
17 * msg - {String} The message to be thrown. This message will be appended
18 * with ": got {got} but expected {expected}" where got and expected are
19 * replaced with string representations of the above arguments.
21 function assertEqual(got, expected, msg) {
22 if(got === undefined) {
24 } else if (got === null) {
27 if(expected === undefined) {
28 expected = "undefined";
29 } else if (expected === null) {
33 throw msg + ": got '" + got + "' but expected '" + expected + "'";
38 * Function assertGeometryEqual
39 * Test two geometries for equivalence. Geometries are considered
40 * equivalent if they are of the same class, and given component
41 * geometries, if all components are equivalent. Throws a message as
42 * exception if not equivalent.
45 * got - {OpenLayers.Geometry}
46 * expected - {OpenLayers.Geometry}
47 * options - {Object} Optional object for configuring test options.
49 function assertGeometryEqual(got, expected, options) {
51 var OpenLayers = Test.AnotherWay._g_test_iframe.OpenLayers;
54 assertEqual(typeof got, typeof expected, "Object types mismatch");
57 assertEqual(got.CLASS_NAME, expected.CLASS_NAME, "Object class mismatch");
59 if(got instanceof OpenLayers.Geometry.Point) {
61 assertEqual(got.x, expected.x, "x mismatch");
62 assertEqual(got.y, expected.y, "y mismatch");
63 assertEqual(got.z, expected.z, "z mismatch");
67 got.components.length, expected.components.length,
68 "Component length mismatch for " + got.CLASS_NAME
70 for(var i=0; i<got.components.length; ++i) {
73 got.components[i], expected.components[i], options
76 throw "Bad component " + i + " for " + got.CLASS_NAME + ": " + err;
84 * Function: Test.AnotherWay._test_object_t.geom_eq
85 * Test if two geometry objects are equivalent. Tests for same geometry
86 * class, same number of components (if any), equivalent component
87 * geometries, and same coordinates.
90 * t.geom_eq(got, expected, message);
94 * got - {OpenLayers.Geometry} Any geometry instance.
95 * expected - {OpenLayers.Geometry} The expected geometry.
96 * msg - {String} A message to print with test output.
97 * options - {Object} Optional object for configuring test options.
99 var proto = Test.AnotherWay._test_object_t.prototype;
100 proto.geom_eq = function(got, expected, msg, options) {
101 // test geometries for equivalence
103 assertGeometryEqual(got, expected, options);
106 this.fail(msg + ": " + err);