From ed757cb2cedfe06c2ddc1c52433732253acbe18d Mon Sep 17 00:00:00 2001 From: danshapero Date: Thu, 31 Mar 2016 20:56:45 -0700 Subject: [PATCH] Test of SparseMatrix move ctor checks that ExcInUse is thrown --- tests/lac/sparse_matrix_move.cc | 75 +++++++++++++------ .../sparse_matrix_move.with_cxx11=on.output | 1 + 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/tests/lac/sparse_matrix_move.cc b/tests/lac/sparse_matrix_move.cc index 8652539bd4..0da8932f77 100644 --- a/tests/lac/sparse_matrix_move.cc +++ b/tests/lac/sparse_matrix_move.cc @@ -71,30 +71,61 @@ int main() testproblem.five_point_structure(sparsity); sparsity.compress(); - // Return a sparse matrix, possibly using RVO or move constructor - SparseMatrix A = graph_laplacian(sparsity); - deallog << A.n_nonzero_elements() << std::endl; - Vector x(dim), y(dim); - x = 1.0; - y = 1.0; - A.vmult(y, x); - - deallog << y.l2_norm() << std::endl; - - // Return a sparse matrix using the move constructor - SparseMatrix B = graph_laplacian_move_return(sparsity); - deallog << B.n_nonzero_elements() << std::endl; - y = 1.0; - B.vmult(y, x); - - deallog << y.l2_norm() << std::endl; - // Explicitly move a sparse matrix - SparseMatrix C; - C = std::move(B); - deallog << C.m() << std::endl; - deallog << B.empty() << std::endl; + { + // Return a sparse matrix, possibly using RVO or move constructor + SparseMatrix A = graph_laplacian(sparsity); + deallog << A.n_nonzero_elements() << std::endl; + + x = 1.0; + y = 1.0; + A.vmult(y, x); + + deallog << y.l2_norm() << std::endl; + } + + { + // Return a sparse matrix using the move constructor + SparseMatrix A = graph_laplacian_move_return(sparsity); + deallog << A.n_nonzero_elements() << std::endl; + y = 1.0; + A.vmult(y, x); + + deallog << y.l2_norm() << std::endl; + + // Explicitly move a sparse matrix + SparseMatrix B; + B = std::move(A); + deallog << B.m() << std::endl; + deallog << A.empty() << std::endl; + } + + { + // Try to move a sparse matrix that has a subscription + SparseMatrix A = graph_laplacian(sparsity); + SmartPointer > smart_pointer_to_A(&A); + + bool need_to_catch_exc_in_use = false; +#ifdef DEBUG + need_to_catch_exc_in_use = true; +#endif + + try + { + SparseMatrix B = std::move(A); + } + catch (const Subscriptor::ExcInUse&) + { + need_to_catch_exc_in_use = false; + } + catch(...) + { + return 1; + } + + deallog << "Exception caught if in debug mode." << std::endl; + } return 0; } diff --git a/tests/lac/sparse_matrix_move.with_cxx11=on.output b/tests/lac/sparse_matrix_move.with_cxx11=on.output index 7239c9cda8..ced490f8e7 100644 --- a/tests/lac/sparse_matrix_move.with_cxx11=on.output +++ b/tests/lac/sparse_matrix_move.with_cxx11=on.output @@ -5,3 +5,4 @@ DEAL::64 DEAL::0.00 DEAL::16 DEAL::1 +DEAL::Exception caught if in debug mode. -- 2.39.5