Index: trunk/src/libs/xpcom18a4/xpcom/reflect/xptcall/tests/TestXPTCInvoke.cpp
===================================================================
--- trunk/src/libs/xpcom18a4/xpcom/reflect/xptcall/tests/TestXPTCInvoke.cpp	(revision 86422)
+++ trunk/src/libs/xpcom18a4/xpcom/reflect/xptcall/tests/TestXPTCInvoke.cpp	(revision 86423)
@@ -48,7 +48,76 @@
 
 // forward declration
-static void DoMultipleInheritenceTest();
-static void DoMultipleInheritenceTest2();
+static int DoMultipleInheritenceTest(int rcExit);
+static int DoMultipleInheritenceTest2(int rcExit);
 static void DoSpeedTest();
+
+
+#include <iprt/string.h>
+
+static char  g_szDirect[16384];
+static char  g_szInvoke[16384];
+static char *g_pszBuffer = NULL;
+static void bufprintf(const char *pszFormat, ...)
+{
+    va_list va;
+    va_start(va, pszFormat);
+    vprintf(pszFormat, va);
+    va_end(va);
+    if (g_pszBuffer)
+    {
+        size_t  cchBuf = strlen(g_pszBuffer);
+        ssize_t cbLeft = (ssize_t)sizeof(g_szDirect) - (ssize_t)cchBuf;
+        if (cbLeft > 0)
+        {
+            va_list va;
+            va_start(va, pszFormat);
+            vsnprintf(&g_pszBuffer[cchBuf], (size_t)cbLeft, pszFormat, va);
+            va_end(va);
+        }
+    }
+}
+
+static void setbuffer(bool fDirect)
+{
+    g_pszBuffer = fDirect ? g_szDirect : g_szInvoke;
+    *g_pszBuffer = '\0';
+}
+
+static int comparebuffers(int rcExit)
+{
+    if (strcmp(g_szDirect, g_szInvoke) == 0)
+        return rcExit;
+    size_t offLine = 0;
+    unsigned iLine   = 1;
+    for (size_t off = 0; ; off++)
+    {
+        char chDirect = g_szDirect[off];
+        char chInvoke = g_szInvoke[off];
+        if (chDirect == chInvoke)
+        {
+            if (!chDirect)
+                return rcExit;
+            if (chDirect == '\n')
+            {
+                offLine = off + 1;
+                iLine++;
+            }
+        }
+        else
+        {
+            size_t cchDirectLine = RTStrOffCharOrTerm(&g_szDirect[offLine], '\n');
+            size_t cchInvokeLine = RTStrOffCharOrTerm(&g_szInvoke[offLine], '\n');
+            printf("direct and invoke runs differs on line %u!\n", iLine);
+            printf("direct: %*.*s\n", (int)cchDirectLine, (int)cchDirectLine, &g_szDirect[offLine]);
+            printf("invoke: %*.*s\n", (int)cchInvokeLine, (int)cchInvokeLine, &g_szInvoke[offLine]);
+
+            return 1;
+        }
+
+    }
+    printf("direct and invoke runs differs!\n");
+    return 1;
+}
+
 
 // {AAC1FB90-E099-11d2-984E-006008962422}
@@ -312,8 +381,9 @@
     PRInt64 out64;
     printf("calling direct:\n");
+    setbuffer(true);
     if(NS_SUCCEEDED(test->AddTwoInts(1,1,&out)))
-        printf("\t1 + 1 = %d\n", out);
-    else
-        printf("\tFAILED");
+        bufprintf("\t1 + 1 = %d\n", out);
+    else
+        bufprintf("\tFAILED");
     PRInt64 one, two;
     LL_I2L(one, 1);
@@ -322,19 +392,19 @@
     {
         LL_L2I(tmp32, out64);
-        printf("\t1L + 1L = %d\n", (int)tmp32);
+        bufprintf("\t1L + 1L = %d\n", (int)tmp32);
     }
     else
-        printf("\tFAILED");
+        bufprintf("\tFAILED");
     if(NS_SUCCEEDED(test->MultTwoInts(2,2,&out)))
-        printf("\t2 * 2 = %d\n", out);
-    else
-        printf("\tFAILED");
+        bufprintf("\t2 * 2 = %d\n", out);
+    else
+        bufprintf("\tFAILED");
     if(NS_SUCCEEDED(test->MultTwoLLs(two,two,&out64)))
     {
         LL_L2I(tmp32, out64);
-        printf("\t2L * 2L = %d\n", (int)tmp32);
+        bufprintf("\t2L * 2L = %d\n", (int)tmp32);
     }
     else
