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/markup-processor/markup-processor.h>
25 #include <dali-toolkit-test-suite-utils.h>
32 struct MarkupStringTest
35 std::string expectedResult;
38 bool TestMarkupString( const std::string& input, const std::string& expectedResult, std::string& result )
40 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
42 GetStyledTextArray( input, styledTextArray, true );
43 GetMarkupString( styledTextArray, result );
45 return expectedResult == result;
50 static void Startup();
51 static void Cleanup();
54 void (*tet_startup)() = Startup;
55 void (*tet_cleanup)() = Cleanup;
59 POSITIVE_TC_IDX = 0x01,
63 #define MAX_NUMBER_OF_TESTS 10000
65 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
68 // Add test functionality for all APIs in the class (Positive and Negative)
69 TEST_FUNCTION( UtcDaliMarkupProcessor, POSITIVE_TC_IDX );
70 TEST_FUNCTION( UtcDaliMarkupProcessorSetTextStyle01, POSITIVE_TC_IDX );
71 TEST_FUNCTION( UtcDaliMarkupProcessorSetTextStyle02, NEGATIVE_TC_IDX );
72 TEST_FUNCTION( UtcDaliMarkupProcessorTestColors, POSITIVE_TC_IDX );
75 // Called only once before first test is run.
80 // Called only once after last test is run
86 // Positive test case for a method
87 static void UtcDaliMarkupProcessor()
89 ToolkitTestApplication application;
91 tet_infoline(" UtcDaliMarkupProcessor ");
93 const std::string text1( "Text" );
94 const std::string text2( "< font face ='FreeSerif' color= 'green' >t< / font >" );
95 const std::string text3( "< font face = 'FreeSerif' size= '16' style = 'Bold' color='red'>< i><u >Styled< / u> Text< /i >< / font >< br / >" );
96 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/>" );
97 const std::string text5( "< shadow color = 'blue' paramx = '1' paramy = '0.75' >Shadow< / shadow><br />" );
98 const std::string text6( "<smooth param= '0.75' >< glow color = 'red' param = '0.1' >Glow</glow></smooth>< br />" );
99 const std::string text7( "<font color='green''>< outline color = 'red' paramx = '0.7' paramy = '0.7' >Outline< / outline >< /font >< br / >" );
100 const std::string text8( "<smooth param='0.75'>Smooth</smooth>< br / >" );
101 const std::string text9( "\\<" );
102 const std::string text10( "\\>" );
107 const std::string text11( crlf, 2 );
109 const std::string result1( text1 );
110 const std::string result2( "<font face='FreeSerif' color='green'>t</font>" );
111 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 />" );
112 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 />" );
113 const std::string result5( "<shadow color='blue' paramx='1' paramy='0.75'>Shadow</shadow><br />" );
114 const std::string result6( "<smooth param='0.75'><glow color='red' param='0.1'>Glow</glow></smooth><br />" );
115 const std::string result7( "<font color='green'><outline color='red' paramx='0.7' paramy='0.7'>Outline</outline></font><br />" );
116 const std::string result8( "<smooth param='0.75'>Smooth</smooth><br />" );
117 const std::string result9( text9 );
118 const std::string result10( text10 );
119 const std::string result11( "<br />" );
121 std::string markupString;
122 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
124 GetStyledTextArray( text1, styledTextArray, true );
125 GetMarkupString( styledTextArray, markupString );
126 DALI_TEST_EQUALS( result1, markupString, TEST_LOCATION );
128 GetStyledTextArray( text2, styledTextArray, true );
129 GetMarkupString( styledTextArray, markupString );
130 DALI_TEST_EQUALS( result2, markupString, TEST_LOCATION );
132 GetStyledTextArray( text3, styledTextArray, true );
133 GetMarkupString( styledTextArray, markupString );
134 DALI_TEST_EQUALS( result3, markupString, TEST_LOCATION );
136 GetStyledTextArray( text4, styledTextArray, true );
137 GetMarkupString( styledTextArray, markupString );
138 DALI_TEST_EQUALS( result4, markupString, TEST_LOCATION );
140 GetStyledTextArray( text5, styledTextArray, true );
141 GetMarkupString( styledTextArray, markupString );
142 DALI_TEST_EQUALS( result5, markupString, TEST_LOCATION );
144 GetStyledTextArray( text6, styledTextArray, true );
145 GetMarkupString( styledTextArray, markupString );
146 DALI_TEST_EQUALS( result6, markupString, TEST_LOCATION );
148 GetStyledTextArray( text7, styledTextArray, true );
149 GetMarkupString( styledTextArray, markupString );
150 DALI_TEST_EQUALS( result7, markupString, TEST_LOCATION );
152 GetStyledTextArray( text8, styledTextArray, true );
153 GetMarkupString( styledTextArray, markupString );
154 DALI_TEST_EQUALS( result8, markupString, TEST_LOCATION );
156 GetStyledTextArray( text9, styledTextArray, true );
157 GetMarkupString( styledTextArray, markupString );
158 DALI_TEST_EQUALS( result9, markupString, TEST_LOCATION );
160 GetStyledTextArray( text10, styledTextArray, true );
161 GetMarkupString( styledTextArray, markupString );
163 DALI_TEST_EQUALS( result10, markupString, TEST_LOCATION );
165 GetStyledTextArray( text11, styledTextArray, true );
166 GetMarkupString( styledTextArray, markupString );
168 DALI_TEST_EQUALS( result11, markupString, TEST_LOCATION );
171 static void UtcDaliMarkupProcessorSetTextStyle01()
173 ToolkitTestApplication application;
175 tet_infoline(" UtcDaliMarkupProcessorSetTextStyle01 ");
177 const std::string text1( "Text with no defined style" );
178 const std::string result1( "<font color='green'><i>Text with no defined style</i></font>" );
179 const std::string result2( "Text with <font color='green'><i>no defined</i></font> style" );
181 std::string markupString;
182 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
184 GetStyledTextArray( text1, styledTextArray, true );
187 style.SetItalics( true );
188 style.SetTextColor( Color::GREEN );
190 SetTextStyle( styledTextArray, style );
191 GetMarkupString( styledTextArray, markupString );
193 DALI_TEST_EQUALS( result1, markupString, TEST_LOCATION );
195 styledTextArray.clear();
196 SetTextStyle( text1, styledTextArray, style );
197 GetMarkupString( styledTextArray, markupString );
199 DALI_TEST_EQUALS( result1, markupString, TEST_LOCATION );
201 GetStyledTextArray( text1, styledTextArray, true );
202 SetTextStyleToRange( styledTextArray, style, TextStyle::ALL, 0, text1.size() - 1 );
203 GetMarkupString( styledTextArray, markupString );
205 DALI_TEST_EQUALS( result1, markupString, TEST_LOCATION );
207 GetStyledTextArray( text1, styledTextArray, true );
208 SetTextStyleToRange( styledTextArray, style, TextStyle::ALL, 10, 19 );
209 GetMarkupString( styledTextArray, markupString );
211 DALI_TEST_EQUALS( result2, markupString, TEST_LOCATION );
213 std::string plainString;
214 GetPlainString( styledTextArray, plainString );
216 DALI_TEST_EQUALS( text1, plainString, TEST_LOCATION );
219 static void UtcDaliMarkupProcessorSetTextStyle02()
221 ToolkitTestApplication application;
223 tet_infoline(" UtcDaliMarkupProcessorSetTextStyle02 ");
225 Toolkit::MarkupProcessor::StyledTextArray styledTextArray;
227 // Test style applied to and empty string doesn't crash
230 style.SetItalics( true );
231 style.SetTextColor( Color::GREEN );
236 SetTextStyle( styledTextArray, style );
243 DALI_TEST_CHECK( !fails );
246 static void UtcDaliMarkupProcessorTestColors()
248 ToolkitTestApplication application;
250 tet_infoline("UtcDaliMarkupProcessorTestColors ");
252 struct MarkupStringTest colorTests[] =
255 std::string( "<font color='0xFF000000'>black</font>" ),
256 std::string( "<font color='black'>black</font>" )
259 std::string( "<font color='0xFFFFFFFF'>white</font>" ),
260 std::string( "white" )
263 std::string( "<font color='0xFFFF0000'>red</font>" ),
264 std::string( "<font color='red'>red</font>" )
267 std::string( "<font color='0xFF00FF00'>green</font>" ),
268 std::string( "<font color='green'>green</font>" )
271 std::string( "<font color='0xFF0000FF'>blue</font>" ),
272 std::string( "<font color='blue'>blue</font>" )
275 std::string( "<font color='0xFFFFFF00'>yellow</font>" ),
276 std::string( "<font color='yellow'>yellow</font>" )
279 std::string( "<font color='0xFFFF00FF'>magenta</font>" ),
280 std::string( "<font color='magenta'>magenta</font>" )
283 std::string( "<font color='0xFF00FFFF'>cyan</font>" ),
284 std::string( "<font color='cyan'>cyan</font>" )
287 std::string( "<font color='0x00000000'>transparent</font>" ),
288 std::string( "<font color='transparent'>transparent</font>" )
291 std::string( "<font color='#000000'>black</font>" ),
292 std::string( "<font color='black'>black</font>" )
295 std::string( "<font color='#FFFFFF'>white</font>" ),
296 std::string( "white" )
299 std::string( "<font color='#FF0000'>red</font>" ),
300 std::string( "<font color='red'>red</font>" )
303 std::string( "<font color='#00FF00'>green</font>" ),
304 std::string( "<font color='green'>green</font>" )
307 std::string( "<font color='#0000FF'>blue</font>" ),
308 std::string( "<font color='blue'>blue</font>" )
311 std::string( "<font color='#FFFF00'>yellow</font>" ),
312 std::string( "<font color='yellow'>yellow</font>" )
315 std::string( "<font color='#FF00FF'>magenta</font>" ),
316 std::string( "<font color='magenta'>magenta</font>" )
319 std::string( "<font color='#00FFFF'>cyan</font>" ),
320 std::string( "<font color='cyan'>cyan</font>" )
323 std::string( "<font color='#000'>black</font>" ),
324 std::string( "<font color='black'>black</font>" )
327 std::string( "<font color='#FFF'>white</font>" ),
328 std::string( "white" )
331 std::string( "<font color='#F00'>red</font>" ),
332 std::string( "<font color='red'>red</font>" )
335 std::string( "<font color='#0F0'>green</font>" ),
336 std::string( "<font color='green'>green</font>" )
339 std::string( "<font color='#00F'>blue</font>" ),
340 std::string( "<font color='blue'>blue</font>" )
343 std::string( "<font color='#FF0'>yellow</font>" ),
344 std::string( "<font color='yellow'>yellow</font>" )
347 std::string( "<font color='#F0F'>magenta</font>" ),
348 std::string( "<font color='magenta'>magenta</font>" )
351 std::string( "<font color='#0FF'>cyan</font>" ),
352 std::string( "<font color='cyan'>cyan</font>" )
355 std::string( "<font color='0x000000'>black</font>" ),
356 std::string( "<font color='black'>black</font>" )
359 std::string( "<font color='black'>black</font>" ),
360 std::string( "<font color='black'>black</font>" )
363 std::string( "<font color='white'>white</font>" ),
364 std::string( "white" )
367 std::string( "<font color='red'>red</font>" ),
368 std::string( "<font color='red'>red</font>" )
371 std::string( "<font color='0xFF00FF00'>green</font>" ),
372 std::string( "<font color='green'>green</font>" )
375 std::string( "<font color='blue'>blue</font>" ),
376 std::string( "<font color='blue'>blue</font>" )
379 std::string( "<font color='yellow'>yellow</font>" ),
380 std::string( "<font color='yellow'>yellow</font>" )
383 std::string( "<font color='magenta'>magenta</font>" ),
384 std::string( "<font color='magenta'>magenta</font>" )
387 std::string( "<font color='cyan'>cyan</font>" ),
388 std::string( "<font color='cyan'>cyan</font>" )
391 std::string( "<font color='transparent'>transparent</font>" ),
392 std::string( "<font color='transparent'>transparent</font>" )
395 std::string( "<outline color='white'>outline</outline>" ),
396 std::string( "<outline color='white'>outline</outline>" )
400 const std::size_t numberOfTests( 36 );
403 for( std::size_t index = 0; index < numberOfTests; ++index )
405 const MarkupStringTest& test = colorTests[index];
408 if( !TestMarkupString( test.input, test.expectedResult, result ) )
410 TestMarkupString( test.input, test.expectedResult, result );
411 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() );
417 DALI_TEST_CHECK( !fails );