[PATCH 4/9] libtests: Add new test: utf8proc01

Ralf Kirchner ralf.kirchner at embedded-brains.de
Fri May 31 13:42:20 UTC 2013


utf8proc is a library for processing UTF-8 encoded Unicode strings.
Some features are Unicode normalization, stripping of default ignorable characters, case folding and detection of grapheme cluster boundaries.
For now utf8proc is intended for normalizing and folding strings for comparison purposes within the UTF-8 support of the FAT file system.
This test will call interface methods of library utf8proc in order to make sure they compiled and linked ok.
The library is third party, thus it should be sufficient for us to make sure we can build it correctly.
---
 testsuites/libtests/Makefile.am               |    1 +
 testsuites/libtests/configure.ac              |    1 +
 testsuites/libtests/utf8proc01/Makefile.am    |   19 ++
 testsuites/libtests/utf8proc01/init.c         |  271 +++++++++++++++++++++++++
 testsuites/libtests/utf8proc01/utf8proc01.doc |   23 +++
 testsuites/libtests/utf8proc01/utf8proc01.scn |    2 +
 6 Dateien geändert, 317 Zeilen hinzugefügt(+)
 create mode 100644 testsuites/libtests/utf8proc01/Makefile.am
 create mode 100644 testsuites/libtests/utf8proc01/init.c
 create mode 100644 testsuites/libtests/utf8proc01/utf8proc01.doc
 create mode 100644 testsuites/libtests/utf8proc01/utf8proc01.scn

diff --git a/testsuites/libtests/Makefile.am b/testsuites/libtests/Makefile.am
index c30e857..d1ffabc 100644
--- a/testsuites/libtests/Makefile.am
+++ b/testsuites/libtests/Makefile.am
@@ -3,6 +3,7 @@ ACLOCAL_AMFLAGS = -I ../aclocal
 SUBDIRS = POSIX
 SUBDIRS += exit02
 SUBDIRS += exit01
+SUBDIRS += utf8proc01
 SUBDIRS += md501
 SUBDIRS += sparsedisk01
 SUBDIRS += block16
