From: Wolfgang Bangerth Date: Thu, 29 Mar 2018 01:30:45 +0000 (-0600) Subject: Add tests. X-Git-Tag: v9.0.0-rc1~259^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fac0bad41505502867917c8a7a1a67bc46f42ace;p=dealii.git Add tests. --- diff --git a/tests/base/thread_validity_13.cc b/tests/base/thread_validity_13.cc new file mode 100644 index 0000000000..6bf7c98108 --- /dev/null +++ b/tests/base/thread_validity_13.cc @@ -0,0 +1,95 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2008 - 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. +// +// --------------------------------------------------------------------- + + +// See that we can query a thread object's return value for cases +// where these returned objects are not copyable but only +// movable. This is relevant, for example, when calling functions that +// return a std::unique_ptr. + +#include "../tests.h" +#include + +#include + + +class X +{ +public: + // default constructor + X () : + value (13) + {} + + X (int i) : + value (i) + {} + + // delete the copy constructor + X (const X &) = delete; + + // move constructor. sets the moved-from value to a recognizable + // value + X (X &&x) + { + value = x.value; + x.value = 0; + } + + // same idea about copy operators + X &operator = (const X &) = delete; + + X &operator = (X &&x) + { + value = x.value; + x.value = 0; + + return *this; + } + + + int value; +}; + + + +X foo () +{ + return X(42); +} + + + +int main() +{ + initlog(); + + Threads::Thread t = Threads::new_thread (&foo); + + // wait for the thread to return and query its value + deallog << t.return_value().value + << std::endl; + + // we can't copy the return_value() object directly, but we can move + // it. do so and check that we still get the correct value. then + // also check that the value of the original return object has been + // reset in the move constructor/operator + X x = std::move(t.return_value()); + deallog << x.value + << std::endl; + + deallog << t.return_value().value + << std::endl; +} diff --git a/tests/base/thread_validity_13.output b/tests/base/thread_validity_13.output new file mode 100644 index 0000000000..63953b22b5 --- /dev/null +++ b/tests/base/thread_validity_13.output @@ -0,0 +1,4 @@ + +DEAL::42 +DEAL::42 +DEAL::0 diff --git a/tests/base/thread_validity_14.cc b/tests/base/thread_validity_14.cc new file mode 100644 index 0000000000..015eff2779 --- /dev/null +++ b/tests/base/thread_validity_14.cc @@ -0,0 +1,95 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2008 - 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. +// +// --------------------------------------------------------------------- + + +// See that we can query a task object's return value for cases +// where these returned objects are not copyable but only +// movable. This is relevant, for example, when calling functions that +// return a std::unique_ptr. + +#include "../tests.h" +#include + +#include + + +class X +{ +public: + X (int i) : + value (i) + {} + + // default constructor + X () : + value (13) + {} + + // delete the copy constructor + X (const X &) = delete; + + // move constructor. sets the moved-from value to a recognizable + // value + X (X &&x) + { + value = x.value; + x.value = 0; + } + + // same idea about copy operators + X &operator = (const X &) = delete; + + X &operator = (X &&x) + { + value = x.value; + x.value = 0; + + return *this; + } + + + int value; +}; + + + +X foo () +{ + return X(42); +} + + + +int main() +{ + initlog(); + + Threads::Task t = Threads::new_task (&foo); + + // wait for the thread to return and query its value + deallog << t.return_value().value + << std::endl; + + // we can't copy the return_value() object directly, but we can move + // it. do so and check that we still get the correct value. then + // also check that the value of the original return object has been + // reset in the move constructor/operator + X x = std::move(t.return_value()); + deallog << x.value + << std::endl; + + deallog << t.return_value().value + << std::endl; +} diff --git a/tests/base/thread_validity_14.output b/tests/base/thread_validity_14.output new file mode 100644 index 0000000000..63953b22b5 --- /dev/null +++ b/tests/base/thread_validity_14.output @@ -0,0 +1,4 @@ + +DEAL::42 +DEAL::42 +DEAL::0