From 9f7f009ce4c619cee2a65054c959248007bd4922 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 10 Jan 2010 15:28:30 +0100 Subject: [PATCH] Tests for module 'unistr/u8-move'. --- ChangeLog | 5 ++ modules/unistr/u8-move-tests | 13 +++ tests/unistr/test-move.h | 152 +++++++++++++++++++++++++++++++++++ tests/unistr/test-u8-move.c | 28 +++++++ 4 files changed, 198 insertions(+) create mode 100644 modules/unistr/u8-move-tests create mode 100644 tests/unistr/test-move.h create mode 100644 tests/unistr/test-u8-move.c diff --git a/ChangeLog b/ChangeLog index 9b8e9cbe10..addd794e9d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2010-01-10 Bruno Haible + 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 index 0000000000..9a0744cd81 --- /dev/null +++ b/modules/unistr/u8-move-tests @@ -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 index 0000000000..2462367d2f --- /dev/null +++ b/tests/unistr/test-move.h @@ -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 . */ + +/* Written by Bruno Haible , 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 index 0000000000..d18d8dd234 --- /dev/null +++ b/tests/unistr/test-u8-move.c @@ -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 . */ + +/* Written by Bruno Haible , 2010. */ + +#include + +#include "unistr.h" + +#include "macros.h" + +#define UNIT uint8_t +#define U_MOVE u8_move +#define MAGIC 0xBA +#include "test-move.h" -- 2.30.2