mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Clang-format tests, examples, libraries, benchmarks, etc.
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
3252ecc7a4
commit
46e9cdb7fe
@@ -7,7 +7,6 @@
|
||||
// Public License v. 2.0. If a copy of the MPL was not distributed
|
||||
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
|
||||
// Various sanity tests with exceptions and non trivially copyable scalar type.
|
||||
// - no memory leak when a custom scalar type trow an exceptions
|
||||
// - todo: complete the list of tests!
|
||||
@@ -17,33 +16,37 @@
|
||||
#include "main.h"
|
||||
#include "AnnoyingScalar.h"
|
||||
|
||||
#define CHECK_MEMLEAK(OP) { \
|
||||
AnnoyingScalar::countdown = 100; \
|
||||
int before = AnnoyingScalar::instances; \
|
||||
bool exception_thrown = false; \
|
||||
try { OP; } \
|
||||
catch (my_exception) { \
|
||||
exception_thrown = true; \
|
||||
VERIFY(AnnoyingScalar::instances==before && "memory leak detected in " && EIGEN_MAKESTRING(OP)); \
|
||||
} \
|
||||
VERIFY( (AnnoyingScalar::dont_throw) || (exception_thrown && " no exception thrown in " && EIGEN_MAKESTRING(OP)) ); \
|
||||
#define CHECK_MEMLEAK(OP) \
|
||||
{ \
|
||||
AnnoyingScalar::countdown = 100; \
|
||||
int before = AnnoyingScalar::instances; \
|
||||
bool exception_thrown = false; \
|
||||
try { \
|
||||
OP; \
|
||||
} catch (my_exception) { \
|
||||
exception_thrown = true; \
|
||||
VERIFY(AnnoyingScalar::instances == before && "memory leak detected in " && EIGEN_MAKESTRING(OP)); \
|
||||
} \
|
||||
VERIFY((AnnoyingScalar::dont_throw) || (exception_thrown && " no exception thrown in " && EIGEN_MAKESTRING(OP))); \
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(exceptions)
|
||||
{
|
||||
typedef Eigen::Matrix<AnnoyingScalar,Dynamic,1> VectorType;
|
||||
typedef Eigen::Matrix<AnnoyingScalar,Dynamic,Dynamic> MatrixType;
|
||||
|
||||
EIGEN_DECLARE_TEST(exceptions) {
|
||||
typedef Eigen::Matrix<AnnoyingScalar, Dynamic, 1> VectorType;
|
||||
typedef Eigen::Matrix<AnnoyingScalar, Dynamic, Dynamic> MatrixType;
|
||||
|
||||
{
|
||||
AnnoyingScalar::dont_throw = false;
|
||||
int n = 50;
|
||||
VectorType v0(n), v1(n);
|
||||
MatrixType m0(n,n), m1(n,n), m2(n,n);
|
||||
v0.setOnes(); v1.setOnes();
|
||||
m0.setOnes(); m1.setOnes(); m2.setOnes();
|
||||
MatrixType m0(n, n), m1(n, n), m2(n, n);
|
||||
v0.setOnes();
|
||||
v1.setOnes();
|
||||
m0.setOnes();
|
||||
m1.setOnes();
|
||||
m2.setOnes();
|
||||
CHECK_MEMLEAK(v0 = m0 * m1 * v1);
|
||||
CHECK_MEMLEAK(m2 = m0 * m1 * m2);
|
||||
CHECK_MEMLEAK((v0+v1).dot(v0+v1));
|
||||
CHECK_MEMLEAK((v0 + v1).dot(v0 + v1));
|
||||
}
|
||||
VERIFY(AnnoyingScalar::instances==0 && "global memory leak detected in " && EIGEN_MAKESTRING(OP));
|
||||
VERIFY(AnnoyingScalar::instances == 0 && "global memory leak detected in " && EIGEN_MAKESTRING(OP));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user