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
32 std::string JSON_TEXT_ACTOR("\
39 'text':'Template Hello', \
40 'size': [150,170,1], \
41 'position':[-10,10,0] \
50 'parent-origin':[0.0,0.0,0], \
51 'anchor-point' :[0.5,0.5,0], \
52 'size': [150,170,1], \
53 'position':[-10,10,0] \
65 'property':'rotation', \
66 'value':[0, 3, 0, 0], \
67 'alpha-function': 'EASE_IN_OUT', \
68 'time-period': {'delay': 0, 'duration': 3 } \
77 'type':'basic-text', \
82 'type':'basic-text', \
86 { 'name': 'on-stage', 'action':'set', 'actor':'text2', 'property':'text', 'value':'Jaylo' } \
93 'name':'other-text', \
94 'type':'basic-text', \
102 std::string JSON_CORE_ACTOR_TREE("\
107 'type':'CameraActor', \
108 'camera-type':'FreeLook', \
109 'field-of-view': 0.125, \
110 'aspect-ratio':5.0, \
111 'near-plane-distance': 100, \
112 'far-plane-distance': 200 \
115 'type':'TextActor', \
119 'position': [-10.0, 10.0, -1000.0], \
120 'size': [300.0, 250.0, 0.0] \
126 'type':'TextActor', \
135 'type':'TextActor', \
136 'text':'Hello World', \
138 'parent-origin':'CENTER', \
141 { 'type':'basic-text', 'text':'Hello', 'position-y':50 }, \
142 { 'type':'basic-text', 'text':'Hello', 'position-y':100 }, \
143 { 'type':'basic-text', 'text':'Hello', 'position-y':150 }, \
144 { 'type':'basic-text', 'text':'Hello', 'position-y':200 }, \
145 { 'type':'basic-text', 'text':'Hello', 'position-y':250 } \
153 std::string ReplaceQuotes(const std::string &in_s)
156 // wrong as no embedded quote but had regex link problems
157 std::replace(s.begin(), s.end(), '\'', '"');
165 void builder_startup(void)
167 test_return_value = TET_UNDEF;
170 void builder_cleanup(void)
172 test_return_value = TET_PASS;
175 int UtcDaliBuilderTextActorCreate(void)
177 ToolkitTestApplication application;
178 Stage stage = Stage::GetCurrent();
180 tet_infoline(" UtcDaliBuilderTextActorCreate");
182 Builder builder = Builder::New();
184 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
186 TextActor actor( TextActor::DownCast( builder.Create("basic-text") ) );
188 DALI_TEST_CHECK( actor );
190 stage.GetRootLayer().Add( actor );
192 application.SendNotification();
193 application.Render();
197 v = actor.GetCurrentPosition();
198 DALI_TEST_CHECK(v.x == -10.0);
199 DALI_TEST_CHECK(v.y == 10.0);
200 DALI_TEST_CHECK(v.z == 0.0);
202 v = actor.GetCurrentSize();
203 DALI_TEST_CHECK(v.x == 150.0);
204 DALI_TEST_CHECK(v.y == 170.0);
205 DALI_TEST_CHECK(v.z == 1.0);
207 DALI_TEST_CHECK(actor.GetText() == "Template Hello");
209 actor = TextActor::DownCast( builder.Create("*(&^") );
210 DALI_TEST_CHECK(!actor);
215 int UtcDaliBuilderTextActorCreateAnimation(void)
217 ToolkitTestApplication application;
219 tet_infoline(" UtcDaliBuilderTextActorCreateAnimation");
221 Builder builder = Builder::New();
223 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
225 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
227 Animation anim = builder.CreateAnimation("rotate");
228 DALI_TEST_CHECK( anim );
230 DALI_TEST_CHECK( 10.0f == anim.GetDuration() );
235 int UtcDaliBuilderTextActorApplyFromStyle(void)
237 ToolkitTestApplication application;
239 tet_infoline(" UtcDaliBuilderTextActorApplyFromStyle");
241 Builder builder = Builder::New();
243 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
245 TextActor actor = TextActor::New("a");
247 builder.ApplyStyle("basic-text", actor);
249 DALI_TEST_CHECK( actor );
251 Stage::GetCurrent().GetRootLayer().Add( actor );
253 application.SendNotification();
254 application.Render();
258 v = actor.GetCurrentPosition();
259 DALI_TEST_CHECK(v.x == -10.0);
260 DALI_TEST_CHECK(v.y == 10.0);
261 DALI_TEST_CHECK(v.z == 0.0);
263 v = actor.GetCurrentSize();
264 DALI_TEST_CHECK(v.x == 150.0);
265 DALI_TEST_CHECK(v.y == 170.0);
266 DALI_TEST_CHECK(v.z == 1.0);
268 DALI_TEST_CHECK(actor.GetText() == "Hello");
273 int UtcDaliBuilderAddActors(void)
275 ToolkitTestApplication application;
277 tet_infoline(" UtcDaliBuilderAddActors");
279 Builder builder = Builder::New();
281 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
283 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
285 application.SendNotification();
286 application.Render();
288 TextActor actor = TextActor::DownCast( Stage::GetCurrent().GetRootLayer().FindChildByName("text") );
290 DALI_TEST_CHECK( actor );
291 DALI_TEST_CHECK(actor.GetText() == "Hello");
296 int UtcDaliBuilderAddActorsOther(void)
298 ToolkitTestApplication application;
300 tet_infoline(" UtcDaliBuilderAddActorsOther");
302 Actor rootActor = Stage::GetCurrent().GetRootLayer();
304 Builder builder = Builder::New();
306 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
308 builder.AddActors( "other", rootActor );
310 application.SendNotification();
311 application.Render();
313 TextActor actor = TextActor::DownCast( Stage::GetCurrent().GetRootLayer().FindChildByName("other-text") );
315 DALI_TEST_CHECK( actor );
316 DALI_TEST_CHECK(actor.GetText() == "Hello");
322 int UtcDaliBuilderStyles(void)
324 ToolkitTestApplication application;
326 tet_infoline(" UtcDaliBuilderStyles");
328 Builder builder = Builder::New();
330 builder.LoadFromString(ReplaceQuotes(JSON_CORE_ACTOR_TREE));
332 BaseHandle handle = builder.Create("my-camera");
333 CameraActor camera = CameraActor::DownCast(handle);
335 DALI_TEST_CHECK(camera);
339 v = camera.GetProperty( camera.GetPropertyIndex("field-of-view") );
340 DALI_TEST_CHECK( 0.125f == v.Get<float>() );
342 v = camera.GetProperty( camera.GetPropertyIndex("aspect-ratio") );
343 DALI_TEST_CHECK( 5.0f == v.Get<float>() );
345 handle = builder.Create("basic-text");
346 TextActor textActor = TextActor::DownCast(handle);
348 v = textActor.GetProperty( textActor.GetPropertyIndex("smooth-edge") );
350 DALI_TEST_CHECK( 0.2f == v.Get<float>() );
352 // test ApplyStyle another
353 builder.ApplyStyle("theme2-text", textActor);
355 v = textActor.GetProperty( textActor.GetPropertyIndex("smooth-edge") );
356 DALI_TEST_CHECK( 0.8f == v.Get<float>() );
361 int UtcDaliBuilderSetProperty(void)
363 ToolkitTestApplication application;
365 tet_infoline(" UtcDaliBuilderSetProperty");
367 Builder builder = Builder::New();
369 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
371 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
373 application.SendNotification();
374 application.Render();
376 TextActor actor = TextActor::DownCast( Stage::GetCurrent().GetRootLayer().FindChildByName("text2") );
378 DALI_TEST_CHECK( actor );
379 DALI_TEST_CHECK( actor.GetText() == "Jaylo" );