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 <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
26 void utc_dali_property_notification_startup(void)
28 test_return_value = TET_UNDEF;
31 void utc_dali_property_notification_cleanup(void)
33 test_return_value = TET_PASS;
38 static bool gCallBackCalled;
40 static void TestCallback(PropertyNotification& source)
42 gCallBackCalled = true;
45 const int RENDER_FRAME_INTERVAL(16); ///< Duration of each frame in ms. (at approx 60FPS)
46 const int DEFAULT_WAIT_PERIOD(100); ///< Default waiting period for check.
49 class TestClass : public ConnectionTracker
63 mActor = Actor::New();
64 Stage::GetCurrent().Add( mActor );
65 mNotification = mActor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(100.0f) );
66 mNotification.NotifySignal().Connect( this, &TestClass::OnPropertyNotify );
69 void RemovePropertyNotification()
71 mActor.RemovePropertyNotification( mNotification );
74 void RemovePropertyNotifications()
76 mActor.RemovePropertyNotifications();
81 Stage::GetCurrent().Remove( mActor );
83 mNotification.Reset();
86 void OnPropertyNotify( PropertyNotification& source )
88 tet_infoline(" OnPropertyNotify");
89 gCallBackCalled = true;
93 PropertyNotification mNotification;
98 * Simulate time passed by.
100 * @note this will always process at least 1 frame (1/60 sec)
102 * @param application Test application instance
103 * @param duration Time to pass in milliseconds.
104 * @return The actual time passed in milliseconds
106 int Wait(TestApplication& application, int duration = 0)
110 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
112 application.SendNotification();
113 application.Render(RENDER_FRAME_INTERVAL);
114 time += RENDER_FRAME_INTERVAL;
120 } // unnamed namespace
123 // Positive test case for a method
124 int UtcDaliPropertyNotificationDownCast(void)
126 TestApplication application;
127 tet_infoline(" UtcDaliPropertyNotificationDownCast");
129 Actor actor = Actor::New();
130 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X, GreaterThanCondition(100.0f));
131 BaseHandle handle = notification;
132 PropertyNotification notificationHandle;
134 DALI_TEST_CHECK(notification);
135 DALI_TEST_CHECK(handle);
136 DALI_TEST_CHECK(!notificationHandle);
138 notificationHandle = PropertyNotification::DownCast( handle );
139 DALI_TEST_CHECK(notificationHandle);
144 // Negative test case for a method
145 int UtcDaliPropertyNotificationDownCastNegative(void)
147 TestApplication application;
148 tet_infoline(" UtcDaliPropertyNotificationDownCastNegative");
150 // Create something derived from BaseHandle other than a PropertyNotification.
151 Actor somethingElse = Actor::New();
153 Actor actor = Actor::New();
154 actor.AddPropertyNotification(Actor::Property::POSITION_X, GreaterThanCondition(100.0f));
155 BaseHandle handle = somethingElse;
156 PropertyNotification notificationHandle;
158 notificationHandle = PropertyNotification::DownCast( handle );
159 DALI_TEST_CHECK(!notificationHandle);
163 int UtcDaliAddPropertyNotification(void)
165 TestApplication application; // Reset all test adapter return codes
166 tet_infoline(" UtcDaliAddPropertyNotification");
168 Actor actor = Actor::New();
170 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X, GreaterThanCondition(100.0f));
171 PropertyNotification notification2 = actor.AddPropertyNotification(Actor::Property::SIZE, StepCondition( 1.0f, 1.0f ));
172 DALI_TEST_CHECK( notification );
173 DALI_TEST_CHECK( notification2 );
177 int UtcDaliAddPropertyNotificationCallback(void)
179 TestApplication application; // Reset all test adapter return codes
181 TestClass* object = new TestClass;
183 object->Initialize();
184 application.Render(RENDER_FRAME_INTERVAL);
185 application.SendNotification();
187 gCallBackCalled = false;
189 tet_infoline(" UtcDaliAddPropertyNotificationCallback - Forcing notification condition true, should receive a notification");
190 object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
191 application.Render(RENDER_FRAME_INTERVAL);
192 application.SendNotification();
193 application.Render(RENDER_FRAME_INTERVAL);
194 application.SendNotification();
195 DALI_TEST_CHECK( gCallBackCalled );
196 gCallBackCalled = false;
198 tet_infoline(" UtcDaliAddPropertyNotificationCallback - Forcing notification condition false, should not receive a notification");
199 object->mActor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
200 application.Render(RENDER_FRAME_INTERVAL);
201 application.SendNotification();
202 application.Render(RENDER_FRAME_INTERVAL);
203 application.SendNotification();
204 DALI_TEST_CHECK( !gCallBackCalled );
205 gCallBackCalled = false;
207 tet_infoline(" UtcDaliAddPropertyNotificationCallback - Deleting notification and it's owning object, should not receive a notification");
208 object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
209 application.Render(RENDER_FRAME_INTERVAL);
210 application.SendNotification();
212 application.Render(RENDER_FRAME_INTERVAL);
213 application.SendNotification();
214 DALI_TEST_CHECK( !gCallBackCalled );
216 tet_infoline(" UtcDaliAddPropertyNotificationCallback - Removing notification and it's owning object, should not receive a notification");
217 object->Initialize();
218 application.Render(RENDER_FRAME_INTERVAL);
219 application.SendNotification();
220 gCallBackCalled = false;
222 object->RemovePropertyNotification();
224 object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
225 application.Render(RENDER_FRAME_INTERVAL);
226 application.SendNotification();
227 application.Render(RENDER_FRAME_INTERVAL);
228 application.SendNotification();
229 DALI_TEST_CHECK( !gCallBackCalled );
231 tet_infoline(" UtcDaliAddPropertyNotificationCallback - Removing all notifications and it's owning object, should not receive a notification");
232 object->Initialize();
233 application.Render(RENDER_FRAME_INTERVAL);
234 application.SendNotification();
235 gCallBackCalled = false;
237 object->RemovePropertyNotifications();
239 object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
240 application.Render(RENDER_FRAME_INTERVAL);
241 application.SendNotification();
242 application.Render(RENDER_FRAME_INTERVAL);
243 application.SendNotification();
244 DALI_TEST_CHECK( !gCallBackCalled );
251 int UtcDaliAddPropertyNotificationTypeProperty(void)
253 TestApplication application;
255 Actor actor = Actor::New();
257 // Currently, Type registry properties cannot be animated
260 actor.AddPropertyNotification( PROPERTY_REGISTRATION_START_INDEX, GreaterThanCondition( 100.0f ) );
262 catch ( DaliException& e )
264 DALI_TEST_ASSERT( e, "Property notification added to event side only property", TEST_LOCATION );
269 int UtcDaliAddPropertyNotificationEventSidePropertyN(void)
271 TestApplication application;
273 Actor actor = Actor::New();
275 // Currently, Type registry properties cannot be animated
278 actor.AddPropertyNotification( PROPERTY_REGISTRATION_MAX_INDEX - 1, GreaterThanCondition( 100.0f ) );
280 catch ( DaliException& e )
282 DALI_TEST_ASSERT( e, "Property notification added to event side only property", TEST_LOCATION );
287 int UtcDaliAddPropertyNotificationSize(void)
289 TestApplication application;
290 tet_infoline(" UtcDaliAddPropertyNotificationSize");
292 Actor actor = Actor::New();
294 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::SIZE, StepCondition( 1.0f, 1.0f ));
295 DALI_TEST_CHECK( notification );
299 int UtcDaliPropertyNotificationGetCondition(void)
301 TestApplication application;
302 tet_infoline(" UtcDaliPropertyNotificationGetCondition");
304 Actor actor = Actor::New();
306 PropertyCondition condition = GreaterThanCondition(100.0f);
307 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X, condition);
308 DALI_TEST_CHECK( condition == notification.GetCondition() );
312 class PropertyNotificationConstWrapper
316 PropertyNotificationConstWrapper(PropertyNotification propertyNotification)
317 :mPropertyNotification(propertyNotification)
323 * Returns const reference to property notification.
324 * @return const reference.
326 const PropertyCondition& GetCondition() const
328 return mPropertyNotification.GetCondition();
331 PropertyNotification mPropertyNotification;
334 int UtcDaliPropertyNotificationGetConditionConst(void)
336 TestApplication application;
337 tet_infoline(" UtcDaliPropertyNotificationGetConditionConst");
339 Actor actor = Actor::New();
341 PropertyCondition condition = GreaterThanCondition(100.0f);
342 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X, condition);
343 PropertyNotificationConstWrapper notificationConst(notification);
344 const PropertyCondition& conditionReference1 = notificationConst.GetCondition();
345 const PropertyCondition& conditionReference2 = notificationConst.GetCondition();
347 DALI_TEST_CHECK( (&conditionReference1) == (&conditionReference2) );
348 DALI_TEST_CHECK( conditionReference1 == condition );
352 int UtcDaliPropertyNotificationGetTarget(void)
354 TestApplication application;
355 tet_infoline(" UtcDaliPropertyNotificationGetTarget");
357 Actor actor = Actor::New();
358 Actor actor2 = Actor::New();
360 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
361 GreaterThanCondition(100.0f));
362 Actor targetActor = Actor::DownCast( notification.GetTarget() );
364 DALI_TEST_CHECK( targetActor == actor );
368 int UtcDaliPropertyNotificationGetProperty(void)
370 TestApplication application;
371 tet_infoline(" UtcDaliPropertyNotificationGetProperty");
373 Actor actor = Actor::New();
375 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
376 GreaterThanCondition(100.0f));
377 Property::Index targetProperty = notification.GetTargetProperty();
379 DALI_TEST_EQUALS( targetProperty, (Property::Index)Actor::Property::POSITION_X, TEST_LOCATION );
383 int UtcDaliPropertyNotificationGetNotifyMode(void)
385 TestApplication application;
386 tet_infoline(" UtcDaliPropertyNotificationGetNotifyMode");
388 Actor actor = Actor::New();
390 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
391 GreaterThanCondition(100.0f));
392 notification.SetNotifyMode(PropertyNotification::NotifyOnChanged);
393 PropertyNotification::NotifyMode notifyMode = notification.GetNotifyMode();
395 DALI_TEST_EQUALS( notifyMode, PropertyNotification::NotifyOnChanged, TEST_LOCATION );
399 int UtcDaliPropertyNotificationGetNotifyResultP(void)
401 TestApplication application;
402 tet_infoline(" UtcDaliPropertyNotificationGetNotifyMode");
404 Actor actor = Actor::New();
406 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
407 GreaterThanCondition(100.0f));
408 notification.SetNotifyMode(PropertyNotification::NotifyOnChanged);
409 gCallBackCalled = false;
410 notification.NotifySignal().Connect( &TestCallback );
412 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
414 application.Render(RENDER_FRAME_INTERVAL);
415 application.SendNotification();
416 application.Render(RENDER_FRAME_INTERVAL);
417 application.SendNotification();
419 bool notifyResult = notification.GetNotifyResult();
421 DALI_TEST_EQUALS( notifyResult, false, TEST_LOCATION );
426 int UtcDaliPropertyNotificationGreaterThan(void)
428 TestApplication application;
429 tet_infoline(" UtcDaliPropertyNotificationGreaterThan");
431 Actor actor = Actor::New();
432 Stage::GetCurrent().Add(actor);
434 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(100.0f) );
435 notification.NotifySignal().Connect( &TestCallback );
437 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
438 Wait(application, DEFAULT_WAIT_PERIOD);
440 // Move right to satisfy condition
441 gCallBackCalled = false;
442 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
443 Wait(application, DEFAULT_WAIT_PERIOD);
444 DALI_TEST_CHECK( gCallBackCalled );
446 // Move left to un-satisfy condition
447 gCallBackCalled = false;
448 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
449 Wait(application, DEFAULT_WAIT_PERIOD);
450 DALI_TEST_CHECK( !gCallBackCalled );
452 // Move right to satisfy condition again.
453 gCallBackCalled = false;
454 Wait(application, DEFAULT_WAIT_PERIOD);
455 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
456 Wait(application, DEFAULT_WAIT_PERIOD);
457 DALI_TEST_CHECK( gCallBackCalled );
461 int UtcDaliPropertyNotificationLessThan(void)
463 TestApplication application;
464 tet_infoline(" UtcDaliPropertyNotificationLessThan");
466 Actor actor = Actor::New();
467 Stage::GetCurrent().Add(actor);
469 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, LessThanCondition(100.0f ) );
470 notification.NotifySignal().Connect( &TestCallback );
472 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
473 Wait(application, DEFAULT_WAIT_PERIOD);
475 // Move left to satisfy condition
476 gCallBackCalled = false;
477 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
478 Wait(application, DEFAULT_WAIT_PERIOD);
479 DALI_TEST_CHECK( gCallBackCalled );
481 // Move right to un-satisfy condition
482 gCallBackCalled = false;
483 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
484 Wait(application, DEFAULT_WAIT_PERIOD);
485 DALI_TEST_CHECK( !gCallBackCalled );
487 // Move left to satisfy condition again.
488 gCallBackCalled = false;
489 Wait(application, DEFAULT_WAIT_PERIOD);
490 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
491 Wait(application, DEFAULT_WAIT_PERIOD);
492 DALI_TEST_CHECK( gCallBackCalled );
496 int UtcDaliPropertyNotificationInside(void)
498 TestApplication application;
499 tet_infoline(" UtcDaliPropertyNotificationInside");
501 Actor actor = Actor::New();
502 Stage::GetCurrent().Add(actor);
504 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, InsideCondition(100.0f, 200.0f) );
505 notification.NotifySignal().Connect( &TestCallback );
507 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
508 Wait(application, DEFAULT_WAIT_PERIOD);
510 // Move inside to satisfy condition
511 gCallBackCalled = false;
512 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
513 Wait(application, DEFAULT_WAIT_PERIOD);
514 DALI_TEST_CHECK( gCallBackCalled );
516 // Move outside (right) to un-satisfy condition
517 gCallBackCalled = false;
518 actor.SetPosition(Vector3(300.0f, 0.0f, 0.0f));
519 Wait(application, DEFAULT_WAIT_PERIOD);
520 DALI_TEST_CHECK( !gCallBackCalled );
522 // Move inside to satisfy condition again.
523 gCallBackCalled = false;
524 Wait(application, DEFAULT_WAIT_PERIOD);
525 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
526 Wait(application, DEFAULT_WAIT_PERIOD);
527 DALI_TEST_CHECK( gCallBackCalled );
531 int UtcDaliPropertyNotificationOutside(void)
533 TestApplication application;
534 tet_infoline(" UtcDaliPropertyNotificationOutside");
536 Actor actor = Actor::New();
537 Stage::GetCurrent().Add(actor);
539 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, OutsideCondition(100.0f, 200.0f) );
540 notification.NotifySignal().Connect( &TestCallback );
542 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
543 Wait(application, DEFAULT_WAIT_PERIOD);
545 // Move outside (left) to satisfy condition
546 gCallBackCalled = false;
547 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
548 Wait(application, DEFAULT_WAIT_PERIOD);
549 DALI_TEST_CHECK( gCallBackCalled );
551 // Move inside to un-satisfy condition
552 gCallBackCalled = false;
553 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
554 Wait(application, DEFAULT_WAIT_PERIOD);
555 DALI_TEST_CHECK( !gCallBackCalled );
557 // Move outside (right) to satisfy condition again.
558 gCallBackCalled = false;
559 Wait(application, DEFAULT_WAIT_PERIOD);
560 actor.SetPosition(Vector3(300.0f, 0.0f, 0.0f));
561 Wait(application, DEFAULT_WAIT_PERIOD);
562 DALI_TEST_CHECK( gCallBackCalled );
566 int UtcDaliPropertyNotificationVectorComponentGreaterThan(void)
568 TestApplication application;
569 tet_infoline(" UtcDaliPropertyNotificationGreaterThan");
571 Actor actor = Actor::New();
572 Stage::GetCurrent().Add(actor);
574 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, GreaterThanCondition(100.0f) );
575 notification.NotifySignal().Connect( &TestCallback );
576 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, GreaterThanCondition(100.0f) );
577 notification.NotifySignal().Connect( &TestCallback );
578 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, GreaterThanCondition(100.0f) );
579 notification.NotifySignal().Connect( &TestCallback );
580 notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, GreaterThanCondition(0.5f) );
581 notification.NotifySignal().Connect( &TestCallback );
583 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
584 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
585 Wait(application, DEFAULT_WAIT_PERIOD);
587 // Move right to satisfy XAxis condition
588 gCallBackCalled = false;
589 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
590 Wait(application, DEFAULT_WAIT_PERIOD);
591 DALI_TEST_CHECK( gCallBackCalled );
593 // Move down to satisfy YAxis condition
594 gCallBackCalled = false;
595 actor.SetPosition(Vector3(200.0f, 200.0f, 0.0f));
596 Wait(application, DEFAULT_WAIT_PERIOD);
597 DALI_TEST_CHECK( gCallBackCalled );
599 // Move forward to satisfy ZAxis
600 gCallBackCalled = false;
601 Wait(application, DEFAULT_WAIT_PERIOD);
602 actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
603 Wait(application, DEFAULT_WAIT_PERIOD);
604 DALI_TEST_CHECK( gCallBackCalled );
606 // Change alpha Colour to satisfy w/alpha component condition
607 gCallBackCalled = false;
608 Wait(application, DEFAULT_WAIT_PERIOD);
609 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
610 Wait(application, DEFAULT_WAIT_PERIOD);
611 DALI_TEST_CHECK( gCallBackCalled );
615 int UtcDaliPropertyNotificationVectorComponentLessThan(void)
617 TestApplication application;
618 tet_infoline(" UtcDaliPropertyNotificationLessThan");
620 Actor actor = Actor::New();
621 Stage::GetCurrent().Add(actor);
623 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, LessThanCondition(-100.0f) );
624 notification.NotifySignal().Connect( &TestCallback );
625 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, LessThanCondition(-100.0f) );
626 notification.NotifySignal().Connect( &TestCallback );
627 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, LessThanCondition(-100.0f) );
628 notification.NotifySignal().Connect( &TestCallback );
629 notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, LessThanCondition(0.5f) );
630 notification.NotifySignal().Connect( &TestCallback );
632 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
633 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
634 Wait(application, DEFAULT_WAIT_PERIOD);
636 // Move left to satisfy XAxis condition
637 gCallBackCalled = false;
638 actor.SetPosition(Vector3(-200.0f, 0.0f, 0.0f));
639 Wait(application, DEFAULT_WAIT_PERIOD);
640 DALI_TEST_CHECK( gCallBackCalled );
642 // Move up to satisfy YAxis condition
643 gCallBackCalled = false;
644 actor.SetPosition(Vector3(-200.0f, -200.0f, 0.0f));
645 Wait(application, DEFAULT_WAIT_PERIOD);
646 DALI_TEST_CHECK( gCallBackCalled );
648 // Move back to satisfy ZAxis
649 gCallBackCalled = false;
650 Wait(application, DEFAULT_WAIT_PERIOD);
651 actor.SetPosition(Vector3(-200.0f, -200.0f, -200.0f));
652 Wait(application, DEFAULT_WAIT_PERIOD);
653 DALI_TEST_CHECK( gCallBackCalled );
655 // Change alpha Colour to satisfy w/alpha component condition
656 gCallBackCalled = false;
657 Wait(application, DEFAULT_WAIT_PERIOD);
658 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
659 Wait(application, DEFAULT_WAIT_PERIOD);
660 DALI_TEST_CHECK( gCallBackCalled );
664 int UtcDaliPropertyNotificationVectorComponentInside(void)
666 TestApplication application;
667 tet_infoline(" UtcDaliPropertyNotificationInside");
669 Actor actor = Actor::New();
670 Stage::GetCurrent().Add(actor);
672 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, InsideCondition(-100.0f, 100.0f) );
673 notification.NotifySignal().Connect( &TestCallback );
674 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, InsideCondition(-100.0f, 100.0f) );
675 notification.NotifySignal().Connect( &TestCallback );
676 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, InsideCondition(-100.0f, 100.0f) );
677 notification.NotifySignal().Connect( &TestCallback );
678 notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, InsideCondition(0.25f, 0.75f) );
679 notification.NotifySignal().Connect( &TestCallback );
681 // set outside all conditions
682 actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
683 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
684 Wait(application, DEFAULT_WAIT_PERIOD);
686 // Move x to inside condition
687 gCallBackCalled = false;
688 actor.SetPosition(Vector3(0.0f, 200.0f, 200.0f));
689 Wait(application, DEFAULT_WAIT_PERIOD);
690 DALI_TEST_CHECK( gCallBackCalled );
692 // Move y to inside condition
693 gCallBackCalled = false;
694 actor.SetPosition(Vector3(0.0f, 0.0f, 200.0f));
695 Wait(application, DEFAULT_WAIT_PERIOD);
696 DALI_TEST_CHECK( gCallBackCalled );
698 // Move z to inside condition
699 gCallBackCalled = false;
700 Wait(application, DEFAULT_WAIT_PERIOD);
701 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
702 Wait(application, DEFAULT_WAIT_PERIOD);
703 DALI_TEST_CHECK( gCallBackCalled );
705 // change alpha to inside condition
706 gCallBackCalled = false;
707 Wait(application, DEFAULT_WAIT_PERIOD);
708 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.5f));
709 Wait(application, DEFAULT_WAIT_PERIOD);
710 DALI_TEST_CHECK( gCallBackCalled );
714 int UtcDaliPropertyNotificationVectorComponentOutside(void)
716 TestApplication application;
717 tet_infoline(" UtcDaliPropertyNotificationOutside");
719 Actor actor = Actor::New();
720 Stage::GetCurrent().Add(actor);
722 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, OutsideCondition(-100.0f, 100.0f) );
723 notification.NotifySignal().Connect( &TestCallback );
724 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, OutsideCondition(-100.0f, 100.0f) );
725 notification.NotifySignal().Connect( &TestCallback );
726 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, OutsideCondition(-100.0f, 100.0f) );
727 notification.NotifySignal().Connect( &TestCallback );
728 notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, OutsideCondition(0.25f, 0.75f) );
729 notification.NotifySignal().Connect( &TestCallback );
731 // set inside all conditions
732 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
733 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.5f));
734 Wait(application, DEFAULT_WAIT_PERIOD);
736 // Move x to outside condition
737 gCallBackCalled = false;
738 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
739 Wait(application, DEFAULT_WAIT_PERIOD);
740 DALI_TEST_CHECK( gCallBackCalled );
742 // Move y to outside condition
743 gCallBackCalled = false;
744 actor.SetPosition(Vector3(200.0f, 200.0f, 0.0f));
745 Wait(application, DEFAULT_WAIT_PERIOD);
746 DALI_TEST_CHECK( gCallBackCalled );
748 // Move z to outside condition
749 gCallBackCalled = false;
750 Wait(application, DEFAULT_WAIT_PERIOD);
751 actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
752 Wait(application, DEFAULT_WAIT_PERIOD);
753 DALI_TEST_CHECK( gCallBackCalled );
755 // change alpha to outside condition
756 gCallBackCalled = false;
757 Wait(application, DEFAULT_WAIT_PERIOD);
758 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
759 Wait(application, DEFAULT_WAIT_PERIOD);
760 DALI_TEST_CHECK( gCallBackCalled );
764 int UtcDaliPropertyNotificationSetSizeResultP(void)
766 TestApplication application;
768 tet_infoline(" UtcDaliPropertyNotificationSetSizeResultP");
770 Actor actor = Actor::New();
772 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::SIZE, StepCondition( 1.0f, 1.0f ) );
773 notification.SetNotifyMode(PropertyNotification::NotifyOnChanged);
774 gCallBackCalled = false;
775 notification.NotifySignal().Connect( &TestCallback );
777 actor.SetSize(100.0f, 100.0f);
779 application.Render(RENDER_FRAME_INTERVAL);
780 application.SendNotification();
781 application.Render(RENDER_FRAME_INTERVAL);
782 application.SendNotification();
784 notifyResult = notification.GetNotifyResult();
786 DALI_TEST_EQUALS( notifyResult, true, TEST_LOCATION );
788 gCallBackCalled = false;
790 actor.SetSize(200.0f, 200.0f);
792 application.Render(RENDER_FRAME_INTERVAL);
793 application.SendNotification();
794 application.Render(RENDER_FRAME_INTERVAL);
795 application.SendNotification();
797 notifyResult = notification.GetNotifyResult();
799 DALI_TEST_EQUALS( notifyResult, true, TEST_LOCATION );
804 int UtcDaliPropertyConditionGetArguments(void)
806 TestApplication application;
807 tet_infoline(" UtcDaliPropertyConditionGetArguments");
809 PropertyCondition condition = GreaterThanCondition( 50.0f );
811 DALI_TEST_EQUALS( condition.GetArgumentCount(), 1u, TEST_LOCATION );
812 float value = condition.GetArgument( 0 );
813 DALI_TEST_EQUALS( value, 50.0f, TEST_LOCATION );
815 condition = InsideCondition( 125.0f, 250.0f );
817 DALI_TEST_EQUALS( condition.GetArgumentCount(), 2u, TEST_LOCATION );
818 float value1 = condition.GetArgument( 0 );
819 float value2 = condition.GetArgument( 1 );
820 DALI_TEST_EQUALS( value1, 125.0f, TEST_LOCATION );
821 DALI_TEST_EQUALS( value2, 250.0f, TEST_LOCATION );
825 int UtcDaliPropertyNotificationStep(void)
827 TestApplication application;
828 tet_infoline(" UtcDaliPropertyNotificationStep");
830 Actor actor = Actor::New();
831 Stage::GetCurrent().Add(actor);
833 const float step = 100.0f;
835 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, StepCondition(step, 50.0f) );
836 notification.NotifySignal().Connect( &TestCallback );
838 // set initial position
839 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
840 Wait(application, DEFAULT_WAIT_PERIOD);
842 // test both directions
843 for( int i = 1 ; i < 10 ; ++i )
845 // Move x to negative position
846 gCallBackCalled = false;
847 actor.SetPosition(Vector3((i * step), 0.0f, 0.0f));
848 Wait(application, DEFAULT_WAIT_PERIOD);
849 DALI_TEST_CHECK( gCallBackCalled );
852 for( int i = 1 ; i < 10 ; ++i )
854 // Move x to negative position
855 gCallBackCalled = false;
856 actor.SetPosition(Vector3(-(i * step), 0.0f, 0.0f));
857 Wait(application, DEFAULT_WAIT_PERIOD);
858 DALI_TEST_CHECK( gCallBackCalled );
863 int UtcDaliPropertyNotificationVariableStep(void)
865 TestApplication application;
866 tet_infoline(" UtcDaliPropertyNotificationStep");
868 Actor actor = Actor::New();
869 Stage::GetCurrent().Add(actor);
871 Dali::Vector<float> values;
873 const float averageStep = 100.0f;
875 for( int i = 1 ; i < 10 ; i++ )
877 values.PushBack(i * averageStep + (i % 2 == 0 ? -(averageStep * 0.2f) : (averageStep * 0.2f)));
880 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, VariableStepCondition(values) );
881 notification.NotifySignal().Connect( &TestCallback );
883 // set initial position lower than first position in list
884 actor.SetPosition(Vector3(values[0] - averageStep, 0.0f, 0.0f));
885 Wait(application, DEFAULT_WAIT_PERIOD);
887 for( unsigned int i = 0 ; i < values.Count() - 1 ; ++i )
889 gCallBackCalled = false;
890 // set position half way between the current values
891 float position = values[i] + (0.5f * (values[i + 1] - values[i]));
892 actor.SetPosition(Vector3(position, 0.0f, 0.0f));
893 Wait(application, DEFAULT_WAIT_PERIOD);
894 DALI_TEST_CHECK( gCallBackCalled );
899 static bool gCallBack2Called = false;
900 void TestCallback2(PropertyNotification& source)
902 gCallBack2Called = true;
905 int UtcDaliPropertyNotificationOrder(void)
907 TestApplication application; // Reset all test adapter return codes
909 Actor actor = Actor::New();
910 Stage::GetCurrent().Add(actor);
911 // this should complete in first frame
912 PropertyNotification notification1 = actor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(90.0f) );
913 notification1.NotifySignal().Connect( &TestCallback );
914 // this should complete in second frame
915 PropertyNotification notification2 = actor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(150.0f) );
916 notification2.NotifySignal().Connect( &TestCallback2 );
917 Animation animation = Animation::New( 0.032f ); // finishes in 32 ms
918 animation.AnimateTo( Property(actor, Actor::Property::POSITION ), Vector3( 200.0f, 0.0f, 0.0f ), AlphaFunction::LINEAR );
922 application.SendNotification();
924 application.Render(RENDER_FRAME_INTERVAL);
925 // no notifications yet
926 DALI_TEST_EQUALS( gCallBackCalled, false, TEST_LOCATION );
927 DALI_TEST_EQUALS( gCallBack2Called, false, TEST_LOCATION );
928 gCallBackCalled = false;
929 gCallBack2Called = false;
931 // dont serve the notifications but run another update & render
932 // this simulates situation where there is a notification in event side but it's not been picked up by event thread
934 application.Render(RENDER_FRAME_INTERVAL);
935 DALI_TEST_EQUALS( gCallBackCalled, false, TEST_LOCATION );
936 DALI_TEST_EQUALS( gCallBack2Called, false, TEST_LOCATION );
938 // serve the notifications
939 application.SendNotification();
940 DALI_TEST_EQUALS( gCallBackCalled, true, TEST_LOCATION );
941 DALI_TEST_EQUALS( gCallBack2Called, true, TEST_LOCATION );
943 gCallBackCalled = false;
944 gCallBack2Called = false;
945 application.Render(RENDER_FRAME_INTERVAL);
946 application.SendNotification();
947 DALI_TEST_EQUALS( gCallBackCalled, false, TEST_LOCATION );
948 DALI_TEST_EQUALS( gCallBack2Called, false, TEST_LOCATION );