📄 string_test.cpp
字号:
if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else ret = HandleFormat<char>(*pStr, info, UTParamUtil::GetChar); return ret;}bool HLXStringTest::HandleFormatCharStarCmd(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 ret = HandleFormat<const char*>(*pStr, info, GetCharStar); return ret;}bool HLXStringTest::HandleFormatPtrCmd(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 ret = HandleFormat<void*>(*pStr, info, GetPtr); return ret;}bool HLXStringTest::HandleFormatDoubleCmd(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 ret = HandleFormat<double>(*pStr, info, UTParamUtil::GetDouble); return ret;}bool HLXStringTest::HandleFormatMixedCmd(const UTVector<UTString>& /*info*/){ CHXString str; // XXXSAB - now what??? const char* expected = ""; char* ptr = (char*)0x60616263; str.Format ("%p,%d,%u,%c", ptr, (int)ptr, (unsigned int)ptr, (char)ptr);#ifdef _WINDOWS expected = "60616263,1616994915,1616994915,c";#else expected = "0x60616263,1616994915,1616994915,c";#endif /* _WINDOWS */ if (str != expected) { DPRINTF(D_ERROR, ("FormatMixed #1: Got \"%s\" expected \"%s\"\n", (const char*)str, expected)); return false; } ptr = 0; str.Format ("%p,%p,%p,%p", ptr, ptr+1, ptr+2, ptr+3);#ifdef _WINDOWS expected = "00000000,00000001,00000002,00000003";#elif defined(_SYMBIAN) expected = "0x0,0x1,0x2,0x3";#else expected = "(nil),0x1,0x2,0x3";#endif /* _WINDOWS */ if (str != expected) { DPRINTF(D_ERROR, ("FormatMixed #2: Got \"%s\" expected \"%s\"\n", (const char*)str, expected)); return false; } str.Format ("%6d,%5u,%x", 1,1,1); expected = " 1, 1,1"; if (str != expected) { DPRINTF(D_ERROR, ("FormatMixed #3: Got \"%s\" expected \"%s\"\n", (const char*)str, expected)); return false; } return true;}bool HLXStringTest::HandleAppendULONGCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); unsigned int value; if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else if (!UTParamUtil::GetUInt(info[2], value)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); } else { ret = true; pStr->AppendULONG((ULONG32)value); } return ret;}bool HLXStringTest::HandleAppendEndOfLineCmd(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 { UINT32 beforeLength = pStr->GetLength(); pStr->AppendEndOfLine(); // Check that the proper EOL sequence was added if (pStr->IsEmpty()) { DPRINTF(D_ERROR, ("Failed to add EOL sequence: string is now empty\n")); } else { const char* pEnd = (const char*)*pStr + pStr->GetLength() - 1;#if defined(_UNIX) ret = (*pEnd == '\n') && (pStr->GetLength() == (beforeLength+1));#elif defined(_MACINTOSH) ret = (*pEnd == '\r') && (pStr->GetLength() == (beforeLength+1));#elif defined(_WINDOWS) || defined(_SYMBIAN) ret = (*(pEnd-1) == '\r' && *pEnd == '\n') && (pStr->GetLength() == (beforeLength+2));#else ret = (*pEnd == '\n') && (pStr->GetLength() == (beforeLength+1));#endif if (!ret) { DPRINTF(D_ERROR, ("Failed to add EOL: got \"%s\"\n", (const char*)*pStr)); } } } return ret;}bool HLXStringTest::HandleGetBufferCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); int length; if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else if (!UTParamUtil::GetInt(info[2], length)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); } else { // NOTE: If didn't get at least 4 elements in 'info', then we // don't care what's in the returned buffer... char*& p = (pStr == m_pA ? m_pABuffer : m_pBBuffer); p = pStr->GetBuffer(length); if (!p) DPRINTF(D_ERROR, ("Got NULL from GetBuffer()\n")); else if (info.Nelements() >= 4 && strcmp(p, (const char*)info[3]) != 0) { DPRINTF(D_ERROR, ("Got \"%s\" expected \"%s\"\n", p, (const char*)info[3])); } else ret = true; } return ret;}bool HLXStringTest::HandleGetBufferSetLengthCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); int length; if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else if (!UTParamUtil::GetInt(info[2], length)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); } else { // NOTE: If didn't get at least 4 elements in 'info', then we // don't care what's in the returned buffer... char*& p = (pStr == m_pA ? m_pABuffer : m_pBBuffer); p = pStr->GetBufferSetLength(length); if (!p) DPRINTF(D_ERROR, ("Got NULL from GetBuffer()\n")); else if (info.Nelements() >= 4 && strcmp(p, (const char*)info[3]) != 0) { DPRINTF(D_ERROR, ("Got \"%s\" expected \"%s\"\n", p, (const char*)info[3])); } else ret = true; } return ret;}bool HLXStringTest::HandleBufferSetCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); int index = 0; if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else if (info.Nelements() >= 4 && !UTParamUtil::GetInt(info[2], index)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); } else { char* p = (pStr == m_pA ? m_pABuffer : m_pBBuffer); const char* pValue = (const char*)info[info.Nelements()-1]; memcpy (p+index, pValue, strlen(pValue)); /* Flawfinder: ignore */ ret = true; } return ret;}bool HLXStringTest::HandleBufferFillCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); int index = 0; int repeat = 0; if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else if (!UTParamUtil::GetInt(info[info.Nelements() - 1], repeat) || (info.Nelements() >= 5 && !UTParamUtil::GetInt(info[2], index))) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); } else { char* p = (pStr == m_pA ? m_pABuffer : m_pBBuffer); const char* pValue = (const char*)info[info.Nelements()-2]; size_t len = strlen(pValue); for (p += index; repeat > 0; p += len, --repeat) memcpy (p, pValue, len); /* Flawfinder: ignore */ ret = true; } return ret;}bool HLXStringTest::HandleBufferEndStringCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); int index = 0; 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 { char* p = (pStr == m_pA ? m_pABuffer : m_pBBuffer); *(p+index) = 0; ret = true; } return ret;}bool HLXStringTest::HandleReleaseBufferCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); int length = -9999; if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else if (info.Nelements() >= 3 && !UTParamUtil::GetInt(info[2], length)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); } else { ret = true; if (length == -9999) pStr->ReleaseBuffer(); else pStr->ReleaseBuffer(length); if (pStr == m_pA) m_pABuffer = 0; else m_pBBuffer = 0; } return ret;}bool HLXStringTest::HandleFreeExtraCmd(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 { ret = true; pStr->FreeExtra(); } return ret;}bool HLXStringTest::HandleGetAllocLengthCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); int expected, maxExpected = -1; if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else if (!UTParamUtil::GetInt(info[2], expected) || (info.Nelements() >= 4 && !UTParamUtil::GetInt(info[3], maxExpected))) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); } else if (pStr->GetAllocLength() < expected || pStr->GetAllocLength() > (maxExpected > expected ? maxExpected : expected)) { if (maxExpected > expected) DPRINTF (D_ERROR, ("Got %d expected %d..%d\n", pStr->GetAllocLength(), expected, maxExpected)); else DPRINTF (D_ERROR, ("Got %d expected %d\n", pStr->GetAllocLength(), expected)); } else ret = true; return ret;}bool HLXStringTest::HandleSetMinBufSizeCmd(const UTVector<UTString>& info){ bool ret = false; CHXString* pStr = GetStringObj(info[1]); int value, expected; if (!pStr) { DPRINTF(D_ERROR, ("Failed to get the string object '%s'\n", (const char*)info[1])); } else if (!UTParamUtil::GetInt(info[2], value) || !UTParamUtil::GetInt(info[3], expected)) { DPRINTF(D_ERROR, ("Failed to convert parameters\n")); } else { INT32 got = pStr->SetMinBufSize(value); if (got == expected) ret = true; else DPRINTF (D_ERROR, ("Got %d expected %d\n", got, expected)); } return ret;}CHXString* HLXStringTest::GetStringObj(const UTString& strName){ CHXString* pRet = 0; if (strName == "A") pRet = m_pA; else if (strName == "B") pRet = m_pB; else { DPRINTF(D_ERROR, ("GetStringObj() : get '%s' failed\n", (const char*)strName)); } return pRet;}void HLXStringTest::SetStringObj(const UTString& strName, CHXString* pNewStr){ if (strName == "A") { delete m_pA; m_pA = pNewStr; } else if (strName == "B") { delete m_pB; m_pB = pNewStr; } else DPRINTF(D_ERROR, ("SetStringObj() : set '%s' failed\n", (const char*)strName));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -