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.
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
26 #include <dali-toolkit/dali-toolkit.h>
30 void utc_dali_toolkit_markup_processor_startup(void)
32 test_return_value = TET_UNDEF;
35 void utc_dali_toolkit_markup_processor_cleanup(void)
37 test_return_value = TET_PASS;
43 struct MarkupStringTest
46 std::string expectedResult;
49 bool TestMarkupString( const std::string& input, const std::string& expectedResult, std::string& result )
51 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
53 GetStyledTextArray( input, styledTextArray, true );
54 GetMarkupString( styledTextArray, result );
56 return expectedResult == result;
62 // Positive test case for a method
63 int UtcDaliMarkupProcessor(void)
65 ToolkitTestApplication application;
67 tet_infoline(" UtcDaliMarkupProcessor ");
69 const std::string text1( "Text" );
70 const std::string text2( "< font face ='FreeSerif' color= 'green' >t< / font >" );
71 const std::string text3( "< font face = 'FreeSerif' size= '16' style = 'Bold' color='red'>< i><u >Styled< / u> Text< /i >< / font >< br / >" );
72 const std::string text4( "<font face='FreeSerif' size='14' color='0xaadd8744'><b><u>Styled</u> Te<font size='20'>x</font>t</b></font>< br/>" );
73 const std::string text5( "< shadow color = 'blue' paramx = '1' paramy = '0.75' >Shadow< / shadow><br />" );
74 const std::string text6( "<smooth param= '0.75' >< glow color = 'red' param = '0.1' >Glow</glow></smooth>< br />" );
75 const std::string text7( "<font color='green''>< outline color = 'red' paramx = '0.7' paramy = '0.7' >Outline< / outline >< /font >< br / >" );
76 const std::string text8( "<smooth param='0.75'>Smooth</smooth>< br / >" );
77 const std::string text9( "\\<" );
78 const std::string text10( "\\>" );
83 const std::string text11( crlf, 2 );
85 const std::string result1( text1 );
86 const std::string result2( "<font face='FreeSerif' color='green'>t</font>" );
87 const std::string result3( "<font face='FreeSerif' style='Bold' size='16' color='red'><i><u>Styled</u></i></font><font face='FreeSerif' style='Bold' size='16' color='red'><i> Text</i></font><br />" );
88 const std::string result4( "<font face='FreeSerif' size='14' color='0xaadd8744'><b><u>Styled</u></b></font><font face='FreeSerif' size='14' color='0xaadd8744'><b> Te</b></font><font face='FreeSerif' size='20' color='0xaadd8744'><b>x</b></font><font face='FreeSerif' size='14' color='0xaadd8744'><b>t</b></font><br />" );
89 const std::string result5( "<shadow color='blue' paramx='1' paramy='0.75'>Shadow</shadow><br />" );
90 const std::string result6( "<smooth param='0.75'><glow color='red' param='0.1'>Glow</glow></smooth><br />" );
91 const std::string result7( "<font color='green'><outline color='red' paramx='0.7' paramy='0.7'>Outline</outline></font><br />" );
92 const std::string result8( "<smooth param='0.75'>Smooth</smooth><br />" );
93 const std::string result9( text9 );
94 const std::string result10( text10 );
95 const std::string result11( "<br />" );
97 std::string markupString;
98 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
100 GetStyledTextArray( text1, styledTextArray, true );
101 GetMarkupString( styledTextArray, markupString );
102 DALI_TEST_EQUALS( result1, markupString, TEST_LOCATION );
104 GetStyledTextArray( text2, styledTextArray, true );
105 GetMarkupString( styledTextArray, markupString );
106 DALI_TEST_EQUALS( result2, markupString, TEST_LOCATION );
108 GetStyledTextArray( text3, styledTextArray, true );
109 GetMarkupString( styledTextArray, markupString );
110 DALI_TEST_EQUALS( result3, markupString, TEST_LOCATION );
112 GetStyledTextArray( text4, styledTextArray, true );
113 GetMarkupString( styledTextArray, markupString );
114 DALI_TEST_EQUALS( result4, markupString, TEST_LOCATION );
116 GetStyledTextArray( text5, styledTextArray, true );
117 GetMarkupString( styledTextArray, markupString );
118 DALI_TEST_EQUALS( result5, markupString, TEST_LOCATION );
120 GetStyledTextArray( text6, styledTextArray, true );
121 GetMarkupString( styledTextArray, markupString );
122 DALI_TEST_EQUALS( result6, markupString, TEST_LOCATION );
124 GetStyledTextArray( text7, styledTextArray, true );
125 GetMarkupString( styledTextArray, markupString );
126 DALI_TEST_EQUALS( result7, markupString, TEST_LOCATION );
128 GetStyledTextArray( text8, styledTextArray, true );
129 GetMarkupString( styledTextArray, markupString );
130 DALI_TEST_EQUALS( result8, markupString, TEST_LOCATION );
132 GetStyledTextArray( text9, styledTextArray, true );
133 GetMarkupString( styledTextArray, markupString );
134 DALI_TEST_EQUALS( result9, markupString, TEST_LOCATION );
136 GetStyledTextArray( text10, styledTextArray, true );
137 GetMarkupString( styledTextArray, markupString );
139 DALI_TEST_EQUALS( result10, markupString, TEST_LOCATION );
141 GetStyledTextArray( text11, styledTextArray, true );
142 GetMarkupString( styledTextArray, markupString );
144 DALI_TEST_EQUALS( result11, markupString, TEST_LOCATION );
148 int UtcDaliMarkupProcessorSetTextStyle01(void)
150 ToolkitTestApplication application;
152 tet_infoline(" UtcDaliMarkupProcessorSetTextStyle01 ");
154 const std::string text1( "Text with no defined style" );
155 const std::string result1( "<font color='green'><i>Text with no defined style</i></font>" );
156 const std::string result2( "Text with <font color='green'><i>no defined</i></font> style" );
158 std::string markupString;
159 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
161 GetStyledTextArray( text1, styledTextArray, true );
164 style.SetItalics( true );
165 style.SetTextColor( Color::GREEN );
167 SetTextStyle( styledTextArray, style );
168 GetMarkupString( styledTextArray, markupString );
170 DALI_TEST_EQUALS( result1, markupString, TEST_LOCATION );
172 styledTextArray.clear();
173 SetTextStyle( text1, styledTextArray, style );
174 GetMarkupString( styledTextArray, markupString );
176 DALI_TEST_EQUALS( result1, markupString, TEST_LOCATION );
178 GetStyledTextArray( text1, styledTextArray, true );
179 SetTextStyleToRange( styledTextArray, style, TextStyle::ALL, 0, text1.size() - 1 );
180 GetMarkupString( styledTextArray, markupString );
182 DALI_TEST_EQUALS( result1, markupString, TEST_LOCATION );
184 GetStyledTextArray( text1, styledTextArray, true );
185 SetTextStyleToRange( styledTextArray, style, TextStyle::ALL, 10, 19 );
186 GetMarkupString( styledTextArray, markupString );
188 DALI_TEST_EQUALS( result2, markupString, TEST_LOCATION );
190 std::string plainString;
191 GetPlainString( styledTextArray, plainString );
193 DALI_TEST_EQUALS( text1, plainString, TEST_LOCATION );
197 int UtcDaliMarkupProcessorSetTextStyle02(void)
199 ToolkitTestApplication application;
201 tet_infoline(" UtcDaliMarkupProcessorSetTextStyle02 ");
203 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
205 // Test style applied to and empty string doesn't crash
208 style.SetItalics( true );
209 style.SetTextColor( Color::GREEN );
214 SetTextStyle( styledTextArray, style );
221 DALI_TEST_CHECK( !fails );
225 int UtcDaliMarkupProcessorTestColors(void)
227 ToolkitTestApplication application;
229 tet_infoline("UtcDaliMarkupProcessorTestColors ");
231 struct MarkupStringTest colorTests[] =
234 std::string( "<font color='0xFF000000'>black</font>" ),
235 std::string( "<font color='black'>black</font>" )
238 std::string( "<font color='0xFFFFFFFF'>white</font>" ),
239 std::string( "white" )
242 std::string( "<font color='0xFFFF0000'>red</font>" ),
243 std::string( "<font color='red'>red</font>" )
246 std::string( "<font color='0xFF00FF00'>green</font>" ),
247 std::string( "<font color='green'>green</font>" )
250 std::string( "<font color='0xFF0000FF'>blue</font>" ),
251 std::string( "<font color='blue'>blue</font>" )
254 std::string( "<font color='0xFFFFFF00'>yellow</font>" ),
255 std::string( "<font color='yellow'>yellow</font>" )
258 std::string( "<font color='0xFFFF00FF'>magenta</font>" ),
259 std::string( "<font color='magenta'>magenta</font>" )
262 std::string( "<font color='0xFF00FFFF'>cyan</font>" ),
263 std::string( "<font color='cyan'>cyan</font>" )
266 std::string( "<font color='0x00000000'>transparent</font>" ),
267 std::string( "<font color='transparent'>transparent</font>" )
270 std::string( "<font color='#000000'>black</font>" ),
271 std::string( "<font color='black'>black</font>" )
274 std::string( "<font color='#FFFFFF'>white</font>" ),
275 std::string( "white" )
278 std::string( "<font color='#FF0000'>red</font>" ),
279 std::string( "<font color='red'>red</font>" )
282 std::string( "<font color='#00FF00'>green</font>" ),
283 std::string( "<font color='green'>green</font>" )
286 std::string( "<font color='#0000FF'>blue</font>" ),
287 std::string( "<font color='blue'>blue</font>" )
290 std::string( "<font color='#FFFF00'>yellow</font>" ),
291 std::string( "<font color='yellow'>yellow</font>" )
294 std::string( "<font color='#FF00FF'>magenta</font>" ),
295 std::string( "<font color='magenta'>magenta</font>" )
298 std::string( "<font color='#00FFFF'>cyan</font>" ),
299 std::string( "<font color='cyan'>cyan</font>" )
302 std::string( "<font color='#000'>black</font>" ),
303 std::string( "<font color='black'>black</font>" )
306 std::string( "<font color='#FFF'>white</font>" ),
307 std::string( "white" )
310 std::string( "<font color='#F00'>red</font>" ),
311 std::string( "<font color='red'>red</font>" )
314 std::string( "<font color='#0F0'>green</font>" ),
315 std::string( "<font color='green'>green</font>" )
318 std::string( "<font color='#00F'>blue</font>" ),
319 std::string( "<font color='blue'>blue</font>" )
322 std::string( "<font color='#FF0'>yellow</font>" ),
323 std::string( "<font color='yellow'>yellow</font>" )
326 std::string( "<font color='#F0F'>magenta</font>" ),
327 std::string( "<font color='magenta'>magenta</font>" )
330 std::string( "<font color='#0FF'>cyan</font>" ),
331 std::string( "<font color='cyan'>cyan</font>" )
334 std::string( "<font color='0x000000'>black</font>" ),
335 std::string( "<font color='black'>black</font>" )
338 std::string( "<font color='black'>black</font>" ),
339 std::string( "<font color='black'>black</font>" )
342 std::string( "<font color='white'>white</font>" ),
343 std::string( "white" )
346 std::string( "<font color='red'>red</font>" ),
347 std::string( "<font color='red'>red</font>" )
350 std::string( "<font color='0xFF00FF00'>green</font>" ),
351 std::string( "<font color='green'>green</font>" )
354 std::string( "<font color='blue'>blue</font>" ),
355 std::string( "<font color='blue'>blue</font>" )
358 std::string( "<font color='yellow'>yellow</font>" ),
359 std::string( "<font color='yellow'>yellow</font>" )
362 std::string( "<font color='magenta'>magenta</font>" ),
363 std::string( "<font color='magenta'>magenta</font>" )
366 std::string( "<font color='cyan'>cyan</font>" ),
367 std::string( "<font color='cyan'>cyan</font>" )
370 std::string( "<font color='transparent'>transparent</font>" ),
371 std::string( "<font color='transparent'>transparent</font>" )
374 std::string( "<outline color='white'>outline</outline>" ),
375 std::string( "<outline color='white'>outline</outline>" )
379 const std::size_t numberOfTests( 36 );
382 for( std::size_t index = 0; index < numberOfTests; ++index )
384 const MarkupStringTest& test = colorTests[index];
387 if( !TestMarkupString( test.input, test.expectedResult, result ) )
389 TestMarkupString( test.input, test.expectedResult, result );
390 tet_printf( "%s\n input : %s\nexpected result : %s\n result : %s\n", TEST_LOCATION, test.input.c_str(), test.expectedResult.c_str(), result.c_str() );
396 DALI_TEST_CHECK( !fails );