From: Wolfgang Bangerth Date: Fri, 7 Jan 2022 07:19:54 +0000 (-0700) Subject: Add a test. X-Git-Tag: v9.4.0-rc1~645^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=95a7a0c8669e845af37bdc728a8d32996ae53f22;p=dealii.git Add a test. --- diff --git a/tests/serialization/sparsity_pattern_empty.cc b/tests/serialization/sparsity_pattern_empty.cc new file mode 100644 index 0000000000..1127804a98 --- /dev/null +++ b/tests/serialization/sparsity_pattern_empty.cc @@ -0,0 +1,60 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2010 - 2018 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + +// Check serialization for SparsityPattern. This used to fail for empty +// sparsity patterns with a segfault. + +#include + +#include "../testmatrix.h" +#include "serialization.h" + + +void +test() +{ + // Try a sparsity pattern that has nonzero size, but is otherwise empty + const unsigned int N1 = 5; + SparsityPattern sp1((N1 - 1) * (N1 - 1), (N1 - 1) * (N1 - 1), 5); + sp1.compress(); + + // Also try one that is completely empty. This is the case that was + // shown in the original report. + SparsityPattern sp2; + + { + SparsityPattern sp3; + verify(sp1, sp3); + } + + { + SparsityPattern sp3; + verify(sp2, sp3); + } +} + + +int +main() +{ + initlog(); + deallog << std::setprecision(3); + + // Now also try with the usual harness + test(); + + deallog << "OK" << std::endl; +} diff --git a/tests/serialization/sparsity_pattern_empty.output b/tests/serialization/sparsity_pattern_empty.output new file mode 100644 index 0000000000..aa452f6475 --- /dev/null +++ b/tests/serialization/sparsity_pattern_empty.output @@ -0,0 +1,6 @@ + +DEAL::0 0 0 0 0 0 16 16 16 16 5 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 + +DEAL::0 0 0 0 0 0 0 0 0 0 0 0 0 + +DEAL::OK