Debian Codegraph @

ext/safestringlib/unittests/test_strlastchar_s.c

raw
1 /*------------------------------------------------------------------
2 * test_strlastchar_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_strlastchar_s()
16 {
17 errno_t rc;
18
19 char *last;
20 char str1[LEN];
21
22 /*--------------------------------------------------*/
23
24 rc = strlastchar_s(NULL, LEN, 'a', &last);
25 if (rc != ESNULLP) {
26 printf("%s %u Error str1=%p last=%p rc=%d \n",
27 __FUNCTION__, __LINE__, str1, last, rc);
28 }
29
30 if (last) {
31 printf("%s %u Error str1=%p last=%p rc=%d \n",
32 __FUNCTION__, __LINE__, str1, last, rc);
33 }
34
35 /*--------------------------------------------------*/
36
37 rc = strlastchar_s(str1, LEN, 'a', NULL);
38 if (rc != ESNULLP) {
39 printf("%s %u Error str1=%p last=%p rc=%d \n",
40 __FUNCTION__, __LINE__, str1, last, rc);
41 }
42
43 /*--------------------------------------------------*/
44
45 rc = strlastchar_s(str1, 0, 'a', &last);
46 if (rc != ESZEROL) {
47 printf("%s %u Error str1=%p last=%p rc=%d \n",
48 __FUNCTION__, __LINE__, str1, last, rc);
49 }
50
51 if (last) {
52 printf("%s %u Error str1=%p last=%p rc=%d \n",
53 __FUNCTION__, __LINE__, str1, last, rc);
54 }
55
56 /*--------------------------------------------------*/
57
58 rc = strlastchar_s(str1, RSIZE_MAX_STR+1, 'a', &last);
59 if (rc != ESLEMAX) {
60 printf("%s %u Error str1=%p last=%p rc=%d \n",
61 __FUNCTION__, __LINE__, str1, last, rc);
62 }
63
64 if (last) {
65 printf("%s %u Error str1=%p last=%p rc=%d \n",
66 __FUNCTION__, __LINE__, str1, last, rc);
67 }
68
69 /*--------------------------------------------------*/
70
71 str1[0] = '\0';
72
73 rc = strlastchar_s(str1, LEN, 'a', &last);
74 if (rc != ESNOTFND) {
75 printf("%s %u Error str1=%p last=%p rc=%d \n",
76 __FUNCTION__, __LINE__, str1, last, rc);
77 }
78
79 if (last) {
80 printf("%s %u Error str1=%p last=%p rc=%d \n",
81 __FUNCTION__, __LINE__, str1, last, rc);
82 }
83
84 /*--------------------------------------------------*/
85
86 strcpy (str1, "Keep it simple");
87
88 rc = strlastchar_s(str1, 5, 'z', &last);
89 if (rc != ESNOTFND) {
90 printf("%s %u Error str1=%p last=%p rc=%d \n",
91 __FUNCTION__, __LINE__, str1, last, rc);
92 }
93
94 if (last) {
95 printf("%s %u Error str1=%p last=%p rc=%d \n",
96 __FUNCTION__, __LINE__, str1, last, rc);
97 }
98
99 /*--------------------------------------------------*/
100
101 strcpy (str1, "Keep it simplezz");
102
103 rc = strlastchar_s(str1, LEN, 'z', &last);
104 if (rc != EOK) {
105 printf("%s %u Error str1=%p last=%p rc=%d \n",
106 __FUNCTION__, __LINE__, str1, last, rc);
107 }
108
109 if (last != &str1[15]) {
110 printf("%s %u Error str1=%p last=%p rc=%d \n",
111 __FUNCTION__, __LINE__, str1, last, rc);
112 }
113
114 /*--------------------------------------------------*/
115
116 strcpy (str1, "Keep it simple");
117
118 rc = strlastchar_s(str1, LEN, 'K', &last);
119 if (rc != EOK) {
120 printf("%s %u Error rc=%d \n",
121 __FUNCTION__, __LINE__, rc);
122 }
123
124 if (last != &str1[0]) {
125 printf("%s %u Error str1=%p last=%p rc=%d \n",
126 __FUNCTION__, __LINE__, str1, last, rc);
127 }
128
129 /*--------------------------------------------------*/
130
131 strcpy (str1, "kEEp it simple");
132
133 rc = strlastchar_s(str1, LEN, 'E', &last);
134 if (rc != EOK) {
135 printf("%s %u Error rc=%d \n",
136 __FUNCTION__, __LINE__, rc);
137 }
138
139 if (last != &str1[2]) {
140 printf("%s %u Error str1=%p last=%p rc=%d \n",
141 __FUNCTION__, __LINE__, str1, last, rc);
142 }
143
144 /*--------------------------------------------------*/
145
146 strcpy (str1, "kEep it Simple");
147
148 rc = strlastchar_s(str1, LEN, 'S', &last);
149 if (rc != EOK) {
150 printf("%s %u Error rc=%d \n",
151 __FUNCTION__, __LINE__, rc);
152 }
153
154 if (last != &str1[8]) {
155 printf("%s %u Error str1=%p last=%p rc=%d \n",
156 __FUNCTION__, __LINE__, str1, last, rc);
157 }
158
159 /*--------------------------------------------------*/
160 /*--------------------------------------------------*/
161
162 return (0);
163 }