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', \
105 'name':'other-text', \
106 'type':'basic-text', \
114 std::string JSON_CORE_ACTOR_TREE("\
119 'type':'CameraActor', \
120 'camera-type':'FreeLook', \
121 'field-of-view': 0.125, \
122 'aspect-ratio':5.0, \
123 'near-plane-distance': 100, \
124 'far-plane-distance': 200 \
127 'type':'TextActor', \
131 'position': [-10.0, 10.0, -1000.0], \
132 'size': [300.0, 250.0, 0.0] \
135 'type':'TextActor', \
144 'type':'TextActor', \
145 'text':'Hello World', \
147 'parent-origin':'CENTER', \
150 { 'type':'basic-text', 'text':'Hello', 'position-y':50 }, \
151 { 'type':'basic-text', 'text':'Hello', 'position-y':100 }, \
152 { 'type':'basic-text', 'text':'Hello', 'position-y':150 }, \
153 { 'type':'basic-text', 'text':'Hello', 'position-y':200 }, \
154 { 'type':'basic-text', 'text':'Hello', 'position-y':250 } \
162 std::string ReplaceQuotes(const std::string &in_s)
165 // wrong as no embedded quote but had regex link problems
166 std::replace(s.begin(), s.end(), '\'', '"');
172 static void Startup();
173 static void Cleanup();
176 void (*tet_startup)() = Startup;
177 void (*tet_cleanup)() = Cleanup;
180 static void UtcDaliBuilderTextActorCreateFromStyle();
181 static void UtcDaliBuilderTextActorCreateAnimation();
182 static void UtcDaliBuilderTextActorApplyFromStyle();
183 static void UtcDaliBuilderStyles();
184 static void UtcDaliBuilderAddActorsOther();
185 static void UtcDaliBuilderAddActors();
188 POSITIVE_TC_IDX = 0x01,
192 // Add test functionality for all APIs in the class (Positive and Negative)
194 struct tet_testlist tet_testlist[] = {
195 { UtcDaliBuilderTextActorCreateFromStyle, POSITIVE_TC_IDX },
196 { UtcDaliBuilderTextActorCreateAnimation, POSITIVE_TC_IDX },
197 { UtcDaliBuilderTextActorApplyFromStyle, POSITIVE_TC_IDX },
198 { UtcDaliBuilderStyles, POSITIVE_TC_IDX },
199 { UtcDaliBuilderAddActorsOther, POSITIVE_TC_IDX },
200 { UtcDaliBuilderAddActors, POSITIVE_TC_IDX },
205 // Called only once before first test is run.
206 static void Startup()
210 // Called only once after last test is run
211 static void Cleanup()
215 static void UtcDaliBuilderTextActorCreateFromStyle()
217 ToolkitTestApplication application;
218 Stage stage = Stage::GetCurrent();
220 tet_infoline(" UtcDaliBuilderTextActorCreateFromStyle");
222 Builder builder = Builder::New();
224 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
226 TextActor actor( TextActor::DownCast( builder.CreateFromStyle("basic-text") ) );
228 DALI_TEST_CHECK( actor );
230 stage.GetRootLayer().Add( actor );
232 application.SendNotification();
233 application.Render();
237 v = actor.GetCurrentPosition();
238 DALI_TEST_CHECK(v.x == -10.0);
239 DALI_TEST_CHECK(v.y == 10.0);
240 DALI_TEST_CHECK(v.z == 0.0);
242 v = actor.GetCurrentSize();
243 DALI_TEST_CHECK(v.x == 150.0);
244 DALI_TEST_CHECK(v.y == 170.0);
245 DALI_TEST_CHECK(v.z == 1.0);
247 DALI_TEST_CHECK(actor.GetText() == "Hello");
249 actor = TextActor::DownCast( builder.CreateFromStyle("*(&^") );
250 DALI_TEST_CHECK(!actor);
254 static void UtcDaliBuilderTextActorCreateAnimation()
256 ToolkitTestApplication application;
258 tet_infoline(" UtcDaliBuilderTextActorCreateAnimation");
260 Builder builder = Builder::New();
262 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
264 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
266 Animation anim = builder.CreateAnimation("rotate");
267 DALI_TEST_CHECK( anim );
269 DALI_TEST_CHECK( 10.0f == anim.GetDuration() );
273 static void UtcDaliBuilderTextActorApplyFromStyle()
275 ToolkitTestApplication application;
277 tet_infoline(" UtcDaliBuilderTextActorApplyFromStyle");
279 Builder builder = Builder::New();
281 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
283 TextActor actor = TextActor::New("a");
285 builder.ApplyStyle("basic-text", actor);
287 DALI_TEST_CHECK( actor );
289 Stage::GetCurrent().GetRootLayer().Add( actor );
291 application.SendNotification();
292 application.Render();
296 v = actor.GetCurrentPosition();
297 DALI_TEST_CHECK(v.x == -10.0);
298 DALI_TEST_CHECK(v.y == 10.0);
299 DALI_TEST_CHECK(v.z == 0.0);
301 v = actor.GetCurrentSize();
302 DALI_TEST_CHECK(v.x == 150.0);
303 DALI_TEST_CHECK(v.y == 170.0);
304 DALI_TEST_CHECK(v.z == 1.0);
306 DALI_TEST_CHECK(actor.GetText() == "Hello");
310 static void UtcDaliBuilderAddActors()
312 ToolkitTestApplication application;
314 tet_infoline(" UtcDaliBuilderAddActors");
316 Builder builder = Builder::New();
318 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
320 builder.AddActors( Stage::GetCurrent().GetRootLayer() );
322 application.SendNotification();
323 application.Render();
325 TextActor actor = TextActor::DownCast( Stage::GetCurrent().GetRootLayer().FindChildByName("text") );
327 DALI_TEST_CHECK( actor );
328 DALI_TEST_CHECK(actor.GetText() == "Hello");
332 static void UtcDaliBuilderAddActorsOther()
334 ToolkitTestApplication application;
336 tet_infoline(" UtcDaliBuilderAddActorsOther");
338 Actor rootActor = Stage::GetCurrent().GetRootLayer();
340 Builder builder = Builder::New();
342 builder.LoadFromString(ReplaceQuotes(JSON_TEXT_ACTOR));
344 builder.AddActors( "other", rootActor );
346 application.SendNotification();
347 application.Render();
349 TextActor actor = TextActor::DownCast( Stage::GetCurrent().GetRootLayer().FindChildByName("other-text") );
351 DALI_TEST_CHECK( actor );
352 DALI_TEST_CHECK(actor.GetText() == "Hello");
357 static void UtcDaliBuilderStyles()
359 ToolkitTestApplication application;
361 tet_infoline(" UtcDaliBuilderStyles");
363 Builder builder = Builder::New();
365 builder.LoadFromString(ReplaceQuotes(JSON_CORE_ACTOR_TREE));
367 BaseHandle handle = builder.CreateFromStyle("my-camera");
368 CameraActor camera = CameraActor::DownCast(handle);
370 DALI_TEST_CHECK(camera);
374 v = camera.GetProperty( camera.GetPropertyIndex("field-of-view") );
375 DALI_TEST_CHECK( 0.125f == v.Get<float>() );
377 v = camera.GetProperty( camera.GetPropertyIndex("aspect-ratio") );
378 DALI_TEST_CHECK( 5.0f == v.Get<float>() );
380 handle = builder.CreateFromStyle("basic-text");
381 TextActor textActor = TextActor::DownCast(handle);
383 v = textActor.GetProperty( textActor.GetPropertyIndex("smooth-edge") );
385 DALI_TEST_CHECK( 0.2f == v.Get<float>() );
387 // test ApplyStyle another
388 builder.ApplyStyle("theme2-text", textActor);
390 v = textActor.GetProperty( textActor.GetPropertyIndex("smooth-edge") );
391 DALI_TEST_CHECK( 0.8f == v.Get<float>() );