mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Define EIGEN_TRY, EIGEN_CATCH, EIGEN_THROW as suggested by Moritz Klammer.
Make it possible to run unit-tests with exceptions disabled via EIGEN_TEST_NO_EXCEPTIONS flag. Enhanced ctorleak unit-test
This commit is contained in:
@@ -158,7 +158,9 @@ ei_add_test(basicstuff)
|
||||
ei_add_test(linearstructure)
|
||||
ei_add_test(integer_types)
|
||||
ei_add_test(unalignedcount)
|
||||
ei_add_test(exceptions)
|
||||
if(NOT EIGEN_TEST_NO_EXCEPTIONS)
|
||||
ei_add_test(exceptions)
|
||||
endif()
|
||||
ei_add_test(redux)
|
||||
ei_add_test(visitor)
|
||||
ei_add_test(block)
|
||||
@@ -238,7 +240,9 @@ ei_add_test(nesting_ops "${CMAKE_CXX_FLAGS_DEBUG}")
|
||||
ei_add_test(zerosized)
|
||||
ei_add_test(dontalign)
|
||||
ei_add_test(evaluators)
|
||||
ei_add_test(sizeoverflow)
|
||||
if(NOT EIGEN_TEST_NO_EXCEPTIONS)
|
||||
ei_add_test(sizeoverflow)
|
||||
endif()
|
||||
ei_add_test(prec_inverse_4x4)
|
||||
ei_add_test(vectorwiseop)
|
||||
ei_add_test(special_numbers)
|
||||
@@ -251,8 +255,6 @@ ei_add_test(bicgstab)
|
||||
ei_add_test(sparselu)
|
||||
ei_add_test(sparseqr)
|
||||
|
||||
ei_add_test(ctorleak)
|
||||
|
||||
# ei_add_test(denseLM)
|
||||
|
||||
if(QT4_FOUND)
|
||||
|
||||
@@ -28,42 +28,24 @@ struct Foo
|
||||
unsigned Foo::object_count = 0;
|
||||
unsigned Foo::object_limit = 0;
|
||||
|
||||
namespace Eigen
|
||||
{
|
||||
template<>
|
||||
struct NumTraits<Foo>
|
||||
{
|
||||
typedef double Real;
|
||||
typedef double NonInteger;
|
||||
typedef double Nested;
|
||||
enum
|
||||
{
|
||||
IsComplex = 0,
|
||||
IsInteger = 1,
|
||||
ReadCost = -1,
|
||||
AddCost = -1,
|
||||
MulCost = -1,
|
||||
IsSigned = 1,
|
||||
RequireInitialization = 1
|
||||
};
|
||||
static inline Real epsilon() { return 1.0; }
|
||||
static inline Real dummy_epsilon() { return 0.0; }
|
||||
};
|
||||
}
|
||||
|
||||
void test_ctorleak()
|
||||
{
|
||||
typedef DenseIndex Index;
|
||||
Foo::object_count = 0;
|
||||
Foo::object_limit = internal::random(0, 14 * 92 - 2);
|
||||
for(int i = 0; i < g_repeat; i++) {
|
||||
Index rows = internal::random<Index>(2,EIGEN_TEST_MAX_SIZE), cols = internal::random<Index>(2,EIGEN_TEST_MAX_SIZE);
|
||||
Foo::object_limit = internal::random(0, rows*cols - 2);
|
||||
#ifdef EIGEN_EXCEPTIONS
|
||||
try
|
||||
#endif
|
||||
try
|
||||
{
|
||||
Matrix<Foo, Dynamic, Dynamic> m(14, 92);
|
||||
eigen_assert(false); // not reached
|
||||
}
|
||||
#ifdef EIGEN_EXCEPTIONS
|
||||
catch (const Foo::Fail&) { /* ignore */ }
|
||||
#endif
|
||||
Matrix<Foo, Dynamic, Dynamic> m(rows, cols);
|
||||
#ifdef EIGEN_EXCEPTIONS
|
||||
VERIFY(false); // not reached if exceptions are enabled
|
||||
}
|
||||
catch (const Foo::Fail&) { /* ignore */ }
|
||||
#endif
|
||||
}
|
||||
VERIFY_IS_EQUAL(static_cast<unsigned>(0), Foo::object_count);
|
||||
}
|
||||
|
||||
16
test/main.h
16
test/main.h
@@ -117,13 +117,14 @@ namespace Eigen
|
||||
if(report_on_cerr_on_assert_failure) \
|
||||
std::cerr << #a << " " __FILE__ << "(" << __LINE__ << ")\n"; \
|
||||
Eigen::no_more_assert = true; \
|
||||
throw Eigen::eigen_assert_exception(); \
|
||||
EIGEN_THROW_X(Eigen::eigen_assert_exception()); \
|
||||
} \
|
||||
else if (Eigen::internal::push_assert) \
|
||||
{ \
|
||||
eigen_assert_list.push_back(std::string(EI_PP_MAKE_STRING(__FILE__) " (" EI_PP_MAKE_STRING(__LINE__) ") : " #a) ); \
|
||||
}
|
||||
|
||||
#ifdef EIGEN_EXCEPTIONS
|
||||
#define VERIFY_RAISES_ASSERT(a) \
|
||||
{ \
|
||||
Eigen::no_more_assert = false; \
|
||||
@@ -142,6 +143,7 @@ namespace Eigen
|
||||
Eigen::report_on_cerr_on_assert_failure = true; \
|
||||
Eigen::internal::push_assert = false; \
|
||||
}
|
||||
#endif //EIGEN_EXCEPTIONS
|
||||
|
||||
#elif !defined(__CUDACC__) // EIGEN_DEBUG_ASSERTS
|
||||
// see bug 89. The copy_bool here is working around a bug in gcc <= 4.3
|
||||
@@ -152,9 +154,10 @@ namespace Eigen
|
||||
if(report_on_cerr_on_assert_failure) \
|
||||
eigen_plain_assert(a); \
|
||||
else \
|
||||
throw Eigen::eigen_assert_exception(); \
|
||||
EIGEN_THROW_X(Eigen::eigen_assert_exception()); \
|
||||
}
|
||||
#define VERIFY_RAISES_ASSERT(a) { \
|
||||
#ifdef EIGEN_EXCEPTIONS
|
||||
#define VERIFY_RAISES_ASSERT(a) { \
|
||||
Eigen::no_more_assert = false; \
|
||||
Eigen::report_on_cerr_on_assert_failure = false; \
|
||||
try { \
|
||||
@@ -164,9 +167,14 @@ namespace Eigen
|
||||
catch (Eigen::eigen_assert_exception&) { VERIFY(true); } \
|
||||
Eigen::report_on_cerr_on_assert_failure = true; \
|
||||
}
|
||||
|
||||
#endif //EIGEN_EXCEPTIONS
|
||||
#endif // EIGEN_DEBUG_ASSERTS
|
||||
|
||||
#ifndef VERIFY_RAISES_ASSERT
|
||||
#define VERIFY_RAISES_ASSERT(a) \
|
||||
std::cout << "Can't VERIFY_RAISES_ASSERT( " #a " ) with exceptions disabled";
|
||||
#endif
|
||||
|
||||
#if !defined(__CUDACC__)
|
||||
#define EIGEN_USE_CUSTOM_ASSERT
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user