| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #include "reflection/reflection.h"
- #include "xcode_gtest_helper.h"
- using reflection::Object;
- using reflection::Reflection;
- using testing::Eq;
- using testing::NotNull;
- namespace {
- struct Example {
- int a;
- int b;
- };
- bool _ = Reflection<Example>().bind("a", &Example::a).bind("c", &Example::b);
- }
- TEST(ReflectionTest, AquiresGetter) {
- EXPECT_NO_THROW(Reflection<Example>::getter("a"));
- }
- TEST(ReflectionTest, AquiresAccessor) {
- EXPECT_NO_THROW(Reflection<Example>::accessor("a"));
- }
- TEST(ReflectionTest, ThrowsOnFakeGetter) {
- EXPECT_THROW(Reflection<Example>::getter("b"), std::out_of_range);
- }
- TEST(ReflectionTest, ThrowsOnFakeAccessor) {
- EXPECT_THROW(Reflection<Example>::accessor("b"), std::out_of_range);
- }
- TEST(ReflectionTest, UseOnPrimitiveThrows) {
- EXPECT_THROW(Reflection<int>::getter("a"), std::logic_error);
- EXPECT_THROW(Reflection<int>::accessor("a"), std::logic_error);
- }
- TEST(ReflectionTest, UseOnStringThrows) {
- EXPECT_THROW(Reflection<std::string>::getter("a"), std::logic_error);
- EXPECT_THROW(Reflection<std::string>::accessor("a"), std::logic_error);
- }
- // 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));
- // }
- //
- // TEST(ReflectionTest, CanGetNameFromMemPtr) {
- // EXPECT_THAT(reflection<example>::name(&example::a), Eq("a"));
- // EXPECT_THAT(reflection<example>::name(&example::b), Eq("c"));
- // }
- //
- // TEST(ReflectionTest, CanGetNameFromThis) {
- // example ex = { 5, 6 };
- // EXPECT_THAT(reflection<example>::name(ex, ex.a), Eq("a"));
- // EXPECT_THAT(reflection<example>::name(ex, ex.b), Eq("c"));
- // }
- //
- // TEST(ReflectionTest, NameForMissingIsEmpty) {
- // example ex = { 5, 6 };
- // EXPECT_THAT(reflection<example>::name(ex, 5), Eq(""));
- // }
|