4
好吧,我基本上想要讓球滾動並寫一些CPPUnit測試,但我不知道如何去做。在這裏,我有一些代碼基本上獲得了一個指向相關按鈕組和位置參數的菜單按鈕的指針,我將如何去爲此創建一個測試?CPPUnit如何編寫測試?
CMenuButton* CMenuContainer::GetButton(const enumButtonGroup argGroup, const int32_t argPosition)
{
CMenuButton* pButton = NULL;
if (argGroup < MAX_GROUP_BUTTONS)
{
pButton = m_ButtonGroupList[argGroup].GetButton(argPosition);
}
return pButton;
回覆@Fabio Ceconello,是否可以爲這樣的代碼設置一些測試?
unsigned long CCRC32::Reflect(unsigned long ulReflect, const char cChar)
{
unsigned long ulValue = 0;
// Swap bit 0 for bit 7, bit 1 For bit 6, etc....
for(int iPos = 1; iPos < (cChar + 1); iPos++)
{
if(ulReflect & 1)
{
ulValue |= (1 << (cChar - iPos));
}
ulReflect >>= 1;
}
return ulValue;
}
我已經回答了你,在我的主要問題添加一些代碼。 – bigbaz34
感謝您的幫助。我是這些cppunit測試的完全新手,我如何才能真正實現它?包括陳述? #include cppunit.h什麼的? – bigbaz34
是的,抱歉沒有提及它,我跳過了準備部分。 CPPUnit使用每個類一個頭的約定,並且頭名與相應的類相同。所以在上面的例子中你需要#include TestCase.h,TestRunner.h和TestCaller.h –