-        printf("\tFAILED");
+        bufprintf("\tFAILED");
 
     double outD;
@@ -344,56 +414,57 @@
 
     if(NS_SUCCEEDED(test->AddManyInts(1,2,3,4,5,6,7,8,9,10,&outI)))
-        printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n", outI);
-    else
-        printf("\tFAILED");
+        bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n", outI);
+    else
+        bufprintf("\tFAILED");
 
     if(NS_SUCCEEDED(test->AddTwoFloats(1,2,&outF)))
-        printf("\t1 + 2 = %ff\n", (double)outF);
-    else
-        printf("\tFAILED");
+        bufprintf("\t1 + 2 = %ff\n", (double)outF);
+    else
+        bufprintf("\tFAILED");
 
     if(NS_SUCCEEDED(test->AddManyDoubles(1,2,3,4,5,6,7,8,9,10,&outD)))
-        printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %f\n", outD);
-    else
-        printf("\tFAILED");
+        bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %f\n", outD);
+    else
+        bufprintf("\tFAILED");
 
     if(NS_SUCCEEDED(test->AddManyFloats(1,2,3,4,5,6,7,8,9,10,&outF)))
-        printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %ff\n", (double)outF);
-    else
-        printf("\tFAILED");
+        bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %ff\n", (double)outF);
+    else
+        bufprintf("\tFAILED");
 
     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)))
-        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);
-    else
-        printf("\tFAILED");
+        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);
+    else
+        bufprintf("\tFAILED");
 
     if(NS_SUCCEEDED(test->AddMixedInts(1,2,3,4,5,6,7,8,9,10,&out64)))
      {
          LL_L2I(tmp32, out64);
-         printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n", (int)tmp32);
+         bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n", (int)tmp32);
      }
      else
-         printf("\tFAILED");
+         bufprintf("\tFAILED");
  
      if(NS_SUCCEEDED(test->AddMixedInts2(1,2,3,4,5,6,7,8,9,10,&out64)))
      {
           LL_L2I(tmp32, out64);
-         printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n", (int)tmp32);
+         bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n", (int)tmp32);
      }
      else
-         printf("\tFAILED");
+         bufprintf("\tFAILED");
 
      if(NS_SUCCEEDED(test->AddMixedFloats(1,2,3,4,5,6,7,8,9,10,11,&outD)))
-         printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 = %f\n", (double)outD);
+         bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 = %f\n", (double)outD);
      else
-         printf("\tFAILED");
+         bufprintf("\tFAILED");
 
      if (NS_SUCCEEDED(test->PassTwoStrings("moo","cow",&outS))) {
-       printf(" = %s\n", outS);
+       bufprintf(" = %s\n", outS);
         nsMemory::Free(outS);
       } else
-        printf("\tFAILED");
+        bufprintf("\tFAILED");
 
     printf("calling via invoke:\n");
+    setbuffer(false);
 
     nsXPTCVariant var[21];
@@ -413,7 +484,7 @@
 
     if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 3, 3, var)))
-        printf("\t1 + 1 = %d\n", var[2].val.i32);
-    else
-        printf("\tFAILED");
+        bufprintf("\t1 + 1 = %d\n", var[2].val.i32);
+    else
+        bufprintf("\tFAILED");
 
     LL_I2L(var[0].val.i64, 1);
@@ -431,7 +502,7 @@
 
     if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 5, 3, var)))
-        printf("\t1L + 1L = %d\n", (int)var[2].val.i64);
-    else
-        printf("\tFAILED");
+        bufprintf("\t1L + 1L = %d\n", (int)var[2].val.i64);
+    else
+        bufprintf("\tFAILED");
 
     var[0].val.i32 = 2;
@@ -449,7 +520,7 @@
 
     if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 4, 3, var)))
-        printf("\t2 * 2 = %d\n", var[2].val.i32);
-    else
-        printf("\tFAILED");
+        bufprintf("\t2 * 2 = %d\n", var[2].val.i32);
+    else
+        bufprintf("\tFAILED");
 
     LL_I2L(var[0].val.i64,2);
@@ -467,7 +538,7 @@
 
     if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 6, 3, var)))
-        printf("\t2L * 2L = %d\n", (int)var[2].val.i64);
-    else
-        printf("\tFAILED");
+        bufprintf("\t2L * 2L = %d\n", (int)var[2].val.i64);
+    else
+        bufprintf("\tFAILED");
 
     var[0].val.i32 = 1;
@@ -517,5 +588,5 @@
 
     if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 7, 11, var)))
-        printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n",
+        bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n",
                 var[10].val.i32);
 
@@ -534,5 +605,5 @@
 
     if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 8, 3, var)))
-        printf("\t1 + 2 = %ff\n",
+        bufprintf("\t1 + 2 = %ff\n",
                 (double) var[2].val.f);
 
@@ -584,8 +655,8 @@
 
     if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 9, 11, var)))
-        printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %f\n",
+        bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %f\n",
                 var[10].val.d);
     else
-        printf("\tFAILED");
+        bufprintf("\tFAILED");
 
     var[0].val.f = 1.0f;
@@ -635,8 +706,8 @@
 
     if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 10, 11, var)))
-        printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %ff\n",
+        bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %ff\n",
                 (double) var[10].val.f);
     else
-        printf("\tFAILED");
+        bufprintf("\tFAILED");
 
     var[0].val.f = 1.0f;
@@ -726,5 +797,5 @@
 
     if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 11, 21, var)))
-        printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 = %ff\n",
+        bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 = %ff\n",
                 (double) var[20].val.f);
 
@@ -775,8 +846,8 @@
 
     if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 12, 11, var)))
-        printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n",
+        bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n",
 	       (int)var[10].val.i64);
     else
-        printf("\tFAILED");
+        bufprintf("\tFAILED");
 
     var[0].val.i32 = 1;
@@ -826,8 +897,8 @@
 
     if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 13, 11, var)))
-        printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n",
+        bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = %d\n",
 	       (int)var[10].val.i64);
     else
-        printf("\tFAILED");
+        bufprintf("\tFAILED");
 
     var[0].val.f = 1.0f;
@@ -881,8 +952,8 @@
 
     if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 14, 12, var)))
-        printf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 = %f\n",
+        bufprintf("\t1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 = %f\n",
                 var[11].val.d);
     else
-        printf("\tFAILED");
+        bufprintf("\tFAILED");
 
     var[0].val.p = (void*)"moo";
@@ -901,12 +972,13 @@
     if(NS_SUCCEEDED(XPTC_InvokeByIndex(test, 15, 3, var)))
     {
-        printf(" = %s\n", var[2].val.p);
+        bufprintf(" = %s\n", var[2].val.p);
         nsMemory::Free(var[2].val.p);
     }
     else
-        printf("\tFAILED");
-
-    DoMultipleInheritenceTest();
-    DoMultipleInheritenceTest2();
+        bufprintf("\tFAILED");
+    int rcExit = comparebuffers(0);
+
+    rcExit = DoMultipleInheritenceTest(rcExit);
+    rcExit = DoMultipleInheritenceTest2(rcExit);
     // Disabled by default - takes too much time on slow machines
     //DoSpeedTest();
@@ -914,5 +986,5 @@
     NS_RELEASE(test);
 
-    return 0;
+    return rcExit;
 }
 
