summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/30_threads/promise/members
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/testsuite/30_threads/promise/members')
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/members/get_future.cc52
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/members/get_future2.cc57
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/members/set_exception.cc57
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/members/set_exception2.cc93
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/members/set_value.cc106
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/members/set_value2.cc87
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/members/set_value3.cc78
-rw-r--r--libstdc++-v3/testsuite/30_threads/promise/members/swap.cc46
8 files changed, 576 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/get_future.cc b/libstdc++-v3/testsuite/30_threads/promise/members/get_future.cc
new file mode 100644
index 000000000..b09e302cc
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/members/get_future.cc
@@ -0,0 +1,52 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int&> p1;
+ std::future<int&> f1 = p1.get_future();
+
+ VERIFY( f1.valid() );
+
+ int i1 = 0;
+
+ p1.set_value(i1);
+
+ int& i2 = f1.get();
+
+ VERIFY( &i1 == &i2 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/get_future2.cc b/libstdc++-v3/testsuite/30_threads/promise/members/get_future2.cc
new file mode 100644
index 000000000..cc44fc479
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/members/get_future2.cc
@@ -0,0 +1,57 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <system_error>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test = false;
+ using namespace std;
+
+ promise<int&> p1;
+ p1.get_future();
+
+ try
+ {
+ p1.get_future();
+ VERIFY( false );
+ }
+ catch (future_error& e)
+ {
+ VERIFY(e.code() == make_error_code(future_errc::future_already_retrieved));
+ test = true;
+ }
+
+ VERIFY( test );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/set_exception.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_exception.cc
new file mode 100644
index 000000000..4d2a1ec02
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_exception.cc
@@ -0,0 +1,57 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test = false;
+
+ std::promise<int> p1;
+ std::future<int> f1 = p1.get_future();
+
+ VERIFY( f1.valid() );
+
+ p1.set_exception(std::copy_exception(0));
+
+ try
+ {
+ f1.get();
+ }
+ catch (int)
+ {
+ test = true;
+ }
+ VERIFY( test );
+ VERIFY( !f1.valid() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/set_exception2.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_exception2.cc
new file mode 100644
index 000000000..872a4792f
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_exception2.cc
@@ -0,0 +1,93 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test = false;
+
+ std::promise<int> p1;
+ std::future<int> f1 = p1.get_future();
+
+ p1.set_exception(std::copy_exception(0));
+
+ try
+ {
+ p1.set_exception(std::copy_exception(1));
+ VERIFY( false );
+ }
+ catch (std::future_error& e)
+ {
+ VERIFY(e.code() ==
+ std::make_error_code(std::future_errc::promise_already_satisfied));
+ test = true;
+ }
+
+ try
+ {
+ f1.get();
+ test = false;
+ }
+ catch(int i)
+ {
+ VERIFY( i == 0 );
+ }
+
+ VERIFY( test );
+}
+
+void test02()
+{
+ bool test = false;
+
+ std::promise<int> p1;
+ std::future<int> f1 = p1.get_future();
+
+ p1.set_value(2);
+
+ try
+ {
+ p1.set_exception(std::copy_exception(0));
+ VERIFY( false );
+ }
+ catch (std::future_error& e)
+ {
+ VERIFY(e.code() ==
+ std::make_error_code(std::future_errc::promise_already_satisfied));
+ test = true;
+ }
+
+ VERIFY( test );
+}
+
+int main()
+{
+ test01();
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/set_value.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_value.cc
new file mode 100644
index 000000000..9d3f8ead3
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_value.cc
@@ -0,0 +1,106 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+#include <testsuite_rvalref.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::future<int> f1 = p1.get_future();
+
+ VERIFY( f1.valid() );
+
+ p1.set_value(0);
+
+ int&& i1 = f1.get();
+
+ VERIFY( i1 == 0 );
+}
+
+void test02()
+{
+ bool test __attribute__((unused)) = true;
+ using __gnu_test::rvalstruct;
+
+ std::promise<rvalstruct> p1;
+ std::future<rvalstruct> f1 = p1.get_future();
+
+ VERIFY( f1.valid() );
+
+ p1.set_value(rvalstruct(1));
+
+ rvalstruct r1(f1.get());
+
+ VERIFY( !f1.valid() );
+ VERIFY( r1.val == 1 );
+}
+
+
+void test03()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int&> p1;
+ std::future<int&> f1 = p1.get_future();
+
+ VERIFY( f1.valid() );
+
+ int i1 = 0;
+ p1.set_value(i1);
+ int& i2 = f1.get();
+
+ VERIFY( !f1.valid() );
+ VERIFY( &i1 == &i2 );
+}
+
+void test04()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<void> p1;
+ std::future<void> f1 = p1.get_future();
+
+ VERIFY( f1.valid() );
+
+ p1.set_value();
+ f1.get();
+
+ VERIFY( !f1.valid() );
+}
+
+int main()
+{
+ test01();
+ test02();
+ test03();
+ test04();
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/set_value2.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_value2.cc
new file mode 100644
index 000000000..09c8a52fa
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_value2.cc
@@ -0,0 +1,87 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test = false;
+
+ std::promise<int> p1;
+ std::future<int> f1 = p1.get_future();
+
+ p1.set_value(1);
+
+ try
+ {
+ p1.set_value(2);
+ VERIFY( false );
+ }
+ catch (std::future_error& e)
+ {
+ VERIFY(e.code() ==
+ std::make_error_code(std::future_errc::promise_already_satisfied));
+ test = true;
+ }
+
+ VERIFY( f1.wait_for(std::chrono::milliseconds(1)) );
+ VERIFY( f1.get() == 1 );
+ VERIFY( test );
+}
+
+void test02()
+{
+ bool test = false;
+
+ std::promise<int> p1;
+ std::future<int> f1 = p1.get_future();
+
+ p1.set_value(3);
+
+ try
+ {
+ p1.set_exception(std::copy_exception(4));
+ VERIFY( false );
+ }
+ catch (std::future_error& e)
+ {
+ VERIFY(e.code() ==
+ std::make_error_code(std::future_errc::promise_already_satisfied));
+ test = true;
+ }
+
+ VERIFY( f1.wait_for(std::chrono::milliseconds(1)) );
+ VERIFY( f1.get() == 3 );
+ VERIFY( test );
+}
+
+int main()
+{
+ test01();
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/set_value3.cc b/libstdc++-v3/testsuite/30_threads/promise/members/set_value3.cc
new file mode 100644
index 000000000..5dabff97d
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/members/set_value3.cc
@@ -0,0 +1,78 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <future>
+#include <testsuite_hooks.h>
+
+
+// Test promise::set_value() for deadlock by checking if the state is ready
+// during construction and destruction of the associated state.
+
+struct tester
+{
+ tester(int);
+ tester(const tester&);
+ tester() = delete;
+ tester& operator=(const tester&);
+};
+
+std::promise<tester> pglobal;
+std::future<tester> fglobal = pglobal.get_future();
+
+tester::tester(int)
+{
+ bool test __attribute__((unused)) = true;
+ VERIFY (!fglobal.wait_for(std::chrono::milliseconds(1)));
+}
+
+tester::tester(const tester&)
+{
+ bool test __attribute__((unused)) = true;
+ // if this copy happens while a mutex is locked next line could deadlock:
+ VERIFY (!fglobal.wait_for(std::chrono::milliseconds(1)));
+}
+
+tester& tester::operator=(const tester&)
+{
+ bool test __attribute__((unused)) = true;
+ // if this copy happens while a mutex is locked next line could deadlock:
+ VERIFY (!fglobal.wait_for(std::chrono::milliseconds(1)));
+ return *this;
+}
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ pglobal.set_value( tester(1) );
+
+ VERIFY( fglobal.wait_for(std::chrono::milliseconds(1)) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/30_threads/promise/members/swap.cc b/libstdc++-v3/testsuite/30_threads/promise/members/swap.cc
new file mode 100644
index 000000000..b27ee2be7
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/promise/members/swap.cc
@@ -0,0 +1,46 @@
+// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } }
+// { dg-options " -std=gnu++0x -pthreads" { target *-*-solaris* } }
+// { dg-options " -std=gnu++0x " { target *-*-cygwin *-*-darwin* } }
+// { dg-require-cstdint "" }
+// { dg-require-gthreads "" }
+// { dg-require-atomic-builtins "" }
+
+// Copyright (C) 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <future>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::promise<int> p1;
+ std::promise<int> p2;
+ p1.set_value(1);
+ p1.swap(p2);
+ VERIFY( !p1.get_future().wait_for(std::chrono::milliseconds(1)) );
+ VERIFY( p2.get_future().wait_for(std::chrono::milliseconds(1)) );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}