From fc948f524532083d94024f560da3749819125383 Mon Sep 17 00:00:00 2001 From: Victor Cebollada Date: Wed, 6 May 2015 09:08:06 +0100 Subject: [PATCH] UTC added for Text, Segmentation. Change-Id: Icccc1ca3d0f2426622a0f81ca93f07884af25582 Signed-off-by: Victor Cebollada --- .../src/dali-toolkit-internal/CMakeLists.txt | 1 + .../utc-Dali-Text-Segmentation.cpp | 219 +++++++++++++++++++++ 2 files changed, 220 insertions(+) create mode 100644 automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Segmentation.cpp diff --git a/automated-tests/src/dali-toolkit-internal/CMakeLists.txt b/automated-tests/src/dali-toolkit-internal/CMakeLists.txt index f7500ac..c3b14ab 100644 --- a/automated-tests/src/dali-toolkit-internal/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit-internal/CMakeLists.txt @@ -9,6 +9,7 @@ SET(CAPI_LIB "dali-toolkit-internal") SET(TC_SOURCES utc-Dali-PushButton.cpp utc-Dali-Text-CharacterSetConversion.cpp + utc-Dali-Text-Segmentation.cpp ) # Append list of test harness files (Won't get parsed for test cases) diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Segmentation.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Segmentation.cpp new file mode 100644 index 0000000..2e60ee5 --- /dev/null +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Segmentation.cpp @@ -0,0 +1,219 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include + +#include +#include +#include +#include +#include + + +using namespace Dali; +using namespace Toolkit; +using namespace Text; + +// Tests the following functions with different scripts. +// void SetLineBreakInfo( const Vector& text, Vector& lineBreakInfo ); +// void SetWordBreakInfo( const Vector& text, Vector& wordBreakInfo ); + +////////////////////////////////////////////////////////// + +namespace +{ + +struct BreakInfoData +{ + std::string description; ///< Description of the test. + std::string text; ///< input text. + std::string breakInfo; ///< The expected break info. +}; + +bool LineBreakInfoTest( const BreakInfoData& data ) +{ + // 1) Convert to utf32 + Vector utf32; + utf32.Resize( data.text.size() ); + + const uint32_t numberOfCharacters = Utf8ToUtf32( reinterpret_cast( data.text.c_str() ), + data.text.size(), + &utf32[0u] ); + utf32.Resize( numberOfCharacters ); + + // 2) Set the line break info. + Vector lineBreakInfo; + lineBreakInfo.Resize( numberOfCharacters ); + + SetLineBreakInfo( utf32, lineBreakInfo ); + + // 3) compare the results + std::ostringstream breakInfo; + + for( unsigned int index = 0u; index < numberOfCharacters; ++index ) + { + breakInfo << static_cast( lineBreakInfo[index] ); + } + + return data.breakInfo == breakInfo.str(); +} + +bool WordBreakInfoTest( const BreakInfoData& data ) +{ + // 1) Convert to utf32 + Vector utf32; + utf32.Resize( data.text.size() ); + + const uint32_t numberOfCharacters = Utf8ToUtf32( reinterpret_cast( data.text.c_str() ), + data.text.size(), + &utf32[0u] ); + utf32.Resize( numberOfCharacters ); + + // 2) Set the word break info. + Vector wordBreakInfo; + wordBreakInfo.Resize( numberOfCharacters ); + + SetWordBreakInfo( utf32, wordBreakInfo ); + + // 3) compare the results + std::ostringstream breakInfo; + + for( unsigned int index = 0u; index < numberOfCharacters; ++index ) + { + breakInfo << static_cast( wordBreakInfo[index] ); + } + + return data.breakInfo == breakInfo.str(); +} + +} // namespace + +////////////////////////////////////////////////////////// + +int UtcDaliTextSegnemtationSetLineBreakInfo(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextSegnemtationSetLineBreakInfo"); + + struct BreakInfoData data[] = + { + { + "Zero characters", + "", + "", + }, + { + "Latin script", + "Hello world", + "22222122220", + }, + { + "Latin script with \n", + "Hello\nworld", + "22222022220", + }, + { + "Japanese script", + "こんにちは世界", + "1111110", + }, + { + "Japanese script with \n", + "こんにちは\n世界", + "11112010", + }, + { + "Chinese script", + "你好世界", + "1110", + }, + { + "Chinese script with \n", + "你好\n世界", + "12010", + } + }; + const unsigned int numberOfTests = 7u; + + for( unsigned int index = 0u; index < numberOfTests; ++index ) + { + if( !LineBreakInfoTest( data[index] ) ) + { + tet_result(TET_FAIL); + } + } + + tet_result(TET_PASS); + END_TEST; +} + +int UtcDaliTextSegnemtationSetWordBreakInfo(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextSegnemtationSetWordBreakInfo"); + + struct BreakInfoData data[] = + { + { + "Zero characters", + "", + "", + }, + { + "Latin script", + "Hello world", + "11110011110", + }, + { + "Latin script with \n", + "Hello\nworld", + "11110011110", + }, + { + "Japanese script", + "こんにちは世界", + "0000000", + }, + { + "Japanese script with \n", + "こんにちは\n世界", + "00000000", + }, + { + "Chinese script", + "你好世界", + "0000", + }, + { + "Chinese script with \n", + "你好\n世界", + "00000", + } + }; + const unsigned int numberOfTests = 7u; + + for( unsigned int index = 0u; index < numberOfTests; ++index ) + { + if( !WordBreakInfoTest( data[index] ) ) + { + tet_result(TET_FAIL); + } + } + + tet_result(TET_PASS); + END_TEST; +} -- 2.7.4