VirtualBox

Changeset 40074 in vbox for trunk/src/VBox/Runtime/testcase


Ignore:
Timestamp:
Feb 10, 2012 10:08:41 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
76208
Message:

Runtime/strings: add Utf-8 and Utf-16 sanitising to a white list of characters. Fix unit test.

File:
1 edited

Legend:

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

    r40071 r40074  
    896896        const char *pcszIn;
    897897        const char *pcszOut;
     898        size_t      cwc;  /* Zero means the strings are Utf-8. */
    898899        PCRTUNICP   pcCpSet;
    899900        char        chReplacement;
     
    902903    aTests[] =
    903904    {
    904         { "1234werttrew4321", "1234werttrew4321", aCpSet, '_', 0 },
     905        { "1234werttrew4321", "1234werttrew4321", 0, aCpSet, '_', 0 },
    905906        { "123654wert\xc2\xa2trew\xe2\x82\xac""4321",
    906           "123_54wert_trew_4321", aCpSet, '_', 3 },
    907         { "hjhj8766", "????????", aCpSet, '?', 8 },
    908         { "123\xf0\xa4\xad\xa2""4", "123__4", aCpSet, '_', 1 }
    909         /* No test for invalid encoding. */
     907          "123_54wert_trew_4321", 0, aCpSet, '_', 3 },
     908        { "hjhj8766", "????????", 0, aCpSet, '?', 8 },
     909        { "123\xf0\xa4\xad\xa2""4", "123__4", 0, aCpSet, '_', 1 },
     910        { "\xff\xff\0", "\xff\xff\0", 2, aCpSet, '_', -1 },
     911        { "\xff\xff\0", "\xff\xff\0", 2, aCpSet, '_', -1 }
    910912    };
    911913    enum { MAX_IN_STRING = 256 };
     
    916918        RTUTF16 wszOutCopy[MAX_IN_STRING], *pwszOutCopy = wszOutCopy;
    917919        ssize_t cReplacements;
    918         AssertRC(RTStrToUtf16Ex(aTests[i].pcszIn, RTSTR_MAX, &pwszInCopy,
    919                                 RT_ELEMENTS(wszInCopy), NULL));
    920         AssertRC(RTStrToUtf16Ex(aTests[i].pcszOut, RTSTR_MAX, &pwszOutCopy,
    921                                 RT_ELEMENTS(wszOutCopy), NULL));
     920        if (!aTests[i].cwc)
     921        {
     922            AssertRC(RTStrToUtf16Ex(aTests[i].pcszIn, RTSTR_MAX, &pwszInCopy,
     923                                    RT_ELEMENTS(wszInCopy), NULL));
     924            AssertRC(RTStrToUtf16Ex(aTests[i].pcszOut, RTSTR_MAX, &pwszOutCopy,
     925                                    RT_ELEMENTS(wszOutCopy), NULL));
     926        }
     927        else
     928        {
     929            Assert(aTests[i].cwc <= RT_ELEMENTS(wszInCopy));
     930            memcpy(wszInCopy, aTests[i].pcszIn, aTests[i].cwc * 2);
     931            memcpy(wszOutCopy, aTests[i].pcszOut, aTests[i].cwc * 2);
     932        }
    922933        cReplacements = RTUtf16PurgeComplementSet(wszInCopy, aTests[i].pcCpSet,
    923934                                                  aTests[i].chReplacement);
Note: See TracChangeset for help on using the changeset viewer.

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