| 1234567891011121314151617181920212223242526272829303132 |
- #include "reflect/reflect.hpp"
- #include <gmock/gmock.h>
- struct example {
- int a;
- int b;
- };
- CREATE_REFLECTION(example, (a), (b, "c"));
- using testing::Eq;
- using testing::NotNull;
- TEST(ReflectionTest, BindsParameterByName) {
- EXPECT_TRUE(reflection<example>::exists<int>("a"));
- }
- TEST(ReflectionTest, CanRenameParameter) {
- EXPECT_FALSE(reflection<example>::exists<int>("b"));
- EXPECT_TRUE(reflection<example>::exists<int>("c"));
- }
- TEST(ReflectionTest, CanAccessMember) {
- auto p = reflection<example>::get_pointer<int>("a");
- EXPECT_THAT(p, NotNull());
- EXPECT_THAT(p, Eq(&example::a));
- example ex = { 5, 6 };
- EXPECT_THAT(&(ex.*p), Eq(&ex.a));
- EXPECT_THAT(ex.*p, Eq(5));
- }
|