Index: /trunk/include/iprt/string.h
===================================================================
--- /trunk/include/iprt/string.h	(revision 19941)
+++ /trunk/include/iprt/string.h	(revision 19942)
@@ -530,20 +530,21 @@
  * that not all flags makes sense to both of the functions.
  * @{ */
-#define RTSTR_F_CAPITAL    0x0001
-#define RTSTR_F_LEFT       0x0002
-#define RTSTR_F_ZEROPAD    0x0004
-#define RTSTR_F_SPECIAL    0x0008
-#define RTSTR_F_VALSIGNED  0x0010
-#define RTSTR_F_PLUS       0x0020
-#define RTSTR_F_BLANK      0x0040
-#define RTSTR_F_WIDTH      0x0080
-#define RTSTR_F_PRECISION  0x0100
-
-#define RTSTR_F_BIT_MASK   0xf800
-#define RTSTR_F_8BIT       0x0800
-#define RTSTR_F_16BIT      0x1000
-#define RTSTR_F_32BIT      0x2000
-#define RTSTR_F_64BIT      0x4000
-#define RTSTR_F_128BIT     0x8000
+#define RTSTR_F_CAPITAL         0x0001
+#define RTSTR_F_LEFT            0x0002
+#define RTSTR_F_ZEROPAD         0x0004
+#define RTSTR_F_SPECIAL         0x0008
+#define RTSTR_F_VALSIGNED       0x0010
+#define RTSTR_F_PLUS            0x0020
+#define RTSTR_F_BLANK           0x0040
+#define RTSTR_F_WIDTH           0x0080
+#define RTSTR_F_PRECISION       0x0100
+#define RTSTR_F_THOUSAND_SEP    0x0200
+
+#define RTSTR_F_BIT_MASK        0xf800
+#define RTSTR_F_8BIT            0x0800
+#define RTSTR_F_16BIT           0x1000
+#define RTSTR_F_32BIT           0x2000
+#define RTSTR_F_64BIT           0x4000
+#define RTSTR_F_128BIT          0x8000
 /** @} */
 
Index: /trunk/src/VBox/Main/xml/Settings.cpp
===================================================================
--- /trunk/src/VBox/Main/xml/Settings.cpp	(revision 19941)
+++ /trunk/src/VBox/Main/xml/Settings.cpp	(revision 19942)
@@ -246,4 +246,6 @@
 
     stdx::char_auto_ptr result (new char [len]);
+    if (aBase == 0)
+        aBase = 10;
     int vrc = RTStrFormatNumber (result.get(), aValue, aBase, 0, 0, flags);
     if (RT_SUCCESS (vrc))
Index: /trunk/src/VBox/Runtime/common/string/strformat.cpp
===================================================================
--- /trunk/src/VBox/Runtime/common/string/strformat.cpp	(revision 19941)
+++ /trunk/src/VBox/Runtime/common/string/strformat.cpp	(revision 19942)
@@ -170,27 +170,23 @@
 static int rtStrFormatNumber(char *psz, KSIZE64 ullValue, unsigned int uiBase, signed int cchWidth, signed int cchPrecision, unsigned int fFlags)
 {
-    const char *    pachDigits = "0123456789abcdef";
-    char *          pszStart = psz;
+    const char     *pachDigits = "0123456789abcdef";
+    char           *pszStart = psz;
     int             cchValue;
     unsigned long   ul;
-#if 0
-    unsigned long   ullow;
-#endif
     int             i;
     int             j;
 
-/** @todo Formatting of 64 bit numbers is broken, fix it! */
-
     /*
-     * Validate and addjust input...
+     * Validate and adjust input...
      */
-/** @todo r=bird: Dmitry, who is calling this code with uiBase == 0? */
-    if (uiBase == 0)
-        uiBase = 10;
-    kASSERT((uiBase >= 2 || uiBase <= 16));
+    Assert(uiBase >= 2 || uiBase <= 16);
     if (fFlags & RTSTR_F_CAPITAL)
         pachDigits = "0123456789ABCDEF";
     if (fFlags & RTSTR_F_LEFT)
         fFlags &= ~RTSTR_F_ZEROPAD;
+    if (    (fFlags & RTSTR_F_THOUSAND_SEP) 
+        &&  (   uiBase != 10 
+             || (fFlags & RTSTR_F_ZEROPAD))) /** @todo implement RTSTR_F_ZEROPAD + RTSTR_F_THOUSAND_SEP. */
+        fFlags &= ~RTSTR_F_THOUSAND_SEP;
 
     /*
@@ -218,4 +214,11 @@
         } while (ul);
     }
+    if (fFlags & RTSTR_F_THOUSAND_SEP)
+    {
+        if (cchValue <= 3)
+            fFlags &= ~RTSTR_F_THOUSAND_SEP;
+        else
+            cchValue += cchValue / 3 - (cchValue % 3 == 0);
+    }
 
     /*
@@ -281,20 +284,45 @@
     {
         uint64_t    u64 = *(uint64_t *)(void *)&ullValue;
-        do
-        {
-            psz[i--] = pachDigits[u64 % uiBase];
-            u64 /= uiBase;
-        } while (u64);
+        if (fFlags & RTSTR_F_THOUSAND_SEP)
+        {    
+            do
+            {
+                if ((-i - 1) % 4 == 3)
+                    psz[i--] = ' ';
+                psz[i--] = pachDigits[u64 % uiBase];
+                u64 /= uiBase;
+            } while (u64);
+        }
+        else
+        {    
+            do
+            {
+                psz[i--] = pachDigits[u64 % uiBase];
+                u64 /= uiBase;
+            } while (u64);
+        }
     }
     else
     {
         ul = (fFlags & RTSTR_F_VALSIGNED) && (ullValue.ulLo & 0x80000000) ? -(int32_t)ullValue.ulLo : ullValue.ulLo;
-        do
+        if (fFlags & RTSTR_F_THOUSAND_SEP)
         {
-            psz[i--] = pachDigits[ul % uiBase];
-            ul /= uiBase;
-        } while (ul);
+            do
+            {
+                if ((-i - 1) % 4 == 3)
+                    psz[i--] = ' ';
+                psz[i--] = pachDigits[ul % uiBase];
+                ul /= uiBase;
+            } while (ul);
+        }
+        else
+        {
+            do
+            {
+                psz[i--] = pachDigits[ul % uiBase];
+                ul /= uiBase;
+            } while (ul);
+        }
     }
-
 
     /*
@@ -358,9 +386,10 @@
                     switch (*pszFormat++)
                     {
-                        case '#':   fFlags |= RTSTR_F_SPECIAL;   continue;
-                        case '-':   fFlags |= RTSTR_F_LEFT;      continue;
-                        case '+':   fFlags |= RTSTR_F_PLUS;      continue;
-                        case ' ':   fFlags |= RTSTR_F_BLANK;     continue;
-                        case '0':   fFlags |= RTSTR_F_ZEROPAD;   continue;
+                        case '#':   fFlags |= RTSTR_F_SPECIAL;      continue;
+                        case '-':   fFlags |= RTSTR_F_LEFT;         continue;
+                        case '+':   fFlags |= RTSTR_F_PLUS;         continue;
+                        case ' ':   fFlags |= RTSTR_F_BLANK;        continue;
+                        case '0':   fFlags |= RTSTR_F_ZEROPAD;      continue;
+                        case '\'':  fFlags |= RTSTR_F_THOUSAND_SEP; continue;
                     }
                     pszFormat--;
Index: /trunk/src/VBox/Runtime/common/string/strformatrt.cpp
===================================================================
--- /trunk/src/VBox/Runtime/common/string/strformatrt.cpp	(revision 19941)
+++ /trunk/src/VBox/Runtime/common/string/strformatrt.cpp	(revision 19942)
@@ -414,5 +414,5 @@
                     case RTSF_FP16:
                     {
-                        fFlags &= ~(RTSTR_F_VALSIGNED | RTSTR_F_BIT_MASK | RTSTR_F_WIDTH | RTSTR_F_PRECISION);
+                        fFlags &= ~(RTSTR_F_VALSIGNED | RTSTR_F_BIT_MASK | RTSTR_F_WIDTH | RTSTR_F_PRECISION | RTSTR_F_THOUSAND_SEP);
                         cch = RTStrFormatNumber(&szBuf[0], u.fp16.sel, 16, 4, -1, fFlags | RTSTR_F_16BIT);
                         Assert(cch == 4);
@@ -425,5 +425,5 @@
                     case RTSF_FP32:
                     {
-                        fFlags &= ~(RTSTR_F_VALSIGNED | RTSTR_F_BIT_MASK | RTSTR_F_WIDTH | RTSTR_F_PRECISION);
+                        fFlags &= ~(RTSTR_F_VALSIGNED | RTSTR_F_BIT_MASK | RTSTR_F_WIDTH | RTSTR_F_PRECISION | RTSTR_F_THOUSAND_SEP);
                         cch = RTStrFormatNumber(&szBuf[0], u.fp32.sel, 16, 4, -1, fFlags | RTSTR_F_16BIT);
                         Assert(cch == 4);
@@ -436,5 +436,5 @@
                     case RTSF_FP64:
                     {
-                        fFlags &= ~(RTSTR_F_VALSIGNED | RTSTR_F_BIT_MASK | RTSTR_F_WIDTH | RTSTR_F_PRECISION);
+                        fFlags &= ~(RTSTR_F_VALSIGNED | RTSTR_F_BIT_MASK | RTSTR_F_WIDTH | RTSTR_F_PRECISION | RTSTR_F_THOUSAND_SEP);
                         cch = RTStrFormatNumber(&szBuf[0], u.fp64.sel, 16, 4, -1, fFlags | RTSTR_F_16BIT);
                         Assert(cch == 4);
Index: /trunk/src/VBox/Runtime/testcase/tstStrFormat.cpp
===================================================================
--- /trunk/src/VBox/Runtime/testcase/tstStrFormat.cpp	(revision 19941)
+++ /trunk/src/VBox/Runtime/testcase/tstStrFormat.cpp	(revision 19942)
@@ -33,13 +33,9 @@
 *******************************************************************************/
 #include <iprt/string.h>
+
 #include <iprt/initterm.h>
+#include <iprt/stream.h>
+#include <iprt/test.h>
 #include <iprt/uuid.h>
-#include <iprt/string.h>
-#include <iprt/stream.h>
-
-/*******************************************************************************
-*   Global Variables                                                           *
-*******************************************************************************/
-static int g_cErrors = 0;
 
 
@@ -52,15 +48,9 @@
     /* validate */
     if (strncmp(pszType, "type", 4))
-    {
-        RTPrintf("tstStrFormat: pszType=%s expected 'typeN'\n", pszType);
-        g_cErrors++;
-    }
+        RTTestIFailed("pszType=%s expected 'typeN'\n", pszType);
 
     int iType = pszType[4] - '0';
     if ((uintptr_t)pvUser != (uintptr_t)TstType + iType)
-    {
-        RTPrintf("tstStrFormat: pvValue=%p expected %p\n", pvUser, (void *)((uintptr_t)TstType + iType));
-        g_cErrors++;
-    }
+        RTTestIFailed("pvValue=%p expected %p\n", pvUser, (void *)((uintptr_t)TstType + iType));
 
     /* format */
@@ -68,5 +58,5 @@
     cch += pfnOutput(pvArgOutput, "=", 1);
     char szNum[64];
-    size_t cchNum = RTStrFormatNumber(szNum, (uintptr_t)pvValue, 0, cchWidth, cchPrecision, fFlags);
+    size_t cchNum = RTStrFormatNumber(szNum, (uintptr_t)pvValue, 10, cchWidth, cchPrecision, fFlags);
     cch += pfnOutput(pvArgOutput, szNum, cchNum);
     return cch;
@@ -76,51 +66,55 @@
 int main()
 {
-    RTR3Init();
+    int rc = RTR3Init();
+    if (RT_FAILURE(rc))
+        return 1;
+    RTTEST      hTest;
+    rc = RTTestCreate("tstStrFormat", &hTest);
+    if (RT_FAILURE(rc))
+        return 1;
+    RTTestBanner(hTest);
 
     uint32_t    u32 = 0x010;
     uint64_t    u64 = 0x100;
-    char        szStr[120];
+#define BUF_SIZE    120
+    char       *pszBuf = (char *)RTTestGuardedAllocHead(hTest, BUF_SIZE);
+
+    RTTestSub(hTest, "Basics");
 
     /* simple */
-    size_t cch = RTStrPrintf(szStr, sizeof(szStr), "u32=%d u64=%lld u64=%#llx", u32, u64, u64);
-    if (strcmp(szStr, "u32=16 u64=256 u64=0x100"))
-    {
-        RTPrintf("error: '%s'\n"
-               "wanted 'u32=16 u64=256 u64=0x100'\n", szStr);
-        g_cErrors++;
+    size_t cch = RTStrPrintf(pszBuf, BUF_SIZE, "u32=%d u64=%lld u64=%#llx", u32, u64, u64);
+    if (strcmp(pszBuf, "u32=16 u64=256 u64=0x100"))
+    {
+        RTTestIFailed("error: '%s'\n"
+                      "wanted 'u32=16 u64=256 u64=0x100'\n", pszBuf);
     }
 
     /* just big. */
     u64 = UINT64_C(0x7070605040302010);
-    cch = RTStrPrintf(szStr, sizeof(szStr), "u64=%#llx 42=%d u64=%lld 42=%d", u64, 42, u64, 42);
-    if (strcmp(szStr, "u64=0x7070605040302010 42=42 u64=8102081627430068240 42=42"))
-    {
-        RTPrintf("error: '%s'\n"
-                 "wanted 'u64=0x8070605040302010 42=42 u64=8102081627430068240 42=42'\n", szStr);
-        RTPrintf("%d\n", (int)(u64 % 10));
-        g_cErrors++;
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "u64=%#llx 42=%d u64=%lld 42=%d", u64, 42, u64, 42);
+    if (strcmp(pszBuf, "u64=0x7070605040302010 42=42 u64=8102081627430068240 42=42"))
+    {
+        RTTestIFailed("error: '%s'\n"
+                      "wanted 'u64=0x8070605040302010 42=42 u64=8102081627430068240 42=42'\n", pszBuf);
+        RTTestIPrintf(RTTESTLVL_FAILURE, "%d\n", (int)(u64 % 10));
     }
 
     /* huge and negative. */
     u64 = UINT64_C(0x8070605040302010);
-    cch = RTStrPrintf(szStr, sizeof(szStr), "u64=%#llx 42=%d u64=%llu 42=%d u64=%lld 42=%d", u64, 42, u64, 42, u64, 42);
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "u64=%#llx 42=%d u64=%llu 42=%d u64=%lld 42=%d", u64, 42, u64, 42, u64, 42);
     /* Not sure if this is the correct decimal representation... But both */
-    if (strcmp(szStr, "u64=0x8070605040302010 42=42 u64=9255003132036915216 42=42 u64=-9191740941672636400 42=42"))
-    {
-        RTPrintf("error: '%s'\n"
-                 "wanted 'u64=0x8070605040302010 42=42 u64=9255003132036915216 42=42 u64=-9191740941672636400 42=42'\n", szStr);
-        RTPrintf("%d\n", (int)(u64 % 10));
-        g_cErrors++;
+    if (strcmp(pszBuf, "u64=0x8070605040302010 42=42 u64=9255003132036915216 42=42 u64=-9191740941672636400 42=42"))
+    {
+        RTTestIFailed("error: '%s'\n"
+                      "wanted 'u64=0x8070605040302010 42=42 u64=9255003132036915216 42=42 u64=-9191740941672636400 42=42'\n", pszBuf);
+        RTTestIPrintf(RTTESTLVL_FAILURE, "%d\n", (int)(u64 % 10));
     }
 
     /* 64-bit value bug. */
     u64 = 0xa0000000;
-    cch = RTStrPrintf(szStr, sizeof(szStr), "u64=%#llx 42=%d u64=%lld 42=%d", u64, 42, u64, 42);
-    if (strcmp(szStr, "u64=0xa0000000 42=42 u64=2684354560 42=42"))
-    {
-        RTPrintf("error: '%s'\n"
-                 "wanted 'u64=0xa0000000 42=42 u64=2684354560 42=42'\n", szStr);
-        g_cErrors++;
-    }
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "u64=%#llx 42=%d u64=%lld 42=%d", u64, 42, u64, 42);
+    if (strcmp(pszBuf, "u64=0xa0000000 42=42 u64=2684354560 42=42"))
+        RTTestIFailed("error: '%s'\n"
+                      "wanted 'u64=0xa0000000 42=42 u64=2684354560 42=42'\n", pszBuf);
 
     /* uuid */
@@ -129,58 +123,49 @@
     char szCorrect[RTUUID_STR_LENGTH];
     RTUuidToStr(&Uuid, szCorrect, sizeof(szCorrect));
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%Vuuid", &Uuid);
-    if (strcmp(szStr, szCorrect))
-    {
-        RTPrintf("error:    '%s'\n"
-                 "expected: '%s'\n",
-                 szStr, szCorrect);
-        g_cErrors++;
-    }
-
-    /* allocation */
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%Vuuid", &Uuid);
+    if (strcmp(pszBuf, szCorrect))
+        RTTestIFailed("error:    '%s'\n"
+                      "expected: '%s'\n",
+                      pszBuf, szCorrect);
+
+    /* 
+     * allocation
+     */
+    RTTestSub(hTest, "RTStrAPrintf");
     char *psz = (char *)~0;
     int cch2 = RTStrAPrintf(&psz, "Hey there! %s%s", "This is a test", "!");
     if (cch2 < 0)
-    {
-        RTPrintf("error: RTStrAPrintf failed, cch2=%d\n", cch2);
-        g_cErrors++;
-    }
+        RTTestIFailed("RTStrAPrintf failed, cch2=%d\n", cch2);
     else if (strcmp(psz, "Hey there! This is a test!"))
-    {
-        RTPrintf("error: RTStrAPrintf failed\n"
-                 "got   : '%s'\n"
-                 "wanted: 'Hey there! This is a test!'\n",
-               psz);
-        g_cErrors++;
-    }
+        RTTestIFailed("RTStrAPrintf failed\n"
+                      "got   : '%s'\n"
+                      "wanted: 'Hey there! This is a test!'\n",
+                      psz);
     else if ((int)strlen(psz) != cch2)
-    {
-        RTPrintf("error: RTStrAPrintf failed, cch2 == %d expected %u\n", cch2, strlen(psz));
-        g_cErrors++;
-    }
+        RTTestIFailed("RTStrAPrintf failed, cch2 == %d expected %u\n", cch2, strlen(psz));
     RTStrFree(psz);
 
 #define CHECK42(fmt, arg, out) \
     do { \
-        cch = RTStrPrintf(szStr, sizeof(szStr), fmt " 42=%d " fmt " 42=%d", arg, 42, arg, 42); \
-        if (strcmp(szStr, out " 42=42 " out " 42=42")) \
-        { \
-            RTPrintf("error(%d): format '%s'\n" \
-                     "    output: '%s'\n"  \
-                     "    wanted: '%s'\n", \
-                     __LINE__, fmt, szStr, out " 42=42 " out " 42=42"); \
-            g_cErrors++; \
-        } \
+        cch = RTStrPrintf(pszBuf, BUF_SIZE, fmt " 42=%d " fmt " 42=%d", arg, 42, arg, 42); \
+        if (strcmp(pszBuf, out " 42=42 " out " 42=42")) \
+            RTTestIFailed("at line %d: format '%s'\n" \
+                          "    output: '%s'\n"  \
+                          "    wanted: '%s'\n", \
+                          __LINE__, fmt, pszBuf, out " 42=42 " out " 42=42"); \
         else if (cch != sizeof(out " 42=42 " out " 42=42") - 1) \
-        { \
-            RTPrintf("error(%d): Invalid length %d returned, expected %u!\n", \
-                     __LINE__, cch, sizeof(out " 42=42 " out " 42=42") - 1); \
-            g_cErrors++; \
-        } \
+            RTTestIFailed("at line %d: Invalid length %d returned, expected %u!\n", \
+                          __LINE__, cch, sizeof(out " 42=42 " out " 42=42") - 1); \
     } while (0)
+
+#define CHECKSTR(Correct) \
+    if (strcmp(pszBuf, Correct)) \
+        RTTestIFailed("error:    '%s'\n" \
+                      "expected: '%s'\n", pszBuf, Correct); \
 
     /*
      * Runtime extensions.
      */
+    RTTestSub(hTest, "Runtime format types (%R*)");
     CHECK42("%RGi", (RTGCINT)127, "127");
     CHECK42("%RGi", (RTGCINT)-586589, "-586589");
@@ -357,12 +342,9 @@
     RTUuidCreate(&Uuid);
     RTUuidToStr(&Uuid, szCorrect, sizeof(szCorrect));
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%RTuuid", &Uuid);
-    if (strcmp(szStr, szCorrect))
-    {
-        RTPrintf("error:    '%s'\n"
-                 "expected: '%s'\n",
-                 szStr, szCorrect);
-        g_cErrors++;
-    }
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%RTuuid", &Uuid);
+    if (strcmp(pszBuf, szCorrect))
+        RTTestIFailed("error:    '%s'\n"
+                      "expected: '%s'\n",
+                      pszBuf, szCorrect);
 
     CHECK42("%RTxint", (RTGCUINT)0x2345, "2345");
@@ -395,25 +377,42 @@
     CHECK42("%RX8", 0x100, "0");
 
-#define CHECKSTR(Correct) \
-    if (strcmp(szStr, Correct)) \
-    { \
-        RTPrintf("error:    '%s'\n" \
-                 "expected: '%s'\n", szStr, Correct); \
-        g_cErrors++; \
-    }
+    /*
+     * Thousand separators.
+     */
+    RTTestSub(hTest, "Thousand Separators (%'*)");
+
+    RTStrFormatNumber(pszBuf,       1, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("1");              memset(pszBuf, '!', BUF_SIZE);
+    RTStrFormatNumber(pszBuf,      10, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("10");             memset(pszBuf, '!', BUF_SIZE);
+    RTStrFormatNumber(pszBuf,     100, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("100");            memset(pszBuf, '!', BUF_SIZE);
+    RTStrFormatNumber(pszBuf,    1000, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("1 000");          memset(pszBuf, '!', BUF_SIZE);
+    RTStrFormatNumber(pszBuf,   10000, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("10 000");         memset(pszBuf, '!', BUF_SIZE);
+    RTStrFormatNumber(pszBuf,  100000, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("100 000");        memset(pszBuf, '!', BUF_SIZE);
+    RTStrFormatNumber(pszBuf, 1000000, 10, 0, 0, RTSTR_F_THOUSAND_SEP); CHECKSTR("1 000 000");      memset(pszBuf, '!', BUF_SIZE);
+    
+    CHECK42("%'u", 1,                              "1");
+    CHECK42("%'u", 10,                            "10");
+    CHECK42("%'u", 100,                          "100");
+    CHECK42("%'u", 1000,                       "1 000");
+    CHECK42("%'u", 10000,                     "10 000");
+    CHECK42("%'u", 100000,                   "100 000");
+    CHECK42("%'u", 1000000,                "1 000 000");
+    CHECK42("%'RU64", _1T,         "1 099 511 627 776");
+    CHECK42("%'RU64", _1E, "1 152 921 504 606 846 976");
 
     /*
      * String formatting.
      */
+    RTTestSub(hTest, "String formatting (%s)");
+
 //            0         1         2         3         4         5         6         7
 //            0....5....0....5....0....5....0....5....0....5....0....5....0....5....0
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%-10s %-30s %s", "cmd", "args", "description");
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10s %-30s %s", "cmd", "args", "description");
     CHECKSTR("cmd        args                           description");
 
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%-10s %-30s %s", "cmd", "", "description");
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10s %-30s %s", "cmd", "", "description");
     CHECKSTR("cmd                                       description");
 
 
-    cch = RTStrPrintf(szStr, sizeof(szStr),  "%*s", 0, "");
+    cch = RTStrPrintf(pszBuf, BUF_SIZE,  "%*s", 0, "");
     CHECKSTR("");
 
@@ -422,12 +421,12 @@
     static RTUTF16 s_wsz1[] = { 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', 0 }; //assumes ascii.
 
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%ls", s_wsz1);
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%ls", s_wsz1);
     CHECKSTR("hello world");
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%Ls", s_usz1);
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%Ls", s_usz1);
     CHECKSTR("hello world");
 
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%.5ls", s_wsz1);
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.5ls", s_wsz1);
     CHECKSTR("hello");
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%.5Ls", s_usz1);
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%.5Ls", s_usz1);
     CHECKSTR("hello");
 
@@ -435,4 +434,5 @@
      * Unicode string formatting.
      */
+    RTTestSub(hTest, "Unicode string formatting (%ls)");
     static RTUTF16 s_wszEmpty[]  = { 0 }; //assumes ascii.
     static RTUTF16 s_wszCmd[]    = { 'c', 'm', 'd', 0 }; //assumes ascii.
@@ -442,8 +442,8 @@
 //            0         1         2         3         4         5         6         7
 //            0....5....0....5....0....5....0....5....0....5....0....5....0....5....0
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%-10ls %-30ls %ls", s_wszCmd, s_wszArgs, s_wszDesc);
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10ls %-30ls %ls", s_wszCmd, s_wszArgs, s_wszDesc);
     CHECKSTR("cmd        args                           description");
 
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%-10ls %-30ls %ls", s_wszCmd, s_wszEmpty, s_wszDesc);
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%-10ls %-30ls %ls", s_wszCmd, s_wszEmpty, s_wszDesc);
     CHECKSTR("cmd                                       description");
 
@@ -454,7 +454,7 @@
     static char    s_sz2[]  = { 0xc5, 0xc6, 0xf8, 0 };///@todo multibyte tests.
 
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%ls", s_wsz2);
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%ls", s_wsz2);
     CHECKSTR(s_sz2);
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%Ls", s_usz2);
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%Ls", s_usz2);
     CHECKSTR(s_sz2);
 #endif
@@ -463,67 +463,61 @@
      * Custom types.
      */
-#define CHECK(expr)  do { if (!(expr)) { RTPrintf("tstEnv: error line %d: %s\n", __LINE__, #expr); g_cErrors++; } } while (0)
-#define CHECK_RC(expr, rc)  do { int rc2 = expr; if (rc2 != (rc)) { RTPrintf("tstEnv: error line %d: %s -> %Rrc expected %Rrc\n", __LINE__, #expr, rc2, rc); g_cErrors++; } } while (0)
-
-    CHECK_RC(RTStrFormatTypeRegister("type3", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
-    CHECK_RC(RTStrFormatTypeSetUser("type3",           (void *)((uintptr_t)TstType + 3)), VINF_SUCCESS);
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%R[type3]", (void *)1);
+    RTTestSub(hTest, "Custom format types (%R[*])");
+    RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type3", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
+    RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type3",           (void *)((uintptr_t)TstType + 3)), VINF_SUCCESS);
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3]", (void *)1);
     CHECKSTR("type3=1");
 
-    CHECK_RC(RTStrFormatTypeRegister("type1", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
-    CHECK_RC(RTStrFormatTypeSetUser("type1",           (void *)((uintptr_t)TstType + 1)), VINF_SUCCESS);
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%R[type3] %R[type1]", (void *)1, (void *)2);
+    RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type1", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
+    RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type1",           (void *)((uintptr_t)TstType + 1)), VINF_SUCCESS);
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1]", (void *)1, (void *)2);
     CHECKSTR("type3=1 type1=2");
 
-    CHECK_RC(RTStrFormatTypeRegister("type4", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
-    CHECK_RC(RTStrFormatTypeSetUser("type4",           (void *)((uintptr_t)TstType + 4)), VINF_SUCCESS);
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%R[type3] %R[type1] %R[type4]", (void *)1, (void *)2, (void *)3);
+    RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type4", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
+    RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type4",           (void *)((uintptr_t)TstType + 4)), VINF_SUCCESS);
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4]", (void *)1, (void *)2, (void *)3);
     CHECKSTR("type3=1 type1=2 type4=3");
 
-    CHECK_RC(RTStrFormatTypeRegister("type2", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
-    CHECK_RC(RTStrFormatTypeSetUser("type2",           (void *)((uintptr_t)TstType + 2)), VINF_SUCCESS);
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%R[type3] %R[type1] %R[type4] %R[type2]", (void *)1, (void *)2, (void *)3, (void *)4);
+    RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type2", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
+    RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type2",           (void *)((uintptr_t)TstType + 2)), VINF_SUCCESS);
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4] %R[type2]", (void *)1, (void *)2, (void *)3, (void *)4);
     CHECKSTR("type3=1 type1=2 type4=3 type2=4");
 
-    CHECK_RC(RTStrFormatTypeRegister("type5", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
-    CHECK_RC(RTStrFormatTypeSetUser("type5",           (void *)((uintptr_t)TstType + 5)), VINF_SUCCESS);
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%R[type3] %R[type1] %R[type4] %R[type2] %R[type5]", (void *)1, (void *)2, (void *)3, (void *)4, (void *)5);
+    RTTESTI_CHECK_RC(RTStrFormatTypeRegister("type5", TstType, (void *)((uintptr_t)TstType)), VINF_SUCCESS);
+    RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type5",           (void *)((uintptr_t)TstType + 5)), VINF_SUCCESS);
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4] %R[type2] %R[type5]", (void *)1, (void *)2, (void *)3, (void *)4, (void *)5);
     CHECKSTR("type3=1 type1=2 type4=3 type2=4 type5=5");
 
-    CHECK_RC(RTStrFormatTypeSetUser("type1",           (void *)((uintptr_t)TstType + 1)), VINF_SUCCESS);
-    CHECK_RC(RTStrFormatTypeSetUser("type2",           (void *)((uintptr_t)TstType + 2)), VINF_SUCCESS);
-    CHECK_RC(RTStrFormatTypeSetUser("type3",           (void *)((uintptr_t)TstType + 3)), VINF_SUCCESS);
-    CHECK_RC(RTStrFormatTypeSetUser("type4",           (void *)((uintptr_t)TstType + 4)), VINF_SUCCESS);
-    CHECK_RC(RTStrFormatTypeSetUser("type5",           (void *)((uintptr_t)TstType + 5)), VINF_SUCCESS);
-
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%R[type3] %R[type1] %R[type4] %R[type2] %R[type5]", (void *)10, (void *)20, (void *)30, (void *)40, (void *)50);
+    RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type1",           (void *)((uintptr_t)TstType + 1)), VINF_SUCCESS);
+    RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type2",           (void *)((uintptr_t)TstType + 2)), VINF_SUCCESS);
+    RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type3",           (void *)((uintptr_t)TstType + 3)), VINF_SUCCESS);
+    RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type4",           (void *)((uintptr_t)TstType + 4)), VINF_SUCCESS);
+    RTTESTI_CHECK_RC(RTStrFormatTypeSetUser("type5",           (void *)((uintptr_t)TstType + 5)), VINF_SUCCESS);
+
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4] %R[type2] %R[type5]", (void *)10, (void *)20, (void *)30, (void *)40, (void *)50);
     CHECKSTR("type3=10 type1=20 type4=30 type2=40 type5=50");
 
-    CHECK_RC(RTStrFormatTypeDeregister("type2"), VINF_SUCCESS);
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%R[type3] %R[type1] %R[type4] %R[type5]", (void *)10, (void *)20, (void *)30, (void *)40);
+    RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type2"), VINF_SUCCESS);
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4] %R[type5]", (void *)10, (void *)20, (void *)30, (void *)40);
     CHECKSTR("type3=10 type1=20 type4=30 type5=40");
 
-    CHECK_RC(RTStrFormatTypeDeregister("type5"), VINF_SUCCESS);
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%R[type3] %R[type1] %R[type4]", (void *)10, (void *)20, (void *)30);
+    RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type5"), VINF_SUCCESS);
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1] %R[type4]", (void *)10, (void *)20, (void *)30);
     CHECKSTR("type3=10 type1=20 type4=30");
 
-    CHECK_RC(RTStrFormatTypeDeregister("type4"), VINF_SUCCESS);
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%R[type3] %R[type1]", (void *)10, (void *)20);
+    RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type4"), VINF_SUCCESS);
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3] %R[type1]", (void *)10, (void *)20);
     CHECKSTR("type3=10 type1=20");
 
-    CHECK_RC(RTStrFormatTypeDeregister("type1"), VINF_SUCCESS);
-    cch = RTStrPrintf(szStr, sizeof(szStr), "%R[type3]", (void *)10);
+    RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type1"), VINF_SUCCESS);
+    cch = RTStrPrintf(pszBuf, BUF_SIZE, "%R[type3]", (void *)10);
     CHECKSTR("type3=10");
 
-    CHECK_RC(RTStrFormatTypeDeregister("type3"), VINF_SUCCESS);
+    RTTESTI_CHECK_RC(RTStrFormatTypeDeregister("type3"), VINF_SUCCESS);
 
     /*
      * Summarize and exit.
      */
-    if (!g_cErrors)
-        RTPrintf("tstStrFormat: SUCCESS\n");
-    else
-        RTPrintf("tstStrFormat: FAILED - %d errors\n", g_cErrors);
-    return !!g_cErrors;
+    return RTTestSummaryAndDestroy(hTest);
 }
 
