21#include <gtest/gtest.h>
23TEST(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());
34TEST(Property, copy_construction_yields_correct_value)
36 static const int default_value = 42;
40 EXPECT_EQ(default_value, p2.get());
43TEST(Property, assignment_operator_for_properties_works)
45 static const int default_value = 42;
50 EXPECT_EQ(default_value, p2.
get());
53TEST(Property, assignment_operator_for_raw_values_works)
55 static const int default_value = 42;
59 EXPECT_EQ(default_value, p1.
get());
62TEST(Property, equality_operator_for_properties_works)
64 static const int default_value = 42;
72TEST(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;
100TEST(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());
113TEST(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());
127TEST(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);
153TEST(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);
170TEST(Property, chaining_properties_works)
178 EXPECT_EQ(42, p2.
get());
181TEST(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);
197TEST(Property, setter_is_invoked_for_set_operations)
200 auto setter = [&value](
int new_value)
209 EXPECT_EQ(42, value);
A very simple, templated class that allows for uniform declaration of get-able/set-able/observable me...
void install(const Setter &setter)
install takes the provided functor and installs it for dispatching all set operations.
virtual void set(const T &new_value)
Set the contained value to the provided value. Notify observers of the change.
const Signal< T > & changed() const
Access to the changed signal, allows observers to subscribe to change notifications.
virtual const T & get() const
Access the value contained within this property.
virtual bool update(const std::function< bool(T &t)> &update_functor)
Provides in-place update facilities.
Connection connect(const Slot &slot) const
Connects the provided slot to this signal instance.
TEST(Property, default_construction_yields_default_value)