1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
23
* Pierre Phaneuf <pp@ludusdesign.com>
24
* Stuart Parmenter <pavlov@netscape.com>
25
* Chris Seawood <cls@seawood.org>
27
* Alternatively, the contents of this file may be used under the terms of
28
* either the GNU General Public License Version 2 or later (the "GPL"), or
29
* 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 NPL, 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 NPL, the GPL or the LGPL.
39
* ***** END LICENSE BLOCK ***** */
41
/* Invoke tests xptcall. */
50
static void DoMultipleInheritenceTest();
51
static void DoMultipleInheritenceTest2();
52
static void DoSpeedTest();
54
// {AAC1FB90-E099-11d2-984E-006008962422}
55
#define INVOKETESTTARGET_IID \
56
{ 0xaac1fb90, 0xe099, 0x11d2, \
57
{ 0x98, 0x4e, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
60
class InvokeTestTargetInterface : public nsISupports
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;
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;
73
NS_IMETHOD AddTwoFloats(float p1, float p2, float* retval) = 0;
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;
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;
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,
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;
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;
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,
103
NS_IMETHOD PassTwoStrings(const char* s1, const char* s2, char** retval) = 0;
107
class InvokeTestTarget : public InvokeTestTargetInterface
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);
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);
120
NS_IMETHOD AddTwoFloats(float p1, float p2, float* retval);
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);
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);
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);
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);
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,
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,
150
NS_IMETHOD PassTwoStrings(const char* s1, const char* s2, char** retval);
155
NS_IMPL_ISUPPORTS1(InvokeTestTarget, InvokeTestTargetInterface)
157
InvokeTestTarget::InvokeTestTarget()
163
InvokeTestTarget::AddTwoInts(PRInt32 p1, PRInt32 p2, PRInt32* retval)
170
InvokeTestTarget::MultTwoInts(PRInt32 p1, PRInt32 p2, PRInt32* retval)
177
InvokeTestTarget::AddTwoLLs(PRInt64 p1, PRInt64 p2, PRInt64* retval)
179
LL_ADD(*retval, p1, p2);
184
InvokeTestTarget::MultTwoLLs(PRInt64 p1, PRInt64 p2, PRInt64* retval)
186
LL_MUL(*retval, p1, p2);
191
InvokeTestTarget::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)
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);
199
*retval = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10;
204
InvokeTestTarget::AddTwoFloats(float p1, float p2, float *retval)
206
#ifdef DEBUG_TESTINVOKE
207
printf("%f, %f\n", p1, p2);
214
InvokeTestTarget::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)
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);
222
*retval = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10;
227
InvokeTestTarget::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)
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);
235
*retval = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10;
240
InvokeTestTarget::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,
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);
249
*retval = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 + p11;
254
InvokeTestTarget::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,
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);
267
*retval = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10 +
268
p11 + p12 + p13 + p14 + p15 + p16 + p17 + p18 + p19 + p20;
273
InvokeTestTarget::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)
277
*retval = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10;
282
InvokeTestTarget::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)
286
*retval = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10;
291
InvokeTestTarget::PassTwoStrings(const char* s1, const char* s2, char** retval)
293
const char milk[] = "milk";
294
char *ret = (char*)nsMemory::Alloc(sizeof(milk));
296
return NS_ERROR_OUT_OF_MEMORY;
297
strncpy(ret, milk, sizeof(milk));
298
printf("\t%s %s", s1, s2);
305
InvokeTestTarget *test = new InvokeTestTarget();
307
/* here we make the global 'check for alloc failure' checker happy */
311
PRInt32 out, tmp32 = 0;
313
printf("calling direct:\n");
314
if(NS_SUCCEEDED(test->AddTwoInts(1,1,&out)))
315
printf("\t1 + 1 = %d\n", out);
321
if(NS_SUCCEEDED(test->AddTwoLLs(one,one,&out64)))
323
LL_L2I(tmp32, out64);
324
printf("\t1L + 1L = %d\n", (int)tmp32);
328
if(NS_SUCCEEDED(test->MultTwoInts(2,2,&out)))
329
printf("\t2 * 2 = %d\n", out);
332
if(NS_SUCCEEDED(test->MultTwoLLs(two,two,&out64)))
334
LL_L2I(tmp32, out64);
335
printf("\t2L * 2L = %d\n", (int)tmp32);
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);
350
if(NS_SUCCEEDED(test->AddTwoFloats(1,2,&outF)))
351
printf("\t1 + 2 = %ff\n", (double)outF);
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);
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);
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);
370
if(NS_SUCCEEDED(test->AddMixedInts(1,2,3,4,5,6,7,8,9,10,&out64)))
372
LL_L2I(tmp32, out64);
373
printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n", (int)tmp32);
378
if(NS_SUCCEEDED(test->AddMixedInts2(1,2,3,4,5,6,7,8,9,10,&out64)))
380
LL_L2I(tmp32, out64);
381
printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n", (int)tmp32);
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);
391
if (NS_SUCCEEDED(test->PassTwoStrings("moo","cow",&outS))) {
392
printf(" = %s\n", outS);
393
nsMemory::Free(outS);
397
printf("calling via invoke:\n");
399
nsXPTCVariant var[21];
402
var[0].type = nsXPTType::T_I32;
406
var[1].type = nsXPTType::T_I32;
410
var[2].type = nsXPTType::T_I32;
411
var[2].flags = nsXPTCVariant::PTR_IS_DATA;
412
var[2].ptr = &var[2].val.i32;
414
if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 3, 3, var)))
415
printf("\t1 + 1 = %d\n", var[2].val.i32);
419
LL_I2L(var[0].val.i64, 1);
420
var[0].type = nsXPTType::T_I64;
423
LL_I2L(var[1].val.i64, 1);
424
var[1].type = nsXPTType::T_I64;
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;
432
if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 5, 3, var)))
433
printf("\t1L + 1L = %d\n", (int)var[2].val.i64);
438
var[0].type = nsXPTType::T_I32;
442
var[1].type = nsXPTType::T_I32;
446
var[2].type = nsXPTType::T_I32;
447
var[2].flags = nsXPTCVariant::PTR_IS_DATA;
448
var[2].ptr = &var[2].val.i32;
450
if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 4, 3, var)))
451
printf("\t2 * 2 = %d\n", var[2].val.i32);
455
LL_I2L(var[0].val.i64,2);
456
var[0].type = nsXPTType::T_I64;
459
LL_I2L(var[1].val.i64,2);
460
var[1].type = nsXPTType::T_I64;
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;
468
if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 6, 3, var)))
469
printf("\t2L * 2L = %d\n", (int)var[2].val.i64);
474
var[0].type = nsXPTType::T_I32;
478
var[1].type = nsXPTType::T_I32;
482
var[2].type = nsXPTType::T_I32;
486
var[3].type = nsXPTType::T_I32;
490
var[4].type = nsXPTType::T_I32;
494
var[5].type = nsXPTType::T_I32;
498
var[6].type = nsXPTType::T_I32;
502
var[7].type = nsXPTType::T_I32;
506
var[8].type = nsXPTType::T_I32;
510
var[9].type = nsXPTType::T_I32;
514
var[10].type = nsXPTType::T_I32;
515
var[10].flags = nsXPTCVariant::PTR_IS_DATA;
516
var[10].ptr = &var[10].val.i32;
518
if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 7, 11, var)))
519
printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n",
523
var[0].type = nsXPTType::T_FLOAT;
527
var[1].type = nsXPTType::T_FLOAT;
531
var[2].type = nsXPTType::T_FLOAT;
532
var[2].flags = nsXPTCVariant::PTR_IS_DATA;
533
var[2].ptr = &var[2].val.f;
535
if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 8, 3, var)))
536
printf("\t1 + 2 = %ff\n",
537
(double) var[2].val.f);
541
var[0].type = nsXPTType::T_DOUBLE;
545
var[1].type = nsXPTType::T_DOUBLE;
549
var[2].type = nsXPTType::T_DOUBLE;
553
var[3].type = nsXPTType::T_DOUBLE;
557
var[4].type = nsXPTType::T_DOUBLE;
561
var[5].type = nsXPTType::T_DOUBLE;
565
var[6].type = nsXPTType::T_DOUBLE;
569
var[7].type = nsXPTType::T_DOUBLE;
573
var[8].type = nsXPTType::T_DOUBLE;
577
var[9].type = nsXPTType::T_DOUBLE;
581
var[10].type = nsXPTType::T_DOUBLE;
582
var[10].flags = nsXPTCVariant::PTR_IS_DATA;
583
var[10].ptr = &var[10].val.d;
585
if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 9, 11, var)))
586
printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %f\n",
592
var[0].type = nsXPTType::T_FLOAT;
596
var[1].type = nsXPTType::T_FLOAT;
600
var[2].type = nsXPTType::T_FLOAT;
604
var[3].type = nsXPTType::T_FLOAT;
608
var[4].type = nsXPTType::T_FLOAT;
612
var[5].type = nsXPTType::T_FLOAT;
616
var[6].type = nsXPTType::T_FLOAT;
620
var[7].type = nsXPTType::T_FLOAT;
624
var[8].type = nsXPTType::T_FLOAT;
627
var[9].val.f = 10.0f;
628
var[9].type = nsXPTType::T_FLOAT;
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;
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);
643
var[0].type = nsXPTType::T_FLOAT;
647
var[1].type = nsXPTType::T_FLOAT;
651
var[2].type = nsXPTType::T_FLOAT;
655
var[3].type = nsXPTType::T_FLOAT;
659
var[4].type = nsXPTType::T_FLOAT;
663
var[5].type = nsXPTType::T_FLOAT;
667
var[6].type = nsXPTType::T_FLOAT;
671
var[7].type = nsXPTType::T_FLOAT;
675
var[8].type = nsXPTType::T_FLOAT;
678
var[9].val.f = 10.0f;
679
var[9].type = nsXPTType::T_FLOAT;
682
var[10].val.f = 11.0f;
683
var[10].type = nsXPTType::T_FLOAT;
686
var[11].val.f = 12.0f;
687
var[11].type = nsXPTType::T_FLOAT;
690
var[12].val.f = 13.0f;
691
var[12].type = nsXPTType::T_FLOAT;
694
var[13].val.f = 14.0f;
695
var[13].type = nsXPTType::T_FLOAT;
698
var[14].val.f = 15.0f;
699
var[14].type = nsXPTType::T_FLOAT;
702
var[15].val.f = 16.0f;
703
var[15].type = nsXPTType::T_FLOAT;
706
var[16].val.f = 17.0f;
707
var[16].type = nsXPTType::T_FLOAT;
710
var[17].val.f = 18.0f;
711
var[17].type = nsXPTType::T_FLOAT;
714
var[18].val.f = 19.0f;
715
var[18].type = nsXPTType::T_FLOAT;
718
var[19].val.f = 20.0f;
719
var[19].type = nsXPTType::T_FLOAT;
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;
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);
732
var[0].type = nsXPTType::T_I64;
736
var[1].type = nsXPTType::T_I32;
740
var[2].type = nsXPTType::T_I64;
744
var[3].type = nsXPTType::T_I32;
748
var[4].type = nsXPTType::T_I32;
752
var[5].type = nsXPTType::T_I64;
756
var[6].type = nsXPTType::T_I32;
760
var[7].type = nsXPTType::T_I32;
764
var[8].type = nsXPTType::T_I64;
768
var[9].type = nsXPTType::T_I32;
772
var[10].type = nsXPTType::T_I64;
773
var[10].flags = nsXPTCVariant::PTR_IS_DATA;
774
var[10].ptr = &var[10].val.i64;
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);
783
var[0].type = nsXPTType::T_I32;
787
var[1].type = nsXPTType::T_I64;
791
var[2].type = nsXPTType::T_I32;
795
var[3].type = nsXPTType::T_I64;
799
var[4].type = nsXPTType::T_I64;
803
var[5].type = nsXPTType::T_I32;
807
var[6].type = nsXPTType::T_I64;
811
var[7].type = nsXPTType::T_I64;
815
var[8].type = nsXPTType::T_I32;
819
var[9].type = nsXPTType::T_I64;
823
var[10].type = nsXPTType::T_I64;
824
var[10].flags = nsXPTCVariant::PTR_IS_DATA;
825
var[10].ptr = &var[10].val.i64;
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);
834
var[0].type = nsXPTType::T_FLOAT;
838
var[1].type = nsXPTType::T_FLOAT;
842
var[2].type = nsXPTType::T_DOUBLE;
846
var[3].type = nsXPTType::T_DOUBLE;
850
var[4].type = nsXPTType::T_FLOAT;
854
var[5].type = nsXPTType::T_FLOAT;
858
var[6].type = nsXPTType::T_DOUBLE;
862
var[7].type = nsXPTType::T_DOUBLE;
866
var[8].type = nsXPTType::T_FLOAT;
870
var[9].type = nsXPTType::T_DOUBLE;
873
var[10].val.f = 11.0f;
874
var[10].type = nsXPTType::T_FLOAT;
878
var[11].type = nsXPTType::T_DOUBLE;
879
var[11].flags = nsXPTCVariant::PTR_IS_DATA;
880
var[11].ptr = &var[11].val.d;
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",
888
var[0].val.p = (void*)"moo";
889
var[0].type = nsXPTType::T_CHAR_STR;
892
var[1].val.p = (void*)"cow";
893
var[1].type = nsXPTType::T_CHAR_STR;
897
var[2].type = nsXPTType::T_CHAR_STR;
898
var[2].flags = nsXPTCVariant::PTR_IS_DATA;
899
var[2].ptr = &var[2].val.p;
901
if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 15, 3, var)))
902
printf(" = %s\n", var[2].val.p);
906
DoMultipleInheritenceTest();
907
DoMultipleInheritenceTest2();
908
// Disabled by default - takes too much time on slow machines
914
/***************************************************************************/
915
/***************************************************************************/
916
/***************************************************************************/
918
// {491C65A0-3317-11d3-9885-006008962422}
920
{ 0x491c65a0, 0x3317, 0x11d3, \
921
{ 0x98, 0x85, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
923
// {491C65A1-3317-11d3-9885-006008962422}
925
{ 0x491c65a1, 0x3317, 0x11d3, \
926
{ 0x98, 0x85, 0x0, 0x60, 0x8, 0x96, 0x24, 0x22 } }
928
/***************************/
930
class nsIFoo : public nsISupports
933
NS_DEFINE_STATIC_IID_ACCESSOR(FOO_IID)
934
NS_IMETHOD FooMethod1(PRInt32 i) = 0;
935
NS_IMETHOD FooMethod2(PRInt32 i) = 0;
938
class nsIBar : public nsISupports
941
NS_DEFINE_STATIC_IID_ACCESSOR(BAR_IID)
942
NS_IMETHOD BarMethod1(PRInt32 i) = 0;
943
NS_IMETHOD BarMethod2(PRInt32 i) = 0;
946
/***************************/
948
class FooImpl : public nsIFoo
951
NS_IMETHOD FooMethod1(PRInt32 i);
952
NS_IMETHOD FooMethod2(PRInt32 i);
960
virtual const char* ImplName() = 0;
967
class BarImpl : public nsIBar
970
NS_IMETHOD BarMethod1(PRInt32 i);
971
NS_IMETHOD BarMethod2(PRInt32 i);
979
virtual const char * ImplName() = 0;
986
/***************************/
988
FooImpl::FooImpl() : Name("FooImpl")
992
NS_IMETHODIMP FooImpl::FooMethod1(PRInt32 i)
994
printf("\tFooImpl::FooMethod1 called with i == %d, %s part of a %s\n",
995
i, Name, ImplName());
999
NS_IMETHODIMP FooImpl::FooMethod2(PRInt32 i)
1001
printf("\tFooImpl::FooMethod2 called with i == %d, %s part of a %s\n",
1002
i, Name, ImplName());
1006
/***************************/
1008
BarImpl::BarImpl() : Name("BarImpl")
1012
NS_IMETHODIMP BarImpl::BarMethod1(PRInt32 i)
1014
printf("\tBarImpl::BarMethod1 called with i == %d, %s part of a %s\n",
1015
i, Name, ImplName());
1019
NS_IMETHODIMP BarImpl::BarMethod2(PRInt32 i)
1021
printf("\tBarImpl::BarMethod2 called with i == %d, %s part of a %s\n",
1022
i, Name, ImplName());
1026
/***************************/
1028
class FooBarImpl : public FooImpl, public BarImpl
1033
const char* ImplName();
1044
FooBarImpl::FooBarImpl() : MyName("FooBarImpl")
1049
const char* FooBarImpl::ImplName()
1055
FooBarImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr)
1057
if (NULL == aInstancePtr) {
1058
return NS_ERROR_NULL_POINTER;
1061
*aInstancePtr = NULL;
1064
if (aIID.Equals(NS_GET_IID(nsIFoo))) {
1065
*aInstancePtr = (void*) NS_STATIC_CAST(nsIFoo*,this);
1069
if (aIID.Equals(NS_GET_IID(nsIBar))) {
1070
*aInstancePtr = (void*) NS_STATIC_CAST(nsIBar*,this);
1075
if (aIID.Equals(NS_GET_IID(nsISupports))) {
1076
*aInstancePtr = (void*) NS_STATIC_CAST(nsISupports*,
1077
NS_STATIC_CAST(nsIFoo*,this));
1081
return NS_NOINTERFACE;
1084
NS_IMPL_ADDREF(FooBarImpl)
1085
NS_IMPL_RELEASE(FooBarImpl)
1088
static void DoMultipleInheritenceTest()
1090
FooBarImpl* impl = new FooBarImpl();
1097
nsXPTCVariant var[1];
1100
if(NS_SUCCEEDED(impl->QueryInterface(NS_GET_IID(nsIFoo), (void**)&foo)) &&
1101
NS_SUCCEEDED(impl->QueryInterface(NS_GET_IID(nsIBar), (void**)&bar)))
1103
printf("impl == %p\n", impl);
1104
printf("foo == %p\n", foo);
1105
printf("bar == %p\n", bar);
1107
printf("Calling Foo...\n");
1108
printf("direct calls:\n");
1112
printf("invoke calls:\n");
1114
var[0].type = nsXPTType::T_I32;
1116
XPTC_InvokeByIndex(foo, 3, 1, var);
1119
var[0].type = nsXPTType::T_I32;
1121
XPTC_InvokeByIndex(foo, 4, 1, var);
1125
printf("Calling Bar...\n");
1126
printf("direct calls:\n");
1130
printf("invoke calls:\n");
1132
var[0].type = nsXPTType::T_I32;
1134
XPTC_InvokeByIndex(bar, 3, 1, var);
1137
var[0].type = nsXPTType::T_I32;
1139
XPTC_InvokeByIndex(bar, 4, 1, var);
1148
/***************************************************************************/
1149
/***************************************************************************/
1150
/***************************************************************************/
1151
/* This is a variation on the theme submitted by duncan@be.com (Duncan Wilcox).
1152
* He was seeing the other test work and this test not work. They should both
1153
* Work on any given platform
1156
class nsIFoo2 : public nsISupports
1159
NS_IMETHOD FooMethod1(PRInt32 i) = 0;
1160
NS_IMETHOD FooMethod2(PRInt32 i) = 0;
1163
class nsIBar2 : public nsISupports
1166
NS_IMETHOD BarMethod1(PRInt32 i) = 0;
1167
NS_IMETHOD BarMethod2(PRInt32 i) = 0;
1170
class FooBarImpl2 : public nsIFoo2, public nsIBar2
1174
NS_IMETHOD FooMethod1(PRInt32 i);
1175
NS_IMETHOD FooMethod2(PRInt32 i);
1178
NS_IMETHOD BarMethod1(PRInt32 i);
1179
NS_IMETHOD BarMethod2(PRInt32 i);
1192
FooBarImpl2::FooBarImpl2() : value(0x12345678)
1197
NS_IMETHODIMP FooBarImpl2::FooMethod1(PRInt32 i)
1199
printf("\tFooBarImpl2::FooMethod1 called with i == %d, local value = %x\n",
1204
NS_IMETHODIMP FooBarImpl2::FooMethod2(PRInt32 i)
1206
printf("\tFooBarImpl2::FooMethod2 called with i == %d, local value = %x\n",
1211
NS_IMETHODIMP FooBarImpl2::BarMethod1(PRInt32 i)
1213
printf("\tFooBarImpl2::BarMethod1 called with i == %d, local value = %x\n",
1218
NS_IMETHODIMP FooBarImpl2::BarMethod2(PRInt32 i)
1220
printf("\tFooBarImpl2::BarMethod2 called with i == %d, local value = %x\n",
1226
FooBarImpl2::QueryInterface(REFNSIID aIID, void** aInstancePtr)
1228
if (NULL == aInstancePtr) {
1229
return NS_ERROR_NULL_POINTER;
1232
*aInstancePtr = NULL;
1235
if (aIID.Equals(NS_GET_IID(nsIFoo))) {
1236
*aInstancePtr = (void*) NS_STATIC_CAST(nsIFoo2*,this);
1240
if (aIID.Equals(NS_GET_IID(nsIBar))) {
1241
*aInstancePtr = (void*) NS_STATIC_CAST(nsIBar2*,this);
1246
if (aIID.Equals(NS_GET_IID(nsISupports))) {
1247
*aInstancePtr = (void*) NS_STATIC_CAST(nsISupports*,
1248
NS_STATIC_CAST(nsIFoo2*,this));
1252
return NS_NOINTERFACE;
1255
NS_IMPL_ADDREF(FooBarImpl2)
1256
NS_IMPL_RELEASE(FooBarImpl2)
1258
static void DoMultipleInheritenceTest2()
1260
FooBarImpl2* impl = new FooBarImpl2();
1267
nsXPTCVariant var[1];
1270
if(NS_SUCCEEDED(impl->QueryInterface(NS_GET_IID(nsIFoo), (void**)&foo)) &&
1271
NS_SUCCEEDED(impl->QueryInterface(NS_GET_IID(nsIBar), (void**)&bar)))
1273
printf("impl == %p\n", impl);
1274
printf("foo == %p\n", foo);
1275
printf("bar == %p\n", bar);
1277
printf("Calling Foo...\n");
1278
printf("direct calls:\n");
1282
printf("invoke calls:\n");
1284
var[0].type = nsXPTType::T_I32;
1286
XPTC_InvokeByIndex(foo, 3, 1, var);
1289
var[0].type = nsXPTType::T_I32;
1291
XPTC_InvokeByIndex(foo, 4, 1, var);
1295
printf("Calling Bar...\n");
1296
printf("direct calls:\n");
1300
printf("invoke calls:\n");
1302
var[0].type = nsXPTType::T_I32;
1304
XPTC_InvokeByIndex(bar, 3, 1, var);
1307
var[0].type = nsXPTType::T_I32;
1309
XPTC_InvokeByIndex(bar, 4, 1, var);
1319
static void DoSpeedTest()
1321
InvokeTestTarget *test = new InvokeTestTarget();
1323
nsXPTCVariant var[3];
1326
var[0].type = nsXPTType::T_I32;
1330
var[1].type = nsXPTType::T_I32;
1334
var[2].type = nsXPTType::T_I32;
1335
var[2].flags = nsXPTCVariant::PTR_IS_DATA;
1336
var[2].ptr = &var[2].val.i32;
1342
// Crank this number down if your platform is slow :)
1343
static const int count = 100000000;
1345
PRIntervalTime start;
1346
PRIntervalTime interval_direct;
1347
PRIntervalTime interval_invoke;
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;
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;
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);