File: test_any_moveable.cpp

package info (click to toggle)
gridtools 2.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 21,728 kB
  • sloc: cpp: 45,263; python: 9,383; javascript: 8,445; ansic: 2,564; sh: 509; f90: 370; makefile: 216
file content (38 lines) | stat: -rw-r--r-- 1,030 bytes parent folder | download | duplicates (3)
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