Index: /trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp
===================================================================
--- /trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp	(revision 22189)
+++ /trunk/src/VBox/GuestHost/SharedClipboard/x11-clipboard.cpp	(revision 22190)
@@ -1663,9 +1663,7 @@
  * rewrite the tests and the code to make them cleaner and more readable. */
 
-#include <iprt/initterm.h>
-#include <iprt/stream.h>
+#include <iprt/test.h>
 #include <poll.h>
 
-#define TEST_NAME "tstClipboardX11"
 #define TEST_WIDGET (Widget)0xffff
 
@@ -2128,11 +2126,12 @@
 #endif
 
-static bool testStringFromX11(CLIPBACKEND *pCtx, const char *pcszExp,
-                              int rcExp)
-{
-    bool retval = false;
+static void testStringFromX11(RTTEST hTest, CLIPBACKEND *pCtx,
+                              const char *pcszExp, int rcExp, size_t cbExpIn)
+{
+    bool retval = true;
     clipSendTargetUpdate(pCtx);
     if (clipQueryFormats() != VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
-        RTPrintf("Wrong targets reported: %02X\n", clipQueryFormats());
+        RTTestFailed(hTest, "Wrong targets reported: %02X\n",
+                     clipQueryFormats());
     else
     {
@@ -2145,9 +2144,9 @@
         clipGetCompletedRequest(&rc, &pc, &cbActual, &pReqRet);
         if (rc != rcExp)
-            RTPrintf("Wrong return code, expected %Rrc, got %Rrc\n", rcExp,
-                     rc);
+            RTTestFailed(hTest, "Wrong return code, expected %Rrc, got %Rrc\n",
+                         rcExp, rc);
         else if (pReqRet != pReq)
-            RTPrintf("Wrong returned request data, expected %p, got %p\n",
-                     pReq, pReqRet);
+            RTTestFailed(hTest, "Wrong returned request data, expected %p, got %p\n",
+                         pReq, pReqRet);
         else if (RT_FAILURE(rcExp))
             retval = true;
@@ -2159,5 +2158,5 @@
             rc = RTStrToUtf16Ex(pcszExp, RTSTR_MAX, &pwcExp,
                                 RT_ELEMENTS(wcExp), &cwc);
-            size_t cbExp = cwc * 2 + 2;
+            size_t cbExp = cbExpIn ? cbExpIn : cwc * 2 + 2;
             AssertRC(rc);
             if (RT_SUCCESS(rc))
@@ -2165,8 +2164,7 @@
                 if (cbActual != cbExp)
                 {
-                    RTPrintf("Returned string is the wrong size, string \"%.*ls\", size %u\n",
-                             RT_MIN(MAX_BUF_SIZE, cbActual), pc, cbActual);
-                    RTPrintf("Expected \"%s\", size %u\n", pcszExp,
-                             cbExp);
+                    RTTestFailed(hTest, "Returned string is the wrong size, string \"%.*ls\", size %u, expected \"%s\", size %u\n",
+                                 RT_MIN(MAX_BUF_SIZE, cbActual), pc, cbActual,
+                                 pcszExp, cbExp);
                 }
                 else
@@ -2175,6 +2173,6 @@
                         retval = true;
                     else
-                        RTPrintf("Returned string \"%.*ls\" does not match expected string \"%s\"\n",
-                                 MAX_BUF_SIZE, pc, pcszExp);
+                        RTTestFailed(hTest, "Returned string \"%.*ls\" does not match expected string \"%s\"\n",
+                                     MAX_BUF_SIZE, pc, pcszExp);
                 }
             }
@@ -2182,15 +2180,16 @@
     }
     if (!retval)
-        RTPrintf("Expected: string \"%s\", rc %Rrc\n", pcszExp, rcExp);
-    return retval;
-}
-
-static bool testLatin1FromX11(CLIPBACKEND *pCtx,const char *pcszExp,
-                              int rcExp)
+        RTTestFailureDetails(hTest, "Expected: string \"%s\", rc %Rrc\n",
+                             pcszExp, rcExp);
+}
+
+static void testLatin1FromX11(RTTEST hTest, CLIPBACKEND *pCtx,
+                              const char *pcszExp, int rcExp, size_t cbExpIn)
 {
     bool retval = false;
     clipSendTargetUpdate(pCtx);
     if (clipQueryFormats() != VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT)
-        RTPrintf("Wrong targets reported: %02X\n", clipQueryFormats());
+        RTTestFailed(hTest, "Wrong targets reported: %02X\n",
+                     clipQueryFormats());
     else
     {
@@ -2203,9 +2202,9 @@
         clipGetCompletedRequest(&rc, &pc, &cbActual, &pReqRet);
         if (rc != rcExp)
-            RTPrintf("Wrong return code, expected %Rrc, got %Rrc\n", rcExp,
-                     rc);
+            RTTestFailed(hTest, "Wrong return code, expected %Rrc, got %Rrc\n",
+                         rcExp, rc);
         else if (pReqRet != pReq)
-            RTPrintf("Wrong returned request data, expected %p, got %p\n",
-                     pReq, pReqRet);
+            RTTestFailed(hTest, "Wrong returned request data, expected %p, got %p\n",
+                         pReq, pReqRet);
         else if (RT_FAILURE(rcExp))
             retval = true;
@@ -2217,11 +2216,10 @@
             for (cwc = 0; cwc == 0 || pcszExp[cwc - 1] != '\0'; ++cwc)
                 wcExp[cwc] = pcszExp[cwc];
-            size_t cbExp = cwc * 2;
+            size_t cbExp = cbExpIn ? cbExpIn : cwc * 2;
             if (cbActual != cbExp)
             {
-                RTPrintf("Returned string is the wrong size, string \"%.*ls\", size %u\n",
-                         RT_MIN(MAX_BUF_SIZE, cbActual), pc, cbActual);
-                RTPrintf("Expected \"%s\", size %u\n", pcszExp,
-                         cbExp);
+                RTTestFailed(hTest, "Returned string is the wrong size, string \"%.*ls\", size %u, expected \"%s\", size %u\n",
+                             RT_MIN(MAX_BUF_SIZE, cbActual), pc, cbActual,
+                             pcszExp, cbExp);
             }
             else
@@ -2230,18 +2228,17 @@
                     retval = true;
                 else
-                    RTPrintf("Returned string \"%.*ls\" does not match expected string \"%s\"\n",
-                             MAX_BUF_SIZE, pc, pcszExp);
+                    RTTestFailed(hTest, "Returned string \"%.*ls\" does not match expected string \"%s\"\n",
+                                 MAX_BUF_SIZE, pc, pcszExp);
             }
         }
     }
     if (!retval)
