File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
tests/auto/foundation/object Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ class KDFOUNDATION_API Object : public EventReceiver
6262 }
6363
6464 template <typename T, typename ... Ts>
65- T *createChild (Ts... args)
65+ T *createChild (Ts && ...args)
6666 {
6767 auto child = std::make_unique<T>(std::forward<Ts>(args)...);
6868 return static_cast <T *>(this ->addChild (std::move (child)));
Original file line number Diff line number Diff line change @@ -99,6 +99,17 @@ class UserEvent : public Event
9999 }
100100};
101101
102+ class ObjectThatTakesInRef : public Object
103+ {
104+ public:
105+ ObjectThatTakesInRef (Object &obj)
106+ : ref(obj)
107+ {
108+ }
109+
110+ Object &ref;
111+ };
112+
102113TEST_CASE (" Object construction" )
103114{
104115 SUBCASE (" can create an object with no parent" )
@@ -131,6 +142,29 @@ TEST_CASE("Object construction")
131142 REQUIRE (std::get<1 >(childAddedSpy.args ()) == child);
132143 }
133144
145+ SUBCASE (" can create an object that takes in a ref with a parent" )
146+ {
147+ // GIVEN
148+ auto parent = std::make_unique<Object>();
149+ SignalSpy<Object *, Object *> childAddedSpy (parent->childAdded );
150+
151+ // THEN
152+ REQUIRE (childAddedSpy.count () == 0 );
153+
154+ // WHEN
155+ {
156+ auto child = parent->createChild <ObjectThatTakesInRef>(*parent);
157+
158+ // THEN
159+ REQUIRE (child != nullptr );
160+ REQUIRE (child->parent () == parent.get ());
161+ REQUIRE (parent->children ().size () == 1 );
162+ REQUIRE (childAddedSpy.count () == 1 );
163+ REQUIRE (std::get<0 >(childAddedSpy.args ()) == parent.get ());
164+ REQUIRE (std::get<1 >(childAddedSpy.args ()) == child);
165+ }
166+ }
167+
134168 SUBCASE (" can create a subclass of Object taking an argument" )
135169 {
136170 auto obj = std::make_unique<IntObject>(7 );
You can’t perform that action at this time.
0 commit comments