Debian Codegraph @

ext/safestringlib/unittests/test_strzero_s.c

raw
1 /*------------------------------------------------------------------
2 * test_strzero_s
3 *
4 *
5 *------------------------------------------------------------------
6 */
7
8 #include "test_private.h"
9 #include "safe_str_lib.h"
10
11 #define LEN ( 128 )
12
13
14 int test_strzero_s()
15 {
16 errno_t rc;
17 rsize_t max_len;
18 char str1[LEN];
19 uint32_t i;
20
21
22 /*--------------------------------------------------*/
23
24 rc = strzero_s(NULL, 5);
25 if (rc != ESNULLP) {
26 printf("%s %u Error rc=%u \n",
27 __FUNCTION__, __LINE__, rc );
28 }
29
30 /*--------------------------------------------------*/
31
32 rc = strzero_s(str1, 0);
33 if (rc != ESZEROL) {
34 printf("%s %u Error rc=%u \n",
35 __FUNCTION__, __LINE__, rc );
36 }
37
38 /*--------------------------------------------------*/
39
40 rc = strzero_s(str1, RSIZE_MAX_STR+1);
41 if (rc != ESLEMAX) {
42 printf("%s %u Error rc=%u \n",
43 __FUNCTION__, __LINE__, rc );
44 }
45
46 /*--------------------------------------------------*/
47
48 max_len = 1;
49 rc = strzero_s(str1, max_len);
50 if (rc != EOK) {
51 printf("%s %u Error rc=%u \n",
52 __FUNCTION__, __LINE__, rc );
53 }
54
55 for (i=0; i<max_len; i++) {
56 if (str1[i] != '\0') {
57 printf("%s %u Error rc=%u \n",
58 __FUNCTION__, __LINE__, rc );
59 }
60 }
61
62 /*--------------------------------------------------*/
63
64 max_len = 2;
65 rc = strzero_s(str1, max_len);
66 if (rc != EOK) {
67 printf("%s %u Error rc=%u \n",
68 __FUNCTION__, __LINE__, rc );
69 }
70
71 for (i=0; i<max_len; i++) {
72 if (str1[i] != '\0') {
73 printf("%s %u Error rc=%u \n",
74 __FUNCTION__, __LINE__, rc );
75 }
76 }
77
78 /*--------------------------------------------------*/
79
80 max_len = 3;
81 rc = strzero_s(str1, max_len);
82 if (rc != EOK) {
83 printf("%s %u Error rc=%u \n",
84 __FUNCTION__, __LINE__, rc );
85 }
86
87 for (i=0; i<max_len; i++) {
88 if (str1[i] != '\0') {
89 printf("%s %u Error rc=%u \n",
90 __FUNCTION__, __LINE__, rc );
91 }
92 }
93
94 /*--------------------------------------------------*/
95
96 max_len = LEN;
97 rc = strzero_s(str1, max_len);
98 if (rc != EOK) {
99 printf("%s %u Error rc=%u \n",
100 __FUNCTION__, __LINE__, rc );
101 }
102
103 for (i=0; i<max_len; i++) {
104 if (str1[i] != '\0') {
105 printf("%s %u Error rc=%u \n",
106 __FUNCTION__, __LINE__, rc );
107 }
108 }
109
110 /*--------------------------------------------------*/
111
112 strcpy(str1, "Now is the time for all data to be zeroed");
113 max_len = strlen("Now is the ");
114
115 rc = strzero_s(str1, max_len);
116 if (rc != EOK) {
117 printf("%s %u Error rc=%u \n",
118 __FUNCTION__, __LINE__, rc );
119 }
120
121 if (strcmp(&str1[max_len], "time for all data to be zeroed") ) {
122 printf("%s %u ERROR --%s-- \n",
123 __FUNCTION__, __LINE__,
124 &str1[max_len]);
125 }
126
127 /*--------------------------------------------------*/
128
129
130 return (0);
131 }