|
- #include <gtest/gtest.h>
-
- #include <cppmp.h>
-
- using namespace ::testing;
- using namespace ::cppmp;
-
- struct test_obj
- {
- mutable int value;
-
- void set(int v)
- { value = v; }
-
- void cset(int v) const
- { value = v; }
-
- static void sset(test_obj& o, int v)
- { o.value = v; }
- };
-
- TEST(cppmp_setter_tests, member_var)
- {
- test_obj o { 0 };
-
- auto s = make_setter(&test_obj::value);
- s(o, 1);
-
- EXPECT_EQ(1, o.value);
- }
-
- TEST(cppmp_setter_tests, member_func)
- {
- test_obj o { 1 };
-
- auto s = make_setter(&test_obj::set);
- s(o, 1);
-
- EXPECT_EQ(1, o.value);
- }
-
- TEST(cppmp_setter_tests, const_member_func)
- {
- test_obj o { 1 };
-
- auto s = make_setter(&test_obj::cset);
- s(o, 1);
-
- EXPECT_EQ(1, o.value);
- }
-
- TEST(cppmp_setter_tests, static_func)
- {
- test_obj o { 1 };
-
- auto s = make_setter(&test_obj::sset);
- s(o, 1);
-
- EXPECT_EQ(1, o.value);
- }
-
- TEST(cppmp_setter_tests, lambda)
- {
- test_obj obj { 1 };
-
- auto s = make_setter([](test_obj& o, int v){
- o.value = v;
- });
- s(obj, 1);
-
- EXPECT_EQ(1, obj.value);
- }
|