1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
/*
* GridTools
*
* Copyright (c) 2014-2019, ETH Zurich
* All rights reserved.
*
* Please, refer to the LICENSE file in the root directory.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <cpp_bindgen/common/any_moveable.hpp>
#include <gtest/gtest.h>
#include <memory>
namespace cpp_bindgen {
TEST(any_moveable, smoke) {
any_moveable x = 42;
EXPECT_TRUE(x.has_value());
EXPECT_EQ(typeid(int), x.type());
EXPECT_EQ(42, any_cast<int>(x));
auto &ref = any_cast<int &>(x);
ref = 88;
EXPECT_EQ(88, any_cast<int>(x));
EXPECT_FALSE(any_cast<double *>(&x));
}
TEST(any_moveable, empty) { EXPECT_FALSE(any_moveable{}.has_value()); }
TEST(any_moveable, move_only) {
using testee_t = std::unique_ptr<int>;
any_moveable x = testee_t(new int(42));
EXPECT_EQ(42, *any_cast<testee_t const &>(x));
any_moveable y = std::move(x);
EXPECT_EQ(42, *any_cast<testee_t const &>(y));
}
} // namespace cpp_bindgen
|