VirtualBox

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

Last change on this file since 15922 was 1, checked in by vboxsync, 55 years ago

import

  • 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 printf(" = %s\n", var[2].val.p);
903 else
904 printf("\tFAILED");
905
906 DoMultipleInheritenceTest();
907 DoMultipleInheritenceTest2();
908 // Disabled by default - takes too much time on slow machines
909 //DoSpeedTest();
910
911 return 0;
912}
913
914/***************************************************************************/
915/***************************************************************************/
916/***************************************************************************/
917
918// {491C65A0-3317-11d3-9885-006008962422}
919#define FOO_IID \
920{ 0x491c65a0, 0x3317, 0x11d3, \
921 { 0x98, 0x85, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
922
923// {491C65A1-3317-11d3-9885-006008962422}
924#define BAR_IID \
925{ 0x491c65a1, 0x3317, 0x11d3, \
926 { 0x98, 0x85, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
927
928/***************************/
929
930class nsIFoo : public nsISupports
931{
932public:
933 NS_DEFINE_STATIC_IID_ACCESSOR(FOO_IID)
934 NS_IMETHOD FooMethod1(PRInt32 i) = 0;
935 NS_IMETHOD FooMethod2(PRInt32 i) = 0;
936};
937
938class nsIBar : public nsISupports
939{
940public:
941 NS_DEFINE_STATIC_IID_ACCESSOR(BAR_IID)
942 NS_IMETHOD BarMethod1(PRInt32 i) = 0;
943 NS_IMETHOD BarMethod2(PRInt32 i) = 0;
944};
945
946/***************************/
947
948class FooImpl : public nsIFoo
949{
950public:
951 NS_IMETHOD FooMethod1(PRInt32 i);
952 NS_IMETHOD FooMethod2(PRInt32 i);
953
954 FooImpl();
955
956protected:
957 ~FooImpl() {}
958
959public:
960 virtual const char* ImplName() = 0;
961
962 int SomeData1;
963 int SomeData2;
964 const char* Name;
965};
966
967class BarImpl : public nsIBar
968{
969public:
970 NS_IMETHOD BarMethod1(PRInt32 i);
971 NS_IMETHOD BarMethod2(PRInt32 i);
972
973 BarImpl();
974
975protected:
976 ~BarImpl() {}
977
978public:
979 virtual const char * ImplName() = 0;
980
981 int SomeData1;
982 int SomeData2;
983 const char* Name;
984};
985
986/***************************/
987
988FooImpl::FooImpl() : Name("FooImpl")
989{
990}
991
992NS_IMETHODIMP FooImpl::FooMethod1(PRInt32 i)
993{
994 printf("\tFooImpl::FooMethod1 called with i == %d, %s part of a %s\n",
995 i, Name, ImplName());
996 return NS_OK;
997}
998
999NS_IMETHODIMP FooImpl::FooMethod2(PRInt32 i)
1000{
1001 printf("\tFooImpl::FooMethod2 called with i == %d, %s part of a %s\n",
1002 i, Name, ImplName());
1003 return NS_OK;
1004}
1005
1006/***************************/
1007
1008BarImpl::BarImpl() : Name("BarImpl")
1009{
1010}
1011
1012NS_IMETHODIMP BarImpl::BarMethod1(PRInt32 i)
1013{
1014 printf("\tBarImpl::BarMethod1 called with i == %d, %s part of a %s\n",
1015 i, Name, ImplName());
1016 return NS_OK;
1017}
1018
1019NS_IMETHODIMP BarImpl::BarMethod2(PRInt32 i)
1020{
1021 printf("\tBarImpl::BarMethod2 called with i == %d, %s part of a %s\n",
1022 i, Name, ImplName());
1023 return NS_OK;
1024}
1025
1026/***************************/
1027
1028class FooBarImpl : public FooImpl, public BarImpl
1029{
1030public:
1031 NS_DECL_ISUPPORTS
1032
1033 const char* ImplName();
1034
1035 FooBarImpl();
1036
1037private:
1038 ~FooBarImpl() {}
1039
1040public:
1041 const char* MyName;
1042};
1043
1044FooBarImpl::FooBarImpl() : MyName("FooBarImpl")
1045{
1046 NS_ADDREF_THIS();
1047}
1048
1049const char* FooBarImpl::ImplName()
1050{
1051 return MyName;
1052}
1053
1054NS_IMETHODIMP
1055FooBarImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr)
1056{
1057 if (NULL == aInstancePtr) {
1058 return NS_ERROR_NULL_POINTER;
1059 }
1060
1061 *aInstancePtr = NULL;
1062
1063
1064 if (aIID.Equals(NS_GET_IID(nsIFoo))) {
1065 *aInstancePtr = (void*) NS_STATIC_CAST(nsIFoo*,this);
1066 NS_ADDREF_THIS();
1067 return NS_OK;
1068 }
1069 if (aIID.Equals(NS_GET_IID(nsIBar))) {
1070 *aInstancePtr = (void*) NS_STATIC_CAST(nsIBar*,this);
1071 NS_ADDREF_THIS();
1072 return NS_OK;
1073 }
1074
1075 if (aIID.Equals(NS_GET_IID(nsISupports))) {
1076 *aInstancePtr = (void*) NS_STATIC_CAST(nsISupports*,
1077 NS_STATIC_CAST(nsIFoo*,this));
1078 NS_ADDREF_THIS();
1079 return NS_OK;
1080 }
1081 return NS_NOINTERFACE;
1082}
1083
1084NS_IMPL_ADDREF(FooBarImpl)
1085NS_IMPL_RELEASE(FooBarImpl)
1086
1087
1088static void DoMultipleInheritenceTest()
1089{
1090 FooBarImpl* impl = new FooBarImpl();
1091 if(!impl)
1092 return;
1093
1094 nsIFoo* foo;
1095 nsIBar* bar;
1096
1097 nsXPTCVariant var[1];
1098
1099 printf("\n");
1100 if(NS_SUCCEEDED(impl->QueryInterface(NS_GET_IID(nsIFoo), (void**)&foo)) &&
1101 NS_SUCCEEDED(impl->QueryInterface(NS_GET_IID(nsIBar), (void**)&bar)))
1102 {
1103 printf("impl == %p\n", impl);
1104 printf("foo == %p\n", foo);
1105 printf("bar == %p\n", bar);
1106
1107 printf("Calling Foo...\n");
1108 printf("direct calls:\n");
1109 foo->FooMethod1(1);
1110 foo->FooMethod2(2);
1111
1112 printf("invoke calls:\n");
1113 var[0].val.i32 = 1;
1114 var[0].type = nsXPTType::T_I32;
1115 var[0].flags = 0;
1116 XPTC_InvokeByIndex(foo, 3, 1, var);
1117
1118 var[0].val.i32 = 2;
1119 var[0].type = nsXPTType::T_I32;
1120 var[0].flags = 0;
1121 XPTC_InvokeByIndex(foo, 4, 1, var);
1122
1123 printf("\n");
1124
1125 printf("Calling Bar...\n");
1126 printf("direct calls:\n");
1127 bar->BarMethod1(1);
1128 bar->BarMethod2(2);
1129
1130 printf("invoke calls:\n");
1131 var[0].val.i32 = 1;
1132 var[0].type = nsXPTType::T_I32;
1133 var[0].flags = 0;
1134 XPTC_InvokeByIndex(bar, 3, 1, var);
1135
1136 var[0].val.i32 = 2;
1137 var[0].type = nsXPTType::T_I32;
1138 var[0].flags = 0;
1139 XPTC_InvokeByIndex(bar, 4, 1, var);
1140
1141 printf("\n");
1142
1143 NS_RELEASE(foo);
1144 NS_RELEASE(bar);
1145 }
1146 NS_RELEASE(impl);
1147}
1148/***************************************************************************/
1149/***************************************************************************/
1150/***************************************************************************/
1151/* This is a variation on the theme submitted by [email protected] (Duncan Wilcox).
1152* He was seeing the other test work and this test not work. They should both
1153* Work on any given platform
1154*/
1155
1156class nsIFoo2 : public nsISupports
1157{
1158public:
1159 NS_IMETHOD FooMethod1(PRInt32 i) = 0;
1160 NS_IMETHOD FooMethod2(PRInt32 i) = 0;
1161};
1162
1163class nsIBar2 : public nsISupports
1164{
1165public:
1166 NS_IMETHOD BarMethod1(PRInt32 i) = 0;
1167 NS_IMETHOD BarMethod2(PRInt32 i) = 0;
1168};
1169
1170class FooBarImpl2 : public nsIFoo2, public nsIBar2
1171{
1172public:
1173 // Foo interface
1174 NS_IMETHOD FooMethod1(PRInt32 i);
1175 NS_IMETHOD FooMethod2(PRInt32 i);
1176
1177 // Bar interface
1178 NS_IMETHOD BarMethod1(PRInt32 i);
1179 NS_IMETHOD BarMethod2(PRInt32 i);
1180
1181 NS_DECL_ISUPPORTS
1182
1183 FooBarImpl2();
1184
1185private:
1186 ~FooBarImpl2() {}
1187
1188public:
1189 PRInt32 value;
1190};
1191
1192FooBarImpl2::FooBarImpl2() : value(0x12345678)
1193{
1194 NS_ADDREF_THIS();
1195}
1196
1197NS_IMETHODIMP FooBarImpl2::FooMethod1(PRInt32 i)
1198{
1199 printf("\tFooBarImpl2::FooMethod1 called with i == %d, local value = %x\n",
1200 i, value);
1201 return NS_OK;
1202}
1203
1204NS_IMETHODIMP FooBarImpl2::FooMethod2(PRInt32 i)
1205{
1206 printf("\tFooBarImpl2::FooMethod2 called with i == %d, local value = %x\n",
1207 i, value);
1208 return NS_OK;
1209}
1210
1211NS_IMETHODIMP FooBarImpl2::BarMethod1(PRInt32 i)
1212{
1213 printf("\tFooBarImpl2::BarMethod1 called with i == %d, local value = %x\n",
1214 i, value);
1215 return NS_OK;
1216}
1217
1218NS_IMETHODIMP FooBarImpl2::BarMethod2(PRInt32 i)
1219{
1220 printf("\tFooBarImpl2::BarMethod2 called with i == %d, local value = %x\n",
1221 i, value);
1222 return NS_OK;
1223}
1224
1225NS_IMETHODIMP
1226FooBarImpl2::QueryInterface(REFNSIID aIID, void** aInstancePtr)
1227{
1228 if (NULL == aInstancePtr) {
1229 return NS_ERROR_NULL_POINTER;
1230 }
1231
1232 *aInstancePtr = NULL;
1233
1234
1235 if (aIID.Equals(NS_GET_IID(nsIFoo))) {
1236 *aInstancePtr = (void*) NS_STATIC_CAST(nsIFoo2*,this);
1237 NS_ADDREF_THIS();
1238 return NS_OK;
1239 }
1240 if (aIID.Equals(NS_GET_IID(nsIBar))) {
1241 *aInstancePtr = (void*) NS_STATIC_CAST(nsIBar2*,this);
1242 NS_ADDREF_THIS();
1243 return NS_OK;
1244 }
1245
1246 if (aIID.Equals(NS_GET_IID(nsISupports))) {
1247 *aInstancePtr = (void*) NS_STATIC_CAST(nsISupports*,
1248 NS_STATIC_CAST(nsIFoo2*,this));
1249 NS_ADDREF_THIS();
1250 return NS_OK;
1251 }
1252 return NS_NOINTERFACE;
1253}
1254
1255NS_IMPL_ADDREF(FooBarImpl2)
1256NS_IMPL_RELEASE(FooBarImpl2)
1257
1258static void DoMultipleInheritenceTest2()
1259{
1260 FooBarImpl2* impl = new FooBarImpl2();
1261 if(!impl)
1262 return;
1263
1264 nsIFoo2* foo;
1265 nsIBar2* bar;
1266
1267 nsXPTCVariant var[1];
1268
1269 printf("\n");
1270 if(NS_SUCCEEDED(impl->QueryInterface(NS_GET_IID(nsIFoo), (void**)&foo)) &&
1271 NS_SUCCEEDED(impl->QueryInterface(NS_GET_IID(nsIBar), (void**)&bar)))
1272 {
1273 printf("impl == %p\n", impl);
1274 printf("foo == %p\n", foo);
1275 printf("bar == %p\n", bar);
1276
1277 printf("Calling Foo...\n");
1278 printf("direct calls:\n");
1279 foo->FooMethod1(1);
1280 foo->FooMethod2(2);
1281
1282 printf("invoke calls:\n");
1283 var[0].val.i32 = 1;
1284 var[0].type = nsXPTType::T_I32;
1285 var[0].flags = 0;
1286 XPTC_InvokeByIndex(foo, 3, 1, var);
1287
1288 var[0].val.i32 = 2;
1289 var[0].type = nsXPTType::T_I32;
1290 var[0].flags = 0;
1291 XPTC_InvokeByIndex(foo, 4, 1, var);
1292
1293 printf("\n");
1294
1295 printf("Calling Bar...\n");
1296 printf("direct calls:\n");
1297 bar->BarMethod1(1);
1298 bar->BarMethod2(2);
1299
1300 printf("invoke calls:\n");
1301 var[0].val.i32 = 1;
1302 var[0].type = nsXPTType::T_I32;
1303 var[0].flags = 0;
1304 XPTC_InvokeByIndex(bar, 3, 1, var);
1305
1306 var[0].val.i32 = 2;
1307 var[0].type = nsXPTType::T_I32;
1308 var[0].flags = 0;
1309 XPTC_InvokeByIndex(bar, 4, 1, var);
1310
1311 printf("\n");
1312
1313 NS_RELEASE(foo);
1314 NS_RELEASE(bar);
1315 }
1316 NS_RELEASE(impl);
1317}
1318
1319static void DoSpeedTest()
1320{
1321 InvokeTestTarget *test = new InvokeTestTarget();
1322
1323 nsXPTCVariant var[3];
1324
1325 var[0].val.i32 = 1;
1326 var[0].type = nsXPTType::T_I32;
1327 var[0].flags = 0;
1328
1329 var[1].val.i32 = 1;
1330 var[1].type = nsXPTType::T_I32;
1331 var[1].flags = 0;
1332
1333 var[2].val.i32 = 0;
1334 var[2].type = nsXPTType::T_I32;
1335 var[2].flags = nsXPTCVariant::PTR_IS_DATA;
1336 var[2].ptr = &var[2].val.i32;
1337
1338 PRInt32 in1 = 1;
1339 PRInt32 in2 = 1;
1340 PRInt32 out;
1341
1342 // Crank this number down if your platform is slow :)
1343 static const int count = 100000000;
1344 int i;
1345 PRIntervalTime start;
1346 PRIntervalTime interval_direct;
1347 PRIntervalTime interval_invoke;
1348
1349 printf("Speed test...\n\n");
1350 printf("Doing %d direct call iterations...\n", count);
1351 start = PR_IntervalNow();
1352 for(i = count; i; i--)
1353 (void)test->AddTwoInts(in1, in2, &out);
1354 interval_direct = PR_IntervalNow() - start;
1355
1356 printf("Doing %d invoked call iterations...\n", count);
1357 start = PR_IntervalNow();
1358 for(i = count; i; i--)
1359 (void)XPTC_InvokeByIndex(test, 3, 3, var);
1360 interval_invoke = PR_IntervalNow() - start;
1361
1362 printf(" direct took %0.2f seconds\n",
1363 (double)interval_direct/(double)PR_TicksPerSecond());
1364 printf(" invoke took %0.2f seconds\n",
1365 (double)interval_invoke/(double)PR_TicksPerSecond());
1366 printf(" So, invoke overhead was ~ %0.2f seconds (~ %0.0f%%)\n",
1367 (double)(interval_invoke-interval_direct)/(double)PR_TicksPerSecond(),
1368 (double)(interval_invoke-interval_direct)/(double)interval_invoke*100);
1369}
Note: See TracBrowser for help on using the repository browser.

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