[Cppunit-devel] cppunit
Brought to you by:
blep
From: Martin F. <mar...@gm...> - 2001-11-20 23:13:17
|
Hi! I can tell the cause of the problem with the failed "ExceptionTest.testAssignment" test in CppUnit test suite using VC++, which you metioned in your FAQ document of cppunit-1.6.2. The exception assignment operator is internally implemented as something like this: (Unfortunatelly I couldn't find the source could in the MSVCRT files, so I had to look at the assembler code with the debugger.) exception& std::exception::operator=(const exception& other) { if (&other != this) { this->~exception(); exception(other); } return *this; } While calling the destructor the virtual function pointer ist overwritten with that of the base class. This is the cause, why afterwards calling what() calls std::exception::what(), not CppUnit::Exception::what(), like expected. There seem to be two solutions. One would be to overwrite the without calling the destructor: exception& std::exception::operator=(const exception& other) { if (&other != this) { // this->~exception(); exception(other); } return *this; } But this way we get the warning message:" warning C4273: '=' : inconsistent dll linkage. dllexport assumed." I think the best way is not to call std::exeption::operator=() at all: Exception& Exception::operator=( const Exception& other ) { //SuperClass::operator= (other); if (&other != this) { m_message = other.m_message; m_lineNumber = other.m_lineNumber; m_fileName = other.m_fileName; } return *this; } It isn't necesarry anyway, because you dont't use any members variables of std::excpetion. There is also a solution for sucessfully using the list control style LVS_EX_FULLROWSELECT in TestRunnerDlg.cpp: ListView_SetExtendedListViewStyleEx(m_listCtrl, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT); This way it works like expected. LVS_EX_FULLROWSELECT isn't a traditional attribut one can set using GWL_EXSTYLE. But something special to COMCTL32.DLL. I've another suggestment: You should add the "const" attribute to the functions Exception::lineNumber() and Exception::fileName(). So you can use constant references in: ExceptionTest::checkIsSame(CppUnit::Exception &e, const CppUnit::Exception &other) I frist heared of your project yesterday. It seems very interesting for me. May be I will use it in my next project to see if really can make live easier... :-) cu, Martin Fuchs |