| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- #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;
- int d;
- int get() const { return d; }
- int & get() { return d; }
- };
- }
- namespace reflection {
- INSTANTIATE_REFLECTION(Example);
- }
- REFLECTION(Example)
- .bind("a", &Example::a)
- .bind("c", &Example::b)
- .bind("d", &Example::get, &Example::get);
- 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(""));
- // }
|