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