Merge changes Icccc1ca3,Ia32ce8ab into devel/master
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 11 Jun 2015 16:15:57 +0000 (09:15 -0700)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Thu, 11 Jun 2015 16:15:57 +0000 (09:15 -0700)
* changes:
  UTC added for Text, Segmentation.
  UTC added for Text, CharacterSetConversion.

automated-tests/src/dali-toolkit-internal/CMakeLists.txt
automated-tests/src/dali-toolkit-internal/utc-Dali-Text-CharacterSetConversion.cpp [new file with mode: 0644]
automated-tests/src/dali-toolkit-internal/utc-Dali-Text-Segmentation.cpp [new file with mode: 0644]
dali-toolkit/internal/text/character-set-conversion.cpp
dali-toolkit/internal/text/character-set-conversion.h

index 8011f6a..c3b14ab 100644 (file)
@@ -8,6 +8,8 @@ SET(CAPI_LIB "dali-toolkit-internal")
 # List of test case sources (Only these get parsed for test cases)
 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-CharacterSetConversion.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Text-CharacterSetConversion.cpp
new file mode 100644 (file)
index 0000000..9f816ef
--- /dev/null
@@ -0,0 +1,315 @@
+/*
+ * 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-test-suite-utils.h>
+#include <dali-toolkit/dali-toolkit.h>
+
+
+using namespace Dali;
+using namespace Toolkit;
+using namespace Text;
+
+// Tests the following functions for scripts with different number of bytes per character.
+// Latin 1 byte per character, Arabic 2 bytes per character, Devanagari 3 bytes per character and emojis 4 bytes per character.
+//
+// uint32_t GetNumberOfUtf8Characters( const uint8_t* const utf8, uint32_t length );
+// uint32_t GetNumberOfUtf8Bytes( const uint32_t* const utf32, uint32_t numberOfCharacters );
+// uint32_t Utf8ToUtf32( const uint8_t* const utf8, uint32_t length, uint32_t* utf32 );
+// uint32_t Utf32ToUtf8( const uint32_t* const utf32, uint32_t numberOfCharacters, uint8_t* utf8 );
+//     void Utf32ToUtf8( const uint32_t* const utf32, uint32_t numberOfCharacters, std::string& utf8 );
+//
+
+//////////////////////////////////////////////////////////
+
+namespace
+{
+
+struct GetNumberOfUtf8CharactersData
+{
+  std::string  description;        ///< Description of the test.
+  std::string  text;               ///< input text.
+  unsigned int numberOfCharacters; ///< The expected number of characters.
+};
+
+bool GetNumberOfUtf8CharactersTest( const GetNumberOfUtf8CharactersData& data )
+{
+  return GetNumberOfUtf8Characters( reinterpret_cast<const uint8_t*>( data.text.c_str() ), data.text.size() ) == data.numberOfCharacters;
+}
+
+//////////////////////////////////////////////////////////
+
+struct GetNumberOfUtf8BytesData
+{
+  std::string   description;        ///< Description of the test.
+  unsigned int* utf32;              ///< input text in utf32.
+  unsigned int  numberOfCharacters; ///< The number of characters.
+  unsigned int  numberOfBytes;      ///< The expected number of bytes in utf8.
+};
+
+bool GetNumberOfUtf8BytesTest( const GetNumberOfUtf8BytesData& data )
+{
+  return GetNumberOfUtf8Bytes( data.utf32, data.numberOfCharacters ) == data.numberOfBytes;
+}
+
+//////////////////////////////////////////////////////////
+
+struct Utf8ToUtf32Data
+{
+  std::string   description; ///< Description of the test.
+  std::string   text;        ///< input text.
+  unsigned int* utf32;       ///< The expected text (array of bytes with text encoded in utf32).
+};
+
+
+bool Utf8ToUtf32Test( const Utf8ToUtf32Data& data )
+{
+  Vector<uint32_t> 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.Begin() );
+
+  for( unsigned int index = 0u; index < numberOfCharacters; ++index )
+  {
+    if( data.utf32[index] != utf32[index] )
+    {
+      return false;
+    }
+  }
+
+  return true;
+}
+
+} // namespace
+
+//////////////////////////////////////////////////////////
+
+struct Utf32ToUtf8Data
+{
+  std::string   description;        ///< Description of the test.
+  unsigned int* utf32;              ///< The input text (array of bytes with text encoded in utf32).
+  unsigned int  numberOfCharacters; ///< The number of characters.
+  std::string   text;               ///< The expected text.
+};
+
+bool Utf32ToUtf8Test( const Utf32ToUtf8Data& data )
+{
+  std::string text;
+
+  Utf32ToUtf8( data.utf32, data.numberOfCharacters, text );
+
+  return text == data.text;
+}
+
+//////////////////////////////////////////////////////////
+
+int UtcDaliTextCharacterSetConversionGetNumberOfUtf8Characters(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliTextCharacterSetConversionGetNumberOfUtf8Characters");
+
+  const GetNumberOfUtf8CharactersData data[] =
+  {
+    {
+      "Latin script",
+      "Hello World",
+      11u,
+    },
+    {
+      "Arabic script",
+      "مرحبا بالعالم",
+      13u,
+    },
+    {
+      "Devanagari script",
+      "हैलो वर्ल्ड",
+      11u,
+    },
+    {
+      "Emojis",
+      "\xF0\x9F\x98\x81 \xF0\x9F\x98\x82 \xF0\x9F\x98\x83 \xF0\x9F\x98\x84",
+      7u,
+    },
+  };
+  const unsigned int numberOfTests = 4u;
+
+  for( unsigned int index = 0u; index < numberOfTests; ++index )
+  {
+    if( !GetNumberOfUtf8CharactersTest( data[index] ) )
+    {
+      tet_result(TET_FAIL);
+    }
+  }
+
+  tet_result(TET_PASS);
+  END_TEST;
+}
+
+int UtcDaliTextCharacterSetConversionGetNumberOfUtf8Bytes(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliTextCharacterSetConversionGetNumberOfUtf8Bytes");
+
+  unsigned int utf32_01[] = { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 }; // Hello World
+  unsigned int utf32_02[] = { 0x645, 0x631, 0x62D, 0x628, 0x627, 0x20, 0x628, 0x627, 0x644, 0x639, 0x627, 0x644, 0x645 }; // مرحبا بالعالم
+  unsigned int utf32_03[] = { 0x939, 0x948, 0x932, 0x94B, 0x20, 0x935, 0x930, 0x94D, 0x932, 0x94D, 0x921 }; // हैलो वर्ल्ड
+  unsigned int utf32_04[] = { 0x1F601, 0x20, 0x1F602, 0x20, 0x1F603, 0x20, 0x1F604 }; // Emojis
+
+  const GetNumberOfUtf8BytesData data[] =
+  {
+    {
+      "Latin script",
+      utf32_01,
+      11u,
+      11u,
+    },
+    {
+      "Arabic script",
+      utf32_02,
+      13u,
+      25u,
+    },
+    {
+      "Devanagari script",
+      utf32_03,
+      11u,
+      31u,
+    },
+    {
+      "Emojis",
+      utf32_04,
+      7u,
+      19u,
+    },
+  };
+  const unsigned int numberOfTests = 4u;
+
+  for( unsigned int index = 0u; index < numberOfTests; ++index )
+  {
+    if( !GetNumberOfUtf8BytesTest( data[index] ) )
+    {
+      tet_result(TET_FAIL);
+    }
+  }
+
+  tet_result(TET_PASS);
+  END_TEST;
+}
+
+int UtcDaliTextCharacterSetConversionUtf8ToUtf32(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliTextCharacterSetConversionGetNumberOfUtf8Bytes");
+
+  unsigned int utf32_01[] = { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 }; // Hello World
+  unsigned int utf32_02[] = { 0x645, 0x631, 0x62D, 0x628, 0x627, 0x20, 0x628, 0x627, 0x644, 0x639, 0x627, 0x644, 0x645 }; // مرحبا بالعالم
+  unsigned int utf32_03[] = { 0x939, 0x948, 0x932, 0x94B, 0x20, 0x935, 0x930, 0x94D, 0x932, 0x94D, 0x921 }; // हैलो वर्ल्ड
+  unsigned int utf32_04[] = { 0x1F601, 0x20, 0x1F602, 0x20, 0x1F603, 0x20, 0x1F604 }; // Emojis
+
+  const Utf8ToUtf32Data data[] =
+  {
+    {
+      "Latin script",
+      "Hello World",
+      utf32_01,
+    },
+    {
+      "Arabic script",
+      "مرحبا بالعالم",
+      utf32_02,
+    },
+    {
+      "Devanagari script",
+      "हैलो वर्ल्ड",
+      utf32_03,
+    },
+    {
+      "Emojis",
+      "\xF0\x9F\x98\x81 \xF0\x9F\x98\x82 \xF0\x9F\x98\x83 \xF0\x9F\x98\x84",
+      utf32_04,
+    },
+  };
+  const unsigned int numberOfTests = 4u;
+
+  for( unsigned int index = 0u; index < numberOfTests; ++index )
+  {
+    if( !Utf8ToUtf32Test( data[index] ) )
+    {
+      tet_result(TET_FAIL);
+    }
+  }
+
+  tet_result(TET_PASS);
+  END_TEST;
+}
+
+int UtcDaliTextCharacterSetConversionUtf32ToUtf8(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliTextCharacterSetConversionUtf32ToUtf8");
+
+  unsigned int utf32_01[] = { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 }; // Hello World
+  unsigned int utf32_02[] = { 0x645, 0x631, 0x62D, 0x628, 0x627, 0x20, 0x628, 0x627, 0x644, 0x639, 0x627, 0x644, 0x645 }; // مرحبا بالعالم
+  unsigned int utf32_03[] = { 0x939, 0x948, 0x932, 0x94B, 0x20, 0x935, 0x930, 0x94D, 0x932, 0x94D, 0x921 }; // हैलो वर्ल्ड
+  unsigned int utf32_04[] = { 0x1F601, 0x20, 0x1F602, 0x20, 0x1F603, 0x20, 0x1F604 }; // Emojis
+
+  struct Utf32ToUtf8Data data[] =
+  {
+    {
+      "Latin script",
+      utf32_01,
+      11u,
+      "Hello World",
+    },
+    {
+      "Arabic script",
+      utf32_02,
+      13u,
+      "مرحبا بالعالم",
+    },
+    {
+      "Devanagari script",
+      utf32_03,
+      11u,
+      "हैलो वर्ल्ड",
+    },
+    {
+      "Emojis",
+      utf32_04,
+      7u,
+      "\xF0\x9F\x98\x81 \xF0\x9F\x98\x82 \xF0\x9F\x98\x83 \xF0\x9F\x98\x84",
+    },
+  };
+
+  const unsigned int numberOfTests = 4u;
+
+  for( unsigned int index = 0u; index < numberOfTests; ++index )
+  {
+    if( !Utf32ToUtf8Test( data[index] ) )
+    {
+      tet_result(TET_FAIL);
+    }
+  }
+
+  tet_result(TET_PASS);
+  END_TEST;
+}
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;
+}
index b1b9993..67c294b 100644 (file)
@@ -24,6 +24,9 @@ namespace Dali
 namespace Toolkit
 {
 
+namespace Text
+{
+
 namespace
 {
   const static uint8_t U1 = 1u;
@@ -222,6 +225,8 @@ void Utf32ToUtf8( const uint32_t* const utf32, uint32_t numberOfCharacters, std:
   Utf32ToUtf8( utf32, numberOfCharacters, reinterpret_cast<uint8_t*>(&utf8[0]) );
 }
 
+} // namespace Text
+
 } // namespace Toolkit
 
 } // namespace Dali
index 19784fb..720114b 100644 (file)
@@ -31,6 +31,9 @@ namespace Dali
 namespace Toolkit
 {
 
+namespace Text
+{
+
 /**
  * @brief Retrieves the number of characters of the text array encoded in UTF8
  *
@@ -86,6 +89,8 @@ uint32_t Utf32ToUtf8( const uint32_t* const utf32, uint32_t numberOfCharacters,
  */
 void Utf32ToUtf8( const uint32_t* const utf32, uint32_t numberOfCharacters, std::string& utf8 );
 
+} // namespace Text
+
 } // namespace Toolkit
 
 } // namespace Dali