diff --git a/testsuites/libtests/configure.ac b/testsuites/libtests/configure.ac
index c2e1d9c..741c603 100644
--- a/testsuites/libtests/configure.ac
+++ b/testsuites/libtests/configure.ac
@@ -45,6 +45,7 @@ AM_CONDITIONAL(HAS_POSIX,test x"${rtems_cv_RTEMS_POSIX_API}" = x"yes")
 AC_CONFIG_FILES([Makefile
 exit02/Makefile
 exit01/Makefile
+utf8proc01/Makefile
 md501/Makefile
 sparsedisk01/Makefile
 block16/Makefile
diff --git a/testsuites/libtests/utf8proc01/Makefile.am b/testsuites/libtests/utf8proc01/Makefile.am
new file mode 100644
index 0000000..6884c07
--- /dev/null
+++ b/testsuites/libtests/utf8proc01/Makefile.am
@@ -0,0 +1,19 @@
+rtems_tests_PROGRAMS = utf8proc01
+utf8proc01_SOURCES = init.c
+
+dist_rtems_tests_DATA = utf8proc01.scn utf8proc01.doc
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP at .cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(utf8proc01_OBJECTS)
+LINK_LIBS = $(utf8proc01_LDLIBS)
+
+utf8proc01$(EXEEXT): $(utf8proc01_OBJECTS) $(utf8proc01_DEPENDENCIES)
+	@rm -f utf8proc01$(EXEEXT)
+	$(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/libtests/utf8proc01/init.c b/testsuites/libtests/utf8proc01/init.c
new file mode 100644
index 0000000..e55a1d6
--- /dev/null
+++ b/testsuites/libtests/utf8proc01/init.c
@@ -0,0 +1,271 @@
+/*
+ * Copyright (c) 2012 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Obere Lagerstr. 30
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+  #include "config.h"
+#endif
+
+#include "tmacros.h"
+
+#include <string.h>
+#include <utf8proc/utf8proc.h>
+
+static void
+test_utf8proc_errmsg ( void )
+{
+  int          error;
+  size_t       string_length;
+  const char*  err_msg;
+
+  for ( error = 0; error >= UTF8PROC_ERROR_INVALIDOPTS - 1; --error ) {
+    err_msg = utf8proc_errmsg ( error );
+    rtems_test_assert ( err_msg != NULL );
+
+    string_length = strlen (err_msg );
+    rtems_test_assert ( string_length > 0 );
+  }
+}
+
+static void
+test_utf8proc_version ( void )
+{
+  const char*  version;
+  size_t       string_length;
+
+  version = utf8proc_version ( );
+  rtems_test_assert ( version != NULL );
+
+  string_length = strlen ( version );
+  rtems_test_assert ( string_length > 0 );
+
+  rtems_test_assert (0 == strcmp ( version, "1.1.5" ) );
+}
+
+static void
+test_utf8proc_iterate ( void )
+{
+  char         utf8_str_simple[]    = "The quick brown.fox";
+  uint8_t     *utf8_str_simple_ptr  = (uint8_t*)(&utf8_str_simple[0]);
+  size_t       length_simple_string = strlen ( utf8_str_simple );
+  int32_t      unicode_char;
+  unsigned int index;
+  ssize_t      bytes_read;
+
+  for (index = 0; index < length_simple_string; ++index) {
+    bytes_read = utf8proc_iterate (
+      &utf8_str_simple_ptr[index],
+      length_simple_string - index,
+      &unicode_char );
+    rtems_test_assert ( bytes_read == 1 );
+    rtems_test_assert ( (uint8_t)unicode_char == utf8_str_simple_ptr[index]);
+  }
+}
+
+static void
+test_utf8proc_encode_char ( void )
+{
+  uint8_t utf8_str[4];
+  int32_t unicode_char;
+  ssize_t bytes_written;
+
+  for ( unicode_char = 0; unicode_char < 128; ++unicode_char ) {
+    bytes_written = utf8proc_encode_char ( unicode_char, utf8_str );
+
+    rtems_test_assert ( bytes_written == 1 );
+    rtems_test_assert ( utf8_str[0]   == (uint8_t)unicode_char );
+  }
+}
+
+static void
+test_utf8proc_get_property ( void )
+{
+  int32_t                    unicode_char;
+  const utf8proc_property_t* properties;
+
+  for ( unicode_char = 0x0000; unicode_char <= 0x10FFFF; ++unicode_char ) {
+    properties = utf8proc_get_property ( unicode_char );
+    rtems_test_assert ( NULL != properties );
+  }
+}
+
+static void
+test_utf8proc_decompose_char ( void )
+{
+  int32_t unicode_char;
+  int32_t unicode_char_decomposed[4];
+  ssize_t chars_written;
+
+  for ( unicode_char = 0x0000; unicode_char <= 0x10FFFF; ++unicode_char ) {
+    chars_written = utf8proc_decompose_char (
+      unicode_char,
+      unicode_char_decomposed,
+      sizeof ( unicode_char_decomposed ) / sizeof ( unicode_char_decomposed[0] ),
+      UTF8PROC_STABLE | UTF8PROC_DECOMPOSE,
+      0);
+    if ( unicode_char < 0x80 ) {
+      rtems_test_assert ( chars_written == 1 );
+      rtems_test_assert ( unicode_char_decomposed[0] == unicode_char);
+    }
+    else
+     rtems_test_assert ( chars_written > 0 );
+  }
+}
+
+static void
+test_utf8proc_decompose ( void )
+{
+  char         string_simple[]    = "The quick brown.fox";
+  uint8_t     *string_simple_utf8 = (uint8_t*)(&string_simple[0]);
+  int32_t      string_decomposed[sizeof ( string_simple ) * 4];
+  ssize_t      chars_written;
+  unsigned int index;
+
+  memset (&string_decomposed[0], 0, sizeof ( string_decomposed ) );
+
+  chars_written = utf8proc_decompose (
+    string_simple_utf8,
+    sizeof ( string_simple ),
+    &string_decomposed[0],
+    sizeof ( string_decomposed ),
+    UTF8PROC_NULLTERM | UTF8PROC_STABLE | UTF8PROC_DECOMPOSE );
+  rtems_test_assert ( chars_written == strlen ( string_simple ) );
+  /* Our source string contains only very simple characters. Thus the above
+   * decomposition should result in exactly the same string
+   */
+  for ( index = 0; index < sizeof ( string_simple ); ++index ) {
+    rtems_test_assert ( string_simple_utf8[index] == (uint8_t)string_decomposed[index] );
+  }
+}
+
+static void
+test_utf8proc_reencode ( void )
+{
+  char         string_simple[]    = "The quick brown.fox";
+  uint8_t     *string_simple_utf8 = (uint8_t*)(&string_simple[0]);
+  int32_t      string_decomposed[sizeof ( string_simple ) * 4];
+  uint8_t     *string_reencoded   = (uint8_t*)(&string_decomposed[0]);
+  ssize_t      chars_written;
+  unsigned int index;
+
+  memset (&string_decomposed[0], 0, sizeof ( string_decomposed ) );
+
+  chars_written = utf8proc_decompose (
+    string_simple_utf8,
+    sizeof ( string_simple ),
+    &string_decomposed[0],
+    sizeof ( string_decomposed ),
+    UTF8PROC_NULLTERM | UTF8PROC_STABLE | UTF8PROC_DECOMPOSE );
+  rtems_test_assert ( chars_written == strlen ( string_simple ) );
+
+  chars_written = utf8proc_reencode (
+    &string_decomposed[0],
+    chars_written,
+    UTF8PROC_NULLTERM | UTF8PROC_STABLE | UTF8PROC_DECOMPOSE );
+  rtems_test_assert ( chars_written == strlen ( string_simple ) );
+  /* Our source string contains only very simple characters. Thus the above
+   * decomposition should result in exactly the same string
+   */
+  for ( index = 0; index < sizeof ( string_simple ); ++index ) {
+    rtems_test_assert ( string_simple_utf8[index] == string_reencoded[index] );
+  }
+}
+
+static void
+test_utf8proc_map ( void )
+{
+  char         string_simple[]    = "The quick brown.fox";
+  uint8_t     *string_simple_utf8 = (uint8_t*)(&string_simple[0]);
+  uint8_t     *dest               = NULL;
+  ssize_t      chars_written;
+  unsigned int index;
+
+  chars_written = utf8proc_map(
+    string_simple_utf8,
+    sizeof ( string_simple ),
+    &dest,
+    UTF8PROC_NULLTERM | UTF8PROC_STABLE | UTF8PROC_DECOMPOSE );
+  rtems_test_assert ( chars_written == strlen ( string_simple ) );
+  rtems_test_assert ( dest != NULL);
+
+  /* Our source string contains only very simple characters. Thus the above
+   * decomposition should result in exactly the same string
+   */
+  for ( index = 0; index < chars_written; ++index ) {
+    rtems_test_assert ( string_simple_utf8[index] == dest[index] );
+  }
+  free ( dest );
+}
+
+typedef uint8_t* (*normalization_method)(const uint8_t* str);
+
+static void
+test_utf8proc_normalize ( const normalization_method test_sample )
+{
+  char         string_simple[]    = "The quick brown.fox";
+  uint8_t     *string_simple_utf8 = (uint8_t*)(&string_simple[0]);
+  uint8_t     *dest               = NULL;
+  unsigned int index;
+
+  dest = test_sample ( string_simple_utf8 );
+  rtems_test_assert ( dest != NULL);
+
+  /* Our source string contains only very simple characters. Thus the above
+   * decomposition should result in exactly the same string
+   */
+  for ( index = 0; index < sizeof ( string_simple ); ++index ) {
+    rtems_test_assert ( string_simple_utf8[index] == dest[index] );
+  }
+  free ( dest );
+}
+
+static void test ( void )
+{
+  test_utf8proc_errmsg         ( );
+  test_utf8proc_version        ( );
+  test_utf8proc_iterate        ( );
+  test_utf8proc_encode_char    ( );
+  test_utf8proc_get_property   ( );
+  test_utf8proc_decompose_char ( );
+  test_utf8proc_decompose      ( );
+  test_utf8proc_reencode       ( );
+  test_utf8proc_map            ( );
+  test_utf8proc_normalize      ( utf8proc_NFD  );
+  test_utf8proc_normalize      ( utf8proc_NFC  );
+  test_utf8proc_normalize      ( utf8proc_NFKD );
+  test_utf8proc_normalize      ( utf8proc_NFKC );
+}
+
+static void Init ( rtems_task_argument arg )
+{
+  puts ( "\n\n*** TEST utf8proc01 ***" );
+
+  test ( );
+
+  puts ( "*** END OF TEST utf8proc01 ***" );
+
+  rtems_test_exit ( 0 );
+}
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
+
+#define CONFIGURE_MAXIMUM_TASKS 1
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
diff --git a/testsuites/libtests/utf8proc01/utf8proc01.doc b/testsuites/libtests/utf8proc01/utf8proc01.doc
new file mode 100644
index 0000000..f8b6990
--- /dev/null
+++ b/testsuites/libtests/utf8proc01/utf8proc01.doc
@@ -0,0 +1,23 @@
+This file describes the directives and concepts tested by this test set.
+
+test set name: utf8proc01
+
+directives:
+- utf8proc_errmsg ( )
+- utf8proc_version ( )
+- utf8proc_iterate ( )
+- utf8proc_encode_char ( )
+- utf8proc_get_property ( )
+- utf8proc_decompose_char ( )
+- utf8proc_decompose ( )
+- utf8proc_reencode ( )
+- utf8proc_map ( )
+- utf8proc_NFD ( )
+- utf8proc_NFC ( )
+- utf8proc_NFKD ( )
+- utf8proc_NFKC ( )
+
+concepts:
+- Call interface methods of library utf8proc in order to make sure they compiled and linked ok.
+- The library is third party, thus it should be sufficient for us to make sure we can build it correctly.
+
diff --git a/testsuites/libtests/utf8proc01/utf8proc01.scn b/testsuites/libtests/utf8proc01/utf8proc01.scn
new file mode 100644
index 0000000..62155a4
--- /dev/null
+++ b/testsuites/libtests/utf8proc01/utf8proc01.scn
@@ -0,0 +1,2 @@
+*** TEST utf8proc01 ***
+*** END OF TEST utf8proc01 ***
\ No newline at end of file
-- 
1.7.10.4




More information about the devel mailing list