From: Bruno Haible Date: Sun, 8 Feb 2009 20:24:51 +0000 (+0100) Subject: Tests for module 'unicase/toupper'. X-Git-Tag: v0.1~6340 X-Git-Url: https://erislabs.net/gitweb/?a=commitdiff_plain;h=f2fd6bcd353822eeb40dac4ff11da755bed1c334;hp=6732f3d6708503b5cfc1bff627a9c119e2abc651;p=gnulib.git Tests for module 'unicase/toupper'. --- diff --git a/ChangeLog b/ChangeLog index 2437436c6..0f45dcd78 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2009-02-08 Bruno Haible + Tests for module 'unicase/toupper'. + * modules/unicase/toupper-tests: New file. + * tests/unicase/test-mapping-part1.h: New file. + * tests/unicase/test-mapping-part2.h: New file. + New module 'unicase/totitle'. * modules/unicase/totitle: New file. * lib/unicase/totitle.c: New file. diff --git a/modules/unicase/toupper-tests b/modules/unicase/toupper-tests new file mode 100644 index 000000000..93adf9a98 --- /dev/null +++ b/modules/unicase/toupper-tests @@ -0,0 +1,14 @@ +Files: +tests/unicase/test-uc_toupper.c +tests/unicase/test-mapping-part1.h +tests/unicase/test-mapping-part2.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-uc_toupper +check_PROGRAMS += test-uc_toupper +test_uc_toupper_SOURCES = unicase/test-uc_toupper.c + diff --git a/tests/unicase/test-mapping-part1.h b/tests/unicase/test-mapping-part1.h new file mode 100644 index 000000000..4b7ac8ecb --- /dev/null +++ b/tests/unicase/test-mapping-part1.h @@ -0,0 +1,45 @@ +/* Test of single character case mapping functions. + Copyright (C) 2007-2009 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 . */ + +#include + +#include "unicase.h" + +#include +#include +#include + +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed for c = 0x%04X\n", \ + __FILE__, __LINE__, c); \ + fflush (stderr); \ + abort (); \ + } \ + } \ + while (0) +#define SIZEOF(a) (sizeof(a) / sizeof(a[0])) + +/* Pair of Unicode characters. */ +typedef struct { ucs4_t ch; ucs4_t value; } pair_t; + +/* Characters and their mapping values, ignoring no-op mappings, in increasing + order. */ +static const pair_t mapping[] = + { diff --git a/tests/unicase/test-mapping-part2.h b/tests/unicase/test-mapping-part2.h new file mode 100644 index 000000000..ef43cddea --- /dev/null +++ b/tests/unicase/test-mapping-part2.h @@ -0,0 +1,37 @@ +/* Test of single character case mapping functions. + Copyright (C) 2007-2009 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 . */ + + }; + +int +main () +{ + unsigned int c; + size_t i; + + c = 0; + for (i = 0; i < SIZEOF (mapping); i++) + { + for (; c < mapping[i].ch; c++) + ASSERT (MAP (c) == c); + ASSERT (MAP (c) == mapping[i].value); + c++; + } + for (; c < 0x110000; c++) + ASSERT (MAP (c) == c); + + return 0; +}