Changeset 86423 in vbox
- Timestamp:
- Oct 2, 2020 1:03:48 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/xpcom/reflect/xptcall/tests/TestXPTCInvoke.cpp
r86422 r86423 48 48 49 49 // forward declration 50 static void DoMultipleInheritenceTest();51 static void DoMultipleInheritenceTest2();50 static int DoMultipleInheritenceTest(int rcExit); 51 static int DoMultipleInheritenceTest2(int rcExit); 52 52 static void DoSpeedTest(); 53 54 55 #include <iprt/string.h> 56 57 static char g_szDirect[16384]; 58 static char g_szInvoke[16384]; 59 static char *g_pszBuffer = NULL; 60 static 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 80 static void setbuffer(bool fDirect) 81 { 82 g_pszBuffer = fDirect ? g_szDirect : g_szInvoke; 83 *g_pszBuffer = '\0'; 84 } 85 86 static 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 53 122 54 123 // {AAC1FB90-E099-11d2-984E-006008962422} … … 312 381 PRInt64 out64; 313 382 printf("calling direct:\n"); 383 setbuffer(true); 314 384 if(NS_SUCCEEDED(test->AddTwoInts(1,1,&out))) 315 printf("\t1 + 1 = %d\n", out);316 else 317 printf("\tFAILED");385 bufprintf("\t1 + 1 = %d\n", out); 386 else 387 bufprintf("\tFAILED"); 318 388 PRInt64 one, two; 319 389 LL_I2L(one, 1); … … 322 392 { 323 393 LL_L2I(tmp32, out64); 324 printf("\t1L + 1L = %d\n", (int)tmp32);394 bufprintf("\t1L + 1L = %d\n", (int)tmp32); 325 395 } 326 396 else 327 printf("\tFAILED");397 bufprintf("\tFAILED"); 328 398 if(NS_SUCCEEDED(test->MultTwoInts(2,2,&out))) 329 printf("\t2 * 2 = %d\n", out);330 else 331 printf("\tFAILED");399 bufprintf("\t2 * 2 = %d\n", out); 400 else 401 bufprintf("\tFAILED"); 332 402 if(NS_SUCCEEDED(test->MultTwoLLs(two,two,&out64))) 333 403 { 334 404 LL_L2I(tmp32, out64); 335 printf("\t2L * 2L = %d\n", (int)tmp32);405 bufprintf("\t2L * 2L = %d\n", (int)tmp32); 336 406 } 337 407 else 338 printf("\tFAILED");408 bufprintf("\tFAILED"); 339 409 340 410 double outD; … … 344 414 345 415 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");416 bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n", outI); 417 else 418 bufprintf("\tFAILED"); 349 419 350 420 if(NS_SUCCEEDED(test->AddTwoFloats(1,2,&outF))) 351 printf("\t1 + 2 = %ff\n", (double)outF);352 else 353 printf("\tFAILED");421 bufprintf("\t1 + 2 = %ff\n", (double)outF); 422 else 423 bufprintf("\tFAILED"); 354 424 355 425 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");426 bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %f\n", outD); 427 else 428 bufprintf("\tFAILED"); 359 429 360 430 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");431 bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %ff\n", (double)outF); 432 else 433 bufprintf("\tFAILED"); 364 434 365 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))) 366 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 +115 + 16 + 17 + 18 + 19 + 20 = %ff\n", (double)outF);367 else 368 printf("\tFAILED");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"); 369 439 370 440 if(NS_SUCCEEDED(test->AddMixedInts(1,2,3,4,5,6,7,8,9,10,&out64))) 371 441 { 372 442 LL_L2I(tmp32, out64); 373 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n", (int)tmp32);443 bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n", (int)tmp32); 374 444 } 375 445 else 376 printf("\tFAILED");446 bufprintf("\tFAILED"); 377 447 378 448 if(NS_SUCCEEDED(test->AddMixedInts2(1,2,3,4,5,6,7,8,9,10,&out64))) 379 449 { 380 450 LL_L2I(tmp32, out64); 381 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n", (int)tmp32);451 bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n", (int)tmp32); 382 452 } 383 453 else 384 printf("\tFAILED");454 bufprintf("\tFAILED"); 385 455 386 456 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);457 bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 = %f\n", (double)outD); 388 458 else 389 printf("\tFAILED");459 bufprintf("\tFAILED"); 390 460 391 461 if (NS_SUCCEEDED(test->PassTwoStrings("moo","cow",&outS))) { 392 printf(" = %s\n", outS);462 bufprintf(" = %s\n", outS); 393 463 nsMemory::Free(outS); 394 464 } else 395 printf("\tFAILED");465 bufprintf("\tFAILED"); 396 466 397 467 printf("calling via invoke:\n"); 468 setbuffer(false); 398 469 399 470 nsXPTCVariant var[21]; … … 413 484 414 485 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 3, 3, var))) 415 printf("\t1 + 1 = %d\n", var[2].val.i32);416 else 417 printf("\tFAILED");486 bufprintf("\t1 + 1 = %d\n", var[2].val.i32); 487 else 488 bufprintf("\tFAILED"); 418 489 419 490 LL_I2L(var[0].val.i64, 1); … … 431 502 432 503 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");504 bufprintf("\t1L + 1L = %d\n", (int)var[2].val.i64); 505 else 506 bufprintf("\tFAILED"); 436 507 437 508 var[0].val.i32 = 2; … … 449 520 450 521 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 4, 3, var))) 451 printf("\t2 * 2 = %d\n", var[2].val.i32);452 else 453 printf("\tFAILED");522 bufprintf("\t2 * 2 = %d\n", var[2].val.i32); 523 else 524 bufprintf("\tFAILED"); 454 525 455 526 LL_I2L(var[0].val.i64,2); … … 467 538 468 539 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");540 bufprintf("\t2L * 2L = %d\n", (int)var[2].val.i64); 541 else 542 bufprintf("\tFAILED"); 472 543 473 544 var[0].val.i32 = 1; … … 517 588 518 589 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 7, 11, var))) 519 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n",590 bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n", 520 591 var[10].val.i32); 521 592 … … 534 605 535 606 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 8, 3, var))) 536 printf("\t1 + 2 = %ff\n",607 bufprintf("\t1 + 2 = %ff\n", 537 608 (double) var[2].val.f); 538 609 … … 584 655 585 656 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 9, 11, var))) 586 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %f\n",657 bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %f\n", 587 658 var[10].val.d); 588 659 else 589 printf("\tFAILED");660 bufprintf("\tFAILED"); 590 661 591 662 var[0].val.f = 1.0f; … … 635 706 636 707 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 10, 11, var))) 637 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %ff\n",708 bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %ff\n", 638 709 (double) var[10].val.f); 639 710 else 640 printf("\tFAILED");711 bufprintf("\tFAILED"); 641 712 642 713 var[0].val.f = 1.0f; … … 726 797 727 798 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",799 bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 = %ff\n", 729 800 (double) var[20].val.f); 730 801 … … 775 846 776 847 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 12, 11, var))) 777 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n",848 bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n", 778 849 (int)var[10].val.i64); 779 850 else 780 printf("\tFAILED");851 bufprintf("\tFAILED"); 781 852 782 853 var[0].val.i32 = 1; … … 826 897 827 898 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 13, 11, var))) 828 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n",899 bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n", 829 900 (int)var[10].val.i64); 830 901 else 831 printf("\tFAILED");902 bufprintf("\tFAILED"); 832 903 833 904 var[0].val.f = 1.0f; … … 881 952 882 953 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 14, 12, var))) 883 printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 = %f\n",954 bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 = %f\n", 884 955 var[11].val.d); 885 956 else 886 printf("\tFAILED");957 bufprintf("\tFAILED"); 887 958 888 959 var[0].val.p = (void*)"moo"; … … 901 972 if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 15, 3, var))) 902 973 { 903 printf(" = %s\n", var[2].val.p);974 bufprintf(" = %s\n", var[2].val.p); 904 975 nsMemory::Free(var[2].val.p); 905 976 } 906 977 else 907 printf("\tFAILED"); 908 909 DoMultipleInheritenceTest(); 910 DoMultipleInheritenceTest2(); 978 bufprintf("\tFAILED"); 979 int rcExit = comparebuffers(0); 980 981 rcExit = DoMultipleInheritenceTest(rcExit); 982 rcExit = DoMultipleInheritenceTest2(rcExit); 911 983 // Disabled by default - takes too much time on slow machines 912 984 //DoSpeedTest(); … … 914 986 NS_RELEASE(test); 915 987 916 return 0;988 return rcExit; 917 989 } 918 990 … … 997 1069 NS_IMETHODIMP FooImpl::FooMethod1(PRInt32 i) 998 1070 { 999 printf("\tFooImpl::FooMethod1 called with i == %d, %s part of a %s\n",1071 bufprintf("\tFooImpl::FooMethod1 called with i == %d, %s part of a %s\n", 1000 1072 i, Name, ImplName()); 1001 1073 return NS_OK; … … 1004 1076 NS_IMETHODIMP FooImpl::FooMethod2(PRInt32 i) 1005 1077 { 1006 printf("\tFooImpl::FooMethod2 called with i == %d, %s part of a %s\n",1078 bufprintf("\tFooImpl::FooMethod2 called with i == %d, %s part of a %s\n", 1007 1079 i, Name, ImplName()); 1008 1080 return NS_OK; … … 1017 1089 NS_IMETHODIMP BarImpl::BarMethod1(PRInt32 i) 1018 1090 { 1019 printf("\tBarImpl::BarMethod1 called with i == %d, %s part of a %s\n",1091 bufprintf("\tBarImpl::BarMethod1 called with i == %d, %s part of a %s\n", 1020 1092 i, Name, ImplName()); 1021 1093 return NS_OK; … … 1024 1096 NS_IMETHODIMP BarImpl::BarMethod2(PRInt32 i) 1025 1097 { 1026 printf("\tBarImpl::BarMethod2 called with i == %d, %s part of a %s\n",1098 bufprintf("\tBarImpl::BarMethod2 called with i == %d, %s part of a %s\n", 1027 1099 i, Name, ImplName()); 1028 1100 return NS_OK; … … 1091 1163 1092 1164 1093 static void DoMultipleInheritenceTest()1165 static int DoMultipleInheritenceTest(int rcExit) 1094 1166 { 1095 1167 FooBarImpl* impl = new FooBarImpl(); 1096 1168 if(!impl) 1097 return ;1169 return 1; 1098 1170 1099 1171 nsIFoo* foo; … … 1112 1184 printf("Calling Foo...\n"); 1113 1185 printf("direct calls:\n"); 1186 setbuffer(true); 1114 1187 foo->FooMethod1(1); 1115 1188 foo->FooMethod2(2); 1116 1189 1117 1190 printf("invoke calls:\n"); 1191 setbuffer(false); 1118 1192 var[0].val.i32 = 1; 1119 1193 var[0].type = nsXPTType::T_I32; … … 1126 1200 XPTC_InvokeByIndex(foo, 4, 1, var); 1127 1201 1202 rcExit = comparebuffers(rcExit); 1128 1203 printf("\n"); 1129 1204 1130 1205 printf("Calling Bar...\n"); 1131 1206 printf("direct calls:\n"); 1207 setbuffer(true); 1132 1208 bar->BarMethod1(1); 1133 1209 bar->BarMethod2(2); 1134 1210 1135 1211 printf("invoke calls:\n"); 1212 setbuffer(false); 1136 1213 var[0].val.i32 = 1; 1137 1214 var[0].type = nsXPTType::T_I32; … … 1144 1221 XPTC_InvokeByIndex(bar, 4, 1, var); 1145 1222 1223 rcExit = comparebuffers(rcExit); 1146 1224 printf("\n"); 1147 1225 … … 1149 1227 NS_RELEASE(bar); 1150 1228 } 1229 else 1230 rcExit = 1; 1151 1231 NS_RELEASE(impl); 1232 return rcExit; 1152 1233 } 1153 1234 /***************************************************************************/ … … 1202 1283 NS_IMETHODIMP FooBarImpl2::FooMethod1(PRInt32 i) 1203 1284 { 1204 printf("\tFooBarImpl2::FooMethod1 called with i == %d, local value = %x\n",1285 bufprintf("\tFooBarImpl2::FooMethod1 called with i == %d, local value = %x\n", 1205 1286 i, value); 1206 1287 return NS_OK; … … 1209 1290 NS_IMETHODIMP FooBarImpl2::FooMethod2(PRInt32 i) 1210 1291 { 1211 printf("\tFooBarImpl2::FooMethod2 called with i == %d, local value = %x\n",1292 bufprintf("\tFooBarImpl2::FooMethod2 called with i == %d, local value = %x\n", 1212 1293 i, value); 1213 1294 return NS_OK; … … 1216 1297 NS_IMETHODIMP FooBarImpl2::BarMethod1(PRInt32 i) 1217 1298 { 1218 printf("\tFooBarImpl2::BarMethod1 called with i == %d, local value = %x\n",1299 bufprintf("\tFooBarImpl2::BarMethod1 called with i == %d, local value = %x\n", 1219 1300 i, value); 1220 1301 return NS_OK; … … 1223 1304 NS_IMETHODIMP FooBarImpl2::BarMethod2(PRInt32 i) 1224 1305 { 1225 printf("\tFooBarImpl2::BarMethod2 called with i == %d, local value = %x\n",1306 bufprintf("\tFooBarImpl2::BarMethod2 called with i == %d, local value = %x\n", 1226 1307 i, value); 1227 1308 return NS_OK; … … 1261 1342 NS_IMPL_RELEASE(FooBarImpl2) 1262 1343 1263 static void DoMultipleInheritenceTest2()1344 static int DoMultipleInheritenceTest2(int rcExit) 1264 1345 { 1265 1346 FooBarImpl2* impl = new FooBarImpl2(); 1266 1347 if(!impl) 1267 return ;1348 return 1; 1268 1349 1269 1350 nsIFoo2* foo; … … 1282 1363 printf("Calling Foo...\n"); 1283 1364 printf("direct calls:\n"); 1365 setbuffer(true); 1284 1366 foo->FooMethod1(1); 1285 1367 foo->FooMethod2(2); 1286 1368 1287 1369 printf("invoke calls:\n"); 1370 setbuffer(false); 1288 1371 var[0].val.i32 = 1; 1289 1372 var[0].type = nsXPTType::T_I32; … … 1296 1379 XPTC_InvokeByIndex(foo, 4, 1, var); 1297 1380 1381 rcExit = comparebuffers(rcExit); 1298 1382 printf("\n"); 1299 1383 1300 1384 printf("Calling Bar...\n"); 1301 1385 printf("direct calls:\n"); 1386 setbuffer(true); 1302 1387 bar->BarMethod1(1); 1303 1388 bar->BarMethod2(2); 1304 1389 1305 1390 printf("invoke calls:\n"); 1391 setbuffer(false); 1306 1392 var[0].val.i32 = 1; 1307 1393 var[0].type = nsXPTType::T_I32; … … 1314 1400 XPTC_InvokeByIndex(bar, 4, 1, var); 1315 1401 1402 rcExit = comparebuffers(rcExit); 1316 1403 printf("\n"); 1317 1404 … … 1319 1406 NS_RELEASE(bar); 1320 1407 } 1408 else 1409 rcExit = 1; 1321 1410 NS_RELEASE(impl); 1411 return rcExit; 1322 1412 } 1323 1413
Note:
See TracChangeset
for help on using the changeset viewer.