VirtualBox

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

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

xpcom/TestXPTCInvoke: Exit with non-zero status on failure. Compare direct and invoke'ed result (printf output) to determine whether stuff works. bugref:9841

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