⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 string_test.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        2);                     // AppendEndOfLine A|B


    HX_ASSERT(i < cmds.Nelements());
    cmds[i++] = new HLXUnitTestCmdInfoDisp<HLXStringTest>(
        this,
        "GetBuffer",
        &HLXStringTest::HandleGetBufferCmd,
        3, 4);                  // GetBuffer A|B <length> [<expected value>]

    HX_ASSERT(i < cmds.Nelements());
    cmds[i++] = new HLXUnitTestCmdInfoDisp<HLXStringTest>(
        this,
        "BufferSet",
        &HLXStringTest::HandleBufferSetCmd,
        3, 4);                  // BufferSet A|B [<index>] <string>

    HX_ASSERT(i < cmds.Nelements());
    cmds[i++] = new HLXUnitTestCmdInfoDisp<HLXStringTest>(
        this,
        "BufferFill",
        &HLXStringTest::HandleBufferFillCmd,
        4, 5);                  // BufferFill A|B [<index>] <string> <repeat count>

    HX_ASSERT(i < cmds.Nelements());
    cmds[i++] = new HLXUnitTestCmdInfoDisp<HLXStringTest>(
        this,
        "BufferEndString",
        &HLXStringTest::HandleBufferEndStringCmd,
        3);                     // BufferEndString A|B <index>

    HX_ASSERT(i < cmds.Nelements());
    cmds[i++] = new HLXUnitTestCmdInfoDisp<HLXStringTest>(
        this,
        "GetBufferSetLength",
        &HLXStringTest::HandleGetBufferSetLengthCmd,
        4);                     // GetBufferSetLength A|B <length> <expected value>

#ifdef XXXSAB
    HX_ASSERT(i < cmds.Nelements());
    cmds[i++] = new HLXUnitTestCmdInfoDisp<HLXStringTest>(
        this,
        "ReleaseBuffer0",
        &HLXStringTest::HandleReleaseBufferCmd,
        2);                     // ReleaseBuffer0 A|B

    HX_ASSERT(i < cmds.Nelements());
    cmds[i++] = new HLXUnitTestCmdInfoDisp<HLXStringTest>(
        this,
        "ReleaseBuffer1",
        &HLXStringTest::HandleReleaseBufferCmd,
        3);                     // ReleaseBuffer1 A|B <length>
#endif /* XXXSAB */

    HX_ASSERT(i < cmds.Nelements());
    cmds[i++] = new HLXUnitTestCmdInfoDisp<HLXStringTest>(
        this,
        "ReleaseBuffer",
        &HLXStringTest::HandleReleaseBufferCmd,
        2, 3);                  // ReleaseBuffer A|B [<length>]

    HX_ASSERT(i < cmds.Nelements());
    cmds[i++] = new HLXUnitTestCmdInfoDisp<HLXStringTest>(
        this,
        "FreeExtra",
        &HLXStringTest::HandleFreeExtraCmd,
        2);                     // FreeExtra A|B


    HX_ASSERT(i < cmds.Nelements());
    cmds[i++] = new HLXUnitTestCmdInfoDisp<HLXStringTest>(
        this,
        "GetAllocLength",
        &HLXStringTest::HandleGetAllocLengthCmd,
        3, 4);                  // GetAllocLength A|B <expected value> [<max expected>]

    HX_ASSERT(i < cmds.Nelements());
    cmds[i++] = new HLXUnitTestCmdInfoDisp<HLXStringTest>(
        this,
        "SetMinBufSize",
        &HLXStringTest::HandleSetMinBufSizeCmd,
        4);                     // SetMinBufSize A|B <new value> <expected value>
}

HLXCmdBasedTest* HLXStringTest::Clone() const
{
    return new HLXStringTest();
}

bool HLXStringTest::HandleConstruct1Cmd(const UTVector<UTString>& info)
{
    SetStringObj(info[1], new CHXString());

    return true;
}

bool HLXStringTest::HandleConstruct2Cmd(const UTVector<UTString>& info)
{
    bool ret = false;

    CHXString* pStr = GetStringObj(info[2]);

    if (!pStr)
    {
	DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", 
			  (const char*)info[2]));
    }
    else
    {
	SetStringObj(info[1], new CHXString(*pStr));

	ret = true;
    }

    return ret;
}

