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 UtcDaliPropertyNotificationGetNotifyResultP(void)
369 TestApplication application;
370 tet_infoline(" UtcDaliPropertyNotificationGetNotifyMode");
372 Actor actor = Actor::New();
374 PropertyNotification notification = actor.AddPropertyNotification(Actor::Property::POSITION_X,
375 GreaterThanCondition(100.0f));
376 notification.SetNotifyMode(PropertyNotification::NotifyOnChanged);
377 gCallBackCalled = false;
378 notification.NotifySignal().Connect( &TestCallback );
380 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
382 application.Render(RENDER_FRAME_INTERVAL);
383 application.SendNotification();
384 application.Render(RENDER_FRAME_INTERVAL);
385 application.SendNotification();
387 bool notifyResult = notification.GetNotifyResult();
389 DALI_TEST_EQUALS( notifyResult, false, TEST_LOCATION );
394 int UtcDaliPropertyNotificationGreaterThan(void)
396 TestApplication application;
397 tet_infoline(" UtcDaliPropertyNotificationGreaterThan");
399 Actor actor = Actor::New();
400 Stage::GetCurrent().Add(actor);
402 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(100.0f) );
403 notification.NotifySignal().Connect( &TestCallback );
405 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
406 Wait(application, DEFAULT_WAIT_PERIOD);
408 // Move right to satisfy condition
409 gCallBackCalled = false;
410 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
411 Wait(application, DEFAULT_WAIT_PERIOD);
412 DALI_TEST_CHECK( gCallBackCalled );
414 // Move left to un-satisfy condition
415 gCallBackCalled = false;
416 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
417 Wait(application, DEFAULT_WAIT_PERIOD);
418 DALI_TEST_CHECK( !gCallBackCalled );
420 // Move right to satisfy condition again.
421 gCallBackCalled = false;
422 Wait(application, DEFAULT_WAIT_PERIOD);
423 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
424 Wait(application, DEFAULT_WAIT_PERIOD);
425 DALI_TEST_CHECK( gCallBackCalled );
429 int UtcDaliPropertyNotificationLessThan(void)
431 TestApplication application;
432 tet_infoline(" UtcDaliPropertyNotificationLessThan");
434 Actor actor = Actor::New();
435 Stage::GetCurrent().Add(actor);
437 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, LessThanCondition(100.0f ) );
438 notification.NotifySignal().Connect( &TestCallback );
440 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
441 Wait(application, DEFAULT_WAIT_PERIOD);
443 // Move left to satisfy condition
444 gCallBackCalled = false;
445 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
446 Wait(application, DEFAULT_WAIT_PERIOD);
447 DALI_TEST_CHECK( gCallBackCalled );
449 // Move right to un-satisfy condition
450 gCallBackCalled = false;
451 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
452 Wait(application, DEFAULT_WAIT_PERIOD);
453 DALI_TEST_CHECK( !gCallBackCalled );
455 // Move left to satisfy condition again.
456 gCallBackCalled = false;
457 Wait(application, DEFAULT_WAIT_PERIOD);
458 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
459 Wait(application, DEFAULT_WAIT_PERIOD);
460 DALI_TEST_CHECK( gCallBackCalled );
464 int UtcDaliPropertyNotificationInside(void)
466 TestApplication application;
467 tet_infoline(" UtcDaliPropertyNotificationInside");
469 Actor actor = Actor::New();
470 Stage::GetCurrent().Add(actor);
472 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, InsideCondition(100.0f, 200.0f) );
473 notification.NotifySignal().Connect( &TestCallback );
475 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
476 Wait(application, DEFAULT_WAIT_PERIOD);
478 // Move inside to satisfy condition
479 gCallBackCalled = false;
480 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
481 Wait(application, DEFAULT_WAIT_PERIOD);
482 DALI_TEST_CHECK( gCallBackCalled );
484 // Move outside (right) to un-satisfy condition
485 gCallBackCalled = false;
486 actor.SetPosition(Vector3(300.0f, 0.0f, 0.0f));
487 Wait(application, DEFAULT_WAIT_PERIOD);
488 DALI_TEST_CHECK( !gCallBackCalled );
490 // Move inside to satisfy condition again.
491 gCallBackCalled = false;
492 Wait(application, DEFAULT_WAIT_PERIOD);
493 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
494 Wait(application, DEFAULT_WAIT_PERIOD);
495 DALI_TEST_CHECK( gCallBackCalled );
499 int UtcDaliPropertyNotificationOutside(void)
501 TestApplication application;
502 tet_infoline(" UtcDaliPropertyNotificationOutside");
504 Actor actor = Actor::New();
505 Stage::GetCurrent().Add(actor);
507 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION_X, OutsideCondition(100.0f, 200.0f) );
508 notification.NotifySignal().Connect( &TestCallback );
510 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
511 Wait(application, DEFAULT_WAIT_PERIOD);
513 // Move outside (left) to satisfy condition
514 gCallBackCalled = false;
515 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
516 Wait(application, DEFAULT_WAIT_PERIOD);
517 DALI_TEST_CHECK( gCallBackCalled );
519 // Move inside to un-satisfy condition
520 gCallBackCalled = false;
521 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
522 Wait(application, DEFAULT_WAIT_PERIOD);
523 DALI_TEST_CHECK( !gCallBackCalled );
525 // Move outside (right) to satisfy condition again.
526 gCallBackCalled = false;
527 Wait(application, DEFAULT_WAIT_PERIOD);
528 actor.SetPosition(Vector3(300.0f, 0.0f, 0.0f));
529 Wait(application, DEFAULT_WAIT_PERIOD);
530 DALI_TEST_CHECK( gCallBackCalled );
534 int UtcDaliPropertyNotificationVectorComponentGreaterThan(void)
536 TestApplication application;
537 tet_infoline(" UtcDaliPropertyNotificationGreaterThan");
539 Actor actor = Actor::New();
540 Stage::GetCurrent().Add(actor);
542 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, GreaterThanCondition(100.0f) );
543 notification.NotifySignal().Connect( &TestCallback );
544 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, GreaterThanCondition(100.0f) );
545 notification.NotifySignal().Connect( &TestCallback );
546 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, GreaterThanCondition(100.0f) );
547 notification.NotifySignal().Connect( &TestCallback );
548 notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, GreaterThanCondition(0.5f) );
549 notification.NotifySignal().Connect( &TestCallback );
551 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
552 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
553 Wait(application, DEFAULT_WAIT_PERIOD);
555 // Move right to satisfy XAxis condition
556 gCallBackCalled = false;
557 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
558 Wait(application, DEFAULT_WAIT_PERIOD);
559 DALI_TEST_CHECK( gCallBackCalled );
561 // Move down to satisfy YAxis condition
562 gCallBackCalled = false;
563 actor.SetPosition(Vector3(200.0f, 200.0f, 0.0f));
564 Wait(application, DEFAULT_WAIT_PERIOD);
565 DALI_TEST_CHECK( gCallBackCalled );
567 // Move forward to satisfy ZAxis
568 gCallBackCalled = false;
569 Wait(application, DEFAULT_WAIT_PERIOD);
570 actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
571 Wait(application, DEFAULT_WAIT_PERIOD);
572 DALI_TEST_CHECK( gCallBackCalled );
574 // Change alpha Colour to satisfy w/alpha component condition
575 gCallBackCalled = false;
576 Wait(application, DEFAULT_WAIT_PERIOD);
577 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
578 Wait(application, DEFAULT_WAIT_PERIOD);
579 DALI_TEST_CHECK( gCallBackCalled );
583 int UtcDaliPropertyNotificationVectorComponentLessThan(void)
585 TestApplication application;
586 tet_infoline(" UtcDaliPropertyNotificationLessThan");
588 Actor actor = Actor::New();
589 Stage::GetCurrent().Add(actor);
591 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, LessThanCondition(-100.0f) );
592 notification.NotifySignal().Connect( &TestCallback );
593 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, LessThanCondition(-100.0f) );
594 notification.NotifySignal().Connect( &TestCallback );
595 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, LessThanCondition(-100.0f) );
596 notification.NotifySignal().Connect( &TestCallback );
597 notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, LessThanCondition(0.5f) );
598 notification.NotifySignal().Connect( &TestCallback );
600 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
601 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
602 Wait(application, DEFAULT_WAIT_PERIOD);
604 // Move left to satisfy XAxis condition
605 gCallBackCalled = false;
606 actor.SetPosition(Vector3(-200.0f, 0.0f, 0.0f));
607 Wait(application, DEFAULT_WAIT_PERIOD);
608 DALI_TEST_CHECK( gCallBackCalled );
610 // Move up to satisfy YAxis condition
611 gCallBackCalled = false;
612 actor.SetPosition(Vector3(-200.0f, -200.0f, 0.0f));
613 Wait(application, DEFAULT_WAIT_PERIOD);
614 DALI_TEST_CHECK( gCallBackCalled );
616 // Move back to satisfy ZAxis
617 gCallBackCalled = false;
618 Wait(application, DEFAULT_WAIT_PERIOD);
619 actor.SetPosition(Vector3(-200.0f, -200.0f, -200.0f));
620 Wait(application, DEFAULT_WAIT_PERIOD);
621 DALI_TEST_CHECK( gCallBackCalled );
623 // Change alpha Colour to satisfy w/alpha component condition
624 gCallBackCalled = false;
625 Wait(application, DEFAULT_WAIT_PERIOD);
626 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
627 Wait(application, DEFAULT_WAIT_PERIOD);
628 DALI_TEST_CHECK( gCallBackCalled );
632 int UtcDaliPropertyNotificationVectorComponentInside(void)
634 TestApplication application;
635 tet_infoline(" UtcDaliPropertyNotificationInside");
637 Actor actor = Actor::New();
638 Stage::GetCurrent().Add(actor);
640 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, InsideCondition(-100.0f, 100.0f) );
641 notification.NotifySignal().Connect( &TestCallback );
642 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, InsideCondition(-100.0f, 100.0f) );
643 notification.NotifySignal().Connect( &TestCallback );
644 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, InsideCondition(-100.0f, 100.0f) );
645 notification.NotifySignal().Connect( &TestCallback );
646 notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, InsideCondition(0.25f, 0.75f) );
647 notification.NotifySignal().Connect( &TestCallback );
649 // set outside all conditions
650 actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
651 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
652 Wait(application, DEFAULT_WAIT_PERIOD);
654 // Move x to inside condition
655 gCallBackCalled = false;
656 actor.SetPosition(Vector3(0.0f, 200.0f, 200.0f));
657 Wait(application, DEFAULT_WAIT_PERIOD);
658 DALI_TEST_CHECK( gCallBackCalled );
660 // Move y to inside condition
661 gCallBackCalled = false;
662 actor.SetPosition(Vector3(0.0f, 0.0f, 200.0f));
663 Wait(application, DEFAULT_WAIT_PERIOD);
664 DALI_TEST_CHECK( gCallBackCalled );
666 // Move z to inside condition
667 gCallBackCalled = false;
668 Wait(application, DEFAULT_WAIT_PERIOD);
669 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
670 Wait(application, DEFAULT_WAIT_PERIOD);
671 DALI_TEST_CHECK( gCallBackCalled );
673 // change alpha to inside condition
674 gCallBackCalled = false;
675 Wait(application, DEFAULT_WAIT_PERIOD);
676 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.5f));
677 Wait(application, DEFAULT_WAIT_PERIOD);
678 DALI_TEST_CHECK( gCallBackCalled );
682 int UtcDaliPropertyNotificationVectorComponentOutside(void)
684 TestApplication application;
685 tet_infoline(" UtcDaliPropertyNotificationOutside");
687 Actor actor = Actor::New();
688 Stage::GetCurrent().Add(actor);
690 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, OutsideCondition(-100.0f, 100.0f) );
691 notification.NotifySignal().Connect( &TestCallback );
692 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 1, OutsideCondition(-100.0f, 100.0f) );
693 notification.NotifySignal().Connect( &TestCallback );
694 notification = actor.AddPropertyNotification( Actor::Property::POSITION, 2, OutsideCondition(-100.0f, 100.0f) );
695 notification.NotifySignal().Connect( &TestCallback );
696 notification = actor.AddPropertyNotification( Actor::Property::COLOR, 3, OutsideCondition(0.25f, 0.75f) );
697 notification.NotifySignal().Connect( &TestCallback );
699 // set inside all conditions
700 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
701 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.5f));
702 Wait(application, DEFAULT_WAIT_PERIOD);
704 // Move x to outside condition
705 gCallBackCalled = false;
706 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
707 Wait(application, DEFAULT_WAIT_PERIOD);
708 DALI_TEST_CHECK( gCallBackCalled );
710 // Move y to outside condition
711 gCallBackCalled = false;
712 actor.SetPosition(Vector3(200.0f, 200.0f, 0.0f));
713 Wait(application, DEFAULT_WAIT_PERIOD);
714 DALI_TEST_CHECK( gCallBackCalled );
716 // Move z to outside condition
717 gCallBackCalled = false;
718 Wait(application, DEFAULT_WAIT_PERIOD);
719 actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
720 Wait(application, DEFAULT_WAIT_PERIOD);
721 DALI_TEST_CHECK( gCallBackCalled );
723 // change alpha to outside condition
724 gCallBackCalled = false;
725 Wait(application, DEFAULT_WAIT_PERIOD);
726 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
727 Wait(application, DEFAULT_WAIT_PERIOD);
728 DALI_TEST_CHECK( gCallBackCalled );
732 int UtcDaliPropertyConditionGetArguments(void)
734 TestApplication application;
735 tet_infoline(" UtcDaliPropertyConditionGetArguments");
737 PropertyCondition condition = GreaterThanCondition( 50.0f );
739 DALI_TEST_EQUALS( condition.GetArgumentCount(), 1u, TEST_LOCATION );
740 float value = condition.GetArgument( 0 );
741 DALI_TEST_EQUALS( value, 50.0f, TEST_LOCATION );
743 condition = InsideCondition( 125.0f, 250.0f );
745 DALI_TEST_EQUALS( condition.GetArgumentCount(), 2u, TEST_LOCATION );
746 float value1 = condition.GetArgument( 0 );
747 float value2 = condition.GetArgument( 1 );
748 DALI_TEST_EQUALS( value1, 125.0f, TEST_LOCATION );
749 DALI_TEST_EQUALS( value2, 250.0f, TEST_LOCATION );
753 int UtcDaliPropertyNotificationStep(void)
755 TestApplication application;
756 tet_infoline(" UtcDaliPropertyNotificationStep");
758 Actor actor = Actor::New();
759 Stage::GetCurrent().Add(actor);
761 const float step = 100.0f;
763 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, StepCondition(step, 50.0f) );
764 notification.NotifySignal().Connect( &TestCallback );
766 // set initial position
767 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
768 Wait(application, DEFAULT_WAIT_PERIOD);
770 // test both directions
771 for( int i = 1 ; i < 10 ; ++i )
773 // Move x to negative position
774 gCallBackCalled = false;
775 actor.SetPosition(Vector3((i * step), 0.0f, 0.0f));
776 Wait(application, DEFAULT_WAIT_PERIOD);
777 DALI_TEST_CHECK( gCallBackCalled );
780 for( int i = 1 ; i < 10 ; ++i )
782 // Move x to negative position
783 gCallBackCalled = false;
784 actor.SetPosition(Vector3(-(i * step), 0.0f, 0.0f));
785 Wait(application, DEFAULT_WAIT_PERIOD);
786 DALI_TEST_CHECK( gCallBackCalled );
791 int UtcDaliPropertyNotificationVariableStep(void)
793 TestApplication application;
794 tet_infoline(" UtcDaliPropertyNotificationStep");
796 Actor actor = Actor::New();
797 Stage::GetCurrent().Add(actor);
799 Dali::Vector<float> values;
801 const float averageStep = 100.0f;
803 for( int i = 1 ; i < 10 ; i++ )
805 values.PushBack(i * averageStep + (i % 2 == 0 ? -(averageStep * 0.2f) : (averageStep * 0.2f)));
808 PropertyNotification notification = actor.AddPropertyNotification( Actor::Property::POSITION, 0, VariableStepCondition(values) );
809 notification.NotifySignal().Connect( &TestCallback );
811 // set initial position lower than first position in list
812 actor.SetPosition(Vector3(values[0] - averageStep, 0.0f, 0.0f));
813 Wait(application, DEFAULT_WAIT_PERIOD);
815 for( unsigned int i = 0 ; i < values.Count() - 1 ; ++i )
817 gCallBackCalled = false;
818 // set position half way between the current values
819 float position = values[i] + (0.5f * (values[i + 1] - values[i]));
820 actor.SetPosition(Vector3(position, 0.0f, 0.0f));
821 Wait(application, DEFAULT_WAIT_PERIOD);
822 DALI_TEST_CHECK( gCallBackCalled );
827 static bool gCallBack2Called = false;
828 void TestCallback2(PropertyNotification& source)
830 gCallBack2Called = true;
833 int UtcDaliPropertyNotificationOrder(void)
835 TestApplication application; // Reset all test adapter return codes
837 Actor actor = Actor::New();
838 Stage::GetCurrent().Add(actor);
839 // this should complete in first frame
840 PropertyNotification notification1 = actor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(90.0f) );
841 notification1.NotifySignal().Connect( &TestCallback );
842 // this should complete in second frame
843 PropertyNotification notification2 = actor.AddPropertyNotification( Actor::Property::POSITION_X, GreaterThanCondition(150.0f) );
844 notification2.NotifySignal().Connect( &TestCallback2 );
845 Animation animation = Animation::New( 0.032f ); // finishes in 32 ms
846 animation.AnimateTo( Property(actor, Actor::Property::POSITION ), Vector3( 200.0f, 0.0f, 0.0f ), AlphaFunction::LINEAR );
850 application.SendNotification();
852 application.Render(RENDER_FRAME_INTERVAL);
853 // no notifications yet
854 DALI_TEST_EQUALS( gCallBackCalled, false, TEST_LOCATION );
855 DALI_TEST_EQUALS( gCallBack2Called, false, TEST_LOCATION );
856 gCallBackCalled = false;
857 gCallBack2Called = false;
859 // dont serve the notifications but run another update & render
860 // this simulates situation where there is a notification in event side but it's not been picked up by event thread
862 application.Render(RENDER_FRAME_INTERVAL);
863 DALI_TEST_EQUALS( gCallBackCalled, false, TEST_LOCATION );
864 DALI_TEST_EQUALS( gCallBack2Called, false, TEST_LOCATION );
866 // serve the notifications
867 application.SendNotification();
868 DALI_TEST_EQUALS( gCallBackCalled, true, TEST_LOCATION );
869 DALI_TEST_EQUALS( gCallBack2Called, true, TEST_LOCATION );
871 gCallBackCalled = false;
872 gCallBack2Called = false;
873 application.Render(RENDER_FRAME_INTERVAL);
874 application.SendNotification();
875 DALI_TEST_EQUALS( gCallBackCalled, false, TEST_LOCATION );
876 DALI_TEST_EQUALS( gCallBack2Called, false, TEST_LOCATION );