VirtualBox

Changeset 25801 in vbox


Ignore:
Timestamp:
Jan 13, 2010 2:08:11 PM (15 years ago)
Author:
vboxsync
Message:

tstRTStrFormat: Added %N test.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/tstRTStrFormat.cpp

    r25596 r25801  
    6565
    6666
     67static void testNested(int iLine, const char *pszExpect, const char *pszFormat, ...)
     68{
     69    size_t  cchExpect = strlen(pszExpect);
     70    char    szBuf[512];
     71
     72    va_list va;
     73    va_start(va, pszFormat);
     74    size_t cch = RTStrPrintf(szBuf, sizeof(szBuf), "%N", pszFormat, va);
     75    va_end(va);
     76    if (strcmp(szBuf, pszExpect))
     77        RTTestIFailed("at line %d: nested format '%s'\n"
     78                      "    output: '%s'\n"
     79                      "    wanted: '%s'\n",
     80                      iLine, pszFormat, szBuf, pszExpect);
     81    else if (cch != cchExpect)
     82        RTTestIFailed("at line %d: Invalid length %d returned, expected %u!\n",
     83                      iLine, cch, cchExpect);
     84
     85    va_start(va, pszFormat);
     86    cch = RTStrPrintf(szBuf, sizeof(szBuf), "%uxxx%Nyyy%u", 43, pszFormat, va, 43);
     87    va_end(va);
     88    if (   strncmp(szBuf, "43xxx", 5)
     89        || strncmp(szBuf + 5, pszExpect, cchExpect)
     90        || strcmp( szBuf + 5 + cchExpect, "yyy43") )
     91        RTTestIFailed("at line %d: nested format '%s'\n"
     92                      "    output: '%s'\n"
     93                      "    wanted: '43xxx%syyy43'\n",
     94                      iLine, pszFormat, szBuf, pszExpect);
     95    else if (cch != 5 + cchExpect + 5)
     96        RTTestIFailed("at line %d: Invalid length %d returned, expected %u!\n",
     97                      iLine, cch, 5 + cchExpect + 5);
     98}
     99
     100
    67101int main()
    68102{
     
    126160                      "expected: '%s'\n",
    127161                      pszBuf, szCorrect);
     162
     163    /*
     164     * Nested
     165     */
     166    RTTestSub(hTest, "Nested (%N)");
     167    testNested(__LINE__, "42 2684354560 42 asdf 42", "42 %u 42 %s 42", 2684354560, "asdf");
     168    testNested(__LINE__, "", "");
    128169
    129170    /*
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette