Tests for module 'unistr/u8-move'.
authorBruno Haible <bruno@clisp.org>
Sun, 10 Jan 2010 14:28:30 +0000 (15:28 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 10 Jan 2010 22:12:58 +0000 (23:12 +0100)
ChangeLog
modules/unistr/u8-move-tests [new file with mode: 0644]
tests/unistr/test-move.h [new file with mode: 0644]
tests/unistr/test-u8-move.c [new file with mode: 0644]

index 9b8e9cbe10a1330899f66c32f85a14dd4a0d8cbf..addd794e9d359656abf9ce884544ca1b2193cc67 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2010-01-10  Bruno Haible  <bruno@clisp.org>
 
+       Tests for module 'unistr/u8-move'.
+       * modules/unistr/u8-move-tests: New file.
+       * tests/unistr/test-u8-move.c: New file.
+       * tests/unistr/test-move.h: New file.
+
        Tests for module 'unistr/u32-cpy'.
        * modules/unistr/u32-cpy-tests: New file.
        * tests/unistr/test-u32-cpy.c: New file.
diff --git a/modules/unistr/u8-move-tests b/modules/unistr/u8-move-tests
new file mode 100644 (file)
index 0000000..9a0744c
--- /dev/null
@@ -0,0 +1,13 @@
+Files:
+tests/unistr/test-u8-move.c
+tests/unistr/test-move.h
+tests/macros.h
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-u8-move
+check_PROGRAMS += test-u8-move
+test_u8_move_SOURCES = unistr/test-u8-move.c
diff --git a/tests/unistr/test-move.h b/tests/unistr/test-move.h
new file mode 100644 (file)
index 0000000..2462367
--- /dev/null
@@ -0,0 +1,152 @@
+/* Test of uN_move() functions.
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2010.  */
+
+int
+main ()
+{
+  /* Test copying operations with disjoint source and destination.  */
+  {
+    static const UNIT src[] = { 'c', 'l', 'i', 'm', 'a', 't', 'e' };
+    size_t n;
+
+    for (n = 0; n <= SIZEOF (src); n++)
+      {
+        UNIT dest[1 + SIZEOF (src) + 1] =
+          { MAGIC, MAGIC, MAGIC, MAGIC, MAGIC, MAGIC, MAGIC, MAGIC, MAGIC };
+        UNIT *ret;
+        size_t i;
+
+        ret = U_MOVE (dest + 1, src, n);
+        ASSERT (ret == dest + 1);
+        ASSERT (dest[0] == MAGIC);
+        for (i = 0; i < n; i++)
+          ASSERT (dest[1 + i] == src[i]);
+        ASSERT (dest[1 + n] == MAGIC);
+      }
+  }
+
+  /* Test copying operations with overlap, in-place.  */
+  {
+    static const UNIT src[] = { 'c', 'l', 'i', 'm', 'a', 't', 'e' };
+    size_t n;
+
+    for (n = 0; n <= SIZEOF (src); n++)
+      {
+        UNIT dest[1 + SIZEOF (src) + 1];
+        UNIT *ret;
+        size_t i;
+
+        dest[0] = MAGIC;
+        for (i = 0; i < n; i++)
+          dest[1 + i] = src[i];
+        dest[1 + n] = MAGIC;
+
+        ret = U_MOVE (dest + 1, dest + 1, n);
+        ASSERT (ret == dest + 1);
+        ASSERT (dest[0] == MAGIC);
+        for (i = 0; i < n; i++)
+          ASSERT (dest[1 + i] == src[i]);
+        ASSERT (dest[1 + n] == MAGIC);
+      }
+  }
+
+  /* Test copying operations with overlap, moving downward.  */
+  {
+    static const UNIT src[] = { 'c', 'l', 'i', 'm', 'a', 't', 'e' };
+    static const UNIT src2[] = { 'C', 'L', 'I', 'M', 'A', 'T', 'E' };
+    size_t d;
+
+    ASSERT (SIZEOF (src) == SIZEOF (src2));
+    for (d = 0; d <= SIZEOF (src); d++)
+      {
+        size_t n;
+
+        for (n = 0; n <= SIZEOF (src); n++)
+          {
+            UNIT dest[1 + 2 * SIZEOF (src) + 1];
+            UNIT *ret;
+            size_t i;
+
+            dest[0] = MAGIC;
+            for (i = 0; i < SIZEOF (src2); i++)
+              dest[1 + i] = src2[i];
+            for (i = 0; i < SIZEOF (src); i++)
+              dest[1 + SIZEOF (src) + i] = src[i];
+            dest[1 + 2 * SIZEOF (src)] = MAGIC;
+
+            ret =
+              U_MOVE (dest + 1 + SIZEOF (src) - d, dest + 1 + SIZEOF (src), n);
+            ASSERT (ret == dest + 1 + SIZEOF (src) - d);
+            ASSERT (dest[0] == MAGIC);
+            for (i = 0; i < SIZEOF (src) - d; i++)
+              ASSERT (dest[1 + i] == src2[i]);
+            for (i = 0; i < n; i++)
+              ASSERT (dest[1 + SIZEOF (src) - d + i] == src[i]);
+            for (i = SIZEOF (src) - d + n; i < SIZEOF (src2); i++)
+              ASSERT (dest[1 + i] == src2[i]);
+            for (i = (n >= d ? n - d : 0); i < SIZEOF (src); i++)
+              ASSERT (dest[1 + SIZEOF (src) + i] == src[i]);
+            ASSERT (dest[1 + 2 * SIZEOF (src)] == MAGIC);
+          }
+      }
+  }
+
+  /* Test copying operations with overlap, moving upward.  */
+  {
+    static const UNIT src[] = { 'c', 'l', 'i', 'm', 'a', 't', 'e' };
+    static const UNIT src2[] = { 'C', 'L', 'I', 'M', 'A', 'T', 'E' };
+    size_t d;
+
+    ASSERT (SIZEOF (src) == SIZEOF (src2));
+    for (d = 0; d <= SIZEOF (src); d++)
+      {
+        size_t n;
+
+        for (n = 0; n <= SIZEOF (src); n++)
+          {
+            UNIT dest[1 + 2 * SIZEOF (src) + 1];
+            UNIT *ret;
+            size_t i;
+
+            dest[0] = MAGIC;
+            for (i = 0; i < SIZEOF (src); i++)
+              dest[1 + i] = src[i];
+            for (i = 0; i < SIZEOF (src2); i++)
+              dest[1 + SIZEOF (src) + i] = src2[i];
+            dest[1 + 2 * SIZEOF (src)] = MAGIC;
+
+            ret = U_MOVE (dest + 1 + d, dest + 1, n);
+            ASSERT (ret == dest + 1 + d);
+            ASSERT (dest[0] == MAGIC);
+            for (i = 0; i < d; i++)
+              ASSERT (dest[1 + i] == src[i]);
+            for (i = 0; i < n; i++)
+              ASSERT (dest[1 + d + i] == src[i]);
+            for (i = d + n; i < SIZEOF (src); i++)
+              ASSERT (dest[1 + i] == src[i]);
+            for (i = (d + n >= SIZEOF (src) ? d + n - SIZEOF (src) : 0);
+                 i < SIZEOF (src2);
+                 i++)
+              ASSERT (dest[1 + SIZEOF (src) + i] == src2[i]);
+            ASSERT (dest[1 + 2 * SIZEOF (src)] == MAGIC);
+          }
+      }
+  }
+
+  return 0;
+}
diff --git a/tests/unistr/test-u8-move.c b/tests/unistr/test-u8-move.c
new file mode 100644 (file)
index 0000000..d18d8dd
--- /dev/null
@@ -0,0 +1,28 @@
+/* Test of u8_move() function.
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2010.  */
+
+#include <config.h>
+
+#include "unistr.h"
+
+#include "macros.h"
+
+#define UNIT uint8_t
+#define U_MOVE u8_move
+#define MAGIC 0xBA
+#include "test-move.h"