1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013
|
// arraytest.c -- test array/vector messages
//
// What does this test?
// 1. sending typestring [i] (an array with one integer)
// 2. sending typestring [] (an array with no integers)
// 3. sending typestring [ii] (an array with 2 integers)
// 4. sending typestring [xixdx] where x is one of: ihfdcBbtsSmTFIN
// (just in case a mix of sizes causes problems)
// 5. sending typestring i[ih][fdt]d to test multiple arrays
// 6. sending typestring [ddddd...] where there are 1 to 100 d's
// 7. sending typestring vi (with length 0 to 100)
// 8. sending typestring vf (with length 0 to 100)
// 9. sending typestring vh (with length 0 to 100)
// 10. sending typestring vd (with length 0 to 100)
// 11. sending typestring vt (with length 0 to 100)
// 12. sending typestring ifvtif (with vector length 0 to 100)
// (this last test is an extra check for embedded vectors)
// 13. sending typestring vivd (with lenghts 0 to 100)
// (another test to look for bugs in allocation, receiving multiple
// vectors in one message)
// 14. sending i[xxxx...]i where x is in ihfdt and there are 0 to 100
// of them AND the data is received as a vector using coercion
// 15. sending ivxi where x is in ihfdt and there are 0 to 100
// of them AND the data is received as an array using coercion
#include <stdio.h>
#include "o2.h"
#include "assert.h"
#include "string.h"
#ifdef WIN32
#define snprintf _snprintf
#endif
int got_the_message = FALSE;
o2_blob_ptr a_blob;
uint32_t a_midi_msg;
char xtype = 0; // used to tell handler what type(s) to expect when
char ytype = 0; // used to tell handler what type(s) to coerce to
// a handler is used to accept multiple message types
int arg_count = 0; // used to tell handler how many is correct
// 1. sending typestring [i] (an array with one integer)
//
void service_ai(o2_msg_data_ptr data, const char *types,
o2_arg_ptr *argv, int argc, void *user_data)
{
o2_extract_start(data);
assert(*types++ == '[');
#ifndef NDEBUG
o2_arg_ptr arg = // only needed by assert()
#endif
o2_get_next('[');
assert(arg == o2_got_start_array);
assert(*types++ == 'i');
#ifndef NDEBUG
arg = // only needed by assert()
#endif
o2_get_next('i');
assert(arg->i == 3456);
assert(*types++ == ']');
#ifndef NDEBUG
arg = // only needed by assert()
#endif
o2_get_next(']');
assert(arg == o2_got_end_array);
assert(*types == 0);
got_the_message = TRUE;
}
// 2. sending typestring [] (an array with no integers)
//
void service_a(o2_msg_data_ptr data, const char *types,
o2_arg_ptr *argv, int argc, void *user_data)
{
o2_extract_start(data);
assert(*types++ == '[');
#ifndef NDEBUG
o2_arg_ptr arg = // only needed by assert()
#endif
o2_get_next('[');
assert(arg == o2_got_start_array);
assert(*types++ == ']');
#ifndef NDEBUG
arg = // only needed by assert()
#endif
o2_get_next(']');
assert(arg == o2_got_end_array);
assert(*types == 0);
got_the_message = TRUE;
}
// 3. sending typestring [ii] (an array with 2 integers)
//
void service_aii(o2_msg_data_ptr data, const char *types,
o2_arg_ptr *argv, int argc, void *user_data)
{
o2_extract_start(data);
assert(*types++ == '[');
#ifndef NDEBUG
o2_arg_ptr arg = // only needed by assert()
#endif
o2_get_next('[');
assert(arg == o2_got_start_array);
assert(*types++ == 'i');
#ifndef NDEBUG
arg = // only needed by assert()
#endif
o2_get_next('i');
assert(arg->i == 123);
assert(*types++ == 'i');
#ifndef NDEBUG
arg = // only needed by assert()
#endif
o2_get_next('i');
assert(arg->i == 234);
assert(*types++ == ']');
#ifndef NDEBUG
arg = // only needed by assert()
#endif
o2_get_next(']');
assert(arg == o2_got_end_array);
assert(*types == 0);
got_the_message = TRUE;
}
void check_val(char actual_type)
{
o2_arg_ptr arg;
assert(actual_type == xtype);
arg = o2_get_next(xtype);
switch (xtype) {
case O2_INT32:
assert(arg->i == 1234);
break;
case O2_INT64:
assert(arg->h == 12345);
break;
case O2_FLOAT:
assert(arg->f == 1234.56F);
break;
case O2_DOUBLE:
assert(arg->d == 1234.567);
break;
case O2_TIME:
assert(arg->t == 2345.678);
break;
case O2_BOOL:
assert(arg->B);
break;
case O2_CHAR:
assert(arg->c == '$');
break;
case O2_TRUE:
case O2_FALSE:
case O2_INFINITUM:
case O2_NIL:
assert(arg);
break;
case O2_BLOB:
assert(arg->b.size == a_blob->size &&
memcmp(arg->b.data, a_blob->data, 15) == 0);
break;
case O2_STRING:
assert(strcmp(arg->S, "This is a string") == 0);
break;
case O2_SYMBOL:
assert(strcmp(arg->S, "This is a symbol") == 0);
break;
case O2_MIDI:
assert(arg->m == a_midi_msg);
break;
default:
assert(FALSE);
}
return;
}
void icheck(char typ, int val)
{
assert(typ == 'i');
#ifndef NDEBUG
o2_arg_ptr arg = // only needed for assert()
#endif
o2_get_next('i');
assert(arg && arg->i == val);
}
void hcheck(char typ, int64_t val)
{
assert(typ == 'h');
#ifndef NDEBUG
o2_arg_ptr arg = // only needed for assert()
#endif
o2_get_next('h');
assert(arg && arg->h == val);
}
void dcheck(char typ, double val)
{
assert(typ == 'd');
#ifndef NDEBUG
o2_arg_ptr arg = // only needed for assert()
#endif
o2_get_next('d');
assert(arg && arg->d == val);
}
void tcheck(char typ, double val)
{
assert(typ == 't');
#ifndef NDEBUG
o2_arg_ptr arg = // only needed for assert()
#endif
o2_get_next('t');
assert(arg && arg->t == val);
}
void fcheck(char typ, float val)
{
assert(typ == 'f');
#ifndef NDEBUG
o2_arg_ptr arg = // only needed for assert()
#endif
o2_get_next('f');
assert(arg && arg->f == val);
}
void acheck(char typ)
{
assert(typ == '[');
#ifndef NDEBUG
o2_arg_ptr arg = // only needed for assert()
#endif
o2_get_next('[');
assert(arg && arg == o2_got_start_array);
}
void zcheck(char typ)
{
assert(typ == ']');
#ifndef NDEBUG
o2_arg_ptr arg = // only needed for assert()
#endif
o2_get_next(']');
assert(arg && arg == o2_got_end_array);
}
// 4. sending typestring [xixdx] where x is one of: ihfdcBbtsSmTFIN
// (just in case a mix of sizes causes problems); the global
// char xtype; provides the value of x
//
void service_xixdx(o2_msg_data_ptr data, const char *types,
o2_arg_ptr *argv, int argc, void *user_data)
{
o2_extract_start(data);
acheck(*types++);
check_val(*types++);
icheck(*types++, 456);
check_val(*types++);
dcheck(*types++, 234.567);
check_val(*types++);
zcheck(*types++);
assert(*types == 0);
got_the_message = TRUE;
}
// 5. sending typestring i[ih][fdt]d to test multiple arrays
//
void service_2arrays(o2_msg_data_ptr data, const char *types,
o2_arg_ptr *argv, int argc, void *user_data)
{
o2_extract_start(data);
icheck(*types++, 456);
acheck(*types++);
icheck(*types++, 1234);
hcheck(*types++, 12345);
zcheck(*types++);
acheck(*types++);
fcheck(*types++, 1234.56F);
dcheck(*types++, 1234.567);
tcheck(*types++, 2345.678);
zcheck(*types++);
dcheck(*types++, 1234.567);
assert(*types == 0);
got_the_message = TRUE;
}
// 6. sending typestring [ddddd...] where there are 1 to 100 d's
//
void service_bigarray(o2_msg_data_ptr data, const char *types,
o2_arg_ptr *argv, int argc, void *user_data)
{
o2_extract_start(data);
acheck(*types++);
for (int i = 0; i < arg_count; i++) {
dcheck(*types++, 123.456 + i);
}
zcheck(*types++);
assert(*types == 0); // got all of typestring
got_the_message = TRUE;
}
// 7. sending typestring vi (with length 0 to 100)
//
void service_vi(o2_msg_data_ptr data, const char *types,
o2_arg_ptr *argv, int argc, void *user_data)
{
o2_extract_start(data);
assert(*types++ == 'v');
#ifndef NDEBUG
o2_arg_ptr arg = // only needed for assert()
#endif
o2_get_next('v');
assert(arg);
assert(*types++ == 'i');
#ifndef NDEBUG
o2_arg_ptr arg2 = // only needed for assert()
#endif
o2_get_next('i');
assert(arg2);
assert(arg2 == arg);
assert(arg->v.len == arg_count);
assert(arg->v.typ == 'i');
for (int i = 0; i < arg_count; i++) {
assert(arg->v.vi);
assert(arg->v.vi[i] == 1234 + i);
}
assert(*types == 0); // got all of typestring
got_the_message = TRUE;
}
// 8. sending typestring vf (with length 0 to 100)
//
void service_vf(o2_msg_data_ptr data, const char *types,
o2_arg_ptr *argv, int argc, void *user_data)
{
o2_extract_start(data);
assert(*types++ == 'v');
#ifndef NDEBUG
o2_arg_ptr arg = // only needed by assert()
#endif
o2_get_next('v');
assert(arg);
assert(*types++ == 'f');
#ifndef NDEBUG
o2_arg_ptr arg2 = // only needed by assert()
#endif
o2_get_next('f');
assert(arg2);
assert(arg2 == arg);
assert(arg->v.len == arg_count);
assert(arg->v.typ == 'f');
for (int i = 0; i < arg_count; i++) {
#ifndef NDEBUG
float correct = 123.456F + i; // only used by asserts
#endif
assert(arg->v.vf);
assert(arg->v.vf[i] == correct);
}
assert(*types == 0); // got all of typestring
got_the_message = TRUE;
}
// 9. sending typestring vh (with length 0 to 100)
void service_vh(o2_msg_data_ptr data, const char *types,
o2_arg_ptr *argv, int argc, void *user_data)
{
o2_extract_start(data);
assert(*types++ == 'v');
#ifndef NDEBUG
o2_arg_ptr arg = // only needed by assert()
#endif
o2_get_next('v');
assert(arg);
assert(*types++ == 'h');
#ifndef NDEBUG
o2_arg_ptr arg2 = // only needed by assert()
#endif
o2_get_next('h');
assert(arg2);
assert(arg2 == arg);
assert(arg->v.len == arg_count);
assert(arg->v.typ == 'h');
for (int i = 0; i < arg_count; i++) {
#ifndef NDEBUG
int64_t correct = 123456 + i; // only used by asserts
#endif
assert(arg->v.vh);
assert(arg->v.vh[i] == correct);
}
assert(*types == 0); // got all of typestring
got_the_message = TRUE;
}
// 10. sending typestring vd (with length 0 to 100)
void service_vd(o2_msg_data_ptr data, const char *types,
o2_arg_ptr *argv, int argc, void *user_data)
{
o2_extract_start(data);
assert(*types++ == 'v');
#ifndef NDEBUG
o2_arg_ptr arg = // only needed by assert()
#endif
o2_get_next('v');
assert(arg);
assert(*types++ == 'd');
#ifndef NDEBUG
o2_arg_ptr arg2 = // only needed by assert()
#endif
o2_get_next('d');
assert(arg2);
assert(arg2 == arg);
assert(arg->v.len == arg_count);
assert(arg->v.typ == 'd');
for (int i = 0; i < arg_count; i++) {
#ifndef NDEBUG
double correct = 1234.567 + i;
#endif
assert(arg->v.vd);
assert(arg->v.vd[i] == correct);
}
assert(*types == 0); // got all of typestring
got_the_message = TRUE;
}
// 12. sending typestring ifv?if (with vector length 0 to 100)
// (this last test is an extra check for embedded vectors)
void service_ifvxif(o2_msg_data_ptr data, const char *types,
o2_arg_ptr *argv, int argc, void *user_data)
{
o2_extract_start(data);
icheck(*types++, 2345);
fcheck(*types++, 345.67F);
assert(*types++ == 'v');
#ifndef NDEBUG
o2_arg_ptr arg = // only needed by assert()
#endif
o2_get_next('v');
assert(arg);
assert(*types++ == xtype);
#ifndef NDEBUG
o2_arg_ptr arg2 = // only needed by assert()
#endif
o2_get_next(xtype);
assert(arg2);
assert(arg2 == arg);
assert(arg->v.len == arg_count);
assert(arg->v.typ == xtype);
for (int i = 0; i < arg_count; i++) {
assert(arg->v.vd);
switch (xtype) {
case 'i': {
assert(arg->v.vi[i] == 1234 + i);
break;
}
case 'h': {
assert(arg->v.vh[i] == 123456 + i);
break;
}
case 'f': {
assert(arg->v.vf[i] == 123.456F + i);
break;
}
case 'd': {
assert(arg->v.vd[i] == 1234.567 + i);
break;
}
default:
assert(FALSE);
break;
}
}
icheck(*types++, 4567);
fcheck(*types++, 567.89F);
assert(*types == 0); // got all of typestring
got_the_message = TRUE;
}
// 13. sending typestring vivd (with lenghts 0 to 100)
// (another test to look for bugs in allocation, receiving multiple
// vectors in one message)
void service_vivd(o2_msg_data_ptr data, const char *types,
o2_arg_ptr *argv, int argc, void *user_data)
{
o2_extract_start(data);
assert(*types++ == 'v');
#ifndef NDEBUG
o2_arg_ptr arg = // only needed by assert()
#endif
o2_get_next('v');
assert(arg);
assert(*types++ == 'i');
#ifndef NDEBUG
o2_arg_ptr arg2 = // only needed by assert()
#endif
o2_get_next('i');
assert(arg2);
assert(arg2 == arg);
assert(arg->v.len == arg_count);
assert(arg->v.typ == 'i');
for (int i = 0; i < arg_count; i++) {
assert(arg->v.vi);
assert(arg->v.vi[i] == 1234 + i);
}
assert(*types++ == 'v');
#ifndef NDEBUG
arg = // only needed by assert()
#endif
o2_get_next('v');
assert(arg);
assert(*types++ == 'd');
#ifndef NDEBUG
arg2 = // only needed by assert()
#endif
o2_get_next('d');
assert(arg2);
assert(arg2 == arg);
assert(arg->v.len == arg_count);
assert(arg->v.typ == 'd');
for (int i = 0; i < arg_count; i++) {
assert(arg->v.vi);
assert(arg->v.vd[i] == 1234.567 + i);
}
assert(*types == 0); // got all of typestring
got_the_message = TRUE;
}
// 14. sending i[xxxx...]i where x is in ihfdt and there are 0 to 100
// of them AND the data is received as a vector using coercion
void service_coerce(o2_msg_data_ptr data, const char *types,
o2_arg_ptr *argv, int argc, void *user_data)
{
o2_extract_start(data);
icheck(*types++, 5678);
#ifndef NDEBUG
o2_arg_ptr arg = // only needed by assert()
#endif
o2_get_next('v');
assert(*types++ == '[');
#ifndef NDEBUG
o2_arg_ptr arg2 = // only needed by assert()
#endif
o2_get_next(ytype);
assert(arg2);
assert(arg2 == arg);
assert(arg->v.len == arg_count);
assert(arg->v.typ == ytype);
for (int i = 0; i < arg_count; i++) {
assert(arg->v.vi);
double expected;
switch (xtype) {
case 'i': expected = 543 + i; break;
case 'h': expected = 543 + i; break;
case 'f': expected = (float) (543.21 + i); break;
case 'd': expected = 543.21 + i; break;
}
switch (ytype) {
case 'i': assert(arg->v.vi[i] == (int32_t) expected); break;
case 'h': assert(arg->v.vh[i] == (int64_t) expected); break;
case 'f': assert(arg->v.vf[i] == (float) expected); break;
case 'd': assert(arg->v.vd[i] == expected); break;
default: assert(FALSE);
}
assert(*types++ == xtype);
}
assert(*types++ == ']');
#ifndef NDEBUG
arg2 = // only needed by assert()
#endif
o2_get_next(']');
assert(arg2 == o2_got_end_array);
icheck(*types++, 6789);
assert(*types == 0); // got all of typestring
got_the_message = TRUE;
}
// 15. sending ivxi where x is in ihfdt and there are 0 to 100
// of them AND the data is received as an array using coercion
void service_coerce2(o2_msg_data_ptr data, const char *types,
o2_arg_ptr *argv, int argc, void *user_data)
{
o2_extract_start(data);
icheck(*types++, 5678);
fcheck(*types++, 567.89F);
assert(*types++ == 'v');
assert(*types++ == xtype);
o2_arg_ptr arg = o2_get_next('[');
assert(arg);
for (int i = 0; i < arg_count; i++) {
arg = o2_get_next(ytype);
assert(arg);
double expected;
switch (xtype) {
case 'i': {
expected = 1234 + i;
break;
}
case 'h': {
expected = 123456 + i;
break;
}
case 'f': {
expected = 123.456F + i;
break;
}
case 'd': {
expected = 1234.567 + i;
break;
}
default:
assert(FALSE);
break;
}
switch (ytype) {
case 'i': assert(arg->i == (int32_t) expected); break;
case 'h': assert(arg->h == (int64_t) expected); break;
case 'f': assert(arg->f == (float) expected); break;
case 'd': case 't':
assert(arg->d == expected); break;
default: assert(FALSE);
}
}
#ifndef NDEBUG
arg = // only needed by assert()
#endif
o2_get_next(']');
assert(arg == o2_got_end_array);
icheck(*types++, 6789);
fcheck(*types++, 567.89F);
assert(*types == 0); // got all of typestring
got_the_message = TRUE;
}
void send_the_message()
{
for (int i = 0; i < 1000000; i++) {
if (got_the_message) break;
o2_poll();
}
assert(got_the_message);
got_the_message = FALSE;
}
// add a parameter of type xtype
void add_x_parameter()
{
switch (xtype) {
case O2_INT32:
o2_add_int32(1234);
break;
case O2_INT64:
o2_add_int64(12345);
break;
case O2_FLOAT:
o2_add_float(1234.56F);
break;
case O2_DOUBLE:
o2_add_double(1234.567);
break;
case O2_TIME:
o2_add_time(2345.678);
break;
case O2_CHAR:
o2_add_char('$');
break;
case O2_BOOL:
o2_add_bool(TRUE);
break;
case O2_TRUE:
o2_add_true();
break;
case O2_FALSE:
o2_add_false();
break;
case O2_INFINITUM:
o2_add_infinitum();
break;
case O2_NIL:
o2_add_nil();
break;
case O2_BLOB:
o2_add_blob(a_blob);
break;
case O2_STRING:
o2_add_string("This is a string");
break;
case O2_SYMBOL:
o2_add_symbol("This is a symbol");
break;
case O2_MIDI:
o2_add_midi(a_midi_msg);
break;
default:
assert(FALSE);
}
return;
}
int main(int argc, const char * argv[])
{
a_blob = malloc(20);
a_blob->size = 15;
memcpy(a_blob->data, "This is a blob", 15);
a_midi_msg = (0x90 << 16) + (60 << 8) + 100;
o2_initialize("test");
o2_service_new("one");
o2_method_new("/one/service_ai", "[i]", &service_ai, NULL, FALSE, FALSE);
o2_method_new("/one/service_a", "[]", &service_a, NULL, FALSE, FALSE);
o2_method_new("/one/service_aii", "[ii]", &service_aii,
NULL, FALSE, FALSE);
// [xixdx] where x is one of: hfcBbtsSmTFIN
char *xtypes = "ihfdcBbtsSmTFIN";
for (char *xtp = xtypes; *xtp; xtp++) {
xtype = *xtp;
char type_string[32];
snprintf(type_string, 32, "[%ci%cd%c]", xtype, xtype, xtype);
char address[32];
snprintf(address, 32, "/one/service_%ci%cd%c", xtype, xtype, xtype);
o2_method_new(address, type_string, &service_xixdx,
NULL, FALSE, FALSE);
}
o2_method_new("/one/service_2arrays", "i[ih][fdt]d", &service_2arrays, NULL, FALSE, FALSE);
// use NULL for type string to disable type-string checking
o2_method_new("/one/service_bigarray", NULL, &service_bigarray, NULL, FALSE, FALSE);
o2_method_new("/one/service_vi", NULL, &service_vi, NULL, FALSE, FALSE);
o2_method_new("/one/service_vf", NULL, &service_vf, NULL, FALSE, FALSE);
o2_method_new("/one/service_vh", NULL, &service_vh, NULL, FALSE, FALSE);
o2_method_new("/one/service_vd", NULL, &service_vd, NULL, FALSE, FALSE);
o2_method_new("/one/service_ifvxif", NULL,
&service_ifvxif, NULL, FALSE, FALSE);
o2_method_new("/one/service_vivd", NULL, &service_vivd, NULL, FALSE, FALSE);
o2_method_new("/one/service_coerce", NULL, &service_coerce, NULL, FALSE, FALSE);
o2_method_new("/one/service_coerce2", NULL, &service_coerce2, NULL, FALSE, FALSE);
o2_send_start();
o2_add_start_array();
o2_add_int32(3456);
o2_add_end_array();
o2_send_finish(0, "/one/service_ai", TRUE);
send_the_message();
printf("DONE sending [3456]\n");
o2_send_start();
o2_add_start_array();
o2_add_end_array();
o2_send_finish(0, "/one/service_a", TRUE);
send_the_message();
printf("DONE sending []\n");
o2_send_start();
o2_add_start_array();
o2_add_int32(123);
o2_add_int32(234);
o2_add_end_array();
o2_send_finish(0, "/one/service_aii", TRUE);
send_the_message();
printf("DONE sending [123, 234]\n");
// 4. sending typestring [xixdx] where x is one of: hfcBbtsSmTFIN
for (char *xtp = xtypes; *xtp; xtp++) {
xtype = *xtp;
o2_send_start();
o2_add_start_array();
add_x_parameter();
o2_add_int32(456);
add_x_parameter();
o2_add_double(234.567);
add_x_parameter();
o2_add_end_array();
char address[32];
snprintf(address, 32, "/one/service_%ci%cd%c", xtype, xtype, xtype);
o2_send_finish(0, address, TRUE);
send_the_message();
}
printf("DONE sending [xixdx] messages\n");
// 5. sending typestring i[ih][fdt]d to test multiple arrays
o2_send_start();
o2_add_int32(456);
o2_add_start_array();
o2_add_int32(1234);
o2_add_int64(12345);
o2_add_end_array();
o2_add_start_array();
o2_add_float(1234.56F);
o2_add_double(1234.567);
o2_add_time(2345.678);
o2_add_end_array();
o2_add_double(1234.567);
o2_send_finish(0, "/one/service_2arrays", TRUE);
send_the_message();
printf("DONE sending 456,[456,12345][1234.56,1234.567,2345.678],1234.567\n");
// 6. sending typestring [ddddd...] where there are 1 to 100 d's
for (int i = 0; i < 101; i++) {
arg_count = i;
o2_send_start();
o2_add_start_array();
for (int j = 0; j < i; j++) {
o2_add_double(123.456 + j);
}
o2_add_end_array();
o2_send_finish(0, "/one/service_bigarray", TRUE);
send_the_message();
}
printf("DONE sending [ddd...], size 0 through 100\n");
// 7. sending typestring vi (with length 0 to 100)
int ivec[102];
for (int j = 0; j < 102; j++) {
ivec[j] = 1234 + j;
}
for (int i = 0; i < 101; i++) {
arg_count = i;
o2_send_start();
o2_add_vector('i', i, ivec);
o2_send_finish(0, "/one/service_vi", TRUE);
send_the_message();
}
printf("DONE sending vi, size 0 through 100\n");
// 8. sending typestring vf (with length 0 to 100)
float fvec[102];
for (int j = 0; j < 102; j++) {
fvec[j] = 123.456F + j;
}
for (int i = 0; i < 101; i++) {
arg_count = i;
o2_send_start();
o2_add_vector('f', i, fvec);
o2_send_finish(0, "/one/service_vf", TRUE);
send_the_message();
}
printf("DONE sending vf, size 0 through 100\n");
// 9. sending typestring vh (with length 0 to 100)
int64_t hvec[102];
for (int j = 0; j < 102; j++) {
hvec[j] = 123456 + j;
}
for (int i = 0; i < 101; i++) {
arg_count = i;
o2_send_start();
o2_add_vector('h', i, hvec);
o2_send_finish(0, "/one/service_vh", TRUE);
send_the_message();
}
printf("DONE sending vh, size 0 through 100\n");
// 10. sending typestring vd (with length 0 to 100)
double dvec[102];
for (int j = 0; j < 102; j++) {
dvec[j] = 1234.567 + j;
}
for (int i = 0; i < 101; i++) {
arg_count = i;
o2_send_start();
o2_add_vector('d', i, dvec);
o2_send_finish(0, "/one/service_vd", TRUE);
send_the_message();
}
printf("DONE sending vd, size 0 through 100\n");
// 12. sending typestring ifvxif (with length 0 to 100)
for (char *xtp = "ihfd"; *xtp; xtp++) {
xtype = *xtp;
for (int i = 0; i < 101; i++) {
o2_send_start();
o2_add_int32(2345);
o2_add_float(345.67F);
arg_count = i;
switch (xtype) {
case 'i': o2_add_vector('i', i, ivec); break;
case 'h': o2_add_vector('h', i, hvec); break;
case 'f': o2_add_vector('f', i, fvec); break;
case 'd': o2_add_vector('d', i, dvec); break;
default: assert(FALSE);
}
o2_add_int32(4567);
o2_add_float(567.89F);
o2_send_finish(0, "/one/service_ifvxif", TRUE);
send_the_message();
}
}
printf("DONE sending ifvxif, types ihfd, size 0 through 100\n");
// 13. sending typestring vivd (with length 0 to 100)
for (int i = 0; i < 101; i++) {
o2_send_start();
arg_count = i;
o2_add_vector('i', i, ivec);
o2_add_vector('d', i, dvec);
o2_send_finish(0, "/one/service_vivd", TRUE);
send_the_message();
}
printf("DONE sending vivd, size 0 through 100\n");
// 14. sending i[xxxx...]i where x is in ihfdt and there are 0 to 100
// of them AND the data is received as a vector using coercion
for (char *xtp = "ihfd"; *xtp; xtp++) {
xtype = *xtp;
for (char *ytp = "ihfd"; *ytp; ytp++) {
ytype = *ytp;
for (int i = 0; i < 101; i++) {
o2_send_start();
o2_add_int32(5678);
arg_count = i;
o2_add_start_array();
for (int j = 0; j < i; j++) {
switch (xtype) {
case 'i': o2_add_int32(543 + j); break;
case 'h': o2_add_int64(543 + j); break;
case 'f': o2_add_float(543.21F + j); break;
case 'd': o2_add_double(543.21 + j); break;
default: assert(FALSE);
}
}
o2_add_end_array();
o2_add_int32(6789);
o2_send_finish(0, "/one/service_coerce", TRUE);
send_the_message();
}
}
}
printf("DONE sending ifvxif, types ihfdt, size 0 through 100\n");
// 15. sending ivxi where x is in ihfd and there are 0 to 100
// of them AND the data is received as an array using coercion
for (char *x = "ihfd"; *x; x++) {
xtype = *x;
for (char *y = "ihfdt"; *y; y++) {
ytype = *y;
for (int i = 0; i < 101; i++) {
o2_send_start();
o2_add_int32(5678);
o2_add_float(567.89F);
arg_count = i;
switch (xtype) {
case 'i': o2_add_vector('i', i, ivec); break;
case 'h': o2_add_vector('h', i, hvec); break;
case 'f': o2_add_vector('f', i, fvec); break;
case 'd': o2_add_vector('d', i, dvec); break;
default: assert(FALSE);
}
o2_add_int32(6789);
o2_add_float(567.89F);
o2_send_finish(0, "/one/service_coerce2", TRUE);
send_the_message();
}
}
}
printf("DONE\n");
o2_finish();
return 0;
}
|