<html>
<head>
<!--<script src="http://openlayers.org/api/2.10/OpenLayers.js"></script>-->
<!--<script src="http://openlayers.org/dev/OpenLayers.js"></script>-->
<script src="OLLoader.js"></script>
<script type="text/javascript">
// the overload function under test
function overload(C, o) {
if(typeof o.initialize === "function" &&
C === C.prototype.initialize) {
// OL 2.11
var proto = C.prototype;
var staticProps = OpenLayers.Util.extend({}, C);
C = o.initialize;
C.prototype = proto;
OpenLayers.Util.extend(C, staticProps);
}
OpenLayers.Util.extend(C.prototype, o);
return C;
}
function test_overload_1(t) {
// overload constructor
t.plan(1);
var A = OpenLayers.Class({
initialize: function() {
this.a = "foo";
}
});
A = overload(A, {
initialize: function() {
this.a = "bar";
}
});
var a = new A;
t.eq(a.a, "bar", "ctor overloaded");
}
function test_overload_2(t) {
// overload regular method
t.plan(1);
var A = OpenLayers.Class({
initialize: function() {
},
method: function() {
this.a = "foo";
}
});
A = overload(A, {
method: function() {
this.a = "bar";
}
});
var a = new A;
a.method();
t.eq(a.a, "bar", "method overloaded");
}
function test_overload_3(t) {
// overload constructor of subclass
t.plan(1);
var A = OpenLayers.Class({
initialize: function() {
this.a = "foo";
}
});
var B = OpenLayers.Class(A, {
initialize: function() {
A.prototype.initialize.call(this);
}
});
B = overload(B, {
initialize: function() {
A.prototype.initialize.call(this);
this.a = "bar";
}
});
var b = new B;
t.eq(b.a, "bar", "ctor overloaded");
}
function test_overload_4(t) {
// overload constructor of parent class
t.plan(1);
var A = OpenLayers.Class({
initialize: function() {
this.a = "foo";
}
});
var B = OpenLayers.Class(A, {
initialize: function() {
A.prototype.initialize.call(this);
}
});
A = overload(A, {
initialize: function() {
this.a = "bar";
}
});
var b = new B;
t.eq(b.a, "bar", "ctor overloaded");
}
function test_overload_5(t) {
// overload constructor of parent class, which itself
// doesn't defined "initialize"
t.plan(1);
var A = OpenLayers.Class({
initialize: function() {
this.a = "foo";
}
});
var B = OpenLayers.Class(A, {});
A = overload(A, {
initialize: function() {
this.a = "bar";
}
});
var b = new B;
t.eq(b.a, "bar", "ctor overloaded");
}
function test_overload_6(t) {
// with static methods
t.plan(1);
var A = OpenLayers.Class({
initialize: function() {
}
});
A.staticMethod = function() {};
A = overload(A, {
initialize: function() {
}
});
var exc = false;
try {
A.staticMethod();
} catch(e) {
exc = true;
}
t.ok(!exc, "static method still there");
}
</script>
</head>
<body>
</body>
</html>