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 DALI_TEST_CHECK( notification );
175 int UtcDaliAddPropertyNotificationCallback(void)
177 TestApplication application; // Reset all test adapter return codes
179 TestClass* object = new TestClass;
181 object->Initialize();
182 application.Render(RENDER_FRAME_INTERVAL);
183 application.SendNotification();
185 gCallBackCalled = false;
187 tet_infoline(" UtcDaliAddPropertyNotificationCallback - Forcing notification condition true, should receive a notification");
188 object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
189 application.Render(RENDER_FRAME_INTERVAL);
190 application.SendNotification();
191 application.Render(RENDER_FRAME_INTERVAL);
192 application.SendNotification();
193 DALI_TEST_CHECK( gCallBackCalled );
194 gCallBackCalled = false;
196 tet_infoline(" UtcDaliAddPropertyNotificationCallback - Forcing notification condition false, should not receive a notification");
197 object->mActor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
198 application.Render(RENDER_FRAME_INTERVAL);
199 application.SendNotification();
200 application.Render(RENDER_FRAME_INTERVAL);
201 application.SendNotification();
202 DALI_TEST_CHECK( !gCallBackCalled );
203 gCallBackCalled = false;
205 tet_infoline(" UtcDaliAddPropertyNotificationCallback - Deleting notification and it's owning object, should not receive a notification");
206 object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
207 application.Render(RENDER_FRAME_INTERVAL);
208 application.SendNotification();
210 application.Render(RENDER_FRAME_INTERVAL);
211 application.SendNotification();
212 DALI_TEST_CHECK( !gCallBackCalled );
214 tet_infoline(" UtcDaliAddPropertyNotificationCallback - Removing notification and it's owning object, should not receive a notification");
215 object->Initialize();
216 application.Render(RENDER_FRAME_INTERVAL);
217 application.SendNotification();
218 gCallBackCalled = false;
220 object->RemovePropertyNotification();
222 object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
223 application.Render(RENDER_FRAME_INTERVAL);
224 application.SendNotification();
225 application.Render(RENDER_FRAME_INTERVAL);
226 application.SendNotification();
227 DALI_TEST_CHECK( !gCallBackCalled );
229 tet_infoline(" UtcDaliAddPropertyNotificationCallback - Removing all notifications and it's owning object, should not receive a notification");
230 object->Initialize();
231 application.Render(RENDER_FRAME_INTERVAL);
232 application.SendNotification();
233 gCallBackCalled = false;
235 object->RemovePropertyNotifications();
237 object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
238 application.Render(RENDER_FRAME_INTERVAL);
239 application.SendNotification();
240 application.Render(RENDER_FRAME_INTERVAL);
241 application.SendNotification();
242 DALI_TEST_CHECK( !gCallBackCalled );
249 int UtcDaliAddPropertyNotificationTypeProperty(void)
251 TestApplication application;
253 Actor actor = Actor::New();
255 // Currently, Type registry properties cannot be animated
258 actor.AddPropertyNotification( PROPERTY_REGISTRATION_START_INDEX, GreaterThanCondition( 100.0f ) );
260 catch ( DaliException& e )
262 DALI_TEST_ASSERT( e, "Property notification added to event side only property", TEST_LOCATION );
267 int UtcDaliAddPropertyNotificationEventSidePropertyN(void)
269 TestApplication application;
271 Actor actor = Actor::New();
273 // Currently, Type registry properties cannot be animated
276 actor.AddPropertyNotification( PROPERTY_REGISTRATION_MAX_INDEX - 1, GreaterThanCondition( 100.0f ) );
278 catch ( DaliException& e )
280 DALI_TEST_ASSERT( e, "Property notification added to event side only property", TEST_LOCATION );
285 int UtcDaliPropertyNotificationGetCondition(void)
287 TestApplication application;
288 tet_infoline(" UtcDaliPropertyNotificationGetCondition");
290 Actor actor = Actor::New();
292 PropertyCondition condition = GreaterThanCondition(100.0f);
293 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X, condition);
294 DALI_TEST_CHECK( condition == notification.GetCondition() );
298 class PropertyNotificationConstWrapper
302 PropertyNotificationConstWrapper(PropertyNotification propertyNotification)
303 :mPropertyNotification(propertyNotification)
309 * Returns const reference to property notification.
310 * @return const reference.
312 const PropertyCondition& GetCondition() const
314 return mPropertyNotification.GetCondition();
317 PropertyNotification mPropertyNotification;
320 int UtcDaliPropertyNotificationGetConditionConst(void)
322 TestApplication application;
323 tet_infoline(" UtcDaliPropertyNotificationGetConditionConst");
325 Actor actor = Actor::New();
327 PropertyCondition condition = GreaterThanCondition(100.0f);
328 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X, condition);
329 PropertyNotificationConstWrapper notificationConst(notification);
330 const PropertyCondition& conditionReference1 = notificationConst.GetCondition();
331 const PropertyCondition& conditionReference2 = notificationConst.GetCondition();
333 DALI_TEST_CHECK( (&conditionReference1) == (&conditionReference2) );
334 DALI_TEST_CHECK( conditionReference1 == condition );
338 int UtcDaliPropertyNotificationGetTarget(void)
340 TestApplication application;
341 tet_infoline(" UtcDaliPropertyNotificationGetTarget");
343 Actor actor = Actor::New();
344 Actor actor2 = Actor::New();
346 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
347 GreaterThanCondition(100.0f));
348 Actor targetActor = Actor::DownCast( notification.GetTarget() );
350 DALI_TEST_CHECK( targetActor == actor );
354 int UtcDaliPropertyNotificationGetProperty(void)
356 TestApplication application;
357 tet_infoline(" UtcDaliPropertyNotificationGetProperty");
359 Actor actor = Actor::New();
361 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
362 GreaterThanCondition(100.0f));
363 Property::Index targetProperty = notification.GetTargetProperty();
365 DALI_TEST_EQUALS( targetProperty, (Property::Index)Actor::Property::POSITION_X, TEST_LOCATION );
369 int UtcDaliPropertyNotificationGetNotifyMode(void)
371 TestApplication application;
372 tet_infoline(" UtcDaliPropertyNotificationGetNotifyMode");
374 Actor actor = Actor::New();
376 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
377 GreaterThanCondition(100.0f));
378 notification.SetNotifyMode(PropertyNotification::NotifyOnChanged);
379 PropertyNotification::NotifyMode notifyMode = notification.GetNotifyMode();
381 DALI_TEST_EQUALS( notifyMode, PropertyNotification::NotifyOnChanged, TEST_LOCATION );
385 int UtcDaliPropertyNotificationGetNotifyResultP(void)
387 TestApplication application;
388 tet_infoline(" UtcDaliPropertyNotificationGetNotifyMode");
390 Actor actor = Actor::New();
392 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
393 GreaterThanCondition(100.0f));
394 notification.SetNotifyMode(PropertyNotification::NotifyOnChanged);
395 gCallBackCalled = false;
396 notification.NotifySignal().Connect( &TestCallback );
398 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
400 application.Render(RENDER_FRAME_INTERVAL);
401 application.SendNotification();
402 application.Render(RENDER_FRAME_INTERVAL);
403 application.SendNotification();
405 bool notifyResult = notification.GetNotifyResult();
407 DALI_TEST_EQUALS( notifyResult, false, TEST_LOCATION );
412 int UtcDaliPropertyNotificationGreaterThan(void)
414 TestApplication application;
415 tet_infoline(" UtcDaliPropertyNotificationGreaterThan");
417 Actor actor = Actor::New();
418 Stage::GetCurrent().Add(actor);
420 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(100.0f) );
421 notification.NotifySignal().Connect( &TestCallback );
423 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
424 Wait(application, DEFAULT_WAIT_PERIOD);
426 // Move right to satisfy condition
427 gCallBackCalled = false;
428 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
429 Wait(application, DEFAULT_WAIT_PERIOD);
430 DALI_TEST_CHECK( gCallBackCalled );
432 // Move left to un-satisfy condition
433 gCallBackCalled = false;
434 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
435 Wait(application, DEFAULT_WAIT_PERIOD);
436 DALI_TEST_CHECK( !gCallBackCalled );
438 // Move right to satisfy condition again.
439 gCallBackCalled = false;
440 Wait(application, DEFAULT_WAIT_PERIOD);
441 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
442 Wait(application, DEFAULT_WAIT_PERIOD);
443 DALI_TEST_CHECK( gCallBackCalled );
447 int UtcDaliPropertyNotificationLessThan(void)
449 TestApplication application;
450 tet_infoline(" UtcDaliPropertyNotificationLessThan");
452 Actor actor = Actor::New();
453 Stage::GetCurrent().Add(actor);
455 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, LessThanCondition(100.0f ) );
456 notification.NotifySignal().Connect( &TestCallback );
458 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
459 Wait(application, DEFAULT_WAIT_PERIOD);
461 // Move left to satisfy condition
462 gCallBackCalled = false;
463 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
464 Wait(application, DEFAULT_WAIT_PERIOD);
465 DALI_TEST_CHECK( gCallBackCalled );
467 // Move right to un-satisfy condition
468 gCallBackCalled = false;
469 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
470 Wait(application, DEFAULT_WAIT_PERIOD);
471 DALI_TEST_CHECK( !gCallBackCalled );
473 // Move left to satisfy condition again.
474 gCallBackCalled = false;
475 Wait(application, DEFAULT_WAIT_PERIOD);
476 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
477 Wait(application, DEFAULT_WAIT_PERIOD);
478 DALI_TEST_CHECK( gCallBackCalled );
482 int UtcDaliPropertyNotificationInside(void)
484 TestApplication application;
485 tet_infoline(" UtcDaliPropertyNotificationInside");
487 Actor actor = Actor::New();
488 Stage::GetCurrent().Add(actor);
490 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, InsideCondition(100.0f, 200.0f) );
491 notification.NotifySignal().Connect( &TestCallback );
493 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
494 Wait(application, DEFAULT_WAIT_PERIOD);
496 // Move inside to satisfy condition
497 gCallBackCalled = false;
498 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
499 Wait(application, DEFAULT_WAIT_PERIOD);
500 DALI_TEST_CHECK( gCallBackCalled );
502 // Move outside (right) to un-satisfy condition
503 gCallBackCalled = false;
504 actor.SetPosition(Vector3(300.0f, 0.0f, 0.0f));
505 Wait(application, DEFAULT_WAIT_PERIOD);
506 DALI_TEST_CHECK( !gCallBackCalled );
508 // Move inside to satisfy condition again.
509 gCallBackCalled = false;
510 Wait(application, DEFAULT_WAIT_PERIOD);
511 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
512 Wait(application, DEFAULT_WAIT_PERIOD);
513 DALI_TEST_CHECK( gCallBackCalled );
517 int UtcDaliPropertyNotificationOutside(void)
519 TestApplication application;
520 tet_infoline(" UtcDaliPropertyNotificationOutside");
522 Actor actor = Actor::New();
523 Stage::GetCurrent().Add(actor);
525 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, OutsideCondition(100.0f, 200.0f) );
526 notification.NotifySignal().Connect( &TestCallback );
528 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
529 Wait(application, DEFAULT_WAIT_PERIOD);
531 // Move outside (left) to satisfy condition
532 gCallBackCalled = false;
533 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
534 Wait(application, DEFAULT_WAIT_PERIOD);
535 DALI_TEST_CHECK( gCallBackCalled );
537 // Move inside to un-satisfy condition
538 gCallBackCalled = false;
539 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
540 Wait(application, DEFAULT_WAIT_PERIOD);
541 DALI_TEST_CHECK( !gCallBackCalled );
543 // Move outside (right) to satisfy condition again.
544 gCallBackCalled = false;
545 Wait(application, DEFAULT_WAIT_PERIOD);
546 actor.SetPosition(Vector3(300.0f, 0.0f, 0.0f));
547 Wait(application, DEFAULT_WAIT_PERIOD);
548 DALI_TEST_CHECK( gCallBackCalled );
552 int UtcDaliPropertyNotificationVectorComponentGreaterThan(void)
554 TestApplication application;
555 tet_infoline(" UtcDaliPropertyNotificationGreaterThan");
557 Actor actor = Actor::New();
558 Stage::GetCurrent().Add(actor);
560 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, GreaterThanCondition(100.0f) );
561 notification.NotifySignal().Connect( &TestCallback );
562 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, GreaterThanCondition(100.0f) );
563 notification.NotifySignal().Connect( &TestCallback );
564 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, GreaterThanCondition(100.0f) );
565 notification.NotifySignal().Connect( &TestCallback );
566 notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, GreaterThanCondition(0.5f) );
567 notification.NotifySignal().Connect( &TestCallback );
569 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
570 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
571 Wait(application, DEFAULT_WAIT_PERIOD);
573 // Move right to satisfy XAxis condition
574 gCallBackCalled = false;
575 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
576 Wait(application, DEFAULT_WAIT_PERIOD);
577 DALI_TEST_CHECK( gCallBackCalled );
579 // Move down to satisfy YAxis condition
580 gCallBackCalled = false;
581 actor.SetPosition(Vector3(200.0f, 200.0f, 0.0f));
582 Wait(application, DEFAULT_WAIT_PERIOD);
583 DALI_TEST_CHECK( gCallBackCalled );
585 // Move forward to satisfy ZAxis
586 gCallBackCalled = false;
587 Wait(application, DEFAULT_WAIT_PERIOD);
588 actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
589 Wait(application, DEFAULT_WAIT_PERIOD);
590 DALI_TEST_CHECK( gCallBackCalled );
592 // Change alpha Colour to satisfy w/alpha component condition
593 gCallBackCalled = false;
594 Wait(application, DEFAULT_WAIT_PERIOD);
595 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
596 Wait(application, DEFAULT_WAIT_PERIOD);
597 DALI_TEST_CHECK( gCallBackCalled );
601 int UtcDaliPropertyNotificationVectorComponentLessThan(void)
603 TestApplication application;
604 tet_infoline(" UtcDaliPropertyNotificationLessThan");
606 Actor actor = Actor::New();
607 Stage::GetCurrent().Add(actor);
609 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, LessThanCondition(-100.0f) );
610 notification.NotifySignal().Connect( &TestCallback );
611 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, LessThanCondition(-100.0f) );
612 notification.NotifySignal().Connect( &TestCallback );
613 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, LessThanCondition(-100.0f) );
614 notification.NotifySignal().Connect( &TestCallback );
615 notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, LessThanCondition(0.5f) );
616 notification.NotifySignal().Connect( &TestCallback );
618 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
619 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
620 Wait(application, DEFAULT_WAIT_PERIOD);
622 // Move left to satisfy XAxis condition
623 gCallBackCalled = false;
624 actor.SetPosition(Vector3(-200.0f, 0.0f, 0.0f));
625 Wait(application, DEFAULT_WAIT_PERIOD);
626 DALI_TEST_CHECK( gCallBackCalled );
628 // Move up to satisfy YAxis condition
629 gCallBackCalled = false;
630 actor.SetPosition(Vector3(-200.0f, -200.0f, 0.0f));
631 Wait(application, DEFAULT_WAIT_PERIOD);
632 DALI_TEST_CHECK( gCallBackCalled );
634 // Move back to satisfy ZAxis
635 gCallBackCalled = false;
636 Wait(application, DEFAULT_WAIT_PERIOD);
637 actor.SetPosition(Vector3(-200.0f, -200.0f, -200.0f));
638 Wait(application, DEFAULT_WAIT_PERIOD);
639 DALI_TEST_CHECK( gCallBackCalled );
641 // Change alpha Colour to satisfy w/alpha component condition
642 gCallBackCalled = false;
643 Wait(application, DEFAULT_WAIT_PERIOD);
644 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
645 Wait(application, DEFAULT_WAIT_PERIOD);
646 DALI_TEST_CHECK( gCallBackCalled );
650 int UtcDaliPropertyNotificationVectorComponentInside(void)
652 TestApplication application;
653 tet_infoline(" UtcDaliPropertyNotificationInside");
655 Actor actor = Actor::New();
656 Stage::GetCurrent().Add(actor);
658 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, InsideCondition(-100.0f, 100.0f) );
659 notification.NotifySignal().Connect( &TestCallback );
660 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, InsideCondition(-100.0f, 100.0f) );
661 notification.NotifySignal().Connect( &TestCallback );
662 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, InsideCondition(-100.0f, 100.0f) );
663 notification.NotifySignal().Connect( &TestCallback );
664 notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, InsideCondition(0.25f, 0.75f) );
665 notification.NotifySignal().Connect( &TestCallback );
667 // set outside all conditions
668 actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
669 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
670 Wait(application, DEFAULT_WAIT_PERIOD);
672 // Move x to inside condition
673 gCallBackCalled = false;
674 actor.SetPosition(Vector3(0.0f, 200.0f, 200.0f));
675 Wait(application, DEFAULT_WAIT_PERIOD);
676 DALI_TEST_CHECK( gCallBackCalled );
678 // Move y to inside condition
679 gCallBackCalled = false;
680 actor.SetPosition(Vector3(0.0f, 0.0f, 200.0f));
681 Wait(application, DEFAULT_WAIT_PERIOD);
682 DALI_TEST_CHECK( gCallBackCalled );
684 // Move z to inside condition
685 gCallBackCalled = false;
686 Wait(application, DEFAULT_WAIT_PERIOD);
687 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
688 Wait(application, DEFAULT_WAIT_PERIOD);
689 DALI_TEST_CHECK( gCallBackCalled );
691 // change alpha to inside condition
692 gCallBackCalled = false;
693 Wait(application, DEFAULT_WAIT_PERIOD);
694 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.5f));
695 Wait(application, DEFAULT_WAIT_PERIOD);
696 DALI_TEST_CHECK( gCallBackCalled );
700 int UtcDaliPropertyNotificationVectorComponentOutside(void)
702 TestApplication application;
703 tet_infoline(" UtcDaliPropertyNotificationOutside");
705 Actor actor = Actor::New();
706 Stage::GetCurrent().Add(actor);
708 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, OutsideCondition(-100.0f, 100.0f) );
709 notification.NotifySignal().Connect( &TestCallback );
710 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, OutsideCondition(-100.0f, 100.0f) );
711 notification.NotifySignal().Connect( &TestCallback );
712 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, OutsideCondition(-100.0f, 100.0f) );
713 notification.NotifySignal().Connect( &TestCallback );
714 notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, OutsideCondition(0.25f, 0.75f) );
715 notification.NotifySignal().Connect( &TestCallback );
717 // set inside all conditions
718 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
719 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.5f));
720 Wait(application, DEFAULT_WAIT_PERIOD);
722 // Move x to outside condition
723 gCallBackCalled = false;
724 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
725 Wait(application, DEFAULT_WAIT_PERIOD);
726 DALI_TEST_CHECK( gCallBackCalled );
728 // Move y to outside condition
729 gCallBackCalled = false;
730 actor.SetPosition(Vector3(200.0f, 200.0f, 0.0f));
731 Wait(application, DEFAULT_WAIT_PERIOD);
732 DALI_TEST_CHECK( gCallBackCalled );
734 // Move z to outside condition
735 gCallBackCalled = false;
736 Wait(application, DEFAULT_WAIT_PERIOD);
737 actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
738 Wait(application, DEFAULT_WAIT_PERIOD);
739 DALI_TEST_CHECK( gCallBackCalled );
741 // change alpha to outside condition
742 gCallBackCalled = false;
743 Wait(application, DEFAULT_WAIT_PERIOD);
744 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
745 Wait(application, DEFAULT_WAIT_PERIOD);
746 DALI_TEST_CHECK( gCallBackCalled );
750 int UtcDaliPropertyConditionGetArguments(void)
752 TestApplication application;
753 tet_infoline(" UtcDaliPropertyConditionGetArguments");
755 PropertyCondition condition = GreaterThanCondition( 50.0f );
757 DALI_TEST_EQUALS( condition.GetArgumentCount(), 1u, TEST_LOCATION );
758 float value = condition.GetArgument( 0 );
759 DALI_TEST_EQUALS( value, 50.0f, TEST_LOCATION );
761 condition = InsideCondition( 125.0f, 250.0f );
763 DALI_TEST_EQUALS( condition.GetArgumentCount(), 2u, TEST_LOCATION );
764 float value1 = condition.GetArgument( 0 );
765 float value2 = condition.GetArgument( 1 );
766 DALI_TEST_EQUALS( value1, 125.0f, TEST_LOCATION );
767 DALI_TEST_EQUALS( value2, 250.0f, TEST_LOCATION );
771 int UtcDaliPropertyNotificationStep(void)
773 TestApplication application;
774 tet_infoline(" UtcDaliPropertyNotificationStep");
776 Actor actor = Actor::New();
777 Stage::GetCurrent().Add(actor);
779 const float step = 100.0f;
781 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, StepCondition(step, 50.0f) );
782 notification.NotifySignal().Connect( &TestCallback );
784 // set initial position
785 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
786 Wait(application, DEFAULT_WAIT_PERIOD);
788 // test both directions
789 for( int i = 1 ; i < 10 ; ++i )
791 // Move x to negative position
792 gCallBackCalled = false;
793 actor.SetPosition(Vector3((i * step), 0.0f, 0.0f));
794 Wait(application, DEFAULT_WAIT_PERIOD);
795 DALI_TEST_CHECK( gCallBackCalled );
798 for( int i = 1 ; i < 10 ; ++i )
800 // Move x to negative position
801 gCallBackCalled = false;
802 actor.SetPosition(Vector3(-(i * step), 0.0f, 0.0f));
803 Wait(application, DEFAULT_WAIT_PERIOD);
804 DALI_TEST_CHECK( gCallBackCalled );
809 int UtcDaliPropertyNotificationVariableStep(void)
811 TestApplication application;
812 tet_infoline(" UtcDaliPropertyNotificationStep");
814 Actor actor = Actor::New();
815 Stage::GetCurrent().Add(actor);
817 Dali::Vector<float> values;
819 const float averageStep = 100.0f;
821 for( int i = 1 ; i < 10 ; i++ )
823 values.PushBack(i * averageStep + (i % 2 == 0 ? -(averageStep * 0.2f) : (averageStep * 0.2f)));
826 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, VariableStepCondition(values) );
827 notification.NotifySignal().Connect( &TestCallback );
829 // set initial position lower than first position in list
830 actor.SetPosition(Vector3(values[0] - averageStep, 0.0f, 0.0f));
831 Wait(application, DEFAULT_WAIT_PERIOD);
833 for( unsigned int i = 0 ; i < values.Count() - 1 ; ++i )
835 gCallBackCalled = false;
836 // set position half way between the current values
837 float position = values[i] + (0.5f * (values[i + 1] - values[i]));
838 actor.SetPosition(Vector3(position, 0.0f, 0.0f));
839 Wait(application, DEFAULT_WAIT_PERIOD);
840 DALI_TEST_CHECK( gCallBackCalled );
845 static bool gCallBack2Called = false;
846 void TestCallback2(PropertyNotification& source)
848 gCallBack2Called = true;
851 int UtcDaliPropertyNotificationOrder(void)
853 TestApplication application; // Reset all test adapter return codes
855 Actor actor = Actor::New();
856 Stage::GetCurrent().Add(actor);
857 // this should complete in first frame
858 PropertyNotification notification1 = actor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(90.0f) );
859 notification1.NotifySignal().Connect( &TestCallback );
860 // this should complete in second frame
861 PropertyNotification notification2 = actor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(150.0f) );
862 notification2.NotifySignal().Connect( &TestCallback2 );
863 Animation animation = Animation::New( 0.032f ); // finishes in 32 ms
864 animation.AnimateTo( Property(actor, Actor::Property::POSITION ), Vector3( 200.0f, 0.0f, 0.0f ), AlphaFunction::LINEAR );
868 application.SendNotification();
870 application.Render(RENDER_FRAME_INTERVAL);
871 // no notifications yet
872 DALI_TEST_EQUALS( gCallBackCalled, false, TEST_LOCATION );
873 DALI_TEST_EQUALS( gCallBack2Called, false, TEST_LOCATION );
874 gCallBackCalled = false;
875 gCallBack2Called = false;
877 // dont serve the notifications but run another update & render
878 // this simulates situation where there is a notification in event side but it's not been picked up by event thread
880 application.Render(RENDER_FRAME_INTERVAL);
881 DALI_TEST_EQUALS( gCallBackCalled, false, TEST_LOCATION );
882 DALI_TEST_EQUALS( gCallBack2Called, false, TEST_LOCATION );
884 // serve the notifications
885 application.SendNotification();
886 DALI_TEST_EQUALS( gCallBackCalled, true, TEST_LOCATION );
887 DALI_TEST_EQUALS( gCallBack2Called, true, TEST_LOCATION );
889 gCallBackCalled = false;
890 gCallBack2Called = false;
891 application.Render(RENDER_FRAME_INTERVAL);
892 application.SendNotification();
893 DALI_TEST_EQUALS( gCallBackCalled, false, TEST_LOCATION );
894 DALI_TEST_EQUALS( gCallBack2Called, false, TEST_LOCATION );