【发布时间】:2012-10-13 02:47:09
【问题描述】:
我正在学习 boost 单元测试,我很高兴地发现它可以检测内存泄漏,所以我正在测试它。我创建了以下可怕的方法:
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
为什么我没有收到错误消息?
【问题讨论】:
-
您在哪个平台上运行? Boost Execution Monitor 内存泄漏检测仅适用于某些平台。
标签: c++ unit-testing boost