2 * Copyright (c) 2014 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>
23 #include <dali/devel-api/actors/mesh-actor.h>
24 #include <dali/devel-api/geometry/mesh.h>
28 #include "mesh-builder.h"
33 // Functors to test whether Object created/destroyed signal is emitted for different types of Objects
35 struct TestObjectDestroyedCallback
37 TestObjectDestroyedCallback(bool& signalReceived, Dali::RefObject*& objectPointer)
38 : mSignalVerified(signalReceived),
39 mObjectPointer(objectPointer)
43 void operator()(const Dali::RefObject* objectPointer)
45 tet_infoline("Verifying TestObjectDestroyedCallback()");
47 if(objectPointer == mObjectPointer)
49 mSignalVerified = true;
53 bool& mSignalVerified;
54 Dali::RefObject*& mObjectPointer;
57 struct TestActorCallback
59 TestActorCallback(bool& signalReceived)
60 : mSignalVerified(signalReceived)
64 void operator()(BaseHandle object)
66 tet_infoline("Verifying TestActorCallback()");
67 Actor actor = Actor::DownCast(object);
70 mSignalVerified = true;
74 bool& mSignalVerified;
77 struct TestCameraActorCallback
79 TestCameraActorCallback(bool& signalReceived)
80 : mSignalVerified(signalReceived)
83 void operator()(BaseHandle object)
85 tet_infoline("Verifying TestCameraActorCallback()");
86 CameraActor actor = CameraActor::DownCast(object);
89 mSignalVerified = true;
92 bool& mSignalVerified;
95 struct TestImageActorCallback
97 TestImageActorCallback(bool& signalReceived)
98 : mSignalVerified(signalReceived)
101 void operator()(BaseHandle object)
103 tet_infoline("Verifying TestImageActorCallback()");
104 ImageActor actor = ImageActor::DownCast(object);
107 mSignalVerified = true;
110 bool& mSignalVerified;
113 struct TestLayerCallback
115 TestLayerCallback(bool& signalReceived)
116 : mSignalVerified(signalReceived)
119 void operator()(BaseHandle object)
121 tet_infoline("Verifying TestLayerCallback()");
122 Layer actor = Layer::DownCast(object);
125 mSignalVerified = true;
128 bool& mSignalVerified;
132 struct TestMeshActorCallback
134 TestMeshActorCallback(bool& signalReceived)
135 : mSignalVerified(signalReceived)
138 void operator()(BaseHandle object)
140 tet_infoline("Verifying TestMeshActorCallback()");
141 MeshActor actor = MeshActor::DownCast(object);
144 mSignalVerified = true;
147 bool& mSignalVerified;
150 struct TestAnimationCallback
152 TestAnimationCallback(bool& signalReceived)
153 : mSignalVerified(signalReceived)
156 void operator()(BaseHandle object)
158 tet_infoline("Verifying TestAnimationCallback()");
159 Animation actor = Animation::DownCast(object);
162 mSignalVerified = true;
165 bool& mSignalVerified;
168 struct TestShaderEffectCallback
170 TestShaderEffectCallback(bool& signalReceived)
171 : mSignalVerified(signalReceived)
174 void operator()(BaseHandle object)
176 tet_infoline("Verifying TestShaderEffectCallback()");
177 ShaderEffect actor = ShaderEffect::DownCast(object);
180 mSignalVerified = true;
183 bool& mSignalVerified;
187 } // anonymous namespace
192 int UtcDaliObjectRegistryGet(void)
194 TestApplication application;
196 ObjectRegistry registry; // like this for ctor code coverage
197 registry= Stage::GetCurrent().GetObjectRegistry();
199 DALI_TEST_CHECK( registry );
203 int UtcDaliObjectRegistryCopyConstructor(void)
205 TestApplication application;
206 tet_printf(" copy consturctor ");
208 ObjectRegistry myRegistry;
210 ObjectRegistry anotherRegistry( myRegistry );
212 tet_result( TET_PASS );
218 int UtcDaliObjectRegistrySignalActorCreated(void)
220 tet_infoline("Testing GetObjectRegistry()");
221 TestApplication application;
222 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
223 DALI_TEST_CHECK( registry );
225 bool verified = false;
226 TestActorCallback test(verified);
228 Dali::RefObject* objectPointer = NULL;
229 TestObjectDestroyedCallback test2(verified, objectPointer);
231 registry.ObjectCreatedSignal().Connect(&application, test);
232 registry.ObjectDestroyedSignal().Connect(&application, test2);
235 Actor actor = Actor::New();
236 DALI_TEST_CHECK( test.mSignalVerified );
239 objectPointer = actor.GetObjectPtr();
241 DALI_TEST_CHECK( test.mSignalVerified );
245 int UtcDaliObjectRegistrySignalCameraCreated(void)
247 TestApplication application;
249 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
251 bool verified = false;
252 TestCameraActorCallback test(verified);
254 Dali::RefObject* objectPointer = NULL;
255 TestObjectDestroyedCallback test2(verified, objectPointer);
257 registry.ObjectCreatedSignal().Connect(&application, test);
258 registry.ObjectDestroyedSignal().Connect(&application, test2);
261 CameraActor actor = CameraActor::New();
262 DALI_TEST_CHECK( test.mSignalVerified );
265 objectPointer = actor.GetObjectPtr();
267 DALI_TEST_CHECK( test.mSignalVerified );
271 int UtcDaliObjectRegistrySignalImageActorCreated(void)
273 TestApplication application;
274 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
276 static const char* TestImageFilename = "icon_wrt.png";
277 Image image = ResourceImage::New(TestImageFilename);
279 bool verified = false;
280 TestImageActorCallback test(verified);
282 Dali::RefObject* objectPointer = NULL;
283 TestObjectDestroyedCallback test2(verified, objectPointer);
285 registry.ObjectCreatedSignal().Connect(&application, test);
286 registry.ObjectDestroyedSignal().Connect(&application, test2);
289 ImageActor actor = ImageActor::New(image);
290 DALI_TEST_CHECK( test.mSignalVerified );
293 objectPointer = actor.GetObjectPtr();
295 DALI_TEST_CHECK( test.mSignalVerified );
299 int UtcDaliObjectRegistrySignalLayerCreated(void)
301 TestApplication application;
302 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
304 bool verified = false;
305 TestLayerCallback test(verified);
307 Dali::RefObject* objectPointer = NULL;
308 TestObjectDestroyedCallback test2(verified, objectPointer);
310 registry.ObjectCreatedSignal().Connect(&application, test);
311 registry.ObjectDestroyedSignal().Connect(&application, test2);
314 Layer actor = Layer::New();
315 DALI_TEST_CHECK( test.mSignalVerified );
318 objectPointer = actor.GetObjectPtr();
320 DALI_TEST_CHECK( test.mSignalVerified );
325 int UtcDaliObjectRegistrySignalMeshActorCreated(void)
327 TestApplication application;
328 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
330 bool verified = false;
331 TestMeshActorCallback test(verified);
333 Dali::RefObject* objectPointer = NULL;
334 TestObjectDestroyedCallback test2(verified, objectPointer);
336 registry.ObjectCreatedSignal().Connect(&application, test);
337 registry.ObjectDestroyedSignal().Connect(&application, test2);
339 Mesh mesh = ConstructMesh(60);
342 MeshActor actor = MeshActor::New(mesh);
344 DALI_TEST_CHECK(actor);
345 DALI_TEST_CHECK( test.mSignalVerified );
348 objectPointer = actor.GetObjectPtr();
350 DALI_TEST_CHECK( test.mSignalVerified );
355 int UtcDaliObjectRegistrySignalAnimationCreated(void)
357 TestApplication application;
358 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
360 bool verified = false;
361 TestAnimationCallback test(verified);
363 Dali::RefObject* objectPointer = NULL;
364 TestObjectDestroyedCallback test2(verified, objectPointer);
366 registry.ObjectCreatedSignal().Connect(&application, test);
367 registry.ObjectDestroyedSignal().Connect(&application, test2);
370 Animation animation = Animation::New(1.0f);
371 DALI_TEST_CHECK( test.mSignalVerified );
374 objectPointer = animation.GetObjectPtr();
376 DALI_TEST_CHECK( test.mSignalVerified );
380 int UtcDaliObjectRegistrySignalShaderEffectCreated(void)
382 TestApplication application;
383 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
385 static const char* VertexSource =
388 " gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\n"
389 " vTexCoord = aTexCoord;\n"
392 static const char* FragmentSource =
395 " gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n"
398 bool verified = false;
399 TestShaderEffectCallback test(verified);
401 Dali::RefObject* objectPointer = NULL;
402 TestObjectDestroyedCallback test2(verified, objectPointer);
404 registry.ObjectCreatedSignal().Connect(&application, test);
405 registry.ObjectDestroyedSignal().Connect(&application, test2);
408 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
409 DALI_TEST_CHECK( test.mSignalVerified );
412 objectPointer = effect.GetObjectPtr();
414 DALI_TEST_CHECK( test.mSignalVerified );