# HG changeset patch # User Bruno Haible # Date 1234124691 -3600 # Node ID 6cf2f8dbf056597573cfd164ea3cd2b0a99190e6 # Parent 33928cb804c4167e9f60995fad80ea669f9ee1f7 Tests for module 'unicase/toupper'. diff --git a/ChangeLog b/ChangeLog --- 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 --- /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 --- /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 --- /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; +}