UTC added for Text, Segmentation. 10/41210/1
authorVictor Cebollada <v.cebollada@samsung.com>
Wed, 6 May 2015 08:08:06 +0000 (09:08 +0100)
committerVictor Cebollada <v.cebollada@samsung.com>
Thu, 11 Jun 2015 15:40:43 +0000 (16:40 +0100)
Change-Id: Icccc1ca3d0f2426622a0f81ca93f07884af25582
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
automated-tests/src/dali-toolkit-internal/CMakeLists.txt
automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Segmentation.cpp [new file with mode: 0644]

index f7500ac..c3b14ab 100644 (file)
@@ -9,6 +9,7 @@ SET(CAPI_LIB "dali-toolkit-internal")
 SET(TC_SOURCES
  utc-Dali-PushButton.cpp
  utc-Dali-Text-CharacterSetConversion.cpp
 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)
 )
 
 # 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 (file)
index 0000000..2e60ee5
--- /dev/null
@@ -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 <iostream>
+
+#include <stdlib.h>
+#include <dali-toolkit/internal/text/character-set-conversion.h>
+#include <dali-toolkit/internal/text/segmentation.h>
+#include <dali-toolkit-test-suite-utils.h>
+#include <dali-toolkit/dali-toolkit.h>
+
+
+using namespace Dali;
+using namespace Toolkit;
+using namespace Text;
+
+// Tests the following functions with different scripts.
+// void SetLineBreakInfo( const Vector<Character>& text, Vector<LineBreakInfo>& lineBreakInfo );
+// void SetWordBreakInfo( const Vector<Character>& text, Vector<WordBreakInfo>& 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<Character> utf32;
+  utf32.Resize( data.text.size() );
+
+  const uint32_t numberOfCharacters = Utf8ToUtf32( reinterpret_cast<const uint8_t* const>( data.text.c_str() ),
+                                                   data.text.size(),
+                                                   &utf32[0u] );
+  utf32.Resize( numberOfCharacters );
+
+  // 2) Set the line break info.
+  Vector<LineBreakInfo> 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<unsigned int>( lineBreakInfo[index] );
+  }
+
+  return data.breakInfo == breakInfo.str();
+}
+
+bool WordBreakInfoTest( const BreakInfoData& data )
+{
+  // 1) Convert to utf32
+  Vector<Character> utf32;
+  utf32.Resize( data.text.size() );
+
+  const uint32_t numberOfCharacters = Utf8ToUtf32( reinterpret_cast<const uint8_t* const>( data.text.c_str() ),
+                                                   data.text.size(),
+                                                   &utf32[0u] );
+  utf32.Resize( numberOfCharacters );
+
+  // 2) Set the word break info.
+  Vector<WordBreakInfo> 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<unsigned int>( 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;
+}