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.
22 #include <dali/public-api/dali-core.h>
23 #include <dali-toolkit/public-api/builder/builder.h>
24 #include <dali-toolkit-test-suite-utils.h>
27 using namespace Toolkit;
32 // Note: To avoid escaping double quotes single quotes are used and then replaced
33 // before parsing. JSON uses double quotes
35 std::string JSON_TEXTSTYLE_ONLY("\
39 'title-text-style':{'font-name': 'Vera', \
40 'font-style': 'Bold', \
43 'text-color': [0.0,0.5,0.5,1], \
49 'shadow-color': [0.0,1.0,0.0,1.0], \
50 'shadow-offset': [3.0,2.0], \
52 'glow-color': [0.9,0.6,0.3,1.0], \
53 'glow-intensity':0.1, \
54 'smooth-edge': 0.45, \
55 'outline-color': [1.0,0.5,0.0,1.0], \
56 'outline-thickness': [0.7,0.6] \
62 std::string JSON_TEXT_ACTOR("\
71 'parent-origin':[0.0,0.0,0], \
72 'anchor-point' :[0.5,0.5,0], \
73 'size': [150,170,1], \
74 'position':[-10,10,0] \
86 'property':'rotation', \
87 'value':[0, 3, 0, 0], \
88 'alpha-function': 'EASE_IN_OUT', \
89 'time-period': {'delay': 0, 'duration': 3 } \
98 'type':'basic-text', \
103 'type':'basic-text', \
107 { 'name': 'on-stage', 'action':'set', 'actor':'text2', 'property':'text', 'value':'Jaylo' } \
114 'name':'other-text', \
115 'type':'basic-text', \
123 std::string JSON_CORE_ACTOR_TREE("\
128 'type':'CameraActor', \
129 'camera-type':'FreeLook', \
130 'field-of-view': 0.125, \
131 'aspect-ratio':5.0, \
132 'near-plane-distance': 100, \
133 'far-plane-distance': 200 \
136 'type':'TextActor', \
140 'position': [-10.0, 10.0, -1000.0], \
141 'size': [300.0, 250.0, 0.0] \
144 'type':'TextActor', \
153 'type':'TextActor', \
154 'text':'Hello World', \
156 'parent-origin':'CENTER', \
159 { 'type':'basic-text', 'text':'Hello', 'position-y':50 }, \
160 { 'type':'basic-text', 'text':'Hello', 'position-y':100 }, \
161 { 'type':'basic-text', 'text':'Hello', 'position-y':150 }, \
162 { 'type':'basic-text', 'text':'Hello', 'position-y':200 }, \
163 { 'type':'basic-text', 'text':'Hello', 'position-y':250 } \
171 std::string ReplaceQuotes(const std::string &in_s)
174 // wrong as no embedded quote but had regex link problems
175 std::replace(s.begin(), s.end(), '\'', '"');
181 static void Startup();
182 static void Cleanup();
185 void (*tet_startup)() = Startup;
186 void (*tet_cleanup)() = Cleanup;
189 static void UtcDaliBuilderTextActorCreateFromStyle();
190 static void UtcDaliBuilderTextActorCreateAnimation();
191 static void UtcDaliBuilderTextActorApplyFromStyle();
192 static void UtcDaliBuilderStyles();
193 static void UtcDaliBuilderAddActorsOther();
194 static void UtcDaliBuilderAddActors();
195 static void UtcDaliBuilderSetProperty();
198 POSITIVE_TC_IDX = 0x01,
202 // Add test functionality for all APIs in the class (Positive and Negative)
204 struct tet_testlist tet_testlist[] = {
205 { UtcDaliBuilderTextActorCreateFromStyle, POSITIVE_TC_IDX },
206 { UtcDaliBuilderTextActorCreateAnimation, POSITIVE_TC_IDX },
207 { UtcDaliBuilderTextActorApplyFromStyle, POSITIVE_TC_IDX },
208 { UtcDaliBuilderStyles, POSITIVE_TC_IDX },
209 { UtcDaliBuilderAddActorsOther, POSITIVE_TC_IDX },
210 { UtcDaliBuilderAddActors, POSITIVE_TC_IDX },
211 { UtcDaliBuilderSetProperty, POSITIVE_TC_IDX },
216 // Called only once before first test is run.
217 static void Startup()
221 // Called only once after last test is run
222 static void Cleanup()
226 static void UtcDaliBuilderTextActorCreateFromStyle()
228 ToolkitTestApplication application;
229 Stage stage = Stage::GetCurrent();
231 tet_infoline(" UtcDaliBuilderTextActorCreateFromStyle");
233 Builder builder = Builder::New();
235 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
237 TextActor actor( TextActor::DownCast( builder.CreateFromStyle("basic-text") ) );
239 DALI_TEST_CHECK( actor );
241 stage.GetRootLayer().Add( actor );
243 application.SendNotification();
244 application.Render();
248 v = actor.GetCurrentPosition();
249 DALI_TEST_CHECK(v.x == -10.0);
250 DALI_TEST_CHECK(v.y == 10.0);
251 DALI_TEST_CHECK(v.z == 0.0);
253 v = actor.GetCurrentSize();
254 DALI_TEST_CHECK(v.x == 150.0);
255 DALI_TEST_CHECK(v.y == 170.0);
256 DALI_TEST_CHECK(v.z == 1.0);
258 DALI_TEST_CHECK(actor.GetText() == "Hello");
260 actor = TextActor::DownCast( builder.CreateFromStyle("*(&^") );
261 DALI_TEST_CHECK(!actor);
265 static void UtcDaliBuilderTextActorCreateAnimation()
267 ToolkitTestApplication application;
269 tet_infoline(" UtcDaliBuilderTextActorCreateAnimation");
271 Builder builder = Builder::New();
273 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
275 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
277 Animation anim = builder.CreateAnimation("rotate");
278 DALI_TEST_CHECK( anim );
280 DALI_TEST_CHECK( 10.0f == anim.GetDuration() );
284 static void UtcDaliBuilderTextActorApplyFromStyle()
286 ToolkitTestApplication application;
288 tet_infoline(" UtcDaliBuilderTextActorApplyFromStyle");
290 Builder builder = Builder::New();
292 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
294 TextActor actor = TextActor::New("a");
296 builder.ApplyStyle("basic-text", actor);
298 DALI_TEST_CHECK( actor );
300 Stage::GetCurrent().GetRootLayer().Add( actor );
302 application.SendNotification();
303 application.Render();
307 v = actor.GetCurrentPosition();
308 DALI_TEST_CHECK(v.x == -10.0);
309 DALI_TEST_CHECK(v.y == 10.0);
310 DALI_TEST_CHECK(v.z == 0.0);
312 v = actor.GetCurrentSize();
313 DALI_TEST_CHECK(v.x == 150.0);
314 DALI_TEST_CHECK(v.y == 170.0);
315 DALI_TEST_CHECK(v.z == 1.0);
317 DALI_TEST_CHECK(actor.GetText() == "Hello");
321 static void UtcDaliBuilderAddActors()
323 ToolkitTestApplication application;
325 tet_infoline(" UtcDaliBuilderAddActors");
327 Builder builder = Builder::New();
329 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
331 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
333 application.SendNotification();
334 application.Render();
336 TextActor actor = TextActor::DownCast( Stage::GetCurrent().GetRootLayer().FindChildByName("text") );
338 DALI_TEST_CHECK( actor );
339 DALI_TEST_CHECK(actor.GetText() == "Hello");
343 static void UtcDaliBuilderAddActorsOther()
345 ToolkitTestApplication application;
347 tet_infoline(" UtcDaliBuilderAddActorsOther");
349 Actor rootActor = Stage::GetCurrent().GetRootLayer();
351 Builder builder = Builder::New();
353 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
355 builder.AddActors( "other", rootActor );
357 application.SendNotification();
358 application.Render();
360 TextActor actor = TextActor::DownCast( Stage::GetCurrent().GetRootLayer().FindChildByName("other-text") );
362 DALI_TEST_CHECK( actor );
363 DALI_TEST_CHECK(actor.GetText() == "Hello");
368 static void UtcDaliBuilderStyles()
370 ToolkitTestApplication application;
372 tet_infoline(" UtcDaliBuilderStyles");
374 Builder builder = Builder::New();
376 builder.LoadFromString(ReplaceQuotes(JSON_CORE_ACTOR_TREE));
378 BaseHandle handle = builder.CreateFromStyle("my-camera");
379 CameraActor camera = CameraActor::DownCast(handle);
381 DALI_TEST_CHECK(camera);
385 v = camera.GetProperty( camera.GetPropertyIndex("field-of-view") );
386 DALI_TEST_CHECK( 0.125f == v.Get<float>() );
388 v = camera.GetProperty( camera.GetPropertyIndex("aspect-ratio") );
389 DALI_TEST_CHECK( 5.0f == v.Get<float>() );
391 handle = builder.CreateFromStyle("basic-text");
392 TextActor textActor = TextActor::DownCast(handle);
394 v = textActor.GetProperty( textActor.GetPropertyIndex("smooth-edge") );
396 DALI_TEST_CHECK( 0.2f == v.Get<float>() );
398 // test ApplyStyle another
399 builder.ApplyStyle("theme2-text", textActor);
401 v = textActor.GetProperty( textActor.GetPropertyIndex("smooth-edge") );
402 DALI_TEST_CHECK( 0.8f == v.Get<float>() );
406 static void UtcDaliBuilderSetProperty()
408 ToolkitTestApplication application;
410 tet_infoline(" UtcDaliBuilderSetProperty");
412 Builder builder = Builder::New();
414 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
416 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
418 application.SendNotification();
419 application.Render();
421 TextActor actor = TextActor::DownCast( Stage::GetCurrent().GetRootLayer().FindChildByName("text2") );
423 DALI_TEST_CHECK( actor );
424 DALI_TEST_CHECK( actor.GetText() == "Jaylo" );