| xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1 | /* Copyright (C) 2003-2016 Free Software Foundation, Inc. | 
|  | 2 | This file is part of the GNU C Library. | 
|  | 3 | Contributed by Ulrich Drepper <drepper@cygnus.com>, 2003. | 
|  | 4 |  | 
|  | 5 | The GNU C Library is free software; you can redistribute it and/or | 
|  | 6 | modify it under the terms of the GNU Lesser General Public | 
|  | 7 | License as published by the Free Software Foundation; either | 
|  | 8 | version 2.1 of the License, or (at your option) any later version. | 
|  | 9 |  | 
|  | 10 | The GNU C Library is distributed in the hope that it will be useful, | 
|  | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|  | 13 | Lesser General Public License for more details. | 
|  | 14 |  | 
|  | 15 | You should have received a copy of the GNU Lesser General Public | 
|  | 16 | License along with the GNU C Library; if not, see | 
|  | 17 | <http://www.gnu.org/licenses/>.  */ | 
|  | 18 |  | 
|  | 19 | #include <stdio.h> | 
|  | 20 | #include <wchar.h> | 
|  | 21 |  | 
|  | 22 |  | 
|  | 23 | static int | 
|  | 24 | do_test (void) | 
|  | 25 | { | 
|  | 26 | int result = 0; | 
|  | 27 |  | 
|  | 28 | const wchar_t src[] = L"0"; | 
|  | 29 | wchar_t dest[21]; | 
|  | 30 | wmemset (dest, L'\0', 10); | 
|  | 31 | wchar_t *endp = wcpncpy (dest, src, 2); | 
|  | 32 | if (wcscmp (dest, src) != 0) | 
|  | 33 | { | 
|  | 34 | result = 1; | 
|  | 35 | puts ("L\"0\" string test failed"); | 
|  | 36 | } | 
|  | 37 | if (endp != dest + 1) | 
|  | 38 | { | 
|  | 39 | result = 1; | 
|  | 40 | puts ("return value of L\"0\" string call incorrect"); | 
|  | 41 | } | 
|  | 42 |  | 
|  | 43 | const wchar_t src2[] = L"abc"; | 
|  | 44 | endp = wcpncpy (dest, src2, 2); | 
|  | 45 | if (endp != dest + 2) | 
|  | 46 | { | 
|  | 47 | result = 1; | 
|  | 48 | puts ("return value of limited call incorrect"); | 
|  | 49 | } | 
|  | 50 |  | 
|  | 51 | const wchar_t src3[] = L""; | 
|  | 52 | endp = wcpncpy (dest, src3, 2); | 
|  | 53 | if (endp != dest) | 
|  | 54 | { | 
|  | 55 | result = 1; | 
|  | 56 | puts ("return value of empty string call incorrect"); | 
|  | 57 | } | 
|  | 58 |  | 
|  | 59 | const wchar_t src4[] = L"abcdefghijklmnopqrstuvwxyz"; | 
|  | 60 | endp = wcpncpy (dest, src4, 2); | 
|  | 61 | if (endp != dest + 2) | 
|  | 62 | { | 
|  | 63 | result = 1; | 
|  | 64 | puts ("return value of long string call incorrect"); | 
|  | 65 | } | 
|  | 66 |  | 
|  | 67 | const wchar_t src5[] = L"ab"; | 
|  | 68 | endp = wcpncpy (dest, src5, 20); | 
|  | 69 | if (endp != dest + 2) | 
|  | 70 | { | 
|  | 71 | result = 1; | 
|  | 72 | puts ("return value of large limit call incorrect"); | 
|  | 73 | } | 
|  | 74 |  | 
|  | 75 | return result; | 
|  | 76 | } | 
|  | 77 |  | 
|  | 78 | #define TEST_FUNCTION do_test () | 
|  | 79 | #include "../test-skeleton.c" |