]> git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_3/inherit/proto_1.js
JavaScriptCore-7601.1.46.3.tar.gz
[apple/javascriptcore.git] / tests / mozilla / js1_3 / inherit / proto_1.js
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_1.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_1";
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 WorkerBee.prototype = new Employee();
61
62 function SalesPerson () {
63 this.dept = "sales";
64 this.quota = 100;
65 }
66 SalesPerson.prototype = new WorkerBee();
67
68 function Engineer () {
69 this.dept = "engineering";
70 this.machine = "";
71 }
72 Engineer.prototype = new WorkerBee();
73
74 function test() {
75 for ( tc=0; tc < testcases.length; tc++ ) {
76 testcases[tc].passed = writeTestCaseResult(
77 testcases[tc].expect,
78 testcases[tc].actual,
79 testcases[tc].description +" = "+
80 testcases[tc].actual );
81
82 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
83 }
84 stopTest();
85 return ( testcases );
86 }
87 var jim = new Employee();
88
89 testcases[tc++] = new TestCase( SECTION,
90 "jim = new Employee(); jim.name",
91 "",
92 jim.name );
93
94
95 testcases[tc++] = new TestCase( SECTION,
96 "jim = new Employee(); jim.dept",
97 "general",
98 jim.dept );
99
100 var sally = new Manager();
101
102 testcases[tc++] = new TestCase( SECTION,
103 "sally = new Manager(); sally.name",
104 "",
105 sally.name );
106 testcases[tc++] = new TestCase( SECTION,
107 "sally = new Manager(); sally.dept",
108 "general",
109 sally.dept );
110
111 testcases[tc++] = new TestCase( SECTION,
112 "sally = new Manager(); sally.reports.length",
113 0,
114 sally.reports.length );
115
116 testcases[tc++] = new TestCase( SECTION,
117 "sally = new Manager(); typeof sally.reports",
118 "object",
119 typeof sally.reports );
120
121 var fred = new SalesPerson();
122
123 testcases[tc++] = new TestCase( SECTION,
124 "fred = new SalesPerson(); fred.name",
125 "",
126 fred.name );
127
128 testcases[tc++] = new TestCase( SECTION,
129 "fred = new SalesPerson(); fred.dept",
130 "sales",
131 fred.dept );
132
133 testcases[tc++] = new TestCase( SECTION,
134 "fred = new SalesPerson(); fred.quota",
135 100,
136 fred.quota );
137
138 testcases[tc++] = new TestCase( SECTION,
139 "fred = new SalesPerson(); fred.projects.length",
140 0,
141 fred.projects.length );
142
143 var jane = new Engineer();
144
145 testcases[tc++] = new TestCase( SECTION,
146 "jane = new Engineer(); jane.name",
147 "",
148 jane.name );
149
150 testcases[tc++] = new TestCase( SECTION,
151 "jane = new Engineer(); jane.dept",
152 "engineering",
153 jane.dept );
154
155 testcases[tc++] = new TestCase( SECTION,
156 "jane = new Engineer(); jane.projects.length",
157 0,
158 jane.projects.length );
159
160 testcases[tc++] = new TestCase( SECTION,
161 "jane = new Engineer(); jane.machine",
162 "",
163 jane.machine );
164
165
166 test();