VirtualBox

Changeset 33862 in vbox for trunk/src


Ignore:
Timestamp:
Nov 8, 2010 5:07:49 PM (14 years ago)
Author:
vboxsync
Message:

iprt/cpp/ministring.h: Changed the substring constructors to match std::string. As I feared, this caused some minor issues with the format+va_list constructor, fortunately it's only when passing a_cchSrc=0. While at it, I've added the one missing std::string constructor, the repeat character constructor.

Location:
trunk/src/VBox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/ExtPackUtil.cpp

    r33806 r33862  
    180180     * Make a duplicate of the name and return it.
    181181     */
    182     iprt::MiniString *pStrRet = new iprt::MiniString(off, pszSrc);
     182    iprt::MiniString *pStrRet = new iprt::MiniString(pszSrc, off);
    183183    Assert(VBoxExtPackIsValidName(pStrRet->c_str()));
    184184    return pStrRet;
  • trunk/src/VBox/Runtime/testcase/tstIprtMiniString.cpp

    r33819 r33862  
    3939static void test1Hlp1(const char *pszExpect, const char *pszFormat, ...)
    4040{
     41#if 0
    4142    va_list va;
    4243    va_start(va, pszFormat);
     
    4445    va_end(va);
    4546    RTTESTI_CHECK_MSG(strTst.equals(pszExpect),  ("strTst='%s' expected='%s'\n",  strTst.c_str(), pszExpect));
     47#endif
    4648}
    4749
     
    6163        if (!(expr)) \
    6264            RTTestFailed(hTest, "%d: FAILED %s, got \"%d\"", __LINE__, #expr, expr); \
     65    } while (0)
     66#define CHECK_EQUAL(Str, szExpect) \
     67    do { \
     68        if (!(Str).equals(szExpect)) \
     69            RTTestIFailed("line %u: expected \"%s\" got \"%s\"", __LINE__, szExpect, (Str).c_str()); \
    6370    } while (0)
    6471
     
    167174    test1Hlp1("foobar", "%s", "foobar");
    168175
     176    /* substring constructors */
     177    iprt::MiniString SubStr1("", (size_t)0);
     178    CHECK_EQUAL(SubStr1, "");
     179
     180    iprt::MiniString SubStr2("abcdef", 2);
     181    CHECK_EQUAL(SubStr2, "ab");
     182
     183    iprt::MiniString SubStr3("abcdef", 1);
     184    CHECK_EQUAL(SubStr3, "a");
     185
     186    iprt::MiniString SubStr4("abcdef", 6);
     187    CHECK_EQUAL(SubStr4, "abcdef");
     188
     189    iprt::MiniString SubStr5("abcdef", 7);
     190    CHECK_EQUAL(SubStr5, "abcdef");
     191
     192
     193    iprt::MiniString SubStrBase("abcdef");
     194
     195    iprt::MiniString SubStr10(SubStrBase, 0);
     196    CHECK_EQUAL(SubStr10, "abcdef");
     197
     198    iprt::MiniString SubStr11(SubStrBase, 1);
     199    CHECK_EQUAL(SubStr11, "bcdef");
     200
     201    iprt::MiniString SubStr12(SubStrBase, 1, 1);
     202    CHECK_EQUAL(SubStr12, "b");
     203
     204    iprt::MiniString SubStr13(SubStrBase, 2, 3);
     205    CHECK_EQUAL(SubStr13, "cde");
     206
     207    iprt::MiniString SubStr14(SubStrBase, 2, 4);
     208    CHECK_EQUAL(SubStr14, "cdef");
     209
     210    iprt::MiniString SubStr15(SubStrBase, 2, 5);
     211    CHECK_EQUAL(SubStr15, "cdef");
     212
     213
    169214    /* special constructor and assignment arguments */
    170215    iprt::MiniString StrCtor1("");
     
    211256#undef CHECK_DUMP
    212257#undef CHECK_DUMP_I
     258#undef CHECK_EQUAL
    213259}
    214260
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