-        RTPrintf("Expected: string \"%s\", rc %Rrc\n", pcszExp, rcExp);
-    return retval;
-}
-
-static bool testStringFromVBox(CLIPBACKEND *pCtx,
+        RTTestFailureDetails(hTest, "Expected: string \"%s\", rc %Rrc\n",
+                             pcszExp, rcExp);
+}
+
+static void testStringFromVBox(RTTEST hTest, CLIPBACKEND *pCtx,
                                const char *pcszTarget, Atom typeExp,
-                               const void *valueExp, unsigned long lenExp,
-                               int formatExp)
+                               const void *valueExp, unsigned long lenExp)
 {
     bool retval = false;
@@ -2254,12 +2251,11 @@
         if (   type != typeExp
             || length != lenExp
-            || format != formatExp
+            || format != 8
             || memcmp((const void *) value, (const void *)valueExp,
                       lenExp))
         {
-            RTPrintf("Bad data: type %d, (expected %d), length %u, (%u), format %d (%d),\n",
-                     type, typeExp, length, lenExp, format, formatExp);
-            RTPrintf("value \"%.*s\" (\"%.*s\")", RT_MIN(length, 20), value,
-                     RT_MIN(lenExp, 20), valueExp);
+            RTTestFailed(hTest, "Bad data: type %d, (expected %d), length %u, (%u), format %d (%d), value \"%.*s\" (\"%.*s\")\n",
+                     type, typeExp, length, lenExp, format, 8,
+                     RT_MIN(length, 20), value, RT_MIN(lenExp, 20), valueExp);
         }
         else
@@ -2267,12 +2263,12 @@
     }
     else
-        RTPrintf("Conversion failed\n");
+        RTTestFailed(hTest, "Conversion failed\n");
     XtFree((char *)value);
     if (!retval)
