Merge "Remove pointless boost includes" into tizen
[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, "false && \"Property notification added to event side only property", TEST_LOCATION );
263   }
264   END_TEST;
265 }
266
267 int UtcDaliPropertyNotificationGetCondition(void)
268 {
269   TestApplication application;
270   tet_infoline(" UtcDaliPropertyNotificationGetCondition");
271
272   Actor actor = Actor::New();
273
274   PropertyCondition condition = GreaterThanCondition(100.0f);
275   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X, condition);
276   DALI_TEST_CHECK( condition == notification.GetCondition() );
277   END_TEST;
278 }
279
280 class PropertyNotificationConstWrapper
281 {
282 public:
283
284   PropertyNotificationConstWrapper(PropertyNotification propertyNotification)
285   :mPropertyNotification(propertyNotification)
286   {
287
288   }
289
290   /**
291    * Returns const reference to property notification.
292    * @return const reference.
293    */
294   const PropertyCondition& GetCondition() const
295   {
296     return mPropertyNotification.GetCondition();
297   }
298
299   PropertyNotification mPropertyNotification;
300 };
301
302 int UtcDaliPropertyNotificationGetConditionConst(void)
303 {
304   TestApplication application;
305   tet_infoline(" UtcDaliPropertyNotificationGetConditionConst");
306
307   Actor actor = Actor::New();
308
309   PropertyCondition condition = GreaterThanCondition(100.0f);
310   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X, condition);
311   PropertyNotificationConstWrapper notificationConst(notification);
312   const PropertyCondition& conditionReference1 = notificationConst.GetCondition();
313   const PropertyCondition& conditionReference2 = notificationConst.GetCondition();
314
315   DALI_TEST_CHECK( (&conditionReference1) == (&conditionReference2) );
316   DALI_TEST_CHECK( conditionReference1 == condition );
317   END_TEST;
318 }
319
320 int UtcDaliPropertyNotificationGetTarget(void)
321 {
322   TestApplication application;
323   tet_infoline(" UtcDaliPropertyNotificationGetTarget");
324
325   Actor actor = Actor::New();
326   Actor actor2 = Actor::New();
327
328   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
329                                                                     GreaterThanCondition(100.0f));
330   Actor targetActor = Actor::DownCast( notification.GetTarget() );
331
332   DALI_TEST_CHECK( targetActor == actor );
333   END_TEST;
334 }
335
336 int UtcDaliPropertyNotificationGetProperty(void)
337 {
338   TestApplication application;
339   tet_infoline(" UtcDaliPropertyNotificationGetProperty");
340
341   Actor actor = Actor::New();
342
343   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
344                                                                     GreaterThanCondition(100.0f));
345   Property::Index targetProperty = notification.GetTargetProperty();
346
347   DALI_TEST_EQUALS( targetProperty, Actor::Property::POSITION_X, TEST_LOCATION );
348   END_TEST;
349 }
350
351 int UtcDaliPropertyNotificationGetNotifyMode(void)
352 {
353   TestApplication application;
354   tet_infoline(" UtcDaliPropertyNotificationGetNotifyMode");
355
356   Actor actor = Actor::New();
357
358   PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
359                                                                     GreaterThanCondition(100.0f));
360   notification.SetNotifyMode(PropertyNotification::NotifyOnChanged);
361   PropertyNotification::NotifyMode notifyMode = notification.GetNotifyMode();
362
363   DALI_TEST_EQUALS( notifyMode, PropertyNotification::NotifyOnChanged, TEST_LOCATION );
364   END_TEST;
365 }
366
367 int UtcDaliPropertyNotificationGreaterThan(void)
368 {
369   TestApplication application;
370   tet_infoline(" UtcDaliPropertyNotificationGreaterThan");
371
372   Actor actor = Actor::New();
373   Stage::GetCurrent().Add(actor);
374
375   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(100.0f) );
376   notification.NotifySignal().Connect( &TestCallback );
377
378   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
379   Wait(application, DEFAULT_WAIT_PERIOD);
380
381   // Move right to satisfy condition
382   gCallBackCalled = false;
383   actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
384   Wait(application, DEFAULT_WAIT_PERIOD);
385   DALI_TEST_CHECK( gCallBackCalled );
386
387   // Move left to un-satisfy condition
388   gCallBackCalled = false;
389   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
390   Wait(application, DEFAULT_WAIT_PERIOD);
391   DALI_TEST_CHECK( !gCallBackCalled );
392
393   // Move right to satisfy condition again.
394   gCallBackCalled = false;
395   Wait(application, DEFAULT_WAIT_PERIOD);
396   actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
397   Wait(application, DEFAULT_WAIT_PERIOD);
398   DALI_TEST_CHECK( gCallBackCalled );
399   END_TEST;
400 }
401
402 int UtcDaliPropertyNotificationLessThan(void)
403 {
404   TestApplication application;
405   tet_infoline(" UtcDaliPropertyNotificationLessThan");
406
407   Actor actor = Actor::New();
408   Stage::GetCurrent().Add(actor);
409
410   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, LessThanCondition(100.0f ) );
411   notification.NotifySignal().Connect( &TestCallback );
412
413   actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
414   Wait(application, DEFAULT_WAIT_PERIOD);
415
416   // Move left to satisfy condition
417   gCallBackCalled = false;
418   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
419   Wait(application, DEFAULT_WAIT_PERIOD);
420   DALI_TEST_CHECK( gCallBackCalled );
421
422   // Move right to un-satisfy condition
423   gCallBackCalled = false;
424   actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
425   Wait(application, DEFAULT_WAIT_PERIOD);
426   DALI_TEST_CHECK( !gCallBackCalled );
427
428   // Move left to satisfy condition again.
429   gCallBackCalled = false;
430   Wait(application, DEFAULT_WAIT_PERIOD);
431   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
432   Wait(application, DEFAULT_WAIT_PERIOD);
433   DALI_TEST_CHECK( gCallBackCalled );
434   END_TEST;
435 }
436
437 int UtcDaliPropertyNotificationInside(void)
438 {
439   TestApplication application;
440   tet_infoline(" UtcDaliPropertyNotificationInside");
441
442   Actor actor = Actor::New();
443   Stage::GetCurrent().Add(actor);
444
445   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, InsideCondition(100.0f, 200.0f) );
446   notification.NotifySignal().Connect( &TestCallback );
447
448   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
449   Wait(application, DEFAULT_WAIT_PERIOD);
450
451   // Move inside to satisfy condition
452   gCallBackCalled = false;
453   actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
454   Wait(application, DEFAULT_WAIT_PERIOD);
455   DALI_TEST_CHECK( gCallBackCalled );
456
457   // Move outside (right) to un-satisfy condition
458   gCallBackCalled = false;
459   actor.SetPosition(Vector3(300.0f, 0.0f, 0.0f));
460   Wait(application, DEFAULT_WAIT_PERIOD);
461   DALI_TEST_CHECK( !gCallBackCalled );
462
463   // Move inside to satisfy condition again.
464   gCallBackCalled = false;
465   Wait(application, DEFAULT_WAIT_PERIOD);
466   actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
467   Wait(application, DEFAULT_WAIT_PERIOD);
468   DALI_TEST_CHECK( gCallBackCalled );
469   END_TEST;
470 }
471
472 int UtcDaliPropertyNotificationOutside(void)
473 {
474   TestApplication application;
475   tet_infoline(" UtcDaliPropertyNotificationOutside");
476
477   Actor actor = Actor::New();
478   Stage::GetCurrent().Add(actor);
479
480   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, OutsideCondition(100.0f, 200.0f) );
481   notification.NotifySignal().Connect( &TestCallback );
482
483   actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
484   Wait(application, DEFAULT_WAIT_PERIOD);
485
486   // Move outside (left) to satisfy condition
487   gCallBackCalled = false;
488   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
489   Wait(application, DEFAULT_WAIT_PERIOD);
490   DALI_TEST_CHECK( gCallBackCalled );
491
492   // Move inside to un-satisfy condition
493   gCallBackCalled = false;
494   actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
495   Wait(application, DEFAULT_WAIT_PERIOD);
496   DALI_TEST_CHECK( !gCallBackCalled );
497
498   // Move outside (right) to satisfy condition again.
499   gCallBackCalled = false;
500   Wait(application, DEFAULT_WAIT_PERIOD);
501   actor.SetPosition(Vector3(300.0f, 0.0f, 0.0f));
502   Wait(application, DEFAULT_WAIT_PERIOD);
503   DALI_TEST_CHECK( gCallBackCalled );
504   END_TEST;
505 }
506
507 int UtcDaliPropertyNotificationVectorComponentGreaterThan(void)
508 {
509   TestApplication application;
510   tet_infoline(" UtcDaliPropertyNotificationGreaterThan");
511
512   Actor actor = Actor::New();
513   Stage::GetCurrent().Add(actor);
514
515   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, GreaterThanCondition(100.0f) );
516   notification.NotifySignal().Connect( &TestCallback );
517   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, GreaterThanCondition(100.0f) );
518   notification.NotifySignal().Connect( &TestCallback );
519   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, GreaterThanCondition(100.0f) );
520   notification.NotifySignal().Connect( &TestCallback );
521   notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, GreaterThanCondition(0.5f) );
522   notification.NotifySignal().Connect( &TestCallback );
523
524   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
525   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
526   Wait(application, DEFAULT_WAIT_PERIOD);
527
528   // Move right to satisfy XAxis condition
529   gCallBackCalled = false;
530   actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
531   Wait(application, DEFAULT_WAIT_PERIOD);
532   DALI_TEST_CHECK( gCallBackCalled );
533
534   // Move down to satisfy YAxis condition
535   gCallBackCalled = false;
536   actor.SetPosition(Vector3(200.0f, 200.0f, 0.0f));
537   Wait(application, DEFAULT_WAIT_PERIOD);
538   DALI_TEST_CHECK( gCallBackCalled );
539
540   // Move forward to satisfy ZAxis
541   gCallBackCalled = false;
542   Wait(application, DEFAULT_WAIT_PERIOD);
543   actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
544   Wait(application, DEFAULT_WAIT_PERIOD);
545   DALI_TEST_CHECK( gCallBackCalled );
546
547   // Change alpha Colour to satisfy w/alpha component condition
548   gCallBackCalled = false;
549   Wait(application, DEFAULT_WAIT_PERIOD);
550   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
551   Wait(application, DEFAULT_WAIT_PERIOD);
552   DALI_TEST_CHECK( gCallBackCalled );
553   END_TEST;
554 }
555
556 int UtcDaliPropertyNotificationVectorComponentLessThan(void)
557 {
558   TestApplication application;
559   tet_infoline(" UtcDaliPropertyNotificationLessThan");
560
561   Actor actor = Actor::New();
562   Stage::GetCurrent().Add(actor);
563
564   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, LessThanCondition(-100.0f) );
565   notification.NotifySignal().Connect( &TestCallback );
566   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, LessThanCondition(-100.0f) );
567   notification.NotifySignal().Connect( &TestCallback );
568   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, LessThanCondition(-100.0f) );
569   notification.NotifySignal().Connect( &TestCallback );
570   notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, LessThanCondition(0.5f) );
571   notification.NotifySignal().Connect( &TestCallback );
572
573   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
574   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
575   Wait(application, DEFAULT_WAIT_PERIOD);
576
577   // Move left to satisfy XAxis condition
578   gCallBackCalled = false;
579   actor.SetPosition(Vector3(-200.0f, 0.0f, 0.0f));
580   Wait(application, DEFAULT_WAIT_PERIOD);
581   DALI_TEST_CHECK( gCallBackCalled );
582
583   // Move up to satisfy YAxis condition
584   gCallBackCalled = false;
585   actor.SetPosition(Vector3(-200.0f, -200.0f, 0.0f));
586   Wait(application, DEFAULT_WAIT_PERIOD);
587   DALI_TEST_CHECK( gCallBackCalled );
588
589   // Move back to satisfy ZAxis
590   gCallBackCalled = false;
591   Wait(application, DEFAULT_WAIT_PERIOD);
592   actor.SetPosition(Vector3(-200.0f, -200.0f, -200.0f));
593   Wait(application, DEFAULT_WAIT_PERIOD);
594   DALI_TEST_CHECK( gCallBackCalled );
595
596   // Change alpha Colour to satisfy w/alpha component condition
597   gCallBackCalled = false;
598   Wait(application, DEFAULT_WAIT_PERIOD);
599   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
600   Wait(application, DEFAULT_WAIT_PERIOD);
601   DALI_TEST_CHECK( gCallBackCalled );
602   END_TEST;
603 }
604
605 int UtcDaliPropertyNotificationVectorComponentInside(void)
606 {
607   TestApplication application;
608   tet_infoline(" UtcDaliPropertyNotificationInside");
609
610   Actor actor = Actor::New();
611   Stage::GetCurrent().Add(actor);
612
613   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, InsideCondition(-100.0f, 100.0f) );
614   notification.NotifySignal().Connect( &TestCallback );
615   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, InsideCondition(-100.0f, 100.0f) );
616   notification.NotifySignal().Connect( &TestCallback );
617   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, InsideCondition(-100.0f, 100.0f) );
618   notification.NotifySignal().Connect( &TestCallback );
619   notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, InsideCondition(0.25f, 0.75f) );
620   notification.NotifySignal().Connect( &TestCallback );
621
622   // set outside all conditions
623   actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
624   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
625   Wait(application, DEFAULT_WAIT_PERIOD);
626
627   // Move x to inside condition
628   gCallBackCalled = false;
629   actor.SetPosition(Vector3(0.0f, 200.0f, 200.0f));
630   Wait(application, DEFAULT_WAIT_PERIOD);
631   DALI_TEST_CHECK( gCallBackCalled );
632
633   // Move y to inside condition
634   gCallBackCalled = false;
635   actor.SetPosition(Vector3(0.0f, 0.0f, 200.0f));
636   Wait(application, DEFAULT_WAIT_PERIOD);
637   DALI_TEST_CHECK( gCallBackCalled );
638
639   // Move z to inside condition
640   gCallBackCalled = false;
641   Wait(application, DEFAULT_WAIT_PERIOD);
642   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
643   Wait(application, DEFAULT_WAIT_PERIOD);
644   DALI_TEST_CHECK( gCallBackCalled );
645
646   // change alpha to inside condition
647   gCallBackCalled = false;
648   Wait(application, DEFAULT_WAIT_PERIOD);
649   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.5f));
650   Wait(application, DEFAULT_WAIT_PERIOD);
651   DALI_TEST_CHECK( gCallBackCalled );
652   END_TEST;
653 }
654
655 int UtcDaliPropertyNotificationVectorComponentOutside(void)
656 {
657   TestApplication application;
658   tet_infoline(" UtcDaliPropertyNotificationOutside");
659
660   Actor actor = Actor::New();
661   Stage::GetCurrent().Add(actor);
662
663   PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, OutsideCondition(-100.0f, 100.0f) );
664   notification.NotifySignal().Connect( &TestCallback );
665   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, OutsideCondition(-100.0f, 100.0f) );
666   notification.NotifySignal().Connect( &TestCallback );
667   notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, OutsideCondition(-100.0f, 100.0f) );
668   notification.NotifySignal().Connect( &TestCallback );
669   notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, OutsideCondition(0.25f, 0.75f) );
670   notification.NotifySignal().Connect( &TestCallback );
671
672   // set inside all conditions
673   actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
674   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.5f));
675   Wait(application, DEFAULT_WAIT_PERIOD);
676
677   // Move x to outside condition
678   gCallBackCalled = false;
679   actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
680   Wait(application, DEFAULT_WAIT_PERIOD);
681   DALI_TEST_CHECK( gCallBackCalled );
682
683   // Move y to outside condition
684   gCallBackCalled = false;
685   actor.SetPosition(Vector3(200.0f, 200.0f, 0.0f));
686   Wait(application, DEFAULT_WAIT_PERIOD);
687   DALI_TEST_CHECK( gCallBackCalled );
688
689   // Move z to outside condition
690   gCallBackCalled = false;
691   Wait(application, DEFAULT_WAIT_PERIOD);
692   actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
693   Wait(application, DEFAULT_WAIT_PERIOD);
694   DALI_TEST_CHECK( gCallBackCalled );
695
696   // change alpha to outside condition
697   gCallBackCalled = false;
698   Wait(application, DEFAULT_WAIT_PERIOD);
699   actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
700   Wait(application, DEFAULT_WAIT_PERIOD);
701   DALI_TEST_CHECK( gCallBackCalled );
702   END_TEST;
703 }
704
705 int UtcDaliPropertyConditionGetArguments(void)
706 {
707   TestApplication application;
708   tet_infoline(" UtcDaliPropertyConditionGetArguments");
709
710   PropertyCondition condition = GreaterThanCondition( 50.0f );
711   PropertyCondition::ArgumentContainer arguments = condition.GetArguments();
712
713   DALI_TEST_EQUALS( arguments.size(), 1u, TEST_LOCATION );
714   Property::Value value = arguments[0];
715   DALI_TEST_EQUALS( value.Get<float>(), 50.0f, TEST_LOCATION );
716
717   condition = InsideCondition( 125.0f, 250.0f );
718   arguments = condition.GetArguments();
719
720   DALI_TEST_EQUALS( arguments.size(), 2u, TEST_LOCATION );
721   Property::Value value1 = arguments[0];
722   Property::Value value2 = arguments[1];
723   DALI_TEST_EQUALS( value1.Get<float>(), 125.0f, TEST_LOCATION );
724   DALI_TEST_EQUALS( value2.Get<float>(), 250.0f, TEST_LOCATION );
725   END_TEST;
726 }
727
728 namespace
729 {
730
731 class PropertyConditionConstWrapper
732 {
733 public:
734
735   PropertyConditionConstWrapper(PropertyCondition propertyCondition)
736   :mPropertyCondition(propertyCondition)
737   {
738
739   }
740
741   /**
742    * Returns const reference to property arguments.
743    * @return const reference.
744    */
745   const PropertyCondition::ArgumentContainer& GetArguments() const
746   {
747     return mPropertyCondition.GetArguments();
748   }
749
750   PropertyCondition mPropertyCondition;
751 };
752 } // anon namespace
753
754 int UtcDaliPropertyConditionGetArgumentsConst(void)
755 {
756   TestApplication application;
757   tet_infoline(" UtcDaliPropertyConditionGetArgumentsConst");
758
759   PropertyCondition condition = GreaterThanCondition( 50.0f );
760   PropertyConditionConstWrapper conditionConst(condition);
761   const PropertyCondition::ArgumentContainer& argumentsRef1 = conditionConst.GetArguments();
762   const PropertyCondition::ArgumentContainer& argumentsRef2 = conditionConst.GetArguments();
763
764   DALI_TEST_CHECK( (&argumentsRef1) == (&argumentsRef2) );
765   DALI_TEST_EQUALS( argumentsRef1.size(), 1u, TEST_LOCATION );
766   Property::Value value = argumentsRef1[0];
767   DALI_TEST_EQUALS( value.Get<float>(), 50.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   std::vector<float> values;
818
819   const float averageStep = 100.0f;
820
821   for( int i = 1 ; i < 10 ; i++ )
822   {
823     values.push_back(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.size() - 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 ), AlphaFunctions::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 }