From: Bruno Haible Date: Sun, 10 Jan 2010 16:40:14 +0000 (+0100) Subject: Tests for module 'unistr/u32-strmblen'. X-Git-Tag: v0.1~4810 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=805f65a0f7208a6abd216003cddcdddf3694fdc9;p=gnulib.git Tests for module 'unistr/u32-strmblen'. --- diff --git a/ChangeLog b/ChangeLog index 4bff3f708..c342481e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2010-01-10 Bruno Haible + Tests for module 'unistr/u32-strmblen'. + * modules/unistr/u32-strmblen-tests: New file. + * tests/unistr/test-u32-strmblen.c: New file. + Tests for module 'unistr/u16-strmblen'. * modules/unistr/u16-strmblen-tests: New file. * tests/unistr/test-u16-strmblen.c: New file. diff --git a/modules/unistr/u32-strmblen-tests b/modules/unistr/u32-strmblen-tests new file mode 100644 index 000000000..519b2aa39 --- /dev/null +++ b/modules/unistr/u32-strmblen-tests @@ -0,0 +1,12 @@ +Files: +tests/unistr/test-u32-strmblen.c +tests/macros.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-u32-strmblen +check_PROGRAMS += test-u32-strmblen +test_u32_strmblen_SOURCES = unistr/test-u32-strmblen.c diff --git a/tests/unistr/test-u32-strmblen.c b/tests/unistr/test-u32-strmblen.c new file mode 100644 index 000000000..733f8fc82 --- /dev/null +++ b/tests/unistr/test-u32-strmblen.c @@ -0,0 +1,75 @@ +/* Test of u32_strmblen() 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" + +int +main () +{ + int ret; + + /* Test NUL unit input. */ + { + static const uint32_t input[] = { 0 }; + ret = u32_strmblen (input); + ASSERT (ret == 0); + } + + /* Test ISO 646 unit input. */ + { + ucs4_t c; + uint32_t buf[2]; + + for (c = 1; c < 0x80; c++) + { + buf[0] = c; + buf[1] = 0; + ret = u32_strmblen (buf); + ASSERT (ret == 1); + } + } + + /* Test BMP unit input. */ + { + static const uint32_t input[] = { 0x20AC, 0 }; + ret = u32_strmblen (input); + ASSERT (ret == 1); + } + + /* Test non-BMP unit input. */ + { + static const uint32_t input[] = { 0x1D51F, 0 }; + ret = u32_strmblen (input); + ASSERT (ret == 1); + } + +#if CONFIG_UNICODE_SAFETY + /* Test incomplete/invalid 1-unit input. */ + { + static const uint32_t input[] = { 0x340000, 0 }; + ret = u32_strmblen (input); + ASSERT (ret == -1); + } +#endif + + return 0; +}