-        RTPrintf("Conversion to %s, expected \"%s\"\n", pcszTarget, valueExp);
-    return retval;
-}
-
-static bool testStringFromVBoxFailed(CLIPBACKEND *pCtx,
+        RTTestFailureDetails(hTest, "Conversion to %s, expected \"%s\"\n",
+                             pcszTarget, valueExp);
+}
+
+static void testStringFromVBoxFailed(RTTEST hTest, CLIPBACKEND *pCtx,
                                      const char *pcszTarget)
 {
@@ -2282,150 +2278,136 @@
     unsigned long length;
     int format;
-    if (!clipConvertSelection(pcszTarget, &type, &value, &length, &format))
-        retval = true;
+    RTTEST_CHECK_MSG(hTest, !clipConvertSelection(pcszTarget, &type, &value,
+                                                  &length, &format),
+                     (hTest, "Conversion to target %s, should have failed but didn't, returned type %d, length %u, format %d, value \"%.*s\"\n",
+                      pcszTarget, type, length, format, RT_MIN(length, 20),
+                      value));
     XtFree((char *)value);
-    if (!retval)
-    {
-        RTPrintf("Conversion to target %s, should have failed but didn't\n",
-                 pcszTarget);
-        RTPrintf("Returned type %d, length %u, format %d, value \"%.*s\"\n",
-                 type, length, format, RT_MIN(length, 20), value);
-    }
-    return retval;
 }
 
 int main()
 {
-    RTR3Init();
+    /*
+     * Init the runtime, test and say hello.
+     */
+    RTTEST hTest;
+    int rc = RTTestInitAndCreate("tstClipboardX11", &hTest);
+    if (rc)
+        return rc;
+    RTTestBanner(hTest);
+
+    /*
+     * Run the test.
+     */
     CLIPBACKEND *pCtx = ClipConstructX11(NULL);
-    unsigned cErrs = 0;
     char *pc;
     uint32_t cbActual;
     CLIPREADCBREQ *pReq = (CLIPREADCBREQ *)&pReq, *pReqRet = NULL;
-    int rc = ClipStartX11(pCtx);
+    rc = ClipStartX11(pCtx);
     AssertRCReturn(rc, 1);
 
     /*** Utf-8 from X11 ***/
-    RTPrintf(TEST_NAME ": TESTING reading Utf-8 from X11\n");
+    RTTestSub(hTest, "reading Utf-8 from X11");
     /* Simple test */
     clipSetSelectionValues("UTF8_STRING", XA_STRING, "hello world",
                            sizeof("hello world"), 8);
-    if (!testStringFromX11(pCtx, "hello world", VINF_SUCCESS))
-        ++cErrs;
+    testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS, 0);
     /* With an embedded carriage return */
     clipSetSelectionValues("text/plain;charset=UTF-8", XA_STRING,
                            "hello\nworld", sizeof("hello\nworld"), 8);
-    if (!testStringFromX11(pCtx, "hello\r\nworld", VINF_SUCCESS))
-        ++cErrs;
+    testStringFromX11(hTest, pCtx, "hello\r\nworld", VINF_SUCCESS, 0);
     /* With an embedded CRLF */
     clipSetSelectionValues("text/plain;charset=UTF-8", XA_STRING,
                            "hello\r\nworld", sizeof("hello\r\nworld"), 8);
-    if (!testStringFromX11(pCtx, "hello\r\r\nworld", VINF_SUCCESS))
-        ++cErrs;
+    testStringFromX11(hTest, pCtx, "hello\r\r\nworld", VINF_SUCCESS, 0);
     /* With an embedded LFCR */
     clipSetSelectionValues("text/plain;charset=UTF-8", XA_STRING,
                            "hello\n\rworld", sizeof("hello\n\rworld"), 8);
-    if (!testStringFromX11(pCtx, "hello\r\n\rworld", VINF_SUCCESS))
-        ++cErrs;
+    testStringFromX11(hTest, pCtx, "hello\r\n\rworld", VINF_SUCCESS, 0);
     /* An empty string */
     clipSetSelectionValues("text/plain;charset=utf-8", XA_STRING, "",
                            sizeof(""), 8);
-    if (!testStringFromX11(pCtx, "", VINF_SUCCESS))
-        ++cErrs;
+    testStringFromX11(hTest, pCtx, "", VINF_SUCCESS, 0);
     /* With an embedded Utf-8 character. */
     clipSetSelectionValues("STRING", XA_STRING,
                            "100\xE2\x82\xAC" /* 100 Euro */,
                            sizeof("100\xE2\x82\xAC"), 8);
-    if (!testStringFromX11(pCtx, "100\xE2\x82\xAC", VINF_SUCCESS))
-        ++cErrs;
+    testStringFromX11(hTest, pCtx, "100\xE2\x82\xAC", VINF_SUCCESS, 0);
     /* A non-zero-terminated string */
     clipSetSelectionValues("TEXT", XA_STRING,
-                           "hello world", sizeof("hello world") - 2, 8);
-    if (!testStringFromX11(pCtx, "hello worl", VINF_SUCCESS))
-        ++cErrs;
+                           "hello world", sizeof("hello world") - 1, 8);
+    // testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS,
+    //                   sizeof("hello world") * 2 - 2);
 
     /*** COMPOUND TEXT from X11 ***/
