|
- #include <gtest/gtest.h>
-
- #include <cppmp.h>
-
- using namespace ::testing;
- using namespace ::cppmp;
-
- struct test_obj
- {
- mutable int value;
-
- int get()
- { return value; }
-
- int cget() const
- { return value; }
-
- static int sget(test_obj& o)
- { return o.value; }
- };
-
- TEST(cppmp_getter_tests, member_var)
- {
- test_obj o { 1 };
-
- auto g = make_getter(&test_obj::value);
- auto i = g(o);
-
- EXPECT_EQ(1, i);
- }
-
- TEST(cppmp_getter_tests, member_func)
- {
- test_obj o { 1 };
-
- auto g = make_getter(&test_obj::get);
- auto i = g(o);
-
- EXPECT_EQ(1, i);
- }
-
- TEST(cppmp_getter_tests, const_member_func)
- {
- test_obj o { 1 };
-
- auto g = make_getter(&test_obj::cget);
- auto i = g(o);
-
- EXPECT_EQ(1, i);
- }
-
- TEST(cppmp_getter_tests, static_func)
- {
- test_obj o { 1 };
-
- auto g = make_getter(&test_obj::sget);
- auto i = g(o);
-
- EXPECT_EQ(1, i);
- }
-
- TEST(cppmp_getter_tests, lambda)
- {
- test_obj obj { 1 };
-
- auto g = make_getter([](test_obj& o){
- return o.value;
- });
- auto i = g(obj);
-
- EXPECT_EQ(1, i);
- }
|