@@ -997,5 +1069,5 @@
 NS_IMETHODIMP FooImpl::FooMethod1(PRInt32 i)
 {
-    printf("\tFooImpl::FooMethod1 called with i == %d, %s part of a %s\n", 
+    bufprintf("\tFooImpl::FooMethod1 called with i == %d, %s part of a %s\n",
            i, Name, ImplName());
     return NS_OK;
@@ -1004,5 +1076,5 @@
 NS_IMETHODIMP FooImpl::FooMethod2(PRInt32 i)
 {
-    printf("\tFooImpl::FooMethod2 called with i == %d, %s part of a %s\n", 
+    bufprintf("\tFooImpl::FooMethod2 called with i == %d, %s part of a %s\n",
            i, Name, ImplName());
     return NS_OK;
@@ -1017,5 +1089,5 @@
 NS_IMETHODIMP BarImpl::BarMethod1(PRInt32 i)
 {
-    printf("\tBarImpl::BarMethod1 called with i == %d, %s part of a %s\n", 
+    bufprintf("\tBarImpl::BarMethod1 called with i == %d, %s part of a %s\n",
            i, Name, ImplName());
     return NS_OK;
@@ -1024,5 +1096,5 @@
 NS_IMETHODIMP BarImpl::BarMethod2(PRInt32 i)
 {
-    printf("\tBarImpl::BarMethod2 called with i == %d, %s part of a %s\n", 
+    bufprintf("\tBarImpl::BarMethod2 called with i == %d, %s part of a %s\n",
            i, Name, ImplName());
     return NS_OK;
@@ -1091,9 +1163,9 @@
 
 
-static void DoMultipleInheritenceTest()
+static int DoMultipleInheritenceTest(int rcExit)
 {
     FooBarImpl* impl = new FooBarImpl();
     if(!impl)
-        return;
+        return 1;
 
     nsIFoo* foo;
@@ -1112,8 +1184,10 @@
         printf("Calling Foo...\n");
         printf("direct calls:\n");
+        setbuffer(true);
         foo->FooMethod1(1);
         foo->FooMethod2(2);
 
         printf("invoke calls:\n");
+        setbuffer(false);
         var[0].val.i32 = 1;
         var[0].type = nsXPTType::T_I32;
@@ -1126,12 +1200,15 @@
         XPTC_InvokeByIndex(foo, 4, 1, var);
 
+        rcExit = comparebuffers(rcExit);
         printf("\n");
 
         printf("Calling Bar...\n");
         printf("direct calls:\n");
+        setbuffer(true);
         bar->BarMethod1(1);
         bar->BarMethod2(2);
 
         printf("invoke calls:\n");
+        setbuffer(false);
         var[0].val.i32 = 1;
         var[0].type = nsXPTType::T_I32;
@@ -1144,4 +1221,5 @@
         XPTC_InvokeByIndex(bar, 4, 1, var);
 
+        rcExit = comparebuffers(rcExit);
         printf("\n");
 
@@ -1149,5 +1227,8 @@
         NS_RELEASE(bar);
     }
+    else
+        rcExit = 1;
     NS_RELEASE(impl);
+    return rcExit;
 }
 /***************************************************************************/
@@ -1202,5 +1283,5 @@
 NS_IMETHODIMP FooBarImpl2::FooMethod1(PRInt32 i)
 {
-    printf("\tFooBarImpl2::FooMethod1 called with i == %d, local value = %x\n", 
+    bufprintf("\tFooBarImpl2::FooMethod1 called with i == %d, local value = %x\n",
            i, value);
     return NS_OK;
@@ -1209,5 +1290,5 @@
 NS_IMETHODIMP FooBarImpl2::FooMethod2(PRInt32 i)
 {
-    printf("\tFooBarImpl2::FooMethod2 called with i == %d, local value = %x\n", 
+    bufprintf("\tFooBarImpl2::FooMethod2 called with i == %d, local value = %x\n",
            i, value);
     return NS_OK;
@@ -1216,5 +1297,5 @@
 NS_IMETHODIMP FooBarImpl2::BarMethod1(PRInt32 i)
 {
-    printf("\tFooBarImpl2::BarMethod1 called with i == %d, local value = %x\n", 
+    bufprintf("\tFooBarImpl2::BarMethod1 called with i == %d, local value = %x\n",
            i, value);
     return NS_OK;
@@ -1223,5 +1304,5 @@
 NS_IMETHODIMP FooBarImpl2::BarMethod2(PRInt32 i)
 {
-    printf("\tFooBarImpl2::BarMethod2 called with i == %d, local value = %x\n", 
+    bufprintf("\tFooBarImpl2::BarMethod2 called with i == %d, local value = %x\n",
            i, value);
     return NS_OK;
@@ -1261,9 +1342,9 @@
 NS_IMPL_RELEASE(FooBarImpl2)
 
-static void DoMultipleInheritenceTest2()
+static int DoMultipleInheritenceTest2(int rcExit)
 {
     FooBarImpl2* impl = new FooBarImpl2();
     if(!impl)
-        return;
+        return 1;
 
     nsIFoo2* foo;
@@ -1282,8 +1363,10 @@
         printf("Calling Foo...\n");
         printf("direct calls:\n");
+        setbuffer(true);
         foo->FooMethod1(1);
         foo->FooMethod2(2);
 
         printf("invoke calls:\n");
+        setbuffer(false);
         var[0].val.i32 = 1;
         var[0].type = nsXPTType::T_I32;
@@ -1296,12 +1379,15 @@
         XPTC_InvokeByIndex(foo, 4, 1, var);
 
+        rcExit = comparebuffers(rcExit);
         printf("\n");
 
         printf("Calling Bar...\n");
         printf("direct calls:\n");
+        setbuffer(true);
         bar->BarMethod1(1);
         bar->BarMethod2(2);
 
         printf("invoke calls:\n");
+        setbuffer(false);
         var[0].val.i32 = 1;
         var[0].type = nsXPTType::T_I32;
@@ -1314,4 +1400,5 @@
         XPTC_InvokeByIndex(bar, 4, 1, var);
 
+        rcExit = comparebuffers(rcExit);
         printf("\n");
 
@@ -1319,5 +1406,8 @@
         NS_RELEASE(bar);
     }
+    else
+        rcExit = 1;
     NS_RELEASE(impl);
+    return rcExit;
 }
 
