]>
Commit | Line | Data |
---|---|---|
b37bf2e1 A |
1 | /* The contents of this file are subject to the Netscape Public |
2 | * License Version 1.1 (the "License"); you may not use this file | |
3 | * except in compliance with the License. You may obtain a copy of | |
4 | * the License at http://www.mozilla.org/NPL/ | |
5 | * | |
6 | * Software distributed under the License is distributed on an "AS | |
7 | * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | |
8 | * implied. See the License for the specific language governing | |
9 | * rights and limitations under the License. | |
10 | * | |
11 | * The Original Code is Mozilla Communicator client code, released March | |
12 | * 31, 1998. | |
13 | * | |
14 | * The Initial Developer of the Original Code is Netscape Communications | |
15 | * Corporation. Portions created by Netscape are | |
16 | * Copyright (C) 1998 Netscape Communications Corporation. All | |
17 | * Rights Reserved. | |
18 | * | |
19 | * Contributor(s): | |
20 | * | |
21 | */ | |
22 | /** | |
23 | File Name: proto_2.js | |
24 | Section: | |
25 | Description: new PrototypeObject | |
26 | ||
27 | This tests Object Hierarchy and Inheritance, as described in the document | |
28 | Object Hierarchy and Inheritance in JavaScript, last modified on 12/18/97 | |
29 | 15:19:34 on http://devedge.netscape.com/. Current URL: | |
30 | http://devedge.netscape.com/docs/manuals/communicator/jsobj/contents.htm | |
31 | ||
32 | This tests the syntax ObjectName.prototype = new PrototypeObject using the | |
33 | Employee example in the document referenced above. | |
34 | ||
35 | Author: christine@netscape.com | |
36 | Date: 12 november 1997 | |
37 | */ | |
38 | ||
39 | var SECTION = "proto_2"; | |
40 | var VERSION = "JS1_3"; | |
41 | var TITLE = "new PrototypeObject"; | |
42 | ||
43 | startTest(); | |
44 | writeHeaderToLog( SECTION + " "+ TITLE); | |
45 | ||
46 | var testcases = new Array(); | |
47 | ||
48 | function Employee () { | |
49 | this.name = ""; | |
50 | this.dept = "general"; | |
51 | } | |
52 | function Manager () { | |
53 | this.reports = []; | |
54 | } | |
55 | Manager.prototype = new Employee(); | |
56 | ||
57 | function WorkerBee () { | |
58 | this.projects = new Array(); | |
59 | } | |
60 | ||
61 | WorkerBee.prototype = new Employee; | |
62 | ||
63 | function SalesPerson () { | |
64 | this.dept = "sales"; | |
65 | this.quota = 100; | |
66 | } | |
67 | SalesPerson.prototype = new WorkerBee; | |
68 | ||
69 | function Engineer () { | |
70 | this.dept = "engineering"; | |
71 | this.machine = ""; | |
72 | } | |
73 | Engineer.prototype = new WorkerBee; | |
74 | ||
75 | ||
76 | function test() { | |
77 | for ( tc=0; tc < testcases.length; tc++ ) { | |
78 | testcases[tc].passed = writeTestCaseResult( | |
79 | testcases[tc].expect, | |
80 | testcases[tc].actual, | |
81 | testcases[tc].description +" = "+ | |
82 | testcases[tc].actual ); | |
83 | ||
84 | testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; | |
85 | } | |
86 | stopTest(); | |
87 | return ( testcases ); | |
88 | } | |
89 | ||
90 | var employee = new Employee(); | |
91 | var manager = new Manager(); | |
92 | var workerbee = new WorkerBee(); | |
93 | var salesperson = new SalesPerson(); | |
94 | var engineer = new Engineer(); | |
95 | ||
96 | testcases[tc++] = new TestCase( SECTION, | |
97 | "employee.__proto__ == Employee.prototype", | |
98 | true, | |
99 | employee.__proto__ == Employee.prototype ); | |
100 | ||
101 | testcases[tc++] = new TestCase( SECTION, | |
102 | "manager.__proto__ == Manager.prototype", | |
103 | true, | |
104 | manager.__proto__ == Manager.prototype ); | |
105 | ||
106 | testcases[tc++] = new TestCase( SECTION, | |
107 | "workerbee.__proto__ == WorkerBee.prototype", | |
108 | true, | |
109 | workerbee.__proto__ == WorkerBee.prototype ); | |
110 | ||
111 | testcases[tc++] = new TestCase( SECTION, | |
112 | "salesperson.__proto__ == SalesPerson.prototype", | |
113 | true, | |
114 | salesperson.__proto__ == SalesPerson.prototype ); | |
115 | ||
116 | testcases[tc++] = new TestCase( SECTION, | |
117 | "engineer.__proto__ == Engineer.prototype", | |
118 | true, | |
119 | engineer.__proto__ == Engineer.prototype ); | |
120 | ||
121 | test(); | |
122 |