Dali 3D User Interface Engine
utc-Dali-ObjectRegistry.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 
18 #include <iostream>
19 
20 #include <stdlib.h>
21 #include <dali-test-suite-utils.h>
23 
24 using namespace Dali;
25 
26 namespace
27 {
28 
29 // Functors to test whether Object created/destroyed signal is emitted for different types of Objects
30 
32 {
33  TestObjectDestroyedCallback(bool& signalReceived, Dali::RefObject*& objectPointer)
34  : mSignalVerified(signalReceived),
35  mObjectPointer(objectPointer)
36  {
37  }
38 
39  void operator()(const Dali::RefObject* objectPointer)
40  {
41  tet_infoline("Verifying TestObjectDestroyedCallback()");
42 
43  if(objectPointer == mObjectPointer)
44  {
45  mSignalVerified = true;
46  }
47  }
48 
51 };
52 
54 {
55  TestActorCallback(bool& signalReceived)
56  : mSignalVerified(signalReceived)
57  {
58  }
59 
60  void operator()(BaseHandle object)
61  {
62  tet_infoline("Verifying TestActorCallback()");
63  Actor actor = Actor::DownCast(object);
64  if(actor)
65  {
66  mSignalVerified = true;
67  }
68  }
69 
71 };
72 
74 {
75  TestCameraActorCallback(bool& signalReceived)
76  : mSignalVerified(signalReceived)
77  {
78  }
79  void operator()(BaseHandle object)
80  {
81  tet_infoline("Verifying TestCameraActorCallback()");
82  CameraActor actor = CameraActor::DownCast(object);
83  if(actor)
84  {
85  mSignalVerified = true;
86  }
87  }
89 };
90 
92 {
93  TestImageActorCallback(bool& signalReceived)
94  : mSignalVerified(signalReceived)
95  {
96  }
97  void operator()(BaseHandle object)
98  {
99  tet_infoline("Verifying TestImageActorCallback()");
100  ImageActor actor = ImageActor::DownCast(object);
101  if(actor)
102  {
103  mSignalVerified = true;
104  }
105  }
107 };
108 
110 {
111  TestLayerCallback(bool& signalReceived)
112  : mSignalVerified(signalReceived)
113  {
114  }
115  void operator()(BaseHandle object)
116  {
117  tet_infoline("Verifying TestLayerCallback()");
118  Layer actor = Layer::DownCast(object);
119  if(actor)
120  {
121  mSignalVerified = true;
122  }
123  }
125 };
126 
128 {
129  TestAnimationCallback(bool& signalReceived)
130  : mSignalVerified(signalReceived)
131  {
132  }
133  void operator()(BaseHandle object)
134  {
135  tet_infoline("Verifying TestAnimationCallback()");
136  Animation actor = Animation::DownCast(object);
137  if(actor)
138  {
139  mSignalVerified = true;
140  }
141  }
143 };
144 
146 {
147  TestShaderEffectCallback(bool& signalReceived)
148  : mSignalVerified(signalReceived)
149  {
150  }
151  void operator()(BaseHandle object)
152  {
153  tet_infoline("Verifying TestShaderEffectCallback()");
154  ShaderEffect actor = ShaderEffect::DownCast(object);
155  if(actor)
156  {
157  mSignalVerified = true;
158  }
159  }
161 };
162 
163 
164 } // anonymous namespace
165 
166 
167 
168 
170 {
171  TestApplication application;
172 
173  ObjectRegistry registry; // like this for ctor code coverage
174  registry= Stage::GetCurrent().GetObjectRegistry();
175 
176  DALI_TEST_CHECK( registry );
177  END_TEST;
178 }
179 
181 {
182  TestApplication application;
183 
184  ObjectRegistry myRegistry;
185  ObjectRegistry anotherRegistry( myRegistry );
186 
187  DALI_TEST_EQUALS( myRegistry, anotherRegistry, TEST_LOCATION );
188  END_TEST;
189 }
190 
192 {
193  tet_infoline("Testing GetObjectRegistry()");
194  TestApplication application;
196  DALI_TEST_CHECK( registry );
197 
198  bool verified = false;
199  TestActorCallback test(verified);
200 
201  Dali::RefObject* objectPointer = NULL;
202  TestObjectDestroyedCallback test2(verified, objectPointer);
203 
204  registry.ObjectCreatedSignal().Connect(&application, test);
205  registry.ObjectDestroyedSignal().Connect(&application, test2);
206 
207  {
208  Actor actor = Actor::New();
209  DALI_TEST_CHECK( test.mSignalVerified );
210 
211  verified = false;
212  objectPointer = actor.GetObjectPtr();
213  }
214  DALI_TEST_CHECK( test.mSignalVerified );
215  END_TEST;
216 }
217 
219 {
220  TestApplication application;
221 
223 
224  bool verified = false;
225  TestCameraActorCallback test(verified);
226 
227  Dali::RefObject* objectPointer = NULL;
228  TestObjectDestroyedCallback test2(verified, objectPointer);
229 
230  registry.ObjectCreatedSignal().Connect(&application, test);
231  registry.ObjectDestroyedSignal().Connect(&application, test2);
232 
233  {
234  CameraActor actor = CameraActor::New();
235  DALI_TEST_CHECK( test.mSignalVerified );
236 
237  verified = false;
238  objectPointer = actor.GetObjectPtr();
239  }
240  DALI_TEST_CHECK( test.mSignalVerified );
241  END_TEST;
242 }
243 
245 {
246  TestApplication application;
248 
249  static const char* TestImageFilename = "icon_wrt.png";
250  Image image = ResourceImage::New(TestImageFilename);
251 
252  bool verified = false;
253  TestImageActorCallback test(verified);
254 
255  Dali::RefObject* objectPointer = NULL;
256  TestObjectDestroyedCallback test2(verified, objectPointer);
257 
258  registry.ObjectCreatedSignal().Connect(&application, test);
259  registry.ObjectDestroyedSignal().Connect(&application, test2);
260 
261  {
262  ImageActor actor = ImageActor::New(image);
263  DALI_TEST_CHECK( test.mSignalVerified );
264 
265  verified = false;
266  objectPointer = actor.GetObjectPtr();
267  }
268  DALI_TEST_CHECK( test.mSignalVerified );
269  END_TEST;
270 }
271 
273 {
274  TestApplication application;
276 
277  bool verified = false;
278  TestLayerCallback test(verified);
279 
280  Dali::RefObject* objectPointer = NULL;
281  TestObjectDestroyedCallback test2(verified, objectPointer);
282 
283  registry.ObjectCreatedSignal().Connect(&application, test);
284  registry.ObjectDestroyedSignal().Connect(&application, test2);
285 
286  {
287  Layer actor = Layer::New();
288  DALI_TEST_CHECK( test.mSignalVerified );
289 
290  verified = false;
291  objectPointer = actor.GetObjectPtr();
292  }
293  DALI_TEST_CHECK( test.mSignalVerified );
294  END_TEST;
295 }
296 
298 {
299  TestApplication application;
301 
302  bool verified = false;
303  TestAnimationCallback test(verified);
304 
305  Dali::RefObject* objectPointer = NULL;
306  TestObjectDestroyedCallback test2(verified, objectPointer);
307 
308  registry.ObjectCreatedSignal().Connect(&application, test);
309  registry.ObjectDestroyedSignal().Connect(&application, test2);
310 
311  {
312  Animation animation = Animation::New(1.0f);
313  DALI_TEST_CHECK( test.mSignalVerified );
314 
315  verified = false;
316  objectPointer = animation.GetObjectPtr();
317  }
318  DALI_TEST_CHECK( test.mSignalVerified );
319  END_TEST;
320 }
321 
323 {
324  TestApplication application;
326 
327  static const char* VertexSource =
328  "void main()\n"
329  "{\n"
330  " gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\n"
331  " vTexCoord = aTexCoord;\n"
332  "}\n";
333 
334  static const char* FragmentSource =
335  "void main()\n"
336  "{\n"
337  " gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n"
338  "}\n";
339 
340  bool verified = false;
341  TestShaderEffectCallback test(verified);
342 
343  Dali::RefObject* objectPointer = NULL;
344  TestObjectDestroyedCallback test2(verified, objectPointer);
345 
346  registry.ObjectCreatedSignal().Connect(&application, test);
347  registry.ObjectDestroyedSignal().Connect(&application, test2);
348 
349  {
350  ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
351  DALI_TEST_CHECK( test.mSignalVerified );
352 
353  verified = false;
354  objectPointer = effect.GetObjectPtr();
355  }
356  DALI_TEST_CHECK( test.mSignalVerified );
357  END_TEST;
358 }
Dali Docs Home
Read more about Dali