21 #include <gtest/gtest.h>
23 TEST(Property, default_construction_yields_default_value)
26 EXPECT_EQ(
int{}, p1.
get());
28 static const int new_default_value = 42;
31 EXPECT_EQ(new_default_value, p2.get());
34 TEST(Property, copy_construction_yields_correct_value)
36 static const int default_value = 42;
40 EXPECT_EQ(default_value, p2.get());
43 TEST(Property, assignment_operator_for_properties_works)
45 static const int default_value = 42;
50 EXPECT_EQ(default_value, p2.
get());
53 TEST(Property, assignment_operator_for_raw_values_works)
55 static const int default_value = 42;
59 EXPECT_EQ(default_value, p1.
get());
62 TEST(Property, equality_operator_for_properties_works)
64 static const int default_value = 42;
72 TEST(Property, equality_operator_for_raw_values_works)
74 static const int default_value = 42;
77 EXPECT_EQ(default_value, p1);
85 Expectation(
const T& expected_value) : expected_value(expected_value)
89 bool satisfied()
const
91 return triggered && current_value == expected_value;
94 bool triggered =
false;
100 TEST(Property, signal_changed_is_emitted_with_correct_value_for_set)
102 static const int default_value = 42;
104 Expectation<int> expectation{default_value};
106 p1.
changed().connect([&expectation](
int value) { expectation.triggered =
true; expectation.current_value = value; });
108 p1.
set(default_value);
110 EXPECT_TRUE(expectation.satisfied());
113 TEST(Property, signal_changed_is_emitted_with_correct_value_for_assignment)
115 static const int default_value = 42;
118 Expectation<int> expectation{42};
120 p1.
changed().connect([&expectation](
int value) { expectation.triggered =
true; expectation.current_value = value; });
124 EXPECT_TRUE(expectation.satisfied());
127 TEST(Property, signal_changed_is_emitted_with_correct_value_for_update)
129 static const int default_value = 42;
132 Expectation<int> expectation{default_value};
134 p1.
changed().connect([&expectation](
int value) { expectation.triggered =
true; expectation.current_value = value; });
135 p1.
update([](
int& value) { value = default_value;
return true; });
137 EXPECT_TRUE(expectation.satisfied());
144 void move_cursor_to(
int new_position)
146 cursor_position.set(new_position);
153 TEST(Property, cursor_position_changes_are_transported_correctly)
159 tf.cursor_position.changed().connect(
160 [&position](
int value)
165 tf.move_cursor_to(22);
167 EXPECT_EQ(22, position);
170 TEST(Property, chaining_properties_works)
178 EXPECT_EQ(42, p2.
get());
181 TEST(Property, getter_is_invoked_for_get_operations)
183 bool invoked =
false;
184 auto getter = [&invoked]()
193 EXPECT_EQ(42, prop.
get());
194 EXPECT_TRUE(invoked);
197 TEST(Property, setter_is_invoked_for_set_operations)
200 auto setter = [&value](
int new_value)
209 EXPECT_EQ(42, value);