summaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/traits/traits_test.cpp
blob: 82824d8c2eed1cbb11f2bec5c8fb32dbee585c7c (plain) (blame)
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
39
40
41
42
43
44
45
46
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/fastos/fastos.h>
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/vespalib/util/traits.h>
#include <vespa/vespalib/util/arrayqueue.hpp>

using namespace vespalib;

struct Simple {
    int value;
    int moved;
    explicit Simple(int v) : value(v), moved(0) {}
    Simple(const Simple &rhs) : value(rhs.value), moved(rhs.moved) {}
    Simple(Simple &&rhs) : value(rhs.value), moved(rhs.moved + 1) {}
};
typedef std::unique_ptr<Simple> Hard;

struct Base {
    virtual void foo() = 0;
    virtual ~Base() {}
};
struct Child1 : Base {
    void foo() override {}
};
struct Child2 : Base {
    void foo() override {}
};

VESPA_CAN_SKIP_DESTRUCTION(Child2);

TEST("require that is_copyable works") {
    EXPECT_EQUAL(is_copyable<Simple>::value, true);
    EXPECT_EQUAL(is_copyable<Hard>::value, false);
    EXPECT_EQUAL(is_copyable<ArrayQueue<Simple> >::value, true);
    EXPECT_EQUAL(is_copyable<ArrayQueue<Hard> >::value, false);
    EXPECT_EQUAL(is_copyable<std::unique_ptr<Hard> >::value, false);
}

TEST("require that can_skip_destruction works") {
    EXPECT_EQUAL(can_skip_destruction<Simple>::value, true);
    EXPECT_EQUAL(can_skip_destruction<Hard>::value, false);
    EXPECT_EQUAL(can_skip_destruction<Child1>::value, false);
    EXPECT_EQUAL(can_skip_destruction<Child2>::value, true);
}

TEST_MAIN() { TEST_RUN_ALL(); }