| 477 | |
| 478 | #define UNUSED(x) (void)(x) |
| 479 | int zipmapTest(int argc, char *argv[], int accurate) { |
| 480 | unsigned char *zm; |
| 481 | |
| 482 | UNUSED(argc); |
| 483 | UNUSED(argv); |
| 484 | UNUSED(accurate); |
| 485 | |
| 486 | zm = zipmapNew(); |
| 487 | |
| 488 | zm = zipmapSet(zm,(unsigned char*) "name",4, (unsigned char*) "foo",3,NULL); |
| 489 | zm = zipmapSet(zm,(unsigned char*) "surname",7, (unsigned char*) "foo",3,NULL); |
| 490 | zm = zipmapSet(zm,(unsigned char*) "age",3, (unsigned char*) "foo",3,NULL); |
| 491 | zipmapRepr(zm); |
| 492 | |
| 493 | zm = zipmapSet(zm,(unsigned char*) "hello",5, (unsigned char*) "world!",6,NULL); |
| 494 | zm = zipmapSet(zm,(unsigned char*) "foo",3, (unsigned char*) "bar",3,NULL); |
| 495 | zm = zipmapSet(zm,(unsigned char*) "foo",3, (unsigned char*) "!",1,NULL); |
| 496 | zipmapRepr(zm); |
| 497 | zm = zipmapSet(zm,(unsigned char*) "foo",3, (unsigned char*) "12345",5,NULL); |
| 498 | zipmapRepr(zm); |
| 499 | zm = zipmapSet(zm,(unsigned char*) "new",3, (unsigned char*) "xx",2,NULL); |
| 500 | zm = zipmapSet(zm,(unsigned char*) "noval",5, (unsigned char*) "",0,NULL); |
| 501 | zipmapRepr(zm); |
| 502 | zm = zipmapDel(zm,(unsigned char*) "new",3,NULL); |
| 503 | zipmapRepr(zm); |
| 504 | |
| 505 | printf("\nLook up large key:\n"); |
| 506 | { |
| 507 | unsigned char buf[512]; |
| 508 | unsigned char *value; |
| 509 | unsigned int vlen, i; |
| 510 | for (i = 0; i < 512; i++) buf[i] = 'a'; |
| 511 | |
| 512 | zm = zipmapSet(zm,buf,512,(unsigned char*) "long",4,NULL); |
| 513 | if (zipmapGet(zm,buf,512,&value,&vlen)) { |
| 514 | printf(" <long key> is associated to the %d bytes value: %.*s\n", |
| 515 | vlen, vlen, value); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | printf("\nPerform a direct lookup:\n"); |
| 520 | { |
| 521 | unsigned char *value; |
| 522 | unsigned int vlen; |
| 523 | |
| 524 | if (zipmapGet(zm,(unsigned char*) "foo",3,&value,&vlen)) { |
| 525 | printf(" foo is associated to the %d bytes value: %.*s\n", |
| 526 | vlen, vlen, value); |
| 527 | } |
| 528 | } |
| 529 | printf("\nIterate through elements:\n"); |
| 530 | { |
| 531 | unsigned char *i = zipmapRewind(zm); |
| 532 | unsigned char *key, *value; |
| 533 | unsigned int klen, vlen; |
| 534 | |
| 535 | while((i = zipmapNext(i,&key,&klen,&value,&vlen)) != NULL) { |
| 536 | printf(" %d:%.*s => %d:%.*s\n", klen, klen, key, vlen, vlen, value); |
nothing calls this directly
no test coverage detected