pschwartau%netscape.com f6d01f0d66 Initial add.
git-svn-id: svn://10.0.0.236/trunk@100511 18797224-902f-48f8-a5cc-f745e15eee43
2001-08-07 19:45:15 +00:00

297 lines
5.6 KiB
JavaScript

/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either expressed
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation.
* All Rights Reserved.
*
* Contributor(s): pschwartau@netscape.com
* Date: 2001-07-23
*
* SUMMARY: Testing class inheritance
*
*/
//-------------------------------------------------------------------------------------------------
var UBound:Integer = 0;
var bug:String = '(none)';
var summary:String = 'Testing class inheritance';
var propNAME:String = 'name';
var propMOTHER:String = 'mother';
var propFATHER:String = 'father';
var propNONEXIST:String = '@#$%@#^';
var nameUNINIT:String = '(NO NAME HAS BEEN ASSIGNED)';
var nameMOTHER:String = 'Bessie';
var nameFATHER:String = 'Red';
var nameCHILD:String = 'Junior';
var status:String = '';
var statusitems:Array = [];
var actual:String = '';
var actualvalues:Array = [];
var expect:String= '';
var expectedvalues:Array = [];
class Cow
{
static var count:Integer = 0;
var name:String = nameUNINIT;
constructor function Cow(sName:String)
{
count++;
name = sName;
}
}
class Calf extends Cow
{
var mother:Cow;
var father:Cow;
constructor function Calf(sName:String, objMother:Cow, objFather:Cow)
{
Cow(sName);
mother = objMother;
father = objFather;
}
}
var cowMOTHER = new Cow(nameMOTHER);
status = inSection(1);
actual = Cow.count;
expect = 1;
addThis();
status = inSection(2);
actual = typeof cowMOTHER;
expect = TYPE_OBJECT;
addThis();
status = inSection(3);
actual = cowMOTHER is Cow;
expect = true;
addThis();
status = inSection(4);
actual = cowMOTHER is Object;
expect = true;
addThis();
status = inSection(5);
actual = cowMOTHER.name;
expect = nameMOTHER;
addThis();
status = inSection(6);
actual = cowMOTHER[propNAME];
expect = nameMOTHER;
addThis();
status = inSection(7);
actual = cowMOTHER[propNONEXIST];
expect = undefined;
addThis();
var cowFATHER = new Cow(nameFATHER);
status = inSection(8);
actual = Cow.count;
expect = 2;
addThis();
status = inSection(9);
actual = typeof cowFATHER;
expect = TYPE_OBJECT;
addThis();
status = inSection(10);
actual = cowFATHER is Cow
expect = true;
addThis();
status = inSection(11);
actual = cowFATHER is Object;
expect = true;
addThis();
status = inSection(12);
actual = cowFATHER.name;
expect = nameFATHER;
addThis();
status = inSection(13);
actual = cowFATHER[propNAME];
expect = nameFATHER;
addThis();
status = inSection(14);
actual = cowFATHER[propNONEXIST];
expect = undefined;
addThis();
var cowCHILD = new Calf(nameCHILD, cowMOTHER, cowFATHER);
status = inSection(15);
actual = Cow.count;
expect = 3;
addThis();
status = inSection(16);
actual = Calf.count;
expect = Cow.count;
addThis();
status = inSection(17);
actual = typeof cowCHILD;
expect = TYPE_OBJECT;
addThis();
status = inSection(18);
actual = cowCHILD is Calf;
expect = true;
addThis();
status = inSection(19);
actual = cowCHILD is Cow;
expect = true;
addThis();
status = inSection(20);
actual = cowCHILD is Object;
expect = true;
addThis();
status = inSection(21);
actual = cowCHILD.mother;
expect = cowMOTHER;
addThis();
status = inSection(22);
actual = cowCHILD[propMOTHER];
expect = cowMOTHER;
addThis();
status = inSection(23);
actual = cowCHILD.mother.name;
expect = nameMOTHER;
addThis();
status = inSection(24);
actual = cowCHILD.mother[propNAME];
expect = nameMOTHER;
addThis();
status = inSection(25);
actual = cowCHILD[propMOTHER].name;
expect = nameMOTHER;
addThis();
status = inSection(26);
actual = cowCHILD[propMOTHER][propNAME];
expect = nameMOTHER;
addThis();
status = inSection(27);
actual = cowCHILD.father;
expect = cowFATHER;
addThis();
status = inSection(28);
actual = cowCHILD[propFATHER];
expect = cowFATHER;
addThis();
status = inSection(29);
actual = cowCHILD.father.name;
expect = nameFATHER;
addThis();
status = inSection(30);
actual = cowCHILD.father[propNAME];
expect = nameFATHER;
addThis();
status = inSection(31);
actual = cowCHILD[propFATHER].name;
expect = nameFATHER;
addThis();
status = inSection(32);
actual = cowCHILD[propFATHER][propNAME];
expect = nameFATHER;
addThis();
status = inSection(33);
actual = cowCHILD.name;
expect = nameCHILD;
addThis();
status = inSection(34);
actual = cowCHILD[propNAME];
expect = nameCHILD;
addThis();
status = inSection(35);
actual = cowCHILD[propNONEXIST];
expect = undefined;
addThis();
cowCHILD.name = nameCHILD;
status = inSection(36);
actual = cowCHILD.name;
expect = nameCHILD;
addThis();
status = inSection(37);
actual = cowCHILD[propNAME];
expect = nameCHILD;
addThis();
//-------------------------------------------------------------------------------------------------
test();
//-------------------------------------------------------------------------------------------------
function addThis()
{
statusitems[UBound] = status;
actualvalues[UBound] = actual;
expectedvalues[UBound] = expect;
UBound++;
}
function test()
{
enterFunc ('test');
printBugNumber (bug);
printStatus (summary);
for (var i=0; i<UBound; i++)
{
reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
}
exitFunc ('test');
}