>From f50a5a002d05c2a75994896f47457edc60eea7a6 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 24 Nov 2019 13:12:53 +0100 Subject: [PATCH 2/2] wcstok: Add tests. * tests/test-wcstok.c: New file. * modules/wcstok-tests: New file. --- ChangeLog | 6 ++++++ modules/wcstok-tests | 12 ++++++++++++ tests/test-wcstok.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 modules/wcstok-tests create mode 100644 tests/test-wcstok.c diff --git a/ChangeLog b/ChangeLog index 9e6725a..984792b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2019-11-24 Bruno Haible + wcstok: Add tests. + * tests/test-wcstok.c: New file. + * modules/wcstok-tests: New file. + +2019-11-24 Bruno Haible + wcstok: Work around wrong signature on native Windows. * lib/wchar.in.h (wcstok): Override when REPLACE_WCSTOK is 1. * m4/wcstok.m4 (gl_FUNC_WCSTOK): Check for signature of wcstok. Set diff --git a/modules/wcstok-tests b/modules/wcstok-tests new file mode 100644 index 0000000..57ccd08 --- /dev/null +++ b/modules/wcstok-tests @@ -0,0 +1,12 @@ +Files: +tests/test-wcstok.c +tests/signature.h +tests/macros.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-wcstok +check_PROGRAMS += test-wcstok diff --git a/tests/test-wcstok.c b/tests/test-wcstok.c new file mode 100644 index 0000000..5c6fd51 --- /dev/null +++ b/tests/test-wcstok.c @@ -0,0 +1,53 @@ +/* Test of conversion of wide string to string. + Copyright (C) 2019 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 , 2019. */ + +#include + +#include + +#include "signature.h" +SIGNATURE_CHECK (wcstok, wchar_t *, + (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr)); + +#include + +#include "macros.h" + +int +main () +{ + wchar_t string[] = L"hello world!"; + wchar_t delim[] = L" "; + wchar_t *ptr; + wchar_t *ret; + + ret = wcstok (string, delim, &ptr); + ASSERT (ret == string); + ASSERT (memcmp (string, L"hello\0 world!", 14 * sizeof (wchar_t)) == 0); + ASSERT (ptr == string + 6); + + ret = wcstok (NULL, delim, &ptr); + ASSERT (ret == string + 7); + ASSERT (memcmp (string, L"hello\0 world!", 14 * sizeof (wchar_t)) == 0); + ASSERT (ptr == NULL || *ptr == L'\0'); + + ret = wcstok (NULL, delim, &ptr); + ASSERT (ret == NULL); + + return 0; +} -- 2.7.4