请问cppunit中如何测试异常输入?
各位大侠,我最近刚开始接触单元测试,用的工具是CPPUNIT,现在遇到一难题,还请各位帮忙,谢谢了。被测函数:获得当前矩阵的指定行向量
Matrix3x3:: Vertex3d GetRowVector(int nRow) const
{
ASSERT(nRow < m_iDimM && nRow > -1);
return Vertex3d((*this),(*this),(*this));
}
我写的测试用例:
void Matrix3x3TestCase::testGetColVector()
{
Matrix3x3 mtr3x31(1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0);
Vertex3d vtx1=mtr3x31.GetColVector(0);
CPPUNIT_ASSERT_EQUAL(1.0,vtx1.x);
CPPUNIT_ASSERT_EQUAL(4.0,vtx1.y);
CPPUNIT_ASSERT_EQUAL(7.0,vtx1.z);
Vertex3d vtx2=mtr3x31.GetColVector(1);
CPPUNIT_ASSERT_EQUAL(2.0,vtx2.x);
CPPUNIT_ASSERT_EQUAL(5.0,vtx2.y);
CPPUNIT_ASSERT_EQUAL(8.0,vtx2.z);
Vertex3d vtx3=mtr3x31.GetColVector(2);
CPPUNIT_ASSERT_EQUAL(3.0,vtx3.x);
CPPUNIT_ASSERT_EQUAL(6.0,vtx3.y);
CPPUNIT_ASSERT_EQUAL(9.0,vtx3.z);
// Vertex3d vtx4;
// vtx4=mtr3x31.GetColVector(3);
// Vertex3d vtx5;
// vtx5=mtr3x31.GetColVector(-1);
}
请问,对于输入的行号为3或者-1这一类不符合要求的数字时,这类异常应该如何捕获呢?我不会在cppunit中捕获异常用例出错情况,还请各位指导! 自己顶一下,请大家帮忙指导下呢
页:
[1]