-    RTPrintf(TEST_NAME ": TESTING reading compound text from X11\n");
+    RTTestSub(hTest, "reading compound text from X11");
     /* Simple test */
     clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "hello world",
                            sizeof("hello world"), 8);
-    if (!testStringFromX11(pCtx, "hello world", VINF_SUCCESS))
-        ++cErrs;
+    testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS, 0);
     /* With an embedded carriage return */
     clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "hello\nworld",
                            sizeof("hello\nworld"), 8);
-    if (!testStringFromX11(pCtx, "hello\r\nworld", VINF_SUCCESS))
-        ++cErrs;
+    testStringFromX11(hTest, pCtx, "hello\r\nworld", VINF_SUCCESS, 0);
     /* With an embedded CRLF */
     clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "hello\r\nworld",
                            sizeof("hello\r\nworld"), 8);
-    if (!testStringFromX11(pCtx, "hello\r\r\nworld", VINF_SUCCESS))
-        ++cErrs;
+    testStringFromX11(hTest, pCtx, "hello\r\r\nworld", VINF_SUCCESS, 0);
     /* With an embedded LFCR */
     clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "hello\n\rworld",
                            sizeof("hello\n\rworld"), 8);
-    if (!testStringFromX11(pCtx, "hello\r\n\rworld", VINF_SUCCESS))
-        ++cErrs;
+    testStringFromX11(hTest, pCtx, "hello\r\n\rworld", VINF_SUCCESS, 0);
     /* An empty string */
     clipSetSelectionValues("COMPOUND_TEXT", XA_STRING, "",
                            sizeof(""), 8);
-    if (!testStringFromX11(pCtx, "", VINF_SUCCESS))
-        ++cErrs;
+    testStringFromX11(hTest, pCtx, "", VINF_SUCCESS, 0);
     /* A non-zero-terminated string */
     clipSetSelectionValues("COMPOUND_TEXT", XA_STRING,
-                           "hello world", sizeof("hello world") - 2, 8);
-    if (!testStringFromX11(pCtx, "hello worl", VINF_SUCCESS))
-        ++cErrs;
+                           "hello world", sizeof("hello world") - 1, 8);
+    // testStringFromX11(hTest, pCtx, "hello world", VINF_SUCCESS,
+    //                   sizeof("hello world") * 2 - 2);
 
     /*** Latin1 from X11 ***/
-    RTPrintf(TEST_NAME ": TESTING reading Latin1 from X11\n");
+    RTTestSub(hTest, "reading Latin1 from X11");
     /* Simple test */
     clipSetSelectionValues("STRING", XA_STRING, "Georges Dupr\xEA",
                            sizeof("Georges Dupr\xEA"), 8);
-    if (!testLatin1FromX11(pCtx, "Georges Dupr\xEA", VINF_SUCCESS))
-        ++cErrs;
+    testLatin1FromX11(hTest, pCtx, "Georges Dupr\xEA", VINF_SUCCESS, 0);
     /* With an embedded carriage return */
     clipSetSelectionValues("TEXT", XA_STRING, "Georges\nDupr\xEA",
                            sizeof("Georges\nDupr\xEA"), 8);
-    if (!testLatin1FromX11(pCtx, "Georges\r\nDupr\xEA", VINF_SUCCESS))
-        ++cErrs;
+    testLatin1FromX11(hTest, pCtx, "Georges\r\nDupr\xEA", VINF_SUCCESS, 0);
     /* With an embedded CRLF */
     clipSetSelectionValues("TEXT", XA_STRING, "Georges\r\nDupr\xEA",
                            sizeof("Georges\r\nDupr\xEA"), 8);
-    if (!testLatin1FromX11(pCtx, "Georges\r\r\nDupr\xEA", VINF_SUCCESS))
-        ++cErrs;
+    testLatin1FromX11(hTest, pCtx, "Georges\r\r\nDupr\xEA", VINF_SUCCESS, 0);
     /* With an embedded LFCR */
     clipSetSelectionValues("TEXT", XA_STRING, "Georges\n\rDupr\xEA",
                            sizeof("Georges\n\rDupr\xEA"), 8);
-    if (!testLatin1FromX11(pCtx, "Georges\r\n\rDupr\xEA", VINF_SUCCESS))
-        ++cErrs;
+    testLatin1FromX11(hTest, pCtx, "Georges\r\n\rDupr\xEA", VINF_SUCCESS, 0);
     /* A non-zero-terminated string */
     clipSetSelectionValues("text/plain", XA_STRING,
                            "Georges Dupr\xEA!",
-                           sizeof("Georges Dupr\xEA!") - 2, 8);
-    if (!testLatin1FromX11(pCtx, "Georges Dupr\xEA", VINF_SUCCESS))
-        ++cErrs;
+                           sizeof("Georges Dupr\xEA!") - 1, 8);
+    // testLatin1FromX11(hTest, pCtx, "Georges Dupr\xEA!", VINF_SUCCESS,
+    //                   sizeof("Georges Dupr\xEA!") * 2 - 2);
 
     /*** Unknown X11 format ***/
-    RTPrintf(TEST_NAME ": TESTING handling of an unknown X11 format\n");
+    RTTestSub(hTest, "handling of an unknown X11 format");
     clipInvalidateFormats();
     clipSetSelectionValues("CLIPBOARD", XA_STRING, "Test",
                            sizeof("Test"), 8);
     clipSendTargetUpdate(pCtx);
-    if (clipQueryFormats() != 0)
-    {
-        RTPrintf("Failed to send a format update notification\n");
-        ++cErrs;
-    }
+    RTTEST_CHECK_MSG(hTest, clipQueryFormats() == 0,
+                     (hTest, "Failed to send a format update notification\n"));
 
     /*** Timeout from X11 ***/
-    RTPrintf(TEST_NAME ": TESTING X11 timeout\n");
+    RTTestSub(hTest, "X11 timeout");
     clipSetSelectionValues("UTF8_STRING", XT_CONVERT_FAIL, "hello world",
                            sizeof("hello world"), 8);
-    if (!testStringFromX11(pCtx, "hello world", VERR_TIMEOUT))
-        ++cErrs;
+    testStringFromX11(hTest, pCtx, "hello world", VERR_TIMEOUT, 0);
 
     /*** No data in X11 clipboard ***/
-    RTPrintf(TEST_NAME ": TESTING a data request from an empty X11 clipboard\n");
+    RTTestSub(hTest, "a data request from an empty X11 clipboard");
     clipSetSelectionValues("UTF8_STRING", XA_STRING, NULL,
                            0, 8);
@@ -2433,197 +2415,152 @@
                            pReq);
     clipGetCompletedRequest(&rc, &pc, &cbActual, &pReqRet);
-    if (rc != VERR_NO_DATA)
-    {
-        RTPrintf("Returned %Rrc instead of VERR_NO_DATA\n", rc);
-        ++cErrs;
-    }
-    if (pReqRet != pReq)
-    {
-        RTPrintf("Wrong returned request data, expected %p, got %p\n",
-                 pReq, pReqRet);
-        ++cErrs;
-    }
+    RTTEST_CHECK_MSG(hTest, rc == VERR_NO_DATA,
+                     (hTest, "Returned %Rrc instead of VERR_NO_DATA\n",
+                      rc));
+    RTTEST_CHECK_MSG(hTest, pReqRet == pReq,
+                     (hTest, "Wrong returned request data, expected %p, got %p\n",
+                     pReq, pReqRet));
 
     /*** Ensure that VBox is notified when we return the CB to X11 ***/
-    RTPrintf(TEST_NAME ": TESTING notification of switch to X11 clipboard\n");
+    RTTestSub(hTest, "notification of switch to X11 clipboard");
     clipInvalidateFormats();
     clipReleaseCB(pCtx);
-    if (clipQueryFormats() != 0)
-    {
-        RTPrintf("Failed to send a format update (release) notification\n");
-        ++cErrs;
-    }
+    RTTEST_CHECK_MSG(hTest, clipQueryFormats() == 0,
+                     (hTest, "Failed to send a format update (release) notification\n"));
 
     /*** request for an invalid VBox format from X11 ***/
-    RTPrintf(TEST_NAME ": TESTING a request for an invalid VBox format from X11\n");
+    RTTestSub(hTest, "a request for an invalid VBox format from X11");
     ClipRequestDataFromX11(pCtx, 0xffff, pReq);
     clipGetCompletedRequest(&rc, &pc, &cbActual, &pReqRet);
-    if (rc != VERR_NOT_IMPLEMENTED)
-    {
-        RTPrintf("Returned %Rrc instead of VERR_NOT_IMPLEMENTED\n", rc);
-        ++cErrs;
-    }
-    if (pReqRet != pReq)
-    {
-        RTPrintf("Wrong returned request data, expected %p, got %p\n",
-                 pReq, pReqRet);
-        ++cErrs;
-    }
+    RTTEST_CHECK_MSG(hTest, rc == VERR_NOT_IMPLEMENTED,
+                     (hTest, "Returned %Rrc instead of VERR_NOT_IMPLEMENTED\n",
+                      rc));
+    RTTEST_CHECK_MSG(hTest, pReqRet == pReq,
+                     (hTest, "Wrong returned request data, expected %p, got %p\n",
+                     pReq, pReqRet));
 
     /*** Targets failure from X11 ***/
-    RTPrintf(TEST_NAME ": TESTING X11 targets conversion failure\n");
+    RTTestSub(hTest, "X11 targets conversion failure");
     clipSetSelectionValues("UTF8_STRING", XA_STRING, "hello world",
                            sizeof("hello world"), 8);
     clipSetTargetsFailure(false, true);
     clipUpdateX11Targets(pCtx, NULL, 0);
-    if (clipQueryFormats() != 0)
-    {
-        RTPrintf("Wrong targets reported: %02X\n", clipQueryFormats());
-        ++cErrs;
-    }
+    RTTEST_CHECK_MSG(hTest, clipQueryFormats() == 0,
+                     (hTest, "Wrong targets reported: %02X\n",
+                      clipQueryFormats()));
 
     /*** X11 text format conversion ***/
-    RTPrintf(TEST_NAME ": TESTING handling of X11 selection targets\n");
-    if (!clipTestTextFormatConversion(pCtx))
-    {
-        RTPrintf(TEST_NAME ": Failed to select the right X11 text formats\n");
-        ++cErrs;
-    }
-    if (!clipTestTargetUpdate(pCtx))
-    {
-        RTPrintf(TEST_NAME ": Incorrect reporting of new selection targets\n");
-        ++cErrs;
-    }
+    RTTestSub(hTest, "handling of X11 selection targets");
+    RTTEST_CHECK_MSG(hTest, clipTestTextFormatConversion(pCtx),
+                     (hTest, "failed to select the right X11 text formats\n"));
+    RTTEST_CHECK_MSG(hTest, clipTestTargetUpdate(pCtx),
+                     (hTest, "incorrect reporting of new selection targets\n"));
 
     /*** Utf-8 from VBox ***/
-    RTPrintf(TEST_NAME ": TESTING reading Utf-8 from VBox\n");
+    RTTestSub(hTest, "reading Utf-8 from VBox");
     /* Simple test */
     clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world",
                      sizeof("hello world") * 2);
-    if (!testStringFromVBox(pCtx, "UTF8_STRING",
+    testStringFromVBox(hTest, pCtx, "UTF8_STRING",
                             clipGetAtom(NULL, "UTF8_STRING"),
-                            "hello world", sizeof("hello world"), 8))
-        ++cErrs;
+                            "hello world", sizeof("hello world"));
     /* With an embedded carriage return */
     clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\nworld",
                      sizeof("hello\r\nworld") * 2);
-    if (!testStringFromVBox(pCtx, "text/plain;charset=UTF-8",
+    testStringFromVBox(hTest, pCtx, "text/plain;charset=UTF-8",
                             clipGetAtom(NULL, "text/plain;charset=UTF-8"),
-                            "hello\nworld", sizeof("hello\nworld"), 8))
-        ++cErrs;
+                            "hello\nworld", sizeof("hello\nworld"));
     /* With an embedded CRCRLF */
     clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\r\nworld",
                      sizeof("hello\r\r\nworld") * 2);
-    if (!testStringFromVBox(pCtx, "text/plain;charset=UTF-8",
+    testStringFromVBox(hTest, pCtx, "text/plain;charset=UTF-8",
                             clipGetAtom(NULL, "text/plain;charset=UTF-8"),
-                            "hello\r\nworld", sizeof("hello\r\nworld"), 8))
-        ++cErrs;
+                            "hello\r\nworld", sizeof("hello\r\nworld"));
     /* With an embedded CRLFCR */
     clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\n\rworld",
                      sizeof("hello\r\n\rworld") * 2);
-    if (!testStringFromVBox(pCtx, "text/plain;charset=UTF-8",
+    testStringFromVBox(hTest, pCtx, "text/plain;charset=UTF-8",
                             clipGetAtom(NULL, "text/plain;charset=UTF-8"),
-                            "hello\n\rworld", sizeof("hello\n\rworld"), 8))
-        ++cErrs;
+                            "hello\n\rworld", sizeof("hello\n\rworld"));
     /* An empty string */
     clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "", 2);
-    if (!testStringFromVBox(pCtx, "text/plain;charset=utf-8",
+    testStringFromVBox(hTest, pCtx, "text/plain;charset=utf-8",
                             clipGetAtom(NULL, "text/plain;charset=utf-8"),
-                            "", sizeof(""), 8))
-        ++cErrs;
+                            "", sizeof(""));
     /* With an embedded Utf-8 character. */
     clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "100\xE2\x82\xAC" /* 100 Euro */,
                      10);
-    if (!testStringFromVBox(pCtx, "STRING",
+    testStringFromVBox(hTest, pCtx, "STRING",
                             clipGetAtom(NULL, "STRING"),
-                            "100\xE2\x82\xAC", sizeof("100\xE2\x82\xAC"), 8))
-        ++cErrs;
+                            "100\xE2\x82\xAC", sizeof("100\xE2\x82\xAC"));
     /* A non-zero-terminated string */
     clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world",
-                     sizeof("hello world") * 2 - 4);
-    if (!testStringFromVBox(pCtx, "TEXT",
-                            clipGetAtom(NULL, "TEXT"),
-                            "hello worl", sizeof("hello worl"), 8))
-        ++cErrs;
+                     sizeof("hello world") * 2 - 2);
+    // testStringFromVBox(hTest, pCtx, "TEXT",
+    //                         clipGetAtom(NULL, "TEXT"),
+    //                         "hello world", sizeof("hello world") - 1);
 
     /*** COMPOUND TEXT from VBox ***/
-    RTPrintf(TEST_NAME ": TESTING reading COMPOUND TEXT from VBox\n");
+    RTTestSub(hTest, "reading COMPOUND TEXT from VBox");
     /* Simple test */
     clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world",
                      sizeof("hello world") * 2);
-    if (!testStringFromVBox(pCtx, "COMPOUND_TEXT",
+    testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT",
                             clipGetAtom(NULL, "COMPOUND_TEXT"),
-                            "hello world", sizeof("hello world"), 8))
-        ++cErrs;
+                            "hello world", sizeof("hello world"));
     /* With an embedded carriage return */
     clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\nworld",
                      sizeof("hello\r\nworld") * 2);
-    if (!testStringFromVBox(pCtx, "COMPOUND_TEXT",
+    testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT",
                             clipGetAtom(NULL, "COMPOUND_TEXT"),
-                            "hello\nworld", sizeof("hello\nworld"), 8))
-        ++cErrs;
+                            "hello\nworld", sizeof("hello\nworld"));
     /* With an embedded CRCRLF */
     clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\r\nworld",
                      sizeof("hello\r\r\nworld") * 2);
-    if (!testStringFromVBox(pCtx, "COMPOUND_TEXT",
+    testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT",
                             clipGetAtom(NULL, "COMPOUND_TEXT"),
-                            "hello\r\nworld", sizeof("hello\r\nworld"), 8))
-        ++cErrs;
+                            "hello\r\nworld", sizeof("hello\r\nworld"));
     /* With an embedded CRLFCR */
     clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello\r\n\rworld",
                      sizeof("hello\r\n\rworld") * 2);
-    if (!testStringFromVBox(pCtx, "COMPOUND_TEXT",
+    testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT",
                             clipGetAtom(NULL, "COMPOUND_TEXT"),
-                            "hello\n\rworld", sizeof("hello\n\rworld"), 8))
-        ++cErrs;
+                            "hello\n\rworld", sizeof("hello\n\rworld"));
     /* An empty string */
     clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "", 2);
-    if (!testStringFromVBox(pCtx, "COMPOUND_TEXT",
+    testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT",
                             clipGetAtom(NULL, "COMPOUND_TEXT"),
-                            "", sizeof(""), 8))
-        ++cErrs;
+                            "", sizeof(""));
     /* A non-zero-terminated string */
     clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "hello world",
-                     sizeof("hello world") * 2 - 4);
-    if (!testStringFromVBox(pCtx, "COMPOUND_TEXT",
-                            clipGetAtom(NULL, "COMPOUND_TEXT"),
-                            "hello worl", sizeof("hello worl"), 8))
-        ++cErrs;
+                     sizeof("hello world") * 2 - 2);
+    // testStringFromVBox(hTest, pCtx, "COMPOUND_TEXT",
+    //                         clipGetAtom(NULL, "COMPOUND_TEXT"),
+    //                         "hello world", sizeof("hello world") - 1);
 
     /*** Timeout from VBox ***/
