~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/js/src/xpconnect/tests/idispatch/Tests/WrappedCOM/Methods/XPCIDispatchMethodTests.js

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
2
 * ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
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/
 
9
 *
 
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
 
13
 * License.
 
14
 *
 
15
 * The Original Code is the IDispatch implementation for XPConnect.
 
16
 *
 
17
 * The Initial Developer of the Original Code is
 
18
 * David Bradley.
 
19
 * Portions created by the Initial Developer are Copyright (C) 2002
 
20
 * the Initial Developer. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
24
 * Alternatively, the contents of this file may be used under the terms of
 
25
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
26
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
28
 * of those above. If you wish to allow use of your version of this file only
 
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
30
 * use your version of this file under the terms of the MPL, indicate your
 
31
 * decision by deleting the provisions above and replace them with the notice
 
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
33
 * the provisions above, a recipient may use your version of this file under
 
34
 * the terms of any one of the MPL, the GPL or the LGPL.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
 
 
38
/**
 
39
 * Verify that we can access but not overwrite the values of read-only 
 
40
 * attributes.
 
41
 */
 
42
 
 
43
test();
 
44
 
 
45
function TestOutMethod(obj, method, value)
 
46
{
 
47
    printDebug("TestOutMethod - " + method);
 
48
    var x = new Object();
 
49
    try
 
50
    {
 
51
        obj[method](x);
 
52
        reportCompare(value, x.value, "Testing output parameter: " + method);
 
53
    }
 
54
    catch (e)
 
55
    {
 
56
        reportFailure("Testing output parameter failed: " + method + ": " + e.toString());
 
57
    }
 
58
}
 
59
 
 
60
function TestReturnMethod(obj, method, value)
 
61
{
 
62
    printDebug("TestReturnMethod - " + method);
 
63
    try
 
64
    {
 
65
        reportCompare(value, obj[method](), "Testing output parameter: " + method);
 
66
    }
 
67
    catch (e)
 
68
    {
 
69
        reportFailure("Testing return value failed: " + method + ": " + e.toString());
 
70
    }
 
71
}
 
72
 
 
73
function TestInputMethod(obj, method, value)
 
74
{
 
75
    printDebug("TestInputMethod - " + method);
 
76
    try
 
77
    {
 
78
        obj[method.toLowerCase()](value);
 
79
    }
 
80
    catch (e)
 
81
    {
 
82
        reportFailure("Testing input parameter failed: " + method + ": " + e.toString());
 
83
    }
 
84
}
 
85
 
 
86
function TestInOutMethod(obj, method, inValue, outValue)
 
87
{
 
88
    printDebug("TestInOutMethod - " + method);
 
89
    try
 
90
    {
 
91
        var param = { value : inValue };
 
92
        obj[method](param);
 
93
        reportCompare(outValue, param.value, "Testing in/out parameter: " + method);
 
94
    }
 
95
    catch (e)
 
96
    {
 
97
        reportFailure("Testing in/out parameter failed: " + method + ": " + e.toString());
 
98
    }
 
99
}
 
100
 
 
101
function test()
 
