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.
20 // Need to override adaptor classes for toolkit test harness, so include
21 // test harness headers before dali headers.
22 #include <dali-toolkit-test-suite-utils.h>
25 #include <dali-toolkit/dali-toolkit.h>
29 void utc_dali_toolkit_markup_processor_startup(void)
31 test_return_value = TET_UNDEF;
34 void utc_dali_toolkit_markup_processor_cleanup(void)
36 test_return_value = TET_PASS;
42 struct MarkupStringTest
45 std::string expectedResult;
48 bool TestMarkupString( const std::string& input, const std::string& expectedResult, std::string& result )
50 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
52 GetStyledTextArray( input, styledTextArray, true );
53 GetMarkupString( styledTextArray, result );
55 return expectedResult == result;
61 // Positive test case for a method
62 int UtcDaliMarkupProcessor(void)
64 ToolkitTestApplication application;
66 tet_infoline(" UtcDaliMarkupProcessor ");
68 const std::string text1( "Text" );
69 const std::string text2( "< font face ='FreeSerif' color= 'green' >t< / font >" );
70 const std::string text3( "< font face = 'FreeSerif' size= '16' style = 'Bold' color='red'>< i><u >Styled< / u> Text< /i >< / font >< br / >" );
71 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/>" );
72 const std::string text5( "< shadow color = 'blue' paramx = '1' paramy = '0.75' >Shadow< / shadow><br />" );
73 const std::string text6( "<smooth param= '0.75' >< glow color = 'red' param = '0.1' >Glow</glow></smooth>< br />" );
74 const std::string text7( "<font color='green''>< outline color = 'red' paramx = '0.7' paramy = '0.7' >Outline< / outline >< /font >< br / >" );
75 const std::string text8( "<smooth param='0.75'>Smooth</smooth>< br / >" );
76 const std::string text9( "\\<" );
77 const std::string text10( "\\>" );
82 const std::string text11( crlf, 2 );
84 const std::string result1( text1 );
85 const std::string result2( "<font face='FreeSerif' color='green'>t</font>" );
86 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 />" );
87 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 />" );
88 const std::string result5( "<shadow color='blue' paramx='1' paramy='0.75'>Shadow</shadow><br />" );
89 const std::string result6( "<smooth param='0.75'><glow color='red' param='0.1'>Glow</glow></smooth><br />" );
90 const std::string result7( "<font color='green'><outline color='red' paramx='0.7' paramy='0.7'>Outline</outline></font><br />" );
91 const std::string result8( "<smooth param='0.75'>Smooth</smooth><br />" );
92 const std::string result9( text9 );
93 const std::string result10( text10 );
94 const std::string result11( "<br />" );
96 std::string markupString;
97 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
99 GetStyledTextArray( text1, styledTextArray, true );
100 GetMarkupString( styledTextArray, markupString );
101 DALI_TEST_EQUALS( result1, markupString, TEST_LOCATION );
103 GetStyledTextArray( text2, styledTextArray, true );
104 GetMarkupString( styledTextArray, markupString );
105 DALI_TEST_EQUALS( result2, markupString, TEST_LOCATION );
107 GetStyledTextArray( text3, styledTextArray, true );
108 GetMarkupString( styledTextArray, markupString );
109 DALI_TEST_EQUALS( result3, markupString, TEST_LOCATION );
111 GetStyledTextArray( text4, styledTextArray, true );
112 GetMarkupString( styledTextArray, markupString );
113 DALI_TEST_EQUALS( result4, markupString, TEST_LOCATION );
115 GetStyledTextArray( text5, styledTextArray, true );
116 GetMarkupString( styledTextArray, markupString );
117 DALI_TEST_EQUALS( result5, markupString, TEST_LOCATION );
119 GetStyledTextArray( text6, styledTextArray, true );
120 GetMarkupString( styledTextArray, markupString );
121 DALI_TEST_EQUALS( result6, markupString, TEST_LOCATION );
123 GetStyledTextArray( text7, styledTextArray, true );
124 GetMarkupString( styledTextArray, markupString );
125 DALI_TEST_EQUALS( result7, markupString, TEST_LOCATION );
127 GetStyledTextArray( text8, styledTextArray, true );
128 GetMarkupString( styledTextArray, markupString );
129 DALI_TEST_EQUALS( result8, markupString, TEST_LOCATION );
131 GetStyledTextArray( text9, styledTextArray, true );
132 GetMarkupString( styledTextArray, markupString );
133 DALI_TEST_EQUALS( result9, markupString, TEST_LOCATION );
135 GetStyledTextArray( text10, styledTextArray, true );
136 GetMarkupString( styledTextArray, markupString );
138 DALI_TEST_EQUALS( result10, markupString, TEST_LOCATION );
140 GetStyledTextArray( text11, styledTextArray, true );
141 GetMarkupString( styledTextArray, markupString );
143 DALI_TEST_EQUALS( result11, markupString, TEST_LOCATION );
147 int UtcDaliMarkupProcessorSetTextStyle01(void)
149 ToolkitTestApplication application;
151 tet_infoline(" UtcDaliMarkupProcessorSetTextStyle01 ");
153 const std::string text1( "Text with no defined style" );
154 const std::string result1( "<font color='green'><i>Text with no defined style</i></font>" );
155 const std::string result2( "Text with <font color='green'><i>no defined</i></font> style" );
157 std::string markupString;
158 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
160 GetStyledTextArray( text1, styledTextArray, true );
163 style.SetItalics( true );
164 style.SetTextColor( Color::GREEN );
166 SetTextStyle( styledTextArray, style );
167 GetMarkupString( styledTextArray, markupString );
169 DALI_TEST_EQUALS( result1, markupString, TEST_LOCATION );
171 styledTextArray.clear();
172 SetTextStyle( text1, styledTextArray, style );
173 GetMarkupString( styledTextArray, markupString );
175 DALI_TEST_EQUALS( result1, markupString, TEST_LOCATION );
177 GetStyledTextArray( text1, styledTextArray, true );
178 SetTextStyleToRange( styledTextArray, style, TextStyle::ALL, 0, text1.size() - 1 );
179 GetMarkupString( styledTextArray, markupString );
181 DALI_TEST_EQUALS( result1, markupString, TEST_LOCATION );
183 GetStyledTextArray( text1, styledTextArray, true );
184 SetTextStyleToRange( styledTextArray, style, TextStyle::ALL, 10, 19 );
185 GetMarkupString( styledTextArray, markupString );
187 DALI_TEST_EQUALS( result2, markupString, TEST_LOCATION );
189 std::string plainString;
190 GetPlainString( styledTextArray, plainString );
192 DALI_TEST_EQUALS( text1, plainString, TEST_LOCATION );
196 int UtcDaliMarkupProcessorSetTextStyle02(void)
198 ToolkitTestApplication application;
200 tet_infoline(" UtcDaliMarkupProcessorSetTextStyle02 ");
202 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
204 // Test style applied to and empty string doesn't crash
207 style.SetItalics( true );
208 style.SetTextColor( Color::GREEN );
213 SetTextStyle( styledTextArray, style );
220 DALI_TEST_CHECK( !fails );
224 int UtcDaliMarkupProcessorTestColors(void)
226 ToolkitTestApplication application;
228 tet_infoline("UtcDaliMarkupProcessorTestColors ");
230 struct MarkupStringTest colorTests[] =
233 std::string( "<font color='0xFF000000'>black</font>" ),
234 std::string( "<font color='black'>black</font>" )
237 std::string( "<font color='0xFFFFFFFF'>white</font>" ),
238 std::string( "white" )
241 std::string( "<font color='0xFFFF0000'>red</font>" ),
242 std::string( "<font color='red'>red</font>" )
245 std::string( "<font color='0xFF00FF00'>green</font>" ),
246 std::string( "<font color='green'>green</font>" )
249 std::string( "<font color='0xFF0000FF'>blue</font>" ),
250 std::string( "<font color='blue'>blue</font>" )
253 std::string( "<font color='0xFFFFFF00'>yellow</font>" ),
254 std::string( "<font color='yellow'>yellow</font>" )
257 std::string( "<font color='0xFFFF00FF'>magenta</font>" ),
258 std::string( "<font color='magenta'>magenta</font>" )
261 std::string( "<font color='0xFF00FFFF'>cyan</font>" ),
262 std::string( "<font color='cyan'>cyan</font>" )
265 std::string( "<font color='0x00000000'>transparent</font>" ),
266 std::string( "<font color='transparent'>transparent</font>" )
269 std::string( "<font color='#000000'>black</font>" ),
270 std::string( "<font color='black'>black</font>" )
273 std::string( "<font color='#FFFFFF'>white</font>" ),
274 std::string( "white" )
277 std::string( "<font color='#FF0000'>red</font>" ),
278 std::string( "<font color='red'>red</font>" )
281 std::string( "<font color='#00FF00'>green</font>" ),
282 std::string( "<font color='green'>green</font>" )
285 std::string( "<font color='#0000FF'>blue</font>" ),
286 std::string( "<font color='blue'>blue</font>" )
289 std::string( "<font color='#FFFF00'>yellow</font>" ),
290 std::string( "<font color='yellow'>yellow</font>" )
293 std::string( "<font color='#FF00FF'>magenta</font>" ),
294 std::string( "<font color='magenta'>magenta</font>" )
297 std::string( "<font color='#00FFFF'>cyan</font>" ),
298 std::string( "<font color='cyan'>cyan</font>" )
301 std::string( "<font color='#000'>black</font>" ),
302 std::string( "<font color='black'>black</font>" )
305 std::string( "<font color='#FFF'>white</font>" ),
306 std::string( "white" )
309 std::string( "<font color='#F00'>red</font>" ),
310 std::string( "<font color='red'>red</font>" )
313 std::string( "<font color='#0F0'>green</font>" ),
314 std::string( "<font color='green'>green</font>" )
317 std::string( "<font color='#00F'>blue</font>" ),
318 std::string( "<font color='blue'>blue</font>" )
321 std::string( "<font color='#FF0'>yellow</font>" ),
322 std::string( "<font color='yellow'>yellow</font>" )
325 std::string( "<font color='#F0F'>magenta</font>" ),
326 std::string( "<font color='magenta'>magenta</font>" )
329 std::string( "<font color='#0FF'>cyan</font>" ),
330 std::string( "<font color='cyan'>cyan</font>" )
333 std::string( "<font color='0x000000'>black</font>" ),
334 std::string( "<font color='black'>black</font>" )
337 std::string( "<font color='black'>black</font>" ),
338 std::string( "<font color='black'>black</font>" )
341 std::string( "<font color='white'>white</font>" ),
342 std::string( "white" )
345 std::string( "<font color='red'>red</font>" ),
346 std::string( "<font color='red'>red</font>" )
349 std::string( "<font color='0xFF00FF00'>green</font>" ),
350 std::string( "<font color='green'>green</font>" )
353 std::string( "<font color='blue'>blue</font>" ),
354 std::string( "<font color='blue'>blue</font>" )
357 std::string( "<font color='yellow'>yellow</font>" ),
358 std::string( "<font color='yellow'>yellow</font>" )
361 std::string( "<font color='magenta'>magenta</font>" ),
362 std::string( "<font color='magenta'>magenta</font>" )
365 std::string( "<font color='cyan'>cyan</font>" ),
366 std::string( "<font color='cyan'>cyan</font>" )
369 std::string( "<font color='transparent'>transparent</font>" ),
370 std::string( "<font color='transparent'>transparent</font>" )
373 std::string( "<outline color='white'>outline</outline>" ),
374 std::string( "<outline color='white'>outline</outline>" )
378 const std::size_t numberOfTests( 36 );
381 for( std::size_t index = 0; index < numberOfTests; ++index )
383 const MarkupStringTest& test = colorTests[index];
386 if( !TestMarkupString( test.input, test.expectedResult, result ) )
388 TestMarkupString( test.input, test.expectedResult, result );
389 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() );
395 DALI_TEST_CHECK( !fails );