| 1 |
/*------------------------------------------------------------------ |
| 2 |
* test_strcat_s |
| 3 |
* |
| 4 |
* |
| 5 |
*------------------------------------------------------------------ |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "test_private.h" |
| 9 |
#include "safe_str_lib.h" |
| 10 |
|
| 11 |
#define LEN ( 128 ) |
| 12 |
|
| 13 |
static char str1[LEN]; |
| 14 |
static char str2[LEN]; |
| 15 |
|
| 16 |
int test_strcat_s (void) |
| 17 |
{ |
| 18 |
errno_t rc; |
| 19 |
int32_t ind; |
| 20 |
int32_t len1; |
| 21 |
int32_t len2; |
| 22 |
int32_t len3; |
| 23 |
|
| 24 |
/*--------------------------------------------------*/ |
| 25 |
|
| 26 |
rc = strcat_s(NULL, LEN, str2); |
| 27 |
if (rc != ESNULLP) { |
| 28 |
debug_printf("%s %u Error rc=%u \n", |
| 29 |
__FUNCTION__, __LINE__, rc); |
| 30 |
} |
| 31 |
|
| 32 |
/*--------------------------------------------------*/ |
| 33 |
|
| 34 |
rc = strcat_s(str1, LEN, NULL); |
| 35 |
if (rc != ESNULLP) { |
| 36 |
debug_printf("%s %u Error rc=%u \n", |
| 37 |
__FUNCTION__, __LINE__, rc); |
| 38 |
} |
| 39 |
|
| 40 |
/*--------------------------------------------------*/ |
| 41 |
|
| 42 |
rc = strcat_s(str1, 0, str2); |
| 43 |
if (rc != ESZEROL) { |
| 44 |
debug_printf("%s %u Error rc=%u \n", |
| 45 |
__FUNCTION__, __LINE__, rc); |
| 46 |
} |
| 47 |
|
| 48 |
/*--------------------------------------------------*/ |
| 49 |
|
| 50 |
rc = strcat_s(str1, (RSIZE_MAX_STR+1), str2); |
| 51 |
if (rc != ESLEMAX) { |
| 52 |
debug_printf("%s %u Error rc=%u \n", |
| 53 |
__FUNCTION__, __LINE__, rc); |
| 54 |
} |
| 55 |
|
| 56 |
/*--------------------------------------------------*/ |
| 57 |
/*--------------------------------------------------*/ |
| 58 |
|
| 59 |
strcpy(str1, "aaaaaaaaaa"); |
| 60 |
strcpy(str2, "keep it simple"); |
| 61 |
|
| 62 |
rc = strcat_s(str1, 1, str2); |
| 63 |
if (rc != ESUNTERM) { |
| 64 |
debug_printf("%s %u Error rc=%u \n", |
| 65 |
__FUNCTION__, __LINE__, rc); |
| 66 |
} |
| 67 |
|
| 68 |
if (str1[0] != '\0') { |
| 69 |
debug_printf("%s %u Expected null \n", |
| 70 |
__FUNCTION__, __LINE__); |
| 71 |
} |
| 72 |
|
| 73 |
/*--------------------------------------------------*/ |
| 74 |
|
| 75 |
strcpy(str1, "aaaaaaaaaa"); |
| 76 |
strcpy(str2, "keep it simple"); |
| 77 |
|
| 78 |
rc = strcat_s(str1, 2, str2); |
| 79 |
if (rc != ESUNTERM) { |
| 80 |
debug_printf("%s %u Error rc=%u \n", |
| 81 |
__FUNCTION__, __LINE__, rc); |
| 82 |
} |
| 83 |
|
| 84 |
if (str1[0] != '\0') { |
| 85 |
debug_printf("%s %u Expected null \n", |
| 86 |
__FUNCTION__, __LINE__); |
| 87 |
} |
| 88 |
|
| 89 |
/*--------------------------------------------------*/ |
| 90 |
|
| 91 |
strcpy(&str1[0], "aaaaaaaaaa"); |
| 92 |
strcpy(&str2[0], "keep it simple"); |
| 93 |
|
| 94 |
len1 = strlen(str1); |
| 95 |
len2 = strlen(str2); |
| 96 |
|
| 97 |
rc = strcat_s(str1, 50, str2); |
| 98 |
if (rc != EOK) { |
| 99 |
debug_printf("%s %u Error rc=%u \n", |
| 100 |
__FUNCTION__, __LINE__, rc); |
| 101 |
} |
| 102 |
|
| 103 |
len3 = strlen(str1); |
| 104 |
if (len3 != (len1+len2)) { |
| 105 |
debug_printf("%s %u lengths wrong: %u %u %u \n", |
| 106 |
__FUNCTION__, __LINE__, len1, len2, len3); |
| 107 |
} |
| 108 |
|
| 109 |
/*--------------------------------------------------*/ |
| 110 |
/*--------------------------------------------------*/ |
| 111 |
|
| 112 |
str1[0] = '\0'; |
| 113 |
strcpy(str2, "keep it simple"); |
| 114 |
|
| 115 |
rc = strcat_s(str1, 1, str2); |
| 116 |
if (rc != ESNOSPC) { |
| 117 |
debug_printf("%s %u Error rc=%u \n", |
| 118 |
__FUNCTION__, __LINE__, rc); |
| 119 |
} |
| 120 |
|
| 121 |
if (str1[0] != '\0') { |
| 122 |
debug_printf("%s %u Expected null \n", |
| 123 |
__FUNCTION__, __LINE__); |
| 124 |
} |
| 125 |
|
| 126 |
/*--------------------------------------------------*/ |
| 127 |
|
| 128 |
str1[0] = '\0'; |
| 129 |
strcpy(str2, "keep it simple"); |
| 130 |
|
| 131 |
rc = strcat_s(str1, 2, str2); |
| 132 |
if (rc != ESNOSPC) { |
| 133 |
debug_printf("%s %u Error rc=%u \n", |
| 134 |
__FUNCTION__, __LINE__, rc); |
| 135 |
} |
| 136 |
|
| 137 |
if (str1[0] != '\0') { |
| 138 |
debug_printf("%s %u Expected null \n", |
| 139 |
__FUNCTION__, __LINE__); |
| 140 |
} |
| 141 |
|
| 142 |
/*--------------------------------------------------*/ |
| 143 |
|
| 144 |
str1[0] = '\0'; |
| 145 |
strcpy(str2, "keep it simple"); |
| 146 |
|
| 147 |
rc = strcat_s(str1, 20, str2); |
| 148 |
if (rc != EOK) { |
| 149 |
debug_printf("%s %u Error rc=%u \n", |
| 150 |
__FUNCTION__, __LINE__, rc); |
| 151 |
} |
| 152 |
|
| 153 |
ind = strcmp(str1, str2 ); |
| 154 |
if (ind != 0) { |
| 155 |
debug_printf("%s %u Error -%s- \n", |
| 156 |
__FUNCTION__, __LINE__, str1); |
| 157 |
} |
| 158 |
|
| 159 |
/*--------------------------------------------------*/ |
| 160 |
/*--------------------------------------------------*/ |
| 161 |
|
| 162 |
str1[0] = '\0'; |
| 163 |
str2[0] = '\0'; |
| 164 |
|
| 165 |
rc = strcat_s(str1, LEN, str2); |
| 166 |
if (rc != EOK) { |
| 167 |
debug_printf("%s %u Error rc=%u \n", |
| 168 |
__FUNCTION__, __LINE__, rc); |
| 169 |
} |
| 170 |
|
| 171 |
if (str1[0] != '\0') { |
| 172 |
debug_printf("%s %u Expected null \n", |
| 173 |
__FUNCTION__, __LINE__); |
| 174 |
} |
| 175 |
|
| 176 |
/*--------------------------------------------------*/ |
| 177 |
|
| 178 |
str1[0] = '\0'; |
| 179 |
strcpy(str2, "keep it simple"); |
| 180 |
|
| 181 |
rc = strcat_s(str1, LEN, str2); |
| 182 |
if (rc != EOK) { |
| 183 |
debug_printf("%s %u Error rc=%u \n", |
| 184 |
__FUNCTION__, __LINE__, rc); |
| 185 |
} |
| 186 |
|
| 187 |
ind = strcmp(str1, str2); |
| 188 |
if (ind != 0) { |
| 189 |
debug_printf("%s %u Error -%s- \n", |
| 190 |
__FUNCTION__, __LINE__, str1); |
| 191 |
} |
| 192 |
|
| 193 |
/*--------------------------------------------------*/ |
| 194 |
|
| 195 |
strcpy(str1, "qqweqq"); |
| 196 |
strcpy(str2, "keep it simple"); |
| 197 |
|
| 198 |
rc = strcat_s(str1, LEN, str2); |
| 199 |
if (rc != EOK) { |
| 200 |
debug_printf("%s %u Error rc=%u \n", |
| 201 |
__FUNCTION__, __LINE__, rc); |
| 202 |
} |
| 203 |
|
| 204 |
ind = strcmp(str1, "qqweqqkeep it simple"); |
| 205 |
if (ind != 0) { |
| 206 |
debug_printf("%s %u Error -%s- \n", |
| 207 |
__FUNCTION__, __LINE__, str1); |
| 208 |
} |
| 209 |
|
| 210 |
/*--------------------------------------------------*/ |
| 211 |
|
| 212 |
strcpy(str1, "1234"); |
| 213 |
strcpy(str2, "keep it simple"); |
| 214 |
|
| 215 |
rc = strcat_s(str1, 12, str2); |
| 216 |
if (rc != ESNOSPC) { |
| 217 |
debug_printf("%s %u Error rc=%u \n", |
| 218 |
__FUNCTION__, __LINE__, rc); |
| 219 |
} |
| 220 |
|
| 221 |
/*--------------------------------------------------*/ |
| 222 |
|
| 223 |
strcpy(str1, "1234"); |
| 224 |
strcpy(str2, "keep it simple"); |
| 225 |
|
| 226 |
rc = strcat_s(str1, 52, str2); |
| 227 |
if (rc != EOK) { |
| 228 |
debug_printf("%s %u Error rc=%u \n", |
| 229 |
__FUNCTION__, __LINE__, rc); |
| 230 |
} |
| 231 |
|
| 232 |
ind = strcmp(str1, "1234keep it simple"); |
| 233 |
if (ind != 0) { |
| 234 |
debug_printf("%s %u Error -%s- \n", |
| 235 |
__FUNCTION__, __LINE__, str1); |
| 236 |
} |
| 237 |
|
| 238 |
/*--------------------------------------------------*/ |
| 239 |
|
| 240 |
strcpy(str1, "12345678901234567890"); |
| 241 |
|
| 242 |
rc = strcat_s(str1, 8, &str1[7]); |
| 243 |
if (rc != ESOVRLP) { |
| 244 |
debug_printf("%s %u Error rc=%u \n", |
| 245 |
__FUNCTION__, __LINE__, rc); |
| 246 |
} |
| 247 |
|
| 248 |
if (str1[0] != '\0') { |
| 249 |
debug_printf("%s %u Expected null \n", |
| 250 |
__FUNCTION__, __LINE__); |
| 251 |
} |
| 252 |
|
| 253 |
/*--------------------------------------------------*/ |
| 254 |
|
| 255 |
strcpy(str1, "123456789"); |
| 256 |
|
| 257 |
rc = strcat_s(str1, 9, &str1[8]); |
| 258 |
if (rc != ESOVRLP) { |
| 259 |
debug_printf("%s %u Error rc=%u \n", |
| 260 |
__FUNCTION__, __LINE__, rc); |
| 261 |
} |
| 262 |
|
| 263 |
if (str1[0] != '\0') { |
| 264 |
debug_printf("%s %u Expected null \n", |
| 265 |
__FUNCTION__, __LINE__); |
| 266 |
} |
| 267 |
|
| 268 |
/*--------------------------------------------------*/ |
| 269 |
|
| 270 |
strcpy(str2, "123"); |
| 271 |
strcpy(str1, "keep it simple"); |
| 272 |
|
| 273 |
rc = strcat_s(str2, 31, &str1[0]); |
| 274 |
if (rc != EOK) { |
| 275 |
debug_printf("%s %u Error rc=%u \n", |
| 276 |
__FUNCTION__, __LINE__, rc); |
| 277 |
} |
| 278 |
|
| 279 |
ind = strcmp(str2, "123keep it simple"); |
| 280 |
if (ind != 0) { |
| 281 |
debug_printf("%s %u Error -%s- \n", |
| 282 |
__FUNCTION__, __LINE__, str1); |
| 283 |
} |
| 284 |
|
| 285 |
/*--------------------------------------------------*/ |
| 286 |
|
| 287 |
strcpy(str2, "1234"); |
| 288 |
strcpy(str1, "56789"); |
| 289 |
|
| 290 |
rc = strcat_s(str2, 10, str1); |
| 291 |
if (rc != EOK) { |
| 292 |
debug_printf("%s %u Error rc=%u \n", |
| 293 |
__FUNCTION__, __LINE__, rc); |
| 294 |
} |
| 295 |
|
| 296 |
ind = strcmp(str2, "123456789"); |
| 297 |
if (ind != 0) { |
| 298 |
debug_printf("%s %u Error -%s- \n", |
| 299 |
__FUNCTION__, __LINE__, str1); |
| 300 |
} |
| 301 |
|
| 302 |
/*--------------------------------------------------*/ |
| 303 |
|
| 304 |
return (0); |
| 305 |
} |
| 306 |
|
| 307 |
|