Lev Walkin | 4eceeba | 2007-07-23 06:48:26 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <assert.h> |
| 3 | |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 4 | #include <asn_application.h> |
Lev Walkin | 4eceeba | 2007-07-23 06:48:26 +0000 | [diff] [blame] | 5 | #include <INTEGER.h> |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 6 | |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 7 | #define CHECK_XER(a,b,c) check_xer(__LINE__, a, b, c) |
| 8 | |
Lev Walkin | db13f51 | 2004-07-19 17:30:25 +0000 | [diff] [blame] | 9 | static char *shared_scratch_start; |
| 10 | |
| 11 | static int _print2buf(const void *buf, size_t size, void *key) { |
| 12 | (void)key; |
| 13 | memcpy(shared_scratch_start, buf, size); |
| 14 | shared_scratch_start += size; |
| 15 | *shared_scratch_start = '\0'; /* 0-termination */ |
| 16 | return 0; |
| 17 | } |
| 18 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 19 | static void |
Lev Walkin | 494fb70 | 2017-08-07 20:07:00 -0700 | [diff] [blame] | 20 | check(uint8_t *buf, size_t size, long check_long, int check_ret) { |
Lev Walkin | db13f51 | 2004-07-19 17:30:25 +0000 | [diff] [blame] | 21 | char scratch[128]; |
| 22 | char verify[32]; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 23 | INTEGER_t val; |
Lev Walkin | db13f51 | 2004-07-19 17:30:25 +0000 | [diff] [blame] | 24 | uint8_t *buf_end = buf + size; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 25 | int ret; |
| 26 | long rlong = 123; |
| 27 | |
| 28 | assert(buf); |
Vasil Velichkov | 72b1044 | 2017-10-19 04:38:38 +0300 | [diff] [blame] | 29 | assert(size > 0); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 30 | |
| 31 | val.buf = buf; |
| 32 | val.size = size; |
| 33 | |
Lev Walkin | db13f51 | 2004-07-19 17:30:25 +0000 | [diff] [blame] | 34 | printf("Testing: ["); |
| 35 | for(; buf < buf_end; buf++) { |
| 36 | if(buf != val.buf) printf(":"); |
| 37 | printf("%02x", *buf); |
| 38 | } |
| 39 | printf("]: "); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 40 | |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 41 | ret = asn_INTEGER2long(&val, &rlong); |
Lev Walkin | db13f51 | 2004-07-19 17:30:25 +0000 | [diff] [blame] | 42 | printf(" (%ld, %d) vs (%ld, %d)\n", |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 43 | rlong, ret, check_long, check_ret); |
| 44 | assert(ret == check_ret); |
Lev Walkin | 3370016 | 2004-10-26 09:03:31 +0000 | [diff] [blame] | 45 | printf("%ld %ld\n", rlong, check_long); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 46 | assert(rlong == check_long); |
Lev Walkin | db13f51 | 2004-07-19 17:30:25 +0000 | [diff] [blame] | 47 | |
Lev Walkin | c698ee5 | 2004-10-21 11:19:51 +0000 | [diff] [blame] | 48 | if(check_ret == 0) { |
| 49 | INTEGER_t val2; |
| 50 | long rlong2; |
| 51 | val2.buf = 0; |
| 52 | val2.size = 0; |
| 53 | ret = asn_long2INTEGER(&val2, rlong); |
| 54 | assert(ret == 0); |
| 55 | assert(val2.buf); |
| 56 | assert(val2.size <= val.size); /* At least as compact */ |
| 57 | ret = asn_INTEGER2long(&val, &rlong2); |
| 58 | assert(ret == 0); |
| 59 | assert(rlong == rlong2); |
Lev Walkin | 229ad00 | 2017-09-18 20:13:49 -0700 | [diff] [blame] | 60 | ASN_STRUCT_RESET(asn_DEF_INTEGER, &val2); |
Lev Walkin | c698ee5 | 2004-10-21 11:19:51 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Lev Walkin | db13f51 | 2004-07-19 17:30:25 +0000 | [diff] [blame] | 63 | shared_scratch_start = scratch; |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 64 | ret = INTEGER_print(&asn_DEF_INTEGER, &val, 0, _print2buf, scratch); |
Lev Walkin | db13f51 | 2004-07-19 17:30:25 +0000 | [diff] [blame] | 65 | assert(shared_scratch_start < scratch + sizeof(scratch)); |
| 66 | assert(ret == 0); |
| 67 | ret = snprintf(verify, sizeof(verify), "%ld", check_long); |
Lev Walkin | 9736348 | 2016-01-24 19:23:02 -0800 | [diff] [blame] | 68 | assert(ret < 0 || (size_t)ret < sizeof(verify)); |
Lev Walkin | db13f51 | 2004-07-19 17:30:25 +0000 | [diff] [blame] | 69 | ret = strcmp(scratch, verify); |
| 70 | printf(" [%s] vs [%s]: %d%s\n", |
| 71 | scratch, verify, ret, |
| 72 | (check_ret == -1)?" (expected to fail)":"" |
| 73 | ); |
| 74 | if(check_ret == -1) { |
| 75 | assert(strcmp(scratch, verify)); |
| 76 | } else { |
| 77 | assert(strcmp(scratch, verify) == 0); |
| 78 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Lev Walkin | 0be3a99 | 2004-10-21 12:11:57 +0000 | [diff] [blame] | 81 | static void |
Lev Walkin | 5c879db | 2007-11-06 06:23:31 +0000 | [diff] [blame] | 82 | check_unsigned(uint8_t *buf, int size, unsigned long check_long, int check_ret) { |
| 83 | char scratch[128]; |
| 84 | char verify[32]; |
| 85 | INTEGER_t val; |
| 86 | uint8_t *buf_end = buf + size; |
| 87 | int ret; |
| 88 | unsigned long rlong = 123; |
| 89 | |
| 90 | assert(buf); |
| 91 | assert(size >= 0); |
| 92 | |
| 93 | val.buf = buf; |
| 94 | val.size = size; |
| 95 | |
| 96 | printf("Testing: ["); |
| 97 | for(; buf < buf_end; buf++) { |
| 98 | if(buf != val.buf) printf(":"); |
| 99 | printf("%02x", *buf); |
| 100 | } |
| 101 | printf("]: "); |
| 102 | |
| 103 | ret = asn_INTEGER2ulong(&val, &rlong); |
| 104 | printf(" (%lu, %d) vs (%lu, %d)\n", |
| 105 | rlong, ret, check_long, check_ret); |
| 106 | assert(ret == check_ret); |
Lev Walkin | 5c879db | 2007-11-06 06:23:31 +0000 | [diff] [blame] | 107 | assert(rlong == check_long); |
| 108 | |
| 109 | if(check_ret == 0) { |
| 110 | INTEGER_t val2; |
| 111 | unsigned long rlong2; |
| 112 | val2.buf = 0; |
| 113 | val2.size = 0; |
| 114 | ret = asn_ulong2INTEGER(&val2, rlong); |
| 115 | assert(ret == 0); |
| 116 | assert(val2.buf); |
| 117 | if(val2.size > val.size) { |
| 118 | /* At least as compact */ |
| 119 | printf("val2.size=%d, val.size=%d\n", |
| 120 | (int)val2.size, (int)val.size); |
| 121 | assert(val2.size <= val.size); |
| 122 | } |
| 123 | ret = asn_INTEGER2ulong(&val, &rlong2); |
| 124 | assert(ret == 0); |
| 125 | assert(rlong == rlong2); |
Lev Walkin | 229ad00 | 2017-09-18 20:13:49 -0700 | [diff] [blame] | 126 | ASN_STRUCT_RESET(asn_DEF_INTEGER, &val2); |
Lev Walkin | 5c879db | 2007-11-06 06:23:31 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Lev Walkin | 97f8edc | 2013-03-28 04:38:41 -0700 | [diff] [blame] | 129 | return; |
| 130 | |
Lev Walkin | 5c879db | 2007-11-06 06:23:31 +0000 | [diff] [blame] | 131 | shared_scratch_start = scratch; |
| 132 | ret = INTEGER_print(&asn_DEF_INTEGER, &val, 0, _print2buf, scratch); |
| 133 | assert(shared_scratch_start < scratch + sizeof(scratch)); |
| 134 | assert(ret == 0); |
Lev Walkin | 043babe | 2012-01-22 18:06:59 -0800 | [diff] [blame] | 135 | ret = snprintf(verify, sizeof(verify), "%lu", check_long); |
Vasil Velichkov | 72b1044 | 2017-10-19 04:38:38 +0300 | [diff] [blame] | 136 | assert(ret < (int)sizeof(verify)); |
Lev Walkin | 5c879db | 2007-11-06 06:23:31 +0000 | [diff] [blame] | 137 | ret = strcmp(scratch, verify); |
| 138 | printf(" [%s] vs [%s]: %d%s\n", |
| 139 | scratch, verify, ret, |
| 140 | (check_ret == -1)?" (expected to fail)":"" |
| 141 | ); |
| 142 | if(check_ret == -1) { |
| 143 | assert(strcmp(scratch, verify)); |
| 144 | } else { |
| 145 | assert(strcmp(scratch, verify) == 0); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | static void |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 150 | check_xer(int lineno, int tofail, char *xmldata, long orig_value) { |
Lev Walkin | 0be3a99 | 2004-10-21 12:11:57 +0000 | [diff] [blame] | 151 | INTEGER_t *st = 0; |
| 152 | asn_dec_rval_t rc; |
| 153 | long value; |
| 154 | int ret; |
| 155 | |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 156 | printf("%03d: [%s] vs %ld: ", lineno, xmldata, orig_value); |
Lev Walkin | 0be3a99 | 2004-10-21 12:11:57 +0000 | [diff] [blame] | 157 | |
| 158 | rc = xer_decode(0, &asn_DEF_INTEGER, (void *)&st, |
| 159 | xmldata, strlen(xmldata)); |
| 160 | if(rc.code != RC_OK) { |
| 161 | assert(tofail); |
| 162 | printf("\tfailed, as expected\n"); |
Lev Walkin | 229ad00 | 2017-09-18 20:13:49 -0700 | [diff] [blame] | 163 | ASN_STRUCT_FREE(asn_DEF_INTEGER, st); |
Lev Walkin | 0be3a99 | 2004-10-21 12:11:57 +0000 | [diff] [blame] | 164 | return; |
| 165 | } |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 166 | if(tofail) { |
| 167 | printf("\tnot failed, as expected!\n"); |
| 168 | assert(!tofail); |
| 169 | } |
Lev Walkin | 0be3a99 | 2004-10-21 12:11:57 +0000 | [diff] [blame] | 170 | |
| 171 | ret = asn_INTEGER2long(st, &value); |
| 172 | assert(ret == 0); |
| 173 | |
| 174 | printf("\t%ld\n", value); |
| 175 | |
| 176 | assert(value == orig_value); |
| 177 | |
Bi-Ruei, Chiu | 1f87ac0 | 2017-08-20 01:25:45 +0800 | [diff] [blame] | 178 | ASN_STRUCT_FREE(asn_DEF_INTEGER, st); |
Lev Walkin | 0be3a99 | 2004-10-21 12:11:57 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Lev Walkin | 6495ca5 | 2019-08-10 20:07:39 -0700 | [diff] [blame] | 181 | static void |
| 182 | check_strtoimax() { |
| 183 | const intmax_t intmax_max = ((~(uintmax_t)0) >> 1); |
| 184 | const intmax_t intmax_min = -((intmax_t)intmax_max) - 1; |
| 185 | char positive_max[32]; |
| 186 | char negative_min[32]; |
| 187 | const int len_pmax = snprintf(positive_max, sizeof(positive_max), |
| 188 | "+%" ASN_PRIdMAX, intmax_max); |
| 189 | const int len_nmin = snprintf(negative_min, sizeof(negative_min), |
| 190 | "%" ASN_PRIdMAX, intmax_min); |
| 191 | assert(len_pmax < (int)sizeof(positive_max)); |
| 192 | assert(len_nmin < (int)sizeof(negative_min)); |
| 193 | |
| 194 | enum asn_strtox_result_e result; |
| 195 | intmax_t value; |
| 196 | |
| 197 | /* |
| 198 | * Test edge values first. |
| 199 | */ |
| 200 | // Positive. |
| 201 | const char *last_pmax = &positive_max[len_pmax]; |
| 202 | result = asn_strtoimax_lim(positive_max, &last_pmax, &value); |
| 203 | assert(result == ASN_STRTOX_OK); |
| 204 | assert(last_pmax == &positive_max[len_pmax]); |
| 205 | assert(value == intmax_max); |
| 206 | // Negative. |
| 207 | const char *last_nmin = &negative_min[len_nmin]; |
| 208 | result = asn_strtoimax_lim(negative_min, &last_nmin, &value); |
| 209 | assert(result == ASN_STRTOX_OK); |
| 210 | assert(last_nmin == &negative_min[len_nmin]); |
| 211 | assert(value == intmax_min); |
| 212 | |
| 213 | /* |
| 214 | * Test one smaller than edge evalues. |
| 215 | */ |
| 216 | positive_max[len_pmax - 1]--; |
| 217 | negative_min[len_nmin - 1]--; |
| 218 | // Positive. |
| 219 | result = asn_strtoimax_lim(positive_max, &last_pmax, &value); |
| 220 | assert(result == ASN_STRTOX_OK); |
| 221 | assert(last_pmax == &positive_max[len_pmax]); |
| 222 | assert(value == intmax_max - 1); |
| 223 | // Negative. |
| 224 | result = asn_strtoimax_lim(negative_min, &last_nmin, &value); |
| 225 | assert(result == ASN_STRTOX_OK); |
| 226 | assert(last_nmin == &negative_min[len_nmin]); |
| 227 | assert(value == intmax_min + 1); |
| 228 | |
| 229 | /* |
| 230 | * Test one bigger than edge evalues. |
| 231 | */ |
| 232 | positive_max[len_pmax - 1] += 2; |
| 233 | negative_min[len_nmin - 1] += 2; |
| 234 | // Positive. |
| 235 | value = 42; |
| 236 | result = asn_strtoimax_lim(positive_max, &last_pmax, &value); |
| 237 | assert(result == ASN_STRTOX_ERROR_RANGE); |
| 238 | assert(last_pmax == &positive_max[len_pmax - 1]); |
| 239 | assert(value == 42); |
| 240 | // Negative. |
| 241 | value = 42; |
| 242 | result = asn_strtoimax_lim(negative_min, &last_nmin, &value); |
| 243 | assert(result == ASN_STRTOX_ERROR_RANGE); |
| 244 | assert(last_nmin == &negative_min[len_nmin - 1]); |
| 245 | assert(value == 42); |
| 246 | |
| 247 | /* |
| 248 | * Get back to the edge. |
| 249 | * Append an extra digit at the end. |
| 250 | */ |
| 251 | positive_max[len_pmax - 1]--; |
| 252 | negative_min[len_nmin - 1]--; |
| 253 | assert(len_pmax < (int)sizeof(positive_max) - 1); |
| 254 | assert(len_nmin < (int)sizeof(negative_min) - 1); |
| 255 | strcat(positive_max, "0"); |
| 256 | strcat(negative_min, "0"); |
| 257 | last_pmax++; |
| 258 | last_nmin++; |
| 259 | value = 42; |
| 260 | result = asn_strtoimax_lim(positive_max, &last_pmax, &value); |
| 261 | assert(result == ASN_STRTOX_OK); |
| 262 | assert(value == intmax_max); |
| 263 | result = asn_strtoimax_lim(negative_min, &last_nmin, &value); |
| 264 | assert(result == ASN_STRTOX_OK); |
| 265 | assert(value == intmax_min); |
| 266 | } |
| 267 | |
| 268 | /* |
| 269 | * Check that asn_strtoimax_lim() always reaches the end of the numeric |
| 270 | * sequence, even if it can't fit into the range. |
| 271 | */ |
| 272 | static void |
| 273 | check_strtoimax_span() { |
| 274 | const intmax_t intmax_max = ((~(uintmax_t)0) >> 1); |
| 275 | const intmax_t almost_min = -((intmax_t)(intmax_max - 10)); |
| 276 | char buf[64]; |
| 277 | intmax_t value = 42; |
| 278 | enum asn_strtox_result_e result; |
| 279 | |
| 280 | // Check a particular way to integer overflow. |
| 281 | // Check that we scan until the very end. |
| 282 | int len = snprintf(buf, sizeof(buf), "%" PRIdMAX "0</end>", almost_min); |
| 283 | assert(len < (int)sizeof(buf)); |
| 284 | const char *nmlast = &buf[len]; |
| 285 | result = asn_strtoimax_lim(buf, &nmlast, &value); |
| 286 | assert(*nmlast == '0'); |
| 287 | assert((ptrdiff_t)(nmlast - buf) == (ptrdiff_t)(len - strlen("0</end>"))); |
| 288 | assert(result == ASN_STRTOX_ERROR_RANGE); |
| 289 | assert(value == 42); |
| 290 | |
| 291 | // Check a particular way to integer overflow. |
| 292 | // Check that we scan until the very end. |
| 293 | len = snprintf(buf, sizeof(buf), "%" PRIdMAX "</end>", almost_min); |
| 294 | assert(len < (int)sizeof(buf)); |
| 295 | nmlast = &buf[len]; |
| 296 | result = asn_strtoimax_lim(buf, &nmlast, &value); |
| 297 | assert(*nmlast == '<'); |
| 298 | assert((ptrdiff_t)(nmlast - buf) == (ptrdiff_t)(len - strlen("</end>"))); |
| 299 | assert(result == ASN_STRTOX_EXTRA_DATA); |
| 300 | assert(value == almost_min); |
| 301 | |
| 302 | } |
| 303 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 304 | int |
Lev Walkin | 9736348 | 2016-01-24 19:23:02 -0800 | [diff] [blame] | 305 | main() { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 306 | uint8_t buf1[] = { 1 }; |
| 307 | uint8_t buf2[] = { 0xff }; |
| 308 | uint8_t buf3[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
| 309 | uint8_t buf4[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0 }; |
| 310 | uint8_t buf5[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 }; |
| 311 | uint8_t buf6[] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; |
| 312 | uint8_t buf7[] = { 0xff, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; |
| 313 | uint8_t buf8[] = { 0x7f, 0x7e, 0x7d, 0x7c }; |
| 314 | uint8_t buf9[] = { 0, 0x7f, 0x7e, 0x7d, 0x7c }; |
| 315 | uint8_t buf10[] = { 0, 0, 0, 0, 0, 0, 0x7f, 0x7e, 0x7d, 0x7c }; |
Lev Walkin | c698ee5 | 2004-10-21 11:19:51 +0000 | [diff] [blame] | 316 | uint8_t buf11[] = { 0x80, 0, 0, 0 }; |
| 317 | uint8_t buf12[] = { 0x80, 0 }; |
| 318 | uint8_t buf13[] = { 0x80 }; |
Lev Walkin | 5c879db | 2007-11-06 06:23:31 +0000 | [diff] [blame] | 319 | uint8_t buf14[] = { 0x00, 0x80, 0x00, 0x00 }; |
| 320 | uint8_t buf15[] = { 0x00, 0x80, 0x00, 0x00, 0x00 }; |
| 321 | uint8_t buf16[] = { 0x00, 0xff, 0xff, 0x00, 0x00 }; |
| 322 | |
| 323 | #define UCHECK(buf, val, ret) check_unsigned(buf, sizeof(buf), val, ret) |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 324 | |
| 325 | #define CHECK(buf, val, ret) check(buf, sizeof(buf), val, ret) |
| 326 | |
| 327 | CHECK(buf1, 1, 0); |
| 328 | CHECK(buf2, -1, 0); |
| 329 | CHECK(buf3, -1, 0); |
| 330 | CHECK(buf4, -16, 0); |
| 331 | CHECK(buf5, 257, 0); |
| 332 | CHECK(buf6, 123, -1); |
| 333 | CHECK(buf7, 123, -1); |
| 334 | CHECK(buf8, 0x7F7E7D7C, 0); |
| 335 | CHECK(buf9, 0x7F7E7D7C, 0); |
| 336 | CHECK(buf10, 0x7F7E7D7C, 0); |
Lev Walkin | 5c879db | 2007-11-06 06:23:31 +0000 | [diff] [blame] | 337 | UCHECK(buf10, 0x7F7E7D7C, 0); |
Lev Walkin | 3f36e46 | 2005-08-15 01:02:47 +0000 | [diff] [blame] | 338 | CHECK(buf11, -2147483647-1, 0); /* 0x80000000 */ |
Lev Walkin | c698ee5 | 2004-10-21 11:19:51 +0000 | [diff] [blame] | 339 | CHECK(buf12, -32768, 0); |
| 340 | CHECK(buf13, -128, 0); |
Lev Walkin | 5c879db | 2007-11-06 06:23:31 +0000 | [diff] [blame] | 341 | UCHECK(buf14, 0x800000, 0); |
Lev Walkin | 043babe | 2012-01-22 18:06:59 -0800 | [diff] [blame] | 342 | UCHECK(buf15, 0x80000000UL, 0); |
| 343 | UCHECK(buf16, 0xffff0000UL, 0); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 344 | |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 345 | CHECK_XER(-1, "", 0); |
| 346 | CHECK_XER(-1, "<INTEGER></INTEGER>", 0); |
| 347 | CHECK_XER(-1, "<INTEGER> </INTEGER>", 0); |
| 348 | CHECK_XER(-1, "<INTEGER>-</INTEGER>", 0); |
| 349 | CHECK_XER(-1, "<INTEGER>+</INTEGER>", 0); |
| 350 | CHECK_XER(-1, "<INTEGER>+-</INTEGER>", 0); |
| 351 | CHECK_XER(-1, "<INTEGER> -</INTEGER>", 0); |
| 352 | CHECK_XER(-1, "<INTEGER> +</INTEGER>", 0); |
| 353 | CHECK_XER(-1, "<INTEGER> +-</INTEGER>", 0); |
| 354 | CHECK_XER(-1, "<INTEGER>- </INTEGER>", 0); |
| 355 | CHECK_XER(-1, "<INTEGER>+ </INTEGER>", 0); |
| 356 | CHECK_XER(-1, "<INTEGER>+- </INTEGER>", 0); |
| 357 | CHECK_XER(-1, "<INTEGER> - </INTEGER>", 0); |
| 358 | CHECK_XER(-1, "<INTEGER> + </INTEGER>", 0); |
| 359 | CHECK_XER(-1, "<INTEGER> +- </INTEGER>", 0); |
| 360 | CHECK_XER(0, "<INTEGER>+0</INTEGER>", 0); |
| 361 | CHECK_XER(0, "<INTEGER>-0</INTEGER>", 0); |
| 362 | CHECK_XER(0, "<INTEGER>+1</INTEGER>", 1); |
| 363 | CHECK_XER(0, "<INTEGER>-1</INTEGER>", -1); |
| 364 | CHECK_XER(0, "<INTEGER>1</INTEGER>", 1); |
| 365 | CHECK_XER(0, "<INTEGER>-15</INTEGER>", -15); |
| 366 | CHECK_XER(0, "<INTEGER>+15</INTEGER>", 15); |
| 367 | CHECK_XER(0, "<INTEGER>15</INTEGER>", 15); |
| 368 | CHECK_XER(0, "<INTEGER> 15</INTEGER>", 15); |
| 369 | CHECK_XER(0, "<INTEGER> 15 </INTEGER>", 15); |
| 370 | CHECK_XER(0, "<INTEGER>15 </INTEGER>", 15); |
| 371 | CHECK_XER(0, "<INTEGER> +15 </INTEGER>", 15); |
| 372 | CHECK_XER(-1, "<INTEGER> +15 -</INTEGER>", 0); |
| 373 | CHECK_XER(-1, "<INTEGER> +15 1</INTEGER>", 0); |
| 374 | CHECK_XER(-1, "<INTEGER>+ 15</INTEGER>", 0); |
| 375 | CHECK_XER(-1, "<INTEGER>12<z>34</INTEGER>", 0); |
| 376 | CHECK_XER(-1, "<INTEGER>12 <z>34</INTEGER>", 0); |
| 377 | CHECK_XER(-1, "<INTEGER>12 <z></INTEGER>", 0); |
| 378 | CHECK_XER(0, "<INTEGER>1234</INTEGER>", 1234); |
| 379 | CHECK_XER(-1, "<INTEGER>1234 5678</INTEGER>", 0); |
| 380 | CHECK_XER(0, "<INTEGER>-2147483647</INTEGER>", -2147483647); |
| 381 | CHECK_XER(0, "<INTEGER>-2147483648</INTEGER>", -2147483647-1); |
| 382 | CHECK_XER(0, "<INTEGER>+2147483647</INTEGER>", 2147483647); |
| 383 | CHECK_XER(0, "<INTEGER>2147483647</INTEGER>", 2147483647); |
Lev Walkin | e59f767 | 2004-10-23 10:17:02 +0000 | [diff] [blame] | 384 | if(sizeof(long) == 4) { |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 385 | CHECK_XER( 0, "<INTEGER>-2147483648</INTEGER>", -2147483648); |
| 386 | CHECK_XER(-1, "<INTEGER>-2147483649</INTEGER>", 0); |
| 387 | CHECK_XER(-1, "<INTEGER>2147483648</INTEGER>", 0); |
| 388 | CHECK_XER(-1, "<INTEGER>2147483649</INTEGER>", 0); |
| 389 | CHECK_XER(-1, "<INTEGER>3147483649</INTEGER>", 0); |
| 390 | CHECK_XER(-1, "<INTEGER>4147483649</INTEGER>", 0); |
| 391 | CHECK_XER(-1, "<INTEGER>5147483649</INTEGER>", 0); /* special */ |
| 392 | CHECK_XER(-1, "<INTEGER>9147483649</INTEGER>", 0); |
| 393 | CHECK_XER(-1, "<INTEGER>9999999999</INTEGER>", 0); |
| 394 | CHECK_XER(-1, "<INTEGER>-5147483649</INTEGER>", 0);/* special */ |
| 395 | CHECK_XER(-1, "<INTEGER>-9147483649</INTEGER>", 0); |
| 396 | CHECK_XER(-1, "<INTEGER>-9999999999</INTEGER>", 0); |
Lev Walkin | a7d1fb3 | 2012-01-23 01:21:55 +0000 | [diff] [blame] | 397 | } |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 398 | #ifdef TEST_64BIT |
Lev Walkin | a7d1fb3 | 2012-01-23 01:21:55 +0000 | [diff] [blame] | 399 | if(sizeof(long) == 8) { |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 400 | CHECK_XER(0, "<INTEGER>2147483648</INTEGER>", 2147483648); |
| 401 | CHECK_XER(0, "<INTEGER>2147483649</INTEGER>", 2147483649); |
| 402 | CHECK_XER(0, "<INTEGER>3147483649</INTEGER>", 3147483649); |
| 403 | CHECK_XER(0, "<INTEGER>4147483649</INTEGER>", 4147483649); |
| 404 | CHECK_XER(0, "<INTEGER>5147483649</INTEGER>", 5147483649); |
| 405 | CHECK_XER(0, "<INTEGER>9147483649</INTEGER>", 9147483649); |
| 406 | CHECK_XER(0, "<INTEGER>9999999999</INTEGER>", 9999999999); |
| 407 | CHECK_XER(0, "<INTEGER>9223372036854775807</INTEGER>", 9223372036854775807); |
| 408 | CHECK_XER(-1, "<INTEGER>9223372036854775808</INTEGER>", 0); |
| 409 | CHECK_XER(-1, "<INTEGER>10223372036854775807</INTEGER>", 0); |
| 410 | CHECK_XER(-1, "<INTEGER>50223372036854775807</INTEGER>", 0); |
| 411 | CHECK_XER(-1, "<INTEGER>100223372036854775807</INTEGER>", 0); |
| 412 | CHECK_XER(-1, "<INTEGER>500223372036854775807</INTEGER>", 0); |
| 413 | CHECK_XER(0, "<INTEGER>-9223372036854775808</INTEGER>", -9223372036854775807-1); |
| 414 | CHECK_XER(-1, "<INTEGER>-9223372036854775809</INTEGER>", 0); |
| 415 | CHECK_XER(-1, "<INTEGER>-10223372036854775807</INTEGER>", 0); |
| 416 | CHECK_XER(-1, "<INTEGER>-50223372036854775807</INTEGER>", 0); |
| 417 | CHECK_XER(-1, "<INTEGER>-100223372036854775807</INTEGER>", 0); |
| 418 | CHECK_XER(-1, "<INTEGER>-500223372036854775807</INTEGER>", 0); |
| 419 | } else { |
| 420 | assert(sizeof(long) == 8); |
| 421 | } |
| 422 | #endif |
Lev Walkin | 0be3a99 | 2004-10-21 12:11:57 +0000 | [diff] [blame] | 423 | |
Lev Walkin | 6495ca5 | 2019-08-10 20:07:39 -0700 | [diff] [blame] | 424 | check_strtoimax(); |
| 425 | check_strtoimax_span(); |
| 426 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 427 | return 0; |
| 428 | } |