2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali-test-suite-utils.h>
22 #include <dali/public-api/dali-core.h>
29 // Functors to test whether Object created/destroyed signal is emitted for different types of Objects
31 struct TestObjectDestroyedCallback
33 TestObjectDestroyedCallback(bool& signalReceived, Dali::RefObject*& objectPointer)
34 : mSignalVerified(signalReceived),
35 mObjectPointer(objectPointer)
39 void operator()(const Dali::RefObject* objectPointer)
41 tet_infoline("Verifying TestObjectDestroyedCallback()");
43 if(objectPointer == mObjectPointer)
45 mSignalVerified = true;
49 bool& mSignalVerified;
50 Dali::RefObject*& mObjectPointer;
53 struct TestActorCallback
55 TestActorCallback(bool& signalReceived)
56 : mSignalVerified(signalReceived)
60 void operator()(BaseHandle object)
62 tet_infoline("Verifying TestActorCallback()");
63 Actor actor = Actor::DownCast(object);
66 mSignalVerified = true;
70 bool& mSignalVerified;
73 struct TestCameraActorCallback
75 TestCameraActorCallback(bool& signalReceived)
76 : mSignalVerified(signalReceived)
79 void operator()(BaseHandle object)
81 tet_infoline("Verifying TestCameraActorCallback()");
82 CameraActor actor = CameraActor::DownCast(object);
85 mSignalVerified = true;
88 bool& mSignalVerified;
91 struct TestLayerCallback
93 TestLayerCallback(bool& signalReceived)
94 : mSignalVerified(signalReceived)
97 void operator()(BaseHandle object)
99 tet_infoline("Verifying TestLayerCallback()");
100 Layer actor = Layer::DownCast(object);
103 mSignalVerified = true;
106 bool& mSignalVerified;
109 struct TestAnimationCallback
111 TestAnimationCallback(bool& signalReceived)
112 : mSignalVerified(signalReceived)
115 void operator()(BaseHandle object)
117 tet_infoline("Verifying TestAnimationCallback()");
118 Animation actor = Animation::DownCast(object);
121 mSignalVerified = true;
124 bool& mSignalVerified;
127 } // anonymous namespace
129 int UtcDaliObjectRegistryGet(void)
131 TestApplication application;
133 ObjectRegistry registry; // like this for ctor code coverage
134 registry= application.GetCore().GetObjectRegistry();
136 DALI_TEST_CHECK( registry );
140 int UtcDaliObjectRegistryCopyConstructor(void)
142 TestApplication application;
144 ObjectRegistry myRegistry;
145 ObjectRegistry anotherRegistry( myRegistry );
147 DALI_TEST_EQUALS( myRegistry, anotherRegistry, TEST_LOCATION );
151 int UtcDaliObjectRegistryMoveConstructor(void)
153 TestApplication application;
155 ObjectRegistry registry = application.GetCore().GetObjectRegistry();
156 DALI_TEST_CHECK( registry );
157 DALI_TEST_EQUALS( 2, registry.GetBaseObject().ReferenceCount(), TEST_LOCATION );
159 ObjectRegistry move = std::move( registry );
160 DALI_TEST_CHECK( move );
162 // Check that object is moved (not copied, so ref count keeps the same)
163 DALI_TEST_EQUALS( 2, move.GetBaseObject().ReferenceCount(), TEST_LOCATION );
164 DALI_TEST_CHECK( !registry );
169 int UtcDaliObjectRegistryMoveAssignment(void)
171 TestApplication application;
173 ObjectRegistry registry = application.GetCore().GetObjectRegistry();
174 DALI_TEST_CHECK( registry );
175 DALI_TEST_EQUALS( 2, registry.GetBaseObject().ReferenceCount(), TEST_LOCATION );
178 move = std::move( registry );
179 DALI_TEST_CHECK( move );
181 // Check that object is moved (not copied, so ref count keeps the same)
182 DALI_TEST_EQUALS( 2, move.GetBaseObject().ReferenceCount(), TEST_LOCATION );
183 DALI_TEST_CHECK( !registry );
188 int UtcDaliObjectRegistrySignalActorCreated(void)
190 tet_infoline("Testing GetObjectRegistry()");
191 TestApplication application;
192 ObjectRegistry registry = application.GetCore().GetObjectRegistry();
193 DALI_TEST_CHECK( registry );
195 bool verified = false;
196 TestActorCallback test(verified);
198 Dali::RefObject* objectPointer = NULL;
199 TestObjectDestroyedCallback test2(verified, objectPointer);
201 registry.ObjectCreatedSignal().Connect(&application, test);
202 registry.ObjectDestroyedSignal().Connect(&application, test2);
205 Actor actor = Actor::New();
206 DALI_TEST_CHECK( test.mSignalVerified );
209 objectPointer = actor.GetObjectPtr();
211 DALI_TEST_CHECK( test.mSignalVerified );
215 int UtcDaliObjectRegistrySignalCameraCreated(void)
217 TestApplication application;
219 ObjectRegistry registry = application.GetCore().GetObjectRegistry();
221 bool verified = false;
222 TestCameraActorCallback test(verified);
224 Dali::RefObject* objectPointer = NULL;
225 TestObjectDestroyedCallback test2(verified, objectPointer);
227 registry.ObjectCreatedSignal().Connect(&application, test);
228 registry.ObjectDestroyedSignal().Connect(&application, test2);
231 CameraActor actor = CameraActor::New();
232 DALI_TEST_CHECK( test.mSignalVerified );
235 objectPointer = actor.GetObjectPtr();
237 DALI_TEST_CHECK( test.mSignalVerified );
241 int UtcDaliObjectRegistrySignalLayerCreated(void)
243 TestApplication application;
244 ObjectRegistry registry = application.GetCore().GetObjectRegistry();
246 bool verified = false;
247 TestLayerCallback test(verified);
249 Dali::RefObject* objectPointer = NULL;
250 TestObjectDestroyedCallback test2(verified, objectPointer);
252 registry.ObjectCreatedSignal().Connect(&application, test);
253 registry.ObjectDestroyedSignal().Connect(&application, test2);
256 Layer actor = Layer::New();
257 DALI_TEST_CHECK( test.mSignalVerified );
260 objectPointer = actor.GetObjectPtr();
262 DALI_TEST_CHECK( test.mSignalVerified );
266 int UtcDaliObjectRegistrySignalAnimationCreated(void)
268 TestApplication application;
269 ObjectRegistry registry = application.GetCore().GetObjectRegistry();
271 bool verified = false;
272 TestAnimationCallback test(verified);
274 Dali::RefObject* objectPointer = NULL;
275 TestObjectDestroyedCallback test2(verified, objectPointer);
277 registry.ObjectCreatedSignal().Connect(&application, test);
278 registry.ObjectDestroyedSignal().Connect(&application, test2);
281 Animation animation = Animation::New(1.0f);
282 DALI_TEST_CHECK( test.mSignalVerified );
285 objectPointer = animation.GetObjectPtr();
287 DALI_TEST_CHECK( test.mSignalVerified );
291 int UtcDaliObjectRegistryObjectCreatedSignalNegative(void)
293 TestApplication application;
294 Dali::ObjectRegistry instance;
297 instance.ObjectCreatedSignal();
298 DALI_TEST_CHECK(false); // Should not get here
302 DALI_TEST_CHECK(true); // We expect an assert
307 int UtcDaliObjectRegistryObjectDestroyedSignalNegative(void)
309 TestApplication application;
310 Dali::ObjectRegistry instance;
313 instance.ObjectDestroyedSignal();
314 DALI_TEST_CHECK(false); // Should not get here
318 DALI_TEST_CHECK(true); // We expect an assert