📄 slist_test.cpp
字号:
if (!GetList(info[1], list)) { DPRINTF(D_ERROR, ("npSList::HandleAddTailListCmd : failed to convert parameter\n")); } else { m_list.AddTail(&list); ret = true; } return ret;}bool HLXSListTest::HandleRemoveAllCmd(const UTVector<UTString>& /*info*/){ m_list.RemoveAll(); return true;}bool HLXSListTest::HandleGetHeadPosCmd(const UTVector<UTString>& /*info*/){ m_pos = m_list.GetHeadPosition(); return true;}bool HLXSListTest::HandleGetTailPosCmd(const UTVector<UTString>& /*info*/){ m_pos = m_list.GetTailPosition(); return true;}bool HLXSListTest::HandleGetNextCmd(const UTVector<UTString>& info){ bool ret = false; int expected = 0; int result = 0; if (!UTParamUtil::GetInt(info[1], expected)) { DPRINTF(D_ERROR, ("npSList::HandleGetNextCmd : failed to convert parameter\n")); } else if (!GetValue(m_list.GetNext(m_pos), result)) { DPRINTF(D_ERROR, ("npSList::HandleGetNextCmd : failed to get value\n")); } else if (result != expected) { DPRINTF(D_ERROR, ("npSList::HandleGetNextCmd : got %d expected %d\n", result, expected)); } else ret = true; return ret;}bool HLXSListTest::HandleReplaceNextCmd(const UTVector<UTString>& info){ bool ret = false; int value = 0; if (!UTParamUtil::GetInt(info[1], value)) { DPRINTF(D_ERROR, ("npSList::HandleReplaceNextCmd : failed to convert parameter\n")); } else { LISTPOSITION tmpPos = m_pos; DestroyValue(m_list.GetNext(tmpPos)); m_list.GetNext(m_pos) = CreateValue(value); ret = true; } return ret;}bool HLXSListTest::HandleGetPrevCmd(const UTVector<UTString>& info){ bool ret = false; int expected = 0; int result = 0; if (!UTParamUtil::GetInt(info[1], expected)) { DPRINTF(D_ERROR, ("npSList::HandleGetPrevCmd : failed to convert parameter\n")); } else if (!GetValue(m_list.GetPrev(m_pos), result)) { DPRINTF(D_ERROR, ("npSList::HandleGetPrevCmd : failed to get value\n")); } else if (result != expected) { DPRINTF(D_ERROR, ("npSList::HandleGetPrevCmd : got %d expected %d\n", result, expected)); } else ret = true; return ret;}bool HLXSListTest::HandleReplacePrevCmd(const UTVector<UTString>& info){ bool ret = false; int value = 0; if (!UTParamUtil::GetInt(info[1], value)) { DPRINTF(D_ERROR, ("npSList::HandleReplacePrevCmd : failed to convert parameter\n")); } else { LISTPOSITION tmpPos = m_pos; DestroyValue(m_list.GetPrev(tmpPos)); m_list.GetPrev(m_pos) = CreateValue(value); ret = true; } return ret;}bool HLXSListTest::HandleGetAtNextCmd(const UTVector<UTString>& info){ bool ret = false; bool expectValid = false; int expected = 0; if (!UTParamUtil::GetBool(info[1], expectValid) || !UTParamUtil::GetInt(info[2], expected)) { DPRINTF(D_ERROR, ("npSList::HandleGetAtNextCmd : failed to convert parameter\n")); } else { int result = 0; bool resultValid = GetValue(m_list.GetAtNext(m_pos), result); if (expectValid != resultValid) { DPRINTF(D_ERROR, ("npSList::HandleGetAtNextCmd : got valid=%d expected valid=%d\n", resultValid, expectValid)); } else if (expectValid && (result != expected)) { DPRINTF(D_ERROR, ("npSList::HandleGetAtNextCmd : got %d expected %d\n", result, expected)); } else ret = true; } return ret;}bool HLXSListTest::HandleGetAtPrevCmd(const UTVector<UTString>& info){ bool ret = false; bool expectValid = false; int expected = 0; if (!UTParamUtil::GetBool(info[1], expectValid) || !UTParamUtil::GetInt(info[2], expected)) { DPRINTF(D_ERROR, ("npSList::HandleGetAtPrevCmd : failed to convert parameter\n")); } else { int result = 0; bool resultValid = GetValue(m_list.GetAtPrev(m_pos), result); if (expectValid != resultValid) { DPRINTF(D_ERROR, ("npSList::HandleGetAtPrevCmd : got valid=%d expected valid=%d\n", resultValid, expectValid)); } else if (expectValid && (result != expected)) { DPRINTF(D_ERROR, ("npSList::HandleGetAtPrevCmd : got %d expected %d\n", result, expected)); } else ret = true; } return ret;}bool HLXSListTest::HandleReplaceAtPrevCmd(const UTVector<UTString>& info){ bool ret = false; int value = 0; if (!UTParamUtil::GetInt(info[1], value)) { DPRINTF(D_ERROR, ("npSList::HandleReplaceAtPrevCmd : failed to convert parameter\n")); } else { LISTPOSITION tmpPos = m_pos; DestroyValue(m_list.GetAtPrev(tmpPos)); m_list.GetAtPrev(m_pos) = CreateValue(value); ret = true; } return ret;}bool HLXSListTest::HandleGetAtCmd(const UTVector<UTString>& info){ bool ret = false; int expected = 0; if (!UTParamUtil::GetInt(info[1], expected)) { DPRINTF(D_ERROR, ("npSList::HandleGetAtCmd : failed to convert parameter\n")); } else { int result = 0; if (!GetValue(m_list.GetAt(m_pos), result)) { DPRINTF(D_ERROR, ("npSList::HandleGetAtCmd : invalid value\n")); } else if (result != expected) { DPRINTF(D_ERROR, ("npSList::HandleGetAtCmd : got %d expected %d\n", result, expected)); } else ret = true; } return ret;}bool HLXSListTest::HandleReplaceAtCmd(const UTVector<UTString>& info){ bool ret = false; int value = 0; if (!UTParamUtil::GetInt(info[1], value)) { DPRINTF(D_ERROR, ("npSList::HandleReplaceAtCmd : failed to convert parameter\n")); } else { DestroyValue(m_list.GetAt(m_pos)); m_list.GetAt(m_pos) = CreateValue(value); ret = true; } return ret;}bool HLXSListTest::HandleSetAtCmd(const UTVector<UTString>& info){ bool ret = false; int value = 0; if (!UTParamUtil::GetInt(info[1], value)) { DPRINTF(D_ERROR, ("npSList::HandleSetAtCmd : failed to convert parameter\n")); } else { DestroyValue(m_list.GetAt(m_pos)); m_list.SetAt(m_pos, CreateValue(value)); ret = true; } return ret;}bool HLXSListTest::HandleRemoveAtCmd(const UTVector<UTString>& /*info*/){ m_pos = m_list.RemoveAt(m_pos); return true;}bool HLXSListTest::HandleInsertBeforeCmd(const UTVector<UTString>& info){ bool ret = false; int value = 0; if (!UTParamUtil::GetInt(info[1], value)) { DPRINTF(D_ERROR, ("npSList::HandleInsertBeforeCmd : failed to convert parameter\n")); } else { m_pos = m_list.InsertBefore(m_pos, CreateValue(value)); ret = true; } return ret;}bool HLXSListTest::HandleInsertAfterCmd(const UTVector<UTString>& info){ bool ret = false; int value = 0; if (!UTParamUtil::GetInt(info[1], value)) { DPRINTF(D_ERROR, ("npSList::HandleInsertAfterCmd : failed to convert parameter\n")); } else { m_pos = m_list.InsertAfter(m_pos, CreateValue(value)); ret = true; } return ret;}bool HLXSListTest::HandleFindCmd(const UTVector<UTString>& info){ bool ret = false; int value = 0; bool useCurrentPos = false; if (!UTParamUtil::GetInt(info[1], value) || !UTParamUtil::GetBool(info[2], useCurrentPos)) { DPRINTF(D_ERROR, ("npSList::HandleFindCmd : failed to convert parameter\n")); } else { LISTPOSITION pos = (useCurrentPos) ? m_pos : m_list.GetHeadPosition(); void* pValue = 0; bool destroyValue = FindValue(value, pos, pValue); if (useCurrentPos) m_pos = m_list.Find(pValue, pos); else m_pos = m_list.Find(pValue); if (destroyValue) DestroyValue(pValue); ret = true; } return ret;}bool HLXSListTest::HandleFindIndexCmd(const UTVector<UTString>& info){ bool ret = false; int index = 0; if (!UTParamUtil::GetInt(info[1], index)) { DPRINTF(D_ERROR, ("npSList::HandleFindCmd : failed to convert parameter\n")); } else { m_pos = m_list.FindIndex(index); ret = true; } return ret;}bool HLXSListTest::HandleIsPosValidCmd(const UTVector<UTString>& info){ bool ret = false; bool expected = false; if (!UTParamUtil::GetBool(info[1], expected)) { DPRINTF(D_ERROR, ("npSList::HandleIsPosValidCmd : failed to convert parameter\n")); } else { bool result = (m_pos != 0); if (result != expected) { DPRINTF(D_ERROR, ("npSList::HandleIsPosValidCmd : got %d expected %d\n", result, expected)); } else ret = true; } return ret;}bool HLXSListTest::HandleClearPosCmd(const UTVector<UTString>& /*info*/){ m_pos = 0; return true;}bool HLXSListTest::HandleTestIteratorCmd(const UTVector<UTString>& /*info*/){ bool ret = true; LISTPOSITION pos = m_list.GetHeadPosition(); CHXSimpleList::Iterator itr = m_list.Begin(); for(; ret && (itr != m_list.End()) && pos; ++itr) { int expected = 0; int result = 0; if (!GetValue(m_list.GetNext(pos), expected)) { DPRINTF (D_ERROR,("HLXSListTest::HandleTestIteratorCmd() : failed to get expected value\n")); ret = false; } else if (!GetValue(*itr, result)) { DPRINTF (D_ERROR,("HLXSListTest::HandleTestIteratorCmd() : failed to get result value\n")); ret = false; } else if (expected != result) { DPRINTF (D_ERROR,("HLXSListTest::HandleTestIteratorCmd() : got %d expected %d\n", result, expected)); ret = false; } } if (ret) { // The comparisons are arranged this way so // that I can test the == operator if (itr == m_list.End()) { if (pos != 0) { DPRINTF (D_ERROR,("HLXSListTest::HandleTestIteratorCmd() : Position is not at the end\n")); ret = false; } } else { DPRINTF (D_ERROR,("HLXSListTest::HandleTestIteratorCmd() : iterator not at the end\n")); ret = false; } } return ret;}bool HLXSListTest::HandleDumpCmd(const UTVector<UTString>& info){ if (info.Nelements() >= 2) m_list.Dump((const char*)info[1]); else m_list.Dump(); return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -