From: Wolfgang Bangerth Date: Fri, 26 Jan 2018 17:40:08 +0000 (-0700) Subject: Add a test for the fast-path pack()/unpack() functions. X-Git-Tag: v9.0.0-rc1~514^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F5810%2Fhead;p=dealii.git Add a test for the fast-path pack()/unpack() functions. --- diff --git a/tests/base/utilities_pack_unpack_03.cc b/tests/base/utilities_pack_unpack_03.cc new file mode 100644 index 0000000000..be7162ce2b --- /dev/null +++ b/tests/base/utilities_pack_unpack_03.cc @@ -0,0 +1,77 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 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 at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// test Utilities::pack/unpack on some types. this test checks that +// for trivially-copyable (small) types, packing is just a memcpy +// operation + +#include "../tests.h" + +#include +#include +#include + +#include +#include + +struct X +{ + int i; + int k; + double d; + + bool operator == (const X &x) const + { + return i==x.i && k==x.k && d==x.d; + } + + template + void serialize(Archive &ar, const unsigned int) + { + ar &i &k &d; + } +}; + + + +template +void check (const T &object) +{ + const std::vector buffer = Utilities::pack (object); + if (!(buffer.size() == sizeof(object)) + || + !(std::memcmp(buffer.data(), &object, buffer.size()) == 0) + || + !(Utilities::unpack(buffer) == object)) + deallog << "Fail!" << std::endl; +} + + +void test() +{ + check (std::make_pair(1, 3.14)); + check (X { 1, 2, 3.1415926 }); + check (std::tuple {1,1,1}); + + deallog << "OK!" << std::endl; +} + +int main() +{ + initlog(); + + test(); +} diff --git a/tests/base/utilities_pack_unpack_03.output b/tests/base/utilities_pack_unpack_03.output new file mode 100644 index 0000000000..5cfb783b8f --- /dev/null +++ b/tests/base/utilities_pack_unpack_03.output @@ -0,0 +1,2 @@ + +DEAL::OK!