1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * pschwartau@netscape.com
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
42 * SUMMARY: Testing obj.__lookupGetter__(), obj.__lookupSetter__()
43 * See http://bugzilla.mozilla.org/show_bug.cgi?id=71992
45 * Brendan: "I see no need to provide more than the minimum:
46 * o.__lookupGetter__('p') returns the getter function for o.p,
47 * or undefined if o.p has no getter. Users can wrap and layer."
49 //-----------------------------------------------------------------------------
51 var BUGNUMBER = 71992;
52 var summary = 'Testing obj.__lookupGetter__(), obj.__lookupSetter__()';
53 var statprefix = 'Status: ';
55 var statusitems = [ ];
57 var actualvalues = [ ];
59 var expectedvalues = [ ];
61 var cnColor = 'color';
62 var cnNonExistingProp = 'ASDF_#_$%';
63 var cnDEFAULT = 'default name';
71 // The only setter and getter functions we'll use in the three sections below -
72 var cnNameSetter = function(newValue) {this._name=newValue; this.nameSETS++;};
73 var cnNameGetter = function() {this.nameGETS++; return this._name;};
77 // SECTION1: define getter/setter directly on an object (not its prototype)
81 obj.__defineSetter__(cnName, cnNameSetter);
82 obj.__defineGetter__(cnName, cnNameGetter);
86 status ='In SECTION1 of test; looking up extant getter/setter';
87 actual = [obj.__lookupSetter__(cnName), obj.__lookupGetter__(cnName)];
88 expect = [cnNameSetter, cnNameGetter];
91 status = 'In SECTION1 of test; looking up nonexistent getter/setter';
92 actual = [obj.__lookupSetter__(cnColor), obj.__lookupGetter__(cnColor)];
93 expect = [undefined, undefined];
96 status = 'In SECTION1 of test; looking up getter/setter on nonexistent property';
97 actual = [obj.__lookupSetter__(cnNonExistingProp), obj.__lookupGetter__(cnNonExistingProp)];
98 expect = [undefined, undefined];
103 // SECTION2: define getter/setter in Object.prototype
104 Object.prototype.nameSETS = 0;
105 Object.prototype.nameGETS = 0;
106 Object.prototype.__defineSetter__(cnName, cnNameSetter);
107 Object.prototype.__defineGetter__(cnName, cnNameGetter);
113 status = 'In SECTION2 of test looking up extant getter/setter';
114 actual = [obj.__lookupSetter__(cnName), obj.__lookupGetter__(cnName)];
115 expect = [cnNameSetter, cnNameGetter];
118 status = 'In SECTION2 of test; looking up nonexistent getter/setter';
119 actual = [obj.__lookupSetter__(cnColor), obj.__lookupGetter__(cnColor)];
120 expect = [undefined, undefined];
123 status = 'In SECTION2 of test; looking up getter/setter on nonexistent property';
124 actual = [obj.__lookupSetter__(cnNonExistingProp), obj.__lookupGetter__(cnNonExistingProp)];
125 expect = [undefined, undefined];
130 // SECTION 3: define getter/setter in prototype of user-defined constructor
131 function TestObject()
134 TestObject.prototype.nameSETS = 0;
135 TestObject.prototype.nameGETS = 0;
136 TestObject.prototype.__defineSetter__(cnName, cnNameSetter);
137 TestObject.prototype.__defineGetter__(cnName, cnNameGetter);
138 TestObject.prototype.name = cnDEFAULT;
140 obj = new TestObject();
144 status = 'In SECTION3 of test looking up extant getter/setter';
145 actual = [obj.__lookupSetter__(cnName), obj.__lookupGetter__(cnName)];
146 expect = [cnNameSetter, cnNameGetter];
149 status = 'In SECTION3 of test; looking up nonexistent getter/setter';
150 actual = [obj.__lookupSetter__(cnColor), obj.__lookupGetter__(cnColor)];
151 expect = [undefined, undefined];
154 status = 'In SECTION3 of test; looking up getter/setter on nonexistent property';
155 actual = [obj.__lookupSetter__(cnNonExistingProp), obj.__lookupGetter__(cnNonExistingProp)];
156 expect = [undefined, undefined];
161 //---------------------------------------------------------------------------------
163 //---------------------------------------------------------------------------------
168 statusitems[UBound] = status;
169 actualvalues[UBound] = actual.toString();
170 expectedvalues[UBound] = expect.toString();
178 printBugNumber(BUGNUMBER);
179 printStatus (summary);
181 for (var i = 0; i < UBound; i++)
183 reportCompare(expectedvalues[i], actualvalues[i], getStatus(i));
190 function getStatus(i)
192 return statprefix + statusitems[i];