File: test_xproxy_wrapper.cpp

package info (click to toggle)
xtl 0.7.2-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,352 kB
  • sloc: cpp: 19,501; makefile: 164; python: 25
file content (69 lines) | stat: -rw-r--r-- 1,821 bytes parent folder | download | duplicates (2)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht          *
* Copyright (c) QuantStack                                                 *
*                                                                          *
* Distributed under the terms of the BSD 3-Clause License.                 *
*                                                                          *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#include "gtest/gtest.h"

#include "xtl/xproxy_wrapper.hpp"

namespace xtl
{
    using double_wrapper = xproxy_wrapper<double>;

    double_wrapper func_double()
    {
        return proxy_wrapper(2.5);
    }

    struct Tester
    {
        using value_type = double;

        value_type func() { return 1.; }
        value_type func() const { return 2.; }
    };

    using tester_wrapper = xproxy_wrapper<Tester>;

    tester_wrapper func_tester()
    {
        return proxy_wrapper(Tester());
    }


    TEST(xproxy_wrapper, fundamental_type)
    {
        auto wd = func_double();
        auto pd = &wd;
        
        double d1 = wd;
        double d2 = *pd;
        EXPECT_EQ(2.5, d1);
        EXPECT_EQ(2.5, d2);

        wd = 3.5;
        EXPECT_EQ(3.5, *pd);
    }

    TEST(xproxy_wrapper, user_type)
    {
        auto wu = func_tester();
        auto pu = &wu;

        using wrapper_type = decltype(wu);
        using value_type = wrapper_type::value_type;
        static_assert(std::is_same<value_type, double>::value, "value_type should be double");

        double res = wu.func();
        double res2 = pu->func();

        EXPECT_EQ(1., res);
        EXPECT_EQ(1., res2);
    }
}