2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
21 #include <boost/bind.hpp>
23 #include <dali/public-api/dali-core.h>
25 #include <dali-test-suite-utils.h>
29 static void Startup();
30 static void Cleanup();
34 static bool gCallBackCalled;
36 static void TestCallback(PropertyNotification& source)
38 gCallBackCalled = true;
41 const int RENDER_FRAME_INTERVAL(16); ///< Duration of each frame in ms. (at approx 60FPS)
42 const int DEFAULT_WAIT_PERIOD(100); ///< Default waiting period for check.
44 } // unnamed namespace
47 void (*tet_startup)() = Startup;
48 void (*tet_cleanup)() = Cleanup;
52 POSITIVE_TC_IDX = 0x01,
56 #define MAX_NUMBER_OF_TESTS 10000
58 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
61 // Add test functionality for all APIs in the class (Positive and Negative)
62 TEST_FUNCTION( UtcDaliPropertyNotificationDownCast, POSITIVE_TC_IDX );
63 TEST_FUNCTION( UtcDaliPropertyNotificationDownCastNegative, POSITIVE_TC_IDX );
64 TEST_FUNCTION( UtcDaliAddPropertyNotification, POSITIVE_TC_IDX );
65 TEST_FUNCTION( UtcDaliAddPropertyNotificationCallback, POSITIVE_TC_IDX );
66 TEST_FUNCTION( UtcDaliAddPropertyNotificationTypeProperty, NEGATIVE_TC_IDX );
67 TEST_FUNCTION( UtcDaliPropertyNotificationGetCondition, POSITIVE_TC_IDX );
68 TEST_FUNCTION( UtcDaliPropertyNotificationGetConditionConst, POSITIVE_TC_IDX );
69 TEST_FUNCTION( UtcDaliPropertyNotificationGetTarget, POSITIVE_TC_IDX );
70 TEST_FUNCTION( UtcDaliPropertyNotificationGetProperty, POSITIVE_TC_IDX );
71 TEST_FUNCTION( UtcDaliPropertyNotificationGetNotifyMode, POSITIVE_TC_IDX );
72 TEST_FUNCTION( UtcDaliPropertyNotificationGreaterThan, POSITIVE_TC_IDX );
73 TEST_FUNCTION( UtcDaliPropertyNotificationLessThan, POSITIVE_TC_IDX );
74 TEST_FUNCTION( UtcDaliPropertyNotificationInside, POSITIVE_TC_IDX );
75 TEST_FUNCTION( UtcDaliPropertyNotificationOutside, POSITIVE_TC_IDX );
76 TEST_FUNCTION( UtcDaliPropertyNotificationVectorComponentGreaterThan, POSITIVE_TC_IDX );
77 TEST_FUNCTION( UtcDaliPropertyNotificationVectorComponentLessThan, POSITIVE_TC_IDX );
78 TEST_FUNCTION( UtcDaliPropertyNotificationVectorComponentInside, POSITIVE_TC_IDX );
79 TEST_FUNCTION( UtcDaliPropertyNotificationVectorComponentOutside, POSITIVE_TC_IDX );
80 TEST_FUNCTION( UtcDaliPropertyConditionGetArguments, POSITIVE_TC_IDX );
81 TEST_FUNCTION( UtcDaliPropertyConditionGetArgumentsConst, POSITIVE_TC_IDX );
82 TEST_FUNCTION( UtcDaliPropertyNotificationStep, POSITIVE_TC_IDX );
83 TEST_FUNCTION( UtcDaliPropertyNotificationVariableStep, POSITIVE_TC_IDX );
85 class TestClass : public ConnectionTracker
99 mActor = Actor::New();
100 Stage::GetCurrent().Add( mActor );
101 mNotification = mActor.AddPropertyNotification( Actor::POSITION_X, GreaterThanCondition(100.0f) );
102 mNotification.NotifySignal().Connect( this, &TestClass::OnPropertyNotify );
105 void RemovePropertyNotification()
107 mActor.RemovePropertyNotification( mNotification );
110 void RemovePropertyNotifications()
112 mActor.RemovePropertyNotifications();
117 Stage::GetCurrent().Remove( mActor );
119 mNotification.Reset();
122 void OnPropertyNotify( PropertyNotification& source )
124 tet_infoline(" OnPropertyNotify");
125 gCallBackCalled = true;
129 PropertyNotification mNotification;
134 * Simulate time passed by.
136 * @note this will always process at least 1 frame (1/60 sec)
138 * @param application Test application instance
139 * @param duration Time to pass in milliseconds.
140 * @return The actual time passed in milliseconds
142 int Wait(TestApplication& application, int duration = 0)
146 for(int i = 0; i <= ( duration / RENDER_FRAME_INTERVAL); i++)
148 application.SendNotification();
149 application.Render(RENDER_FRAME_INTERVAL);
150 time += RENDER_FRAME_INTERVAL;
156 // Called only once before first test is run.
157 static void Startup()
161 // Called only once after last test is run
162 static void Cleanup()
166 // Positive test case for a method
167 static void UtcDaliPropertyNotificationDownCast()
169 TestApplication application;
170 tet_infoline(" UtcDaliPropertyNotificationDownCast");
172 Actor actor = Actor::New();
173 PropertyNotification notification = actor.AddPropertyNotification(Actor::POSITION_X, GreaterThanCondition(100.0f));
174 BaseHandle handle = notification;
175 PropertyNotification notificationHandle;
177 DALI_TEST_CHECK(notification);
178 DALI_TEST_CHECK(handle);
179 DALI_TEST_CHECK(!notificationHandle);
181 notificationHandle = PropertyNotification::DownCast( handle );
182 DALI_TEST_CHECK(notificationHandle);
186 // Negative test case for a method
187 static void UtcDaliPropertyNotificationDownCastNegative()
189 TestApplication application;
190 tet_infoline(" UtcDaliPropertyNotificationDownCastNegative");
192 // Create something derived from BaseHandle other than a PropertyNotification.
193 Actor somethingElse = Actor::New();
195 Actor actor = Actor::New();
196 actor.AddPropertyNotification(Actor::POSITION_X, GreaterThanCondition(100.0f));
197 BaseHandle handle = somethingElse;
198 PropertyNotification notificationHandle;
200 notificationHandle = PropertyNotification::DownCast( handle );
201 DALI_TEST_CHECK(!notificationHandle);
204 static void UtcDaliAddPropertyNotification()
206 TestApplication application; // Reset all test adapter return codes
207 tet_infoline(" UtcDaliAddPropertyNotification");
209 Actor actor = Actor::New();
211 PropertyNotification notification = actor.AddPropertyNotification(Actor::POSITION_X, GreaterThanCondition(100.0f));
212 DALI_TEST_CHECK( notification );
215 static void UtcDaliAddPropertyNotificationCallback()
217 TestApplication application; // Reset all test adapter return codes
219 TestClass* object = new TestClass;
221 object->Initialize();
222 application.Render(RENDER_FRAME_INTERVAL);
223 application.SendNotification();
225 gCallBackCalled = false;
227 tet_infoline(" UtcDaliAddPropertyNotificationCallback - Forcing notification condition true, should receive a notification");
228 object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
229 application.Render(RENDER_FRAME_INTERVAL);
230 application.SendNotification();
231 application.Render(RENDER_FRAME_INTERVAL);
232 application.SendNotification();
233 DALI_TEST_CHECK( gCallBackCalled );
234 gCallBackCalled = false;
236 tet_infoline(" UtcDaliAddPropertyNotificationCallback - Forcing notification condition false, should not receive a notification");
237 object->mActor.SetPosition(Vector3(0.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 );
243 gCallBackCalled = false;
245 tet_infoline(" UtcDaliAddPropertyNotificationCallback - Deleting notification and it's owning object, should not receive a notification");
246 object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
247 application.Render(RENDER_FRAME_INTERVAL);
248 application.SendNotification();
250 application.Render(RENDER_FRAME_INTERVAL);
251 application.SendNotification();
252 DALI_TEST_CHECK( !gCallBackCalled );
254 tet_infoline(" UtcDaliAddPropertyNotificationCallback - Removing notification and it's owning object, should not receive a notification");
255 object->Initialize();
256 application.Render(RENDER_FRAME_INTERVAL);
257 application.SendNotification();
258 gCallBackCalled = false;
260 object->RemovePropertyNotification();
262 object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
263 application.Render(RENDER_FRAME_INTERVAL);
264 application.SendNotification();
265 application.Render(RENDER_FRAME_INTERVAL);
266 application.SendNotification();
267 DALI_TEST_CHECK( !gCallBackCalled );
269 tet_infoline(" UtcDaliAddPropertyNotificationCallback - Removing all notifications and it's owning object, should not receive a notification");
270 object->Initialize();
271 application.Render(RENDER_FRAME_INTERVAL);
272 application.SendNotification();
273 gCallBackCalled = false;
275 object->RemovePropertyNotifications();
277 object->mActor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
278 application.Render(RENDER_FRAME_INTERVAL);
279 application.SendNotification();
280 application.Render(RENDER_FRAME_INTERVAL);
281 application.SendNotification();
282 DALI_TEST_CHECK( !gCallBackCalled );
288 void UtcDaliAddPropertyNotificationTypeProperty()
290 TestApplication application;
292 Actor actor = Actor::New();
294 // Currently, Type registry properties cannot be animated
297 actor.AddPropertyNotification( PROPERTY_REGISTRATION_START_INDEX, GreaterThanCondition( 100.0f ) );
299 catch ( DaliException& e )
301 DALI_TEST_ASSERT_CONDITION_STARTS_WITH_SUBSTRING( e, "false && \"Property notification added to non animatable property", TEST_LOCATION );
305 static void UtcDaliPropertyNotificationGetCondition()
307 TestApplication application;
308 tet_infoline(" UtcDaliPropertyNotificationGetCondition");
310 Actor actor = Actor::New();
312 PropertyCondition condition = GreaterThanCondition(100.0f);
313 PropertyNotification notification = actor.AddPropertyNotification(Actor::POSITION_X, condition);
314 DALI_TEST_CHECK( condition == notification.GetCondition() );
317 class PropertyNotificationConstWrapper
321 PropertyNotificationConstWrapper(PropertyNotification propertyNotification)
322 :mPropertyNotification(propertyNotification)
328 * Returns const reference to property notification.
329 * @return const reference.
331 const PropertyCondition& GetCondition() const
333 return mPropertyNotification.GetCondition();
336 PropertyNotification mPropertyNotification;
339 static void UtcDaliPropertyNotificationGetConditionConst()
341 TestApplication application;
342 tet_infoline(" UtcDaliPropertyNotificationGetConditionConst");
344 Actor actor = Actor::New();
346 PropertyCondition condition = GreaterThanCondition(100.0f);
347 PropertyNotification notification = actor.AddPropertyNotification(Actor::POSITION_X, condition);
348 PropertyNotificationConstWrapper notificationConst(notification);
349 const PropertyCondition& conditionReference1 = notificationConst.GetCondition();
350 const PropertyCondition& conditionReference2 = notificationConst.GetCondition();
352 DALI_TEST_CHECK( (&conditionReference1) == (&conditionReference2) );
353 DALI_TEST_CHECK( conditionReference1 == condition );
356 static void UtcDaliPropertyNotificationGetTarget()
358 TestApplication application;
359 tet_infoline(" UtcDaliPropertyNotificationGetTarget");
361 Actor actor = Actor::New();
362 Actor actor2 = Actor::New();
364 PropertyNotification notification = actor.AddPropertyNotification(Actor::POSITION_X,
365 GreaterThanCondition(100.0f));
366 Actor targetActor = Actor::DownCast( notification.GetTarget() );
368 DALI_TEST_CHECK( targetActor == actor );
371 static void UtcDaliPropertyNotificationGetProperty()
373 TestApplication application;
374 tet_infoline(" UtcDaliPropertyNotificationGetProperty");
376 Actor actor = Actor::New();
378 PropertyNotification notification = actor.AddPropertyNotification(Actor::POSITION_X,
379 GreaterThanCondition(100.0f));
380 Property::Index targetProperty = notification.GetTargetProperty();
382 DALI_TEST_EQUALS( targetProperty, Actor::POSITION_X, TEST_LOCATION );
385 static void UtcDaliPropertyNotificationGetNotifyMode()
387 TestApplication application;
388 tet_infoline(" UtcDaliPropertyNotificationGetNotifyMode");
390 Actor actor = Actor::New();
392 PropertyNotification notification = actor.AddPropertyNotification(Actor::POSITION_X,
393 GreaterThanCondition(100.0f));
394 notification.SetNotifyMode(PropertyNotification::NotifyOnChanged);
395 PropertyNotification::NotifyMode notifyMode = notification.GetNotifyMode();
397 DALI_TEST_EQUALS( notifyMode, PropertyNotification::NotifyOnChanged, TEST_LOCATION );
400 static void UtcDaliPropertyNotificationGreaterThan()
402 TestApplication application;
403 tet_infoline(" UtcDaliPropertyNotificationGreaterThan");
405 Actor actor = Actor::New();
406 Stage::GetCurrent().Add(actor);
408 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION_X, GreaterThanCondition(100.0f) );
409 notification.NotifySignal().Connect( &TestCallback );
411 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
412 Wait(application, DEFAULT_WAIT_PERIOD);
414 // Move right to satisfy condition
415 gCallBackCalled = false;
416 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
417 Wait(application, DEFAULT_WAIT_PERIOD);
418 DALI_TEST_CHECK( gCallBackCalled );
420 // Move left to un-satisfy condition
421 gCallBackCalled = false;
422 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
423 Wait(application, DEFAULT_WAIT_PERIOD);
424 DALI_TEST_CHECK( !gCallBackCalled );
426 // Move right to satisfy condition again.
427 gCallBackCalled = false;
428 Wait(application, DEFAULT_WAIT_PERIOD);
429 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
430 Wait(application, DEFAULT_WAIT_PERIOD);
431 DALI_TEST_CHECK( gCallBackCalled );
434 static void UtcDaliPropertyNotificationLessThan()
436 TestApplication application;
437 tet_infoline(" UtcDaliPropertyNotificationLessThan");
439 Actor actor = Actor::New();
440 Stage::GetCurrent().Add(actor);
442 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION_X, LessThanCondition(100.0f ) );
443 notification.NotifySignal().Connect( &TestCallback );
445 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
446 Wait(application, DEFAULT_WAIT_PERIOD);
448 // Move left to satisfy condition
449 gCallBackCalled = false;
450 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
451 Wait(application, DEFAULT_WAIT_PERIOD);
452 DALI_TEST_CHECK( gCallBackCalled );
454 // Move right to un-satisfy condition
455 gCallBackCalled = false;
456 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
457 Wait(application, DEFAULT_WAIT_PERIOD);
458 DALI_TEST_CHECK( !gCallBackCalled );
460 // Move left to satisfy condition again.
461 gCallBackCalled = false;
462 Wait(application, DEFAULT_WAIT_PERIOD);
463 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
464 Wait(application, DEFAULT_WAIT_PERIOD);
465 DALI_TEST_CHECK( gCallBackCalled );
468 static void UtcDaliPropertyNotificationInside()
470 TestApplication application;
471 tet_infoline(" UtcDaliPropertyNotificationInside");
473 Actor actor = Actor::New();
474 Stage::GetCurrent().Add(actor);
476 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION_X, InsideCondition(100.0f, 200.0f) );
477 notification.NotifySignal().Connect( &TestCallback );
479 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
480 Wait(application, DEFAULT_WAIT_PERIOD);
482 // Move inside to satisfy condition
483 gCallBackCalled = false;
484 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
485 Wait(application, DEFAULT_WAIT_PERIOD);
486 DALI_TEST_CHECK( gCallBackCalled );
488 // Move outside (right) to un-satisfy condition
489 gCallBackCalled = false;
490 actor.SetPosition(Vector3(300.0f, 0.0f, 0.0f));
491 Wait(application, DEFAULT_WAIT_PERIOD);
492 DALI_TEST_CHECK( !gCallBackCalled );
494 // Move inside to satisfy condition again.
495 gCallBackCalled = false;
496 Wait(application, DEFAULT_WAIT_PERIOD);
497 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
498 Wait(application, DEFAULT_WAIT_PERIOD);
499 DALI_TEST_CHECK( gCallBackCalled );
502 static void UtcDaliPropertyNotificationOutside()
504 TestApplication application;
505 tet_infoline(" UtcDaliPropertyNotificationOutside");
507 Actor actor = Actor::New();
508 Stage::GetCurrent().Add(actor);
510 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION_X, OutsideCondition(100.0f, 200.0f) );
511 notification.NotifySignal().Connect( &TestCallback );
513 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
514 Wait(application, DEFAULT_WAIT_PERIOD);
516 // Move outside (left) to satisfy condition
517 gCallBackCalled = false;
518 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
519 Wait(application, DEFAULT_WAIT_PERIOD);
520 DALI_TEST_CHECK( gCallBackCalled );
522 // Move inside to un-satisfy condition
523 gCallBackCalled = false;
524 actor.SetPosition(Vector3(150.0f, 0.0f, 0.0f));
525 Wait(application, DEFAULT_WAIT_PERIOD);
526 DALI_TEST_CHECK( !gCallBackCalled );
528 // Move outside (right) to satisfy condition again.
529 gCallBackCalled = false;
530 Wait(application, DEFAULT_WAIT_PERIOD);
531 actor.SetPosition(Vector3(300.0f, 0.0f, 0.0f));
532 Wait(application, DEFAULT_WAIT_PERIOD);
533 DALI_TEST_CHECK( gCallBackCalled );
536 static void UtcDaliPropertyNotificationVectorComponentGreaterThan()
538 TestApplication application;
539 tet_infoline(" UtcDaliPropertyNotificationGreaterThan");
541 Actor actor = Actor::New();
542 Stage::GetCurrent().Add(actor);
544 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION, 0, GreaterThanCondition(100.0f) );
545 notification.NotifySignal().Connect( &TestCallback );
546 notification = actor.AddPropertyNotification( Actor::POSITION, 1, GreaterThanCondition(100.0f) );
547 notification.NotifySignal().Connect( &TestCallback );
548 notification = actor.AddPropertyNotification( Actor::POSITION, 2, GreaterThanCondition(100.0f) );
549 notification.NotifySignal().Connect( &TestCallback );
550 notification = actor.AddPropertyNotification( Actor::COLOR, 3, GreaterThanCondition(0.5f) );
551 notification.NotifySignal().Connect( &TestCallback );
553 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
554 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
555 Wait(application, DEFAULT_WAIT_PERIOD);
557 // Move right to satisfy XAxis condition
558 gCallBackCalled = false;
559 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
560 Wait(application, DEFAULT_WAIT_PERIOD);
561 DALI_TEST_CHECK( gCallBackCalled );
563 // Move down to satisfy YAxis condition
564 gCallBackCalled = false;
565 actor.SetPosition(Vector3(200.0f, 200.0f, 0.0f));
566 Wait(application, DEFAULT_WAIT_PERIOD);
567 DALI_TEST_CHECK( gCallBackCalled );
569 // Move forward to satisfy ZAxis
570 gCallBackCalled = false;
571 Wait(application, DEFAULT_WAIT_PERIOD);
572 actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
573 Wait(application, DEFAULT_WAIT_PERIOD);
574 DALI_TEST_CHECK( gCallBackCalled );
576 // Change alpha Colour to satisfy w/alpha component condition
577 gCallBackCalled = false;
578 Wait(application, DEFAULT_WAIT_PERIOD);
579 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
580 Wait(application, DEFAULT_WAIT_PERIOD);
581 DALI_TEST_CHECK( gCallBackCalled );
584 static void UtcDaliPropertyNotificationVectorComponentLessThan()
586 TestApplication application;
587 tet_infoline(" UtcDaliPropertyNotificationLessThan");
589 Actor actor = Actor::New();
590 Stage::GetCurrent().Add(actor);
592 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION, 0, LessThanCondition(-100.0f) );
593 notification.NotifySignal().Connect( &TestCallback );
594 notification = actor.AddPropertyNotification( Actor::POSITION, 1, LessThanCondition(-100.0f) );
595 notification.NotifySignal().Connect( &TestCallback );
596 notification = actor.AddPropertyNotification( Actor::POSITION, 2, LessThanCondition(-100.0f) );
597 notification.NotifySignal().Connect( &TestCallback );
598 notification = actor.AddPropertyNotification( Actor::COLOR, 3, LessThanCondition(0.5f) );
599 notification.NotifySignal().Connect( &TestCallback );
601 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
602 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
603 Wait(application, DEFAULT_WAIT_PERIOD);
605 // Move left to satisfy XAxis condition
606 gCallBackCalled = false;
607 actor.SetPosition(Vector3(-200.0f, 0.0f, 0.0f));
608 Wait(application, DEFAULT_WAIT_PERIOD);
609 DALI_TEST_CHECK( gCallBackCalled );
611 // Move up to satisfy YAxis condition
612 gCallBackCalled = false;
613 actor.SetPosition(Vector3(-200.0f, -200.0f, 0.0f));
614 Wait(application, DEFAULT_WAIT_PERIOD);
615 DALI_TEST_CHECK( gCallBackCalled );
617 // Move back to satisfy ZAxis
618 gCallBackCalled = false;
619 Wait(application, DEFAULT_WAIT_PERIOD);
620 actor.SetPosition(Vector3(-200.0f, -200.0f, -200.0f));
621 Wait(application, DEFAULT_WAIT_PERIOD);
622 DALI_TEST_CHECK( gCallBackCalled );
624 // Change alpha Colour to satisfy w/alpha component condition
625 gCallBackCalled = false;
626 Wait(application, DEFAULT_WAIT_PERIOD);
627 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
628 Wait(application, DEFAULT_WAIT_PERIOD);
629 DALI_TEST_CHECK( gCallBackCalled );
632 static void UtcDaliPropertyNotificationVectorComponentInside()
634 TestApplication application;
635 tet_infoline(" UtcDaliPropertyNotificationInside");
637 Actor actor = Actor::New();
638 Stage::GetCurrent().Add(actor);
640 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION, 0, InsideCondition(-100.0f, 100.0f) );
641 notification.NotifySignal().Connect( &TestCallback );
642 notification = actor.AddPropertyNotification( Actor::POSITION, 1, InsideCondition(-100.0f, 100.0f) );
643 notification.NotifySignal().Connect( &TestCallback );
644 notification = actor.AddPropertyNotification( Actor::POSITION, 2, InsideCondition(-100.0f, 100.0f) );
645 notification.NotifySignal().Connect( &TestCallback );
646 notification = actor.AddPropertyNotification( Actor::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 );
681 static void UtcDaliPropertyNotificationVectorComponentOutside()
683 TestApplication application;
684 tet_infoline(" UtcDaliPropertyNotificationOutside");
686 Actor actor = Actor::New();
687 Stage::GetCurrent().Add(actor);
689 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION, 0, OutsideCondition(-100.0f, 100.0f) );
690 notification.NotifySignal().Connect( &TestCallback );
691 notification = actor.AddPropertyNotification( Actor::POSITION, 1, OutsideCondition(-100.0f, 100.0f) );
692 notification.NotifySignal().Connect( &TestCallback );
693 notification = actor.AddPropertyNotification( Actor::POSITION, 2, OutsideCondition(-100.0f, 100.0f) );
694 notification.NotifySignal().Connect( &TestCallback );
695 notification = actor.AddPropertyNotification( Actor::COLOR, 3, OutsideCondition(0.25f, 0.75f) );
696 notification.NotifySignal().Connect( &TestCallback );
698 // set inside all conditions
699 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
700 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 0.5f));
701 Wait(application, DEFAULT_WAIT_PERIOD);
703 // Move x to outside condition
704 gCallBackCalled = false;
705 actor.SetPosition(Vector3(200.0f, 0.0f, 0.0f));
706 Wait(application, DEFAULT_WAIT_PERIOD);
707 DALI_TEST_CHECK( gCallBackCalled );
709 // Move y to outside condition
710 gCallBackCalled = false;
711 actor.SetPosition(Vector3(200.0f, 200.0f, 0.0f));
712 Wait(application, DEFAULT_WAIT_PERIOD);
713 DALI_TEST_CHECK( gCallBackCalled );
715 // Move z to outside condition
716 gCallBackCalled = false;
717 Wait(application, DEFAULT_WAIT_PERIOD);
718 actor.SetPosition(Vector3(200.0f, 200.0f, 200.0f));
719 Wait(application, DEFAULT_WAIT_PERIOD);
720 DALI_TEST_CHECK( gCallBackCalled );
722 // change alpha to outside condition
723 gCallBackCalled = false;
724 Wait(application, DEFAULT_WAIT_PERIOD);
725 actor.SetColor(Vector4(0.0f, 0.0f, 0.0f, 1.0f));
726 Wait(application, DEFAULT_WAIT_PERIOD);
727 DALI_TEST_CHECK( gCallBackCalled );
730 static void UtcDaliPropertyConditionGetArguments()
732 TestApplication application;
733 tet_infoline(" UtcDaliPropertyConditionGetArguments");
735 PropertyCondition condition = GreaterThanCondition( 50.0f );
736 PropertyCondition::ArgumentContainer arguments = condition.GetArguments();
738 DALI_TEST_EQUALS( arguments.size(), 1u, TEST_LOCATION );
739 Property::Value value = arguments[0];
740 DALI_TEST_EQUALS( value.Get<float>(), 50.0f, TEST_LOCATION );
742 condition = InsideCondition( 125.0f, 250.0f );
743 arguments = condition.GetArguments();
745 DALI_TEST_EQUALS( arguments.size(), 2u, TEST_LOCATION );
746 Property::Value value1 = arguments[0];
747 Property::Value value2 = arguments[1];
748 DALI_TEST_EQUALS( value1.Get<float>(), 125.0f, TEST_LOCATION );
749 DALI_TEST_EQUALS( value2.Get<float>(), 250.0f, TEST_LOCATION );
752 class PropertyConditionConstWrapper
756 PropertyConditionConstWrapper(PropertyCondition propertyCondition)
757 :mPropertyCondition(propertyCondition)
763 * Returns const reference to property arguments.
764 * @return const reference.
766 const PropertyCondition::ArgumentContainer& GetArguments() const
768 return mPropertyCondition.GetArguments();
771 PropertyCondition mPropertyCondition;
774 static void UtcDaliPropertyConditionGetArgumentsConst()
776 TestApplication application;
777 tet_infoline(" UtcDaliPropertyConditionGetArgumentsConst");
779 PropertyCondition condition = GreaterThanCondition( 50.0f );
780 PropertyConditionConstWrapper conditionConst(condition);
781 const PropertyCondition::ArgumentContainer& argumentsRef1 = conditionConst.GetArguments();
782 const PropertyCondition::ArgumentContainer& argumentsRef2 = conditionConst.GetArguments();
784 DALI_TEST_CHECK( (&argumentsRef1) == (&argumentsRef2) );
785 DALI_TEST_EQUALS( argumentsRef1.size(), 1u, TEST_LOCATION );
786 Property::Value value = argumentsRef1[0];
787 DALI_TEST_EQUALS( value.Get<float>(), 50.0f, TEST_LOCATION );
790 static void UtcDaliPropertyNotificationStep()
792 TestApplication application;
793 tet_infoline(" UtcDaliPropertyNotificationStep");
795 Actor actor = Actor::New();
796 Stage::GetCurrent().Add(actor);
798 const float step = 100.0f;
800 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION, 0, StepCondition(step, 50.0f) );
801 notification.NotifySignal().Connect( &TestCallback );
803 // set initial position
804 actor.SetPosition(Vector3(0.0f, 0.0f, 0.0f));
805 Wait(application, DEFAULT_WAIT_PERIOD);
807 // test both directions
808 for( int i = 1 ; i < 10 ; ++i )
810 // Move x to negative position
811 gCallBackCalled = false;
812 actor.SetPosition(Vector3((i * step), 0.0f, 0.0f));
813 Wait(application, DEFAULT_WAIT_PERIOD);
814 DALI_TEST_CHECK( gCallBackCalled );
817 for( int i = 1 ; i < 10 ; ++i )
819 // Move x to negative position
820 gCallBackCalled = false;
821 actor.SetPosition(Vector3(-(i * step), 0.0f, 0.0f));
822 Wait(application, DEFAULT_WAIT_PERIOD);
823 DALI_TEST_CHECK( gCallBackCalled );
827 static void UtcDaliPropertyNotificationVariableStep()
829 TestApplication application;
830 tet_infoline(" UtcDaliPropertyNotificationStep");
832 Actor actor = Actor::New();
833 Stage::GetCurrent().Add(actor);
835 std::vector<float> values;
837 const float averageStep = 100.0f;
839 for( int i = 1 ; i < 10 ; i++ )
841 values.push_back(i * averageStep + (i % 2 == 0 ? -(averageStep * 0.2f) : (averageStep * 0.2f)));
844 PropertyNotification notification = actor.AddPropertyNotification( Actor::POSITION, 0, VariableStepCondition(values) );
845 notification.NotifySignal().Connect( &TestCallback );
847 // set initial position lower than first position in list
848 actor.SetPosition(Vector3(values[0] - averageStep, 0.0f, 0.0f));
849 Wait(application, DEFAULT_WAIT_PERIOD);
851 for( int i = 0 ; i < values.size() - 1 ; ++i )
853 gCallBackCalled = false;
854 // set position half way between the current values
855 float position = values[i] + (0.5f * (values[i + 1] - values[i]));
856 actor.SetPosition(Vector3(position, 0.0f, 0.0f));
857 Wait(application, DEFAULT_WAIT_PERIOD);
858 DALI_TEST_CHECK( gCallBackCalled );