23f575d6da3884f5f0e15a3525b37a8254ec0d04
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-PropertyNotification.cpp
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/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23
24 using namespace Dali;
25
26 void utc_dali_property_notification_startup(void)
27 {
28   test_return_value = TET_UNDEF;
29 }
30
31 void utc_dali_property_notification_cleanup(void)
32 {
33   test_return_value = TET_PASS;
34 }
35
36 namespace {
37
38 static bool gCallBackCalled;
39
40 static void TestCallback(PropertyNotification& source)
41 {
42   gCallBackCalled = true;
43 }
44
45 const int RENDER_FRAME_INTERVAL(16);                           ///< Duration of each frame in ms. (at approx 60FPS)
46 const int DEFAULT_WAIT_PERIOD(100);                            ///< Default waiting period for check.
47
48
49 class TestClass : public ConnectionTracker
50 {
51 public:
52
53   TestClass()
54   {
55   }
56
57   ~TestClass()
58   {
59   }
60
61   void Initialize()
62   {
63     mActor = Actor::New();
64     Stage::GetCurrent().Add( mActor );
65     mNotification = mActor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(100.0f) );
66     mNotification.NotifySignal().Connect( this, &TestClass::OnPropertyNotify );
67   }
68
69   void RemovePropertyNotification()
70   {
71     mActor.RemovePropertyNotification( mNotification );
72   }
73
74   void RemovePropertyNotifications()
75   {
76     mActor.RemovePropertyNotifications();
77   }
78
79   void Terminate()
80   {
81     Stage::GetCurrent().Remove( mActor );
82     mActor.Reset();
83     mNotification.Reset();
84   }
85
86   void OnPropertyNotify( PropertyNotification& source )
87   {
88     tet_infoline(" OnPropertyNotify");
89     gCallBackCalled = true;
90   }
91
92   Actor mActor;
93   PropertyNotification mNotification;
94 };
95
96
97 /*
98  * Simulate time passed by.
99  *
100  * @note this will always process at least 1 frame (1/60 sec)
101  *
102  * @param application Test application instance
103  * @param duration Time to pass in milliseconds.
104  * @return The actual time passed in milliseconds
105  */
106 int Wait(TestApplication& application, int duration = 0)
107 {
108   int time = 0;
109
110   for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
111   {
112     application.SendNotification();
113     application.Render(RENDER_FRAME_INTERVAL);
114     time += RENDER_FRAME_INTERVAL;
115   }
116
117   return time;
118 }
119
120 } // unnamed namespace
121
122
123 // Positive test case for a method
124 int UtcDaliPropertyNotificationDownCast(void)
125 {
126   TestApplication application;
127   tet_infoline(" UtcDaliPropertyNotificationDownCast");
128
129   Actor actor = Actor::New();
130   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X, GreaterThanCondition(100.0f));
131   BaseHandle handle = notification;
132   PropertyNotification notificationHandle;
133
134   DALI_TEST_CHECK(notification);
135   DALI_TEST_CHECK(handle);
136   DALI_TEST_CHECK(!notificationHandle);
137
138   notificationHandle = PropertyNotification::DownCast( handle );
139   DALI_TEST_CHECK(notificationHandle);
140   END_TEST;
141 }
142
143
144 // Negative test case for a method
145 int UtcDaliPropertyNotificationDownCastNegative(void)
146 {
147   TestApplication application;
148   tet_infoline(" UtcDaliPropertyNotificationDownCastNegative");
149
150   // Create something derived from BaseHandle other than a PropertyNotification.
151   Actor somethingElse = Actor::New();
152
153   Actor actor = Actor::New();
154   actor.AddPropertyNotification(Actor::Property::POSITION_X, GreaterThanCondition(100.0f));
155   BaseHandle handle = somethingElse;
156   PropertyNotification notificationHandle;
157
158   notificationHandle = PropertyNotification::DownCast( handle );
159   DALI_TEST_CHECK(!notificationHandle);
160   END_TEST;
161 }
162
163 int UtcDaliAddPropertyNotification(void)
164 {
165   TestApplication application; // Reset all test adapter return codes
166   tet_infoline(" UtcDaliAddPropertyNotification");
167
168   Actor actor = Actor::New();
169
170   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X, GreaterThanCondition(100.0f));
171   DALI_TEST_CHECK( notification );
172   END_TEST;
173 }
174
175 int UtcDaliAddPropertyNotificationCallback(void)
176 {
177   TestApplication application; // Reset all test adapter return codes
178
179   TestClass* object = new TestClass;
180
181   object->Initialize();
182   application.Render(RENDER_FRAME_INTERVAL);
183   application.SendNotification();
184
185   gCallBackCalled = false;
186
187   tet_infoline(" UtcDaliAddPropertyNotificationCallback - Forcing notification condition true, should receive a notification");
188   object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
189   application.Render(RENDER_FRAME_INTERVAL);
190   application.SendNotification();
191   application.Render(RENDER_FRAME_INTERVAL);
192   application.SendNotification();
193   DALI_TEST_CHECK( gCallBackCalled );
194   gCallBackCalled = false;
195
196   tet_infoline(" UtcDaliAddPropertyNotificationCallback - Forcing notification condition false, should not receive a notification");
197   object->mActor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
198   application.Render(RENDER_FRAME_INTERVAL);
199   application.SendNotification();
200   application.Render(RENDER_FRAME_INTERVAL);
201   application.SendNotification();
202   DALI_TEST_CHECK( !gCallBackCalled );
203   gCallBackCalled = false;
204
205   tet_infoline(" UtcDaliAddPropertyNotificationCallback - Deleting notification and it's owning object, should not receive a notification");
206   object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
207   application.Render(RENDER_FRAME_INTERVAL);
208   application.SendNotification();
209   object->Terminate();
210   application.Render(RENDER_FRAME_INTERVAL);
211   application.SendNotification();
212   DALI_TEST_CHECK( !gCallBackCalled );
213
214   tet_infoline(" UtcDaliAddPropertyNotificationCallback - Removing notification and it's owning object, should not receive a notification");
215   object->Initialize();
216   application.Render(RENDER_FRAME_INTERVAL);
217   application.SendNotification();
218   gCallBackCalled = false;
219
220   object->RemovePropertyNotification();
221
222   object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
223   application.Render(RENDER_FRAME_INTERVAL);
224   application.SendNotification();
225   application.Render(RENDER_FRAME_INTERVAL);
226   application.SendNotification();
227   DALI_TEST_CHECK( !gCallBackCalled );
228
229   tet_infoline(" UtcDaliAddPropertyNotificationCallback - Removing all notifications and it's owning object, should not receive a notification");
230   object->Initialize();
231   application.Render(RENDER_FRAME_INTERVAL);
232   application.SendNotification();
233   gCallBackCalled = false;
234
235   object->RemovePropertyNotifications();
236
237   object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
238   application.Render(RENDER_FRAME_INTERVAL);
239   application.SendNotification();
240   application.Render(RENDER_FRAME_INTERVAL);
241   application.SendNotification();
242   DALI_TEST_CHECK( !gCallBackCalled );
243
244
245   delete object;
246   END_TEST;
247 }
248
249 int UtcDaliAddPropertyNotificationTypeProperty(void)
250 {
251   TestApplication application;
252
253   Actor actor = Actor::New();
254
255   // Currently, Type registry properties cannot be animated
256   try
257   {
258     actor.AddPropertyNotification( PROPERTY_REGISTRATION_START_INDEX, GreaterThanCondition( 100.0f ) );
259   }
260   catch ( DaliException& e )
261   {
262     DALI_TEST_ASSERT( e, "Property notification added to event side only property", TEST_LOCATION );
263   }
264   END_TEST;
265 }
266
267 int UtcDaliAddPropertyNotificationEventSidePropertyN(void)
268 {
269   TestApplication application;
270
271   Actor actor = Actor::New();
272
273   // Currently, Type registry properties cannot be animated
274   try
275   {
276     actor.AddPropertyNotification( PROPERTY_REGISTRATION_MAX_INDEX - 1, GreaterThanCondition( 100.0f ) );
277   }
278   catch ( DaliException& e )
279   {
280     DALI_TEST_ASSERT( e, "Property notification added to event side only property", TEST_LOCATION );
281   }
282   END_TEST;
283 }
284
285 int UtcDaliPropertyNotificationGetCondition(void)
286 {
287   TestApplication application;
288   tet_infoline(" UtcDaliPropertyNotificationGetCondition");
289
290   Actor actor = Actor::New();
291
292   PropertyCondition condition = GreaterThanCondition(100.0f);
293   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X, condition);
294   DALI_TEST_CHECK( condition == notification.GetCondition() );
295   END_TEST;
296 }
297
298 class PropertyNotificationConstWrapper
299 {
300 public:
301
302   PropertyNotificationConstWrapper(PropertyNotification propertyNotification)
303   :mPropertyNotification(propertyNotification)
304   {
305
306   }
307
308   /**
309    * Returns const reference to property notification.
310    * @return const reference.
311    */
312   const PropertyCondition& GetCondition() const
313   {
314     return mPropertyNotification.GetCondition();
315   }
316
317   PropertyNotification mPropertyNotification;
318 };
319
320 int UtcDaliPropertyNotificationGetConditionConst(void)
321 {
322   TestApplication application;
323   tet_infoline(" UtcDaliPropertyNotificationGetConditionConst");
324
325   Actor actor = Actor::New();
326
327   PropertyCondition condition = GreaterThanCondition(100.0f);
328   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X, condition);
329   PropertyNotificationConstWrapper notificationConst(notification);
330   const PropertyCondition& conditionReference1 = notificationConst.GetCondition();
331   const PropertyCondition& conditionReference2 = notificationConst.GetCondition();
332
333   DALI_TEST_CHECK( (&conditionReference1) == (&conditionReference2) );
334   DALI_TEST_CHECK( conditionReference1 == condition );
335   END_TEST;
336 }
337
338 int UtcDaliPropertyNotificationGetTarget(void)
339 {
340   TestApplication application;
341   tet_infoline(" UtcDaliPropertyNotificationGetTarget");
342
343   Actor actor = Actor::New();
344   Actor actor2 = Actor::New();
345
346   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
347                                                                     GreaterThanCondition(100.0f));
348   Actor targetActor = Actor::DownCast( notification.GetTarget() );
349
350   DALI_TEST_CHECK( targetActor == actor );
351   END_TEST;
352 }
353
354 int UtcDaliPropertyNotificationGetProperty(void)
355 {
356   TestApplication application;
357   tet_infoline(" UtcDaliPropertyNotificationGetProperty");
358
359   Actor actor = Actor::New();
360
361   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
362                                                                     GreaterThanCondition(100.0f));
363   Property::Index targetProperty = notification.GetTargetProperty();
364
365   DALI_TEST_EQUALS( targetProperty, (Property::Index)Actor::Property::POSITION_X, TEST_LOCATION );
366   END_TEST;
367 }
368
369 int UtcDaliPropertyNotificationGetNotifyMode(void)
370 {
371   TestApplication application;
372   tet_infoline(" UtcDaliPropertyNotificationGetNotifyMode");
373
374   Actor actor = Actor::New();
375
376   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
377                                                                     GreaterThanCondition(100.0f));
378   notification.SetNotifyMode(PropertyNotification::NotifyOnChanged);
379   PropertyNotification::NotifyMode notifyMode = notification.GetNotifyMode();
380
381   DALI_TEST_EQUALS( notifyMode, PropertyNotification::NotifyOnChanged, TEST_LOCATION );
382   END_TEST;
383 }
384
385 int UtcDaliPropertyNotificationGetNotifyResultP(void)
386 {
387   TestApplication application;
388   tet_infoline(" UtcDaliPropertyNotificationGetNotifyMode");
389
390   Actor actor = Actor::New();
391
392   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
393                                                                     GreaterThanCondition(100.0f));
394   notification.SetNotifyMode(PropertyNotification::NotifyOnChanged);
395   gCallBackCalled = false;
396   notification.NotifySignal().Connect( &TestCallback );
397
398   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
399
400   application.Render(RENDER_FRAME_INTERVAL);
401   application.SendNotification();
402   application.Render(RENDER_FRAME_INTERVAL);
403   application.SendNotification();
404
405   bool notifyResult = notification.GetNotifyResult();
406
407   DALI_TEST_EQUALS( notifyResult, false, TEST_LOCATION );
408
409   END_TEST;
410 }
411
412 int UtcDaliPropertyNotificationGreaterThan(void)
413 {
414   TestApplication application;
415   tet_infoline(" UtcDaliPropertyNotificationGreaterThan");
416
417   Actor actor = Actor::New();
418   Stage::GetCurrent().Add(actor);
419
420   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(100.0f) );
421   notification.NotifySignal().Connect( &TestCallback );
422
423   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
424   Wait(application, DEFAULT_WAIT_PERIOD);
425
426   // Move right to satisfy condition
427   gCallBackCalled = false;
428   actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
429   Wait(application, DEFAULT_WAIT_PERIOD);
430   DALI_TEST_CHECK( gCallBackCalled );
431
432   // Move left to un-satisfy condition
433   gCallBackCalled = false;
434   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
435   Wait(application, DEFAULT_WAIT_PERIOD);
436   DALI_TEST_CHECK( !gCallBackCalled );
437
438   // Move right to satisfy condition again.
439   gCallBackCalled = false;
440   Wait(application, DEFAULT_WAIT_PERIOD);
441   actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
442   Wait(application, DEFAULT_WAIT_PERIOD);
443   DALI_TEST_CHECK( gCallBackCalled );
444   END_TEST;
445 }
446
447 int UtcDaliPropertyNotificationLessThan(void)
448 {
449   TestApplication application;
450   tet_infoline(" UtcDaliPropertyNotificationLessThan");
451
452   Actor actor = Actor::New();
453   Stage::GetCurrent().Add(actor);
454
455   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, LessThanCondition(100.0f ) );
456   notification.NotifySignal().Connect( &TestCallback );
457
458   actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
459   Wait(application, DEFAULT_WAIT_PERIOD);
460
461   // Move left to satisfy condition
462   gCallBackCalled = false;
463   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
464   Wait(application, DEFAULT_WAIT_PERIOD);
465   DALI_TEST_CHECK( gCallBackCalled );
466
467   // Move right to un-satisfy condition
468   gCallBackCalled = false;
469   actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
470   Wait(application, DEFAULT_WAIT_PERIOD);
471   DALI_TEST_CHECK( !gCallBackCalled );
472
473   // Move left to satisfy condition again.
474   gCallBackCalled = false;
475   Wait(application, DEFAULT_WAIT_PERIOD);
476   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
477   Wait(application, DEFAULT_WAIT_PERIOD);
478   DALI_TEST_CHECK( gCallBackCalled );
479   END_TEST;
480 }
481
482 int UtcDaliPropertyNotificationInside(void)
483 {
484   TestApplication application;
485   tet_infoline(" UtcDaliPropertyNotificationInside");
486
487   Actor actor = Actor::New();
488   Stage::GetCurrent().Add(actor);
489
490   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, InsideCondition(100.0f, 200.0f) );
491   notification.NotifySignal().Connect( &TestCallback );
492
493   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
494   Wait(application, DEFAULT_WAIT_PERIOD);
495
496   // Move inside to satisfy condition
497   gCallBackCalled = false;
498   actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
499   Wait(application, DEFAULT_WAIT_PERIOD);
500   DALI_TEST_CHECK( gCallBackCalled );
501
502   // Move outside (right) to un-satisfy condition
503   gCallBackCalled = false;
504   actor.SetPosition(Vector3(300.0f, 0.0f, 0.0f));
505   Wait(application, DEFAULT_WAIT_PERIOD);
506   DALI_TEST_CHECK( !gCallBackCalled );
507
508   // Move inside to satisfy condition again.
509   gCallBackCalled = false;
510   Wait(application, DEFAULT_WAIT_PERIOD);
511   actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
512   Wait(application, DEFAULT_WAIT_PERIOD);
513   DALI_TEST_CHECK( gCallBackCalled );
514   END_TEST;
515 }
516
517 int UtcDaliPropertyNotificationOutside(void)
518 {
519   TestApplication application;
520   tet_infoline(" UtcDaliPropertyNotificationOutside");
521
522   Actor actor = Actor::New();
523   Stage::GetCurrent().Add(actor);
524
525   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, OutsideCondition(100.0f, 200.0f) );
526   notification.NotifySignal().Connect( &TestCallback );
527
528   actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
529   Wait(application, DEFAULT_WAIT_PERIOD);
530
531   // Move outside (left) to satisfy condition
532   gCallBackCalled = false;
533   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
534   Wait(application, DEFAULT_WAIT_PERIOD);
535   DALI_TEST_CHECK( gCallBackCalled );
536
537   // Move inside to un-satisfy condition
538   gCallBackCalled = false;
539   actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
540   Wait(application, DEFAULT_WAIT_PERIOD);
541   DALI_TEST_CHECK( !gCallBackCalled );
542
543   // Move outside (right) to satisfy condition again.
544   gCallBackCalled = false;
545   Wait(application, DEFAULT_WAIT_PERIOD);
546   actor.SetPosition(Vector3(300.0f, 0.0f, 0.0f));
547   Wait(application, DEFAULT_WAIT_PERIOD);
548   DALI_TEST_CHECK( gCallBackCalled );
549   END_TEST;
550 }
551
552 int UtcDaliPropertyNotificationVectorComponentGreaterThan(void)
553 {
554   TestApplication application;
555   tet_infoline(" UtcDaliPropertyNotificationGreaterThan");
556
557   Actor actor = Actor::New();
558   Stage::GetCurrent().Add(actor);
559
560   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, GreaterThanCondition(100.0f) );
561   notification.NotifySignal().Connect( &TestCallback );
562   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, GreaterThanCondition(100.0f) );
563   notification.NotifySignal().Connect( &TestCallback );
564   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, GreaterThanCondition(100.0f) );
565   notification.NotifySignal().Connect( &TestCallback );
566   notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, GreaterThanCondition(0.5f) );
567   notification.NotifySignal().Connect( &TestCallback );
568
569   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
570   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
571   Wait(application, DEFAULT_WAIT_PERIOD);
572
573   // Move right to satisfy XAxis condition
574   gCallBackCalled = false;
575   actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
576   Wait(application, DEFAULT_WAIT_PERIOD);
577   DALI_TEST_CHECK( gCallBackCalled );
578
579   // Move down to satisfy YAxis condition
580   gCallBackCalled = false;
581   actor.SetPosition(Vector3(200.0f, 200.0f, 0.0f));
582   Wait(application, DEFAULT_WAIT_PERIOD);
583   DALI_TEST_CHECK( gCallBackCalled );
584
585   // Move forward to satisfy ZAxis
586   gCallBackCalled = false;
587   Wait(application, DEFAULT_WAIT_PERIOD);
588   actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
589   Wait(application, DEFAULT_WAIT_PERIOD);
590   DALI_TEST_CHECK( gCallBackCalled );
591
592   // Change alpha Colour to satisfy w/alpha component condition
593   gCallBackCalled = false;
594   Wait(application, DEFAULT_WAIT_PERIOD);
595   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
596   Wait(application, DEFAULT_WAIT_PERIOD);
597   DALI_TEST_CHECK( gCallBackCalled );
598   END_TEST;
599 }
600
601 int UtcDaliPropertyNotificationVectorComponentLessThan(void)
602 {
603   TestApplication application;
604   tet_infoline(" UtcDaliPropertyNotificationLessThan");
605
606   Actor actor = Actor::New();
607   Stage::GetCurrent().Add(actor);
608
609   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, LessThanCondition(-100.0f) );
610   notification.NotifySignal().Connect( &TestCallback );
611   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, LessThanCondition(-100.0f) );
612   notification.NotifySignal().Connect( &TestCallback );
613   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, LessThanCondition(-100.0f) );
614   notification.NotifySignal().Connect( &TestCallback );
615   notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, LessThanCondition(0.5f) );
616   notification.NotifySignal().Connect( &TestCallback );
617
618   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
619   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
620   Wait(application, DEFAULT_WAIT_PERIOD);
621
622   // Move left to satisfy XAxis condition
623   gCallBackCalled = false;
624   actor.SetPosition(Vector3(-200.0f, 0.0f, 0.0f));
625   Wait(application, DEFAULT_WAIT_PERIOD);
626   DALI_TEST_CHECK( gCallBackCalled );
627
628   // Move up to satisfy YAxis condition
629   gCallBackCalled = false;
630   actor.SetPosition(Vector3(-200.0f, -200.0f, 0.0f));
631   Wait(application, DEFAULT_WAIT_PERIOD);
632   DALI_TEST_CHECK( gCallBackCalled );
633
634   // Move back to satisfy ZAxis
635   gCallBackCalled = false;
636   Wait(application, DEFAULT_WAIT_PERIOD);
637   actor.SetPosition(Vector3(-200.0f, -200.0f, -200.0f));
638   Wait(application, DEFAULT_WAIT_PERIOD);
639   DALI_TEST_CHECK( gCallBackCalled );
640
641   // Change alpha Colour to satisfy w/alpha component condition
642   gCallBackCalled = false;
643   Wait(application, DEFAULT_WAIT_PERIOD);
644   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
645   Wait(application, DEFAULT_WAIT_PERIOD);
646   DALI_TEST_CHECK( gCallBackCalled );
647   END_TEST;
648 }
649
650 int UtcDaliPropertyNotificationVectorComponentInside(void)
651 {
652   TestApplication application;
653   tet_infoline(" UtcDaliPropertyNotificationInside");
654
655   Actor actor = Actor::New();
656   Stage::GetCurrent().Add(actor);
657
658   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, InsideCondition(-100.0f, 100.0f) );
659   notification.NotifySignal().Connect( &TestCallback );
660   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, InsideCondition(-100.0f, 100.0f) );
661   notification.NotifySignal().Connect( &TestCallback );
662   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, InsideCondition(-100.0f, 100.0f) );
663   notification.NotifySignal().Connect( &TestCallback );
664   notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, InsideCondition(0.25f, 0.75f) );
665   notification.NotifySignal().Connect( &TestCallback );
666
667   // set outside all conditions
668   actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
669   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
670   Wait(application, DEFAULT_WAIT_PERIOD);
671
672   // Move x to inside condition
673   gCallBackCalled = false;
674   actor.SetPosition(Vector3(0.0f, 200.0f, 200.0f));
675   Wait(application, DEFAULT_WAIT_PERIOD);
676   DALI_TEST_CHECK( gCallBackCalled );
677
678   // Move y to inside condition
679   gCallBackCalled = false;
680   actor.SetPosition(Vector3(0.0f, 0.0f, 200.0f));
681   Wait(application, DEFAULT_WAIT_PERIOD);
682   DALI_TEST_CHECK( gCallBackCalled );
683
684   // Move z to inside condition
685   gCallBackCalled = false;
686   Wait(application, DEFAULT_WAIT_PERIOD);
687   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
688   Wait(application, DEFAULT_WAIT_PERIOD);
689   DALI_TEST_CHECK( gCallBackCalled );
690
691   // change alpha to inside condition
692   gCallBackCalled = false;
693   Wait(application, DEFAULT_WAIT_PERIOD);
694   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.5f));
695   Wait(application, DEFAULT_WAIT_PERIOD);
696   DALI_TEST_CHECK( gCallBackCalled );
697   END_TEST;
698 }
699
700 int UtcDaliPropertyNotificationVectorComponentOutside(void)
701 {
702   TestApplication application;
703   tet_infoline(" UtcDaliPropertyNotificationOutside");
704
705   Actor actor = Actor::New();
706   Stage::GetCurrent().Add(actor);
707
708   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, OutsideCondition(-100.0f, 100.0f) );
709   notification.NotifySignal().Connect( &TestCallback );
710   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, OutsideCondition(-100.0f, 100.0f) );
711   notification.NotifySignal().Connect( &TestCallback );
712   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, OutsideCondition(-100.0f, 100.0f) );
713   notification.NotifySignal().Connect( &TestCallback );
714   notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, OutsideCondition(0.25f, 0.75f) );
715   notification.NotifySignal().Connect( &TestCallback );
716
717   // set inside all conditions
718   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
719   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.5f));
720   Wait(application, DEFAULT_WAIT_PERIOD);
721
722   // Move x to outside condition
723   gCallBackCalled = false;
724   actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
725   Wait(application, DEFAULT_WAIT_PERIOD);
726   DALI_TEST_CHECK( gCallBackCalled );
727
728   // Move y to outside condition
729   gCallBackCalled = false;
730   actor.SetPosition(Vector3(200.0f, 200.0f, 0.0f));
731   Wait(application, DEFAULT_WAIT_PERIOD);
732   DALI_TEST_CHECK( gCallBackCalled );
733
734   // Move z to outside condition
735   gCallBackCalled = false;
736   Wait(application, DEFAULT_WAIT_PERIOD);
737   actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
738   Wait(application, DEFAULT_WAIT_PERIOD);
739   DALI_TEST_CHECK( gCallBackCalled );
740
741   // change alpha to outside condition
742   gCallBackCalled = false;
743   Wait(application, DEFAULT_WAIT_PERIOD);
744   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
745   Wait(application, DEFAULT_WAIT_PERIOD);
746   DALI_TEST_CHECK( gCallBackCalled );
747   END_TEST;
748 }
749
750 int UtcDaliPropertyConditionGetArguments(void)
751 {
752   TestApplication application;
753   tet_infoline(" UtcDaliPropertyConditionGetArguments");
754
755   PropertyCondition condition = GreaterThanCondition( 50.0f );
756
757   DALI_TEST_EQUALS( condition.GetArgumentCount(), 1u, TEST_LOCATION );
758   float value = condition.GetArgument( 0 );
759   DALI_TEST_EQUALS( value, 50.0f, TEST_LOCATION );
760
761   condition = InsideCondition( 125.0f, 250.0f );
762
763   DALI_TEST_EQUALS( condition.GetArgumentCount(), 2u, TEST_LOCATION );
764   float value1 = condition.GetArgument( 0 );
765   float value2 = condition.GetArgument( 1 );
766   DALI_TEST_EQUALS( value1, 125.0f, TEST_LOCATION );
767   DALI_TEST_EQUALS( value2, 250.0f, TEST_LOCATION );
768   END_TEST;
769 }
770
771 int UtcDaliPropertyNotificationStep(void)
772 {
773   TestApplication application;
774   tet_infoline(" UtcDaliPropertyNotificationStep");
775
776   Actor actor = Actor::New();
777   Stage::GetCurrent().Add(actor);
778
779   const float step = 100.0f;
780   // float
781   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, StepCondition(step, 50.0f) );
782   notification.NotifySignal().Connect( &TestCallback );
783
784   // set initial position
785   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
786   Wait(application, DEFAULT_WAIT_PERIOD);
787
788   // test both directions
789   for( int i = 1 ; i < 10 ; ++i )
790   {
791     // Move x to negative position
792     gCallBackCalled = false;
793     actor.SetPosition(Vector3((i * step), 0.0f, 0.0f));
794     Wait(application, DEFAULT_WAIT_PERIOD);
795     DALI_TEST_CHECK( gCallBackCalled );
796   }
797
798   for( int i = 1 ; i < 10 ; ++i )
799   {
800     // Move x to negative position
801     gCallBackCalled = false;
802     actor.SetPosition(Vector3(-(i * step), 0.0f, 0.0f));
803     Wait(application, DEFAULT_WAIT_PERIOD);
804     DALI_TEST_CHECK( gCallBackCalled );
805   }
806   END_TEST;
807 }
808
809 int UtcDaliPropertyNotificationVariableStep(void)
810 {
811   TestApplication application;
812   tet_infoline(" UtcDaliPropertyNotificationStep");
813
814   Actor actor = Actor::New();
815   Stage::GetCurrent().Add(actor);
816
817   Dali::Vector<float> values;
818
819   const float averageStep = 100.0f;
820
821   for( int i = 1 ; i < 10 ; i++ )
822   {
823     values.PushBack(i * averageStep + (i % 2 == 0 ? -(averageStep * 0.2f) : (averageStep * 0.2f)));
824   }
825   // float
826   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, VariableStepCondition(values) );
827   notification.NotifySignal().Connect( &TestCallback );
828
829   // set initial position lower than first position in list
830   actor.SetPosition(Vector3(values[0] - averageStep, 0.0f, 0.0f));
831   Wait(application, DEFAULT_WAIT_PERIOD);
832
833   for( unsigned int i = 0 ; i < values.Count() - 1 ; ++i )
834   {
835     gCallBackCalled = false;
836     // set position half way between the current values
837     float position = values[i] + (0.5f * (values[i + 1] - values[i]));
838     actor.SetPosition(Vector3(position, 0.0f, 0.0f));
839     Wait(application, DEFAULT_WAIT_PERIOD);
840     DALI_TEST_CHECK( gCallBackCalled );
841   }
842   END_TEST;
843 }
844
845 static bool gCallBack2Called = false;
846 void TestCallback2(PropertyNotification& source)
847 {
848   gCallBack2Called = true;
849 }
850
851 int UtcDaliPropertyNotificationOrder(void)
852 {
853   TestApplication application; // Reset all test adapter return codes
854
855   Actor actor = Actor::New();
856   Stage::GetCurrent().Add(actor);
857   // this should complete in first frame
858   PropertyNotification notification1 = actor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(90.0f) );
859   notification1.NotifySignal().Connect( &TestCallback );
860   // this should complete in second frame
861   PropertyNotification notification2 = actor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(150.0f) );
862   notification2.NotifySignal().Connect( &TestCallback2 );
863   Animation animation = Animation::New( 0.032f ); // finishes in 32 ms
864   animation.AnimateTo( Property(actor, Actor::Property::POSITION ), Vector3( 200.0f, 0.0f, 0.0f ), AlphaFunction::LINEAR );
865   animation.Play();
866
867   // flush the queue
868   application.SendNotification();
869   // first frame
870   application.Render(RENDER_FRAME_INTERVAL);
871   // no notifications yet
872   DALI_TEST_EQUALS( gCallBackCalled, false, TEST_LOCATION );
873   DALI_TEST_EQUALS( gCallBack2Called, false, TEST_LOCATION );
874   gCallBackCalled = false;
875   gCallBack2Called = false;
876
877   // dont serve the notifications but run another update & render
878   // this simulates situation where there is a notification in event side but it's not been picked up by event thread
879   // second frame
880   application.Render(RENDER_FRAME_INTERVAL);
881   DALI_TEST_EQUALS( gCallBackCalled, false, TEST_LOCATION );
882   DALI_TEST_EQUALS( gCallBack2Called, false, TEST_LOCATION );
883
884   // serve the notifications
885   application.SendNotification();
886   DALI_TEST_EQUALS( gCallBackCalled, true, TEST_LOCATION );
887   DALI_TEST_EQUALS( gCallBack2Called, true, TEST_LOCATION );
888
889   gCallBackCalled = false;
890   gCallBack2Called = false;
891   application.Render(RENDER_FRAME_INTERVAL);
892   application.SendNotification();
893   DALI_TEST_EQUALS( gCallBackCalled, false, TEST_LOCATION );
894   DALI_TEST_EQUALS( gCallBack2Called, false, TEST_LOCATION );
895
896   END_TEST;
897 }