67 lines
1.9 KiB
C++
67 lines
1.9 KiB
C++
#include <mrw/exception.hpp>
|
|
#include <cppunit/TestFixture.h>
|
|
#include <cppunit/ui/text/TestRunner.h>
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
#include <cppunit/extensions/TestFactoryRegistry.h>
|
|
|
|
namespace mrw {
|
|
class AutoExcStderrTest: public CppUnit::TestFixture {
|
|
private:
|
|
bool enter_unexpectedThrow;
|
|
bool exit_unexpectedThrow;
|
|
bool enter_passUnexpected;
|
|
bool exit_passUnexpected;
|
|
bool enter_catchUnexpected;
|
|
bool exit_catchUnexpected;
|
|
public:
|
|
void setUp() {
|
|
enter_unexpectedThrow = false;
|
|
exit_unexpectedThrow = false;
|
|
enter_passUnexpected = false;
|
|
exit_passUnexpected = false;
|
|
enter_catchUnexpected = false;
|
|
exit_catchUnexpected = false;
|
|
}
|
|
void unexpectedThrow() throw(std::bad_exception) {
|
|
enter_unexpectedThrow = true;
|
|
throw mrw::exception();
|
|
exit_unexpectedThrow = true;
|
|
}
|
|
void passUnexpected() throw(std::bad_exception) {
|
|
enter_passUnexpected = true;
|
|
unexpectedThrow();
|
|
exit_passUnexpected = true;
|
|
}
|
|
void catchUnexpected() throw() {
|
|
enter_catchUnexpected = true;
|
|
bool caught(false);
|
|
try {
|
|
passUnexpected();
|
|
} catch (std::bad_exception&) {
|
|
caught = true;
|
|
}
|
|
CPPUNIT_ASSERT(caught);
|
|
exit_catchUnexpected = true;
|
|
}
|
|
void testcase() {
|
|
catchUnexpected();
|
|
CPPUNIT_ASSERT(enter_catchUnexpected &&
|
|
enter_passUnexpected &&
|
|
enter_unexpectedThrow &&
|
|
exit_catchUnexpected &&
|
|
!exit_passUnexpected &&
|
|
!exit_unexpectedThrow);
|
|
}
|
|
CPPUNIT_TEST_SUITE(AutoExcStderrTest);
|
|
CPPUNIT_TEST(testcase);
|
|
CPPUNIT_TEST_SUITE_END();
|
|
};
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(AutoExcStderrTest);
|
|
}
|
|
|
|
int main() {
|
|
CppUnit::TextUi::TestRunner runner;
|
|
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
|
return runner.run() ? 0 : 1;
|
|
}
|