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