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 that wcsncat correctly appends wide strings, making sure it handles
11** count argument correctly (appending no more than count characters, always
12** placing a null, and padding the string 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 test[] = {'f','o','o',' ','b','a','r','b','a','z',0};
24 WCHAR str1[] = {'f','o','o',' ',0};
25 WCHAR str2[] = {'b','a','r',' ',0};
26 WCHAR str3[] = {'b','a','z',0};
27 WCHAR *ptr;
28 int i;
29
30
31 if (PAL_Initialize(argc, argv))
32 {
33 return FAIL;
34 }
35
36
37 dest[0] = 0;
38 for (i=1; i<80; i++)
39 {
40 dest[i] = (WCHAR)'x';
41 }
42
43 ptr = wcsncat(dest, str1, wcslen(str1));
44 if (ptr != dest)
45 {
46 Fail("ERROR: Expected wcsncat to return ptr to %p, got %p", dest, ptr);
47 }
48
49 ptr = wcsncat(dest, str2, 3);
50 if (ptr != dest)
51 {
52 Fail("ERROR: Expected wcsncat to return ptr to %p, got %p", dest, ptr);
53 }
54 if (dest[7] != 0)
55 {
56 Fail("ERROR: wcsncat did not place a terminating NULL!");
57 }
58
59 ptr = wcsncat(dest, str3, 20);
60 if (ptr != dest)
61 {
62 Fail("ERROR: Expected wcsncat to return ptr to %p, got %p", dest, ptr);
63 }
64 if (wcscmp(dest, test) != 0)
65 {
66 Fail("ERROR: Expected wcsncat to give \"%S\", got \"%S\"\n",
67 test, dest);
68 }
69 if (dest[wcslen(test)+1] != (WCHAR)'x')
70 {
71 Fail("wcsncat went out of bounds!\n");
72 }
73
74 PAL_Terminate();
75
76 return PASS;
77}
78