From b9c0e5f6d1d75617f31f07586565573e1c59a6dd Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 5 Apr 2010 21:17:09 +0200 Subject: [PATCH] Tests for module 'strncat'. --- ChangeLog | 4 +++ modules/strncat-tests | 20 ++++++++++++++ tests/test-strncat.c | 62 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 modules/strncat-tests create mode 100644 tests/test-strncat.c diff --git a/ChangeLog b/ChangeLog index 669815c784..4bd2cde739 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2010-04-05 Bruno Haible + Tests for module 'strncat'. + * modules/strncat-tests: New file. + * tests/test-strncat.c: New file. + New module 'strncat'. * lib/string.in.h (strncat): New declaration. * lib/strncat.c: New file, based on lib/unistr/u-strncat.h. diff --git a/modules/strncat-tests b/modules/strncat-tests new file mode 100644 index 0000000000..263043019b --- /dev/null +++ b/modules/strncat-tests @@ -0,0 +1,20 @@ +Files: +tests/test-strncat.c +tests/unistr/test-strncat.h +tests/zerosize-ptr.h +tests/signature.h +tests/macros.h +m4/mmap-anon.m4 + +Depends-on: +extensions +getpagesize + +configure.ac: +gl_FUNC_MMAP_ANON +AC_CHECK_HEADERS_ONCE([sys/mman.h]) +AC_CHECK_FUNCS_ONCE([mprotect]) + +Makefile.am: +TESTS += test-strncat +check_PROGRAMS += test-strncat diff --git a/tests/test-strncat.c b/tests/test-strncat.c new file mode 100644 index 0000000000..49cf3961fb --- /dev/null +++ b/tests/test-strncat.c @@ -0,0 +1,62 @@ +/* Test of strncat() 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 + +#include "signature.h" +SIGNATURE_CHECK (strncat, char *, (char *, const char *, size_t)); + +#include + +#include "zerosize-ptr.h" +#include "macros.h" + +#define UNIT char +#define U_STRNCAT strncat +#define MAGIC ((char) 0xBA) +#include "unistr/test-strncat.h" + +int +main () +{ + /* Simple string. */ + { /* "Grüß Gott. Здравствуйте! x=(-b±sqrt(b²-4ac))/(2a) 日本語,中文,한글" + in UTF-8 encoding. */ + static const char input[] = + { 'G', 'r', (char) 0xC3, (char) 0xBC, (char) 0xC3, (char) 0x9F, ' ', + 'G', 'o', 't', 't', '.', ' ', (char) 0xD0, (char) 0x97, (char) 0xD0, + (char) 0xB4, (char) 0xD1, (char) 0x80, (char) 0xD0, (char) 0xB0, + (char) 0xD0, (char) 0xB2, (char) 0xD1, (char) 0x81, (char) 0xD1, + (char) 0x82, (char) 0xD0, (char) 0xB2, (char) 0xD1, (char) 0x83, + (char) 0xD0, (char) 0xB9, (char) 0xD1, (char) 0x82, (char) 0xD0, + (char) 0xB5, '!', ' ', 'x', '=', '(', '-', 'b', (char) 0xC2, + (char) 0xB1, 's', 'q', 'r', 't', '(', 'b', (char) 0xC2, (char) 0xB2, + '-', '4', 'a', 'c', ')', ')', '/', '(', '2', 'a', ')', ' ', ' ', + (char) 0xE6, (char) 0x97, (char) 0xA5, (char) 0xE6, (char) 0x9C, + (char) 0xAC, (char) 0xE8, (char) 0xAA, (char) 0x9E, ',', (char) 0xE4, + (char) 0xB8, (char) 0xAD, (char) 0xE6, (char) 0x96, (char) 0x87, ',', + (char) 0xED, (char) 0x95, (char) 0x9C, (char) 0xEA, (char) 0xB8, + (char) 0x80, '\0' + }; + check (input, SIZEOF (input)); + } + + return 0; +} -- 2.30.2