1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/*============================================================================
6**
7** Source: test1.c
8**
9** Purpose:
10** Tests to see that wcsncpy correctly copies wide strings, including handling
11** the count argument correctly (copying no more that count characters, not
12** automatically adding a null, and padding if necessary).
13**
14**
15**==========================================================================*/
16
17#include <palsuite.h>
18
19
20int __cdecl main(int argc, char *argv[])
21{
22 WCHAR dest[80];
23 WCHAR result[] = {'f','o','o','b','a','r',0};
24 WCHAR str[] = {'f','o','o','b','a','r',0,'b','a','z',0};
25 WCHAR *ret;
26 int i;
27
28 if (PAL_Initialize(argc, argv))
29 {
30 return FAIL;
31 }
32
33
34 for (i=0; i<80; i++)
35 {
36 dest[i] = 'x';
37 }
38
39 ret = wcsncpy(dest, str, 3);
40 if (ret != dest)
41 {
42 Fail("Expected wcsncpy to return %p, got %p!\n", dest, ret);
43 }
44
45 if (wcsncmp(dest, result, 3) != 0)
46 {
47 Fail("Expected wcsncpy to give \"%S\", got \"%S\"!\n", result, dest);
48 }
49
50 if (dest[3] != (WCHAR)'x')
51 {
52 Fail("wcsncpy overflowed!\n");
53 }
54
55 ret = wcsncpy(dest, str, 40);
56 if (ret != dest)
57 {
58 Fail("Expected wcsncpy to return %p, got %p!\n", dest, ret);
59 }
60
61 if (wcscmp(dest, result) != 0)
62 {
63 Fail("Expected wcsncpy to give \"%S\", got \"%S\"!\n", result, dest);
64 }
65
66 for (i=wcslen(str); i<40; i++)
67 {
68 if (dest[i] != 0)
69 {
70 Fail("wcsncpy failed to pad the destination with NULLs!\n");
71 }
72 }
73
74 if (dest[40] != (WCHAR)'x')
75 {
76 Fail("wcsncpy overflowed!\n");
77 }
78
79
80
81 PAL_Terminate();
82
83 return PASS;
84}
85