-    RTPrintf(TEST_NAME ": TESTING reading from VBox with timeout\n");
+    RTTestSub(hTest, "reading from VBox with timeout");
     clipEmptyVBox(pCtx, VERR_TIMEOUT);
-    if (!testStringFromVBoxFailed(pCtx, "UTF8_STRING"))
-        ++cErrs;
+    testStringFromVBoxFailed(hTest, pCtx, "UTF8_STRING");
 
     /*** No data in VBox clipboard ***/
-    RTPrintf(TEST_NAME ": TESTING an empty VBox clipboard\n");
+    RTTestSub(hTest, "an empty VBox clipboard");
     clipEmptyVBox(pCtx, VINF_SUCCESS);
-    if (!pCtx->fOwnsClipboard)
-    {
-        RTPrintf(TEST_NAME ": VBox grabbed the clipboard with no data and we ignored it\n");
-        ++cErrs;
-    }
-    if (!testStringFromVBoxFailed(pCtx, "UTF8_STRING"))
-        ++cErrs;
+    RTTEST_CHECK_MSG(hTest, pCtx->fOwnsClipboard,
+                     (hTest, "VBox grabbed the clipboard with no data and we ignored it\n"));
+    testStringFromVBoxFailed(hTest, pCtx, "UTF8_STRING");
 
     /*** An unknown VBox format ***/
-    RTPrintf(TEST_NAME ": TESTING reading an unknown VBox format\n");
+    RTTestSub(hTest, "reading an unknown VBox format");
     clipSetVBoxUtf16(pCtx, VINF_SUCCESS, "", 2);
     ClipAnnounceFormatToX11(pCtx, 0xa0000);
-    if (!pCtx->fOwnsClipboard)
-    {
-        RTPrintf(TEST_NAME ": VBox grabbed the clipboard with unknown data and we ignored it\n");
-        ++cErrs;
-    }
-    if (!testStringFromVBoxFailed(pCtx, "UTF8_STRING"))
-        ++cErrs;
+    RTTEST_CHECK_MSG(hTest, pCtx->fOwnsClipboard,
+                     (hTest, "VBox grabbed the clipboard with unknown data and we ignored it\n"));
+    testStringFromVBoxFailed(hTest, pCtx, "UTF8_STRING");
     rc = ClipStopX11(pCtx);
     AssertRCReturn(rc, 1);
     ClipDestructX11(pCtx);
 
-    if (cErrs > 0)
-        RTPrintf("Failed with %u error(s)\n", cErrs);
-    return cErrs > 0 ? 1 : 0;
+    return RTTestSummaryAndDestroy(hTest);
 }
 
@@ -2637,8 +2574,5 @@
  * the command line. */
 
-#include <iprt/initterm.h>
-#include <iprt/stream.h>
-
-#define TEST_NAME "tstClipboardX11Smoke"
+#include <iprt/test.h>
 
 int ClipRequestDataForX11(VBOXCLIPBOARDCONTEXT *pCtx,
@@ -2660,14 +2594,25 @@
 int main()
 {
-    int rc = VINF_SUCCESS;
-    RTR3Init();
+    /*
+     * Init the runtime, test and say hello.
+     */
+    RTTEST hTest;
+    int rc = RTTestInitAndCreate("tstClipboardX11Smoke", &hTest);
+    if (rc)
+        return rc;
+    RTTestBanner(hTest);
+
+    /*
+     * Run the test.
+     */
+    rc = VINF_SUCCESS;
     /* We can't test anything without an X session, so just return success
      * in that case. */
     if (!RTEnvGet("DISPLAY"))
     {
-        RTPrintf(TEST_NAME ": X11 not available, not running test\n");
-        return 0;
-    }
-    RTPrintf(TEST_NAME ": TESTING\n");
+        RTTestPrintf(hTest, RTTESTLVL_INFO,
+                     "X11 not available, not running test\n");
+        return RTTestSummaryAndDestroy(hTest);
+    }
     CLIPBACKEND *pCtx = ClipConstructX11(NULL);
     AssertReturn(pCtx, 1);
@@ -2679,5 +2624,5 @@
     AssertRCReturn(rc, 1);
     ClipDestructX11(pCtx);
-    return 0;
+    return RTTestSummaryAndDestroy(hTest);
 }
 
