1 /*
2 WCSNCPY: wchar_t *wcsncpy (wchar_t *ws1, const wchar_t *ws2, size_t n);
3 */
4
5 #define TST_FUNCTION wcsncpy
6
7 #include "tsp_common.c"
8 #include "dat_wcsncpy.c"
9
10 #define WCSNUM_NCPY 7
11
12 int
tst_wcsncpy(FILE * fp,int debug_flg)13 tst_wcsncpy (FILE *fp, int debug_flg)
14 {
15 TST_DECL_VARS (wchar_t *);
16 wchar_t ws1[WCSSIZE] =
17 { 0x9999, 0x9999, 0x9999, 0x9999, 0x9999, 0x9999, 0x0000 };
18 wchar_t *ws2, *ws_ex;
19 int err, i;
20 size_t n;
21
22 TST_DO_TEST (wcsncpy)
23 {
24 TST_HEAD_LOCALE (wcsncpy, S_WCSNCPY);
25 TST_DO_REC (wcsncpy)
26 {
27 TST_GET_ERRET (wcsncpy);
28
29 for (n = 0; n < WCSNUM_NCPY - 1; ++n)
30 {
31 ws1[n] = 0x9999;
32 }
33
34 ws1[n] = 0;
35 ws2 = TST_INPUT (wcsncpy).ws; /* external value: size WCSSIZE */
36 n = TST_INPUT (wcsncpy).n;
37 ret = wcsncpy (ws1, ws2, n);
38
39 TST_IF_RETURN (S_WCSNCPY)
40 {
41 if (ret == ws1)
42 {
43 Result (C_SUCCESS, S_WCSNCPY, CASE_3, MS_PASSED);
44 }
45 else
46 {
47 err_count++;
48 Result (C_FAILURE, S_WCSNCPY, CASE_3,
49 "the return address may not be correct");
50 }
51 }
52
53 if (ret == ws1)
54 {
55 if (debug_flg)
56 {
57 fprintf (stderr, "\nwcsncpy: n = %zu\n\n", n);
58 }
59
60 ws_ex = TST_EXPECT (wcsncpy).ws;
61
62 for (err = 0, i = 0; i < WCSNUM_NCPY && i < WCSSIZE; i++)
63 {
64 if (debug_flg)
65 fprintf (stderr,
66 "wcsncpy: ws1[ %d ] = 0x%lx <-> wx_ex[ %d ] = 0x%lx\n",
67 i, (unsigned long int) ws1[i], i,
68 (unsigned long int) ws_ex[i]);
69
70 if (ws1[i] != ws_ex[i])
71 {
72 err++;
73 err_count++;
74 Result (C_FAILURE, S_WCSNCPY, CASE_4,
75 "copied string is different from an "
76 "expected string");
77 break;
78 }
79 }
80
81 if (!err)
82 {
83 Result (C_SUCCESS, S_WCSNCPY, CASE_4, MS_PASSED);
84 }
85
86 /* A null terminate character is not supposed to be copied
87 unless (num chars of ws2)<n. */
88 }
89 }
90 }
91
92 return err_count;
93 }
94