bool HLXStringTest::HandleConstruct3Cmd(const UTVector<UTString>& info)
{
    bool ret = false;

    char ch;
    int size;

    if (!UTParamUtil::GetChar(info[2], ch) || 
	!UTParamUtil::GetInt(info[3], size))
    {
	DPRINTF(D_ERROR, ("Failed to convert parameters\n"));
    }
    else
    {
	SetStringObj(info[1], new CHXString(ch, size));

	ret = true;
    }

    return ret;
}

bool HLXStringTest::HandleConstruct4Cmd(const UTVector<UTString>& info)
{
    SetStringObj(info[1], new CHXString((const char*)info[2]));

    return true;
}

bool HLXStringTest::HandleConstruct5Cmd(const UTVector<UTString>& info)
{
    bool ret = false;
    int size;

    if (!UTParamUtil::GetInt(info[3], size))
    {
	DPRINTF(D_ERROR, ("Failed to convert parameters\n"));
    }
    else
    {
	SetStringObj(info[1], new CHXString((const char*)(info[2]), size));

	ret = true;
    }

    return ret;
}

bool HLXStringTest::HandleConstruct6Cmd(const UTVector<UTString>& info)
{
    SetStringObj(info[1], new CHXString((const unsigned char*)(const char*)(info[2])));

    return true;
}

bool HLXStringTest::HandleGetLengthCmd(const UTVector<UTString>& info)
{
    bool ret = false;

    CHXString* pStr = GetStringObj(info[1]);
    int expected = 0;

    if (!pStr)
    {
	DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", 
			  (const char*)info[1]));
    }
    else if (!UTParamUtil::GetInt(info[2], expected))
    {
	DPRINTF(D_ERROR, ("Failed to convert parameters\n"));
    }
    else if ((int)pStr->GetLength() != expected)
    {
	DPRINTF (D_ERROR, ("Got %lu expected %d\n", 
			   (unsigned long)pStr->GetLength(), 
			   expected));
    }
    else
	ret = true;

    return ret;
}

bool HLXStringTest::HandleIsEmptyCmd(const UTVector<UTString>& info)
{
    bool ret = false;

    CHXString* pStr = GetStringObj(info[1]);
    bool expected = false;

    if (!pStr)
    {
	DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", 
			  (const char*)info[1]));
    }
    else if (!UTParamUtil::GetBool(info[2], expected))
    {
	DPRINTF(D_ERROR, ("Failed to convert parameters\n"));
    }
    else if ((pStr->IsEmpty() == TRUE) != expected)
    {
	DPRINTF(D_ERROR, ("Got %d expected %d\n", 
			  pStr->IsEmpty(),
			  expected));
    }
    else
	ret = true;

    return ret;
}

bool HLXStringTest::HandleEmptyCmd(const UTVector<UTString>& info)
{
    bool ret = false;
    CHXString* pStr = GetStringObj(info[1]);

    if (!pStr)
    {
	DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", 
			  (const char*)info[1]));
    }
    else
    {
	pStr->Empty();
	ret = true;
    }

    return ret;
}

bool HLXStringTest::HandleCharStarOpCmd(const UTVector<UTString>& info)
{
    bool ret = false;
    CHXString* pStr = GetStringObj(info[1]);
    int i;

    if (!pStr)
    {
	DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", 
			  (const char*)info[1]));
    }

    for (i = 2; i < info.Nelements(); ++i)
    {
        if (info[i] == (const char*)*pStr)
        {
            ret = true;
            break;
        }
    }

    if (! ret)
    {
	DPRINTF(D_ERROR, ("Got \"%s\" expected%s \"%s\"",
                          (const char*)*pStr,
                          info.Nelements() > 3 ? " one of" : "",
                          (const char*)info[2]));
        for (i = 3; i < info.Nelements(); ++i)
            DPRINTF(D_ERROR, (", \"%s\"", (const char*)info[i]));
        DPRINTF(D_ERROR, ("\n"));
    }

    return ret;
}

bool HLXStringTest::HandleGetAtCmd(const UTVector<UTString>& info)
{
    bool ret = false;
    CHXString* pStr = GetStringObj(info[1]);
    int index, expected, got;

    if (!pStr)
    {
	DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", 
			  (const char*)info[1]));
    }
    else if (!UTParamUtil::GetInt(info[2], index))
    {
	DPRINTF(D_ERROR, ("Failed to convert parameters\n"));
    }
    else if ((got = pStr->GetAt(index)) != (expected = *((const char*)info[3])))
    {
        DPRINTF(D_ERROR, ("HLXStringTest::GetAt: Got %c[0x%02x] expected %c[0x%02x]\n",
                          got, got, expected, expected));
    }
    else ret = true;

    return ret;
}

bool HLXStringTest::HandleSetAtCmd(const UTVector<UTString>& info)
{
    bool ret = false;
    CHXString* pStr = GetStringObj(info[1]);
    int index;

    if (!pStr)
    {
	DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", 
			  (const char*)info[1]));
    }
    else if (!UTParamUtil::GetInt(info[2], index))
    {
	DPRINTF(D_ERROR, ("Failed to convert parameters\n"));
    }
    else
    {
        ret = true;
        pStr->SetAt(index, *((const char*)info[3]));
    }

    return ret;
}

#define SUBTEST(TYPE) \
    if ((got = (*pStr)[(TYPE)index]) != expected) { \
        DPRINTF(D_ERROR, ("operator[](" #TYPE "): Got %c[0x%02x] expected %c[0x%02x]\n", \
                          got, got, expected, expected)); \
        ret = false; \
    }
bool HLXStringTest::HandleSubscriptCmd(const UTVector<UTString>& info)
{
    bool ret = false;
    CHXString* pStr = GetStringObj(info[1]);
    int index;

    if (!pStr)
    {
	DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", 
			  (const char*)info[1]));
    }
    else if (!UTParamUtil::GetInt(info[2], index))
    {
	DPRINTF(D_ERROR, ("Failed to convert parameters\n"));
    }
    else
    {
        // cycle through various subscript types and make sure that they
        // all work.
        char expected = *((const char*)info[3]);
        char got;
        ret = true;

        SUBTEST(short);
        SUBTEST(unsigned short);
        SUBTEST(int);
        SUBTEST(unsigned int);
        SUBTEST(long);
        SUBTEST(unsigned long);
    }

    return ret;
}
#undef SUBTEST

bool HLXStringTest::HandleAssignOp1Cmd(const UTVector<UTString>& info)
{
    bool ret = true;
    CHXString* pDest = GetStringObj(info[1]);
    CHXString* pSrc = GetStringObj(info[2]);

    if (!pDest)
    {
	DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", 
			  (const char*)info[1]));
        ret = false;
    }
    if (!pSrc)
    {
	DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", 
			  (const char*)info[2]));
        ret = false;
    }

    if (ret)
    {
        const CHXString& result = (*pDest = *pSrc);
        if (&result != pDest)
        {
            DPRINTF(D_ERROR, ("operator=(const CHXString&) didn't return object: got %p expected %p\n",
                              &result, pDest));
            ret = false;
        }
    }

    return ret;
}

bool HLXStringTest::HandleAssignOp2Cmd(const UTVector<UTString>& info)
{
    bool ret = false;
    CHXString* pStr = GetStringObj(info[1]);
    char ch = 0;

    if (!pStr)
    {
	DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", 
			  (const char*)info[1]));
    }
    else if (!UTParamUtil::GetChar(info[2], ch))
    {
	DPRINTF(D_ERROR, ("Failed to convert parameters\n"));
    }
    else
    {
        const CHXString& result = (*pStr = ch);
        if (&result != pStr)
        {
            DPRINTF(D_ERROR, ("operator=(char) didn't return object: got %p expected %p\n",
                              &result, pStr));
        }
        else ret = true;
    }

    return ret;
}

bool HLXStringTest::HandleAssignOp3Cmd(const UTVector<UTString>& info)
{
    bool ret = false;
    CHXString* pStr = GetStringObj(info[1]);

    if (!pStr)
    {
	DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", 
			  (const char*)info[1]));
    }
    else
    {
        const CHXString& result = (*pStr = (const char*)info[2]);
        if (&result != pStr)
        {
            DPRINTF(D_ERROR, ("operator=(char) didn't return object: got %p expected %p\n",
                              &result, pStr));
        }
        else ret = true;
    }

    return ret;
}

bool HLXStringTest::HandleAssignOp4Cmd(const UTVector<UTString>& info)
{
    bool ret = false;
    CHXString* pStr = GetStringObj(info[1]);

    if (!pStr)
    {
	DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", 
			  (const char*)info[1]));
    }
    else
    {
        const CHXString& result = (*pStr = (const unsigned char*)(const char*)info[2]);
        if (&result != pStr)
        {
            DPRINTF(D_ERROR, ("operator=(char) didn't return object: got %p expected %p\n",

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -