2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <boost/bind.hpp>
22 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
27 void utc_dali_property_notification_startup(void)
29 test_return_value = TET_UNDEF;
32 void utc_dali_property_notification_cleanup(void)
34 test_return_value = TET_PASS;
39 static bool gCallBackCalled;
41 static void TestCallback(PropertyNotification& source)
43 gCallBackCalled = true;
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.
50 class TestClass : public ConnectionTracker
64 mActor = Actor::New();
65 Stage::GetCurrent().Add( mActor );
66 mNotification = mActor.AddPropertyNotification( Actor::POSITION_X, GreaterThanCondition(100.0f) );
67 mNotification.NotifySignal().Connect( this, &TestClass::OnPropertyNotify );
70 void RemovePropertyNotification()
72 mActor.RemovePropertyNotification( mNotification );
75 void RemovePropertyNotifications()
77 mActor.RemovePropertyNotifications();
82 Stage::GetCurrent().Remove( mActor );
84 mNotification.Reset();
87 void OnPropertyNotify( PropertyNotification& source )
89 tet_infoline(" OnPropertyNotify");
90 gCallBackCalled = true;
94 PropertyNotification mNotification;
99 * Simulate time passed by.
101 * @note this will always process at least 1 frame (1/60 sec)
103 * @param application Test application instance
104 * @param duration Time to pass in milliseconds.
105 * @return The actual time passed in milliseconds
107 int Wait(TestApplication& application, int duration = 0)
111 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
113 application.SendNotification();
114 application.Render(RENDER_FRAME_INTERVAL);
115 time += RENDER_FRAME_INTERVAL;
121 } // unnamed namespace
124 // Positive test case for a method
125 int UtcDaliPropertyNotificationDownCast(void)
127 TestApplication application;
128 tet_infoline(" UtcDaliPropertyNotificationDownCast");
130 Actor actor = Actor::New();
131 PropertyNotification notification = actor.AddPropertyNotification(Actor::POSITION_X, GreaterThanCondition(100.0f));
132 BaseHandle handle = notification;
133 PropertyNotification notificationHandle;
135 DALI_TEST_CHECK(notification);
136 DALI_TEST_CHECK(handle);
137 DALI_TEST_CHECK(!notificationHandle);
139 notificationHandle = PropertyNotification::DownCast( handle );
140 DALI_TEST_CHECK(notificationHandle);
145 // Negative test case for a method
146 int UtcDaliPropertyNotificationDownCastNegative(void)
148 TestApplication application;
149 tet_infoline(" UtcDaliPropertyNotificationDownCastNegative");
151 // Create something derived from BaseHandle other than a PropertyNotification.
152 Actor somethingElse = Actor::New();
154 Actor actor = Actor::New();
155 actor.AddPropertyNotification(Actor::POSITION_X, GreaterThanCondition(100.0f));
156 BaseHandle handle = somethingElse;
157 PropertyNotification notificationHandle;
159 notificationHandle = PropertyNotification::DownCast( handle );
160 DALI_TEST_CHECK(!notificationHandle);
164 int UtcDaliAddPropertyNotification(void)
166 TestApplication application; // Reset all test adapter return codes
167 tet_infoline(" UtcDaliAddPropertyNotification");
169 Actor actor = Actor::New();
171 PropertyNotification notification = actor.AddPropertyNotification(Actor::POSITION_X, GreaterThanCondition(100.0f));
172 DALI_TEST_CHECK( notification );
176 int UtcDaliAddPropertyNotificationCallback(void)
178 TestApplication application; // Reset all test adapter return codes
180 TestClass* object = new TestClass;
182 object->Initialize();
183 application.Render(RENDER_FRAME_INTERVAL);
184 application.SendNotification();
186 gCallBackCalled = false;
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;
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;
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();
211 application.Render(RENDER_FRAME_INTERVAL);
212 application.SendNotification();
213 DALI_TEST_CHECK( !gCallBackCalled );
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;
221 object->RemovePropertyNotification();
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 );
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;
236 object->RemovePropertyNotifications();
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 );
250 int UtcDaliAddPropertyNotificationTypeProperty(void)
252 TestApplication application;
254 Actor actor = Actor::New();
256 // Currently, Type registry properties cannot be animated
259 actor.AddPropertyNotification( PROPERTY_REGISTRATION_START_INDEX, GreaterThanCondition( 100.0f ) );
261 catch ( DaliException& e )
263 DALI_TEST_ASSERT( e, "false && \"Property notification added to event side only property", TEST_LOCATION );
268 int UtcDaliPropertyNotificationGetCondition(void)
270 TestApplication application;
271 tet_infoline(" UtcDaliPropertyNotificationGetCondition");
273 Actor actor = Actor::New();
275 PropertyCondition condition = GreaterThanCondition(100.0f);
276 PropertyNotification notification = actor.AddPropertyNotification(Actor::POSITION_X, condition);
277 DALI_TEST_CHECK( condition == notification.GetCondition() );
281 class PropertyNotificationConstWrapper
285 PropertyNotificationConstWrapper(PropertyNotification propertyNotification)
286 :mPropertyNotification(propertyNotification)
292 * Returns const reference to property notification.
293 * @return const reference.
295 const PropertyCondition& GetCondition() const
297 return mPropertyNotification.GetCondition();
300 PropertyNotification mPropertyNotification;
303 int UtcDaliPropertyNotificationGetConditionConst(void)
305 TestApplication application;
306 tet_infoline(" UtcDaliPropertyNotificationGetConditionConst");
308 Actor actor = Actor::New();
310 PropertyCondition condition = GreaterThanCondition(100.0f);
311 PropertyNotification notification = actor.AddPropertyNotification(Actor::POSITION_X, condition);
312 PropertyNotificationConstWrapper notificationConst(notification);
313 const PropertyCondition& conditionReference1 = notificationConst.GetCondition();
314 const PropertyCondition& conditionReference2 = notificationConst.GetCondition();
316 DALI_TEST_CHECK( (&conditionReference1) == (&conditionReference2) );
317 DALI_TEST_CHECK( conditionReference1 == condition );
321 int UtcDaliPropertyNotificationGetTarget(void)
323 TestApplication application;
324 tet_infoline(" UtcDaliPropertyNotificationGetTarget");
326 Actor actor = Actor::New();
327 Actor actor2 = Actor::New();
329 PropertyNotification notification = actor.AddPropertyNotification(Actor::POSITION_X,
330 GreaterThanCondition(100.0f));
331 Actor targetActor = Actor::DownCast( notification.GetTarget() );
333 DALI_TEST_CHECK( targetActor == actor );
337 int UtcDaliPropertyNotificationGetProperty(void)
339 TestApplication application;
340 tet_infoline(" UtcDaliPropertyNotificationGetProperty");
342 Actor actor = Actor::New();
344 PropertyNotification notification = actor.AddPropertyNotification(Actor::POSITION_X,
345 GreaterThanCondition(100.0f));
346 Property::Index targetProperty = notification.GetTargetProperty();
348 DALI_TEST_EQUALS( targetProperty, Actor::POSITION_X, TEST_LOCATION );
352 int UtcDaliPropertyNotificationGetNotifyMode(void)
354 TestApplication application;
355 tet_infoline(" UtcDaliPropertyNotificationGetNotifyMode");
357 Actor actor = Actor::New();
359 PropertyNotification notification = actor.AddPropertyNotification(Actor::POSITION_X,
360 GreaterThanCondition(100.0f));
361 notification.SetNotifyMode(PropertyNotification::NotifyOnChanged);
362 PropertyNotification::NotifyMode notifyMode = notification.GetNotifyMode();
364 DALI_TEST_EQUALS( notifyMode, PropertyNotification::NotifyOnChanged, TEST_LOCATION );
368 int UtcDaliPropertyNotificationGreaterThan(void)
370 TestApplication application;
371 tet_infoline(" UtcDaliPropertyNotificationGreaterThan");
373 Actor actor = Actor::New();
374 Stage::GetCurrent().Add(actor);
376 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION_X, GreaterThanCondition(100.0f) );
377 notification.NotifySignal().Connect( &TestCallback );
379 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
380 Wait(application, DEFAULT_WAIT_PERIOD);
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 );
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 );
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 );
403 int UtcDaliPropertyNotificationLessThan(void)
405 TestApplication application;
406 tet_infoline(" UtcDaliPropertyNotificationLessThan");
408 Actor actor = Actor::New();
409 Stage::GetCurrent().Add(actor);
411 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION_X, LessThanCondition(100.0f ) );
412 notification.NotifySignal().Connect( &TestCallback );
414 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
415 Wait(application, DEFAULT_WAIT_PERIOD);
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 );
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 );
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 );
438 int UtcDaliPropertyNotificationInside(void)
440 TestApplication application;
441 tet_infoline(" UtcDaliPropertyNotificationInside");
443 Actor actor = Actor::New();
444 Stage::GetCurrent().Add(actor);
446 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION_X, InsideCondition(100.0f, 200.0f) );
447 notification.NotifySignal().Connect( &TestCallback );
449 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
450 Wait(application, DEFAULT_WAIT_PERIOD);
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 );
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 );
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 );
473 int UtcDaliPropertyNotificationOutside(void)
475 TestApplication application;
476 tet_infoline(" UtcDaliPropertyNotificationOutside");
478 Actor actor = Actor::New();
479 Stage::GetCurrent().Add(actor);
481 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION_X, OutsideCondition(100.0f, 200.0f) );
482 notification.NotifySignal().Connect( &TestCallback );
484 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
485 Wait(application, DEFAULT_WAIT_PERIOD);
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 );
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 );
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 );
508 int UtcDaliPropertyNotificationVectorComponentGreaterThan(void)
510 TestApplication application;
511 tet_infoline(" UtcDaliPropertyNotificationGreaterThan");
513 Actor actor = Actor::New();
514 Stage::GetCurrent().Add(actor);
516 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION, 0, GreaterThanCondition(100.0f) );
517 notification.NotifySignal().Connect( &TestCallback );
518 notification = actor.AddPropertyNotification( Actor::POSITION, 1, GreaterThanCondition(100.0f) );
519 notification.NotifySignal().Connect( &TestCallback );
520 notification = actor.AddPropertyNotification( Actor::POSITION, 2, GreaterThanCondition(100.0f) );
521 notification.NotifySignal().Connect( &TestCallback );
522 notification = actor.AddPropertyNotification( Actor::COLOR, 3, GreaterThanCondition(0.5f) );
523 notification.NotifySignal().Connect( &TestCallback );
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);
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 );
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 );
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 );
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 );
557 int UtcDaliPropertyNotificationVectorComponentLessThan(void)
559 TestApplication application;
560 tet_infoline(" UtcDaliPropertyNotificationLessThan");
562 Actor actor = Actor::New();
563 Stage::GetCurrent().Add(actor);
565 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION, 0, LessThanCondition(-100.0f) );
566 notification.NotifySignal().Connect( &TestCallback );
567 notification = actor.AddPropertyNotification( Actor::POSITION, 1, LessThanCondition(-100.0f) );
568 notification.NotifySignal().Connect( &TestCallback );
569 notification = actor.AddPropertyNotification( Actor::POSITION, 2, LessThanCondition(-100.0f) );
570 notification.NotifySignal().Connect( &TestCallback );
571 notification = actor.AddPropertyNotification( Actor::COLOR, 3, LessThanCondition(0.5f) );
572 notification.NotifySignal().Connect( &TestCallback );
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);
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 );
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 );
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 );
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 );
606 int UtcDaliPropertyNotificationVectorComponentInside(void)
608 TestApplication application;
609 tet_infoline(" UtcDaliPropertyNotificationInside");
611 Actor actor = Actor::New();
612 Stage::GetCurrent().Add(actor);
614 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION, 0, InsideCondition(-100.0f, 100.0f) );
615 notification.NotifySignal().Connect( &TestCallback );
616 notification = actor.AddPropertyNotification( Actor::POSITION, 1, InsideCondition(-100.0f, 100.0f) );
617 notification.NotifySignal().Connect( &TestCallback );
618 notification = actor.AddPropertyNotification( Actor::POSITION, 2, InsideCondition(-100.0f, 100.0f) );
619 notification.NotifySignal().Connect( &TestCallback );
620 notification = actor.AddPropertyNotification( Actor::COLOR, 3, InsideCondition(0.25f, 0.75f) );
621 notification.NotifySignal().Connect( &TestCallback );
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);
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 );
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 );
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 );
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 );
656 int UtcDaliPropertyNotificationVectorComponentOutside(void)
658 TestApplication application;
659 tet_infoline(" UtcDaliPropertyNotificationOutside");
661 Actor actor = Actor::New();
662 Stage::GetCurrent().Add(actor);
664 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION, 0, OutsideCondition(-100.0f, 100.0f) );
665 notification.NotifySignal().Connect( &TestCallback );
666 notification = actor.AddPropertyNotification( Actor::POSITION, 1, OutsideCondition(-100.0f, 100.0f) );
667 notification.NotifySignal().Connect( &TestCallback );
668 notification = actor.AddPropertyNotification( Actor::POSITION, 2, OutsideCondition(-100.0f, 100.0f) );
669 notification.NotifySignal().Connect( &TestCallback );
670 notification = actor.AddPropertyNotification( Actor::COLOR, 3, OutsideCondition(0.25f, 0.75f) );
671 notification.NotifySignal().Connect( &TestCallback );
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);
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 );
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 );
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 );
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 );
706 int UtcDaliPropertyConditionGetArguments(void)
708 TestApplication application;
709 tet_infoline(" UtcDaliPropertyConditionGetArguments");
711 PropertyCondition condition = GreaterThanCondition( 50.0f );
712 PropertyCondition::ArgumentContainer arguments = condition.GetArguments();
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 );
718 condition = InsideCondition( 125.0f, 250.0f );
719 arguments = condition.GetArguments();
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 );
732 class PropertyConditionConstWrapper
736 PropertyConditionConstWrapper(PropertyCondition propertyCondition)
737 :mPropertyCondition(propertyCondition)
743 * Returns const reference to property arguments.
744 * @return const reference.
746 const PropertyCondition::ArgumentContainer& GetArguments() const
748 return mPropertyCondition.GetArguments();
751 PropertyCondition mPropertyCondition;
755 int UtcDaliPropertyConditionGetArgumentsConst(void)
757 TestApplication application;
758 tet_infoline(" UtcDaliPropertyConditionGetArgumentsConst");
760 PropertyCondition condition = GreaterThanCondition( 50.0f );
761 PropertyConditionConstWrapper conditionConst(condition);
762 const PropertyCondition::ArgumentContainer& argumentsRef1 = conditionConst.GetArguments();
763 const PropertyCondition::ArgumentContainer& argumentsRef2 = conditionConst.GetArguments();
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 );
772 int UtcDaliPropertyNotificationStep(void)
774 TestApplication application;
775 tet_infoline(" UtcDaliPropertyNotificationStep");
777 Actor actor = Actor::New();
778 Stage::GetCurrent().Add(actor);
780 const float step = 100.0f;
782 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION, 0, StepCondition(step, 50.0f) );
783 notification.NotifySignal().Connect( &TestCallback );
785 // set initial position
786 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
787 Wait(application, DEFAULT_WAIT_PERIOD);
789 // test both directions
790 for( int i = 1 ; i < 10 ; ++i )
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 );
799 for( int i = 1 ; i < 10 ; ++i )
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 );
810 int UtcDaliPropertyNotificationVariableStep(void)
812 TestApplication application;
813 tet_infoline(" UtcDaliPropertyNotificationStep");
815 Actor actor = Actor::New();
816 Stage::GetCurrent().Add(actor);
818 std::vector<float> values;
820 const float averageStep = 100.0f;
822 for( int i = 1 ; i < 10 ; i++ )
824 values.push_back(i * averageStep + (i % 2 == 0 ? -(averageStep * 0.2f) : (averageStep * 0.2f)));
827 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION, 0, VariableStepCondition(values) );
828 notification.NotifySignal().Connect( &TestCallback );
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);
834 for( unsigned int i = 0 ; i < values.size() - 1 ; ++i )
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 );
846 static bool gCallBack2Called = false;
847 void TestCallback2(PropertyNotification& source)
849 gCallBack2Called = true;
852 int UtcDaliPropertyNotificationOrder(void)
854 TestApplication application; // Reset all test adapter return codes
856 Actor actor = Actor::New();
857 Stage::GetCurrent().Add(actor);
858 // this should complete in first frame
859 PropertyNotification notification1 = actor.AddPropertyNotification( Actor::POSITION_X, GreaterThanCondition(90.0f) );
860 notification1.NotifySignal().Connect( &TestCallback );
861 // this should complete in second frame
862 PropertyNotification notification2 = actor.AddPropertyNotification( Actor::POSITION_X, 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::POSITION ), Vector3( 200.0f, 0.0f, 0.0f ), AlphaFunctions::Linear );
869 application.SendNotification();
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;
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
881 application.Render(RENDER_FRAME_INTERVAL);
882 DALI_TEST_EQUALS( gCallBackCalled, false, TEST_LOCATION );
883 DALI_TEST_EQUALS( gCallBack2Called, false, TEST_LOCATION );
885 // serve the notifications
886 application.SendNotification();
887 DALI_TEST_EQUALS( gCallBackCalled, true, TEST_LOCATION );
888 DALI_TEST_EQUALS( gCallBack2Called, true, TEST_LOCATION );
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 );