| 1 |
/*------------------------------------------------------------------ |
| 2 |
* test_strncat_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_strncat_s (void) |
| 17 |
{ |
| 18 |
errno_t rc; |
| 19 |
int32_t ind; |
| 20 |
|
| 21 |
/*--------------------------------------------------*/ |
| 22 |
|
| 23 |
rc = strncat_s(NULL, LEN, str2, LEN); |
| 24 |
if (rc != ESNULLP) { |
| 25 |
debug_printf("%s %u Error rc=%u \n", |
| 26 |
__FUNCTION__, __LINE__, rc); |
| 27 |
} |
| 28 |
|
| 29 |
/*--------------------------------------------------*/ |
| 30 |
|
| 31 |
rc = strncat_s(str1, LEN, NULL, LEN); |
| 32 |
if (rc != ESNULLP) { |
| 33 |
debug_printf("%s %u Error rc=%u \n", |
| 34 |
__FUNCTION__, __LINE__, rc); |
| 35 |
} |
| 36 |
|
| 37 |
/*--------------------------------------------------*/ |
| 38 |
|
| 39 |
rc = strncat_s(str1, 0, str2, LEN); |
| 40 |
if (rc != ESZEROL) { |
| 41 |
debug_printf("%s %u Error rc=%u \n", |
| 42 |
__FUNCTION__, __LINE__, rc); |
| 43 |
} |
| 44 |
|
| 45 |
/*--------------------------------------------------*/ |
| 46 |
|
| 47 |
rc = strncat_s(str1, (RSIZE_MAX_STR+1), str2, LEN); |
| 48 |
if (rc != ESLEMAX) { |
| 49 |
debug_printf("%s %u Error rc=%u \n", |
| 50 |
__FUNCTION__, __LINE__, rc); |
| 51 |
} |
| 52 |
|
| 53 |
/*--------------------------------------------------*/ |
| 54 |
|
| 55 |
rc = strncat_s(str1, (RSIZE_MAX_STR), str2, (RSIZE_MAX_STR+1)); |
| 56 |
if (rc != ESLEMAX) { |
| 57 |
debug_printf("%s %u Error rc=%u \n", |
| 58 |
__FUNCTION__, __LINE__, rc); |
| 59 |
} |
| 60 |
|
| 61 |
/*--------------------------------------------------*/ |
| 62 |
|
| 63 |
strcpy(str1, "aaaaaaaaaa"); |
| 64 |
strcpy(str2, "keep it simple"); |
| 65 |
|
| 66 |
rc = strncat_s(str1, 1, str2, LEN); |
| 67 |
if (rc != ESUNTERM) { |
| 68 |
debug_printf("%s %u Error rc=%u \n", |
| 69 |
__FUNCTION__, __LINE__, rc); |
| 70 |
} |
| 71 |
|
| 72 |
if (str1[0] != '\0') { |
| 73 |
debug_printf("%s %u Expected null \n", |
| 74 |
__FUNCTION__, __LINE__); |
| 75 |
} |
| 76 |
|
| 77 |
/*--------------------------------------------------*/ |
| 78 |
|
| 79 |
strcpy(str1, "aaaaaaaaaa"); |
| 80 |
strcpy(str2, "keep it simple"); |
| 81 |
|
| 82 |
rc = strncat_s(str1, 2, str2, LEN); |
| 83 |
if (rc != ESUNTERM) { |
| 84 |
debug_printf("%s %u Error rc=%u \n", |
| 85 |
__FUNCTION__, __LINE__, rc); |
| 86 |
} |
| 87 |
|
| 88 |
if (str1[0] != '\0') { |
| 89 |
debug_printf("%s %u Expected null \n", |
| 90 |
__FUNCTION__, __LINE__); |
| 91 |
} |
| 92 |
|
| 93 |
/*--------------------------------------------------*/ |
| 94 |
|
| 95 |
strcpy(str1, "a"); |
| 96 |
strcpy(str2, "b"); |
| 97 |
|
| 98 |
rc = strncat_s(str1, 2, str2, 1); |
| 99 |
if (rc != ESNOSPC) { |
| 100 |
debug_printf("%s %u Error rc=%u \n", |
| 101 |
__FUNCTION__, __LINE__, rc); |
| 102 |
} |
| 103 |
|
| 104 |
if (str1[0] != '\0') { |
| 105 |
debug_printf("%s %u Expected null \n", |
| 106 |
__FUNCTION__, __LINE__); |
| 107 |
} |
| 108 |
|
| 109 |
/*--------------------------------------------------*/ |
| 110 |
|
| 111 |
strcpy(str1, "a"); |
| 112 |
strcpy(str2, "b"); |
| 113 |
|
| 114 |
rc = strncat_s(str1, 3, str2, 1); |
| 115 |
if (rc != EOK) { |
| 116 |
debug_printf("%s %u Error rc=%u \n", |
| 117 |
__FUNCTION__, __LINE__, rc); |
| 118 |
} |
| 119 |
|
| 120 |
ind = strcmp(str1, "ab"); |
| 121 |
if (ind != 0) { |
| 122 |
debug_printf("%s %u Error -%s- \n", |
| 123 |
__FUNCTION__, __LINE__, str1); |
| 124 |
} |
| 125 |
|
| 126 |
/*--------------------------------------------------*/ |
| 127 |
|
| 128 |
strcpy(str1, "aaaaaaaaaa"); |
| 129 |
strcpy(str2, "keep it simple"); |
| 130 |
|
| 131 |
rc = strncat_s(str1, 50, str2, LEN); |
| 132 |
if (rc != EOK) { |
| 133 |
debug_printf("%s %u Error rc=%u \n", |
| 134 |
__FUNCTION__, __LINE__, rc); |
| 135 |
} |
| 136 |
|
| 137 |
ind = strcmp(str1, "aaaaaaaaaakeep it simple"); |
| 138 |
if (ind != 0) { |
| 139 |
debug_printf("%s %u Error -%s- \n", |
| 140 |
__FUNCTION__, __LINE__, str1); |
| 141 |
} |
| 142 |
|
| 143 |
/*--------------------------------------------------*/ |
| 144 |
/*--------------------------------------------------*/ |
| 145 |
/* TR example */ |
| 146 |
|
| 147 |
strcpy(str1, "good"); |
| 148 |
strcpy(str2, "bye"); |
| 149 |
|
| 150 |
rc = strncat_s(str1, 100, str2, 100); |
| 151 |
if (rc != EOK) { |
| 152 |
debug_printf("%s %u Error rc=%u \n", |
| 153 |
__FUNCTION__, __LINE__, rc); |
| 154 |
} |
| 155 |
|
| 156 |
ind = strcmp(str1, "goodbye"); |
| 157 |
if (ind != 0) { |
| 158 |
debug_printf("%s %u Error -%s- \n", |
| 159 |
__FUNCTION__, __LINE__, str1); |
| 160 |
} |
| 161 |
|
| 162 |
/*--------------------------------------------------*/ |
| 163 |
/* TR example */ |
| 164 |
|
| 165 |
strcpy(str1, "hello"); |
| 166 |
|
| 167 |
rc = strncat_s(str1, 6, "", 1); |
| 168 |
if (rc != EOK) { |
| 169 |
debug_printf("%s %u Error rc=%u \n", |
| 170 |
__FUNCTION__, __LINE__, rc); |
| 171 |
} |
| 172 |
|
| 173 |
ind = strcmp(str1, "hello"); |
| 174 |
if (ind != 0) { |
| 175 |
debug_printf("%s %u Error -%s- \n", |
| 176 |
__FUNCTION__, __LINE__, str1); |
| 177 |
} |
| 178 |
|
| 179 |
/*--------------------------------------------------*/ |
| 180 |
/* TR example */ |
| 181 |
|
| 182 |
strcpy(str1, "hello"); |
| 183 |
|
| 184 |
rc = strncat_s(str1, 6, "X", 2); |
| 185 |
if (rc != ESNOSPC) { |
| 186 |
debug_printf("%s %u Error rc=%u \n", |
| 187 |
__FUNCTION__, __LINE__, rc); |
| 188 |
} |
| 189 |
|
| 190 |
if (str1[0] != '\0') { |
| 191 |
debug_printf("%s %u Expected null \n", |
| 192 |
__FUNCTION__, __LINE__); |
| 193 |
} |
| 194 |
|
| 195 |
/*--------------------------------------------------*/ |
| 196 |
/* TR example */ |
| 197 |
|
| 198 |
strcpy(str1, "abc"); |
| 199 |
|
| 200 |
rc = strncat_s(str1, 7, "defghijklmn", 3); |
| 201 |
if (rc != EOK) { |
| 202 |
debug_printf("%s %u Error rc=%u \n", |
| 203 |
__FUNCTION__, __LINE__, rc); |
| 204 |
} |
| 205 |
|
| 206 |
ind = strcmp(str1, "abcdef"); |
| 207 |
if (ind != 0) { |
| 208 |
debug_printf("%s %u Error -%s- \n", |
| 209 |
__FUNCTION__, __LINE__, str1); |
| 210 |
} |
| 211 |
|
| 212 |
/*--------------------------------------------------*/ |
| 213 |
|
| 214 |
return (0); |
| 215 |
} |
| 216 |
|
| 217 |
|