Lev Walkin | 4eceeba | 2007-07-23 06:48:26 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <assert.h> |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 3 | #include <errno.h> |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 4 | #include <sys/time.h> |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 5 | |
Lev Walkin | 4eceeba | 2007-07-23 06:48:26 +0000 | [diff] [blame] | 6 | #include <OBJECT_IDENTIFIER.h> |
| 7 | #include <RELATIVE-OID.h> |
| 8 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 9 | static int |
| 10 | _print(const void *buffer, size_t size, void *app_key) { |
Lev Walkin | 46bf935 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 11 | (void)app_key; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 12 | fwrite(buffer, size, 1, stdout); |
| 13 | return 0; |
| 14 | } |
| 15 | |
| 16 | static void |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 17 | check_OID(int lineno, uint8_t *buf, size_t len, unsigned *ck_buf, int ck_len) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 18 | OBJECT_IDENTIFIER_t *oid; |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 19 | asn_dec_rval_t rval; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 20 | unsigned long arcs[10]; |
| 21 | int alen; |
| 22 | int i; |
| 23 | |
Lev Walkin | 0995f35 | 2017-09-17 23:16:38 -0700 | [diff] [blame] | 24 | printf("%03d: Checking {", lineno); |
Lev Walkin | 46bf935 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 25 | for(i = 0; i < (int)len; i++) { printf("%s%02x", i?" ":"", buf[i]); } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 26 | printf("} against {"); |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 27 | for(i = 0; i < ck_len; i++) { printf("%s%u", i?" ":"", ck_buf[i]); } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 28 | printf("}\n"); |
| 29 | |
| 30 | oid = NULL; |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 31 | rval = ber_decode(0, &asn_DEF_OBJECT_IDENTIFIER, (void *)&oid, buf, len); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 32 | assert(rval.code == RC_OK); |
| 33 | |
Lev Walkin | 494fb70 | 2017-08-07 20:07:00 -0700 | [diff] [blame] | 34 | assert((ssize_t)oid->size == (ssize_t)len - 2); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 35 | |
| 36 | /* |
| 37 | * Print the contents for visual debugging. |
| 38 | */ |
| 39 | printf("OBJECT_IDENTIFIER_print() => "); |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 40 | OBJECT_IDENTIFIER_print(&asn_DEF_OBJECT_IDENTIFIER, oid, 0, _print, 0); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 41 | printf("\n"); |
| 42 | |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 43 | memset(arcs, 'A', sizeof(arcs)); |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 44 | alen = OBJECT_IDENTIFIER_get_arcs(oid, |
| 45 | arcs, sizeof(arcs[0]), sizeof(arcs)/sizeof(arcs[0])); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 46 | assert(alen > 0); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 47 | |
Lev Walkin | 6c9e071 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 48 | printf("OBJECT_IDENTIFIER_get_arcs() => {"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 49 | /* |
| 50 | * Make sure they are equivalent. |
| 51 | */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 52 | for(i = 0; i < alen; i++) { |
| 53 | printf(" %lu", arcs[i]); |
Lev Walkin | 6c9e071 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 54 | if(alen == ck_len) { |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 55 | assert(arcs[i] == ck_buf[i]); |
Lev Walkin | 6c9e071 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 56 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 57 | } |
| 58 | printf(" }\n"); |
Lev Walkin | 6c9e071 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 59 | assert(alen == ck_len); |
| 60 | |
Lev Walkin | 229ad00 | 2017-09-18 20:13:49 -0700 | [diff] [blame] | 61 | ASN_STRUCT_FREE(asn_DEF_OBJECT_IDENTIFIER, oid); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | static void |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 65 | check_ROID(int lineno, uint8_t *buf, size_t len, unsigned *ck_buf, int ck_len) { |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 66 | RELATIVE_OID_t *oid; |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 67 | asn_dec_rval_t rval; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 68 | unsigned long arcs[10]; |
| 69 | int alen; |
| 70 | int i; |
| 71 | |
Lev Walkin | 0995f35 | 2017-09-17 23:16:38 -0700 | [diff] [blame] | 72 | printf("%03d: Checking {", lineno); |
Lev Walkin | 46bf935 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 73 | for(i = 0; i < (ssize_t)len; i++) { printf("%s%02x", i?" ":"", buf[i]); } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 74 | printf("} against {"); |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 75 | for(i = 0; i < ck_len; i++) { printf("%s%u", i?" ":"", ck_buf[i]); } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 76 | printf("}\n"); |
| 77 | |
| 78 | oid = NULL; |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 79 | rval = ber_decode(0, &asn_DEF_RELATIVE_OID, (void *)&oid, buf, len); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 80 | assert(rval.code == RC_OK); |
| 81 | |
Lev Walkin | 494fb70 | 2017-08-07 20:07:00 -0700 | [diff] [blame] | 82 | assert((ssize_t)oid->size == (ssize_t)len - 2); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 83 | |
| 84 | /* |
| 85 | * Print the contents for visual debugging. |
| 86 | */ |
| 87 | printf("RELATIVE_OID_print() => "); |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 88 | RELATIVE_OID_print(&asn_DEF_RELATIVE_OID, oid, 0, _print, 0); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 89 | printf("\n"); |
| 90 | |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 91 | memset(arcs, 'A', sizeof(arcs)); |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 92 | alen = RELATIVE_OID_get_arcs(oid, |
| 93 | arcs, sizeof(arcs[0]), sizeof(arcs)/sizeof(arcs[0])); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 94 | assert(alen > 0); |
| 95 | assert(alen == ck_len); |
| 96 | |
| 97 | /* |
| 98 | * Make sure they are equivalent. |
| 99 | */ |
| 100 | printf("RELATIVE_OID_get_arcs() => {"); |
| 101 | for(i = 0; i < alen; i++) { |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 102 | printf(" %lu", arcs[i]); |
| 103 | assert(arcs[i] == ck_buf[i]); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 104 | } |
| 105 | printf(" }\n"); |
Lev Walkin | 229ad00 | 2017-09-18 20:13:49 -0700 | [diff] [blame] | 106 | ASN_STRUCT_FREE(asn_DEF_RELATIVE_OID, oid); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 109 | static int |
| 110 | check_speed() { |
| 111 | uint8_t buf[] = { 0x80 | 7, 0x80 | 2, 0x80 | 3, 0x80 | 4, 13 }; |
| 112 | int ret = 0; |
| 113 | int cycles = 100000000; |
| 114 | double a, b, c; |
| 115 | struct timeval tv; |
| 116 | unsigned long value; |
| 117 | int i; |
| 118 | |
Lev Walkin | 46bf935 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 119 | ret = OBJECT_IDENTIFIER_get_single_arc(buf, sizeof(buf), 0, &value, sizeof(value)); |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 120 | assert(ret == 0); |
| 121 | assert(value == 0x7040c20d); |
| 122 | |
| 123 | gettimeofday(&tv, 0); |
| 124 | a = tv.tv_sec + tv.tv_usec / 1000000.0; |
| 125 | for(i = 0; i < cycles; i++) { |
| 126 | ret = OBJECT_IDENTIFIER_get_single_arc(buf, sizeof(buf), 0, |
| 127 | &value, sizeof(value)); |
| 128 | } |
| 129 | assert(ret == 0); |
| 130 | assert(value == 0x7040c20d); |
| 131 | gettimeofday(&tv, 0); |
| 132 | b = tv.tv_sec + tv.tv_usec / 1000000.0; |
| 133 | for(i = 0; i < cycles; i++) { |
| 134 | ret = OBJECT_IDENTIFIER_get_single_arc(buf, sizeof(buf), 0, |
| 135 | &value, sizeof(value)); |
| 136 | } |
| 137 | assert(ret == 0); |
| 138 | assert(value == 0x7040c20d); |
| 139 | gettimeofday(&tv, 0); |
| 140 | c = tv.tv_sec + tv.tv_usec / 1000000.0; |
| 141 | |
| 142 | a = b - a; |
| 143 | b = c - b; |
| 144 | printf("Time for single_arc(): %f\n", a); |
| 145 | printf("Time for get_arc_l(): %f\n", b); |
| 146 | |
| 147 | return 0; |
| 148 | } |
| 149 | |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 150 | static void check_parse(const char *oid_txt, int retval) { |
| 151 | int ret; |
| 152 | long l[2]; |
Lev Walkin | cad560a | 2013-03-16 07:00:58 -0700 | [diff] [blame] | 153 | const char *p = oid_txt - 13; |
| 154 | assert(p < oid_txt); |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 155 | |
| 156 | ret = OBJECT_IDENTIFIER_parse_arcs(oid_txt, -1, l, 2, &p); |
| 157 | printf("[%s] => %d == %d\n", oid_txt, ret, retval); |
| 158 | assert(ret == retval); |
| 159 | assert(p >= oid_txt); |
| 160 | } |
| 161 | |
| 162 | static void check_xer(int expect_arcs, char *xer) { |
| 163 | asn_dec_rval_t rc; |
| 164 | RELATIVE_OID_t *st = 0; |
| 165 | long arcs[10]; |
| 166 | int ret; |
| 167 | int i; |
| 168 | |
| 169 | printf("[%s] => ", xer); fflush(stdout); |
Bi-Ruei, Chiu | 1f87ac0 | 2017-08-20 01:25:45 +0800 | [diff] [blame] | 170 | rc = asn_DEF_RELATIVE_OID.op->xer_decoder(0, |
Lev Walkin | 229ad00 | 2017-09-18 20:13:49 -0700 | [diff] [blame] | 171 | &asn_DEF_RELATIVE_OID, (void **)&st, "t", |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 172 | xer, strlen(xer)); |
| 173 | if(expect_arcs == -1) { |
Lev Walkin | f592711 | 2012-09-03 00:48:45 -0700 | [diff] [blame] | 174 | if(rc.code != RC_OK) { |
| 175 | printf("-1\n"); |
Lev Walkin | 229ad00 | 2017-09-18 20:13:49 -0700 | [diff] [blame] | 176 | ASN_STRUCT_FREE(asn_DEF_RELATIVE_OID, st); |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 177 | return; |
Lev Walkin | f592711 | 2012-09-03 00:48:45 -0700 | [diff] [blame] | 178 | } |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 179 | } |
| 180 | assert(rc.code == RC_OK); |
| 181 | |
| 182 | ret = RELATIVE_OID_get_arcs(st, arcs, sizeof(arcs[0]), |
| 183 | sizeof(arcs)/sizeof(arcs[0])); |
| 184 | assert(ret < 10); |
| 185 | if(expect_arcs == -1) { |
| 186 | assert(ret == -1); |
Lev Walkin | 229ad00 | 2017-09-18 20:13:49 -0700 | [diff] [blame] | 187 | ASN_STRUCT_FREE(asn_DEF_RELATIVE_OID, st); |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 188 | return; |
| 189 | } |
| 190 | for(i = 0; i < ret; i++) { |
| 191 | if(i) printf("."); |
| 192 | printf("%ld", arcs[i]); |
Lev Walkin | cad560a | 2013-03-16 07:00:58 -0700 | [diff] [blame] | 193 | if(arcs[i] != i + 1) printf(" != %d\n", i + 1); |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 194 | assert(arcs[i] == i + 1); |
| 195 | } |
| 196 | printf(": %d == %d\n", ret, expect_arcs); |
| 197 | assert(ret == expect_arcs); |
Lev Walkin | 229ad00 | 2017-09-18 20:13:49 -0700 | [diff] [blame] | 198 | ASN_STRUCT_FREE(asn_DEF_RELATIVE_OID, st); |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Lev Walkin | 0995f35 | 2017-09-17 23:16:38 -0700 | [diff] [blame] | 201 | #define CHECK_OID(n) \ |
| 202 | check_OID(__LINE__, buf##n, sizeof(buf##n), buf##n##_check, \ |
| 203 | sizeof(buf##n##_check) / sizeof(buf##n##_check[0])) |
| 204 | #define CHECK_ROID(n) \ |
| 205 | check_ROID(__LINE__, buf##n, sizeof(buf##n), buf##n##_check, \ |
| 206 | sizeof(buf##n##_check) / sizeof(buf##n##_check[0])) |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 207 | |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 208 | static void |
| 209 | check_binary_parsing() { |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 210 | |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 211 | /* {joint-iso-itu-t 230 3} */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 212 | uint8_t buf1[] = { |
| 213 | 0x06, /* OBJECT IDENTIFIER */ |
| 214 | 0x03, /* Length */ |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 215 | 0x82, 0x36, 0x03 |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 216 | }; |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 217 | unsigned buf1_check[] = { 2, 230, 3 }; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 218 | |
| 219 | /* {8571 3 2} */ |
| 220 | uint8_t buf2[] = { |
| 221 | 0x0D, /* RELATIVE-OID */ |
| 222 | 0x04, /* Length */ |
| 223 | 0xC2, 0x7B, 0x03, 0x02 |
| 224 | }; |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 225 | unsigned buf2_check[] = { 8571, 3, 2 }; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 226 | |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 227 | /* {joint-iso-itu-t 42 } */ |
| 228 | uint8_t buf3[] = { |
| 229 | 0x06, /* OBJECT IDENTIFIER */ |
| 230 | 0x01, /* Length */ |
| 231 | 0x7A |
| 232 | }; |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 233 | unsigned buf3_check[] = { 2, 42 }; |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 234 | |
| 235 | /* {joint-iso-itu-t 25957 } */ |
| 236 | uint8_t buf4[] = { |
| 237 | 0x06, /* OBJECT IDENTIFIER */ |
| 238 | 0x03, /* Length */ |
| 239 | 0x81, 0x80 + 0x4B, 0x35 |
| 240 | }; |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 241 | unsigned buf4_check[] = { 2, 25957 }; |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 242 | |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 243 | /* { jounsigned-iso-itu-t 2 1 1 } */ |
| 244 | uint8_t buf5[] = { |
Lev Walkin | 6c9e071 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 245 | 0x06, /* OBJECT IDENTIFIER */ |
| 246 | 0x03, /* Length */ |
| 247 | 0x52, 0x01, 0x01 |
| 248 | }; |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 249 | unsigned buf5_check[] = { 2, 2, 1, 1 }; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 250 | |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 251 | /* { jounsigned-iso-itu-t 2 1 0 1 } */ |
| 252 | uint8_t buf6[] = { |
Lev Walkin | 3251b8e | 2004-08-23 09:23:02 +0000 | [diff] [blame] | 253 | 0x06, /* OBJECT IDENTIFIER */ |
| 254 | 0x04, /* Length */ |
| 255 | 0x52, 0x01, 0x00, 0x01 |
| 256 | }; |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 257 | unsigned buf6_check[] = { 2, 2, 1, 0, 1 }; |
Lev Walkin | 3251b8e | 2004-08-23 09:23:02 +0000 | [diff] [blame] | 258 | |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 259 | CHECK_OID(1); |
| 260 | CHECK_ROID(2); |
| 261 | CHECK_OID(3); |
| 262 | CHECK_OID(4); |
| 263 | CHECK_OID(5); |
| 264 | CHECK_OID(6); |
| 265 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 266 | |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 267 | static void |
| 268 | check_text_parsing() { |
| 269 | check_parse("", 0); |
| 270 | check_parse(" ", 0); |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 271 | check_parse(".", -1); |
| 272 | check_parse(" .", -1); |
Lev Walkin | f592711 | 2012-09-03 00:48:45 -0700 | [diff] [blame] | 273 | check_parse(".1", -1); |
| 274 | check_parse("1.", -1); |
| 275 | check_parse("1. ", -1); |
| 276 | check_parse(".1. ", -1); |
| 277 | check_parse(" .1. ", -1); |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 278 | check_parse(" 1", 1); |
| 279 | check_parse(" 1.2", 2); |
| 280 | check_parse(" 1.", -1); |
| 281 | check_parse(" 1. ", -1); |
| 282 | check_parse("1. ", -1); |
| 283 | check_parse("1.2", 2); |
Lev Walkin | f592711 | 2012-09-03 00:48:45 -0700 | [diff] [blame] | 284 | check_parse("1.2 ", 2); |
| 285 | check_parse("1.2 ", 2); |
| 286 | check_parse(" 1.2 ", 2); |
| 287 | check_parse("1. 2", -1); |
| 288 | check_parse("1 .2", -1); |
Lev Walkin | cad560a | 2013-03-16 07:00:58 -0700 | [diff] [blame] | 289 | check_parse(" 1 .2", -1); |
| 290 | check_parse(" 1 .2 ", -1); |
| 291 | check_parse("1 .2 ", -1); |
| 292 | check_parse("1.+1", -1); |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 293 | check_parse("10.30.234.234", 4); |
| 294 | check_parse("10.30.234.234 ", 4); |
| 295 | check_parse("10.30.234. 234 ", -1); |
| 296 | check_parse("10.30.234.234.", -1); |
| 297 | check_parse("1.2000000000.3", 3); |
| 298 | check_parse("1.2147483647.3", 3); |
| 299 | if(sizeof(long) == 4) { |
| 300 | check_parse("1.2147483648.3", -1); /* overflow on ILP32 */ |
Lev Walkin | a7d1fb3 | 2012-01-23 01:21:55 +0000 | [diff] [blame] | 301 | check_parse("1.2147483649.3", -1); /* overflow on ILP32 */ |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 302 | check_parse("1.3000000000.3", -1); |
| 303 | check_parse("1.4000000000.3", -1); |
| 304 | check_parse("1.5000000000.3", -1); |
| 305 | check_parse("1.6000000000.3", -1); |
| 306 | check_parse("1.9000000000.3", -1); |
Lev Walkin | a7d1fb3 | 2012-01-23 01:21:55 +0000 | [diff] [blame] | 307 | } else if(sizeof(long) == 8) { |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 308 | check_parse("1.2147483648.3", 3); |
Lev Walkin | a7d1fb3 | 2012-01-23 01:21:55 +0000 | [diff] [blame] | 309 | check_parse("1.9223372036854775807.3", 3); |
| 310 | check_parse("1.9223372036854775808.3", -1); |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 311 | } |
| 312 | check_parse("1.900a0000000.3", -1); |
| 313 | check_parse("1.900a.3", -1); |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 314 | } |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 315 | |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 316 | static void |
| 317 | check_xer_parsing() { |
Lev Walkin | f592711 | 2012-09-03 00:48:45 -0700 | [diff] [blame] | 318 | check_xer(-1, "<t></t>"); |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 319 | check_xer(2, "<t>1.2</t>"); |
| 320 | check_xer(3, "<t>1.2.3</t>"); |
| 321 | check_xer(3, "<t> 1.2.3 </t>"); |
| 322 | check_xer(-1, "<t>1.2.3 1</t>"); |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 323 | } |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 324 | |
Lev Walkin | 6cbed3d | 2017-10-07 16:42:41 -0700 | [diff] [blame] | 325 | int |
| 326 | main() { |
| 327 | check_binary_parsing(); |
| 328 | check_text_parsing(); |
| 329 | check_xer_parsing(); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 330 | |
Lev Walkin | c4c6196 | 2004-06-14 08:17:27 +0000 | [diff] [blame] | 331 | if(getenv("CHECK_SPEED")) { |
| 332 | /* Useful for developers only */ |
| 333 | check_speed(); |
| 334 | } |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 335 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 336 | return 0; |
| 337 | } |
Lev Walkin | 725883b | 2006-10-09 12:07:58 +0000 | [diff] [blame] | 338 | |