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.
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <dali-toolkit/public-api/builder/builder.h>
23 using namespace Toolkit;
28 // Note: To avoid escaping double quotes single quotes are used and then replaced
29 // before parsing. JSON uses double quotes
31 std::string JSON_TEXTSTYLE_ONLY("\
35 'title-text-style':{'font-name': 'Vera', \
36 'font-style': 'Bold', \
39 'text-color': [0.0,0.5,0.5,1], \
45 'shadow-color': [0.0,1.0,0.0,1.0], \
46 'shadow-offset': [3.0,2.0], \
48 'glow-color': [0.9,0.6,0.3,1.0], \
49 'glow-intensity':0.1, \
50 'smooth-edge': 0.45, \
51 'outline-color': [1.0,0.5,0.0,1.0], \
52 'outline-thickness': [0.7,0.6] \
58 std::string JSON_TEXT_ACTOR("\
67 'parent-origin':[0.0,0.0,0], \
68 'anchor-point' :[0.5,0.5,0], \
69 'size': [150,170,1], \
70 'position':[-10,10,0] \
82 'property':'rotation', \
83 'value':[0, 3, 0, 0], \
84 'alpha-function': 'EASE_IN_OUT', \
85 'time-period': {'delay': 0, 'duration': 3 } \
94 'type':'basic-text', \
99 'type':'basic-text', \
103 { 'name': 'on-stage', 'action':'set', 'actor':'text2', 'property':'text', 'value':'Jaylo' } \
110 'name':'other-text', \
111 'type':'basic-text', \
119 std::string JSON_CORE_ACTOR_TREE("\
124 'type':'CameraActor', \
125 'camera-type':'FreeLook', \
126 'field-of-view': 0.125, \
127 'aspect-ratio':5.0, \
128 'near-plane-distance': 100, \
129 'far-plane-distance': 200 \
132 'type':'TextActor', \
136 'position': [-10.0, 10.0, -1000.0], \
137 'size': [300.0, 250.0, 0.0] \
140 'type':'TextActor', \
149 'type':'TextActor', \
150 'text':'Hello World', \
152 'parent-origin':'CENTER', \
155 { 'type':'basic-text', 'text':'Hello', 'position-y':50 }, \
156 { 'type':'basic-text', 'text':'Hello', 'position-y':100 }, \
157 { 'type':'basic-text', 'text':'Hello', 'position-y':150 }, \
158 { 'type':'basic-text', 'text':'Hello', 'position-y':200 }, \
159 { 'type':'basic-text', 'text':'Hello', 'position-y':250 } \
167 std::string ReplaceQuotes(const std::string &in_s)
170 // wrong as no embedded quote but had regex link problems
171 std::replace(s.begin(), s.end(), '\'', '"');
179 void builder_startup(void)
181 test_return_value = TET_UNDEF;
184 void builder_cleanup(void)
186 test_return_value = TET_PASS;
189 int UtcDaliBuilderTextActorCreateFromStyle(void)
191 ToolkitTestApplication application;
192 Stage stage = Stage::GetCurrent();
194 tet_infoline(" UtcDaliBuilderTextActorCreateFromStyle");
196 Builder builder = Builder::New();
198 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
200 TextActor actor( TextActor::DownCast( builder.CreateFromStyle("basic-text") ) );
202 DALI_TEST_CHECK( actor );
204 stage.GetRootLayer().Add( actor );
206 application.SendNotification();
207 application.Render();
211 v = actor.GetCurrentPosition();
212 DALI_TEST_CHECK(v.x == -10.0);
213 DALI_TEST_CHECK(v.y == 10.0);
214 DALI_TEST_CHECK(v.z == 0.0);
216 v = actor.GetCurrentSize();
217 DALI_TEST_CHECK(v.x == 150.0);
218 DALI_TEST_CHECK(v.y == 170.0);
219 DALI_TEST_CHECK(v.z == 1.0);
221 DALI_TEST_CHECK(actor.GetText() == "Hello");
223 actor = TextActor::DownCast( builder.CreateFromStyle("*(&^") );
224 DALI_TEST_CHECK(!actor);
229 int UtcDaliBuilderTextActorCreateAnimation(void)
231 ToolkitTestApplication application;
233 tet_infoline(" UtcDaliBuilderTextActorCreateAnimation");
235 Builder builder = Builder::New();
237 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
239 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
241 Animation anim = builder.CreateAnimation("rotate");
242 DALI_TEST_CHECK( anim );
244 DALI_TEST_CHECK( 10.0f == anim.GetDuration() );
249 int UtcDaliBuilderTextActorApplyFromStyle(void)
251 ToolkitTestApplication application;
253 tet_infoline(" UtcDaliBuilderTextActorApplyFromStyle");
255 Builder builder = Builder::New();
257 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
259 TextActor actor = TextActor::New("a");
261 builder.ApplyStyle("basic-text", actor);
263 DALI_TEST_CHECK( actor );
265 Stage::GetCurrent().GetRootLayer().Add( actor );
267 application.SendNotification();
268 application.Render();
272 v = actor.GetCurrentPosition();
273 DALI_TEST_CHECK(v.x == -10.0);
274 DALI_TEST_CHECK(v.y == 10.0);
275 DALI_TEST_CHECK(v.z == 0.0);
277 v = actor.GetCurrentSize();
278 DALI_TEST_CHECK(v.x == 150.0);
279 DALI_TEST_CHECK(v.y == 170.0);
280 DALI_TEST_CHECK(v.z == 1.0);
282 DALI_TEST_CHECK(actor.GetText() == "Hello");
287 int UtcDaliBuilderAddActors(void)
289 ToolkitTestApplication application;
291 tet_infoline(" UtcDaliBuilderAddActors");
293 Builder builder = Builder::New();
295 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
297 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
299 application.SendNotification();
300 application.Render();
302 TextActor actor = TextActor::DownCast( Stage::GetCurrent().GetRootLayer().FindChildByName("text") );
304 DALI_TEST_CHECK( actor );
305 DALI_TEST_CHECK(actor.GetText() == "Hello");
310 int UtcDaliBuilderAddActorsOther(void)
312 ToolkitTestApplication application;
314 tet_infoline(" UtcDaliBuilderAddActorsOther");
316 Actor rootActor = Stage::GetCurrent().GetRootLayer();
318 Builder builder = Builder::New();
320 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
322 builder.AddActors( "other", rootActor );
324 application.SendNotification();
325 application.Render();
327 TextActor actor = TextActor::DownCast( Stage::GetCurrent().GetRootLayer().FindChildByName("other-text") );
329 DALI_TEST_CHECK( actor );
330 DALI_TEST_CHECK(actor.GetText() == "Hello");
336 int UtcDaliBuilderStyles(void)
338 ToolkitTestApplication application;
340 tet_infoline(" UtcDaliBuilderStyles");
342 Builder builder = Builder::New();
344 builder.LoadFromString(ReplaceQuotes(JSON_CORE_ACTOR_TREE));
346 BaseHandle handle = builder.CreateFromStyle("my-camera");
347 CameraActor camera = CameraActor::DownCast(handle);
349 DALI_TEST_CHECK(camera);
353 v = camera.GetProperty( camera.GetPropertyIndex("field-of-view") );
354 DALI_TEST_CHECK( 0.125f == v.Get<float>() );
356 v = camera.GetProperty( camera.GetPropertyIndex("aspect-ratio") );
357 DALI_TEST_CHECK( 5.0f == v.Get<float>() );
359 handle = builder.CreateFromStyle("basic-text");
360 TextActor textActor = TextActor::DownCast(handle);
362 v = textActor.GetProperty( textActor.GetPropertyIndex("smooth-edge") );
364 DALI_TEST_CHECK( 0.2f == v.Get<float>() );
366 // test ApplyStyle another
367 builder.ApplyStyle("theme2-text", textActor);
369 v = textActor.GetProperty( textActor.GetPropertyIndex("smooth-edge") );
370 DALI_TEST_CHECK( 0.8f == v.Get<float>() );
375 int UtcDaliBuilderSetProperty(void)
377 ToolkitTestApplication application;
379 tet_infoline(" UtcDaliBuilderSetProperty");
381 Builder builder = Builder::New();
383 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
385 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
387 application.SendNotification();
388 application.Render();
390 TextActor actor = TextActor::DownCast( Stage::GetCurrent().GetRootLayer().FindChildByName("text2") );
392 DALI_TEST_CHECK( actor );
393 DALI_TEST_CHECK( actor.GetText() == "Jaylo" );