| 1 |
/*------------------------------------------------------------------ |
| 2 |
* test_strcasecmp_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 |
static char str1[LEN]; |
| 15 |
static char str2[LEN]; |
| 16 |
|
| 17 |
int test_strcasecmp_s (void) |
| 18 |
{ |
| 19 |
errno_t rc; |
| 20 |
|
| 21 |
int ind; |
| 22 |
int std_ind; |
| 23 |
|
| 24 |
/*--------------------------------------------------*/ |
| 25 |
|
| 26 |
rc = strcasecmp_s(NULL, LEN, str2, &ind); |
| 27 |
if (rc != ESNULLP) { |
| 28 |
printf("%s %u Error rc=%d \n", |
| 29 |
__FUNCTION__, __LINE__, rc); |
| 30 |
} |
| 31 |
|
| 32 |
if (ind != 0) { |
| 33 |
printf("%s %u Error ind=%d rc=%d \n", |
| 34 |
__FUNCTION__, __LINE__, ind, rc); |
| 35 |
} |
| 36 |
|
| 37 |
/*--------------------------------------------------*/ |
| 38 |
|
| 39 |
rc = strcasecmp_s(str1, LEN, NULL, &ind); |
| 40 |
if (rc != ESNULLP) { |
| 41 |
printf("%s %u Error rc=%d \n", |
| 42 |
__FUNCTION__, __LINE__, rc); |
| 43 |
} |
| 44 |
|
| 45 |
if (ind != 0) { |
| 46 |
printf("%s %u Error ind=%d rc=%d \n", |
| 47 |
__FUNCTION__, __LINE__, ind, rc); |
| 48 |
} |
| 49 |
|
| 50 |
/*--------------------------------------------------*/ |
| 51 |
|
| 52 |
rc = strcasecmp_s(str1, LEN, str2, NULL); |
| 53 |
if (rc != ESNULLP) { |
| 54 |
printf("%s %u Error rc=%d \n", |
| 55 |
__FUNCTION__, __LINE__, rc); |
| 56 |
} |
| 57 |
|
| 58 |
/*--------------------------------------------------*/ |
| 59 |
|
| 60 |
rc = strcasecmp_s(str1, 0, str2, &ind); |
| 61 |
if (rc != ESZEROL) { |
| 62 |
printf("%s %u Error rc=%d \n", |
| 63 |
__FUNCTION__, __LINE__, rc); |
| 64 |
} |
| 65 |
|
| 66 |
if (ind != 0) { |
| 67 |
printf("%s %u Error ind=%d rc=%d \n", |
| 68 |
__FUNCTION__, __LINE__, ind, rc); |
| 69 |
} |
| 70 |
|
| 71 |
/*--------------------------------------------------*/ |
| 72 |
|
| 73 |
rc = strcasecmp_s(str1, RSIZE_MAX_STR+1, str2, &ind); |
| 74 |
if (rc != ESLEMAX) { |
| 75 |
printf("%s %u Error rc=%d \n", |
| 76 |
__FUNCTION__, __LINE__, rc); |
| 77 |
} |
| 78 |
|
| 79 |
if (ind != 0) { |
| 80 |
printf("%s %u Error ind=%d rc=%d \n", |
| 81 |
__FUNCTION__, __LINE__, ind, rc); |
| 82 |
} |
| 83 |
|
| 84 |
/*--------------------------------------------------*/ |
| 85 |
|
| 86 |
str1[0] = '\0'; |
| 87 |
str2[0] = '\0'; |
| 88 |
|
| 89 |
rc = strcasecmp_s(str1, LEN, str2, &ind); |
| 90 |
if (rc != EOK) { |
| 91 |
printf("%s %u Error rc=%d \n", |
| 92 |
__FUNCTION__, __LINE__, rc); |
| 93 |
} |
| 94 |
|
| 95 |
if (ind != 0) { |
| 96 |
printf("%s %u Error ind=%d rc=%d \n", |
| 97 |
__FUNCTION__, __LINE__, ind, rc); |
| 98 |
} |
| 99 |
|
| 100 |
std_ind = strcasecmp(str1, str2); |
| 101 |
if (ind != std_ind) { |
| 102 |
printf("%s %u ind=%d std_ind=%d rc=%d \n", |
| 103 |
__FUNCTION__, __LINE__, ind, std_ind, rc); |
| 104 |
} |
| 105 |
|
| 106 |
/*--------------------------------------------------*/ |
| 107 |
|
| 108 |
strcpy (str1, "KEEP IT SIMPLE"); |
| 109 |
strcpy (str2, "keep it simple"); |
| 110 |
|
| 111 |
rc = strcasecmp_s(str1, 1, str2, &ind); |
| 112 |
if (rc != EOK) { |
| 113 |
printf("%s %u Error rc=%d \n", |
| 114 |
__FUNCTION__, __LINE__, rc); |
| 115 |
} |
| 116 |
|
| 117 |
if (ind != 0) { |
| 118 |
printf("%s %u Error ind=%d rc=%d \n", |
| 119 |
__FUNCTION__, __LINE__, ind, rc); |
| 120 |
} |
| 121 |
/*--------------------------------------------------*/ |
| 122 |
|
| 123 |
strcpy (str1, "KEEP IT SIMPLE"); |
| 124 |
strcpy (str2, "keep it simple"); |
| 125 |
|
| 126 |
rc = strcasecmp_s(str1, 2, str2, &ind); |
| 127 |
if (rc != EOK) { |
| 128 |
printf("%s %u Error rc=%d \n", |
| 129 |
__FUNCTION__, __LINE__, rc); |
| 130 |
} |
| 131 |
|
| 132 |
if (ind != 0) { |
| 133 |
printf("%s %u Error ind=%d rc=%d \n", |
| 134 |
__FUNCTION__, __LINE__, ind, rc); |
| 135 |
} |
| 136 |
|
| 137 |
/*--------------------------------------------------*/ |
| 138 |
|
| 139 |
strcpy (str1, "KEEP IT SIMPLE"); |
| 140 |
strcpy (str2, "keep it simple"); |
| 141 |
|
| 142 |
rc = strcasecmp_s(str1, 4, str2, &ind); |
| 143 |
if (rc != EOK) { |
| 144 |
printf("%s %u Error rc=%d \n", |
| 145 |
__FUNCTION__, __LINE__, rc); |
| 146 |
} |
| 147 |
|
| 148 |
if (ind != 0) { |
| 149 |
printf("%s %u Error ind=%d rc=%d \n", |
| 150 |
__FUNCTION__, __LINE__, ind, rc); |
| 151 |
} |
| 152 |
|
| 153 |
/*--------------------------------------------------*/ |
| 154 |
|
| 155 |
strcpy (str1, "KEEP IT SIMPLE"); |
| 156 |
strcpy (str2, "keep it simple"); |
| 157 |
|
| 158 |
rc = strcasecmp_s(str1, LEN, str2, &ind); |
| 159 |
if (rc != EOK) { |
| 160 |
printf("%s %u Error rc=%d \n", |
| 161 |
__FUNCTION__, __LINE__, rc); |
| 162 |
} |
| 163 |
|
| 164 |
if (ind != 0) { |
| 165 |
printf("%s %u Error ind=%d rc=%d \n", |
| 166 |
__FUNCTION__, __LINE__, ind, rc); |
| 167 |
} |
| 168 |
|
| 169 |
std_ind = strcasecmp(str1, str2); |
| 170 |
if (ind != std_ind) { |
| 171 |
printf("%s %u ind=%d std_ind=%d rc=%d \n", |
| 172 |
__FUNCTION__, __LINE__, ind, std_ind, rc); |
| 173 |
} |
| 174 |
|
| 175 |
/*--------------------------------------------------*/ |
| 176 |
|
| 177 |
strcpy (str1, "keep it simple"); |
| 178 |
strcpy (str2, "keeP it simple"); |
| 179 |
|
| 180 |
rc = strcasecmp_s(str1, LEN, str2, &ind); |
| 181 |
if (rc != EOK) { |
| 182 |
printf("%s %u Error rc=%d \n", |
| 183 |
__FUNCTION__, __LINE__, rc); |
| 184 |
} |
| 185 |
|
| 186 |
if (ind != 0) { |
| 187 |
printf("%s %u Error ind=%d rc=%d \n", |
| 188 |
__FUNCTION__, __LINE__, ind, rc); |
| 189 |
} |
| 190 |
|
| 191 |
/*--------------------------------------------------*/ |
| 192 |
|
| 193 |
strcpy (str1, "keep it simple"); |
| 194 |
|
| 195 |
rc = strcasecmp_s(str1, LEN, str1, &ind); |
| 196 |
if (rc != EOK) { |
| 197 |
printf("%s %u Error rc=%d \n", |
| 198 |
__FUNCTION__, __LINE__, rc); |
| 199 |
} |
| 200 |
|
| 201 |
if (ind != 0) { |
| 202 |
printf("%s %u Error ind=%d rc=%d \n", |
| 203 |
__FUNCTION__, __LINE__, ind, rc); |
| 204 |
} |
| 205 |
|
| 206 |
/*--------------------------------------------------*/ |
| 207 |
|
| 208 |
strcpy (str1, "KEEP it simplified"); |
| 209 |
strcpy (str2, "keep it simple"); |
| 210 |
|
| 211 |
rc = strcasecmp_s(str1, LEN, str2, &ind); |
| 212 |
if (rc != EOK) { |
| 213 |
printf("%s %u Error rc=%d \n", |
| 214 |
__FUNCTION__, __LINE__, rc); |
| 215 |
} |
| 216 |
|
| 217 |
if (ind != ('I' - 'E')) { |
| 218 |
printf("%s %u Error ind=%d rc=%d \n", |
| 219 |
__FUNCTION__, __LINE__, ind, rc); |
| 220 |
} |
| 221 |
|
| 222 |
/*--------------------------------------------------*/ |
| 223 |
|
| 224 |
strcpy (str1, "KEEP 1234567890"); |
| 225 |
strcpy (str2, "keep it simple"); |
| 226 |
|
| 227 |
rc = strcasecmp_s(str1, LEN, str2, &ind); |
| 228 |
if (rc != EOK) { |
| 229 |
printf("%s %u Error rc=%d \n", |
| 230 |
__FUNCTION__, __LINE__, rc); |
| 231 |
} |
| 232 |
|
| 233 |
if (ind != ('1' - 'I')) { |
| 234 |
printf("%s %u Error ind=%d rc=%d %d \n", |
| 235 |
__FUNCTION__, __LINE__, ind, rc, ('1' - 'I')); |
| 236 |
} |
| 237 |
|
| 238 |
/*--------------------------------------------------*/ |
| 239 |
|
| 240 |
return (0); |
| 241 |
} |
| 242 |
|