You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

73 regels
1.1 KiB

  1. #include <gtest/gtest.h>
  2. #include <cppmp.h>
  3. using namespace ::testing;
  4. using namespace ::cppmp;
  5. struct test_obj
  6. {
  7. mutable int value;
  8. void set(int v)
  9. { value = v; }
  10. void cset(int v) const
  11. { value = v; }
  12. static void sset(test_obj& o, int v)
  13. { o.value = v; }
  14. };
  15. TEST(cppmp_setter_tests, member_var)
  16. {
  17. test_obj o { 0 };
  18. auto s = make_setter(&test_obj::value);
  19. s(o, 1);
  20. EXPECT_EQ(1, o.value);
  21. }
  22. TEST(cppmp_setter_tests, member_func)
  23. {
  24. test_obj o { 1 };
  25. auto s = make_setter(&test_obj::set);
  26. s(o, 1);
  27. EXPECT_EQ(1, o.value);
  28. }
  29. TEST(cppmp_setter_tests, const_member_func)
  30. {
  31. test_obj o { 1 };
  32. auto s = make_setter(&test_obj::cset);
  33. s(o, 1);
  34. EXPECT_EQ(1, o.value);
  35. }
  36. TEST(cppmp_setter_tests, static_func)
  37. {
  38. test_obj o { 1 };
  39. auto s = make_setter(&test_obj::sset);
  40. s(o, 1);
  41. EXPECT_EQ(1, o.value);
  42. }
  43. TEST(cppmp_setter_tests, lambda)
  44. {
  45. test_obj obj { 1 };
  46. auto s = make_setter([](test_obj& o, int v){
  47. o.value = v;
  48. });
  49. s(obj, 1);
  50. EXPECT_EQ(1, obj.value);
  51. }