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.
23 #include <dali/public-api/dali-core.h>
24 #include <dali-toolkit/public-api/markup-processor/markup-processor.h>
26 #include <dali-toolkit-test-suite-utils.h>
33 struct MarkupStringTest
36 std::string expectedResult;
39 bool TestMarkupString( const std::string& input, const std::string& expectedResult, std::string& result )
41 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
43 GetStyledTextArray( input, styledTextArray, true );
44 GetMarkupString( styledTextArray, result );
46 return expectedResult == result;
51 static void Startup();
52 static void Cleanup();
55 void (*tet_startup)() = Startup;
56 void (*tet_cleanup)() = Cleanup;
60 POSITIVE_TC_IDX = 0x01,
64 #define MAX_NUMBER_OF_TESTS 10000
66 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
69 // Add test functionality for all APIs in the class (Positive and Negative)
70 TEST_FUNCTION( UtcDaliMarkupProcessor, POSITIVE_TC_IDX );
71 TEST_FUNCTION( UtcDaliMarkupProcessorSetTextStyle01, POSITIVE_TC_IDX );
72 TEST_FUNCTION( UtcDaliMarkupProcessorSetTextStyle02, NEGATIVE_TC_IDX );
73 TEST_FUNCTION( UtcDaliMarkupProcessorTestColors, POSITIVE_TC_IDX );
76 // Called only once before first test is run.
81 // Called only once after last test is run
87 // Positive test case for a method
88 static void UtcDaliMarkupProcessor()
90 ToolkitTestApplication application;
92 tet_infoline(" UtcDaliMarkupProcessor ");
94 const std::string text1( "Text" );
95 const std::string text2( "< font face ='FreeSerif' color= 'green' >t< / font >" );
96 const std::string text3( "< font face = 'FreeSerif' size= '16' style = 'Bold' color='red'>< i><u >Styled< / u> Text< /i >< / font >< br / >" );
97 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/>" );
98 const std::string text5( "< shadow color = 'blue' paramx = '1' paramy = '0.75' >Shadow< / shadow><br />" );
99 const std::string text6( "<smooth param= '0.75' >< glow color = 'red' param = '0.1' >Glow</glow></smooth>< br />" );
100 const std::string text7( "<font color='green''>< outline color = 'red' paramx = '0.7' paramy = '0.7' >Outline< / outline >< /font >< br / >" );
101 const std::string text8( "<smooth param='0.75'>Smooth</smooth>< br / >" );
102 const std::string text9( "\\<" );
103 const std::string text10( "\\>" );
108 const std::string text11( crlf, 2 );
110 const std::string result1( text1 );
111 const std::string result2( "<font face='FreeSerif' color='green'>t</font>" );
112 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 />" );
113 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 />" );
114 const std::string result5( "<shadow color='blue' paramx='1' paramy='0.75'>Shadow</shadow><br />" );
115 const std::string result6( "<smooth param='0.75'><glow color='red' param='0.1'>Glow</glow></smooth><br />" );
116 const std::string result7( "<font color='green'><outline color='red' paramx='0.7' paramy='0.7'>Outline</outline></font><br />" );
117 const std::string result8( "<smooth param='0.75'>Smooth</smooth><br />" );
118 const std::string result9( text9 );
119 const std::string result10( text10 );
120 const std::string result11( "<br />" );
122 std::string markupString;
123 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
125 GetStyledTextArray( text1, styledTextArray, true );
126 GetMarkupString( styledTextArray, markupString );
127 DALI_TEST_EQUALS( result1, markupString, TEST_LOCATION );
129 GetStyledTextArray( text2, styledTextArray, true );
130 GetMarkupString( styledTextArray, markupString );
131 DALI_TEST_EQUALS( result2, markupString, TEST_LOCATION );
133 GetStyledTextArray( text3, styledTextArray, true );
134 GetMarkupString( styledTextArray, markupString );
135 DALI_TEST_EQUALS( result3, markupString, TEST_LOCATION );
137 GetStyledTextArray( text4, styledTextArray, true );
138 GetMarkupString( styledTextArray, markupString );
139 DALI_TEST_EQUALS( result4, markupString, TEST_LOCATION );
141 GetStyledTextArray( text5, styledTextArray, true );
142 GetMarkupString( styledTextArray, markupString );
143 DALI_TEST_EQUALS( result5, markupString, TEST_LOCATION );
145 GetStyledTextArray( text6, styledTextArray, true );
146 GetMarkupString( styledTextArray, markupString );
147 DALI_TEST_EQUALS( result6, markupString, TEST_LOCATION );
149 GetStyledTextArray( text7, styledTextArray, true );
150 GetMarkupString( styledTextArray, markupString );
151 DALI_TEST_EQUALS( result7, markupString, TEST_LOCATION );
153 GetStyledTextArray( text8, styledTextArray, true );
154 GetMarkupString( styledTextArray, markupString );
155 DALI_TEST_EQUALS( result8, markupString, TEST_LOCATION );
157 GetStyledTextArray( text9, styledTextArray, true );
158 GetMarkupString( styledTextArray, markupString );
159 DALI_TEST_EQUALS( result9, markupString, TEST_LOCATION );
161 GetStyledTextArray( text10, styledTextArray, true );
162 GetMarkupString( styledTextArray, markupString );
164 DALI_TEST_EQUALS( result10, markupString, TEST_LOCATION );
166 GetStyledTextArray( text11, styledTextArray, true );
167 GetMarkupString( styledTextArray, markupString );
169 DALI_TEST_EQUALS( result11, markupString, TEST_LOCATION );
172 static void UtcDaliMarkupProcessorSetTextStyle01()
174 ToolkitTestApplication application;
176 tet_infoline(" UtcDaliMarkupProcessorSetTextStyle01 ");
178 const std::string text1( "Text with no defined style" );
179 const std::string result1( "<font color='green'><i>Text with no defined style</i></font>" );
180 const std::string result2( "Text with <font color='green'><i>no defined</i></font> style" );
182 std::string markupString;
183 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
185 GetStyledTextArray( text1, styledTextArray, true );
188 style.SetItalics( true );
189 style.SetTextColor( Color::GREEN );
191 SetTextStyle( styledTextArray, style );
192 GetMarkupString( styledTextArray, markupString );
194 DALI_TEST_EQUALS( result1, markupString, TEST_LOCATION );
196 styledTextArray.clear();
197 SetTextStyle( text1, styledTextArray, style );
198 GetMarkupString( styledTextArray, markupString );
200 DALI_TEST_EQUALS( result1, markupString, TEST_LOCATION );
202 GetStyledTextArray( text1, styledTextArray, true );
203 SetTextStyleToRange( styledTextArray, style, TextStyle::ALL, 0, text1.size() - 1 );
204 GetMarkupString( styledTextArray, markupString );
206 DALI_TEST_EQUALS( result1, markupString, TEST_LOCATION );
208 GetStyledTextArray( text1, styledTextArray, true );
209 SetTextStyleToRange( styledTextArray, style, TextStyle::ALL, 10, 19 );
210 GetMarkupString( styledTextArray, markupString );
212 DALI_TEST_EQUALS( result2, markupString, TEST_LOCATION );
214 std::string plainString;
215 GetPlainString( styledTextArray, plainString );
217 DALI_TEST_EQUALS( text1, plainString, TEST_LOCATION );
220 static void UtcDaliMarkupProcessorSetTextStyle02()
222 ToolkitTestApplication application;
224 tet_infoline(" UtcDaliMarkupProcessorSetTextStyle02 ");
226 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
228 // Test style applied to and empty string doesn't crash
231 style.SetItalics( true );
232 style.SetTextColor( Color::GREEN );
237 SetTextStyle( styledTextArray, style );
244 DALI_TEST_CHECK( !fails );
247 static void UtcDaliMarkupProcessorTestColors()
249 ToolkitTestApplication application;
251 tet_infoline("UtcDaliMarkupProcessorTestColors ");
253 struct MarkupStringTest colorTests[] =
256 std::string( "<font color='0xFF000000'>black</font>" ),
257 std::string( "<font color='black'>black</font>" )
260 std::string( "<font color='0xFFFFFFFF'>white</font>" ),
261 std::string( "white" )
264 std::string( "<font color='0xFFFF0000'>red</font>" ),
265 std::string( "<font color='red'>red</font>" )
268 std::string( "<font color='0xFF00FF00'>green</font>" ),
269 std::string( "<font color='green'>green</font>" )
272 std::string( "<font color='0xFF0000FF'>blue</font>" ),
273 std::string( "<font color='blue'>blue</font>" )
276 std::string( "<font color='0xFFFFFF00'>yellow</font>" ),
277 std::string( "<font color='yellow'>yellow</font>" )
280 std::string( "<font color='0xFFFF00FF'>magenta</font>" ),
281 std::string( "<font color='magenta'>magenta</font>" )
284 std::string( "<font color='0xFF00FFFF'>cyan</font>" ),
285 std::string( "<font color='cyan'>cyan</font>" )
288 std::string( "<font color='0x00000000'>transparent</font>" ),
289 std::string( "<font color='transparent'>transparent</font>" )
292 std::string( "<font color='#000000'>black</font>" ),
293 std::string( "<font color='black'>black</font>" )
296 std::string( "<font color='#FFFFFF'>white</font>" ),
297 std::string( "white" )
300 std::string( "<font color='#FF0000'>red</font>" ),
301 std::string( "<font color='red'>red</font>" )
304 std::string( "<font color='#00FF00'>green</font>" ),
305 std::string( "<font color='green'>green</font>" )
308 std::string( "<font color='#0000FF'>blue</font>" ),
309 std::string( "<font color='blue'>blue</font>" )
312 std::string( "<font color='#FFFF00'>yellow</font>" ),
313 std::string( "<font color='yellow'>yellow</font>" )
316 std::string( "<font color='#FF00FF'>magenta</font>" ),
317 std::string( "<font color='magenta'>magenta</font>" )
320 std::string( "<font color='#00FFFF'>cyan</font>" ),
321 std::string( "<font color='cyan'>cyan</font>" )
324 std::string( "<font color='#000'>black</font>" ),
325 std::string( "<font color='black'>black</font>" )
328 std::string( "<font color='#FFF'>white</font>" ),
329 std::string( "white" )
332 std::string( "<font color='#F00'>red</font>" ),
333 std::string( "<font color='red'>red</font>" )
336 std::string( "<font color='#0F0'>green</font>" ),
337 std::string( "<font color='green'>green</font>" )
340 std::string( "<font color='#00F'>blue</font>" ),
341 std::string( "<font color='blue'>blue</font>" )
344 std::string( "<font color='#FF0'>yellow</font>" ),
345 std::string( "<font color='yellow'>yellow</font>" )
348 std::string( "<font color='#F0F'>magenta</font>" ),
349 std::string( "<font color='magenta'>magenta</font>" )
352 std::string( "<font color='#0FF'>cyan</font>" ),
353 std::string( "<font color='cyan'>cyan</font>" )
356 std::string( "<font color='0x000000'>black</font>" ),
357 std::string( "<font color='black'>black</font>" )
360 std::string( "<font color='black'>black</font>" ),
361 std::string( "<font color='black'>black</font>" )
364 std::string( "<font color='white'>white</font>" ),
365 std::string( "white" )
368 std::string( "<font color='red'>red</font>" ),
369 std::string( "<font color='red'>red</font>" )
372 std::string( "<font color='0xFF00FF00'>green</font>" ),
373 std::string( "<font color='green'>green</font>" )
376 std::string( "<font color='blue'>blue</font>" ),
377 std::string( "<font color='blue'>blue</font>" )
380 std::string( "<font color='yellow'>yellow</font>" ),
381 std::string( "<font color='yellow'>yellow</font>" )
384 std::string( "<font color='magenta'>magenta</font>" ),
385 std::string( "<font color='magenta'>magenta</font>" )
388 std::string( "<font color='cyan'>cyan</font>" ),
389 std::string( "<font color='cyan'>cyan</font>" )
392 std::string( "<font color='transparent'>transparent</font>" ),
393 std::string( "<font color='transparent'>transparent</font>" )
396 std::string( "<outline color='white'>outline</outline>" ),
397 std::string( "<outline color='white'>outline</outline>" )
401 const std::size_t numberOfTests( 36 );
404 for( std::size_t index = 0; index < numberOfTests; ++index )
406 const MarkupStringTest& test = colorTests[index];
409 if( !TestMarkupString( test.input, test.expectedResult, result ) )
411 TestMarkupString( test.input, test.expectedResult, result );
412 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() );
418 DALI_TEST_CHECK( !fails );