Lev Walkin | 4eceeba | 2007-07-23 06:48:26 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <assert.h> |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 3 | #include <sys/time.h> |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 4 | |
Lev Walkin | 4eceeba | 2007-07-23 06:48:26 +0000 | [diff] [blame] | 5 | #include <OBJECT_IDENTIFIER.h> |
| 6 | #include <RELATIVE-OID.h> |
| 7 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 8 | static int |
| 9 | _print(const void *buffer, size_t size, void *app_key) { |
Lev Walkin | 46bf935 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 10 | (void)app_key; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 11 | fwrite(buffer, size, 1, stdout); |
| 12 | return 0; |
| 13 | } |
| 14 | |
| 15 | static void |
| 16 | check_OID(uint8_t *buf, size_t len, int *ck_buf, int ck_len) { |
| 17 | OBJECT_IDENTIFIER_t *oid; |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 18 | asn_dec_rval_t rval; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 19 | unsigned long arcs[10]; |
| 20 | int alen; |
| 21 | int i; |
| 22 | |
| 23 | printf("Checking {"); |
Lev Walkin | 46bf935 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 24 | 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] | 25 | printf("} against {"); |
| 26 | for(i = 0; i < ck_len; i++) { printf("%s%d", i?" ":"", ck_buf[i]); } |
| 27 | printf("}\n"); |
| 28 | |
| 29 | oid = NULL; |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 30 | rval = ber_decode(0, &asn_DEF_OBJECT_IDENTIFIER, (void *)&oid, buf, len); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 31 | assert(rval.code == RC_OK); |
| 32 | |
Lev Walkin | 46bf935 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 33 | assert(oid->size == (ssize_t)len - 2); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 34 | |
| 35 | /* |
| 36 | * Print the contents for visual debugging. |
| 37 | */ |
| 38 | printf("OBJECT_IDENTIFIER_print() => "); |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 39 | OBJECT_IDENTIFIER_print(&asn_DEF_OBJECT_IDENTIFIER, oid, 0, _print, 0); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 40 | printf("\n"); |
| 41 | |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 42 | memset(arcs, 'A', sizeof(arcs)); |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 43 | alen = OBJECT_IDENTIFIER_get_arcs(oid, |
| 44 | arcs, sizeof(arcs[0]), sizeof(arcs)/sizeof(arcs[0])); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 45 | assert(alen > 0); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 46 | |
Lev Walkin | 6c9e071 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 47 | printf("OBJECT_IDENTIFIER_get_arcs() => {"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 48 | /* |
| 49 | * Make sure they are equivalent. |
| 50 | */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 51 | for(i = 0; i < alen; i++) { |
| 52 | printf(" %lu", arcs[i]); |
Lev Walkin | 6c9e071 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 53 | if(alen == ck_len) { |
| 54 | assert(arcs[i] == (unsigned long)ck_buf[i]); |
| 55 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 56 | } |
| 57 | printf(" }\n"); |
Lev Walkin | 6c9e071 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 58 | assert(alen == ck_len); |
| 59 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | static void |
| 63 | check_ROID(uint8_t *buf, size_t len, int *ck_buf, int ck_len) { |
| 64 | RELATIVE_OID_t *oid; |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 65 | asn_dec_rval_t rval; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 66 | unsigned long arcs[10]; |
| 67 | int alen; |
| 68 | int i; |
| 69 | |
| 70 | printf("Checking {"); |
Lev Walkin | 46bf935 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 71 | 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] | 72 | printf("} against {"); |
| 73 | for(i = 0; i < ck_len; i++) { printf("%s%d", i?" ":"", ck_buf[i]); } |
| 74 | printf("}\n"); |
| 75 | |
| 76 | oid = NULL; |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 77 | rval = ber_decode(0, &asn_DEF_RELATIVE_OID, (void *)&oid, buf, len); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 78 | assert(rval.code == RC_OK); |
| 79 | |
Lev Walkin | 46bf935 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 80 | assert(oid->size == (ssize_t)len - 2); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 81 | |
| 82 | /* |
| 83 | * Print the contents for visual debugging. |
| 84 | */ |
| 85 | printf("RELATIVE_OID_print() => "); |
Lev Walkin | 5e03376 | 2004-09-29 13:26:15 +0000 | [diff] [blame] | 86 | RELATIVE_OID_print(&asn_DEF_RELATIVE_OID, oid, 0, _print, 0); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 87 | printf("\n"); |
| 88 | |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 89 | memset(arcs, 'A', sizeof(arcs)); |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 90 | alen = RELATIVE_OID_get_arcs(oid, |
| 91 | arcs, sizeof(arcs[0]), sizeof(arcs)/sizeof(arcs[0])); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 92 | assert(alen > 0); |
| 93 | assert(alen == ck_len); |
| 94 | |
| 95 | /* |
| 96 | * Make sure they are equivalent. |
| 97 | */ |
| 98 | printf("RELATIVE_OID_get_arcs() => {"); |
| 99 | for(i = 0; i < alen; i++) { |
| 100 | printf(" %lu", (unsigned long)arcs[i]); |
Lev Walkin | 46bf935 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 101 | assert(arcs[i] == (unsigned long)ck_buf[i]); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 102 | } |
| 103 | printf(" }\n"); |
| 104 | } |
| 105 | |
| 106 | /* |
| 107 | * Encode the specified array of arcs as RELATIVE-OID, decode it and compare. |
| 108 | */ |
| 109 | static void |
| 110 | check_REGEN(int *arcs, int acount) { |
| 111 | static RELATIVE_OID_t oid; |
| 112 | unsigned long tmp_arcs[10]; |
| 113 | int tmp_alen = 10; |
| 114 | int alen; |
| 115 | int ret; |
| 116 | int i; |
| 117 | |
Lev Walkin | 8db9fab | 2006-07-13 09:22:34 +0000 | [diff] [blame] | 118 | if(0) { |
| 119 | fprintf(stderr, "Encoding (R) {"); |
| 120 | for(i = 0; i < acount; i++) { |
| 121 | fprintf(stderr, " %u", arcs[i]); |
| 122 | } |
| 123 | fprintf(stderr, " }\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 124 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 125 | |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 126 | ret = RELATIVE_OID_set_arcs(&oid, arcs, sizeof(arcs[0]), acount); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 127 | assert(ret == 0); |
| 128 | |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 129 | memset(tmp_arcs, 'A', sizeof(tmp_arcs)); |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 130 | alen = RELATIVE_OID_get_arcs(&oid, tmp_arcs, |
| 131 | sizeof(tmp_arcs[0]), tmp_alen); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 132 | assert(alen >= 0); |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 133 | assert(alen <= tmp_alen); |
| 134 | assert(alen == acount); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 135 | |
Lev Walkin | 8db9fab | 2006-07-13 09:22:34 +0000 | [diff] [blame] | 136 | if(0) { |
| 137 | fprintf(stderr, "Encoded (R) { "); |
| 138 | for(i = 0; i < alen; i++) { |
| 139 | fprintf(stderr, "%lu ", tmp_arcs[i]); fflush(stdout); |
| 140 | assert(arcs[i] == (int)tmp_arcs[i]); |
| 141 | } |
| 142 | fprintf(stderr, "}\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 143 | } |
Lev Walkin | 8db9fab | 2006-07-13 09:22:34 +0000 | [diff] [blame] | 144 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /* |
| 148 | * Encode the specified array of arcs as OBJECT IDENTIFIER, |
| 149 | * decode it and compare. |
| 150 | */ |
| 151 | static void |
| 152 | check_REGEN_OID(int *arcs, int acount) { |
| 153 | static OBJECT_IDENTIFIER_t oid; |
| 154 | unsigned long tmp_arcs[10]; |
| 155 | int tmp_alen = 10; |
| 156 | int alen; |
| 157 | int ret; |
| 158 | int i; |
| 159 | |
Lev Walkin | 8db9fab | 2006-07-13 09:22:34 +0000 | [diff] [blame] | 160 | if(0) { |
| 161 | fprintf(stderr, "Encoding (O) {"); |
| 162 | for(i = 0; i < acount; i++) { |
| 163 | fprintf(stderr, " %u", arcs[i]); |
| 164 | } |
| 165 | fprintf(stderr, " }\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 166 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 167 | |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 168 | ret = OBJECT_IDENTIFIER_set_arcs(&oid, arcs, sizeof(arcs[0]), acount); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 169 | assert(ret == 0); |
| 170 | |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 171 | memset(tmp_arcs, 'A', sizeof(tmp_arcs)); |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 172 | alen = OBJECT_IDENTIFIER_get_arcs(&oid, |
| 173 | tmp_arcs, sizeof(tmp_arcs[0]), tmp_alen); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 174 | assert(alen >= 0); |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 175 | assert(alen <= tmp_alen); |
| 176 | assert(alen == acount); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 177 | |
Lev Walkin | 8db9fab | 2006-07-13 09:22:34 +0000 | [diff] [blame] | 178 | if(0) { |
| 179 | fprintf(stderr, "Encoded (O) { "); |
| 180 | for(i = 0; i < alen; i++) { |
| 181 | fprintf(stderr, "%lu ", tmp_arcs[i]); fflush(stdout); |
| 182 | assert(arcs[i] == (int)tmp_arcs[i]); |
| 183 | } |
| 184 | fprintf(stderr, "}\n"); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 185 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 186 | } |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 187 | static int |
| 188 | check_speed() { |
| 189 | uint8_t buf[] = { 0x80 | 7, 0x80 | 2, 0x80 | 3, 0x80 | 4, 13 }; |
| 190 | int ret = 0; |
| 191 | int cycles = 100000000; |
| 192 | double a, b, c; |
| 193 | struct timeval tv; |
| 194 | unsigned long value; |
| 195 | int i; |
| 196 | |
Lev Walkin | 46bf935 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 197 | 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] | 198 | assert(ret == 0); |
| 199 | assert(value == 0x7040c20d); |
| 200 | |
| 201 | gettimeofday(&tv, 0); |
| 202 | a = tv.tv_sec + tv.tv_usec / 1000000.0; |
| 203 | for(i = 0; i < cycles; i++) { |
| 204 | ret = OBJECT_IDENTIFIER_get_single_arc(buf, sizeof(buf), 0, |
| 205 | &value, sizeof(value)); |
| 206 | } |
| 207 | assert(ret == 0); |
| 208 | assert(value == 0x7040c20d); |
| 209 | gettimeofday(&tv, 0); |
| 210 | b = tv.tv_sec + tv.tv_usec / 1000000.0; |
| 211 | for(i = 0; i < cycles; i++) { |
| 212 | ret = OBJECT_IDENTIFIER_get_single_arc(buf, sizeof(buf), 0, |
| 213 | &value, sizeof(value)); |
| 214 | } |
| 215 | assert(ret == 0); |
| 216 | assert(value == 0x7040c20d); |
| 217 | gettimeofday(&tv, 0); |
| 218 | c = tv.tv_sec + tv.tv_usec / 1000000.0; |
| 219 | |
| 220 | a = b - a; |
| 221 | b = c - b; |
| 222 | printf("Time for single_arc(): %f\n", a); |
| 223 | printf("Time for get_arc_l(): %f\n", b); |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 228 | static void check_parse(const char *oid_txt, int retval) { |
| 229 | int ret; |
| 230 | long l[2]; |
Lev Walkin | cad560a | 2013-03-16 07:00:58 -0700 | [diff] [blame] | 231 | const char *p = oid_txt - 13; |
| 232 | assert(p < oid_txt); |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 233 | |
| 234 | ret = OBJECT_IDENTIFIER_parse_arcs(oid_txt, -1, l, 2, &p); |
| 235 | printf("[%s] => %d == %d\n", oid_txt, ret, retval); |
| 236 | assert(ret == retval); |
| 237 | assert(p >= oid_txt); |
| 238 | } |
| 239 | |
| 240 | static void check_xer(int expect_arcs, char *xer) { |
| 241 | asn_dec_rval_t rc; |
| 242 | RELATIVE_OID_t *st = 0; |
Lev Walkin | b191938 | 2006-07-27 11:46:25 +0000 | [diff] [blame] | 243 | RELATIVE_OID_t **stp = &st; |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 244 | long arcs[10]; |
| 245 | int ret; |
| 246 | int i; |
| 247 | |
| 248 | printf("[%s] => ", xer); fflush(stdout); |
| 249 | rc = asn_DEF_RELATIVE_OID.xer_decoder(0, |
Lev Walkin | b191938 | 2006-07-27 11:46:25 +0000 | [diff] [blame] | 250 | &asn_DEF_RELATIVE_OID, (void **)stp, "t", |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 251 | xer, strlen(xer)); |
| 252 | if(expect_arcs == -1) { |
Lev Walkin | f592711 | 2012-09-03 00:48:45 -0700 | [diff] [blame] | 253 | if(rc.code != RC_OK) { |
| 254 | printf("-1\n"); |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 255 | return; |
Lev Walkin | f592711 | 2012-09-03 00:48:45 -0700 | [diff] [blame] | 256 | } |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 257 | } |
| 258 | assert(rc.code == RC_OK); |
| 259 | |
| 260 | ret = RELATIVE_OID_get_arcs(st, arcs, sizeof(arcs[0]), |
| 261 | sizeof(arcs)/sizeof(arcs[0])); |
| 262 | assert(ret < 10); |
| 263 | if(expect_arcs == -1) { |
| 264 | assert(ret == -1); |
| 265 | return; |
| 266 | } |
| 267 | for(i = 0; i < ret; i++) { |
| 268 | if(i) printf("."); |
| 269 | printf("%ld", arcs[i]); |
Lev Walkin | cad560a | 2013-03-16 07:00:58 -0700 | [diff] [blame] | 270 | if(arcs[i] != i + 1) printf(" != %d\n", i + 1); |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 271 | assert(arcs[i] == i + 1); |
| 272 | } |
| 273 | printf(": %d == %d\n", ret, expect_arcs); |
| 274 | assert(ret == expect_arcs); |
| 275 | } |
| 276 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 277 | #define CHECK_OID(n) check_OID(buf ## n, sizeof(buf ## n), \ |
| 278 | buf ## n ## _check, \ |
| 279 | sizeof(buf ## n ## _check)/sizeof(buf ## n ## _check[0])) |
| 280 | #define CHECK_ROID(n) check_ROID(buf ## n, sizeof(buf ## n), \ |
| 281 | buf ## n ## _check, \ |
| 282 | sizeof(buf ## n ## _check)/sizeof(buf ## n ## _check[0])) |
| 283 | #define CHECK_REGEN(n) check_REGEN(buf ## n ## _check, \ |
| 284 | sizeof(buf ## n ## _check)/sizeof(buf ## n ## _check[0])) |
| 285 | #define CHECK_REGEN_OID(n) check_REGEN_OID(buf ## n ## _check, \ |
| 286 | sizeof(buf ## n ## _check)/sizeof(buf ## n ## _check[0])) |
| 287 | |
| 288 | int |
Lev Walkin | 46bf935 | 2004-06-14 07:40:17 +0000 | [diff] [blame] | 289 | main() { |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 290 | int i; |
| 291 | |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 292 | /* {joint-iso-itu-t 230 3} */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 293 | uint8_t buf1[] = { |
| 294 | 0x06, /* OBJECT IDENTIFIER */ |
| 295 | 0x03, /* Length */ |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 296 | 0x82, 0x36, 0x03 |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 297 | }; |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 298 | int buf1_check[] = { 2, 230, 3 }; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 299 | |
| 300 | /* {8571 3 2} */ |
| 301 | uint8_t buf2[] = { |
| 302 | 0x0D, /* RELATIVE-OID */ |
| 303 | 0x04, /* Length */ |
| 304 | 0xC2, 0x7B, 0x03, 0x02 |
| 305 | }; |
| 306 | int buf2_check[] = { 8571, 3, 2 }; |
| 307 | |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 308 | /* {joint-iso-itu-t 42 } */ |
| 309 | uint8_t buf3[] = { |
| 310 | 0x06, /* OBJECT IDENTIFIER */ |
| 311 | 0x01, /* Length */ |
| 312 | 0x7A |
| 313 | }; |
| 314 | int buf3_check[] = { 2, 42 }; |
| 315 | |
| 316 | /* {joint-iso-itu-t 25957 } */ |
| 317 | uint8_t buf4[] = { |
| 318 | 0x06, /* OBJECT IDENTIFIER */ |
| 319 | 0x03, /* Length */ |
| 320 | 0x81, 0x80 + 0x4B, 0x35 |
| 321 | }; |
| 322 | int buf4_check[] = { 2, 25957 }; |
| 323 | |
| 324 | int buf5_check[] = { 0 }; |
| 325 | int buf6_check[] = { 1 }; |
| 326 | int buf7_check[] = { 80, 40 }; |
| 327 | int buf8_check[] = { 127 }; |
| 328 | int buf9_check[] = { 128 }; |
| 329 | int buf10_check[] = { 65535, 65536 }; |
| 330 | int buf11_check[] = { 100000, 0x20000, 1234, 256, 127, 128 }; |
| 331 | int buf12_check[] = { 0, 0xffffffff, 0xff00ff00, 0 }; |
| 332 | int buf13_check[] = { 0, 1, 2 }; |
| 333 | int buf14_check[] = { 1, 38, 3 }; |
| 334 | int buf15_check[] = { 0, 0, 0xf000 }; |
| 335 | int buf16_check[] = { 0, 0, 0, 1, 0 }; |
| 336 | int buf17_check[] = { 2, 0xffffffAf, 0xff00ff00, 0 }; |
Lev Walkin | 6c9e071 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 337 | int buf18_check[] = { 2, 2, 1, 1 }; |
| 338 | |
| 339 | /* { joint-iso-itu-t 2 1 1 } */ |
| 340 | uint8_t buf19[] = { |
| 341 | 0x06, /* OBJECT IDENTIFIER */ |
| 342 | 0x03, /* Length */ |
| 343 | 0x52, 0x01, 0x01 |
| 344 | }; |
| 345 | int buf19_check[] = { 2, 2, 1, 1 }; |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 346 | |
Lev Walkin | 3251b8e | 2004-08-23 09:23:02 +0000 | [diff] [blame] | 347 | /* { joint-iso-itu-t 2 1 0 1 } */ |
| 348 | uint8_t buf20[] = { |
| 349 | 0x06, /* OBJECT IDENTIFIER */ |
| 350 | 0x04, /* Length */ |
| 351 | 0x52, 0x01, 0x00, 0x01 |
| 352 | }; |
| 353 | int buf20_check[] = { 2, 2, 1, 0, 1 }; |
| 354 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 355 | |
| 356 | CHECK_OID(1); /* buf1, buf1_check */ |
| 357 | CHECK_ROID(2); /* buf2, buf2_check */ |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 358 | CHECK_OID(3); /* buf3, buf3_check */ |
| 359 | CHECK_OID(4); /* buf4, buf4_check */ |
Lev Walkin | 6c9e071 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 360 | CHECK_OID(19); /* buf19, buf19_check */ |
Lev Walkin | 3251b8e | 2004-08-23 09:23:02 +0000 | [diff] [blame] | 361 | CHECK_OID(20); /* buf20, buf20_check */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 362 | |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 363 | CHECK_REGEN(5); /* Regenerate RELATIVE-OID */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 364 | CHECK_REGEN(6); |
| 365 | CHECK_REGEN(7); |
| 366 | CHECK_REGEN(8); |
| 367 | CHECK_REGEN(9); |
| 368 | CHECK_REGEN(10); |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 369 | CHECK_REGEN(11); |
| 370 | CHECK_REGEN(12); |
| 371 | CHECK_REGEN(13); |
| 372 | CHECK_REGEN(14); |
| 373 | CHECK_REGEN(15); |
| 374 | CHECK_REGEN(16); |
| 375 | CHECK_REGEN(17); |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 376 | CHECK_REGEN_OID(1); /* Regenerate OBJECT IDENTIFIER */ |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 377 | CHECK_REGEN_OID(3); /* Regenerate OBJECT IDENTIFIER */ |
| 378 | CHECK_REGEN_OID(4); /* Regenerate OBJECT IDENTIFIER */ |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 379 | CHECK_REGEN_OID(13); |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 380 | CHECK_REGEN_OID(14); |
| 381 | CHECK_REGEN_OID(15); |
| 382 | CHECK_REGEN_OID(16); |
| 383 | CHECK_REGEN_OID(17); |
Lev Walkin | 6c9e071 | 2004-08-22 03:01:37 +0000 | [diff] [blame] | 384 | CHECK_REGEN_OID(18); |
Lev Walkin | 3251b8e | 2004-08-23 09:23:02 +0000 | [diff] [blame] | 385 | CHECK_REGEN_OID(19); |
| 386 | CHECK_REGEN_OID(20); |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 387 | |
Lev Walkin | cad560a | 2013-03-16 07:00:58 -0700 | [diff] [blame] | 388 | check_parse("", 0); |
| 389 | check_parse(" ", 0); |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 390 | check_parse(".", -1); |
| 391 | check_parse(" .", -1); |
Lev Walkin | f592711 | 2012-09-03 00:48:45 -0700 | [diff] [blame] | 392 | check_parse(".1", -1); |
| 393 | check_parse("1.", -1); |
| 394 | check_parse("1. ", -1); |
| 395 | check_parse(".1. ", -1); |
| 396 | check_parse(" .1. ", -1); |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 397 | check_parse(" 1", 1); |
| 398 | check_parse(" 1.2", 2); |
| 399 | check_parse(" 1.", -1); |
| 400 | check_parse(" 1. ", -1); |
| 401 | check_parse("1. ", -1); |
| 402 | check_parse("1.2", 2); |
Lev Walkin | f592711 | 2012-09-03 00:48:45 -0700 | [diff] [blame] | 403 | check_parse("1.2 ", 2); |
| 404 | check_parse("1.2 ", 2); |
| 405 | check_parse(" 1.2 ", 2); |
| 406 | check_parse("1. 2", -1); |
| 407 | check_parse("1 .2", -1); |
Lev Walkin | cad560a | 2013-03-16 07:00:58 -0700 | [diff] [blame] | 408 | check_parse(" 1 .2", -1); |
| 409 | check_parse(" 1 .2 ", -1); |
| 410 | check_parse("1 .2 ", -1); |
| 411 | check_parse("1.+1", -1); |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 412 | check_parse("10.30.234.234", 4); |
| 413 | check_parse("10.30.234.234 ", 4); |
| 414 | check_parse("10.30.234. 234 ", -1); |
| 415 | check_parse("10.30.234.234.", -1); |
| 416 | check_parse("1.2000000000.3", 3); |
| 417 | check_parse("1.2147483647.3", 3); |
| 418 | if(sizeof(long) == 4) { |
| 419 | check_parse("1.2147483648.3", -1); /* overflow on ILP32 */ |
Lev Walkin | a7d1fb3 | 2012-01-23 01:21:55 +0000 | [diff] [blame] | 420 | check_parse("1.2147483649.3", -1); /* overflow on ILP32 */ |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 421 | check_parse("1.3000000000.3", -1); |
| 422 | check_parse("1.4000000000.3", -1); |
| 423 | check_parse("1.5000000000.3", -1); |
| 424 | check_parse("1.6000000000.3", -1); |
| 425 | check_parse("1.9000000000.3", -1); |
Lev Walkin | a7d1fb3 | 2012-01-23 01:21:55 +0000 | [diff] [blame] | 426 | } else if(sizeof(long) == 8) { |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 427 | check_parse("1.2147483648.3", 3); |
Lev Walkin | a7d1fb3 | 2012-01-23 01:21:55 +0000 | [diff] [blame] | 428 | check_parse("1.9223372036854775807.3", 3); |
| 429 | check_parse("1.9223372036854775808.3", -1); |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 430 | } |
| 431 | check_parse("1.900a0000000.3", -1); |
| 432 | check_parse("1.900a.3", -1); |
| 433 | |
Lev Walkin | f592711 | 2012-09-03 00:48:45 -0700 | [diff] [blame] | 434 | check_xer(-1, "<t></t>"); |
Lev Walkin | 9230225 | 2004-10-23 10:16:51 +0000 | [diff] [blame] | 435 | check_xer(2, "<t>1.2</t>"); |
| 436 | check_xer(3, "<t>1.2.3</t>"); |
| 437 | check_xer(3, "<t> 1.2.3 </t>"); |
| 438 | check_xer(-1, "<t>1.2.3 1</t>"); |
| 439 | |
Lev Walkin | 0787ff0 | 2004-06-17 23:43:39 +0000 | [diff] [blame] | 440 | for(i = 0; i < 100000; i++) { |
| 441 | int bufA_check[3] = { 2, i, rand() }; |
| 442 | int bufB_check[2] = { rand(), i * 121 }; |
| 443 | CHECK_REGEN(A); |
| 444 | CHECK_REGEN_OID(A); |
| 445 | CHECK_REGEN(B); |
| 446 | if(i > 100) i++; |
| 447 | if(i > 500) i++; |
| 448 | if(i > 1000) i += 3; |
| 449 | if(i > 5000) i += 151; |
| 450 | } |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 451 | |
Lev Walkin | c4c6196 | 2004-06-14 08:17:27 +0000 | [diff] [blame] | 452 | if(getenv("CHECK_SPEED")) { |
| 453 | /* Useful for developers only */ |
| 454 | check_speed(); |
| 455 | } |
Lev Walkin | 29a044b | 2004-06-14 07:24:36 +0000 | [diff] [blame] | 456 | |
Lev Walkin | f15320b | 2004-06-03 03:38:44 +0000 | [diff] [blame] | 457 | return 0; |
| 458 | } |
Lev Walkin | 725883b | 2006-10-09 12:07:58 +0000 | [diff] [blame] | 459 | |