Debian Codegraph @

ext/safestringlib/unittests/test_strprefix_s.c

raw
1 /*------------------------------------------------------------------
2 * test_strprefix_s
3 *
4 *
5 *------------------------------------------------------------------
6 */
7
8 #include "test_private.h"
9 #include "safe_str_lib.h"
10
11 #define LEN ( 128 )
12 #define SHORT_LEN ( 5 )
13
14
15 int test_strprefix_s()
16 {
17 errno_t rc;
18 rsize_t len;
19
20 char str1[LEN];
21 char str2[LEN];
22
23 /*--------------------------------------------------*/
24
25 rc = strprefix_s(NULL, LEN, str2);
26 if (rc != ESNULLP) {
27 printf("%s %u Error rc=%d \n",
28 __FUNCTION__, __LINE__, rc);
29 }
30
31 /*--------------------------------------------------*/
32
33 rc = strprefix_s(str1, LEN, NULL);
34 if (rc != ESNULLP) {
35 printf("%s %u Error rc=%d \n",
36 __FUNCTION__, __LINE__, rc);
37 }
38
39 /*--------------------------------------------------*/
40
41 rc = strprefix_s(str1, 0, str2);
42 if (rc != ESZEROL) {
43 printf("%s %u Error rc=%d \n",
44 __FUNCTION__, __LINE__, rc);
45 }
46
47 /*--------------------------------------------------*/
48
49 rc = strprefix_s(str1, RSIZE_MAX_STR+1, str2);
50 if (rc != ESLEMAX) {
51 printf("%s %u Error rc=%d \n",
52 __FUNCTION__, __LINE__, rc);
53 }
54
55 /*--------------------------------------------------*/
56
57 str1[0] = '\0';
58 str2[0] = '\0';
59
60 rc = strprefix_s(str1, LEN, str2);
61 if (rc != ESNOTFND) {
62 printf("%s %u Error rc=%d \n",
63 __FUNCTION__, __LINE__, rc);
64 }
65
66 /*--------------------------------------------------*/
67
68 strcpy(str1, "keep it simple");
69 strcpy(str2, "keep");
70
71 rc = strprefix_s(str1, 55, str2);
72 if (rc != EOK) {
73 printf("%s %u Error rc=%d \n",
74 __FUNCTION__, __LINE__, rc);
75 }
76
77 /*--------------------------------------------------*/
78
79 strcpy(str1, "keep it simple");
80 strcpy(str2, "kerp");
81
82 rc = strprefix_s(str1, 55, str2);
83 if (rc != ESNOTFND) {
84 printf("%s %u Error rc=%d \n",
85 __FUNCTION__, __LINE__, rc);
86 }
87
88 /*--------------------------------------------------*/
89
90 strcpy(str1, "ke");
91 strcpy(str2, "kerp");
92
93 rc = strprefix_s(str1, 2, str2);
94 if (rc != EOK) {
95 printf("%s %u Error rc=%d \n",
96 __FUNCTION__, __LINE__, rc);
97 }
98
99 /*--------------------------------------------------*/
100
101 strcpy(str1, "keep it simple");
102 strcpy(str2, "keep");
103
104 rc = strprefix_s(str1, 4, str2);
105 if (rc != EOK) {
106 printf("%s %u Error rc=%d \n",
107 __FUNCTION__, __LINE__, rc);
108 }
109
110 /*--------------------------------------------------*/
111
112 strcpy(str1, "keep it simple");
113 strcpy(str2, "keeeep");
114
115 rc = strprefix_s(str1, 4, str2);
116 if (rc != ESNOTFND) {
117 printf("%s %u Error rc=%d \n",
118 __FUNCTION__, __LINE__, rc);
119 }
120
121 /*--------------------------------------------------*/
122
123 strcpy(str1, "keep it simple");
124
125 rc = strprefix_s(str1, 4, "");
126 if (rc != ESNOTFND) {
127 printf("%s %u Error rc=%d \n",
128 __FUNCTION__, __LINE__, rc);
129 }
130
131 /*--------------------------------------------------*/
132
133 strcpy(str1, "keep it simple");
134 strcpy(str2, "keep it sipmle and very long");
135
136 len = strlen(str1);
137
138 rc = strprefix_s(str1, len, str2);
139 if (rc != ESNOTFND) {
140 printf("%s %u Error rc=%d \n",
141 __FUNCTION__, __LINE__, rc);
142 }
143
144 /*--------------------------------------------------*/
145
146 strcpy(str1, "keep it simple");
147 strcpy(str2, "keep it simple");
148
149 len = strlen(str1);
150
151 rc = strprefix_s(str1, len, str2);
152 if (rc != EOK) {
153 printf("%s %u Error rc=%d \n",
154 __FUNCTION__, __LINE__, rc);
155 }
156
157 /*--------------------------------------------------*/
158
159 return (0);
160 }