forked from microsoft/proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy_reflection_tests.cpp
More file actions
79 lines (66 loc) · 2.69 KB
/
proxy_reflection_tests.cpp
File metadata and controls
79 lines (66 loc) · 2.69 KB
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
70
71
72
73
74
75
76
77
78
79
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "utils.h"
#include <gtest/gtest.h>
#include <memory>
#include <proxy/proxy.h>
#include <typeinfo>
namespace proxy_reflection_tests_details {
struct TraitsReflector {
public:
template <class T>
constexpr explicit TraitsReflector(std::in_place_type_t<T>)
: is_default_constructible_(std::is_default_constructible_v<T>),
is_copy_constructible_(std::is_copy_constructible_v<T>),
is_nothrow_move_constructible_(std::is_nothrow_move_constructible_v<T>),
is_nothrow_destructible_(std::is_nothrow_destructible_v<T>),
is_trivial_(std::is_trivial_v<T>) {}
template <class F, bool IsDirect, class R>
struct accessor {
const TraitsReflector& ReflectTraits() const noexcept {
return pro::proxy_reflect<IsDirect, R>(pro::access_proxy<F>(*this));
}
};
bool is_default_constructible_;
bool is_copy_constructible_;
bool is_nothrow_move_constructible_;
bool is_nothrow_destructible_;
bool is_trivial_;
};
struct TestRttiFacade : pro::facade_builder
::add_reflection<utils::RttiReflector>
::add_direct_reflection<utils::RttiReflector>
::build {};
struct TestTraitsFacade : pro::facade_builder
::add_direct_reflection<TraitsReflector>
::build {};
} // namespace proxy_reflection_tests_details
namespace details = proxy_reflection_tests_details;
TEST(ProxyReflectionTests, TestRtti_RawPtr) {
int foo = 123;
pro::proxy<details::TestRttiFacade> p = &foo;
ASSERT_STREQ(p.GetTypeName(), typeid(int*).name());
ASSERT_STREQ(p->GetTypeName(), typeid(int).name());
}
TEST(ProxyReflectionTests, TestRtti_FancyPtr) {
pro::proxy<details::TestRttiFacade> p = std::make_unique<double>(1.23);
ASSERT_STREQ(p.GetTypeName(), typeid(std::unique_ptr<double>).name());
ASSERT_STREQ(p->GetTypeName(), typeid(double).name());
}
TEST(ProxyReflectionTests, TestTraits_RawPtr) {
int foo = 123;
pro::proxy<details::TestTraitsFacade> p = &foo;
ASSERT_EQ(p.ReflectTraits().is_default_constructible_, true);
ASSERT_EQ(p.ReflectTraits().is_copy_constructible_, true);
ASSERT_EQ(p.ReflectTraits().is_nothrow_move_constructible_, true);
ASSERT_EQ(p.ReflectTraits().is_nothrow_destructible_, true);
ASSERT_EQ(p.ReflectTraits().is_trivial_, true);
}
TEST(ProxyReflectionTests, TestTraits_FancyPtr) {
pro::proxy<details::TestTraitsFacade> p = std::make_unique<double>(1.23);
ASSERT_EQ(p.ReflectTraits().is_default_constructible_, true);
ASSERT_EQ(p.ReflectTraits().is_copy_constructible_, false);
ASSERT_EQ(p.ReflectTraits().is_nothrow_move_constructible_, true);
ASSERT_EQ(p.ReflectTraits().is_nothrow_destructible_, true);
ASSERT_EQ(p.ReflectTraits().is_trivial_, false);
}