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, "false && \"Property notification added to event side only property", TEST_LOCATION );
267 int UtcDaliPropertyNotificationGetCondition(void)
269 TestApplication application;
270 tet_infoline(" UtcDaliPropertyNotificationGetCondition");
272 Actor actor = Actor::New();
274 PropertyCondition condition = GreaterThanCondition(100.0f);
275 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X, condition);
276 DALI_TEST_CHECK( condition == notification.GetCondition() );
280 class PropertyNotificationConstWrapper
284 PropertyNotificationConstWrapper(PropertyNotification propertyNotification)
285 :mPropertyNotification(propertyNotification)
291 * Returns const reference to property notification.
292 * @return const reference.
294 const PropertyCondition& GetCondition() const
296 return mPropertyNotification.GetCondition();
299 PropertyNotification mPropertyNotification;
302 int UtcDaliPropertyNotificationGetConditionConst(void)
304 TestApplication application;
305 tet_infoline(" UtcDaliPropertyNotificationGetConditionConst");
307 Actor actor = Actor::New();
309 PropertyCondition condition = GreaterThanCondition(100.0f);
310 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X, condition);
311 PropertyNotificationConstWrapper notificationConst(notification);
312 const PropertyCondition& conditionReference1 = notificationConst.GetCondition();
313 const PropertyCondition& conditionReference2 = notificationConst.GetCondition();
315 DALI_TEST_CHECK( (&conditionReference1) == (&conditionReference2) );
316 DALI_TEST_CHECK( conditionReference1 == condition );
320 int UtcDaliPropertyNotificationGetTarget(void)
322 TestApplication application;
323 tet_infoline(" UtcDaliPropertyNotificationGetTarget");
325 Actor actor = Actor::New();
326 Actor actor2 = Actor::New();
328 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
329 GreaterThanCondition(100.0f));
330 Actor targetActor = Actor::DownCast( notification.GetTarget() );
332 DALI_TEST_CHECK( targetActor == actor );
336 int UtcDaliPropertyNotificationGetProperty(void)
338 TestApplication application;
339 tet_infoline(" UtcDaliPropertyNotificationGetProperty");
341 Actor actor = Actor::New();
343 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
344 GreaterThanCondition(100.0f));
345 Property::Index targetProperty = notification.GetTargetProperty();
347 DALI_TEST_EQUALS( targetProperty, Actor::Property::POSITION_X, TEST_LOCATION );
351 int UtcDaliPropertyNotificationGetNotifyMode(void)
353 TestApplication application;
354 tet_infoline(" UtcDaliPropertyNotificationGetNotifyMode");
356 Actor actor = Actor::New();
358 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
359 GreaterThanCondition(100.0f));
360 notification.SetNotifyMode(PropertyNotification::NotifyOnChanged);
361 PropertyNotification::NotifyMode notifyMode = notification.GetNotifyMode();
363 DALI_TEST_EQUALS( notifyMode, PropertyNotification::NotifyOnChanged, TEST_LOCATION );
367 int UtcDaliPropertyNotificationGreaterThan(void)
369 TestApplication application;
370 tet_infoline(" UtcDaliPropertyNotificationGreaterThan");
372 Actor actor = Actor::New();
373 Stage::GetCurrent().Add(actor);
375 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(100.0f) );
376 notification.NotifySignal().Connect( &TestCallback );
378 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
379 Wait(application, DEFAULT_WAIT_PERIOD);
381 // Move right to satisfy condition
382 gCallBackCalled = false;
383 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
384 Wait(application, DEFAULT_WAIT_PERIOD);
385 DALI_TEST_CHECK( gCallBackCalled );
387 // Move left to un-satisfy condition
388 gCallBackCalled = false;
389 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
390 Wait(application, DEFAULT_WAIT_PERIOD);
391 DALI_TEST_CHECK( !gCallBackCalled );
393 // Move right to satisfy condition again.
394 gCallBackCalled = false;
395 Wait(application, DEFAULT_WAIT_PERIOD);
396 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
397 Wait(application, DEFAULT_WAIT_PERIOD);
398 DALI_TEST_CHECK( gCallBackCalled );
402 int UtcDaliPropertyNotificationLessThan(void)
404 TestApplication application;
405 tet_infoline(" UtcDaliPropertyNotificationLessThan");
407 Actor actor = Actor::New();
408 Stage::GetCurrent().Add(actor);
410 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, LessThanCondition(100.0f ) );
411 notification.NotifySignal().Connect( &TestCallback );
413 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
414 Wait(application, DEFAULT_WAIT_PERIOD);
416 // Move left to satisfy condition
417 gCallBackCalled = false;
418 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
419 Wait(application, DEFAULT_WAIT_PERIOD);
420 DALI_TEST_CHECK( gCallBackCalled );
422 // Move right to un-satisfy condition
423 gCallBackCalled = false;
424 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
425 Wait(application, DEFAULT_WAIT_PERIOD);
426 DALI_TEST_CHECK( !gCallBackCalled );
428 // Move left to satisfy condition again.
429 gCallBackCalled = false;
430 Wait(application, DEFAULT_WAIT_PERIOD);
431 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
432 Wait(application, DEFAULT_WAIT_PERIOD);
433 DALI_TEST_CHECK( gCallBackCalled );
437 int UtcDaliPropertyNotificationInside(void)
439 TestApplication application;
440 tet_infoline(" UtcDaliPropertyNotificationInside");
442 Actor actor = Actor::New();
443 Stage::GetCurrent().Add(actor);
445 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, InsideCondition(100.0f, 200.0f) );
446 notification.NotifySignal().Connect( &TestCallback );
448 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
449 Wait(application, DEFAULT_WAIT_PERIOD);
451 // Move inside to satisfy condition
452 gCallBackCalled = false;
453 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
454 Wait(application, DEFAULT_WAIT_PERIOD);
455 DALI_TEST_CHECK( gCallBackCalled );
457 // Move outside (right) to un-satisfy condition
458 gCallBackCalled = false;
459 actor.SetPosition(Vector3(300.0f, 0.0f, 0.0f));
460 Wait(application, DEFAULT_WAIT_PERIOD);
461 DALI_TEST_CHECK( !gCallBackCalled );
463 // Move inside to satisfy condition again.
464 gCallBackCalled = false;
465 Wait(application, DEFAULT_WAIT_PERIOD);
466 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
467 Wait(application, DEFAULT_WAIT_PERIOD);
468 DALI_TEST_CHECK( gCallBackCalled );
472 int UtcDaliPropertyNotificationOutside(void)
474 TestApplication application;
475 tet_infoline(" UtcDaliPropertyNotificationOutside");
477 Actor actor = Actor::New();
478 Stage::GetCurrent().Add(actor);
480 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, OutsideCondition(100.0f, 200.0f) );
481 notification.NotifySignal().Connect( &TestCallback );
483 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
484 Wait(application, DEFAULT_WAIT_PERIOD);
486 // Move outside (left) to satisfy condition
487 gCallBackCalled = false;
488 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
489 Wait(application, DEFAULT_WAIT_PERIOD);
490 DALI_TEST_CHECK( gCallBackCalled );
492 // Move inside to un-satisfy condition
493 gCallBackCalled = false;
494 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
495 Wait(application, DEFAULT_WAIT_PERIOD);
496 DALI_TEST_CHECK( !gCallBackCalled );
498 // Move outside (right) to satisfy condition again.
499 gCallBackCalled = false;
500 Wait(application, DEFAULT_WAIT_PERIOD);
501 actor.SetPosition(Vector3(300.0f, 0.0f, 0.0f));
502 Wait(application, DEFAULT_WAIT_PERIOD);
503 DALI_TEST_CHECK( gCallBackCalled );
507 int UtcDaliPropertyNotificationVectorComponentGreaterThan(void)
509 TestApplication application;
510 tet_infoline(" UtcDaliPropertyNotificationGreaterThan");
512 Actor actor = Actor::New();
513 Stage::GetCurrent().Add(actor);
515 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, GreaterThanCondition(100.0f) );
516 notification.NotifySignal().Connect( &TestCallback );
517 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, GreaterThanCondition(100.0f) );
518 notification.NotifySignal().Connect( &TestCallback );
519 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, GreaterThanCondition(100.0f) );
520 notification.NotifySignal().Connect( &TestCallback );
521 notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, GreaterThanCondition(0.5f) );
522 notification.NotifySignal().Connect( &TestCallback );
524 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
525 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
526 Wait(application, DEFAULT_WAIT_PERIOD);
528 // Move right to satisfy XAxis condition
529 gCallBackCalled = false;
530 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
531 Wait(application, DEFAULT_WAIT_PERIOD);
532 DALI_TEST_CHECK( gCallBackCalled );
534 // Move down to satisfy YAxis condition
535 gCallBackCalled = false;
536 actor.SetPosition(Vector3(200.0f, 200.0f, 0.0f));
537 Wait(application, DEFAULT_WAIT_PERIOD);
538 DALI_TEST_CHECK( gCallBackCalled );
540 // Move forward to satisfy ZAxis
541 gCallBackCalled = false;
542 Wait(application, DEFAULT_WAIT_PERIOD);
543 actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
544 Wait(application, DEFAULT_WAIT_PERIOD);
545 DALI_TEST_CHECK( gCallBackCalled );
547 // Change alpha Colour to satisfy w/alpha component condition
548 gCallBackCalled = false;
549 Wait(application, DEFAULT_WAIT_PERIOD);
550 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
551 Wait(application, DEFAULT_WAIT_PERIOD);
552 DALI_TEST_CHECK( gCallBackCalled );
556 int UtcDaliPropertyNotificationVectorComponentLessThan(void)
558 TestApplication application;
559 tet_infoline(" UtcDaliPropertyNotificationLessThan");
561 Actor actor = Actor::New();
562 Stage::GetCurrent().Add(actor);
564 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, LessThanCondition(-100.0f) );
565 notification.NotifySignal().Connect( &TestCallback );
566 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, LessThanCondition(-100.0f) );
567 notification.NotifySignal().Connect( &TestCallback );
568 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, LessThanCondition(-100.0f) );
569 notification.NotifySignal().Connect( &TestCallback );
570 notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, LessThanCondition(0.5f) );
571 notification.NotifySignal().Connect( &TestCallback );
573 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
574 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
575 Wait(application, DEFAULT_WAIT_PERIOD);
577 // Move left to satisfy XAxis condition
578 gCallBackCalled = false;
579 actor.SetPosition(Vector3(-200.0f, 0.0f, 0.0f));
580 Wait(application, DEFAULT_WAIT_PERIOD);
581 DALI_TEST_CHECK( gCallBackCalled );
583 // Move up to satisfy YAxis condition
584 gCallBackCalled = false;
585 actor.SetPosition(Vector3(-200.0f, -200.0f, 0.0f));
586 Wait(application, DEFAULT_WAIT_PERIOD);
587 DALI_TEST_CHECK( gCallBackCalled );
589 // Move back to satisfy ZAxis
590 gCallBackCalled = false;
591 Wait(application, DEFAULT_WAIT_PERIOD);
592 actor.SetPosition(Vector3(-200.0f, -200.0f, -200.0f));
593 Wait(application, DEFAULT_WAIT_PERIOD);
594 DALI_TEST_CHECK( gCallBackCalled );
596 // Change alpha Colour to satisfy w/alpha component condition
597 gCallBackCalled = false;
598 Wait(application, DEFAULT_WAIT_PERIOD);
599 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
600 Wait(application, DEFAULT_WAIT_PERIOD);
601 DALI_TEST_CHECK( gCallBackCalled );
605 int UtcDaliPropertyNotificationVectorComponentInside(void)
607 TestApplication application;
608 tet_infoline(" UtcDaliPropertyNotificationInside");
610 Actor actor = Actor::New();
611 Stage::GetCurrent().Add(actor);
613 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, InsideCondition(-100.0f, 100.0f) );
614 notification.NotifySignal().Connect( &TestCallback );
615 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, InsideCondition(-100.0f, 100.0f) );
616 notification.NotifySignal().Connect( &TestCallback );
617 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, InsideCondition(-100.0f, 100.0f) );
618 notification.NotifySignal().Connect( &TestCallback );
619 notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, InsideCondition(0.25f, 0.75f) );
620 notification.NotifySignal().Connect( &TestCallback );
622 // set outside all conditions
623 actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
624 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
625 Wait(application, DEFAULT_WAIT_PERIOD);
627 // Move x to inside condition
628 gCallBackCalled = false;
629 actor.SetPosition(Vector3(0.0f, 200.0f, 200.0f));
630 Wait(application, DEFAULT_WAIT_PERIOD);
631 DALI_TEST_CHECK( gCallBackCalled );
633 // Move y to inside condition
634 gCallBackCalled = false;
635 actor.SetPosition(Vector3(0.0f, 0.0f, 200.0f));
636 Wait(application, DEFAULT_WAIT_PERIOD);
637 DALI_TEST_CHECK( gCallBackCalled );
639 // Move z to inside condition
640 gCallBackCalled = false;
641 Wait(application, DEFAULT_WAIT_PERIOD);
642 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
643 Wait(application, DEFAULT_WAIT_PERIOD);
644 DALI_TEST_CHECK( gCallBackCalled );
646 // change alpha to inside condition
647 gCallBackCalled = false;
648 Wait(application, DEFAULT_WAIT_PERIOD);
649 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.5f));
650 Wait(application, DEFAULT_WAIT_PERIOD);
651 DALI_TEST_CHECK( gCallBackCalled );
655 int UtcDaliPropertyNotificationVectorComponentOutside(void)
657 TestApplication application;
658 tet_infoline(" UtcDaliPropertyNotificationOutside");
660 Actor actor = Actor::New();
661 Stage::GetCurrent().Add(actor);
663 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, OutsideCondition(-100.0f, 100.0f) );
664 notification.NotifySignal().Connect( &TestCallback );
665 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, OutsideCondition(-100.0f, 100.0f) );
666 notification.NotifySignal().Connect( &TestCallback );
667 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, OutsideCondition(-100.0f, 100.0f) );
668 notification.NotifySignal().Connect( &TestCallback );
669 notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, OutsideCondition(0.25f, 0.75f) );
670 notification.NotifySignal().Connect( &TestCallback );
672 // set inside all conditions
673 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
674 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.5f));
675 Wait(application, DEFAULT_WAIT_PERIOD);
677 // Move x to outside condition
678 gCallBackCalled = false;
679 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
680 Wait(application, DEFAULT_WAIT_PERIOD);
681 DALI_TEST_CHECK( gCallBackCalled );
683 // Move y to outside condition
684 gCallBackCalled = false;
685 actor.SetPosition(Vector3(200.0f, 200.0f, 0.0f));
686 Wait(application, DEFAULT_WAIT_PERIOD);
687 DALI_TEST_CHECK( gCallBackCalled );
689 // Move z to outside condition
690 gCallBackCalled = false;
691 Wait(application, DEFAULT_WAIT_PERIOD);
692 actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
693 Wait(application, DEFAULT_WAIT_PERIOD);
694 DALI_TEST_CHECK( gCallBackCalled );
696 // change alpha to outside condition
697 gCallBackCalled = false;
698 Wait(application, DEFAULT_WAIT_PERIOD);
699 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
700 Wait(application, DEFAULT_WAIT_PERIOD);
701 DALI_TEST_CHECK( gCallBackCalled );
705 int UtcDaliPropertyConditionGetArguments(void)
707 TestApplication application;
708 tet_infoline(" UtcDaliPropertyConditionGetArguments");
710 PropertyCondition condition = GreaterThanCondition( 50.0f );
712 DALI_TEST_EQUALS( condition.GetArgumentCount(), 1u, TEST_LOCATION );
713 float value = condition.GetArgument( 0 );
714 DALI_TEST_EQUALS( value, 50.0f, TEST_LOCATION );
716 condition = InsideCondition( 125.0f, 250.0f );
718 DALI_TEST_EQUALS( condition.GetArgumentCount(), 2u, TEST_LOCATION );
719 float value1 = condition.GetArgument( 0 );
720 float value2 = condition.GetArgument( 1 );
721 DALI_TEST_EQUALS( value1, 125.0f, TEST_LOCATION );
722 DALI_TEST_EQUALS( value2, 250.0f, TEST_LOCATION );
726 int UtcDaliPropertyNotificationStep(void)
728 TestApplication application;
729 tet_infoline(" UtcDaliPropertyNotificationStep");
731 Actor actor = Actor::New();
732 Stage::GetCurrent().Add(actor);
734 const float step = 100.0f;
736 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, StepCondition(step, 50.0f) );
737 notification.NotifySignal().Connect( &TestCallback );
739 // set initial position
740 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
741 Wait(application, DEFAULT_WAIT_PERIOD);
743 // test both directions
744 for( int i = 1 ; i < 10 ; ++i )
746 // Move x to negative position
747 gCallBackCalled = false;
748 actor.SetPosition(Vector3((i * step), 0.0f, 0.0f));
749 Wait(application, DEFAULT_WAIT_PERIOD);
750 DALI_TEST_CHECK( gCallBackCalled );
753 for( int i = 1 ; i < 10 ; ++i )
755 // Move x to negative position
756 gCallBackCalled = false;
757 actor.SetPosition(Vector3(-(i * step), 0.0f, 0.0f));
758 Wait(application, DEFAULT_WAIT_PERIOD);
759 DALI_TEST_CHECK( gCallBackCalled );
764 int UtcDaliPropertyNotificationVariableStep(void)
766 TestApplication application;
767 tet_infoline(" UtcDaliPropertyNotificationStep");
769 Actor actor = Actor::New();
770 Stage::GetCurrent().Add(actor);
772 Dali::Vector<float> values;
774 const float averageStep = 100.0f;
776 for( int i = 1 ; i < 10 ; i++ )
778 values.PushBack(i * averageStep + (i % 2 == 0 ? -(averageStep * 0.2f) : (averageStep * 0.2f)));
781 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, VariableStepCondition(values) );
782 notification.NotifySignal().Connect( &TestCallback );
784 // set initial position lower than first position in list
785 actor.SetPosition(Vector3(values[0] - averageStep, 0.0f, 0.0f));
786 Wait(application, DEFAULT_WAIT_PERIOD);
788 for( unsigned int i = 0 ; i < values.Count() - 1 ; ++i )
790 gCallBackCalled = false;
791 // set position half way between the current values
792 float position = values[i] + (0.5f * (values[i + 1] - values[i]));
793 actor.SetPosition(Vector3(position, 0.0f, 0.0f));
794 Wait(application, DEFAULT_WAIT_PERIOD);
795 DALI_TEST_CHECK( gCallBackCalled );
800 static bool gCallBack2Called = false;
801 void TestCallback2(PropertyNotification& source)
803 gCallBack2Called = true;
806 int UtcDaliPropertyNotificationOrder(void)
808 TestApplication application; // Reset all test adapter return codes
810 Actor actor = Actor::New();
811 Stage::GetCurrent().Add(actor);
812 // this should complete in first frame
813 PropertyNotification notification1 = actor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(90.0f) );
814 notification1.NotifySignal().Connect( &TestCallback );
815 // this should complete in second frame
816 PropertyNotification notification2 = actor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(150.0f) );
817 notification2.NotifySignal().Connect( &TestCallback2 );
818 Animation animation = Animation::New( 0.032f ); // finishes in 32 ms
819 animation.AnimateTo( Property(actor, Actor::Property::POSITION ), Vector3( 200.0f, 0.0f, 0.0f ), AlphaFunction::LINEAR );
823 application.SendNotification();
825 application.Render(RENDER_FRAME_INTERVAL);
826 // no notifications yet
827 DALI_TEST_EQUALS( gCallBackCalled, false, TEST_LOCATION );
828 DALI_TEST_EQUALS( gCallBack2Called, false, TEST_LOCATION );
829 gCallBackCalled = false;
830 gCallBack2Called = false;
832 // dont serve the notifications but run another update & render
833 // this simulates situation where there is a notification in event side but it's not been picked up by event thread
835 application.Render(RENDER_FRAME_INTERVAL);
836 DALI_TEST_EQUALS( gCallBackCalled, false, TEST_LOCATION );
837 DALI_TEST_EQUALS( gCallBack2Called, false, TEST_LOCATION );
839 // serve the notifications
840 application.SendNotification();
841 DALI_TEST_EQUALS( gCallBackCalled, true, TEST_LOCATION );
842 DALI_TEST_EQUALS( gCallBack2Called, true, TEST_LOCATION );
844 gCallBackCalled = false;
845 gCallBack2Called = false;
846 application.Render(RENDER_FRAME_INTERVAL);
847 application.SendNotification();
848 DALI_TEST_EQUALS( gCallBackCalled, false, TEST_LOCATION );
849 DALI_TEST_EQUALS( gCallBack2Called, false, TEST_LOCATION );