From 5a83710e371fe68a06e6e3876c6a2c8b820a8976 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Sat, 20 Dec 2014 01:40:03 +0000 Subject: Move test into test/std subdirectory. llvm-svn: 224658 --- .../optional.object.assign/assign_value.pass.cpp | 72 ++++++++++ .../optional.object.assign/copy.pass.cpp | 90 +++++++++++++ .../optional.object.assign/emplace.pass.cpp | 148 +++++++++++++++++++++ .../emplace_initializer_list.pass.cpp | 116 ++++++++++++++++ .../optional.object.assign/move.pass.cpp | 103 ++++++++++++++ .../optional.object.assign/nullopt_t.pass.cpp | 67 ++++++++++ 6 files changed, 596 insertions(+) create mode 100644 libcxx/test/std/experimental/optional/optional.object/optional.object.assign/assign_value.pass.cpp create mode 100644 libcxx/test/std/experimental/optional/optional.object/optional.object.assign/copy.pass.cpp create mode 100644 libcxx/test/std/experimental/optional/optional.object/optional.object.assign/emplace.pass.cpp create mode 100644 libcxx/test/std/experimental/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp create mode 100644 libcxx/test/std/experimental/optional/optional.object/optional.object.assign/move.pass.cpp create mode 100644 libcxx/test/std/experimental/optional/optional.object/optional.object.assign/nullopt_t.pass.cpp (limited to 'libcxx/test/std/experimental/optional/optional.object/optional.object.assign') diff --git a/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/assign_value.pass.cpp b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/assign_value.pass.cpp new file mode 100644 index 00000000000..e256a098f1a --- /dev/null +++ b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/assign_value.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template optional& operator=(U&& v); + +#include +#include +#include +#include + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; + +struct X +{ +}; + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + static_assert(std::is_assignable, int>::value, ""); + static_assert(std::is_assignable, int&>::value, ""); + static_assert(std::is_assignable&, int>::value, ""); + static_assert(std::is_assignable&, int&>::value, ""); + static_assert(std::is_assignable&, const int&>::value, ""); + static_assert(!std::is_assignable&, const int&>::value, ""); + static_assert(!std::is_assignable, X>::value, ""); + { + optional opt; + opt = 1; + assert(static_cast(opt) == true); + assert(*opt == 1); + } + { + optional opt; + const int i = 2; + opt = i; + assert(static_cast(opt) == true); + assert(*opt == i); + } + { + optional opt(3); + const int i = 2; + opt = i; + assert(static_cast(opt) == true); + assert(*opt == i); + } + { + optional> opt; + opt = std::unique_ptr(new int(3)); + assert(static_cast(opt) == true); + assert(**opt == 3); + } + { + optional> opt(std::unique_ptr(new int(2))); + opt = std::unique_ptr(new int(3)); + assert(static_cast(opt) == true); + assert(**opt == 3); + } +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/copy.pass.cpp b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/copy.pass.cpp new file mode 100644 index 00000000000..81c3b4e6dfa --- /dev/null +++ b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/copy.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// optional& operator=(const optional& rhs); + +#include +#include +#include + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; + +struct X +{ + static bool throw_now; + + X() = default; + X(const X&) + { + if (throw_now) + throw 6; + } +}; + +bool X::throw_now = false; + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + optional opt; + constexpr optional opt2; + opt = opt2; + static_assert(static_cast(opt2) == false, ""); + assert(static_cast(opt) == static_cast(opt2)); + } + { + optional opt; + constexpr optional opt2(2); + opt = opt2; + static_assert(static_cast(opt2) == true, ""); + static_assert(*opt2 == 2, ""); + assert(static_cast(opt) == static_cast(opt2)); + assert(*opt == *opt2); + } + { + optional opt(3); + constexpr optional opt2; + opt = opt2; + static_assert(static_cast(opt2) == false, ""); + assert(static_cast(opt) == static_cast(opt2)); + } + { + optional opt(3); + constexpr optional opt2(2); + opt = opt2; + static_assert(static_cast(opt2) == true, ""); + static_assert(*opt2 == 2, ""); + assert(static_cast(opt) == static_cast(opt2)); + assert(*opt == *opt2); + } + { + optional opt; + optional opt2(X{}); + assert(static_cast(opt2) == true); + try + { + X::throw_now = true; + opt = opt2; + assert(false); + } + catch (int i) + { + assert(i == 6); + assert(static_cast(opt) == false); + } + } +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/emplace.pass.cpp b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/emplace.pass.cpp new file mode 100644 index 00000000000..c4361ea5178 --- /dev/null +++ b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/emplace.pass.cpp @@ -0,0 +1,148 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template void optional::emplace(Args&&... args); + +#include +#include +#include +#include + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; + +class X +{ + int i_; + int j_ = 0; +public: + X() : i_(0) {} + X(int i) : i_(i) {} + X(int i, int j) : i_(i), j_(j) {} + + friend bool operator==(const X& x, const X& y) + {return x.i_ == y.i_ && x.j_ == y.j_;} +}; + +class Y +{ +public: + static bool dtor_called; + Y() = default; + ~Y() {dtor_called = true;} +}; + +bool Y::dtor_called = false; + +class Z +{ +public: + static bool dtor_called; + Z() = default; + Z(int) {throw 6;} + ~Z() {dtor_called = true;} +}; + +bool Z::dtor_called = false; + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + optional opt; + opt.emplace(); + assert(static_cast(opt) == true); + assert(*opt == 0); + } + { + optional opt; + opt.emplace(1); + assert(static_cast(opt) == true); + assert(*opt == 1); + } + { + optional opt(2); + opt.emplace(); + assert(static_cast(opt) == true); + assert(*opt == 0); + } + { + optional opt(2); + opt.emplace(1); + assert(static_cast(opt) == true); + assert(*opt == 1); + } + { + optional opt; + opt.emplace(); + assert(static_cast(opt) == true); + assert(*opt == X()); + } + { + optional opt; + opt.emplace(1); + assert(static_cast(opt) == true); + assert(*opt == X(1)); + } + { + optional opt; + opt.emplace(1, 2); + assert(static_cast(opt) == true); + assert(*opt == X(1, 2)); + } + { + optional opt(X{3}); + opt.emplace(); + assert(static_cast(opt) == true); + assert(*opt == X()); + } + { + optional opt(X{3}); + opt.emplace(1); + assert(static_cast(opt) == true); + assert(*opt == X(1)); + } + { + optional opt(X{3}); + opt.emplace(1, 2); + assert(static_cast(opt) == true); + assert(*opt == X(1, 2)); + } + { + Y y; + { + optional opt(y); + assert(Y::dtor_called == false); + opt.emplace(); + assert(Y::dtor_called == true); + } + } + { + Z z; + optional opt(z); + try + { + assert(static_cast(opt) == true); + assert(Z::dtor_called == false); + opt.emplace(1); + } + catch (int i) + { + assert(i == 6); + assert(static_cast(opt) == false); + assert(Z::dtor_called == true); + } + } +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp new file mode 100644 index 00000000000..8d20be3de19 --- /dev/null +++ b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/emplace_initializer_list.pass.cpp @@ -0,0 +1,116 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// void optional::emplace(initializer_list il, Args&&... args); + +#include +#include +#include +#include + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; + +class X +{ + int i_; + int j_ = 0; +public: + static bool dtor_called; + constexpr X() : i_(0) {} + constexpr X(int i) : i_(i) {} + constexpr X(std::initializer_list il) : i_(il.begin()[0]), j_(il.begin()[1]) {} + ~X() {dtor_called = true;} + + friend constexpr bool operator==(const X& x, const X& y) + {return x.i_ == y.i_ && x.j_ == y.j_;} +}; + +bool X::dtor_called = false; + +class Y +{ + int i_; + int j_ = 0; +public: + constexpr Y() : i_(0) {} + constexpr Y(int i) : i_(i) {} + constexpr Y(std::initializer_list il) : i_(il.begin()[0]), j_(il.begin()[1]) {} + + friend constexpr bool operator==(const Y& x, const Y& y) + {return x.i_ == y.i_ && x.j_ == y.j_;} +}; + +class Z +{ + int i_; + int j_ = 0; +public: + static bool dtor_called; + constexpr Z() : i_(0) {} + constexpr Z(int i) : i_(i) {} + constexpr Z(std::initializer_list il) : i_(il.begin()[0]), j_(il.begin()[1]) + {throw 6;} + ~Z() {dtor_called = true;} + + friend constexpr bool operator==(const Z& x, const Z& y) + {return x.i_ == y.i_ && x.j_ == y.j_;} +}; + +bool Z::dtor_called = false; + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + X x; + { + optional opt(x); + assert(X::dtor_called == false); + opt.emplace({1, 2}); + assert(X::dtor_called == true); + assert(*opt == X({1, 2})); + } + } + { + optional> opt; + opt.emplace({1, 2, 3}, std::allocator()); + assert(static_cast(opt) == true); + assert(*opt == std::vector({1, 2, 3})); + } + { + optional opt; + opt.emplace({1, 2}); + assert(static_cast(opt) == true); + assert(*opt == Y({1, 2})); + } + { + Z z; + optional opt(z); + try + { + assert(static_cast(opt) == true); + assert(Z::dtor_called == false); + opt.emplace({1, 2}); + } + catch (int i) + { + assert(i == 6); + assert(static_cast(opt) == false); + assert(Z::dtor_called == true); + } + } +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/move.pass.cpp b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/move.pass.cpp new file mode 100644 index 00000000000..d27313dad42 --- /dev/null +++ b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/move.pass.cpp @@ -0,0 +1,103 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// optional& operator=(optional&& rhs) +// noexcept(is_nothrow_move_assignable::value && +// is_nothrow_move_constructible::value); + +#include +#include +#include + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; + +struct X +{ + static bool throw_now; + + X() = default; + X(X&&) + { + if (throw_now) + throw 6; + } + X& operator=(X&&) noexcept + { + return *this; + } +}; + +struct Y {}; + +bool X::throw_now = false; + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + static_assert(std::is_nothrow_move_assignable>::value, ""); + optional opt; + constexpr optional opt2; + opt = std::move(opt2); + static_assert(static_cast(opt2) == false, ""); + assert(static_cast(opt) == static_cast(opt2)); + } + { + optional opt; + constexpr optional opt2(2); + opt = std::move(opt2); + static_assert(static_cast(opt2) == true, ""); + static_assert(*opt2 == 2, ""); + assert(static_cast(opt) == static_cast(opt2)); + assert(*opt == *opt2); + } + { + optional opt(3); + constexpr optional opt2; + opt = std::move(opt2); + static_assert(static_cast(opt2) == false, ""); + assert(static_cast(opt) == static_cast(opt2)); + } + { + optional opt(3); + constexpr optional opt2(2); + opt = std::move(opt2); + static_assert(static_cast(opt2) == true, ""); + static_assert(*opt2 == 2, ""); + assert(static_cast(opt) == static_cast(opt2)); + assert(*opt == *opt2); + } + { + static_assert(!std::is_nothrow_move_assignable>::value, ""); + optional opt; + optional opt2(X{}); + assert(static_cast(opt2) == true); + try + { + X::throw_now = true; + opt = std::move(opt2); + assert(false); + } + catch (int i) + { + assert(i == 6); + assert(static_cast(opt) == false); + } + } + { + static_assert(std::is_nothrow_move_assignable>::value, ""); + } +#endif // _LIBCPP_STD_VER > 11 +} diff --git a/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/nullopt_t.pass.cpp b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/nullopt_t.pass.cpp new file mode 100644 index 00000000000..7f39744f055 --- /dev/null +++ b/libcxx/test/std/experimental/optional/optional.object/optional.object.assign/nullopt_t.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// optional& operator=(nullopt_t) noexcept; + +#include +#include +#include + +#if _LIBCPP_STD_VER > 11 + +using std::experimental::optional; +using std::experimental::nullopt_t; +using std::experimental::nullopt; + +struct X +{ + static bool dtor_called; + ~X() {dtor_called = true;} +}; + +bool X::dtor_called = false; + +#endif // _LIBCPP_STD_VER > 11 + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + optional opt; + static_assert(noexcept(opt = nullopt) == true, ""); + opt = nullopt; + assert(static_cast(opt) == false); + } + { + optional opt(3); + opt = nullopt; + assert(static_cast(opt) == false); + } + { + optional opt; + static_assert(noexcept(opt = nullopt) == true, ""); + assert(X::dtor_called == false); + opt = nullopt; + assert(X::dtor_called == false); + assert(static_cast(opt) == false); + } + { + X x; + { + optional opt(x); + assert(X::dtor_called == false); + opt = nullopt; + assert(X::dtor_called == true); + assert(static_cast(opt) == false); + } + } +#endif // _LIBCPP_STD_VER > 11 +} -- cgit v1.2.3