blob: dac2193cb5e3631247813c573434e4cfa32ab39c [file] [log] [blame]
Lev Walkin4eceeba2007-07-23 06:48:26 +00001#include <stdio.h>
2#include <assert.h>
Lev Walkin29a044b2004-06-14 07:24:36 +00003#include <sys/time.h>
Lev Walkinf15320b2004-06-03 03:38:44 +00004
Lev Walkin4eceeba2007-07-23 06:48:26 +00005#include <OBJECT_IDENTIFIER.h>
6#include <RELATIVE-OID.h>
7
Lev Walkinf15320b2004-06-03 03:38:44 +00008static int
9_print(const void *buffer, size_t size, void *app_key) {
Lev Walkin46bf9352004-06-14 07:40:17 +000010 (void)app_key;
Lev Walkinf15320b2004-06-03 03:38:44 +000011 fwrite(buffer, size, 1, stdout);
12 return 0;
13}
14
15static void
Lev Walkin0995f352017-09-17 23:16:38 -070016check_OID(int lineno, uint8_t *buf, size_t len, int *ck_buf, int ck_len) {
Lev Walkinf15320b2004-06-03 03:38:44 +000017 OBJECT_IDENTIFIER_t *oid;
Lev Walkindc06f6b2004-10-20 15:50:55 +000018 asn_dec_rval_t rval;
Lev Walkinf15320b2004-06-03 03:38:44 +000019 unsigned long arcs[10];
20 int alen;
21 int i;
22
Lev Walkin0995f352017-09-17 23:16:38 -070023 printf("%03d: Checking {", lineno);
Lev Walkin46bf9352004-06-14 07:40:17 +000024 for(i = 0; i < (int)len; i++) { printf("%s%02x", i?" ":"", buf[i]); }
Lev Walkinf15320b2004-06-03 03:38:44 +000025 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 Walkin5e033762004-09-29 13:26:15 +000030 rval = ber_decode(0, &asn_DEF_OBJECT_IDENTIFIER, (void *)&oid, buf, len);
Lev Walkinf15320b2004-06-03 03:38:44 +000031 assert(rval.code == RC_OK);
32
Lev Walkin494fb702017-08-07 20:07:00 -070033 assert((ssize_t)oid->size == (ssize_t)len - 2);
Lev Walkinf15320b2004-06-03 03:38:44 +000034
35 /*
36 * Print the contents for visual debugging.
37 */
38 printf("OBJECT_IDENTIFIER_print() => ");
Lev Walkin5e033762004-09-29 13:26:15 +000039 OBJECT_IDENTIFIER_print(&asn_DEF_OBJECT_IDENTIFIER, oid, 0, _print, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +000040 printf("\n");
41
Lev Walkin0787ff02004-06-17 23:43:39 +000042 memset(arcs, 'A', sizeof(arcs));
Lev Walkin29a044b2004-06-14 07:24:36 +000043 alen = OBJECT_IDENTIFIER_get_arcs(oid,
44 arcs, sizeof(arcs[0]), sizeof(arcs)/sizeof(arcs[0]));
Lev Walkinf15320b2004-06-03 03:38:44 +000045 assert(alen > 0);
Lev Walkinf15320b2004-06-03 03:38:44 +000046
Lev Walkin6c9e0712004-08-22 03:01:37 +000047 printf("OBJECT_IDENTIFIER_get_arcs() => {");
Lev Walkinf15320b2004-06-03 03:38:44 +000048 /*
49 * Make sure they are equivalent.
50 */
Lev Walkinf15320b2004-06-03 03:38:44 +000051 for(i = 0; i < alen; i++) {
52 printf(" %lu", arcs[i]);
Lev Walkin6c9e0712004-08-22 03:01:37 +000053 if(alen == ck_len) {
54 assert(arcs[i] == (unsigned long)ck_buf[i]);
55 }
Lev Walkinf15320b2004-06-03 03:38:44 +000056 }
57 printf(" }\n");
Lev Walkin6c9e0712004-08-22 03:01:37 +000058 assert(alen == ck_len);
59
Lev Walkinf15320b2004-06-03 03:38:44 +000060}
61
62static void
Lev Walkin0995f352017-09-17 23:16:38 -070063check_ROID(int lineno, uint8_t *buf, size_t len, int *ck_buf, int ck_len) {
Lev Walkinf15320b2004-06-03 03:38:44 +000064 RELATIVE_OID_t *oid;
Lev Walkindc06f6b2004-10-20 15:50:55 +000065 asn_dec_rval_t rval;
Lev Walkinf15320b2004-06-03 03:38:44 +000066 unsigned long arcs[10];
67 int alen;
68 int i;
69
Lev Walkin0995f352017-09-17 23:16:38 -070070 printf("%03d: Checking {", lineno);
Lev Walkin46bf9352004-06-14 07:40:17 +000071 for(i = 0; i < (ssize_t)len; i++) { printf("%s%02x", i?" ":"", buf[i]); }
Lev Walkinf15320b2004-06-03 03:38:44 +000072 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 Walkin5e033762004-09-29 13:26:15 +000077 rval = ber_decode(0, &asn_DEF_RELATIVE_OID, (void *)&oid, buf, len);
Lev Walkinf15320b2004-06-03 03:38:44 +000078 assert(rval.code == RC_OK);
79
Lev Walkin494fb702017-08-07 20:07:00 -070080 assert((ssize_t)oid->size == (ssize_t)len - 2);
Lev Walkinf15320b2004-06-03 03:38:44 +000081
82 /*
83 * Print the contents for visual debugging.
84 */
85 printf("RELATIVE_OID_print() => ");
Lev Walkin5e033762004-09-29 13:26:15 +000086 RELATIVE_OID_print(&asn_DEF_RELATIVE_OID, oid, 0, _print, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +000087 printf("\n");
88
Lev Walkin0787ff02004-06-17 23:43:39 +000089 memset(arcs, 'A', sizeof(arcs));
Lev Walkin29a044b2004-06-14 07:24:36 +000090 alen = RELATIVE_OID_get_arcs(oid,
91 arcs, sizeof(arcs[0]), sizeof(arcs)/sizeof(arcs[0]));
Lev Walkinf15320b2004-06-03 03:38:44 +000092 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 Walkin46bf9352004-06-14 07:40:17 +0000101 assert(arcs[i] == (unsigned long)ck_buf[i]);
Lev Walkinf15320b2004-06-03 03:38:44 +0000102 }
103 printf(" }\n");
104}
105
106/*
107 * Encode the specified array of arcs as RELATIVE-OID, decode it and compare.
108 */
109static void
Lev Walkin0995f352017-09-17 23:16:38 -0700110check_REGEN(int lineno, int *arcs, int acount) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000111 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 Walkin8db9fab2006-07-13 09:22:34 +0000118 if(0) {
Lev Walkin0995f352017-09-17 23:16:38 -0700119 fprintf(stderr, "%03d: Encoding (R) {", lineno);
Lev Walkin8db9fab2006-07-13 09:22:34 +0000120 for(i = 0; i < acount; i++) {
121 fprintf(stderr, " %u", arcs[i]);
122 }
123 fprintf(stderr, " }\n");
Lev Walkinf15320b2004-06-03 03:38:44 +0000124 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000125
Lev Walkin0787ff02004-06-17 23:43:39 +0000126 ret = RELATIVE_OID_set_arcs(&oid, arcs, sizeof(arcs[0]), acount);
Lev Walkinf15320b2004-06-03 03:38:44 +0000127 assert(ret == 0);
128
Lev Walkin0787ff02004-06-17 23:43:39 +0000129 memset(tmp_arcs, 'A', sizeof(tmp_arcs));
Lev Walkin29a044b2004-06-14 07:24:36 +0000130 alen = RELATIVE_OID_get_arcs(&oid, tmp_arcs,
131 sizeof(tmp_arcs[0]), tmp_alen);
Lev Walkinf15320b2004-06-03 03:38:44 +0000132 assert(alen >= 0);
Lev Walkin0787ff02004-06-17 23:43:39 +0000133 assert(alen <= tmp_alen);
134 assert(alen == acount);
Lev Walkinf15320b2004-06-03 03:38:44 +0000135
Lev Walkin8db9fab2006-07-13 09:22:34 +0000136 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 Walkinf15320b2004-06-03 03:38:44 +0000143 }
Lev Walkin8db9fab2006-07-13 09:22:34 +0000144
Lev Walkinf15320b2004-06-03 03:38:44 +0000145}
146
147/*
148 * Encode the specified array of arcs as OBJECT IDENTIFIER,
149 * decode it and compare.
150 */
151static void
Lev Walkin0995f352017-09-17 23:16:38 -0700152check_REGEN_OID(int lineno, int *arcs, int acount) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000153 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 Walkin8db9fab2006-07-13 09:22:34 +0000160 if(0) {
Lev Walkin0995f352017-09-17 23:16:38 -0700161 fprintf(stderr, "%03d: Encoding (O) {", lineno);
Lev Walkin8db9fab2006-07-13 09:22:34 +0000162 for(i = 0; i < acount; i++) {
163 fprintf(stderr, " %u", arcs[i]);
164 }
165 fprintf(stderr, " }\n");
Lev Walkinf15320b2004-06-03 03:38:44 +0000166 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000167
Lev Walkin0787ff02004-06-17 23:43:39 +0000168 ret = OBJECT_IDENTIFIER_set_arcs(&oid, arcs, sizeof(arcs[0]), acount);
Lev Walkinf15320b2004-06-03 03:38:44 +0000169 assert(ret == 0);
170
Lev Walkin0787ff02004-06-17 23:43:39 +0000171 memset(tmp_arcs, 'A', sizeof(tmp_arcs));
Lev Walkin29a044b2004-06-14 07:24:36 +0000172 alen = OBJECT_IDENTIFIER_get_arcs(&oid,
173 tmp_arcs, sizeof(tmp_arcs[0]), tmp_alen);
Lev Walkinf15320b2004-06-03 03:38:44 +0000174 assert(alen >= 0);
Lev Walkin0787ff02004-06-17 23:43:39 +0000175 assert(alen <= tmp_alen);
176 assert(alen == acount);
Lev Walkinf15320b2004-06-03 03:38:44 +0000177
Lev Walkin8db9fab2006-07-13 09:22:34 +0000178 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 Walkinf15320b2004-06-03 03:38:44 +0000185 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000186}
Lev Walkin29a044b2004-06-14 07:24:36 +0000187static int
188check_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 Walkin46bf9352004-06-14 07:40:17 +0000197 ret = OBJECT_IDENTIFIER_get_single_arc(buf, sizeof(buf), 0, &value, sizeof(value));
Lev Walkin29a044b2004-06-14 07:24:36 +0000198 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 Walkin92302252004-10-23 10:16:51 +0000228static void check_parse(const char *oid_txt, int retval) {
229 int ret;
230 long l[2];
Lev Walkincad560a2013-03-16 07:00:58 -0700231 const char *p = oid_txt - 13;
232 assert(p < oid_txt);
Lev Walkin92302252004-10-23 10:16:51 +0000233
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
240static void check_xer(int expect_arcs, char *xer) {
241 asn_dec_rval_t rc;
242 RELATIVE_OID_t *st = 0;
Lev Walkinb1919382006-07-27 11:46:25 +0000243 RELATIVE_OID_t **stp = &st;
Lev Walkin92302252004-10-23 10:16:51 +0000244 long arcs[10];
245 int ret;
246 int i;
247
248 printf("[%s] => ", xer); fflush(stdout);
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +0800249 rc = asn_DEF_RELATIVE_OID.op->xer_decoder(0,
Lev Walkinb1919382006-07-27 11:46:25 +0000250 &asn_DEF_RELATIVE_OID, (void **)stp, "t",
Lev Walkin92302252004-10-23 10:16:51 +0000251 xer, strlen(xer));
252 if(expect_arcs == -1) {
Lev Walkinf5927112012-09-03 00:48:45 -0700253 if(rc.code != RC_OK) {
254 printf("-1\n");
Lev Walkin92302252004-10-23 10:16:51 +0000255 return;
Lev Walkinf5927112012-09-03 00:48:45 -0700256 }
Lev Walkin92302252004-10-23 10:16:51 +0000257 }
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 Walkincad560a2013-03-16 07:00:58 -0700270 if(arcs[i] != i + 1) printf(" != %d\n", i + 1);
Lev Walkin92302252004-10-23 10:16:51 +0000271 assert(arcs[i] == i + 1);
272 }
273 printf(": %d == %d\n", ret, expect_arcs);
274 assert(ret == expect_arcs);
275}
276
Lev Walkin0995f352017-09-17 23:16:38 -0700277#define CHECK_OID(n) \
278 check_OID(__LINE__, buf##n, sizeof(buf##n), buf##n##_check, \
279 sizeof(buf##n##_check) / sizeof(buf##n##_check[0]))
280#define CHECK_ROID(n) \
281 check_ROID(__LINE__, buf##n, sizeof(buf##n), buf##n##_check, \
282 sizeof(buf##n##_check) / sizeof(buf##n##_check[0]))
283#define CHECK_REGEN(n) \
284 check_REGEN(__LINE__, buf##n##_check, \
285 sizeof(buf##n##_check) / sizeof(buf##n##_check[0]))
286#define CHECK_REGEN_OID(n) \
287 check_REGEN_OID(__LINE__, buf##n##_check, \
288 sizeof(buf##n##_check) / sizeof(buf##n##_check[0]))
Lev Walkinf15320b2004-06-03 03:38:44 +0000289
290int
Lev Walkin46bf9352004-06-14 07:40:17 +0000291main() {
Lev Walkin0787ff02004-06-17 23:43:39 +0000292 int i;
293
Lev Walkin29a044b2004-06-14 07:24:36 +0000294 /* {joint-iso-itu-t 230 3} */
Lev Walkinf15320b2004-06-03 03:38:44 +0000295 uint8_t buf1[] = {
296 0x06, /* OBJECT IDENTIFIER */
297 0x03, /* Length */
Lev Walkin29a044b2004-06-14 07:24:36 +0000298 0x82, 0x36, 0x03
Lev Walkinf15320b2004-06-03 03:38:44 +0000299 };
Lev Walkin29a044b2004-06-14 07:24:36 +0000300 int buf1_check[] = { 2, 230, 3 };
Lev Walkinf15320b2004-06-03 03:38:44 +0000301
302 /* {8571 3 2} */
303 uint8_t buf2[] = {
304 0x0D, /* RELATIVE-OID */
305 0x04, /* Length */
306 0xC2, 0x7B, 0x03, 0x02
307 };
308 int buf2_check[] = { 8571, 3, 2 };
309
Lev Walkin0787ff02004-06-17 23:43:39 +0000310 /* {joint-iso-itu-t 42 } */
311 uint8_t buf3[] = {
312 0x06, /* OBJECT IDENTIFIER */
313 0x01, /* Length */
314 0x7A
315 };
316 int buf3_check[] = { 2, 42 };
317
318 /* {joint-iso-itu-t 25957 } */
319 uint8_t buf4[] = {
320 0x06, /* OBJECT IDENTIFIER */
321 0x03, /* Length */
322 0x81, 0x80 + 0x4B, 0x35
323 };
324 int buf4_check[] = { 2, 25957 };
325
326 int buf5_check[] = { 0 };
327 int buf6_check[] = { 1 };
328 int buf7_check[] = { 80, 40 };
329 int buf8_check[] = { 127 };
330 int buf9_check[] = { 128 };
331 int buf10_check[] = { 65535, 65536 };
332 int buf11_check[] = { 100000, 0x20000, 1234, 256, 127, 128 };
333 int buf12_check[] = { 0, 0xffffffff, 0xff00ff00, 0 };
334 int buf13_check[] = { 0, 1, 2 };
335 int buf14_check[] = { 1, 38, 3 };
336 int buf15_check[] = { 0, 0, 0xf000 };
337 int buf16_check[] = { 0, 0, 0, 1, 0 };
338 int buf17_check[] = { 2, 0xffffffAf, 0xff00ff00, 0 };
Lev Walkin6c9e0712004-08-22 03:01:37 +0000339 int buf18_check[] = { 2, 2, 1, 1 };
340
341 /* { joint-iso-itu-t 2 1 1 } */
342 uint8_t buf19[] = {
343 0x06, /* OBJECT IDENTIFIER */
344 0x03, /* Length */
345 0x52, 0x01, 0x01
346 };
347 int buf19_check[] = { 2, 2, 1, 1 };
Lev Walkinf15320b2004-06-03 03:38:44 +0000348
Lev Walkin3251b8e2004-08-23 09:23:02 +0000349 /* { joint-iso-itu-t 2 1 0 1 } */
350 uint8_t buf20[] = {
351 0x06, /* OBJECT IDENTIFIER */
352 0x04, /* Length */
353 0x52, 0x01, 0x00, 0x01
354 };
355 int buf20_check[] = { 2, 2, 1, 0, 1 };
356
Lev Walkinf15320b2004-06-03 03:38:44 +0000357
358 CHECK_OID(1); /* buf1, buf1_check */
359 CHECK_ROID(2); /* buf2, buf2_check */
Lev Walkin0787ff02004-06-17 23:43:39 +0000360 CHECK_OID(3); /* buf3, buf3_check */
361 CHECK_OID(4); /* buf4, buf4_check */
Lev Walkin6c9e0712004-08-22 03:01:37 +0000362 CHECK_OID(19); /* buf19, buf19_check */
Lev Walkin3251b8e2004-08-23 09:23:02 +0000363 CHECK_OID(20); /* buf20, buf20_check */
Lev Walkinf15320b2004-06-03 03:38:44 +0000364
Lev Walkin0787ff02004-06-17 23:43:39 +0000365 CHECK_REGEN(5); /* Regenerate RELATIVE-OID */
Lev Walkinf15320b2004-06-03 03:38:44 +0000366 CHECK_REGEN(6);
367 CHECK_REGEN(7);
368 CHECK_REGEN(8);
369 CHECK_REGEN(9);
370 CHECK_REGEN(10);
Lev Walkin0787ff02004-06-17 23:43:39 +0000371 CHECK_REGEN(11);
372 CHECK_REGEN(12);
373 CHECK_REGEN(13);
374 CHECK_REGEN(14);
375 CHECK_REGEN(15);
376 CHECK_REGEN(16);
377 CHECK_REGEN(17);
Lev Walkinf15320b2004-06-03 03:38:44 +0000378 CHECK_REGEN_OID(1); /* Regenerate OBJECT IDENTIFIER */
Lev Walkin0787ff02004-06-17 23:43:39 +0000379 CHECK_REGEN_OID(3); /* Regenerate OBJECT IDENTIFIER */
380 CHECK_REGEN_OID(4); /* Regenerate OBJECT IDENTIFIER */
Lev Walkinf15320b2004-06-03 03:38:44 +0000381 CHECK_REGEN_OID(13);
Lev Walkin0787ff02004-06-17 23:43:39 +0000382 CHECK_REGEN_OID(14);
383 CHECK_REGEN_OID(15);
384 CHECK_REGEN_OID(16);
385 CHECK_REGEN_OID(17);
Lev Walkin6c9e0712004-08-22 03:01:37 +0000386 CHECK_REGEN_OID(18);
Lev Walkin3251b8e2004-08-23 09:23:02 +0000387 CHECK_REGEN_OID(19);
388 CHECK_REGEN_OID(20);
Lev Walkin0787ff02004-06-17 23:43:39 +0000389
Lev Walkincad560a2013-03-16 07:00:58 -0700390 check_parse("", 0);
391 check_parse(" ", 0);
Lev Walkin92302252004-10-23 10:16:51 +0000392 check_parse(".", -1);
393 check_parse(" .", -1);
Lev Walkinf5927112012-09-03 00:48:45 -0700394 check_parse(".1", -1);
395 check_parse("1.", -1);
396 check_parse("1. ", -1);
397 check_parse(".1. ", -1);
398 check_parse(" .1. ", -1);
Lev Walkin92302252004-10-23 10:16:51 +0000399 check_parse(" 1", 1);
400 check_parse(" 1.2", 2);
401 check_parse(" 1.", -1);
402 check_parse(" 1. ", -1);
403 check_parse("1. ", -1);
404 check_parse("1.2", 2);
Lev Walkinf5927112012-09-03 00:48:45 -0700405 check_parse("1.2 ", 2);
406 check_parse("1.2 ", 2);
407 check_parse(" 1.2 ", 2);
408 check_parse("1. 2", -1);
409 check_parse("1 .2", -1);
Lev Walkincad560a2013-03-16 07:00:58 -0700410 check_parse(" 1 .2", -1);
411 check_parse(" 1 .2 ", -1);
412 check_parse("1 .2 ", -1);
413 check_parse("1.+1", -1);
Lev Walkin92302252004-10-23 10:16:51 +0000414 check_parse("10.30.234.234", 4);
415 check_parse("10.30.234.234 ", 4);
416 check_parse("10.30.234. 234 ", -1);
417 check_parse("10.30.234.234.", -1);
418 check_parse("1.2000000000.3", 3);
419 check_parse("1.2147483647.3", 3);
420 if(sizeof(long) == 4) {
421 check_parse("1.2147483648.3", -1); /* overflow on ILP32 */
Lev Walkina7d1fb32012-01-23 01:21:55 +0000422 check_parse("1.2147483649.3", -1); /* overflow on ILP32 */
Lev Walkin92302252004-10-23 10:16:51 +0000423 check_parse("1.3000000000.3", -1);
424 check_parse("1.4000000000.3", -1);
425 check_parse("1.5000000000.3", -1);
426 check_parse("1.6000000000.3", -1);
427 check_parse("1.9000000000.3", -1);
Lev Walkina7d1fb32012-01-23 01:21:55 +0000428 } else if(sizeof(long) == 8) {
Lev Walkin92302252004-10-23 10:16:51 +0000429 check_parse("1.2147483648.3", 3);
Lev Walkina7d1fb32012-01-23 01:21:55 +0000430 check_parse("1.9223372036854775807.3", 3);
431 check_parse("1.9223372036854775808.3", -1);
Lev Walkin92302252004-10-23 10:16:51 +0000432 }
433 check_parse("1.900a0000000.3", -1);
434 check_parse("1.900a.3", -1);
435
Lev Walkinf5927112012-09-03 00:48:45 -0700436 check_xer(-1, "<t></t>");
Lev Walkin92302252004-10-23 10:16:51 +0000437 check_xer(2, "<t>1.2</t>");
438 check_xer(3, "<t>1.2.3</t>");
439 check_xer(3, "<t> 1.2.3 </t>");
440 check_xer(-1, "<t>1.2.3 1</t>");
441
Lev Walkin0787ff02004-06-17 23:43:39 +0000442 for(i = 0; i < 100000; i++) {
443 int bufA_check[3] = { 2, i, rand() };
444 int bufB_check[2] = { rand(), i * 121 };
445 CHECK_REGEN(A);
446 CHECK_REGEN_OID(A);
447 CHECK_REGEN(B);
448 if(i > 100) i++;
449 if(i > 500) i++;
450 if(i > 1000) i += 3;
451 if(i > 5000) i += 151;
452 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000453
Lev Walkinc4c61962004-06-14 08:17:27 +0000454 if(getenv("CHECK_SPEED")) {
455 /* Useful for developers only */
456 check_speed();
457 }
Lev Walkin29a044b2004-06-14 07:24:36 +0000458
Lev Walkinf15320b2004-06-03 03:38:44 +0000459 return 0;
460}
Lev Walkin725883b2006-10-09 12:07:58 +0000461