102
{
 
103
    printStatus("Testing methods"); 
 
104
    var obj = COMObject(CLSID_nsXPCDispTestMethods);    
 
105
    try
 
106
    {
 
107
        obj.NoParameters();
 
108
    }
 
109
    catch (e)
 
110
    {
 
111
        reportFailure("NoParameters failed: " + e.toString());
 
112
    }
 
113
    printStatus("Test method - Return values"); 
 
114
    TestReturnMethod(obj, "ReturnBSTR", "Boo");
 
115
    TestReturnMethod(obj, "ReturnI4",99999);
 
116
    TestReturnMethod(obj, "ReturnUI1", 99);
 
117
    TestReturnMethod(obj, "ReturnI2",9999);
 
118
    TestReturnMethod(obj, "ReturnR4",99999.1);
 
119
    TestReturnMethod(obj, "ReturnR8", 99999999999.99);
 
120
    TestReturnMethod(obj, "ReturnBool", true);
 
121
 
 
122
    printStatus("TestReturnMethod - ReturnIDispatch");
 
123
    compareObject(obj.ReturnIDispatch(), nsXPCDispSimpleDesc, "Test method - Return IDispatch"); 
 
124
    var E_FAIL= -2147467259;
 
125
    TestReturnMethod(obj, "ReturnError", E_FAIL);
 
126
    TestReturnMethod(obj, "ReturnDate", "5/2/2002");
 
127
    // TestReturnMethod(obj, ReturnIUnknown(IUnknown * * result)
 
128
    TestReturnMethod(obj, "ReturnI1", 120);
 
129
    TestReturnMethod(obj, "ReturnUI2", 9999);
 
130
    TestReturnMethod(obj, "ReturnUI4", 3000000000);
 
131
    TestReturnMethod(obj, "ReturnInt", -999999);
 
132
    TestReturnMethod(obj, "ReturnUInt", 3000000000);
 
133
 
 
134
    printStatus("Test method - Input params");
 
135
    TestInputMethod(obj, "TakesBSTR", "TakesBSTR");
 
136
    TestInputMethod(obj, "TakesI4", 999999);
 
137
    TestInputMethod(obj, "TakesUI1", 42);
 
138
    TestInputMethod(obj, "TakesI2", 32000);
 
139
    TestInputMethod(obj, "TakesR4", 99999.99);
 
140
    TestInputMethod(obj, "TakesR8", 999999999.99);
 
141
    TestInputMethod(obj, "TakesBool", true);
 
142
    var x = { Number : 5, ClassName : "nsXPCDispSimple" };
 
143
    TestInputMethod(obj, "TakesIDispatch", x);
 
144
    // This would always fail, type mismatch (no way to indicate this is going
 
145
    // to an error, and there's no automatic conversion from integers to error
 
146
    // codes
 
147
    // TestInputMethod(obj, "TakesError", E_FAIL);
 
148
    TestInputMethod(obj, "TakesDate", "5/2/2002");
 
149
    // TestInputMethod(obj, TakesIUnknown, );
 
150
    TestInputMethod(obj, "TakesI1", 42);
 
151
    TestInputMethod(obj, "TakesUI2", 50000);
 
152
    TestInputMethod(obj, "TakesUI4", 4026531840);
 
153
    TestInputMethod(obj, "TakesInt", -10000000);
 
154
    TestInputMethod(obj, "TakesUInt", 3758096384);
 
155
 
 
156
    printStatus("Test method - Output params");
 
157
    TestOutMethod(obj, "OutputsBSTR", "Boo");
 
158
    TestOutMethod(obj, "OutputsI4",99999);
 
159
    TestOutMethod(obj, "OutputsUI1", 99);
 
160
    TestOutMethod(obj, "OutputsI2",9999);
 
161
    TestOutMethod(obj, "OutputsR4",999999.1);
 
162
    TestOutMethod(obj, "OutputsR8", 99999999999.99);
 
163
    TestOutMethod(obj, "OutputsBool", true);
 
164
 
 
165
    var outParam = new Object();
 
166
    obj.OutputsIDispatch(outParam);
 
167
    compareObject(outParam.value, nsXPCDispSimpleDesc, "Test method - Output params"); 
 
168
    TestOutMethod(obj, "OutputsError", E_FAIL);
 
169
    TestOutMethod(obj, "OutputsDate", "5/2/2002");
 
170
    // TestOutMethod(obj, OutputsIUnknown(IUnknown * * result)
 
171
    TestOutMethod(obj, "OutputsI1", 120);
 
172
    TestOutMethod(obj, "OutputsUI2", 9999);
 
173
    TestOutMethod(obj, "OutputsUI4", 3000000000);
 
174
 
 
175
    printStatus("Test method - In/out params");
 
176
    TestInOutMethod(obj, "InOutsBSTR", "String", "StringAppended");
 
177
    TestInOutMethod(obj, "InOutsI4", 2000000, -2000000);
 
178
    TestInOutMethod(obj, "InOutsUI1", 50, 8);
 
179
    TestInOutMethod(obj, "InOutsI2", -1000, 9000);
 
180
    TestInOutMethod(obj, "InOutsR4", -2.05, 3.0);
 
181
    TestInOutMethod(obj, "InOutsR8", -5.5, 49999994.50000005);
 
182
    TestInOutMethod(obj, "InOutsBool", true, false);
 
183
    TestInOutMethod(obj, "InOutsBool", false, true);
 
184
    var inoutParam = { value : {ClassName : "InOutTest", Number : 10 } };
 
185
    try
 
186
    {
 
187
        obj.InOutsIDispatch(inoutParam);
 
188
        if (inoutParam.value.Number != 15)
 
189
            reportFailure("Testing in/out parameter failed: IDispatch");
 
190
    }
 
191
    catch (e)
 
192
    {
 
193
        reportFailure("Testing in/out parameter failed: IDispatch - " + e.toString());
 
194
    }
 
195
    // See the TakesError case
 
196
    //TestInOutMethod(obj, "InOutsError", E_FAIL, E_FAIL + 1);
 
197
    TestInOutMethod(obj, "InOutsDate", "5/23/2001", "5/24/2001");
 
198
    //TestInOutMethod(obj, InOutsIUnknown(IUnknown * * result)
 
199
    TestInOutMethod(obj, "InOutsI1", -42, -41);
 
200
    TestInOutMethod(obj, "InOutsUI2", 43, 85);
 
201
    TestInOutMethod(obj, "InOutsUI4", 88, 46);
 
202
 
 
203
    try
 
204
    {
 
205
        reportCompare(obj.OneParameterWithReturn(-20), 22, "Testing OneParameterWithReturn");
 
206
    }
 
207
    catch (e)
 
208
    {
 
209
        reportFailure("Testing OneParameterWithReturn: " + e.toString());
 
210
    }
 
211
 
 
212
    try
 
213
    {
 
214
        reportCompare(obj.StringInputAndReturn("A String "), "A String Appended", "Testing StringInputAndReturn");
 
215
    }
 
216
    catch (e)
 
217
    {
 
218
        reportFailure("Testing StringInputAndReturn: " + e.toString());
 
219
    }
 
220
    try
 
221
    {
 
222
        var inoutIDispatch = {  className : "inouttest", Number : 5 };
 
223
        var result = obj.IDispatchInputAndReturn(inoutIDispatch);
 
224
        reportCompare(81, result.Number, "IDispatchInputAndReturn");
 
225
    }
 
226
    catch (e)
 
227
    {
 
228
        reportFailure("Testing IDispatchInputAndReturn: " + e.toString());
 
229
    }
 
230
    try
 
231
    {
 
232
        obj.TwoParameters(1, 2);
 
233
    }
 
234
    catch (e)
 
235
    {
 
236
        reportFailure("Testing TwoParameters: " + e.toString());
 
237
    }
 
238
 
 
239
    try
 
240
    {
 
241
        obj.TwelveInParameters(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
 
242
    }
 
243
    catch (e)
 
244
    {
 
245
        reportFailure("Testing TwelveInParameters: " + e.toString());
 
246
    }
 
247
 
 
248
    try
 
249
    {
 
250
        var out1 = new Object();
 
251
        var out2 = new Object();
 
252
        var out3 = new Object();
 
253
        var out4 = new Object();
 
254
        var out5 = new Object();
 
255
        var out6 = new Object();
 
256
        var out7 = new Object();
 
257
        var out8 = new Object();
 
258
        var out9 = new Object();
 
259
        var out10 = new Object();
 
260
        var out11 = new Object();
 
261
        var out12 = new Object();
 
262
        obj.TwelveOutParameters(out1, out2, out3, out4, out5, out6, out7, out8, out9, out10, out11, out12);
 
263
        reportCompare(78, out1.value + out2.value + out3.value + out4.value + out5.value + out6.value + out7.value + out8.value + out9.value + out10.value + out11.value + out12.value, "Testing TwelveOutParameters");
 
264
    }
 
265
    catch (e)
 
266
    {
 
267
        reportFailure("Testing TwelveOutParameters: " + e.toString());
 
268
    }
 
269
 
 
270
    try
 
271
    {
 
272
        obj.TwelveStrings("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve");
 
273
    }
 
274
    catch (e)
 
275
    {
 
276
        reportFailure("Testing TwelveStrings: " + e.toString());
 
277
    }
 
278
 
 
279
    try
 
280
    {
 
281
        var out1 = new Object();
 
282
        var out2 = new Object();
 
283
        var out3 = new Object();
 
284
        var out4 = new Object();
 
285
        var out5 = new Object();
 
286
        var out6 = new Object();
 
287
        var out7 = new Object();
 
288
        var out8 = new Object();
 
289
        var out9 = new Object();
 
290
        var out10 = new Object();
 
291
        var out11 = new Object();
 
292
        var out12 = new Object();
 
293
        obj.TwelveOutStrings(out1, out2, out3, out4, out5, out6, out7, out8, out9, out10, out11, out12);
 
294
        reportCompare(true, out1.value == "one" && out2.value == "two" &&
 
295
                            out3.value == "three" && out4.value == "four" &&
 
296
                            out5.value == "five" && out6.value == "six" &&
 
297
                            out7.value == "seven" && out8.value == "eight" &&
 
298
                            out9.value == "nine" && out10.value == "ten" &&
 
299
                            out11.value == "eleven" && out12.value == "twelve",
 
300
                      "Testing TwelveOutString");
 
301
    }
 
302
    catch (e)
 
303
    {
 
304
        reportFailure("Testing TwelveOutParameters: " + e.toString());
 
305
    }
 
306
    try
 
307
    {
 
308
        var out1 = { className : "out1", Number : 5 };
 
309
        var out2 = { className : "out2", Number : 5 };
 
310
        var out3 = { className : "out3", Number : 5 };
 
311
        var out4 = { className : "out4", Number : 5 };
 
312
        var out5 = { className : "out5", Number : 5 };
 
313
        var out6 = { className : "out6", Number : 5 };
 
314
        var out7 = { className : "out7", Number : 5 };
 
315
        var out8 = { className : "out8", Number : 5 };
 
316
        var out9 = { className : "out9", Number : 5 };
 
317
        var out10 = { className : "out10", Number : 5 };
 
318
        var out11 = { className : "out11", Number : 5 };
 
319
        var out12 = { className : "out12", Number : 5 };
 
320
        obj.TwelveIDispatch(out1, out2, out3, out4, out5, out6, out7, out8, out9, out10, out11, out12);
 
321
    }
 
322
    catch (e)
 
323
    {
 
324
        reportFailure("Testing TwelveIDispatch: " + e.toString());
 
325
    }
 
326
    try
 
327
    {
 
328
        var out1 = new Object();
 
329
        var out2 = new Object();
 
330
        var out3 = new Object();
 
331
        var out4 = new Object();
 
332
        var out5 = new Object();
 
333
        var out6 = new Object();
 
334
        var out7 = new Object();
 
335
        var out8 = new Object();
 
336
        var out9 = new Object();
 
337
        var out10 = new Object();
 
338
        var out11 = new Object();
 
339
        var out12 = new Object();
 
340
        obj.TwelveOutIDispatch(out1, out2, out3, out4, out5, out6, out7, out8, out9, out10, out11, out12);
 
341
        print("out1.value" + out1.value.Number);
 
342
        reportCompare(true, out1.value.Number == 5 && out2.value.Number == 5 &&
 
343
                            out3.value.Number == 5 && out4.value.Number == 5 &&
 
344
                            out5.value.Number == 5 && out6.value.Number == 5 &&
 
345
                            out7.value.Number == 5 && out8.value.Number == 5 &&
 
346
                            out9.value.Number == 5 && out10.value.Number == 5 &&
 
347
                            out11.value.Number == 5 && out12.value.Number == 5,
 
348
                      "Testing TwelveOutIDispatch");
 
349
        compareObject(out1.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out1");
 
350
        compareObject(out2.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out2");
 
351
        compareObject(out3.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out3");
 
352
        compareObject(out4.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out4");
 
353
        compareObject(out5.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out5");
 
354
        compareObject(out6.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out6");
 
355
        compareObject(out7.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out7");
 
356
        compareObject(out8.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out8");
 
357
        compareObject(out9.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out9");
 
358
        compareObject(out10.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out10");
 
359
        compareObject(out11.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out11");
 
360
        compareObject(out12.value, nsXPCDispSimpleDesc, "Testing TwelveOutParameters - out12");
 
361
    }
 
362
    catch (e)
 
363
    {
 
364
        reportFailure("Testing TwelveOutIDispatch: " + e.toString());
 
365
    }
 
366
 
 
367
    try
 
368
    {
 
369
        obj.CreateError();
 
370
        reportFailure("Testing CreateError: Didn't generate a catchable exception");
 
371
    }
 
372
    catch (e)
 
373
    {
 
374
        reportCompare(true, e.toString().search("CreateError Test") != -1, "Testing CreateError");
 
375
    }
 
376
}