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