29 #define snprintf _snprintf
40 #define PATHDELIM "\\"
46 #define MSG_NOSIGNAL 0
49 #define TEST(cond) if (!(cond)) { fprintf(stderr, "FAILED " #cond \
50 " at %s:%d\n", __FILE__, __LINE__); \
52 else { printf("passed " #cond "\n"); }
83 void error(
int num,
const char *m,
const char *path);
84 void rep_error(
int num,
const char *m,
const char *path);
131 char *server_url, *path, *protocol, *host, *port;
132 const char *host2, *port2;
134 uint8_t midi_data[4] = {0xff, 0xf7, 0xAA, 0x00};
147 fprintf(stderr,
"FAILED: create bad server thread object!\n");
182 printf(
"type tests\n");
183 TEST(
sizeof(
float) ==
sizeof(int32_t));
184 TEST(
sizeof(
double) ==
sizeof(int64_t));
186 et32.
i = 0x23242526U;
188 if (et32.
c[0] != 0x23 || et32.
c[1] != 0x24 || et32.
c[2] != 0x25 ||
190 fprintf(stderr,
"failed 32bit endian conversion test\n");
191 fprintf(stderr,
"0x23242526 -> %X\n", et32.
i);
194 printf(
"passed 32bit endian conversion test\n");
197 et64.
i = 0x232425262728292AULL;
199 if (et64.
c[0] != 0x23 || et64.
c[1] != 0x24 || et64.
c[2] != 0x25 ||
200 et64.
c[3] != 0x26 || et64.
c[4] != 0x27 || et64.
c[5] != 0x28 ||
201 et64.
c[6] != 0x29 || et64.
c[7] != 0x2A) {
202 fprintf(stderr,
"failed 64bit endian conversion\n");
203 fprintf(stderr,
"0x232425262728292A -> %llX\n", (
long long unsigned int)et64.
i);
206 printf(
"passed 64bit endian conversion\n");
212 if (strcmp(path,
"/a/path/is/here")) {
213 printf(
"failed lo_url_get_path() test1\n");
214 printf(
"'%s' != '/a/path/is/here'\n", path);
217 printf(
"passed lo_url_get_path() test1\n");
222 if (strcmp(protocol,
"udp")) {
223 printf(
"failed lo_url_get_protocol() test1\n");
224 printf(
"'%s' != 'udp'\n", protocol);
227 printf(
"passed lo_url_get_protocol() test1\n");
232 if (strcmp(protocol,
"tcp")) {
233 printf(
"failed lo_url_get_protocol() test2\n");
234 printf(
"'%s' != 'tcp'\n", protocol);
237 printf(
"passed lo_url_get_protocol() test2\n");
242 if (strcmp(protocol,
"udp")) {
243 printf(
"failed lo_url_get_protocol() test1 (IPv6)\n");
244 printf(
"'%s' != 'udp'\n", protocol);
247 printf(
"passed lo_url_get_protocol() test1 (IPv6)\n");
253 printf(
"failed lo_url_get_protocol_id() test1\n");
254 printf(
"'%d' != LO_UDP\n", proto);
257 printf(
"passed lo_url_get_protocol_id() test1\n");
262 printf(
"failed lo_url_get_protocol_id() test2\n");
263 printf(
"'%d' != LO_TCP\n", proto);
266 printf(
"passed lo_url_get_protocol_id() test2\n");
271 printf(
"failed lo_url_get_protocol_id() test3\n");
272 printf(
"'%d' != -1\n", proto);
275 printf(
"passed lo_url_get_protocol_id() test3\n");
280 printf(
"failed lo_url_get_protocol_id() test1 (IPv6)\n");
281 printf(
"'%d' != LO_UDP\n", proto);
284 printf(
"passed lo_url_get_protocol_id() test1 (IPv6)\n");
288 if (strcmp(host,
"foo.example.com")) {
289 printf(
"failed lo_url_get_hostname() test1\n");
290 printf(
"'%s' != 'foo.example.com'\n", host);
293 printf(
"passed lo_url_get_hostname() test1\n");
298 if (strcmp(host,
"0000::::0001")) {
299 printf(
"failed lo_url_get_hostname() test2 (IPv6)\n");
300 printf(
"'%s' != '0000::::0001'\n", host);
303 printf(
"passed lo_url_get_hostname() test2 (IPv6)\n");
308 if (strcmp(port,
"9999")) {
309 printf(
"failed lo_url_get_port() test1\n");
310 printf(
"'%s' != '9999'\n", port);
313 printf(
"passed lo_url_get_port() test1\n");
317 port =
lo_url_get_port(
"osc.udp://[::ffff:127.0.0.1]:9999/a/path/is/here");
318 if (strcmp(port,
"9999")) {
319 printf(
"failed lo_url_get_port() test1 (IPv6)\n");
320 printf(
"'%s' != '9999'\n", port);
323 printf(
"passed lo_url_get_port() test1 (IPv6)\n");
334 if (strcmp(host2,
"foo.example.com")) {
335 printf(
"failed lo_address_get_hostname() test\n");
336 printf(
"'%s' != 'foo.example.com'\n", host2);
339 printf(
"passed lo_address_get_hostname() test\n");
343 if (strcmp(port2,
"9999")) {
344 printf(
"failed lo_address_get_port() test\n");
345 printf(
"'%s' != '9999'\n", port2);
348 printf(
"passed lo_address_get_port() test\n");
353 printf(
"failed lo_address_get_protocol() test\n");
354 printf(
"'%d' != '%d'\n", proto,
LO_TCP);
357 printf(
"passed lo_address_get_protocol() test\n");
361 if (strcmp(server_url,
"osc.tcp://foo.example.com:9999/")) {
362 printf(
"failed lo_address_get_url() test\n");
363 printf(
"'%s' != '%s'\n", server_url,
"osc.tcp://foo.example.com:9999/");
366 printf(
"passed lo_address_get_url() test\n");
375 printf(
"blob is %d (%d) bytes long, should be 5 (12)\n",
378 printf(
" <- blob\n");
387 printf(
"Server URL: %s\n", server_url);
434 if (
lo_send(a,
"/foo/bar",
"ff", 0.12345678f, 23.0f) == -1) {
439 if (
lo_send(a,
"/foo/bar",
"ff", 0.12345678f, 23.0f) == -1) {
448 lo_send(a,
"/pattern/",
"i", 243);
451 lo_send(a,
"/bar",
"ff", 0.12345678f, 1.0/0.0);
453 lo_send(a,
"/lotsofformats",
"fisbmhtdSccTFNI", 0.12345678f, 123,
"123",
454 btest, midi_data, 0x0123456789abcdefULL, tt, 0.9999,
"sym",
456 lo_send(a,
"/coerce",
"fdihsS", 0.1f, 0.2, 123, 124LL,
"aaa",
"bbb");
457 lo_send(a,
"/coerce",
"ffffss", 0.1f, 0.2f, 123.0, 124.0,
"aaa",
"bbb");
458 lo_send(a,
"/coerce",
"ddddSS", 0.1, 0.2, 123.0, 124.0,
"aaa",
"bbb");
459 lo_send(a,
"/a/b/c/d",
"sfsff",
"one", 0.12345678f,
"three",
460 -0.00000023001f, 1.0);
461 lo_send(a,
"/a/b/c/d",
"b", btest);
464 "123", btest, midi_data, 0x0123456789abcdefULL, tt,
473 "123", btest, midi_data, 0x0123456789abcdefULL, tt,
477 "123", btest, midi_data, 0x0123456789abcdefULL, tt, 0.5,
484 btest, midi_data, 0x0123456789abcdefULL, tt, 0.9999,
"sym",
491 lo_send(a,
"/pattern/*",
"s",
"a");
492 lo_send(a,
"/pattern/ba[rz]",
"s",
"b");
495 sprintf(cmd,
"." PATHDELIM "subtest %s &", server_url);
496 if (system(cmd) != 0) {
497 fprintf(stderr,
"Cannot execute subtest command\n");
585 lo_send(a,
"/timestamp",
"it", 0, sched);
587 #define JITTER_ITS 25
598 stamps[
i].
frac = rand();
614 printf(
"pending events, wait...\n");
626 printf(
"bundle timing jitter results:\n"
629 "min jitter = %fs\n\n",
637 printf(
"Testing noblock API on %s\n", server_url);
638 lo_send(a,
"/non-block-test",
"f", 23.0);
643 printf(
"lo_server_recv_noblock() test failed\n");
662 unlink(
"/tmp/testlo.osc");
669 TEST(!strcmp(
"osc.unix:////tmp/testlo.osc", addr));
726 fprintf(stderr,
"\ntest run not completed\n" PACKAGE_NAME
733 void error(
int num,
const char *msg,
const char *path)
735 printf(
"liblo server error %d in %s: %s", num, path, msg);
739 printf(
" (expected)\n");
742 void rep_error(
int num,
const char *msg,
const char *path)
745 error(num, msg, path);
754 printf(
"path: <%s>\n", path);
755 for (i=0; i<argc; i++) {
756 printf(
"arg %d '%c' ", i, types[i]);
772 printf(
"Address of us: %s\n", server_url);
773 printf(
"%s <- f:%f, i:%d\n", path, argv[0]->f, argv[1]->i);
778 printf(
"Reply sent to %s\n\n", url);
791 printf(
"Reply received from %s\n", url);
804 if (strcmp(path,
"/lotsofformats")) {
805 fprintf(stderr,
"path != /lotsofformats\n");
808 printf(
"path = %s\n", path);
809 TEST(types[0] ==
'f' && argv[0]->f == 0.12345678f);
810 TEST(types[1] ==
'i' && argv[1]->i == 123);
811 TEST(types[2] ==
's' && !strcmp(&argv[2]->s,
"123"));
815 TEST(d[0] ==
'A' && d[1] ==
'B' && d[2] ==
'C' && d[3] ==
'D' &&
818 TEST(d[0] == 0xff && d[1] == 0xf7 && d[2] == 0xaa && d[3] == 0x00);
819 TEST(types[5] ==
'h' && argv[5]->h == 0x0123456789ABCDEFULL);
820 TEST(types[6] ==
't' && argv[6]->t.sec == 1 && \
821 argv[6]->
t.
frac == 0x80000000);
822 TEST(types[7] ==
'd' && argv[7]->d == 0.9999);
823 TEST(types[8] ==
'S' && !strcmp(&argv[8]->S,
"sym"));
824 printf(
"char: %d\n", argv[9]->
c);
825 TEST(types[9] ==
'c' && argv[9]->
c ==
'X');
826 TEST(types[10] ==
'c' && argv[10]->
c ==
'Y');
827 TEST(types[11] ==
'T');
828 TEST(types[12] ==
'F');
829 TEST(types[13] ==
'N');
830 TEST(types[14] ==
'I');
840 printf(
"path = %s\n", path);
841 TEST(types[0] ==
'd' && fabs(argv[0]->d - 0.1) < FLT_EPSILON);
842 TEST(types[1] ==
'f' && fabs(argv[1]->f - 0.2) < FLT_EPSILON);
843 TEST(types[2] ==
'h' && argv[2]->h == 123);
844 TEST(types[3] ==
'i' && argv[3]->i == 124);
845 TEST(types[4] ==
'S' && !strcmp(&argv[4]->S,
"aaa"));
846 TEST(types[5] ==
's' && !strcmp(&argv[5]->s,
"bbb"));
856 printf(
"received bundle\n");
864 int bundled = argv[0]->
i;
889 printf(
"%d expected: %x:%x received %x:%x\n", argv[1]->i, argv[0]->t.sec,
902 printf(
"pattern matched %s\n", (
char *)user_data);
946 printf(
"lo_message_add_varargs returned %d\n", error);
951 void replace_char(
char *str,
size_t size,
const char find,
const char replace)
956 if (find == *p) { *p = replace; }
963 char *buf, *buf2, *tmp;
964 const char *types = NULL, *path;
971 uint8_t midi_data[4] = {0xff, 0xf7, 0xAA, 0x00};
1000 TEST(
'f' == types[0] && fabs(argv[0]->f - 0.12345678f) < FLT_EPSILON);
1001 TEST(
'i' == types[1] && 123 == argv[1]->i);
1002 TEST(
's' == types[2] && !strcmp(&argv[2]->s,
"123"));
1003 TEST(
'b' == types[3]);
1008 TEST(
'm' == types[4] && !memcmp(&argv[4]->m, midi_data, 4));
1009 TEST(
'h' == types[5] && 0x0123456789abcdefULL == argv[5]->h);
1010 TEST(
't' == types[6] && 1 == argv[6]->t.sec && 0x80000000 == argv[6]->
t.
frac);
1011 TEST(
'd' == types[7] && fabs(argv[7]->d - 0.9999) < FLT_EPSILON);
1012 TEST(
'S' == types[8] && !strcmp(&argv[8]->s,
"sym"));
1013 TEST(
'c' == types[9] &&
'X' == argv[9]->
c);
1014 TEST(
'c' == types[10] &&
'Y' == argv[10]->
c);
1015 TEST(
'T' == types[11] && NULL == argv[11]);
1016 TEST(
'F' == types[12] && NULL == argv[12]);
1017 TEST(
'N' == types[13] && NULL == argv[13]);
1018 TEST(
'I' == types[14] && NULL == argv[14]);
1022 printf(
"serialise message_length=%d\n", (
int)len);
1023 buf = calloc(len,
sizeof(
char));
1026 TEST(tmp == buf && size == len && 92 == len);
1030 printf(
"deserialise\n");
1032 TEST(NULL != path && !strcmp(path,
"/foo"));
1039 TEST(NULL != types);
1042 TEST(
'f' == types[0] && fabs(argv[0]->f - 0.12345678f) < FLT_EPSILON);
1043 TEST(
'i' == types[1] && 123 == argv[1]->i);
1044 TEST(
's' == types[2] && !strcmp(&argv[2]->s,
"123"));
1045 TEST(
'b' == types[3]);
1050 TEST(
'm' == types[4] && !memcmp(&argv[4]->m, midi_data, 4));
1051 TEST(
'h' == types[5] && 0x0123456789abcdefULL == argv[5]->h);
1052 TEST(
't' == types[6] && 1 == argv[6]->t.sec && 0x80000000 == argv[6]->
t.
frac);
1053 TEST(
'd' == types[7] && fabs(argv[7]->d - 0.9999) < FLT_EPSILON);
1054 TEST(
'S' == types[8] && !strcmp(&argv[8]->s,
"sym"));
1055 TEST(
'c' == types[9] &&
'X' == argv[9]->
c);
1056 TEST(
'c' == types[10] &&
'Y' == argv[10]->
c);
1057 TEST(
'T' == types[11] && NULL == argv[11]);
1058 TEST(
'F' == types[12] && NULL == argv[12]);
1059 TEST(
'N' == types[13] && NULL == argv[13]);
1060 TEST(
'I' == types[14] && NULL == argv[14]);
1064 printf(
"serialise message_length=%d\n", (
int)len);
1065 buf2 = calloc(len,
sizeof(
char));
1068 TEST(tmp == buf2 && size == len && 92 == len);
1069 TEST(!memcmp(buf, buf2, len));
1081 snprintf(data, 256,
"%s",
"/foo");
1085 snprintf(data, 256,
"%s",
"/f_o");
1089 snprintf(data, 256,
"%s",
"/t__");
1094 snprintf(data, 256,
"%s%s",
"/t__",
"____");
1099 snprintf(data, 256,
"%s%s",
"/t__",
",f_");
1104 snprintf(data, 256,
"%s%s",
"/t__",
"ifi_");
1109 snprintf(data, 256,
"%s%s",
"/t__",
",ifi");
1114 snprintf(data, 256,
"%s%s",
"/t__",
",ii_");
1119 snprintf(data, 256,
"%s%s",
"/t__",
",ii_");
1124 snprintf(data, 256,
"%s%s",
"/t__",
",f__");
1129 snprintf(data, 256,
"%s%s",
"/t__",
",bs_");
1131 *(uint32_t *)(data + 8) =
lo_htoo32((uint32_t)99999);
1139 char mem[] = {
"/\0\0\0,bs\0,\x00\x0F\x42\x3F"};
1141 int sock = a->socket;
1151 printf(
"validation\n");
1156 fprintf(stderr,
"Couldn't get socket in test_validation(), %s:%d\n", __FILE__, __LINE__);
1162 a->ai->ai_addr, a->ai->ai_addrlen)==-1) {
1163 fprintf(stderr,
"Error sending packet in test_validation(), %s:%d\n", __FILE__, __LINE__);
1184 "/foo/bar",
"ff", 0.12345678f, 23.0f) == -1) {