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.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/devel-api/builder/builder.h>
22 #include <dali/integration-api/events/touch-event-integ.h>
24 #define STRINGIFY(A)#A
27 using namespace Toolkit;
32 std::string ReplaceQuotes(const std::string &in_s)
35 // wrong as no embedded quote but had regex link problems
36 std::replace(s.begin(), s.end(), '\'', '"');
42 BuilderFunctor( bool& called ) : mCalled( called )
59 void builder_startup(void)
61 test_return_value = TET_UNDEF;
64 void builder_cleanup(void)
66 test_return_value = TET_PASS;
69 int UtcDaliBuilderQuitSignal(void)
71 ToolkitTestApplication application;
73 // JSON with a quit event when the actor is touched
78 "\"type\": \"Actor\","
79 "\"size\": [100,100,1],"
80 "\"parent-origin\": \"TOP_LEFT\","
81 "\"anchor-point\": \"TOP_LEFT\","
83 "\"name\": \"touched\","
84 "\"action\": \"quit\""
89 Builder builder = Builder::New();
90 builder.LoadFromString( json );
91 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
93 // Connect to builder's quit signal
94 bool functorCalled( false );
95 builder.QuitSignal().Connect( &application, BuilderFunctor( functorCalled ) );
98 application.SendNotification();
101 // Emit touch event and check that our quit method is called
102 Integration::TouchEvent touchEvent;
103 touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
104 application.ProcessEvent( touchEvent );
105 DALI_TEST_CHECK( functorCalled );
111 int UtcDaliBuilderAnimationP(void)
113 ToolkitTestApplication application;
115 // JSON with a quit event when the actor is touched
122 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],"
123 " \"curvature\":0.35"
129 " \"end-action\": \"BAKE\","
130 " \"disconnect-action\": \"BAKE\","
133 " \"actor\": \"greeting\","
134 " \"property\": \"position\","
135 " \"value\": [300, 300, -1000],"
136 " \"alpha-function\": \"EASE_IN_OUT\","
137 " \"relative\": true,"
138 " \"time-period\": {"
144 " \"actor\": \"greeting\","
145 " \"property\": \"visible\","
146 " \"alpha-function\": \"LINEAR\","
150 " \"actor\": \"greeting\","
151 " \"property\": \"size-width\","
152 " \"alpha-function\": \"REVERSE\","
156 " \"actor\": \"greeting\","
157 " \"property\": \"orientation\","
158 " \"alpha-function\": \"EASE_IN\","
159 " \"value\": [10.0,20.0,30.0]"
162 " \"actor\": \"greeting\","
163 " \"property\": \"orientation\","
164 " \"alpha-function\": \"EASE_OUT\","
165 " \"value\": [0.0, 0.0, 0.0, 1.0]"
168 " \"actor\": \"greeting\","
169 " \"property\": \"orientation\","
170 " \"alpha-function\": \"EASE_IN_OUT\","
171 " \"value\": [0.0, 0.0, 0.0, 1.0]"
174 " \"actor\": \"greeting\","
175 " \"property\": \"orientation\","
176 " \"alpha-function\": \"EASE_IN_SINE\","
177 " \"value\": [0.0, 0.0, 0.0, 1.0]"
180 " \"actor\": \"greeting\","
181 " \"property\": \"orientation\","
182 " \"alpha-function\": \"EASE_OUT_SINE\","
183 " \"value\": [0.0, 0.0, 0.0, 1.0]"
186 " \"actor\": \"greeting\","
187 " \"property\": \"orientation\","
188 " \"alpha-function\": \"EASE_IN_OUT_SINE\","
189 " \"value\": [0.0, 0.0, 0.0, 1.0]"
192 " \"actor\": \"greeting\","
193 " \"property\": \"orientation\","
194 " \"alpha-function\": \"BOUNCE\","
195 " \"value\": [0.0, 0.0, 0.0, 1.0]"
198 " \"actor\": \"greeting\","
199 " \"property\": \"orientation\","
200 " \"alpha-function\": \"SIN\","
201 " \"value\": [0.0, 0.0, 0.0, 1.0]"
204 " \"actor\": \"greeting\","
205 " \"property\": \"orientation\","
206 " \"alpha-function\": \"EASE_OUT_BACK\","
207 " \"value\": [0.0, 0.0, 0.0, 1.0]"
211 " \"path-animation\": {"
212 " \"duration\": 3.0,"
213 " \"end-action\": \"DISCARD\","
214 " \"disconnect-action\": \"BAKE_FINAL\","
215 " \"properties\": [{"
216 " \"actor\": \"greeting\","
217 " \"path\":\"path0\","
218 " \"forward\":[1,0,0],"
219 " \"alpha-function\": \"EASE_IN_OUT\","
220 " \"time-period\": {"
228 " \"name\": \"greeting\","
229 " \"type\": \"TextLabel\","
230 " \"text\": \"Touch me\","
231 " \"styles\": [\"basic-text\"],"
232 " \"position\": [0, -120, 0],"
233 " \"size\": [200, 200, 1],"
234 " \"orientation\": [0, 0, 30],"
236 " \"name\": \"touched\","
237 " \"action\": \"play\","
238 " \"animation\": \"animate\""
243 Builder builder = Builder::New();
244 builder.LoadFromString( json );
245 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
247 Animation anim = builder.CreateAnimation("animate");
249 DALI_TEST_CHECK( anim );
251 anim = builder.CreateAnimation("path-animation");
253 DALI_TEST_CHECK( anim );
256 // Emit touch event and check that our quit method is called
257 Integration::TouchEvent touchEvent;
258 touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
259 application.ProcessEvent( touchEvent );
262 application.SendNotification();
263 application.Render();
269 int UtcDaliBuilderAnimationN(void)
271 ToolkitTestApplication application;
273 // JSON with a quit event when the actor is touched
280 " \"points\":[ [-150, -50, 0], [0.0,70.0,0.0], [190.0,-150.0,0.0] ],"
281 " \"curvature\":0.35"
287 " \"end-action\": \"BAKE\","
288 " \"disconnect-action\": \"BAKE\","
291 " \"actor\": \"greeting\","
292 " \"property\": \"positioninvalid\","
293 " \"value\": [300, 300, -1000],"
294 " \"alpha-function\": \"EASE_IN_OUT\","
295 " \"relative\": true,"
296 " \"time-period\": {"
305 " \"end-action\": \"BAKE\","
306 " \"disconnect-action\": \"BAKE\","
309 " \"actor\": \"greeting\","
310 " \"property\": \"positioninvalid\","
311 " \"value\": [300, 300, -1000],"
312 " \"alpha-function\": \"EGGS_OVER_EASY\","
313 " \"relative\": true,"
314 " \"time-period\": {"
321 " \"path-animation\": {"
322 " \"duration\": 3.0,"
323 " \"end-action\": \"DISCARD\","
324 " \"disconnect-action\": \"BAKE_FINAL\","
325 " \"properties\": [{"
326 " \"actor\": \"greeting\","
327 " \"path\":\"pathDoesntExist\","
328 " \"forward\":[1,0,0],"
329 " \"alpha-function\": \"EASE_IN_OUT\","
330 " \"time-period\": {"
338 " \"name\": \"greeting\","
339 " \"type\": \"TextLabel\","
340 " \"text\": \"Touch me\","
341 " \"styles\": [\"basic-text\"],"
342 " \"position\": [0, -120, 0],"
343 " \"size\": [200, 200, 1],"
344 " \"orientation\": [0, 0, 30],"
346 " \"name\": \"touched\","
347 " \"action\": \"play\","
348 " \"animation\": \"animate\""
354 Builder builder = Builder::New();
355 builder.LoadFromString( json );
356 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
358 Animation anim = builder.CreateAnimation("animate");
360 // log warning line coverage
361 anim = builder.CreateAnimation("path-animation");
363 anim = builder.CreateAnimation("animate");
365 anim = builder.CreateAnimation("animate2");
367 DALI_TEST_CHECK(true);
373 int UtcDaliBuilderConstantsP(void)
375 ToolkitTestApplication application;
377 // JSON with a quit event when the actor is touched
382 " \"IMAGE_PATH\": \"apath\","
384 " \"ANCHOR\": \"TOP_LEFT\","
385 " \"PADDING\": [1,2,3,4]"
389 " \"type\": \"ImageActor\","
390 " \"size\": [100,100,1],"
391 " \"parent-origin\": \"TOP_LEFT\","
392 " \"anchor-point\": \"{ANCHOR}\","
393 " \"padding\": \"{PADDING}\","
394 " \"image\": { \"filename\": \"dir/{IMAGE_PATH}\" },"
395 " \"size-width\": \"{WIDTH}\","
397 " \"name\": \"touched\","
398 " \"action\": \"quit\""
404 Builder builder = Builder::New();
405 builder.LoadFromString( json );
406 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
407 DALI_TEST_CHECK( builder );
412 int UtcDaliBuilderTemplatesAndStylesP(void)
414 ToolkitTestApplication application;
416 // JSON with a quit event when the actor is touched
421 " \"image-style\": \n"
423 " \"color\": [1,0,0,1],\n"
425 " \"child-image\": {\n"
426 " \"color\": [0,1,0,1]\n"
433 " \"image-tree\": { \n"
434 " \"type\": \"ImageActor\",\n"
435 " \"styles\": [\"image-style\"],\n"
436 " \"name\": \"image\",\n"
437 " \"size\": [100,100,1],\n"
439 " \"name\": \"touched\",\n"
440 " \"action\": \"quit\"\n"
444 " \"type\":\"ImageActor\",\n"
445 " \"name\":\"child-image\" \n"
453 Builder builder = Builder::New();
454 builder.LoadFromString( json );
456 ImageActor actor = ImageActor::DownCast( builder.Create( "image-tree" ) );
457 DALI_TEST_CHECK( actor );
459 // NB: already applied in create
460 DALI_TEST_CHECK( builder.ApplyStyle( "image-style", actor ) );
465 int UtcDaliBuilderRenderTasksP(void)
467 ToolkitTestApplication application;
469 // JSON with a quit event when the actor is touched
472 "\"render-tasks\":\n"
475 " \"source-actor\": \"image\",\n"
476 " \"camera-actor\": \"camera\" \n"
482 " \"type\": \"CameraActor\",\n"
483 " \"name\": \"image\"\n"
486 " \"type\": \"ImageActor\",\n"
487 " \"name\": \"image\",\n"
488 " \"size\": [100,100,1],\n"
490 " \"name\": \"touched\",\n"
491 " \"action\": \"quit\"\n"
495 " \"type\":\"ImageActor\",\n"
496 " \"name\":\"child-image\" \n"
504 Builder builder = Builder::New();
505 builder.LoadFromString( json );
507 unsigned int count = Stage::GetCurrent().GetRenderTaskList().GetTaskCount();
510 builder.CreateRenderTask( "task0" );
512 DALI_TEST_CHECK( count <
513 Stage::GetCurrent().GetRenderTaskList().GetTaskCount() );
518 int UtcDaliBuilderChildActionP(void)
520 ToolkitTestApplication application;
522 // JSON with a quit event when the actor is touched
527 " \"type\": \"Actor\",\n"
528 " \"name\": \"actor\",\n"
529 " \"size\": [100,100,1],\n"
530 " \"parent-origin\": \"TOP_LEFT\",\n"
531 " \"anchor-point\": \"TOP_LEFT\",\n"
533 " \"type\": \"Actor\",\n"
534 " \"name\": \"sub-actor\"\n"
537 " \"name\": \"touched\",\n"
538 " \"action\": \"hide\",\n"
539 " \"actor\": \"actor\",\n"
540 " \"child-actor\": \"sub-actor\"\n"
546 Builder builder = Builder::New();
547 builder.LoadFromString( json );
548 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
551 application.SendNotification();
552 application.Render();
554 // Emit touch event and check that our quit method is called
555 Integration::TouchEvent touchEvent;
556 touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
557 application.ProcessEvent( touchEvent );
560 application.SendNotification();
561 application.Render();
563 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("sub-actor");
564 DALI_TEST_CHECK( actor );
566 DALI_TEST_CHECK( !actor.IsVisible() );
571 int UtcDaliBuilderSetPropertyActionP(void)
573 ToolkitTestApplication application;
575 // JSON with a quit event when the actor is touched
580 " \"type\": \"Actor\",\n"
581 " \"name\": \"actor\",\n"
582 " \"size\": [100,100,1],\n"
583 " \"parent-origin\": \"TOP_LEFT\",\n"
584 " \"anchor-point\": \"TOP_LEFT\",\n"
586 " \"type\": \"Actor\",\n"
587 " \"name\": \"sub-actor\"\n"
590 " \"name\": \"touched\",\n"
591 " \"action\": \"set\",\n"
592 " \"actor\": \"sub-actor\",\n"
593 " \"property\": \"visible\",\n"
594 " \"value\": false\n"
600 Builder builder = Builder::New();
601 builder.LoadFromString( json );
602 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
605 application.SendNotification();
606 application.Render();
608 // Emit touch event and check that our quit method is called
609 Integration::TouchEvent touchEvent;
610 touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
611 application.ProcessEvent( touchEvent );
614 application.SendNotification();
615 application.Render();
617 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("sub-actor");
618 DALI_TEST_CHECK( actor );
620 DALI_TEST_CHECK( !actor.IsVisible() );
625 int UtcDaliBuilderGenericActionP(void)
627 ToolkitTestApplication application;
629 // JSON with a quit event when the actor is touched
634 " \"type\": \"Actor\",\n"
635 " \"name\": \"actor\",\n"
636 " \"size\": [100,100,1],\n"
637 " \"parent-origin\": \"TOP_LEFT\",\n"
638 " \"anchor-point\": \"TOP_LEFT\",\n"
640 " \"type\": \"Actor\",\n"
641 " \"name\": \"sub-actor\"\n"
644 " \"name\": \"touched\",\n"
645 " \"action\": \"hide\"\n"
651 Builder builder = Builder::New();
652 builder.LoadFromString( json );
653 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
656 application.SendNotification();
657 application.Render();
659 // Emit touch event and check that our quit method is called
660 Integration::TouchEvent touchEvent;
661 touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
662 application.ProcessEvent( touchEvent );
665 application.SendNotification();
666 application.Render();
668 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor");
669 DALI_TEST_CHECK( actor );
671 DALI_TEST_CHECK( !actor.IsVisible() );
676 int UtcDaliBuilderPropertyNotificationP(void)
678 ToolkitTestApplication application;
680 // JSON with a quit event when the actor is touched
685 " \"type\": \"Actor\",\n"
686 " \"name\": \"actor\",\n"
687 " \"size\": [100,100,1],\n"
688 " \"parent-origin\": \"TOP_LEFT\",\n"
689 " \"anchor-point\": \"TOP_LEFT\",\n"
691 " \"type\": \"Actor\",\n"
692 " \"name\": \"sub-actor\"\n"
695 " \"name\": \"touched\",\n"
696 " \"action\": \"hide\"\n"
698 " \"notifications\": [{\n"
699 " \"property\": \"visible\",\n"
700 " \"condition\": \"False\",\n"
701 " \"action\": \"show\"\n"
707 Builder builder = Builder::New();
708 builder.LoadFromString( json );
709 builder.AddActors ( Stage::GetCurrent().GetRootLayer() );
712 application.SendNotification();
713 application.Render();
715 // Emit touch event and check that our quit method is called
716 Integration::TouchEvent touchEvent;
717 touchEvent.points.push_back( TouchPoint ( 0, TouchPoint::Down, 10.0f, 10.0f ) );
718 application.ProcessEvent( touchEvent );
721 application.SendNotification();
722 application.Render();
725 application.SendNotification();
726 application.Render();
728 Actor actor = Stage::GetCurrent().GetRootLayer().FindChildByName("actor");
729 DALI_TEST_CHECK( actor );
731 DALI_TEST_CHECK( actor.IsVisible() );