]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Test of SparseMatrix move ctor checks that ExcInUse is thrown
authordanshapero <shapero.daniel@gmail.com>
Fri, 1 Apr 2016 03:56:45 +0000 (20:56 -0700)
committerdanshapero <shapero.daniel@gmail.com>
Fri, 1 Apr 2016 03:56:45 +0000 (20:56 -0700)
tests/lac/sparse_matrix_move.cc
tests/lac/sparse_matrix_move.with_cxx11=on.output

index 8652539bd419bf557a7be7afe71a7797aa23b80c..0da8932f77c3e1f9bb58767b83477417df9ac395 100644 (file)
@@ -71,30 +71,61 @@ int main()
   testproblem.five_point_structure(sparsity);
   sparsity.compress();
 
-  // Return a sparse matrix, possibly using RVO or move constructor
-  SparseMatrix<double> A = graph_laplacian(sparsity);
-  deallog << A.n_nonzero_elements() << std::endl;
-
   Vector<double> 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<double> 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<double> 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<double> 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<double> 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<double> 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<double> A = graph_laplacian(sparsity);
+    SmartPointer<SparseMatrix<double> > 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<double> 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;
 }
index 7239c9cda828639d6e8f41f7429fabc0c1eeceb9..ced490f8e7ea371970b4607cc71b6af1cc41ae69 100644 (file)
@@ -5,3 +5,4 @@ DEAL::64
 DEAL::0.00
 DEAL::16
 DEAL::1
+DEAL::Exception caught if in debug mode.

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.