2 * Copyright (c) 2015 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 #include <dali-toolkit/internal/text/character-set-conversion.h>
22 #include <dali-toolkit/internal/text/segmentation.h>
23 #include <dali-toolkit-test-suite-utils.h>
24 #include <dali-toolkit/dali-toolkit.h>
28 using namespace Toolkit;
31 // Tests the following functions with different scripts.
32 // void SetLineBreakInfo( const Vector<Character>& text, Vector<LineBreakInfo>& lineBreakInfo );
33 // void SetWordBreakInfo( const Vector<Character>& text, Vector<WordBreakInfo>& wordBreakInfo );
35 //////////////////////////////////////////////////////////
42 std::string description; ///< Description of the test.
43 std::string text; ///< input text.
44 std::string breakInfo; ///< The expected break info.
47 bool LineBreakInfoTest( const BreakInfoData& data )
49 // 1) Convert to utf32
50 Vector<Character> utf32;
51 utf32.Resize( data.text.size() );
53 const uint32_t numberOfCharacters = Utf8ToUtf32( reinterpret_cast<const uint8_t* const>( data.text.c_str() ),
56 utf32.Resize( numberOfCharacters );
58 // 2) Set the line break info.
59 Vector<LineBreakInfo> lineBreakInfo;
60 lineBreakInfo.Resize( numberOfCharacters );
62 SetLineBreakInfo( utf32, lineBreakInfo );
64 // 3) compare the results
65 std::ostringstream breakInfo;
67 for( unsigned int index = 0u; index < numberOfCharacters; ++index )
69 breakInfo << static_cast<unsigned int>( lineBreakInfo[index] );
72 return data.breakInfo == breakInfo.str();
75 bool WordBreakInfoTest( const BreakInfoData& data )
77 // 1) Convert to utf32
78 Vector<Character> utf32;
79 utf32.Resize( data.text.size() );
81 const uint32_t numberOfCharacters = Utf8ToUtf32( reinterpret_cast<const uint8_t* const>( data.text.c_str() ),
84 utf32.Resize( numberOfCharacters );
86 // 2) Set the word break info.
87 Vector<WordBreakInfo> wordBreakInfo;
88 wordBreakInfo.Resize( numberOfCharacters );
90 SetWordBreakInfo( utf32, wordBreakInfo );
92 // 3) compare the results
93 std::ostringstream breakInfo;
95 for( unsigned int index = 0u; index < numberOfCharacters; ++index )
97 breakInfo << static_cast<unsigned int>( wordBreakInfo[index] );
100 return data.breakInfo == breakInfo.str();
105 //////////////////////////////////////////////////////////
107 int UtcDaliTextSegnemtationSetLineBreakInfo(void)
109 ToolkitTestApplication application;
110 tet_infoline(" UtcDaliTextSegnemtationSetLineBreakInfo");
112 struct BreakInfoData data[] =
125 "Latin script with \n",
135 "Japanese script with \n",
145 "Chinese script with \n",
150 const unsigned int numberOfTests = 7u;
152 for( unsigned int index = 0u; index < numberOfTests; ++index )
154 if( !LineBreakInfoTest( data[index] ) )
156 tet_result(TET_FAIL);
160 tet_result(TET_PASS);
164 int UtcDaliTextSegnemtationSetWordBreakInfo(void)
166 ToolkitTestApplication application;
167 tet_infoline(" UtcDaliTextSegnemtationSetWordBreakInfo");
169 struct BreakInfoData data[] =
182 "Latin script with \n",
192 "Japanese script with \n",
202 "Chinese script with \n",
207 const unsigned int numberOfTests = 7u;
209 for( unsigned int index = 0u; index < numberOfTests; ++index )
211 if( !WordBreakInfoTest( data[index] ) )
213 tet_result(TET_FAIL);
217 tet_result(TET_PASS);