VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/reflect/xptcall/tests/TestXPTCInvoke.cpp@ 86422

Last change on this file since 86422 was 86422, checked in by vboxsync, 4 years ago

xpcom/TestXPTCInvoke: two leaks. bugref:9841

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 36.5 KB
Line 
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 mozilla.org code.
16 *
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.
21 *
22 * Contributor(s):
23 * Pierre Phaneuf <[email protected]>
24 * Stuart Parmenter <[email protected]>
25 * Chris Seawood <[email protected]>
26 *
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
38 *
39 * ***** END LICENSE BLOCK ***** */
40
41/* Invoke tests xptcall. */
42
43#include <stdio.h>
44#include "xptcall.h"
45#include "prlong.h"
46#include "prinrval.h"
47#include "nsMemory.h"
48
49// forward declration
50static void DoMultipleInheritenceTest();
51static void DoMultipleInheritenceTest2();
52static void DoSpeedTest();
53
54// {AAC1FB90-E099-11d2-984E-006008962422}
55#define INVOKETESTTARGET_IID \
56{ 0xaac1fb90, 0xe099, 0x11d2, \
57 { 0x98, 0x4e, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
58
59
60class InvokeTestTargetInterface : public nsISupports
61{
62public:
63 NS_DEFINE_STATIC_IID_ACCESSOR(INVOKETESTTARGET_IID)
64 NS_IMETHOD AddTwoInts(PRInt32 p1, PRInt32 p2, PRInt32* retval) = 0;
65 NS_IMETHOD MultTwoInts(PRInt32 p1, PRInt32 p2, PRInt32* retval) = 0;
66 NS_IMETHOD AddTwoLLs(PRInt64 p1, PRInt64 p2, PRInt64* retval) = 0;
67 NS_IMETHOD MultTwoLLs(PRInt64 p1, PRInt64 p2, PRInt64* retval) = 0;
68
69 NS_IMETHOD AddManyInts(PRInt32 p1, PRInt32 p2, PRInt32 p3, PRInt32 p4,
70 PRInt32 p5, PRInt32 p6, PRInt32 p7, PRInt32 p8,
71 PRInt32 p9, PRInt32 p10, PRInt32* retval) = 0;
72
73 NS_IMETHOD AddTwoFloats(float p1, float p2, float* retval) = 0;
74
75 NS_IMETHOD AddManyDoubles(double p1, double p2, double p3, double p4,
76 double p5, double p6, double p7, double p8,
77 double p9, double p10, double* retval) = 0;
78
79 NS_IMETHOD AddManyFloats(float p1, float p2, float p3, float p4,
80 float p5, float p6, float p7, float p8,
81 float p9, float p10, float* retval) = 0;
82
83 NS_IMETHOD AddManyManyFloats(float p1, float p2, float p3, float p4,
84 float p5, float p6, float p7, float p8,
85 float p9, float p10, float p11, float p12,
86 float p13, float p14, float p15, float p16,
87 float p17, float p18, float p19, float p20,
88 float *retval) = 0;
89
90 NS_IMETHOD AddMixedInts(PRInt64 p1, PRInt32 p2, PRInt64 p3, PRInt32 p4,
91 PRInt32 p5, PRInt64 p6, PRInt32 p7, PRInt32 p8,
92 PRInt64 p9, PRInt32 p10, PRInt64* retval) = 0;
93
94 NS_IMETHOD AddMixedInts2(PRInt32 p1, PRInt64 p2, PRInt32 p3, PRInt64 p4,
95 PRInt64 p5, PRInt32 p6, PRInt64 p7, PRInt64 p8,
96 PRInt32 p9, PRInt64 p10, PRInt64* retval) = 0;
97
98 NS_IMETHOD AddMixedFloats(float p1, float p2, double p3, double p4,
99 float p5, float p6, double p7, double p8,
100 float p9, double p10, float p11,
101 double *retval) = 0;
102
103 NS_IMETHOD PassTwoStrings(const char* s1, const char* s2, char** retval) = 0;
104
105};
106
107class InvokeTestTarget : public InvokeTestTargetInterface
108{
109public:
110 NS_DECL_ISUPPORTS
111 NS_IMETHOD AddTwoInts(PRInt32 p1, PRInt32 p2, PRInt32* retval);
112 NS_IMETHOD MultTwoInts(PRInt32 p1, PRInt32 p2, PRInt32* retval);
113 NS_IMETHOD AddTwoLLs(PRInt64 p1, PRInt64 p2, PRInt64* retval);
114 NS_IMETHOD MultTwoLLs(PRInt64 p1, PRInt64 p2, PRInt64* retval);
115
116 NS_IMETHOD AddManyInts(PRInt32 p1, PRInt32 p2, PRInt32 p3, PRInt32 p4,
117 PRInt32 p5, PRInt32 p6, PRInt32 p7, PRInt32 p8,
118 PRInt32 p9, PRInt32 p10, PRInt32* retval);
119
120 NS_IMETHOD AddTwoFloats(float p1, float p2, float* retval);
121
122 NS_IMETHOD AddManyDoubles(double p1, double p2, double p3, double p4,
123 double p5, double p6, double p7, double p8,
124 double p9, double p10, double* retval);
125
126 NS_IMETHOD AddManyFloats(float p1, float p2, float p3, float p4,
127 float p5, float p6, float p7, float p8,
128 float p9, float p10, float* retval);
129
130 NS_IMETHOD AddMixedInts(PRInt64 p1, PRInt32 p2, PRInt64 p3, PRInt32 p4,
131 PRInt32 p5, PRInt64 p6, PRInt32 p7, PRInt32 p8,
132 PRInt64 p9, PRInt32 p10, PRInt64* retval);
133
134 NS_IMETHOD AddMixedInts2(PRInt32 p1, PRInt64 p2, PRInt32 p3, PRInt64 p4,
135 PRInt64 p5, PRInt32 p6, PRInt64 p7, PRInt64 p8,
136 PRInt32 p9, PRInt64 p10, PRInt64* retval);
137
138 NS_IMETHOD AddMixedFloats(float p1, float p2, double p3, double p4,
139 float p5, float p6, double p7, double p8,
140 float p9, double p10, float p11,
141 double *retval);
142
143 NS_IMETHOD AddManyManyFloats(float p1, float p2, float p3, float p4,
144 float p5, float p6, float p7, float p8,
145 float p9, float p10, float p11, float p12,
146 float p13, float p14, float p15, float p16,
147 float p17, float p18, float p19, float p20,
148 float *retval);
149
150 NS_IMETHOD PassTwoStrings(const char* s1, const char* s2, char** retval);
151
152 InvokeTestTarget();
153};
154
155NS_IMPL_ISUPPORTS1(InvokeTestTarget, InvokeTestTargetInterface)
156
157InvokeTestTarget::InvokeTestTarget()
158{
159 NS_ADDREF_THIS();
160}
161
162NS_IMETHODIMP
163InvokeTestTarget::AddTwoInts(PRInt32 p1, PRInt32 p2, PRInt32* retval)
164{
165 *retval = p1 + p2;
166 return NS_OK;
167}
168
169NS_IMETHODIMP
170InvokeTestTarget::MultTwoInts(PRInt32 p1, PRInt32 p2, PRInt32* retval)
171{
172 *retval = p1 * p2;
173 return NS_OK;
174}
175
176NS_IMETHODIMP
177InvokeTestTarget::AddTwoLLs(PRInt64 p1, PRInt64 p2, PRInt64* retval)
178{
179 LL_ADD(*retval, p1, p2);
180 return NS_OK;
181}
182
183NS_IMETHODIMP
184InvokeTestTarget::MultTwoLLs(PRInt64 p1, PRInt64 p2, PRInt64* retval)
185{
186 LL_MUL(*retval, p1, p2);
187 return NS_OK;
188}
189
190NS_IMETHODIMP
191InvokeTestTarget::AddManyInts(PRInt32 p1, PRInt32 p2, PRInt32 p3, PRInt32 p4,
192 PRInt32 p5, PRInt32 p6, PRInt32 p7, PRInt32 p8,
193 PRInt32 p9, PRInt32 p10, PRInt32* retval)
194{
195#ifdef DEBUG_TESTINVOKE
196 printf("%d, %d, %d, %d, %d, %d, %d, %d, %d, %d\n",
197 p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
198#endif
199 *retval = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10;
200 return NS_OK;
201}
202
203NS_IMETHODIMP
204InvokeTestTarget::AddTwoFloats(float p1, float p2, float *retval)
205{
206#ifdef DEBUG_TESTINVOKE
207 printf("%f, %f\n", p1, p2);
208#endif
209 *retval = p1 + p2;
210 return NS_OK;
211}
212
213NS_IMETHODIMP
214InvokeTestTarget::AddManyDoubles(double p1, double p2, double p3, double p4,
215 double p5, double p6, double p7, double p8,
216 double p9, double p10, double* retval)
217{
218#ifdef DEBUG_TESTINVOKE
219 printf("%lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf, %lf\n",
220 p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
221#endif
222 *retval = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10;
223 return NS_OK;
224}
225
226NS_IMETHODIMP
227InvokeTestTarget::AddManyFloats(float p1, float p2, float p3, float p4,
228 float p5, float p6, float p7, float p8,
229 float p9, float p10, float* retval)
230{
231#ifdef DEBUG_TESTINVOKE
232 printf("%f, %f, %f, %f, %f, %f, %f, %f, %f, %f\n",
233 p1, p2, p3, p4, p5, p6, p7, p8, p9, p10);
234#endif
235 *retval = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10;
236 return NS_OK;
237}
238
239NS_IMETHODIMP
240InvokeTestTarget::AddMixedFloats(float p1, float p2, double p3, double p4,
241 float p5, float p6, double p7, double p8,
242 float p9, double p10, float p11,
243 double *retval)
244{
245#ifdef DEBUG_TESTINVOKE
246 printf("%f, %f, %lf, %lf, %f, %f, %lf, %lf, %f, %lf, %f\n",
247 p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11);
248#endif
249 *retval = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11;
250 return NS_OK;
251}
252
253NS_IMETHODIMP
254InvokeTestTarget::AddManyManyFloats(float p1, float p2, float p3, float p4,
255 float p5, float p6, float p7, float p8,
256 float p9, float p10, float p11, float p12,
257 float p13, float p14, float p15, float p16,
258 float p17, float p18, float p19, float p20,
259 float *retval)
260{
261#ifdef DEBUG_TESTINVOKE
262 printf("%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, "
263 "%f, %f, %f, %f, %f, %f, %f, %f, %f, %f\n",
264 p1, p2, p3, p4, p5, p6, p7, p8, p9, p10,
265 p11, p12, p13, p14, p15, p16, p17, p18, p19, p20);
266#endif
267 *retval = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 +
268 p11 + p12 + p13 + p14 + p15 + p16 + p17 + p18 + p19 + p20;
269 return NS_OK;
270}
271
272NS_IMETHODIMP
273InvokeTestTarget::AddMixedInts(PRInt64 p1, PRInt32 p2, PRInt64 p3, PRInt32 p4,
274 PRInt32 p5, PRInt64 p6, PRInt32 p7, PRInt32 p8,
275 PRInt64 p9, PRInt32 p10, PRInt64* retval)
276{
277 *retval = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10;
278 return NS_OK;
279}
280
281NS_IMETHODIMP
282InvokeTestTarget::AddMixedInts2(PRInt32 p1, PRInt64 p2, PRInt32 p3, PRInt64 p4,
283 PRInt64 p5, PRInt32 p6, PRInt64 p7, PRInt64 p8,
284 PRInt32 p9, PRInt64 p10, PRInt64* retval)
285{
286 *retval = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10;
287 return NS_OK;
288}
289
290NS_IMETHODIMP
291InvokeTestTarget::PassTwoStrings(const char* s1, const char* s2, char** retval)
292{
293 const char milk[] = "milk";
294 char *ret = (char*)nsMemory::Alloc(sizeof(milk));
295 if (!ret)
296 return NS_ERROR_OUT_OF_MEMORY;
297 strncpy(ret, milk, sizeof(milk));
298 printf("\t%s %s", s1, s2);
299 *retval = ret;
300 return NS_OK;
301}
302
303int main()
304{
305 InvokeTestTarget *test = new InvokeTestTarget();
306
307 /* here we make the global 'check for alloc failure' checker happy */
308 if(!test)
309 return 1;
310
311 PRInt32 out, tmp32 = 0;
312 PRInt64 out64;
313 printf("calling direct:\n");
314 if(NS_SUCCEEDED(test->AddTwoInts(1,1,&out)))
315 printf("\t1 + 1 = %d\n", out);
316 else
317 printf("\tFAILED");
318 PRInt64 one, two;
319 LL_I2L(one, 1);
320 LL_I2L(two, 2);
321 if(NS_SUCCEEDED(test->AddTwoLLs(one,one,&out64)))
322 {
323 LL_L2I(tmp32, out64);
324 printf("\t1L + 1L = %d\n", (int)tmp32);
325 }
326 else
327 printf("\tFAILED");
328 if(NS_SUCCEEDED(test->MultTwoInts(2,2,&out)))
329 printf("\t2 * 2 = %d\n", out);
330 else
331 printf("\tFAILED");
332 if(NS_SUCCEEDED(test->MultTwoLLs(two,two,&out64)))
333 {
334 LL_L2I(tmp32, out64);
335 printf("\t2L * 2L = %d\n", (int)tmp32);
336 }
337 else
338 printf("\tFAILED");
339
340 double outD;
341 float outF;
342 PRInt32 outI;
343 char *outS;
344
345 if(NS_SUCCEEDED(test->AddManyInts(1,2,3,4,5,6,7,8,9,10,&outI)))
346 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n", outI);
347 else
348 printf("\tFAILED");
349
350 if(NS_SUCCEEDED(test->AddTwoFloats(1,2,&outF)))
351 printf("\t1 + 2 = %ff\n", (double)outF);
352 else
353 printf("\tFAILED");
354
355 if(NS_SUCCEEDED(test->AddManyDoubles(1,2,3,4,5,6,7,8,9,10,&outD)))
356 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %f\n", outD);
357 else
358 printf("\tFAILED");
359
360 if(NS_SUCCEEDED(test->AddManyFloats(1,2,3,4,5,6,7,8,9,10,&outF)))
361 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %ff\n", (double)outF);
362 else
363 printf("\tFAILED");
364
365 if(NS_SUCCEEDED(test->AddManyManyFloats(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,&outF)))
366 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 +1 15 + 16 + 17 + 18 + 19 + 20 = %ff\n", (double)outF);
367 else
368 printf("\tFAILED");
369
370 if(NS_SUCCEEDED(test->AddMixedInts(1,2,3,4,5,6,7,8,9,10,&out64)))
371 {
372 LL_L2I(tmp32, out64);
373 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n", (int)tmp32);
374 }
375 else
376 printf("\tFAILED");
377
378 if(NS_SUCCEEDED(test->AddMixedInts2(1,2,3,4,5,6,7,8,9,10,&out64)))
379 {
380 LL_L2I(tmp32, out64);
381 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n", (int)tmp32);
382 }
383 else
384 printf("\tFAILED");
385
386 if(NS_SUCCEEDED(test->AddMixedFloats(1,2,3,4,5,6,7,8,9,10,11,&outD)))
387 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 = %f\n", (double)outD);
388 else
389 printf("\tFAILED");
390
391 if (NS_SUCCEEDED(test->PassTwoStrings("moo","cow",&outS))) {
392 printf(" = %s\n", outS);
393 nsMemory::Free(outS);
394 } else
395 printf("\tFAILED");
396
397 printf("calling via invoke:\n");
398
399 nsXPTCVariant var[21];
400
401 var[0].val.i32 = 1;
402 var[0].type = nsXPTType::T_I32;
403 var[0].flags = 0;
404
405 var[1].val.i32 = 1;
406 var[1].type = nsXPTType::T_I32;
407 var[1].flags = 0;
408
409 var[2].val.i32 = 0;
410 var[2].type = nsXPTType::T_I32;
411 var[2].flags = nsXPTCVariant::PTR_IS_DATA;
412 var[2].ptr = &var[2].val.i32;
413
414 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 3, 3, var)))
415 printf("\t1 + 1 = %d\n", var[2].val.i32);
416 else
417 printf("\tFAILED");
418
419 LL_I2L(var[0].val.i64, 1);
420 var[0].type = nsXPTType::T_I64;
421 var[0].flags = 0;
422
423 LL_I2L(var[1].val.i64, 1);
424 var[1].type = nsXPTType::T_I64;
425 var[1].flags = 0;
426
427 LL_I2L(var[2].val.i64, 0);
428 var[2].type = nsXPTType::T_I64;
429 var[2].flags = nsXPTCVariant::PTR_IS_DATA;
430 var[2].ptr = &var[2].val.i64;
431
432 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 5, 3, var)))
433 printf("\t1L + 1L = %d\n", (int)var[2].val.i64);
434 else
435 printf("\tFAILED");
436
437 var[0].val.i32 = 2;
438 var[0].type = nsXPTType::T_I32;
439 var[0].flags = 0;
440
441 var[1].val.i32 = 2;
442 var[1].type = nsXPTType::T_I32;
443 var[1].flags = 0;
444
445 var[2].val.i32 = 0;
446 var[2].type = nsXPTType::T_I32;
447 var[2].flags = nsXPTCVariant::PTR_IS_DATA;
448 var[2].ptr = &var[2].val.i32;
449
450 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 4, 3, var)))
451 printf("\t2 * 2 = %d\n", var[2].val.i32);
452 else
453 printf("\tFAILED");
454
455 LL_I2L(var[0].val.i64,2);
456 var[0].type = nsXPTType::T_I64;
457 var[0].flags = 0;
458
459 LL_I2L(var[1].val.i64,2);
460 var[1].type = nsXPTType::T_I64;
461 var[1].flags = 0;
462
463 LL_I2L(var[2].val.i64,0);
464 var[2].type = nsXPTType::T_I64;
465 var[2].flags = nsXPTCVariant::PTR_IS_DATA;
466 var[2].ptr = &var[2].val.i64;
467
468 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 6, 3, var)))
469 printf("\t2L * 2L = %d\n", (int)var[2].val.i64);
470 else
471 printf("\tFAILED");
472
473 var[0].val.i32 = 1;
474 var[0].type = nsXPTType::T_I32;
475 var[0].flags = 0;
476
477 var[1].val.i32 = 2;
478 var[1].type = nsXPTType::T_I32;
479 var[1].flags = 0;
480
481 var[2].val.i32 = 3;
482 var[2].type = nsXPTType::T_I32;
483 var[2].flags = 0;
484
485 var[3].val.i32 = 4;
486 var[3].type = nsXPTType::T_I32;
487 var[3].flags = 0;
488
489 var[4].val.i32 = 5;
490 var[4].type = nsXPTType::T_I32;
491 var[4].flags = 0;
492
493 var[5].val.i32 = 6;
494 var[5].type = nsXPTType::T_I32;
495 var[5].flags = 0;
496
497 var[6].val.i32 = 7;
498 var[6].type = nsXPTType::T_I32;
499 var[6].flags = 0;
500
501 var[7].val.i32 = 8;
502 var[7].type = nsXPTType::T_I32;
503 var[7].flags = 0;
504
505 var[8].val.i32 = 9;
506 var[8].type = nsXPTType::T_I32;
507 var[8].flags = 0;
508
509 var[9].val.i32 = 10;
510 var[9].type = nsXPTType::T_I32;
511 var[9].flags = 0;
512
513 var[10].val.i32 = 0;
514 var[10].type = nsXPTType::T_I32;
515 var[10].flags = nsXPTCVariant::PTR_IS_DATA;
516 var[10].ptr = &var[10].val.i32;
517
518 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 7, 11, var)))
519 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n",
520 var[10].val.i32);
521
522 var[0].val.f = 1.0f;
523 var[0].type = nsXPTType::T_FLOAT;
524 var[0].flags = 0;
525
526 var[1].val.f = 2.0f;
527 var[1].type = nsXPTType::T_FLOAT;
528 var[1].flags = 0;
529
530 var[2].val.f = 0.0f;
531 var[2].type = nsXPTType::T_FLOAT;
532 var[2].flags = nsXPTCVariant::PTR_IS_DATA;
533 var[2].ptr = &var[2].val.f;
534
535 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 8, 3, var)))
536 printf("\t1 + 2 = %ff\n",
537 (double) var[2].val.f);
538
539
540 var[0].val.d = 1.0;
541 var[0].type = nsXPTType::T_DOUBLE;
542 var[0].flags = 0;
543
544 var[1].val.d = 2.0;
545 var[1].type = nsXPTType::T_DOUBLE;
546 var[1].flags = 0;
547
548 var[2].val.d = 3.0;
549 var[2].type = nsXPTType::T_DOUBLE;
550 var[2].flags = 0;
551
552 var[3].val.d = 4.0;
553 var[3].type = nsXPTType::T_DOUBLE;
554 var[3].flags = 0;
555
556 var[4].val.d = 5.0;
557 var[4].type = nsXPTType::T_DOUBLE;
558 var[4].flags = 0;
559
560 var[5].val.d = 6.0;
561 var[5].type = nsXPTType::T_DOUBLE;
562 var[5].flags = 0;
563
564 var[6].val.d = 7.0;
565 var[6].type = nsXPTType::T_DOUBLE;
566 var[6].flags = 0;
567
568 var[7].val.d = 8.0;
569 var[7].type = nsXPTType::T_DOUBLE;
570 var[7].flags = 0;
571
572 var[8].val.d = 9.0;
573 var[8].type = nsXPTType::T_DOUBLE;
574 var[8].flags = 0;
575
576 var[9].val.d = 10.0;
577 var[9].type = nsXPTType::T_DOUBLE;
578 var[9].flags = 0;
579
580 var[10].val.d = 0.0;
581 var[10].type = nsXPTType::T_DOUBLE;
582 var[10].flags = nsXPTCVariant::PTR_IS_DATA;
583 var[10].ptr = &var[10].val.d;
584
585 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 9, 11, var)))
586 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %f\n",
587 var[10].val.d);
588 else
589 printf("\tFAILED");
590
591 var[0].val.f = 1.0f;
592 var[0].type = nsXPTType::T_FLOAT;
593 var[0].flags = 0;
594
595 var[1].val.f = 2.0f;
596 var[1].type = nsXPTType::T_FLOAT;
597 var[1].flags = 0;
598
599 var[2].val.f = 3.0f;
600 var[2].type = nsXPTType::T_FLOAT;
601 var[2].flags = 0;
602
603 var[3].val.f = 4.0f;
604 var[3].type = nsXPTType::T_FLOAT;
605 var[3].flags = 0;
606
607 var[4].val.f = 5.0f;
608 var[4].type = nsXPTType::T_FLOAT;
609 var[4].flags = 0;
610
611 var[5].val.f = 6.0f;
612 var[5].type = nsXPTType::T_FLOAT;
613 var[5].flags = 0;
614
615 var[6].val.f = 7.0f;
616 var[6].type = nsXPTType::T_FLOAT;
617 var[6].flags = 0;
618
619 var[7].val.f = 8.0f;
620 var[7].type = nsXPTType::T_FLOAT;
621 var[7].flags = 0;
622
623 var[8].val.f = 9.0f;
624 var[8].type = nsXPTType::T_FLOAT;
625 var[8].flags = 0;
626
627 var[9].val.f = 10.0f;
628 var[9].type = nsXPTType::T_FLOAT;
629 var[9].flags = 0;
630
631 var[10].val.f = 0.0f;
632 var[10].type = nsXPTType::T_FLOAT;
633 var[10].flags = nsXPTCVariant::PTR_IS_DATA;
634 var[10].ptr = &var[10].val.f;
635
636 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 10, 11, var)))
637 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %ff\n",
638 (double) var[10].val.f);
639 else
640 printf("\tFAILED");
641
642 var[0].val.f = 1.0f;
643 var[0].type = nsXPTType::T_FLOAT;
644 var[0].flags = 0;
645
646 var[1].val.f = 2.0f;
647 var[1].type = nsXPTType::T_FLOAT;
648 var[1].flags = 0;
649
650 var[2].val.f = 3.0f;
651 var[2].type = nsXPTType::T_FLOAT;
652 var[2].flags = 0;
653
654 var[3].val.f = 4.0f;
655 var[3].type = nsXPTType::T_FLOAT;
656 var[3].flags = 0;
657
658 var[4].val.f = 5.0f;
659 var[4].type = nsXPTType::T_FLOAT;
660 var[4].flags = 0;
661
662 var[5].val.f = 6.0f;
663 var[5].type = nsXPTType::T_FLOAT;
664 var[5].flags = 0;
665
666 var[6].val.f = 7.0f;
667 var[6].type = nsXPTType::T_FLOAT;
668 var[6].flags = 0;
669
670 var[7].val.f = 8.0f;
671 var[7].type = nsXPTType::T_FLOAT;
672 var[7].flags = 0;
673
674 var[8].val.f = 9.0f;
675 var[8].type = nsXPTType::T_FLOAT;
676 var[8].flags = 0;
677
678 var[9].val.f = 10.0f;
679 var[9].type = nsXPTType::T_FLOAT;
680 var[9].flags = 0;
681
682 var[10].val.f = 11.0f;
683 var[10].type = nsXPTType::T_FLOAT;
684 var[10].flags = 0;
685
686 var[11].val.f = 12.0f;
687 var[11].type = nsXPTType::T_FLOAT;
688 var[11].flags = 0;
689
690 var[12].val.f = 13.0f;
691 var[12].type = nsXPTType::T_FLOAT;
692 var[12].flags = 0;
693
694 var[13].val.f = 14.0f;
695 var[13].type = nsXPTType::T_FLOAT;
696 var[13].flags = 0;
697
698 var[14].val.f = 15.0f;
699 var[14].type = nsXPTType::T_FLOAT;
700 var[14].flags = 0;
701
702 var[15].val.f = 16.0f;
703 var[15].type = nsXPTType::T_FLOAT;
704 var[15].flags = 0;
705
706 var[16].val.f = 17.0f;
707 var[16].type = nsXPTType::T_FLOAT;
708 var[16].flags = 0;
709
710 var[17].val.f = 18.0f;
711 var[17].type = nsXPTType::T_FLOAT;
712 var[17].flags = 0;
713
714 var[18].val.f = 19.0f;
715 var[18].type = nsXPTType::T_FLOAT;
716 var[18].flags = 0;
717
718 var[19].val.f = 20.0f;
719 var[19].type = nsXPTType::T_FLOAT;
720 var[19].flags = 0;
721
722 var[20].val.f = 0.0f;
723 var[20].type = nsXPTType::T_FLOAT;
724 var[20].flags = nsXPTCVariant::PTR_IS_DATA;
725 var[20].ptr = &var[20].val.f;
726
727 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 11, 21, var)))
728 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 = %ff\n",
729 (double) var[20].val.f);
730
731 var[0].val.i64 = 1;
732 var[0].type = nsXPTType::T_I64;
733 var[0].flags = 0;
734
735 var[1].val.i32 = 2;
736 var[1].type = nsXPTType::T_I32;
737 var[1].flags = 0;
738
739 var[2].val.i64 = 3;
740 var[2].type = nsXPTType::T_I64;
741 var[2].flags = 0;
742
743 var[3].val.i32 = 4;
744 var[3].type = nsXPTType::T_I32;
745 var[3].flags = 0;
746
747 var[4].val.i32 = 5;
748 var[4].type = nsXPTType::T_I32;
749 var[4].flags = 0;
750
751 var[5].val.i64 = 6;
752 var[5].type = nsXPTType::T_I64;
753 var[5].flags = 0;
754
755 var[6].val.i32 = 7;
756 var[6].type = nsXPTType::T_I32;
757 var[6].flags = 0;
758
759 var[7].val.i32 = 8;
760 var[7].type = nsXPTType::T_I32;
761 var[7].flags = 0;
762
763 var[8].val.i64 = 9;
764 var[8].type = nsXPTType::T_I64;
765 var[8].flags = 0;
766
767 var[9].val.i32 = 10;
768 var[9].type = nsXPTType::T_I32;
769 var[9].flags = 0;
770
771 var[10].val.i64 = 0;
772 var[10].type = nsXPTType::T_I64;
773 var[10].flags = nsXPTCVariant::PTR_IS_DATA;
774 var[10].ptr = &var[10].val.i64;
775
776 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 12, 11, var)))
777 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n",
778 (int)var[10].val.i64);
779 else
780 printf("\tFAILED");
781
782 var[0].val.i32 = 1;
783 var[0].type = nsXPTType::T_I32;
784 var[0].flags = 0;
785
786 var[1].val.i64 = 2;
787 var[1].type = nsXPTType::T_I64;
788 var[1].flags = 0;
789
790 var[2].val.i32 = 3;
791 var[2].type = nsXPTType::T_I32;
792 var[2].flags = 0;
793
794 var[3].val.i64 = 4;
795 var[3].type = nsXPTType::T_I64;
796 var[3].flags = 0;
797
798 var[4].val.i64 = 5;
799 var[4].type = nsXPTType::T_I64;
800 var[4].flags = 0;
801
802 var[5].val.i32 = 6;
803 var[5].type = nsXPTType::T_I32;
804 var[5].flags = 0;
805
806 var[6].val.i64 = 7;
807 var[6].type = nsXPTType::T_I64;
808 var[6].flags = 0;
809
810 var[7].val.i64 = 8;
811 var[7].type = nsXPTType::T_I64;
812 var[7].flags = 0;
813
814 var[8].val.i32 = 9;
815 var[8].type = nsXPTType::T_I32;
816 var[8].flags = 0;
817
818 var[9].val.i64 = 10;
819 var[9].type = nsXPTType::T_I64;
820 var[9].flags = 0;
821
822 var[10].val.i64 = 0;
823 var[10].type = nsXPTType::T_I64;
824 var[10].flags = nsXPTCVariant::PTR_IS_DATA;
825 var[10].ptr = &var[10].val.i64;
826
827 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 13, 11, var)))
828 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n",
829 (int)var[10].val.i64);
830 else
831 printf("\tFAILED");
832
833 var[0].val.f = 1.0f;
834 var[0].type = nsXPTType::T_FLOAT;
835 var[0].flags = 0;
836
837 var[1].val.f = 2.0f;
838 var[1].type = nsXPTType::T_FLOAT;
839 var[1].flags = 0;
840
841 var[2].val.d = 3.0;
842 var[2].type = nsXPTType::T_DOUBLE;
843 var[2].flags = 0;
844
845 var[3].val.d = 4.0;
846 var[3].type = nsXPTType::T_DOUBLE;
847 var[3].flags = 0;
848
849 var[4].val.f = 5.0f;
850 var[4].type = nsXPTType::T_FLOAT;
851 var[4].flags = 0;
852
853 var[5].val.f = 6.0f;
854 var[5].type = nsXPTType::T_FLOAT;
855 var[5].flags = 0;
856
857 var[6].val.d = 7.0;
858 var[6].type = nsXPTType::T_DOUBLE;
859 var[6].flags = 0;
860
861 var[7].val.d = 8.0;
862 var[7].type = nsXPTType::T_DOUBLE;
863 var[7].flags = 0;
864
865 var[8].val.f = 9.0f;
866 var[8].type = nsXPTType::T_FLOAT;
867 var[8].flags = 0;
868
869 var[9].val.d = 10.0;
870 var[9].type = nsXPTType::T_DOUBLE;
871 var[9].flags = 0;
872
873 var[10].val.f = 11.0f;
874 var[10].type = nsXPTType::T_FLOAT;
875 var[10].flags = 0;
876
877 var[11].val.d = 0.0;
878 var[11].type = nsXPTType::T_DOUBLE;
879 var[11].flags = nsXPTCVariant::PTR_IS_DATA;
880 var[11].ptr = &var[11].val.d;
881
882 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 14, 12, var)))
883 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 = %f\n",
884 var[11].val.d);
885 else
886 printf("\tFAILED");
887
888 var[0].val.p = (void*)"moo";
889 var[0].type = nsXPTType::T_CHAR_STR;
890 var[0].flags = 0;
891
892 var[1].val.p = (void*)"cow";
893 var[1].type = nsXPTType::T_CHAR_STR;
894 var[1].flags = 0;
895
896 var[2].val.p = 0;
897 var[2].type = nsXPTType::T_CHAR_STR;
898 var[2].flags = nsXPTCVariant::PTR_IS_DATA;
899 var[2].ptr = &var[2].val.p;
900
901 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 15, 3, var)))
902 {
903 printf(" = %s\n", var[2].val.p);
904 nsMemory::Free(var[2].val.p);
905 }
906 else
907 printf("\tFAILED");
908
909 DoMultipleInheritenceTest();
910 DoMultipleInheritenceTest2();
911 // Disabled by default - takes too much time on slow machines
912 //DoSpeedTest();
913
914 NS_RELEASE(test);
915
916 return 0;
917}
918
919/***************************************************************************/
920/***************************************************************************/
921/***************************************************************************/
922
923// {491C65A0-3317-11d3-9885-006008962422}
924#define FOO_IID \
925{ 0x491c65a0, 0x3317, 0x11d3, \
926 { 0x98, 0x85, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
927
928// {491C65A1-3317-11d3-9885-006008962422}
929#define BAR_IID \
930{ 0x491c65a1, 0x3317, 0x11d3, \
931 { 0x98, 0x85, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
932
933/***************************/
934
935class nsIFoo : public nsISupports
936{
937public:
938 NS_DEFINE_STATIC_IID_ACCESSOR(FOO_IID)
939 NS_IMETHOD FooMethod1(PRInt32 i) = 0;
940 NS_IMETHOD FooMethod2(PRInt32 i) = 0;
941};
942
943class nsIBar : public nsISupports
944{
945public:
946 NS_DEFINE_STATIC_IID_ACCESSOR(BAR_IID)
947 NS_IMETHOD BarMethod1(PRInt32 i) = 0;
948 NS_IMETHOD BarMethod2(PRInt32 i) = 0;
949};
950
951/***************************/
952
953class FooImpl : public nsIFoo
954{
955public:
956 NS_IMETHOD FooMethod1(PRInt32 i);
957 NS_IMETHOD FooMethod2(PRInt32 i);
958
959 FooImpl();
960
961protected:
962 ~FooImpl() {}
963
964public:
965 virtual const char* ImplName() = 0;
966
967 int SomeData1;
968 int SomeData2;
969 const char* Name;
970};
971
972class BarImpl : public nsIBar
973{
974public:
975 NS_IMETHOD BarMethod1(PRInt32 i);
976 NS_IMETHOD BarMethod2(PRInt32 i);
977
978 BarImpl();
979
980protected:
981 ~BarImpl() {}
982
983public:
984 virtual const char * ImplName() = 0;
985
986 int SomeData1;
987 int SomeData2;
988 const char* Name;
989};
990
991/***************************/
992
993FooImpl::FooImpl() : Name("FooImpl")
994{
995}
996
997NS_IMETHODIMP FooImpl::FooMethod1(PRInt32 i)
998{
999 printf("\tFooImpl::FooMethod1 called with i == %d, %s part of a %s\n",
1000 i, Name, ImplName());
1001 return NS_OK;
1002}
1003
1004NS_IMETHODIMP FooImpl::FooMethod2(PRInt32 i)
1005{
1006 printf("\tFooImpl::FooMethod2 called with i == %d, %s part of a %s\n",
1007 i, Name, ImplName());
1008 return NS_OK;
1009}
1010
1011/***************************/
1012
1013BarImpl::BarImpl() : Name("BarImpl")
1014{
1015}
1016
1017NS_IMETHODIMP BarImpl::BarMethod1(PRInt32 i)
1018{
1019 printf("\tBarImpl::BarMethod1 called with i == %d, %s part of a %s\n",
1020 i, Name, ImplName());
1021 return NS_OK;
1022}
1023
1024NS_IMETHODIMP BarImpl::BarMethod2(PRInt32 i)
1025{
1026 printf("\tBarImpl::BarMethod2 called with i == %d, %s part of a %s\n",
1027 i, Name, ImplName());
1028 return NS_OK;
1029}
1030
1031/***************************/
1032
1033class FooBarImpl : public FooImpl, public BarImpl
1034{
1035public:
1036 NS_DECL_ISUPPORTS
1037
1038 const char* ImplName();
1039
1040 FooBarImpl();
1041
1042private:
1043 ~FooBarImpl() {}
1044
1045public:
1046 const char* MyName;
1047};
1048
1049FooBarImpl::FooBarImpl() : MyName("FooBarImpl")
1050{
1051 NS_ADDREF_THIS();
1052}
1053
1054const char* FooBarImpl::ImplName()
1055{
1056 return MyName;
1057}
1058
1059NS_IMETHODIMP
1060FooBarImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr)
1061{
1062 if (NULL == aInstancePtr) {
1063 return NS_ERROR_NULL_POINTER;
1064 }
1065
1066 *aInstancePtr = NULL;
1067
1068
1069 if (aIID.Equals(NS_GET_IID(nsIFoo))) {
1070 *aInstancePtr = (void*) NS_STATIC_CAST(nsIFoo*,this);
1071 NS_ADDREF_THIS();
1072 return NS_OK;
1073 }
1074 if (aIID.Equals(NS_GET_IID(nsIBar))) {
1075 *aInstancePtr = (void*) NS_STATIC_CAST(nsIBar*,this);
1076 NS_ADDREF_THIS();
1077 return NS_OK;
1078 }
1079
1080 if (aIID.Equals(NS_GET_IID(nsISupports))) {
1081 *aInstancePtr = (void*) NS_STATIC_CAST(nsISupports*,
1082 NS_STATIC_CAST(nsIFoo*,this));
1083 NS_ADDREF_THIS();
1084 return NS_OK;
1085 }
1086 return NS_NOINTERFACE;
1087}
1088
1089NS_IMPL_ADDREF(FooBarImpl)
1090NS_IMPL_RELEASE(FooBarImpl)
1091
1092
1093static void DoMultipleInheritenceTest()
1094{
1095 FooBarImpl* impl = new FooBarImpl();
1096 if(!impl)
1097 return;
1098
1099 nsIFoo* foo;
1100 nsIBar* bar;
1101
1102 nsXPTCVariant var[1];
1103
1104 printf("\n");
1105 if(NS_SUCCEEDED(impl->QueryInterface(NS_GET_IID(nsIFoo), (void**)&foo)) &&
1106 NS_SUCCEEDED(impl->QueryInterface(NS_GET_IID(nsIBar), (void**)&bar)))
1107 {
1108 printf("impl == %p\n", impl);
1109 printf("foo == %p\n", foo);
1110 printf("bar == %p\n", bar);
1111
1112 printf("Calling Foo...\n");
1113 printf("direct calls:\n");
1114 foo->FooMethod1(1);
1115 foo->FooMethod2(2);
1116
1117 printf("invoke calls:\n");
1118 var[0].val.i32 = 1;
1119 var[0].type = nsXPTType::T_I32;
1120 var[0].flags = 0;
1121 XPTC_InvokeByIndex(foo, 3, 1, var);
1122
1123 var[0].val.i32 = 2;
1124 var[0].type = nsXPTType::T_I32;
1125 var[0].flags = 0;
1126 XPTC_InvokeByIndex(foo, 4, 1, var);
1127
1128 printf("\n");
1129
1130 printf("Calling Bar...\n");
1131 printf("direct calls:\n");
1132 bar->BarMethod1(1);
1133 bar->BarMethod2(2);
1134
1135 printf("invoke calls:\n");
1136 var[0].val.i32 = 1;
1137 var[0].type = nsXPTType::T_I32;
1138 var[0].flags = 0;
1139 XPTC_InvokeByIndex(bar, 3, 1, var);
1140
1141 var[0].val.i32 = 2;
1142 var[0].type = nsXPTType::T_I32;
1143 var[0].flags = 0;
1144 XPTC_InvokeByIndex(bar, 4, 1, var);
1145
1146 printf("\n");
1147
1148 NS_RELEASE(foo);
1149 NS_RELEASE(bar);
1150 }
1151 NS_RELEASE(impl);
1152}
1153/***************************************************************************/
1154/***************************************************************************/
1155/***************************************************************************/
1156/* This is a variation on the theme submitted by [email protected] (Duncan Wilcox).
1157* He was seeing the other test work and this test not work. They should both
1158* Work on any given platform
1159*/
1160
1161class nsIFoo2 : public nsISupports
1162{
1163public:
1164 NS_IMETHOD FooMethod1(PRInt32 i) = 0;
1165 NS_IMETHOD FooMethod2(PRInt32 i) = 0;
1166};
1167
1168class nsIBar2 : public nsISupports
1169{
1170public:
1171 NS_IMETHOD BarMethod1(PRInt32 i) = 0;
1172 NS_IMETHOD BarMethod2(PRInt32 i) = 0;
1173};
1174
1175class FooBarImpl2 : public nsIFoo2, public nsIBar2
1176{
1177public:
1178 // Foo interface
1179 NS_IMETHOD FooMethod1(PRInt32 i);
1180 NS_IMETHOD FooMethod2(PRInt32 i);
1181
1182 // Bar interface
1183 NS_IMETHOD BarMethod1(PRInt32 i);
1184 NS_IMETHOD BarMethod2(PRInt32 i);
1185
1186 NS_DECL_ISUPPORTS
1187
1188 FooBarImpl2();
1189
1190private:
1191 ~FooBarImpl2() {}
1192
1193public:
1194 PRInt32 value;
1195};
1196
1197FooBarImpl2::FooBarImpl2() : value(0x12345678)
1198{
1199 NS_ADDREF_THIS();
1200}
1201
1202NS_IMETHODIMP FooBarImpl2::FooMethod1(PRInt32 i)
1203{
1204 printf("\tFooBarImpl2::FooMethod1 called with i == %d, local value = %x\n",
1205 i, value);
1206 return NS_OK;
1207}
1208
1209NS_IMETHODIMP FooBarImpl2::FooMethod2(PRInt32 i)
1210{
1211 printf("\tFooBarImpl2::FooMethod2 called with i == %d, local value = %x\n",
1212 i, value);
1213 return NS_OK;
1214}
1215
1216NS_IMETHODIMP FooBarImpl2::BarMethod1(PRInt32 i)
1217{
1218 printf("\tFooBarImpl2::BarMethod1 called with i == %d, local value = %x\n",
1219 i, value);
1220 return NS_OK;
1221}
1222
1223NS_IMETHODIMP FooBarImpl2::BarMethod2(PRInt32 i)
1224{
1225 printf("\tFooBarImpl2::BarMethod2 called with i == %d, local value = %x\n",
1226 i, value);
1227 return NS_OK;
1228}
1229
1230NS_IMETHODIMP
1231FooBarImpl2::QueryInterface(REFNSIID aIID, void** aInstancePtr)
1232{
1233 if (NULL == aInstancePtr) {
1234 return NS_ERROR_NULL_POINTER;
1235 }
1236
1237 *aInstancePtr = NULL;
1238
1239
1240 if (aIID.Equals(NS_GET_IID(nsIFoo))) {
1241 *aInstancePtr = (void*) NS_STATIC_CAST(nsIFoo2*,this);
1242 NS_ADDREF_THIS();
1243 return NS_OK;
1244 }
1245 if (aIID.Equals(NS_GET_IID(nsIBar))) {
1246 *aInstancePtr = (void*) NS_STATIC_CAST(nsIBar2*,this);
1247 NS_ADDREF_THIS();
1248 return NS_OK;
1249 }
1250
1251 if (aIID.Equals(NS_GET_IID(nsISupports))) {
1252 *aInstancePtr = (void*) NS_STATIC_CAST(nsISupports*,
1253 NS_STATIC_CAST(nsIFoo2*,this));
1254 NS_ADDREF_THIS();
1255 return NS_OK;
1256 }
1257 return NS_NOINTERFACE;
1258}
1259
1260NS_IMPL_ADDREF(FooBarImpl2)
1261NS_IMPL_RELEASE(FooBarImpl2)
1262
1263static void DoMultipleInheritenceTest2()
1264{
1265 FooBarImpl2* impl = new FooBarImpl2();
1266 if(!impl)
1267 return;
1268
1269 nsIFoo2* foo;
1270 nsIBar2* bar;
1271
1272 nsXPTCVariant var[1];
1273
1274 printf("\n");
1275 if(NS_SUCCEEDED(impl->QueryInterface(NS_GET_IID(nsIFoo), (void**)&foo)) &&
1276 NS_SUCCEEDED(impl->QueryInterface(NS_GET_IID(nsIBar), (void**)&bar)))
1277 {
1278 printf("impl == %p\n", impl);
1279 printf("foo == %p\n", foo);
1280 printf("bar == %p\n", bar);
1281
1282 printf("Calling Foo...\n");
1283 printf("direct calls:\n");
1284 foo->FooMethod1(1);
1285 foo->FooMethod2(2);
1286
1287 printf("invoke calls:\n");
1288 var[0].val.i32 = 1;
1289 var[0].type = nsXPTType::T_I32;
1290 var[0].flags = 0;
1291 XPTC_InvokeByIndex(foo, 3, 1, var);
1292
1293 var[0].val.i32 = 2;
1294 var[0].type = nsXPTType::T_I32;
1295 var[0].flags = 0;
1296 XPTC_InvokeByIndex(foo, 4, 1, var);
1297
1298 printf("\n");
1299
1300 printf("Calling Bar...\n");
1301 printf("direct calls:\n");
1302 bar->BarMethod1(1);
1303 bar->BarMethod2(2);
1304
1305 printf("invoke calls:\n");
1306 var[0].val.i32 = 1;
1307 var[0].type = nsXPTType::T_I32;
1308 var[0].flags = 0;
1309 XPTC_InvokeByIndex(bar, 3, 1, var);
1310
1311 var[0].val.i32 = 2;
1312 var[0].type = nsXPTType::T_I32;
1313 var[0].flags = 0;
1314 XPTC_InvokeByIndex(bar, 4, 1, var);
1315
1316 printf("\n");
1317
1318 NS_RELEASE(foo);
1319 NS_RELEASE(bar);
1320 }
1321 NS_RELEASE(impl);
1322}
1323
1324static void DoSpeedTest()
1325{
1326 InvokeTestTarget *test = new InvokeTestTarget();
1327
1328 nsXPTCVariant var[3];
1329
1330 var[0].val.i32 = 1;
1331 var[0].type = nsXPTType::T_I32;
1332 var[0].flags = 0;
1333
1334 var[1].val.i32 = 1;
1335 var[1].type = nsXPTType::T_I32;
1336 var[1].flags = 0;
1337
1338 var[2].val.i32 = 0;
1339 var[2].type = nsXPTType::T_I32;
1340 var[2].flags = nsXPTCVariant::PTR_IS_DATA;
1341 var[2].ptr = &var[2].val.i32;
1342
1343 PRInt32 in1 = 1;
1344 PRInt32 in2 = 1;
1345 PRInt32 out;
1346
1347 // Crank this number down if your platform is slow :)
1348 static const int count = 100000000;
1349 int i;
1350 PRIntervalTime start;
1351 PRIntervalTime interval_direct;
1352 PRIntervalTime interval_invoke;
1353
1354 printf("Speed test...\n\n");
1355 printf("Doing %d direct call iterations...\n", count);
1356 start = PR_IntervalNow();
1357 for(i = count; i; i--)
1358 (void)test->AddTwoInts(in1, in2, &out);
1359 interval_direct = PR_IntervalNow() - start;
1360
1361 printf("Doing %d invoked call iterations...\n", count);
1362 start = PR_IntervalNow();
1363 for(i = count; i; i--)
1364 (void)XPTC_InvokeByIndex(test, 3, 3, var);
1365 interval_invoke = PR_IntervalNow() - start;
1366
1367 printf(" direct took %0.2f seconds\n",
1368 (double)interval_direct/(double)PR_TicksPerSecond());
1369 printf(" invoke took %0.2f seconds\n",
1370 (double)interval_invoke/(double)PR_TicksPerSecond());
1371 printf(" So, invoke overhead was ~ %0.2f seconds (~ %0.0f%%)\n",
1372 (double)(interval_invoke-interval_direct)/(double)PR_TicksPerSecond(),
1373 (double)(interval_invoke-interval_direct)/(double)interval_invoke*100);
1374}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette