📄 string_test.cpp
字号:
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", &result, pStr)); } else ret = true; } return ret;}bool HLXStringTest::HandleAppendTo1Cmd(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::HandleAppendTo2Cmd(const UTVector<UTString>& info){ bool ret = true; 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=(const CHXString&) didn't return object: got %p expected %p\n", &result, pStr)); ret = false; } } return ret;}bool HLXStringTest::HandleAppendTo3Cmd(const UTVector<UTString>& info){ bool ret = true; 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=(const CHXString&) didn't return object: got %p expected %p\n", &result, pStr)); ret = false; } } return ret;}bool HLXStringTest::HandleAdd1Cmd(const UTVector<UTString>& info){ bool ret = true; CHXString* pStr1 = GetStringObj(info[1]); CHXString* pStr2 = GetStringObj(info[2]); if (!pStr1) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); ret = false; } if (!pStr2) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[2])); ret = false; } if (ret) { CHXString got = *pStr1 + *pStr2; if (strcmp (got, (const char*)info[3]) != 0) { DPRINTF(D_ERROR, ("Got \"%s\" expected \"%s\"\n", (const char*)got, (const char*)info[3])); ret = false; } } return ret;}bool HLXStringTest::HandleAdd2Cmd(const UTVector<UTString>& info){ bool ret = true; CHXString* pStr1 = GetStringObj(info[1]); if (!pStr1) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); ret = false; } if (ret) { CHXString got = *pStr1 + *((const char*)info[2]); if (strcmp (got, (const char*)info[3]) != 0) { DPRINTF(D_ERROR, ("Got \"%s\" expected \"%s\"\n", (const char*)got, (const char*)info[3])); ret = false; } } return ret;}bool HLXStringTest::HandleAdd3Cmd(const UTVector<UTString>& info){ bool ret = true; CHXString* pStr2 = GetStringObj(info[2]); if (!pStr2) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[2])); ret = false; } if (ret) { CHXString got = *((const char*)info[1]) + *pStr2; if (strcmp (got, (const char*)info[3]) != 0) { DPRINTF(D_ERROR, ("Got \"%s\" expected \"%s\"\n", (const char*)got, (const char*)info[3])); ret = false; } } return ret;}bool HLXStringTest::HandleAdd4Cmd(const UTVector<UTString>& info){ bool ret = true; CHXString* pStr1 = GetStringObj(info[1]); if (!pStr1) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); ret = false; } if (ret) { CHXString got = *pStr1 + (const char*)info[2]; if (strcmp (got, (const char*)info[3]) != 0) { DPRINTF(D_ERROR, ("Got \"%s\" expected \"%s\"\n", (const char*)got, (const char*)info[3])); ret = false; } } return ret;}bool HLXStringTest::HandleAdd5Cmd(const UTVector<UTString>& info){ bool ret = true; CHXString* pStr2 = GetStringObj(info[2]); if (!pStr2) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[2])); ret = false; } if (ret) { CHXString got = (const char*)info[1] + *pStr2; if (strcmp (got, (const char*)info[3]) != 0) { DPRINTF(D_ERROR, ("Got \"%s\" expected \"%s\"\n", (const char*)got, (const char*)info[3])); ret = false; } } return ret;}bool HLXStringTest::HandleCenterCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); int len; if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else if (!UTParamUtil::GetInt(info[2], len)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); } else { pStr->Center(len); ret = true; } return ret;}bool HLXStringTest::HandleCompareCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); int expected = -9999; bool bNumberExpected = (info[3] != "-" && info[3] != "+"); if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else if (bNumberExpected && !UTParamUtil::GetInt(info[3], expected)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); } else { INT32 got = pStr->Compare(info[2]); if ((info[3] == "+" && got > 0) || (info[3] == "-" && got < 0) || (bNumberExpected && got == expected)) ret = true; else DPRINTF(D_ERROR, ("Got %d expected %s\n", got, (const char*)info[3])); } return ret;}bool HLXStringTest::HandleCompareNoCaseCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); int expected = -9999; bool bNumberExpected = (info[3] != "-" && info[3] != "+"); if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else if (bNumberExpected && !UTParamUtil::GetInt(info[3], expected)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); } else { INT32 got = pStr->CompareNoCase(info[2]); if ((info[3] == "+" && got > 0) || (info[3] == "-" && got < 0) || (bNumberExpected && got == expected)) ret = true; else DPRINTF(D_ERROR, ("Got %d expected %s\n", got, (const char*)info[3])); } return ret;}bool HLXStringTest::HandleMidCmd(const UTVector<UTString>& info){ bool ret = true; CHXString* pStr = GetStringObj(info[1]); int index; const char* expected = NULL; int length = -9999; if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); ret = false; } else if (!UTParamUtil::GetInt(info[2], index)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); ret = false; } else if (info.Nelements() == 4) { expected = (const char*)info[3]; } else if (info.Nelements() == 5) { if (!UTParamUtil::GetInt(info[3], length)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); ret = false; } else expected = (const char*)info[4]; } else { DPRINTF(D_ERROR, ("Bad number of arguments: %ld\n", (long)info.Nelements())); ret = false; } if (ret) { CHXString got = (length == -9999 ? pStr->Mid(index) : pStr->Mid(index, length)); if (strcmp(got, expected) != 0) { DPRINTF(D_ERROR, ("Got \"%s\" expected \"%s\"\n", (const char*)got, expected)); ret = false; } } return ret;}bool HLXStringTest::HandleLeftCmd(const UTVector<UTString>& info){ bool ret = true; CHXString* pStr = GetStringObj(info[1]); const char* expected = (const char*)info[3]; int length = -9999; if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); ret = false; } else if (!UTParamUtil::GetInt(info[2], length)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); ret = false; } else { CHXString got = pStr->Left(length); if (strcmp(got, expected) != 0) { DPRINTF(D_ERROR, ("Got \"%s\" expected \"%s\"\n", (const char*)got, expected)); ret = false; } } return ret;}bool HLXStringTest::HandleRightCmd(const UTVector<UTString>& info){ bool ret = true; CHXString* pStr = GetStringObj(info[1]); const char* expected = (const char*)info[3]; int length = -9999; if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); ret = false; } else if (!UTParamUtil::GetInt(info[2], length)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); ret = false; } else { CHXString got = pStr->Right(length); if (strcmp(got, expected) != 0) { DPRINTF(D_ERROR, ("Got \"%s\" expected \"%s\"\n", (const char*)got, expected)); ret = false; } } return ret;}bool HLXStringTest::HandleCountFieldsCmd(const UTVector<UTString>& info){ bool ret = true; CHXString* pStr = GetStringObj(info[1]); unsigned int expected; if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); ret = false; } else if (!UTParamUtil::GetUInt(info[3], expected)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); ret = false; } else { ULONG32 got = pStr->CountFields(*((const char*)info[2])); if (got != expected) { DPRINTF(D_ERROR, ("Got %lu expected %lu\n", (unsigned long)got, (unsigned long)expected)); ret = false; } } return ret;}bool HLXStringTest::HandleNthFieldCmd(const UTVector<UTString>& info){ bool ret = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -