]>
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_5.js | |
24 | Section: | |
25 | Description: Logical OR || in Constructors | |
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 | This tests the logical OR opererator || syntax in constructors. | |
36 | ||
37 | Author: christine@netscape.com | |
38 | Date: 12 november 1997 | |
39 | */ | |
40 | ||
41 | var SECTION = "proto_5"; | |
42 | var VERSION = "JS1_3"; | |
43 | var TITLE = "Logical OR || in Constructors"; | |
44 | ||
45 | startTest(); | |
46 | writeHeaderToLog( SECTION + " "+ TITLE); | |
47 | ||
48 | var testcases = new Array(); | |
49 | ||
50 | function Employee ( name, dept ) { | |
51 | this.name = name || ""; | |
52 | this.dept = dept || "general"; | |
53 | } | |
54 | function Manager () { | |
55 | this.reports = []; | |
56 | } | |
57 | Manager.prototype = new Employee(); | |
58 | ||
59 | function WorkerBee ( projs ) { | |
60 | this.projects = projs || new Array(); | |
61 | } | |
62 | WorkerBee.prototype = new Employee(); | |
63 | ||
64 | function SalesPerson () { | |
65 | this.dept = "sales"; | |
66 | this.quota = 100; | |
67 | } | |
68 | SalesPerson.prototype = new WorkerBee(); | |
69 | ||
70 | function Engineer ( machine ) { | |
71 | this.dept = "engineering"; | |
72 | this.machine = machine || ""; | |
73 | } | |
74 | Engineer.prototype = new WorkerBee(); | |
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 | ||
91 | var pat = new Engineer( "indy" ); | |
92 | ||
93 | var les = new Engineer(); | |
94 | ||
95 | testcases[tc++] = new TestCase( SECTION, | |
96 | "var pat = new Engineer(\"indy\"); pat.name", | |
97 | "", | |
98 | pat.name ); | |
99 | ||
100 | testcases[tc++] = new TestCase( SECTION, | |
101 | "pat.dept", | |
102 | "engineering", | |
103 | pat.dept ); | |
104 | ||
105 | testcases[tc++] = new TestCase( SECTION, | |
106 | "pat.projects.length", | |
107 | 0, | |
108 | pat.projects.length ); | |
109 | ||
110 | testcases[tc++] = new TestCase( SECTION, | |
111 | "pat.machine", | |
112 | "indy", | |
113 | pat.machine ); | |
114 | ||
115 | testcases[tc++] = new TestCase( SECTION, | |
116 | "pat.__proto__ == Engineer.prototype", | |
117 | true, | |
118 | pat.__proto__ == Engineer.prototype ); | |
119 | ||
120 | testcases[tc++] = new TestCase( SECTION, | |
121 | "var les = new Engineer(); les.name", | |
122 | "", | |
123 | les.name ); | |
124 | ||
125 | testcases[tc++] = new TestCase( SECTION, | |
126 | "les.dept", | |
127 | "engineering", | |
128 | les.dept ); | |
129 | ||
130 | testcases[tc++] = new TestCase( SECTION, | |
131 | "les.projects.length", | |
132 | 0, | |
133 | les.projects.length ); | |
134 | ||
135 | testcases[tc++] = new TestCase( SECTION, | |
136 | "les.machine", | |
137 | "", | |
138 | les.machine ); | |
139 | ||
140 | testcases[tc++] = new TestCase( SECTION, | |
141 | "les.__proto__ == Engineer.prototype", | |
142 | true, | |
143 | les.__proto__ == Engineer.prototype ); | |
144 | ||
145 | ||
146 | test(); |