VirtualBox

Changeset 80836 in vbox for trunk/src


Ignore:
Timestamp:
Sep 17, 2019 12:26:52 AM (5 years ago)
Author:
vboxsync
Message:

Main/glue: Added all the append methods that RTCString have and then some.

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/glue/string.cpp

    r80835 r80836  
    135135{
    136136    cleanup();
     137
    137138    BSTRNOTHROW Args = { this, 0, 0, S_OK };
    138139    RTStrFormatV(printfOutputCallbackNoThrow, &Args, NULL, NULL, pszFormat, va);
     
    143144            return S_OK;
    144145    }
     146
    145147    cleanup();
    146148    return Args.hrc;
     
    301303
    302304
     305Bstr &Bstr::append(const Bstr &rThat)
     306{
     307    if (rThat.isNotEmpty())
     308        return appendWorkerUtf16(rThat.m_bstr, rThat.length());
     309    return *this;
     310}
     311
     312
     313HRESULT Bstr::appendNoThrow(const Bstr &rThat) RT_NOEXCEPT
     314{
     315    if (rThat.isNotEmpty())
     316        return appendWorkerUtf16NoThrow(rThat.m_bstr, rThat.length());
     317    return S_OK;
     318}
     319
     320
     321Bstr &Bstr::append(const RTCString &rThat)
     322{
     323    if (rThat.isNotEmpty())
     324        return appendWorkerUtf8(rThat.c_str(), rThat.length());
     325    return *this;
     326}
     327
     328
     329HRESULT Bstr::appendNoThrow(const RTCString &rThat) RT_NOEXCEPT
     330{
     331    if (rThat.isNotEmpty())
     332        return appendWorkerUtf8NoThrow(rThat.c_str(), rThat.length());
     333    return S_OK;
     334}
     335
     336
     337Bstr &Bstr::append(CBSTR pwszSrc)
     338{
     339    if (pwszSrc && *pwszSrc)
     340        return appendWorkerUtf16(pwszSrc, RTUtf16Len(pwszSrc));
     341    return *this;
     342}
     343
     344
     345HRESULT Bstr::appendNoThrow(CBSTR pwszSrc) RT_NOEXCEPT
     346{
     347    if (pwszSrc && *pwszSrc)
     348        return appendWorkerUtf16NoThrow(pwszSrc, RTUtf16Len(pwszSrc));
     349    return S_OK;
     350}
     351
     352
     353Bstr &Bstr::append(const char *pszSrc)
     354{
     355    if (pszSrc && *pszSrc)
     356        return appendWorkerUtf8(pszSrc, strlen(pszSrc));
     357    return *this;
     358}
     359
     360
     361HRESULT Bstr::appendNoThrow(const char *pszSrc) RT_NOEXCEPT
     362{
     363    if (pszSrc && *pszSrc)
     364        return appendWorkerUtf8NoThrow(pszSrc, strlen(pszSrc));
     365    return S_OK;
     366}
     367
     368
     369Bstr &Bstr::append(const Bstr &rThat, size_t offStart, size_t cwcMax /*= RTSTR_MAX*/)
     370{
     371    size_t cwcSrc = rThat.length();
     372    if (offStart < cwcSrc)
     373        return appendWorkerUtf16(rThat.raw() + offStart, RT_MIN(cwcSrc - offStart, cwcMax));
     374    return *this;
     375}
     376
     377
     378HRESULT Bstr::appendNoThrow(const Bstr &rThat, size_t offStart, size_t cwcMax /*= RTSTR_MAX*/) RT_NOEXCEPT
     379{
     380    size_t cwcSrc = rThat.length();
     381    if (offStart < cwcSrc)
     382        return appendWorkerUtf16NoThrow(rThat.raw() + offStart, RT_MIN(cwcSrc - offStart, cwcMax));
     383    return S_OK;
     384}
     385
     386
     387Bstr &Bstr::append(const RTCString &rThat, size_t offStart, size_t cchMax /*= RTSTR_MAX*/)
     388{
     389    if (offStart < rThat.length())
     390        return appendWorkerUtf8(rThat.c_str() + offStart, RT_MIN(rThat.length() - offStart, cchMax));
     391    return *this;
     392}
     393
     394
     395HRESULT Bstr::appendNoThrow(const RTCString &rThat, size_t offStart, size_t cchMax /*= RTSTR_MAX*/) RT_NOEXCEPT
     396{
     397    if (offStart < rThat.length())
     398        return appendWorkerUtf8NoThrow(rThat.c_str() + offStart, RT_MIN(rThat.length() - offStart, cchMax));
     399    return S_OK;
     400}
     401
     402
     403Bstr &Bstr::append(CBSTR pwszThat, size_t cchMax)
     404{
     405    return appendWorkerUtf16(pwszThat, RTUtf16NLen(pwszThat, cchMax));
     406}
     407
     408
     409HRESULT Bstr::appendNoThrow(CBSTR pwszThat, size_t cchMax) RT_NOEXCEPT
     410{
     411    return appendWorkerUtf16NoThrow(pwszThat, RTUtf16NLen(pwszThat, cchMax));
     412}
     413
     414
     415Bstr &Bstr::append(const char *pszThat, size_t cchMax)
     416{
     417    return appendWorkerUtf8(pszThat, RTStrNLen(pszThat, cchMax));
     418}
     419
     420
     421HRESULT Bstr::appendNoThrow(const char *pszThat, size_t cchMax) RT_NOEXCEPT
     422{
     423    return appendWorkerUtf8NoThrow(pszThat, RTStrNLen(pszThat, cchMax));
     424}
     425
     426
     427Bstr &Bstr::append(char ch)
     428{
     429    AssertMsg(ch > 0 && ch < 127, ("%#x\n", ch));
     430    return appendWorkerUtf8(&ch, 1);
     431}
     432
     433
     434HRESULT Bstr::appendNoThrow(char ch) RT_NOEXCEPT
     435{
     436    AssertMsg(ch > 0 && ch < 127, ("%#x\n", ch));
     437    return appendWorkerUtf8NoThrow(&ch, 1);
     438}
     439
     440
     441Bstr &Bstr::appendCodePoint(RTUNICP uc)
     442{
     443    RTUTF16 wszTmp[3];
     444    PRTUTF16 pwszEnd = RTUtf16PutCp(wszTmp, uc);
     445    *pwszEnd = '\0';
     446    return appendWorkerUtf16(&wszTmp[0], pwszEnd - &wszTmp[0]);
     447}
     448
     449
     450HRESULT Bstr::appendCodePointNoThrow(RTUNICP uc) RT_NOEXCEPT
     451{
     452    RTUTF16 wszTmp[3];
     453    PRTUTF16 pwszEnd = RTUtf16PutCp(wszTmp, uc);
     454    *pwszEnd = '\0';
     455    return appendWorkerUtf16NoThrow(&wszTmp[0], pwszEnd - &wszTmp[0]);
     456}
     457
     458
     459Bstr &Bstr::appendWorkerUtf16(PCRTUTF16 pwszSrc, size_t cwcSrc)
     460{
     461    size_t cwcOld = length();
     462    size_t cwcTotal = cwcOld + cwcSrc;
     463    reserve(cwcTotal, true /*fForce*/);
     464    if (cwcSrc)
     465        memcpy(&m_bstr[cwcOld], pwszSrc, cwcSrc * sizeof(RTUTF16));
     466    m_bstr[cwcTotal] = '\0';
     467    return *this;
     468}
     469
     470
     471HRESULT Bstr::appendWorkerUtf16NoThrow(PCRTUTF16 pwszSrc, size_t cwcSrc) RT_NOEXCEPT
     472{
     473    size_t cwcOld = length();
     474    size_t cwcTotal = cwcOld + cwcSrc;
     475    HRESULT hrc = reserveNoThrow(cwcTotal, true /*fForce*/);
     476    if (hrc == S_OK)
     477    {
     478        if (cwcSrc)
     479            memcpy(&m_bstr[cwcOld], pwszSrc, cwcSrc * sizeof(RTUTF16));
     480        m_bstr[cwcTotal] = '\0';
     481    }
     482    return hrc;
     483}
     484
     485
     486Bstr &Bstr::appendWorkerUtf8(const char *pszSrc, size_t cchSrc)
     487{
     488    size_t cwcSrc;
     489    int rc = RTStrCalcUtf16LenEx(pszSrc, cchSrc, &cwcSrc);
     490    AssertRCStmt(rc, throw std::bad_alloc());
     491
     492    size_t cwcOld = length();
     493    size_t cwcTotal = cwcOld + cwcSrc;
     494    reserve(cwcTotal, true /*fForce*/);
     495    if (cwcSrc)
     496    {
     497        PRTUTF16 pwszDst = &m_bstr[cwcOld];
     498        rc = RTStrToUtf16Ex(pszSrc, cchSrc, &pwszDst, cwcSrc + 1, NULL);
     499        AssertRCStmt(rc, throw std::bad_alloc());
     500    }
     501    m_bstr[cwcTotal] = '\0';
     502    return *this;
     503}
     504
     505
     506HRESULT Bstr::appendWorkerUtf8NoThrow(const char *pszSrc, size_t cchSrc) RT_NOEXCEPT
     507{
     508    size_t cwcSrc;
     509    int rc = RTStrCalcUtf16LenEx(pszSrc, cchSrc, &cwcSrc);
     510    AssertRCStmt(rc, E_INVALIDARG);
     511
     512    size_t cwcOld = length();
     513    size_t cwcTotal = cwcOld + cwcSrc;
     514    HRESULT hrc = reserveNoThrow(cwcTotal, true /*fForce*/);
     515    AssertReturn(hrc == S_OK, hrc);
     516    if (cwcSrc)
     517    {
     518        PRTUTF16 pwszDst = &m_bstr[cwcOld];
     519        rc = RTStrToUtf16Ex(pszSrc, cchSrc, &pwszDst, cwcSrc + 1, NULL);
     520        AssertRCStmt(rc, E_INVALIDARG);
     521    }
     522    m_bstr[cwcTotal] = '\0';
     523    return S_OK;
     524}
     525
     526
     527Bstr &Bstr::appendPrintf(const char *pszFormat, ...)
     528{
     529    va_list va;
     530    va_start(va, pszFormat);
     531    HRESULT hrc = appendPrintfVNoThrow(pszFormat, va);
     532    va_end(va);
     533    if (hrc != S_OK)
     534        throw std::bad_alloc();
     535    return *this;
     536}
     537
     538
     539HRESULT Bstr::appendPrintfNoThrow(const char *pszFormat, ...) RT_NOEXCEPT
     540{
     541    va_list va;
     542    va_start(va, pszFormat);
     543    HRESULT hrc = appendPrintfVNoThrow(pszFormat, va);
     544    va_end(va);
     545    return hrc;
     546}
     547
     548
     549Bstr &Bstr::appendPrintfV(const char *pszFormat, va_list va)
     550{
     551    HRESULT hrc = appendPrintfVNoThrow(pszFormat, va);
     552    if (hrc != S_OK)
     553        throw std::bad_alloc();
     554    return *this;
     555}
     556
     557
     558HRESULT Bstr::appendPrintfVNoThrow(const char *pszFormat, va_list va) RT_NOEXCEPT
     559{
     560    size_t const cwcOld = length();
     561    BSTRNOTHROW Args = { this, cwcOld, cwcOld, S_OK };
     562
     563    RTStrFormatV(printfOutputCallbackNoThrow, &Args, NULL, NULL, pszFormat, va);
     564    if (Args.hrc == S_OK)
     565    {
     566        Args.hrc = joltNoThrow(Args.offDst);
     567        if (Args.hrc == S_OK)
     568            return S_OK;
     569    }
     570
     571    if (m_bstr)
     572        m_bstr[cwcOld] = '\0';
     573    return Args.hrc;
     574}
     575
     576
     577
     578/*********************************************************************************************************************************
     579*   Utf8Str Implementation                                                                                                       *
     580*********************************************************************************************************************************/
     581
    303582/* static */
    304583const Utf8Str Utf8Str::Empty; /* default ctor is OK */
  • trunk/src/VBox/Main/testcase/tstBstr.cpp

    r80835 r80836  
    2828
    2929
    30 static void testBstr1(RTTEST hTest)
    31 {
    32     RTTestSub(hTest, "Bstr::printf");
    33 
     30/*********************************************************************************************************************************
     31*   Defined Constants And Macros                                                                                                 *
     32*********************************************************************************************************************************/
    3433#define CHECK_BSTR(a_Expr, a_bstr, a_szExpected) \
    3534        do { \
    3635            a_Expr; \
    37             size_t cchExpect = strlen(a_szExpected); \
     36            size_t cchExpect = RTStrCalcUtf16Len(a_szExpected); \
    3837            if ((a_bstr).length() != cchExpect) \
    3938                RTTestFailed(hTest, "line %u: length() -> %zu, expected %zu (%ls vs %s)", \
     
    4847        } while (0)
    4948
     49
     50
     51static void testBstrPrintf(RTTEST hTest)
     52{
     53    RTTestSub(hTest, "Bstr::printf");
     54
    5055    com::Bstr bstr1;
    5156    CHECK_BSTR(bstr1.printf(""), bstr1, "");
     
    6065                            bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw()),
    6166               bstr2, "42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42::42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42::42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42");
     67    CHECK_BSTR(bstr2.appendPrintf("-9999998888888777776666655554443322110!"),
     68               bstr2, "42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42::42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42::42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-9999998888888777776666655554443322110!");
     69    CHECK_BSTR(bstr2.appendPrintf("!"),
     70               bstr2, "42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42::42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42::42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-9999998888888777776666655554443322110!!");
     71}
     72
     73static void testBstrAppend(RTTEST hTest)
     74{
     75    RTTestSub(hTest, "Bstr::append");
     76
     77    /* C-string source: */
     78    com::Bstr bstr1;
     79    CHECK_BSTR(bstr1.append("1234"), bstr1, "1234");
     80    CHECK_BSTR(bstr1.append("56"), bstr1, "123456");
     81    CHECK_BSTR(bstr1.append("7"), bstr1, "1234567");
     82    CHECK_BSTR(bstr1.append("89abcdefghijklmnopqrstuvwxyz"), bstr1, "123456789abcdefghijklmnopqrstuvwxyz");
     83    CHECK_BSTR(bstr1.append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), bstr1, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
     84    CHECK_BSTR(bstr1.append("123456789abcdefghijklmnopqrstuvwxyz"), bstr1, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz");
     85    CHECK_BSTR(bstr1.append("_"), bstr1, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
     86    CHECK_BSTR(bstr1.append(""), bstr1, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
     87
     88    com::Bstr bstr2;
     89    CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(""), VINF_SUCCESS), bstr2, "");
     90    CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow("1234"), VINF_SUCCESS), bstr2, "1234");
     91    CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow("56"), VINF_SUCCESS), bstr2, "123456");
     92    CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow("7"), VINF_SUCCESS), bstr2, "1234567");
     93    CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow("89abcdefghijklmnopqrstuvwxyz"), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyz");
     94    CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
     95    CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow("123456789abcdefghijklmnopqrstuvwxyz"), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz");
     96    CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow("_"), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
     97    CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(""), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
     98
     99    /* Bstr source:  */
     100    CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(bstr1), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
     101    CHECK_BSTR(RTTESTI_CHECK_RC(bstr1.appendNoThrow(bstr2), VINF_SUCCESS), bstr1, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
     102
     103    com::Bstr const bstrWord1("word");
     104    CHECK_BSTR(bstr1.setNull(), bstr1, "");
     105    CHECK_BSTR(bstr1.append(bstr2, 5, 10), bstr1, "6789abcdef");
     106    CHECK_BSTR(bstr1.append(bstr2, 4096, 10), bstr1, "6789abcdef");
     107    CHECK_BSTR(bstr1.append(bstrWord1, 1), bstr1, "6789abcdeford");
     108    CHECK_BSTR(bstr1.append(bstrWord1, 1,1), bstr1, "6789abcdefordo");
     109    CHECK_BSTR(bstr1.append(bstrWord1, 1,2), bstr1, "6789abcdefordoor");
     110    CHECK_BSTR(bstr1.append(bstrWord1, 1,3), bstr1, "6789abcdefordoorord");
     111    CHECK_BSTR(bstr1.append(bstrWord1, 1,4), bstr1, "6789abcdefordoorordord");
     112    CHECK_BSTR(bstr1.append(bstrWord1, 3,1), bstr1, "6789abcdefordoorordordd");
     113    CHECK_BSTR(bstr1.append(bstrWord1, 3,2), bstr1, "6789abcdefordoorordorddd");
     114    CHECK_BSTR(bstr1.append(bstrWord1, 3),   bstr1, "6789abcdefordoorordordddd");
     115
     116    com::Bstr bstr3;
     117    CHECK_BSTR(bstr3.setNull(), bstr3, "");
     118    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstr2, 5, 10),   VINF_SUCCESS), bstr3, "6789abcdef");
     119    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstr2, 4096, 10),VINF_SUCCESS), bstr3, "6789abcdef");
     120    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord1, 1),   VINF_SUCCESS), bstr3, "6789abcdeford");
     121    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord1, 1,1), VINF_SUCCESS), bstr3, "6789abcdefordo");
     122    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord1, 1,2), VINF_SUCCESS), bstr3, "6789abcdefordoor");
     123    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord1, 1,3), VINF_SUCCESS), bstr3, "6789abcdefordoorord");
     124    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord1, 1,4), VINF_SUCCESS), bstr3, "6789abcdefordoorordord");
     125    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord1, 3,1), VINF_SUCCESS), bstr3, "6789abcdefordoorordordd");
     126    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord1, 3,2), VINF_SUCCESS), bstr3, "6789abcdefordoorordorddd");
     127    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord1, 3),   VINF_SUCCESS), bstr3, "6789abcdefordoorordordddd");
     128    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord1, 3),   VINF_SUCCESS), bstr3, "6789abcdefordoorordorddddd");
     129    com::Bstr const bstrWord2("-SEP-");
     130    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord2, 0),   VINF_SUCCESS), bstr3, "6789abcdefordoorordorddddd-SEP-");
     131
     132    /* CBSTR source:  */
     133    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstr1.raw()), VINF_SUCCESS), bstr3, "6789abcdefordoorordorddddd-SEP-6789abcdefordoorordordddd");
     134    CHECK_BSTR(RTTESTI_CHECK_RC(bstr1.appendNoThrow(bstr3.raw()), VINF_SUCCESS), bstr1, "6789abcdefordoorordordddd6789abcdefordoorordorddddd-SEP-6789abcdefordoorordordddd");
     135
     136    CBSTR const pwsz2 = bstr2.raw();
     137    CBSTR const pwszWord1 = bstrWord1.raw();
     138    CHECK_BSTR(bstr1.setNull(), bstr1, "");
     139    CHECK_BSTR(bstr1.append(pwsz2 + 5, 10),    bstr1, "6789abcdef");
     140    CHECK_BSTR(bstr1.append(pwszWord1 + 1),    bstr1, "6789abcdeford");
     141    CHECK_BSTR(bstr1.append(pwszWord1 + 1, 1), bstr1, "6789abcdefordo");
     142    CHECK_BSTR(bstr1.append(pwszWord1 + 1, 2), bstr1, "6789abcdefordoor");
     143    CHECK_BSTR(bstr1.append(pwszWord1 + 1, 3), bstr1, "6789abcdefordoorord");
     144    CHECK_BSTR(bstr1.append(pwszWord1 + 1, 4), bstr1, "6789abcdefordoorordord");
     145    CHECK_BSTR(bstr1.append(pwszWord1 + 3, 1), bstr1, "6789abcdefordoorordordd");
     146    CHECK_BSTR(bstr1.append(pwszWord1 + 3, 2), bstr1, "6789abcdefordoorordorddd");
     147    CHECK_BSTR(bstr1.append(pwszWord1 + 3),    bstr1, "6789abcdefordoorordordddd");
     148
     149    CHECK_BSTR(bstr3.setNull(), bstr3, "");
     150    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwsz2 + 5, 10),    VINF_SUCCESS), bstr3, "6789abcdef");
     151    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwszWord1 + 1),    VINF_SUCCESS), bstr3, "6789abcdeford");
     152    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwszWord1 + 1, 1), VINF_SUCCESS), bstr3, "6789abcdefordo");
     153    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwszWord1 + 1, 2), VINF_SUCCESS), bstr3, "6789abcdefordoor");
     154    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwszWord1 + 1, 3), VINF_SUCCESS), bstr3, "6789abcdefordoorord");
     155    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwszWord1 + 1, 4), VINF_SUCCESS), bstr3, "6789abcdefordoorordord");
     156    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwszWord1 + 3, 1), VINF_SUCCESS), bstr3, "6789abcdefordoorordordd");
     157    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwszWord1 + 3, 2), VINF_SUCCESS), bstr3, "6789abcdefordoorordorddd");
     158    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwszWord1 + 3),    VINF_SUCCESS), bstr3, "6789abcdefordoorordordddd");
     159    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwszWord1 + 3),    VINF_SUCCESS), bstr3, "6789abcdefordoorordorddddd");
     160
     161    /* RTCString source: */
     162    bstr1.setNull();
     163    CHECK_BSTR(bstr1.append(RTCString("1234")), bstr1, "1234");
     164    CHECK_BSTR(bstr1.append(RTCString("56")), bstr1, "123456");
     165    CHECK_BSTR(bstr1.append(RTCString("7")), bstr1, "1234567");
     166    CHECK_BSTR(bstr1.append(RTCString("89abcdefghijklmnopqrstuvwxyz")), bstr1, "123456789abcdefghijklmnopqrstuvwxyz");
     167    CHECK_BSTR(bstr1.append(RTCString("ABCDEFGHIJKLMNOPQRSTUVWXYZ")), bstr1, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
     168    CHECK_BSTR(bstr1.append(RTCString("123456789abcdefghijklmnopqrstuvwxyz")), bstr1, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz");
     169    CHECK_BSTR(bstr1.append(RTCString("_")), bstr1, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
     170    CHECK_BSTR(bstr1.append(RTCString()), bstr1, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
     171
     172    bstr2.setNull();
     173    CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(RTCString("")), VINF_SUCCESS), bstr2, "");
     174    CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(RTCString("1234")), VINF_SUCCESS), bstr2, "1234");
     175    CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(RTCString("56")), VINF_SUCCESS), bstr2, "123456");
     176    CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(RTCString("7")), VINF_SUCCESS), bstr2, "1234567");
     177    CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(RTCString("89abcdefghijklmnopqrstuvwxyz")), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyz");
     178    CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(RTCString("ABCDEFGHIJKLMNOPQRSTUVWXYZ")), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
     179    CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(RTCString("123456789abcdefghijklmnopqrstuvwxyz")), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz");
     180    CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(RTCString("_")), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
     181    CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(RTCString("")), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
     182
     183    RTCString const strWord1 = "word";
     184    CHECK_BSTR(bstr1.setNull(), bstr1, "");
     185    CHECK_BSTR(bstr1.append(com::Utf8Str(bstr2), 5, 10), bstr1, "6789abcdef");
     186    CHECK_BSTR(bstr1.append(com::Utf8Str(bstr2), 4096, 10), bstr1, "6789abcdef");
     187    CHECK_BSTR(bstr1.append(strWord1, 1),   bstr1, "6789abcdeford");
     188    CHECK_BSTR(bstr1.append(strWord1, 1,1), bstr1, "6789abcdefordo");
     189    CHECK_BSTR(bstr1.append(strWord1, 1,2), bstr1, "6789abcdefordoor");
     190    CHECK_BSTR(bstr1.append(strWord1, 1,3), bstr1, "6789abcdefordoorord");
     191    CHECK_BSTR(bstr1.append(strWord1, 1,4), bstr1, "6789abcdefordoorordord");
     192    CHECK_BSTR(bstr1.append(strWord1, 3,1), bstr1, "6789abcdefordoorordordd");
     193    CHECK_BSTR(bstr1.append(strWord1, 3,2), bstr1, "6789abcdefordoorordorddd");
     194    CHECK_BSTR(bstr1.append(strWord1, 3),   bstr1, "6789abcdefordoorordordddd");
     195
     196    CHECK_BSTR(bstr3.setNull(), bstr3, "");
     197    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(com::Utf8Str(bstr2), 5, 10),   VINF_SUCCESS), bstr3, "6789abcdef");
     198    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(com::Utf8Str(bstr2), 4096, 10),VINF_SUCCESS), bstr3, "6789abcdef");
     199    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(strWord1, 1),   VINF_SUCCESS), bstr3, "6789abcdeford");
     200    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(strWord1, 1,1), VINF_SUCCESS), bstr3, "6789abcdefordo");
     201    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(strWord1, 1,2), VINF_SUCCESS), bstr3, "6789abcdefordoor");
     202    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(strWord1, 1,3), VINF_SUCCESS), bstr3, "6789abcdefordoorord");
     203    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(strWord1, 1,4), VINF_SUCCESS), bstr3, "6789abcdefordoorordord");
     204    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(strWord1, 3,1), VINF_SUCCESS), bstr3, "6789abcdefordoorordordd");
     205    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(strWord1, 3,2), VINF_SUCCESS), bstr3, "6789abcdefordoorordorddd");
     206    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(strWord1, 3),   VINF_SUCCESS), bstr3, "6789abcdefordoorordordddd");
     207    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(strWord1, 3),   VINF_SUCCESS), bstr3, "6789abcdefordoorordorddddd");
     208
     209    /* char: */
     210    CHECK_BSTR(bstr1.setNull(), bstr1, "");
     211    CHECK_BSTR(bstr1.append('-'), bstr1, "-");
     212    CHECK_BSTR(bstr1.append('a'), bstr1, "-a");
     213    CHECK_BSTR(bstr1.append('b'), bstr1, "-ab");
     214    CHECK_BSTR(bstr1.append('Z'), bstr1, "-abZ");
     215    CHECK_BSTR(bstr1.append('-'), bstr1, "-abZ-");
     216
     217    CHECK_BSTR(bstr3.setNull(), bstr3, "");
     218    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow('-'), VINF_SUCCESS), bstr3, "-");
     219    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow('a'), VINF_SUCCESS), bstr3, "-a");
     220    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow('b'), VINF_SUCCESS), bstr3, "-ab");
     221    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow('Z'), VINF_SUCCESS), bstr3, "-abZ");
     222    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow('-'), VINF_SUCCESS), bstr3, "-abZ-");
     223
     224    /* unicode codepoint: */
     225    CHECK_BSTR(bstr1.setNull(), bstr1, "");
     226    CHECK_BSTR(bstr1.appendCodePoint('-'),    bstr1, "-");
     227    CHECK_BSTR(bstr1.appendCodePoint('a'),    bstr1, "-a");
     228    CHECK_BSTR(bstr1.appendCodePoint('b'),    bstr1, "-ab");
     229    CHECK_BSTR(bstr1.appendCodePoint('Z'),    bstr1, "-abZ");
     230    CHECK_BSTR(bstr1.appendCodePoint('-'),    bstr1, "-abZ-");
     231    CHECK_BSTR(bstr1.appendCodePoint(0x39f),  bstr1, "-abZ-\xce\x9f");
     232    CHECK_BSTR(bstr1.appendCodePoint(0x1f50), bstr1, "-abZ-\xce\x9f\xe1\xbd\x90");
     233    CHECK_BSTR(bstr1.appendCodePoint(0x3c7),  bstr1, "-abZ-\xce\x9f\xe1\xbd\x90\xcf\x87");
     234    CHECK_BSTR(bstr1.appendCodePoint(0x1f76), bstr1, "-abZ-\xce\x9f\xe1\xbd\x90\xcf\x87\xe1\xbd\xb6");
     235
     236    CHECK_BSTR(bstr3.setNull(), bstr3, "");
     237    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendCodePointNoThrow('-'),    VINF_SUCCESS), bstr3, "-");
     238    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendCodePointNoThrow('a'),    VINF_SUCCESS), bstr3, "-a");
     239    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendCodePointNoThrow('b'),    VINF_SUCCESS), bstr3, "-ab");
     240    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendCodePointNoThrow('Z'),    VINF_SUCCESS), bstr3, "-abZ");
     241    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendCodePointNoThrow('-'),    VINF_SUCCESS), bstr3, "-abZ-");
     242    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendCodePointNoThrow(0x39f),  VINF_SUCCESS), bstr3, "-abZ-\xce\x9f");
     243    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendCodePointNoThrow(0x1f50), VINF_SUCCESS), bstr3, "-abZ-\xce\x9f\xe1\xbd\x90");
     244    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendCodePointNoThrow(0x3c7),  VINF_SUCCESS), bstr3, "-abZ-\xce\x9f\xe1\xbd\x90\xcf\x87");
     245    CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendCodePointNoThrow(0x1f76), VINF_SUCCESS), bstr3, "-abZ-\xce\x9f\xe1\xbd\x90\xcf\x87\xe1\xbd\xb6");
    62246}
    63247
     
    71255        RTTestBanner(hTest);
    72256
    73         testBstr1(hTest);
     257        testBstrPrintf(hTest);
     258        testBstrAppend(hTest);
    74259
    75260        rcExit = RTTestSummaryAndDestroy(hTest);
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