blob: d5873c3ac7503070988f6803f410f087de216e4e [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 Walkin229ad002017-09-18 20:13:49 -070060 ASN_STRUCT_FREE(asn_DEF_OBJECT_IDENTIFIER, oid);
Lev Walkinf15320b2004-06-03 03:38:44 +000061}
62
63static void
Lev Walkin0995f352017-09-17 23:16:38 -070064check_ROID(int lineno, uint8_t *buf, size_t len, int *ck_buf, int ck_len) {
Lev Walkinf15320b2004-06-03 03:38:44 +000065 RELATIVE_OID_t *oid;
Lev Walkindc06f6b2004-10-20 15:50:55 +000066 asn_dec_rval_t rval;
Lev Walkinf15320b2004-06-03 03:38:44 +000067 unsigned long arcs[10];
68 int alen;
69 int i;
70
Lev Walkin0995f352017-09-17 23:16:38 -070071 printf("%03d: Checking {", lineno);
Lev Walkin46bf9352004-06-14 07:40:17 +000072 for(i = 0; i < (ssize_t)len; i++) { printf("%s%02x", i?" ":"", buf[i]); }
Lev Walkinf15320b2004-06-03 03:38:44 +000073 printf("} against {");
74 for(i = 0; i < ck_len; i++) { printf("%s%d", i?" ":"", ck_buf[i]); }
75 printf("}\n");
76
77 oid = NULL;
Lev Walkin5e033762004-09-29 13:26:15 +000078 rval = ber_decode(0, &asn_DEF_RELATIVE_OID, (void *)&oid, buf, len);
Lev Walkinf15320b2004-06-03 03:38:44 +000079 assert(rval.code == RC_OK);
80
Lev Walkin494fb702017-08-07 20:07:00 -070081 assert((ssize_t)oid->size == (ssize_t)len - 2);
Lev Walkinf15320b2004-06-03 03:38:44 +000082
83 /*
84 * Print the contents for visual debugging.
85 */
86 printf("RELATIVE_OID_print() => ");
Lev Walkin5e033762004-09-29 13:26:15 +000087 RELATIVE_OID_print(&asn_DEF_RELATIVE_OID, oid, 0, _print, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +000088 printf("\n");
89
Lev Walkin0787ff02004-06-17 23:43:39 +000090 memset(arcs, 'A', sizeof(arcs));
Lev Walkin29a044b2004-06-14 07:24:36 +000091 alen = RELATIVE_OID_get_arcs(oid,
92 arcs, sizeof(arcs[0]), sizeof(arcs)/sizeof(arcs[0]));
Lev Walkinf15320b2004-06-03 03:38:44 +000093 assert(alen > 0);
94 assert(alen == ck_len);
95
96 /*
97 * Make sure they are equivalent.
98 */
99 printf("RELATIVE_OID_get_arcs() => {");
100 for(i = 0; i < alen; i++) {
101 printf(" %lu", (unsigned long)arcs[i]);
Lev Walkin46bf9352004-06-14 07:40:17 +0000102 assert(arcs[i] == (unsigned long)ck_buf[i]);
Lev Walkinf15320b2004-06-03 03:38:44 +0000103 }
104 printf(" }\n");
Lev Walkin229ad002017-09-18 20:13:49 -0700105 ASN_STRUCT_FREE(asn_DEF_RELATIVE_OID, oid);
Lev Walkinf15320b2004-06-03 03:38:44 +0000106}
107
108/*
109 * Encode the specified array of arcs as RELATIVE-OID, decode it and compare.
110 */
111static void
Lev Walkin0995f352017-09-17 23:16:38 -0700112check_REGEN(int lineno, int *arcs, int acount) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000113 static RELATIVE_OID_t oid;
114 unsigned long tmp_arcs[10];
115 int tmp_alen = 10;
116 int alen;
117 int ret;
118 int i;
119
Lev Walkin8db9fab2006-07-13 09:22:34 +0000120 if(0) {
Lev Walkin0995f352017-09-17 23:16:38 -0700121 fprintf(stderr, "%03d: Encoding (R) {", lineno);
Lev Walkin8db9fab2006-07-13 09:22:34 +0000122 for(i = 0; i < acount; i++) {
123 fprintf(stderr, " %u", arcs[i]);
124 }
125 fprintf(stderr, " }\n");
Lev Walkinf15320b2004-06-03 03:38:44 +0000126 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000127
Lev Walkin0787ff02004-06-17 23:43:39 +0000128 ret = RELATIVE_OID_set_arcs(&oid, arcs, sizeof(arcs[0]), acount);
Lev Walkinf15320b2004-06-03 03:38:44 +0000129 assert(ret == 0);
130
Lev Walkin0787ff02004-06-17 23:43:39 +0000131 memset(tmp_arcs, 'A', sizeof(tmp_arcs));
Lev Walkin29a044b2004-06-14 07:24:36 +0000132 alen = RELATIVE_OID_get_arcs(&oid, tmp_arcs,
133 sizeof(tmp_arcs[0]), tmp_alen);
Lev Walkinf15320b2004-06-03 03:38:44 +0000134 assert(alen >= 0);
Lev Walkin0787ff02004-06-17 23:43:39 +0000135 assert(alen <= tmp_alen);
136 assert(alen == acount);
Lev Walkinf15320b2004-06-03 03:38:44 +0000137
Lev Walkin8db9fab2006-07-13 09:22:34 +0000138 if(0) {
139 fprintf(stderr, "Encoded (R) { ");
140 for(i = 0; i < alen; i++) {
141 fprintf(stderr, "%lu ", tmp_arcs[i]); fflush(stdout);
142 assert(arcs[i] == (int)tmp_arcs[i]);
143 }
144 fprintf(stderr, "}\n");
Lev Walkinf15320b2004-06-03 03:38:44 +0000145 }
Lev Walkin8db9fab2006-07-13 09:22:34 +0000146
Lev Walkin229ad002017-09-18 20:13:49 -0700147 ASN_STRUCT_RESET(asn_DEF_RELATIVE_OID, &oid);
Lev Walkinf15320b2004-06-03 03:38:44 +0000148}
149
150/*
151 * Encode the specified array of arcs as OBJECT IDENTIFIER,
152 * decode it and compare.
153 */
154static void
Lev Walkin0995f352017-09-17 23:16:38 -0700155check_REGEN_OID(int lineno, int *arcs, int acount) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000156 static OBJECT_IDENTIFIER_t oid;
157 unsigned long tmp_arcs[10];
158 int tmp_alen = 10;
159 int alen;
160 int ret;
161 int i;
162
Lev Walkin8db9fab2006-07-13 09:22:34 +0000163 if(0) {
Lev Walkin0995f352017-09-17 23:16:38 -0700164 fprintf(stderr, "%03d: Encoding (O) {", lineno);
Lev Walkin8db9fab2006-07-13 09:22:34 +0000165 for(i = 0; i < acount; i++) {
166 fprintf(stderr, " %u", arcs[i]);
167 }
168 fprintf(stderr, " }\n");
Lev Walkinf15320b2004-06-03 03:38:44 +0000169 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000170
Lev Walkin0787ff02004-06-17 23:43:39 +0000171 ret = OBJECT_IDENTIFIER_set_arcs(&oid, arcs, sizeof(arcs[0]), acount);
Lev Walkinf15320b2004-06-03 03:38:44 +0000172 assert(ret == 0);
173
Lev Walkin0787ff02004-06-17 23:43:39 +0000174 memset(tmp_arcs, 'A', sizeof(tmp_arcs));
Lev Walkin29a044b2004-06-14 07:24:36 +0000175 alen = OBJECT_IDENTIFIER_get_arcs(&oid,
176 tmp_arcs, sizeof(tmp_arcs[0]), tmp_alen);
Lev Walkinf15320b2004-06-03 03:38:44 +0000177 assert(alen >= 0);
Lev Walkin0787ff02004-06-17 23:43:39 +0000178 assert(alen <= tmp_alen);
179 assert(alen == acount);
Lev Walkinf15320b2004-06-03 03:38:44 +0000180
Lev Walkin8db9fab2006-07-13 09:22:34 +0000181 if(0) {
182 fprintf(stderr, "Encoded (O) { ");
183 for(i = 0; i < alen; i++) {
184 fprintf(stderr, "%lu ", tmp_arcs[i]); fflush(stdout);
185 assert(arcs[i] == (int)tmp_arcs[i]);
186 }
187 fprintf(stderr, "}\n");
Lev Walkinf15320b2004-06-03 03:38:44 +0000188 }
Lev Walkin229ad002017-09-18 20:13:49 -0700189
190 ASN_STRUCT_RESET(asn_DEF_RELATIVE_OID, &oid);
Lev Walkinf15320b2004-06-03 03:38:44 +0000191}
Lev Walkin229ad002017-09-18 20:13:49 -0700192
Lev Walkin29a044b2004-06-14 07:24:36 +0000193static int
194check_speed() {
195 uint8_t buf[] = { 0x80 | 7, 0x80 | 2, 0x80 | 3, 0x80 | 4, 13 };
196 int ret = 0;
197 int cycles = 100000000;
198 double a, b, c;
199 struct timeval tv;
200 unsigned long value;
201 int i;
202
Lev Walkin46bf9352004-06-14 07:40:17 +0000203 ret = OBJECT_IDENTIFIER_get_single_arc(buf, sizeof(buf), 0, &value, sizeof(value));
Lev Walkin29a044b2004-06-14 07:24:36 +0000204 assert(ret == 0);
205 assert(value == 0x7040c20d);
206
207 gettimeofday(&tv, 0);
208 a = tv.tv_sec + tv.tv_usec / 1000000.0;
209 for(i = 0; i < cycles; i++) {
210 ret = OBJECT_IDENTIFIER_get_single_arc(buf, sizeof(buf), 0,
211 &value, sizeof(value));
212 }
213 assert(ret == 0);
214 assert(value == 0x7040c20d);
215 gettimeofday(&tv, 0);
216 b = tv.tv_sec + tv.tv_usec / 1000000.0;
217 for(i = 0; i < cycles; i++) {
218 ret = OBJECT_IDENTIFIER_get_single_arc(buf, sizeof(buf), 0,
219 &value, sizeof(value));
220 }
221 assert(ret == 0);
222 assert(value == 0x7040c20d);
223 gettimeofday(&tv, 0);
224 c = tv.tv_sec + tv.tv_usec / 1000000.0;
225
226 a = b - a;
227 b = c - b;
228 printf("Time for single_arc(): %f\n", a);
229 printf("Time for get_arc_l(): %f\n", b);
230
231 return 0;
232}
233
Lev Walkin92302252004-10-23 10:16:51 +0000234static void check_parse(const char *oid_txt, int retval) {
235 int ret;
236 long l[2];
Lev Walkincad560a2013-03-16 07:00:58 -0700237 const char *p = oid_txt - 13;
238 assert(p < oid_txt);
Lev Walkin92302252004-10-23 10:16:51 +0000239
240 ret = OBJECT_IDENTIFIER_parse_arcs(oid_txt, -1, l, 2, &p);
241 printf("[%s] => %d == %d\n", oid_txt, ret, retval);
242 assert(ret == retval);
243 assert(p >= oid_txt);
244}
245
246static void check_xer(int expect_arcs, char *xer) {
247 asn_dec_rval_t rc;
248 RELATIVE_OID_t *st = 0;
249 long arcs[10];
250 int ret;
251 int i;
252
253 printf("[%s] => ", xer); fflush(stdout);
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +0800254 rc = asn_DEF_RELATIVE_OID.op->xer_decoder(0,
Lev Walkin229ad002017-09-18 20:13:49 -0700255 &asn_DEF_RELATIVE_OID, (void **)&st, "t",
Lev Walkin92302252004-10-23 10:16:51 +0000256 xer, strlen(xer));
257 if(expect_arcs == -1) {
Lev Walkinf5927112012-09-03 00:48:45 -0700258 if(rc.code != RC_OK) {
259 printf("-1\n");
Lev Walkin229ad002017-09-18 20:13:49 -0700260 ASN_STRUCT_FREE(asn_DEF_RELATIVE_OID, st);
Lev Walkin92302252004-10-23 10:16:51 +0000261 return;
Lev Walkinf5927112012-09-03 00:48:45 -0700262 }
Lev Walkin92302252004-10-23 10:16:51 +0000263 }
264 assert(rc.code == RC_OK);
265
266 ret = RELATIVE_OID_get_arcs(st, arcs, sizeof(arcs[0]),
267 sizeof(arcs)/sizeof(arcs[0]));
268 assert(ret < 10);
269 if(expect_arcs == -1) {
270 assert(ret == -1);
Lev Walkin229ad002017-09-18 20:13:49 -0700271 ASN_STRUCT_FREE(asn_DEF_RELATIVE_OID, st);
Lev Walkin92302252004-10-23 10:16:51 +0000272 return;
273 }
274 for(i = 0; i < ret; i++) {
275 if(i) printf(".");
276 printf("%ld", arcs[i]);
Lev Walkincad560a2013-03-16 07:00:58 -0700277 if(arcs[i] != i + 1) printf(" != %d\n", i + 1);
Lev Walkin92302252004-10-23 10:16:51 +0000278 assert(arcs[i] == i + 1);
279 }
280 printf(": %d == %d\n", ret, expect_arcs);
281 assert(ret == expect_arcs);
Lev Walkin229ad002017-09-18 20:13:49 -0700282 ASN_STRUCT_FREE(asn_DEF_RELATIVE_OID, st);
Lev Walkin92302252004-10-23 10:16:51 +0000283}
284
Lev Walkin0995f352017-09-17 23:16:38 -0700285#define CHECK_OID(n) \
286 check_OID(__LINE__, buf##n, sizeof(buf##n), buf##n##_check, \
287 sizeof(buf##n##_check) / sizeof(buf##n##_check[0]))
288#define CHECK_ROID(n) \
289 check_ROID(__LINE__, buf##n, sizeof(buf##n), buf##n##_check, \
290 sizeof(buf##n##_check) / sizeof(buf##n##_check[0]))
291#define CHECK_REGEN(n) \
292 check_REGEN(__LINE__, buf##n##_check, \
293 sizeof(buf##n##_check) / sizeof(buf##n##_check[0]))
294#define CHECK_REGEN_OID(n) \
295 check_REGEN_OID(__LINE__, buf##n##_check, \
296 sizeof(buf##n##_check) / sizeof(buf##n##_check[0]))
Lev Walkinf15320b2004-06-03 03:38:44 +0000297
298int
Lev Walkin46bf9352004-06-14 07:40:17 +0000299main() {
Lev Walkin0787ff02004-06-17 23:43:39 +0000300 int i;
301
Lev Walkin29a044b2004-06-14 07:24:36 +0000302 /* {joint-iso-itu-t 230 3} */
Lev Walkinf15320b2004-06-03 03:38:44 +0000303 uint8_t buf1[] = {
304 0x06, /* OBJECT IDENTIFIER */
305 0x03, /* Length */
Lev Walkin29a044b2004-06-14 07:24:36 +0000306 0x82, 0x36, 0x03
Lev Walkinf15320b2004-06-03 03:38:44 +0000307 };
Lev Walkin29a044b2004-06-14 07:24:36 +0000308 int buf1_check[] = { 2, 230, 3 };
Lev Walkinf15320b2004-06-03 03:38:44 +0000309
310 /* {8571 3 2} */
311 uint8_t buf2[] = {
312 0x0D, /* RELATIVE-OID */
313 0x04, /* Length */
314 0xC2, 0x7B, 0x03, 0x02
315 };
316 int buf2_check[] = { 8571, 3, 2 };
317
Lev Walkin0787ff02004-06-17 23:43:39 +0000318 /* {joint-iso-itu-t 42 } */
319 uint8_t buf3[] = {
320 0x06, /* OBJECT IDENTIFIER */
321 0x01, /* Length */
322 0x7A
323 };
324 int buf3_check[] = { 2, 42 };
325
326 /* {joint-iso-itu-t 25957 } */
327 uint8_t buf4[] = {
328 0x06, /* OBJECT IDENTIFIER */
329 0x03, /* Length */
330 0x81, 0x80 + 0x4B, 0x35
331 };
332 int buf4_check[] = { 2, 25957 };
333
334 int buf5_check[] = { 0 };
335 int buf6_check[] = { 1 };
336 int buf7_check[] = { 80, 40 };
337 int buf8_check[] = { 127 };
338 int buf9_check[] = { 128 };
339 int buf10_check[] = { 65535, 65536 };
340 int buf11_check[] = { 100000, 0x20000, 1234, 256, 127, 128 };
341 int buf12_check[] = { 0, 0xffffffff, 0xff00ff00, 0 };
342 int buf13_check[] = { 0, 1, 2 };
343 int buf14_check[] = { 1, 38, 3 };
344 int buf15_check[] = { 0, 0, 0xf000 };
345 int buf16_check[] = { 0, 0, 0, 1, 0 };
346 int buf17_check[] = { 2, 0xffffffAf, 0xff00ff00, 0 };
Lev Walkin6c9e0712004-08-22 03:01:37 +0000347 int buf18_check[] = { 2, 2, 1, 1 };
348
349 /* { joint-iso-itu-t 2 1 1 } */
350 uint8_t buf19[] = {
351 0x06, /* OBJECT IDENTIFIER */
352 0x03, /* Length */
353 0x52, 0x01, 0x01
354 };
355 int buf19_check[] = { 2, 2, 1, 1 };
Lev Walkinf15320b2004-06-03 03:38:44 +0000356
Lev Walkin3251b8e2004-08-23 09:23:02 +0000357 /* { joint-iso-itu-t 2 1 0 1 } */
358 uint8_t buf20[] = {
359 0x06, /* OBJECT IDENTIFIER */
360 0x04, /* Length */
361 0x52, 0x01, 0x00, 0x01
362 };
363 int buf20_check[] = { 2, 2, 1, 0, 1 };
364
Lev Walkinf15320b2004-06-03 03:38:44 +0000365
366 CHECK_OID(1); /* buf1, buf1_check */
367 CHECK_ROID(2); /* buf2, buf2_check */
Lev Walkin0787ff02004-06-17 23:43:39 +0000368 CHECK_OID(3); /* buf3, buf3_check */
369 CHECK_OID(4); /* buf4, buf4_check */
Lev Walkin6c9e0712004-08-22 03:01:37 +0000370 CHECK_OID(19); /* buf19, buf19_check */
Lev Walkin3251b8e2004-08-23 09:23:02 +0000371 CHECK_OID(20); /* buf20, buf20_check */
Lev Walkinf15320b2004-06-03 03:38:44 +0000372
Lev Walkin0787ff02004-06-17 23:43:39 +0000373 CHECK_REGEN(5); /* Regenerate RELATIVE-OID */
Lev Walkinf15320b2004-06-03 03:38:44 +0000374 CHECK_REGEN(6);
375 CHECK_REGEN(7);
376 CHECK_REGEN(8);
377 CHECK_REGEN(9);
378 CHECK_REGEN(10);
Lev Walkin0787ff02004-06-17 23:43:39 +0000379 CHECK_REGEN(11);
380 CHECK_REGEN(12);
381 CHECK_REGEN(13);
382 CHECK_REGEN(14);
383 CHECK_REGEN(15);
384 CHECK_REGEN(16);
385 CHECK_REGEN(17);
Lev Walkinf15320b2004-06-03 03:38:44 +0000386 CHECK_REGEN_OID(1); /* Regenerate OBJECT IDENTIFIER */
Lev Walkin0787ff02004-06-17 23:43:39 +0000387 CHECK_REGEN_OID(3); /* Regenerate OBJECT IDENTIFIER */
388 CHECK_REGEN_OID(4); /* Regenerate OBJECT IDENTIFIER */
Lev Walkinf15320b2004-06-03 03:38:44 +0000389 CHECK_REGEN_OID(13);
Lev Walkin0787ff02004-06-17 23:43:39 +0000390 CHECK_REGEN_OID(14);
391 CHECK_REGEN_OID(15);
392 CHECK_REGEN_OID(16);
393 CHECK_REGEN_OID(17);
Lev Walkin6c9e0712004-08-22 03:01:37 +0000394 CHECK_REGEN_OID(18);
Lev Walkin3251b8e2004-08-23 09:23:02 +0000395 CHECK_REGEN_OID(19);
396 CHECK_REGEN_OID(20);
Lev Walkin0787ff02004-06-17 23:43:39 +0000397
Lev Walkincad560a2013-03-16 07:00:58 -0700398 check_parse("", 0);
399 check_parse(" ", 0);
Lev Walkin92302252004-10-23 10:16:51 +0000400 check_parse(".", -1);
401 check_parse(" .", -1);
Lev Walkinf5927112012-09-03 00:48:45 -0700402 check_parse(".1", -1);
403 check_parse("1.", -1);
404 check_parse("1. ", -1);
405 check_parse(".1. ", -1);
406 check_parse(" .1. ", -1);
Lev Walkin92302252004-10-23 10:16:51 +0000407 check_parse(" 1", 1);
408 check_parse(" 1.2", 2);
409 check_parse(" 1.", -1);
410 check_parse(" 1. ", -1);
411 check_parse("1. ", -1);
412 check_parse("1.2", 2);
Lev Walkinf5927112012-09-03 00:48:45 -0700413 check_parse("1.2 ", 2);
414 check_parse("1.2 ", 2);
415 check_parse(" 1.2 ", 2);
416 check_parse("1. 2", -1);
417 check_parse("1 .2", -1);
Lev Walkincad560a2013-03-16 07:00:58 -0700418 check_parse(" 1 .2", -1);
419 check_parse(" 1 .2 ", -1);
420 check_parse("1 .2 ", -1);
421 check_parse("1.+1", -1);
Lev Walkin92302252004-10-23 10:16:51 +0000422 check_parse("10.30.234.234", 4);
423 check_parse("10.30.234.234 ", 4);
424 check_parse("10.30.234. 234 ", -1);
425 check_parse("10.30.234.234.", -1);
426 check_parse("1.2000000000.3", 3);
427 check_parse("1.2147483647.3", 3);
428 if(sizeof(long) == 4) {
429 check_parse("1.2147483648.3", -1); /* overflow on ILP32 */
Lev Walkina7d1fb32012-01-23 01:21:55 +0000430 check_parse("1.2147483649.3", -1); /* overflow on ILP32 */
Lev Walkin92302252004-10-23 10:16:51 +0000431 check_parse("1.3000000000.3", -1);
432 check_parse("1.4000000000.3", -1);
433 check_parse("1.5000000000.3", -1);
434 check_parse("1.6000000000.3", -1);
435 check_parse("1.9000000000.3", -1);
Lev Walkina7d1fb32012-01-23 01:21:55 +0000436 } else if(sizeof(long) == 8) {
Lev Walkin92302252004-10-23 10:16:51 +0000437 check_parse("1.2147483648.3", 3);
Lev Walkina7d1fb32012-01-23 01:21:55 +0000438 check_parse("1.9223372036854775807.3", 3);
439 check_parse("1.9223372036854775808.3", -1);
Lev Walkin92302252004-10-23 10:16:51 +0000440 }
441 check_parse("1.900a0000000.3", -1);
442 check_parse("1.900a.3", -1);
443
Lev Walkinf5927112012-09-03 00:48:45 -0700444 check_xer(-1, "<t></t>");
Lev Walkin92302252004-10-23 10:16:51 +0000445 check_xer(2, "<t>1.2</t>");
446 check_xer(3, "<t>1.2.3</t>");
447 check_xer(3, "<t> 1.2.3 </t>");
448 check_xer(-1, "<t>1.2.3 1</t>");
449
Lev Walkin0787ff02004-06-17 23:43:39 +0000450 for(i = 0; i < 100000; i++) {
451 int bufA_check[3] = { 2, i, rand() };
452 int bufB_check[2] = { rand(), i * 121 };
453 CHECK_REGEN(A);
454 CHECK_REGEN_OID(A);
455 CHECK_REGEN(B);
456 if(i > 100) i++;
457 if(i > 500) i++;
458 if(i > 1000) i += 3;
459 if(i > 5000) i += 151;
460 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000461
Lev Walkinc4c61962004-06-14 08:17:27 +0000462 if(getenv("CHECK_SPEED")) {
463 /* Useful for developers only */
464 check_speed();
465 }
Lev Walkin29a044b2004-06-14 07:24:36 +0000466
Lev Walkinf15320b2004-06-03 03:38:44 +0000467 return 0;
468}
Lev Walkin725883b2006-10-09 12:07:58 +0000469