ブーストユニットテストについて学んでいますが、メモリリークを検出できることがわかったので、テストしています。私は次の恐ろしい方法を作成しました:
int ForTest::Compare(const ForTest item)
{
ForTest* existing_item = this;
char* x=new char[1024];
m_name = std::string(x);
if (existing_item->m_count * existing_item->m_price == item.m_count * item.m_price) return 0;
if (existing_item->m_count * existing_item->m_price > item.m_count * item.m_price) return 1;
return -1;
}
BOOST_AUTO_TEST_CASE( a_test_case)
{
BOOST_TEST_CHECKPOINT("weird...");
ForTest alpha("Pen", 4, 4.3);
ForTest beta;
BOOST_CHECK_EQUAL(alpha.Compare(beta), 1);
}
私は明らかにここで2つのメモリリークを作成しています。テスターが気にしないのはなぜですか?私のテストは飛んでいる色で合格します。
ここで見たように、実際のコードを変更する必要はありません:http ://www.boost.org/doc/libs/1_35_0/libs/test/example/exec_mon_example.cpp
エラーが発生しないのはなぜですか?