Revert "[Tizen] Implement partial update"
[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   PropertyNotification notification2 = actor.AddPropertyNotification(Actor::Property::SIZE, StepCondition( 1.0f, 1.0f ));
172   DALI_TEST_CHECK( notification );
173   DALI_TEST_CHECK( notification2 );
174   END_TEST;
175 }
176
177 int UtcDaliAddPropertyNotificationCallback(void)
178 {
179   TestApplication application; // Reset all test adapter return codes
180
181   TestClass* object = new TestClass;
182
183   object->Initialize();
184   application.Render(RENDER_FRAME_INTERVAL);
185   application.SendNotification();
186
187   gCallBackCalled = false;
188
189   tet_infoline(" UtcDaliAddPropertyNotificationCallback - Forcing notification condition true, should receive a notification");
190   object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
191   application.Render(RENDER_FRAME_INTERVAL);
192   application.SendNotification();
193   application.Render(RENDER_FRAME_INTERVAL);
194   application.SendNotification();
195   DALI_TEST_CHECK( gCallBackCalled );
196   gCallBackCalled = false;
197
198   tet_infoline(" UtcDaliAddPropertyNotificationCallback - Forcing notification condition false, should not receive a notification");
199   object->mActor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
200   application.Render(RENDER_FRAME_INTERVAL);
201   application.SendNotification();
202   application.Render(RENDER_FRAME_INTERVAL);
203   application.SendNotification();
204   DALI_TEST_CHECK( !gCallBackCalled );
205   gCallBackCalled = false;
206
207   tet_infoline(" UtcDaliAddPropertyNotificationCallback - Deleting notification and it's owning object, should not receive a notification");
208   object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
209   application.Render(RENDER_FRAME_INTERVAL);
210   application.SendNotification();
211   object->Terminate();
212   application.Render(RENDER_FRAME_INTERVAL);
213   application.SendNotification();
214   DALI_TEST_CHECK( !gCallBackCalled );
215
216   tet_infoline(" UtcDaliAddPropertyNotificationCallback - Removing notification and it's owning object, should not receive a notification");
217   object->Initialize();
218   application.Render(RENDER_FRAME_INTERVAL);
219   application.SendNotification();
220   gCallBackCalled = false;
221
222   object->RemovePropertyNotification();
223
224   object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
225   application.Render(RENDER_FRAME_INTERVAL);
226   application.SendNotification();
227   application.Render(RENDER_FRAME_INTERVAL);
228   application.SendNotification();
229   DALI_TEST_CHECK( !gCallBackCalled );
230
231   tet_infoline(" UtcDaliAddPropertyNotificationCallback - Removing all notifications and it's owning object, should not receive a notification");
232   object->Initialize();
233   application.Render(RENDER_FRAME_INTERVAL);
234   application.SendNotification();
235   gCallBackCalled = false;
236
237   object->RemovePropertyNotifications();
238
239   object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
240   application.Render(RENDER_FRAME_INTERVAL);
241   application.SendNotification();
242   application.Render(RENDER_FRAME_INTERVAL);
243   application.SendNotification();
244   DALI_TEST_CHECK( !gCallBackCalled );
245
246
247   delete object;
248   END_TEST;
249 }
250
251 int UtcDaliAddPropertyNotificationTypeProperty(void)
252 {
253   TestApplication application;
254
255   Actor actor = Actor::New();
256
257   // Currently, Type registry properties cannot be animated
258   try
259   {
260     actor.AddPropertyNotification( PROPERTY_REGISTRATION_START_INDEX, GreaterThanCondition( 100.0f ) );
261   }
262   catch ( DaliException& e )
263   {
264     DALI_TEST_ASSERT( e, "Property notification added to event side only property", TEST_LOCATION );
265   }
266   END_TEST;
267 }
268
269 int UtcDaliAddPropertyNotificationEventSidePropertyN(void)
270 {
271   TestApplication application;
272
273   Actor actor = Actor::New();
274
275   // Currently, Type registry properties cannot be animated
276   try
277   {
278     actor.AddPropertyNotification( PROPERTY_REGISTRATION_MAX_INDEX - 1, GreaterThanCondition( 100.0f ) );
279   }
280   catch ( DaliException& e )
281   {
282     DALI_TEST_ASSERT( e, "Property notification added to event side only property", TEST_LOCATION );
283   }
284   END_TEST;
285 }
286
287 int UtcDaliAddPropertyNotificationSize(void)
288 {
289   TestApplication application;
290   tet_infoline(" UtcDaliAddPropertyNotificationSize");
291
292   Actor actor = Actor::New();
293
294   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::SIZE, StepCondition( 1.0f, 1.0f ));
295   DALI_TEST_CHECK( notification );
296   END_TEST;
297 }
298
299 int UtcDaliPropertyNotificationGetCondition(void)
300 {
301   TestApplication application;
302   tet_infoline(" UtcDaliPropertyNotificationGetCondition");
303
304   Actor actor = Actor::New();
305
306   PropertyCondition condition = GreaterThanCondition(100.0f);
307   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X, condition);
308   DALI_TEST_CHECK( condition == notification.GetCondition() );
309   END_TEST;
310 }
311
312 class PropertyNotificationConstWrapper
313 {
314 public:
315
316   PropertyNotificationConstWrapper(PropertyNotification propertyNotification)
317   :mPropertyNotification(propertyNotification)
318   {
319
320   }
321
322   /**
323    * Returns const reference to property notification.
324    * @return const reference.
325    */
326   const PropertyCondition& GetCondition() const
327   {
328     return mPropertyNotification.GetCondition();
329   }
330
331   PropertyNotification mPropertyNotification;
332 };
333
334 int UtcDaliPropertyNotificationGetConditionConst(void)
335 {
336   TestApplication application;
337   tet_infoline(" UtcDaliPropertyNotificationGetConditionConst");
338
339   Actor actor = Actor::New();
340
341   PropertyCondition condition = GreaterThanCondition(100.0f);
342   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X, condition);
343   PropertyNotificationConstWrapper notificationConst(notification);
344   const PropertyCondition& conditionReference1 = notificationConst.GetCondition();
345   const PropertyCondition& conditionReference2 = notificationConst.GetCondition();
346
347   DALI_TEST_CHECK( (&conditionReference1) == (&conditionReference2) );
348   DALI_TEST_CHECK( conditionReference1 == condition );
349   END_TEST;
350 }
351
352 int UtcDaliPropertyNotificationGetTarget(void)
353 {
354   TestApplication application;
355   tet_infoline(" UtcDaliPropertyNotificationGetTarget");
356
357   Actor actor = Actor::New();
358   Actor actor2 = Actor::New();
359
360   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
361                                                                     GreaterThanCondition(100.0f));
362   Actor targetActor = Actor::DownCast( notification.GetTarget() );
363
364   DALI_TEST_CHECK( targetActor == actor );
365   END_TEST;
366 }
367
368 int UtcDaliPropertyNotificationGetProperty(void)
369 {
370   TestApplication application;
371   tet_infoline(" UtcDaliPropertyNotificationGetProperty");
372
373   Actor actor = Actor::New();
374
375   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
376                                                                     GreaterThanCondition(100.0f));
377   Property::Index targetProperty = notification.GetTargetProperty();
378
379   DALI_TEST_EQUALS( targetProperty, (Property::Index)Actor::Property::POSITION_X, TEST_LOCATION );
380   END_TEST;
381 }
382
383 int UtcDaliPropertyNotificationGetNotifyMode(void)
384 {
385   TestApplication application;
386   tet_infoline(" UtcDaliPropertyNotificationGetNotifyMode");
387
388   Actor actor = Actor::New();
389
390   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
391                                                                     GreaterThanCondition(100.0f));
392   notification.SetNotifyMode(PropertyNotification::NotifyOnChanged);
393   PropertyNotification::NotifyMode notifyMode = notification.GetNotifyMode();
394
395   DALI_TEST_EQUALS( notifyMode, PropertyNotification::NotifyOnChanged, TEST_LOCATION );
396   END_TEST;
397 }
398
399 int UtcDaliPropertyNotificationGetNotifyResultP(void)
400 {
401   TestApplication application;
402   tet_infoline(" UtcDaliPropertyNotificationGetNotifyMode");
403
404   Actor actor = Actor::New();
405
406   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
407                                                                     GreaterThanCondition(100.0f));
408   notification.SetNotifyMode(PropertyNotification::NotifyOnChanged);
409   gCallBackCalled = false;
410   notification.NotifySignal().Connect( &TestCallback );
411
412   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
413
414   application.Render(RENDER_FRAME_INTERVAL);
415   application.SendNotification();
416   application.Render(RENDER_FRAME_INTERVAL);
417   application.SendNotification();
418
419   bool notifyResult = notification.GetNotifyResult();
420
421   DALI_TEST_EQUALS( notifyResult, false, TEST_LOCATION );
422
423   END_TEST;
424 }
425
426 int UtcDaliPropertyNotificationGreaterThan(void)
427 {
428   TestApplication application;
429   tet_infoline(" UtcDaliPropertyNotificationGreaterThan");
430
431   Actor actor = Actor::New();
432   Stage::GetCurrent().Add(actor);
433
434   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(100.0f) );
435   notification.NotifySignal().Connect( &TestCallback );
436
437   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
438   Wait(application, DEFAULT_WAIT_PERIOD);
439
440   // Move right to satisfy condition
441   gCallBackCalled = false;
442   actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
443   Wait(application, DEFAULT_WAIT_PERIOD);
444   DALI_TEST_CHECK( gCallBackCalled );
445
446   // Move left to un-satisfy condition
447   gCallBackCalled = false;
448   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
449   Wait(application, DEFAULT_WAIT_PERIOD);
450   DALI_TEST_CHECK( !gCallBackCalled );
451
452   // Move right to satisfy condition again.
453   gCallBackCalled = false;
454   Wait(application, DEFAULT_WAIT_PERIOD);
455   actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
456   Wait(application, DEFAULT_WAIT_PERIOD);
457   DALI_TEST_CHECK( gCallBackCalled );
458   END_TEST;
459 }
460
461 int UtcDaliPropertyNotificationLessThan(void)
462 {
463   TestApplication application;
464   tet_infoline(" UtcDaliPropertyNotificationLessThan");
465
466   Actor actor = Actor::New();
467   Stage::GetCurrent().Add(actor);
468
469   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, LessThanCondition(100.0f ) );
470   notification.NotifySignal().Connect( &TestCallback );
471
472   actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
473   Wait(application, DEFAULT_WAIT_PERIOD);
474
475   // Move left to satisfy condition
476   gCallBackCalled = false;
477   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
478   Wait(application, DEFAULT_WAIT_PERIOD);
479   DALI_TEST_CHECK( gCallBackCalled );
480
481   // Move right to un-satisfy condition
482   gCallBackCalled = false;
483   actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
484   Wait(application, DEFAULT_WAIT_PERIOD);
485   DALI_TEST_CHECK( !gCallBackCalled );
486
487   // Move left to satisfy condition again.
488   gCallBackCalled = false;
489   Wait(application, DEFAULT_WAIT_PERIOD);
490   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
491   Wait(application, DEFAULT_WAIT_PERIOD);
492   DALI_TEST_CHECK( gCallBackCalled );
493   END_TEST;
494 }
495
496 int UtcDaliPropertyNotificationInside(void)
497 {
498   TestApplication application;
499   tet_infoline(" UtcDaliPropertyNotificationInside");
500
501   Actor actor = Actor::New();
502   Stage::GetCurrent().Add(actor);
503
504   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, InsideCondition(100.0f, 200.0f) );
505   notification.NotifySignal().Connect( &TestCallback );
506
507   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
508   Wait(application, DEFAULT_WAIT_PERIOD);
509
510   // Move inside to satisfy condition
511   gCallBackCalled = false;
512   actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
513   Wait(application, DEFAULT_WAIT_PERIOD);
514   DALI_TEST_CHECK( gCallBackCalled );
515
516   // Move outside (right) to un-satisfy condition
517   gCallBackCalled = false;
518   actor.SetPosition(Vector3(300.0f, 0.0f, 0.0f));
519   Wait(application, DEFAULT_WAIT_PERIOD);
520   DALI_TEST_CHECK( !gCallBackCalled );
521
522   // Move inside to satisfy condition again.
523   gCallBackCalled = false;
524   Wait(application, DEFAULT_WAIT_PERIOD);
525   actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
526   Wait(application, DEFAULT_WAIT_PERIOD);
527   DALI_TEST_CHECK( gCallBackCalled );
528   END_TEST;
529 }
530
531 int UtcDaliPropertyNotificationOutside(void)
532 {
533   TestApplication application;
534   tet_infoline(" UtcDaliPropertyNotificationOutside");
535
536   Actor actor = Actor::New();
537   Stage::GetCurrent().Add(actor);
538
539   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, OutsideCondition(100.0f, 200.0f) );
540   notification.NotifySignal().Connect( &TestCallback );
541
542   actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
543   Wait(application, DEFAULT_WAIT_PERIOD);
544
545   // Move outside (left) to satisfy condition
546   gCallBackCalled = false;
547   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
548   Wait(application, DEFAULT_WAIT_PERIOD);
549   DALI_TEST_CHECK( gCallBackCalled );
550
551   // Move inside to un-satisfy condition
552   gCallBackCalled = false;
553   actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
554   Wait(application, DEFAULT_WAIT_PERIOD);
555   DALI_TEST_CHECK( !gCallBackCalled );
556
557   // Move outside (right) to satisfy condition again.
558   gCallBackCalled = false;
559   Wait(application, DEFAULT_WAIT_PERIOD);
560   actor.SetPosition(Vector3(300.0f, 0.0f, 0.0f));
561   Wait(application, DEFAULT_WAIT_PERIOD);
562   DALI_TEST_CHECK( gCallBackCalled );
563   END_TEST;
564 }
565
566 int UtcDaliPropertyNotificationVectorComponentGreaterThan(void)
567 {
568   TestApplication application;
569   tet_infoline(" UtcDaliPropertyNotificationGreaterThan");
570
571   Actor actor = Actor::New();
572   Stage::GetCurrent().Add(actor);
573
574   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, GreaterThanCondition(100.0f) );
575   notification.NotifySignal().Connect( &TestCallback );
576   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, GreaterThanCondition(100.0f) );
577   notification.NotifySignal().Connect( &TestCallback );
578   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, GreaterThanCondition(100.0f) );
579   notification.NotifySignal().Connect( &TestCallback );
580   notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, GreaterThanCondition(0.5f) );
581   notification.NotifySignal().Connect( &TestCallback );
582
583   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
584   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
585   Wait(application, DEFAULT_WAIT_PERIOD);
586
587   // Move right to satisfy XAxis condition
588   gCallBackCalled = false;
589   actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
590   Wait(application, DEFAULT_WAIT_PERIOD);
591   DALI_TEST_CHECK( gCallBackCalled );
592
593   // Move down to satisfy YAxis condition
594   gCallBackCalled = false;
595   actor.SetPosition(Vector3(200.0f, 200.0f, 0.0f));
596   Wait(application, DEFAULT_WAIT_PERIOD);
597   DALI_TEST_CHECK( gCallBackCalled );
598
599   // Move forward to satisfy ZAxis
600   gCallBackCalled = false;
601   Wait(application, DEFAULT_WAIT_PERIOD);
602   actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
603   Wait(application, DEFAULT_WAIT_PERIOD);
604   DALI_TEST_CHECK( gCallBackCalled );
605
606   // Change alpha Colour to satisfy w/alpha component condition
607   gCallBackCalled = false;
608   Wait(application, DEFAULT_WAIT_PERIOD);
609   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
610   Wait(application, DEFAULT_WAIT_PERIOD);
611   DALI_TEST_CHECK( gCallBackCalled );
612   END_TEST;
613 }
614
615 int UtcDaliPropertyNotificationVectorComponentLessThan(void)
616 {
617   TestApplication application;
618   tet_infoline(" UtcDaliPropertyNotificationLessThan");
619
620   Actor actor = Actor::New();
621   Stage::GetCurrent().Add(actor);
622
623   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, LessThanCondition(-100.0f) );
624   notification.NotifySignal().Connect( &TestCallback );
625   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, LessThanCondition(-100.0f) );
626   notification.NotifySignal().Connect( &TestCallback );
627   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, LessThanCondition(-100.0f) );
628   notification.NotifySignal().Connect( &TestCallback );
629   notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, LessThanCondition(0.5f) );
630   notification.NotifySignal().Connect( &TestCallback );
631
632   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
633   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
634   Wait(application, DEFAULT_WAIT_PERIOD);
635
636   // Move left to satisfy XAxis condition
637   gCallBackCalled = false;
638   actor.SetPosition(Vector3(-200.0f, 0.0f, 0.0f));
639   Wait(application, DEFAULT_WAIT_PERIOD);
640   DALI_TEST_CHECK( gCallBackCalled );
641
642   // Move up to satisfy YAxis condition
643   gCallBackCalled = false;
644   actor.SetPosition(Vector3(-200.0f, -200.0f, 0.0f));
645   Wait(application, DEFAULT_WAIT_PERIOD);
646   DALI_TEST_CHECK( gCallBackCalled );
647
648   // Move back to satisfy ZAxis
649   gCallBackCalled = false;
650   Wait(application, DEFAULT_WAIT_PERIOD);
651   actor.SetPosition(Vector3(-200.0f, -200.0f, -200.0f));
652   Wait(application, DEFAULT_WAIT_PERIOD);
653   DALI_TEST_CHECK( gCallBackCalled );
654
655   // Change alpha Colour to satisfy w/alpha component condition
656   gCallBackCalled = false;
657   Wait(application, DEFAULT_WAIT_PERIOD);
658   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
659   Wait(application, DEFAULT_WAIT_PERIOD);
660   DALI_TEST_CHECK( gCallBackCalled );
661   END_TEST;
662 }
663
664 int UtcDaliPropertyNotificationVectorComponentInside(void)
665 {
666   TestApplication application;
667   tet_infoline(" UtcDaliPropertyNotificationInside");
668
669   Actor actor = Actor::New();
670   Stage::GetCurrent().Add(actor);
671
672   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, InsideCondition(-100.0f, 100.0f) );
673   notification.NotifySignal().Connect( &TestCallback );
674   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, InsideCondition(-100.0f, 100.0f) );
675   notification.NotifySignal().Connect( &TestCallback );
676   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, InsideCondition(-100.0f, 100.0f) );
677   notification.NotifySignal().Connect( &TestCallback );
678   notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, InsideCondition(0.25f, 0.75f) );
679   notification.NotifySignal().Connect( &TestCallback );
680
681   // set outside all conditions
682   actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
683   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
684   Wait(application, DEFAULT_WAIT_PERIOD);
685
686   // Move x to inside condition
687   gCallBackCalled = false;
688   actor.SetPosition(Vector3(0.0f, 200.0f, 200.0f));
689   Wait(application, DEFAULT_WAIT_PERIOD);
690   DALI_TEST_CHECK( gCallBackCalled );
691
692   // Move y to inside condition
693   gCallBackCalled = false;
694   actor.SetPosition(Vector3(0.0f, 0.0f, 200.0f));
695   Wait(application, DEFAULT_WAIT_PERIOD);
696   DALI_TEST_CHECK( gCallBackCalled );
697
698   // Move z to inside condition
699   gCallBackCalled = false;
700   Wait(application, DEFAULT_WAIT_PERIOD);
701   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
702   Wait(application, DEFAULT_WAIT_PERIOD);
703   DALI_TEST_CHECK( gCallBackCalled );
704
705   // change alpha to inside condition
706   gCallBackCalled = false;
707   Wait(application, DEFAULT_WAIT_PERIOD);
708   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.5f));
709   Wait(application, DEFAULT_WAIT_PERIOD);
710   DALI_TEST_CHECK( gCallBackCalled );
711   END_TEST;
712 }
713
714 int UtcDaliPropertyNotificationVectorComponentOutside(void)
715 {
716   TestApplication application;
717   tet_infoline(" UtcDaliPropertyNotificationOutside");
718
719   Actor actor = Actor::New();
720   Stage::GetCurrent().Add(actor);
721
722   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, OutsideCondition(-100.0f, 100.0f) );
723   notification.NotifySignal().Connect( &TestCallback );
724   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, OutsideCondition(-100.0f, 100.0f) );
725   notification.NotifySignal().Connect( &TestCallback );
726   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, OutsideCondition(-100.0f, 100.0f) );
727   notification.NotifySignal().Connect( &TestCallback );
728   notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, OutsideCondition(0.25f, 0.75f) );
729   notification.NotifySignal().Connect( &TestCallback );
730
731   // set inside all conditions
732   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
733   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.5f));
734   Wait(application, DEFAULT_WAIT_PERIOD);
735
736   // Move x to outside condition
737   gCallBackCalled = false;
738   actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
739   Wait(application, DEFAULT_WAIT_PERIOD);
740   DALI_TEST_CHECK( gCallBackCalled );
741
742   // Move y to outside condition
743   gCallBackCalled = false;
744   actor.SetPosition(Vector3(200.0f, 200.0f, 0.0f));
745   Wait(application, DEFAULT_WAIT_PERIOD);
746   DALI_TEST_CHECK( gCallBackCalled );
747
748   // Move z to outside condition
749   gCallBackCalled = false;
750   Wait(application, DEFAULT_WAIT_PERIOD);
751   actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
752   Wait(application, DEFAULT_WAIT_PERIOD);
753   DALI_TEST_CHECK( gCallBackCalled );
754
755   // change alpha to outside condition
756   gCallBackCalled = false;
757   Wait(application, DEFAULT_WAIT_PERIOD);
758   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
759   Wait(application, DEFAULT_WAIT_PERIOD);
760   DALI_TEST_CHECK( gCallBackCalled );
761   END_TEST;
762 }
763
764 int UtcDaliPropertyNotificationSetSizeResultP(void)
765 {
766   TestApplication application;
767   bool notifyResult;
768   tet_infoline(" UtcDaliPropertyNotificationSetSizeResultP");
769
770   Actor actor = Actor::New();
771
772   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::SIZE, StepCondition( 1.0f, 1.0f ) );
773   notification.SetNotifyMode(PropertyNotification::NotifyOnChanged);
774   gCallBackCalled = false;
775   notification.NotifySignal().Connect( &TestCallback );
776
777   actor.SetSize(100.0f, 100.0f);
778
779   application.Render(RENDER_FRAME_INTERVAL);
780   application.SendNotification();
781   application.Render(RENDER_FRAME_INTERVAL);
782   application.SendNotification();
783
784   notifyResult = notification.GetNotifyResult();
785
786   DALI_TEST_EQUALS( notifyResult, true, TEST_LOCATION );
787
788   gCallBackCalled = false;
789
790   actor.SetSize(200.0f, 200.0f);
791
792   application.Render(RENDER_FRAME_INTERVAL);
793   application.SendNotification();
794   application.Render(RENDER_FRAME_INTERVAL);
795   application.SendNotification();
796
797   notifyResult = notification.GetNotifyResult();
798
799   DALI_TEST_EQUALS( notifyResult, true, TEST_LOCATION );
800
801   END_TEST;
802 }
803
804 int UtcDaliPropertyConditionGetArguments(void)
805 {
806   TestApplication application;
807   tet_infoline(" UtcDaliPropertyConditionGetArguments");
808
809   PropertyCondition condition = GreaterThanCondition( 50.0f );
810
811   DALI_TEST_EQUALS( condition.GetArgumentCount(), 1u, TEST_LOCATION );
812   float value = condition.GetArgument( 0 );
813   DALI_TEST_EQUALS( value, 50.0f, TEST_LOCATION );
814
815   condition = InsideCondition( 125.0f, 250.0f );
816
817   DALI_TEST_EQUALS( condition.GetArgumentCount(), 2u, TEST_LOCATION );
818   float value1 = condition.GetArgument( 0 );
819   float value2 = condition.GetArgument( 1 );
820   DALI_TEST_EQUALS( value1, 125.0f, TEST_LOCATION );
821   DALI_TEST_EQUALS( value2, 250.0f, TEST_LOCATION );
822   END_TEST;
823 }
824
825 int UtcDaliPropertyNotificationStep(void)
826 {
827   TestApplication application;
828   tet_infoline(" UtcDaliPropertyNotificationStep");
829
830   Actor actor = Actor::New();
831   Stage::GetCurrent().Add(actor);
832
833   const float step = 100.0f;
834   // float
835   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, StepCondition(step, 50.0f) );
836   notification.NotifySignal().Connect( &TestCallback );
837
838   // set initial position
839   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
840   Wait(application, DEFAULT_WAIT_PERIOD);
841
842   // test both directions
843   for( int i = 1 ; i < 10 ; ++i )
844   {
845     // Move x to negative position
846     gCallBackCalled = false;
847     actor.SetPosition(Vector3((i * step), 0.0f, 0.0f));
848     Wait(application, DEFAULT_WAIT_PERIOD);
849     DALI_TEST_CHECK( gCallBackCalled );
850   }
851
852   for( int i = 1 ; i < 10 ; ++i )
853   {
854     // Move x to negative position
855     gCallBackCalled = false;
856     actor.SetPosition(Vector3(-(i * step), 0.0f, 0.0f));
857     Wait(application, DEFAULT_WAIT_PERIOD);
858     DALI_TEST_CHECK( gCallBackCalled );
859   }
860   END_TEST;
861 }
862
863 int UtcDaliPropertyNotificationVariableStep(void)
864 {
865   TestApplication application;
866   tet_infoline(" UtcDaliPropertyNotificationStep");
867
868   Actor actor = Actor::New();
869   Stage::GetCurrent().Add(actor);
870
871   Dali::Vector<float> values;
872
873   const float averageStep = 100.0f;
874
875   for( int i = 1 ; i < 10 ; i++ )
876   {
877     values.PushBack(i * averageStep + (i % 2 == 0 ? -(averageStep * 0.2f) : (averageStep * 0.2f)));
878   }
879   // float
880   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, VariableStepCondition(values) );
881   notification.NotifySignal().Connect( &TestCallback );
882
883   // set initial position lower than first position in list
884   actor.SetPosition(Vector3(values[0] - averageStep, 0.0f, 0.0f));
885   Wait(application, DEFAULT_WAIT_PERIOD);
886
887   for( unsigned int i = 0 ; i < values.Count() - 1 ; ++i )
888   {
889     gCallBackCalled = false;
890     // set position half way between the current values
891     float position = values[i] + (0.5f * (values[i + 1] - values[i]));
892     actor.SetPosition(Vector3(position, 0.0f, 0.0f));
893     Wait(application, DEFAULT_WAIT_PERIOD);
894     DALI_TEST_CHECK( gCallBackCalled );
895   }
896   END_TEST;
897 }
898
899 static bool gCallBack2Called = false;
900 void TestCallback2(PropertyNotification& source)
901 {
902   gCallBack2Called = true;
903 }
904
905 int UtcDaliPropertyNotificationOrder(void)
906 {
907   TestApplication application; // Reset all test adapter return codes
908
909   Actor actor = Actor::New();
910   Stage::GetCurrent().Add(actor);
911   // this should complete in first frame
912   PropertyNotification notification1 = actor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(90.0f) );
913   notification1.NotifySignal().Connect( &TestCallback );
914   // this should complete in second frame
915   PropertyNotification notification2 = actor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(150.0f) );
916   notification2.NotifySignal().Connect( &TestCallback2 );
917   Animation animation = Animation::New( 0.032f ); // finishes in 32 ms
918   animation.AnimateTo( Property(actor, Actor::Property::POSITION ), Vector3( 200.0f, 0.0f, 0.0f ), AlphaFunction::LINEAR );
919   animation.Play();
920
921   // flush the queue
922   application.SendNotification();
923   // first frame
924   application.Render(RENDER_FRAME_INTERVAL);
925   // no notifications yet
926   DALI_TEST_EQUALS( gCallBackCalled, false, TEST_LOCATION );
927   DALI_TEST_EQUALS( gCallBack2Called, false, TEST_LOCATION );
928   gCallBackCalled = false;
929   gCallBack2Called = false;
930
931   // dont serve the notifications but run another update & render
932   // this simulates situation where there is a notification in event side but it's not been picked up by event thread
933   // second frame
934   application.Render(RENDER_FRAME_INTERVAL);
935   DALI_TEST_EQUALS( gCallBackCalled, false, TEST_LOCATION );
936   DALI_TEST_EQUALS( gCallBack2Called, false, TEST_LOCATION );
937
938   // serve the notifications
939   application.SendNotification();
940   DALI_TEST_EQUALS( gCallBackCalled, true, TEST_LOCATION );
941   DALI_TEST_EQUALS( gCallBack2Called, true, TEST_LOCATION );
942
943   gCallBackCalled = false;
944   gCallBack2Called = false;
945   application.Render(RENDER_FRAME_INTERVAL);
946   application.SendNotification();
947   DALI_TEST_EQUALS( gCallBackCalled, false, TEST_LOCATION );
948   DALI_TEST_EQUALS( gCallBack2Called, false, TEST_LOCATION );
949
950   END_TEST;
951 }