CSL 5.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

subtest.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2005 Steve Harris
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation; either version 2.1 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * $Id$
15 */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 #ifndef _MSC_VER
21 #include <unistd.h>
22 #endif
23
24 #include "lo/lo.h"
25
26 int subtest_handler(const char *path, const char *types, lo_arg **argv,
27 int argc, lo_message data, void *user_data);
28
29 int main(int argc, char *argv[])
30 {
31 lo_server st = lo_server_thread_new(NULL, NULL);
32 lo_address t;
33
34 if (argc != 2) {
35 fprintf(stderr, "Usage: subtest <uri>\n");
36
37 return 1;
38 }
39
40 lo_server_thread_add_method(st, NULL, "i", subtest_handler, NULL);
41 lo_server_thread_start(st);
42
43 t = lo_address_new_from_url(argv[1]);
44 lo_send(t, "/subtest", "i", 0xf00);
45
46 #ifdef WIN32
47 Sleep(4000);
48 #else
49 sleep(4);
50 #endif
51
52 return 0;
53 }
54
55 int subtest_handler(const char *path, const char *types, lo_arg **argv,
56 int argc, lo_message data, void *user_data)
57 {
58 int i;
59 lo_address a = lo_message_get_source(data);
60 static char *uri = NULL;
61
62 printf("subtest: got reply (%s)\n", path);
63 if (!uri) {
64 uri = lo_address_get_url(a);
65 } else {
66 char *new_uri = lo_address_get_url(a);
67
68 if (strcmp(uri, new_uri)) {
69 printf("ERROR: %s != %s\n", uri, new_uri);
70
71 exit(1);
72 }
73 free(new_uri);
74 }
75 lo_send(a, "/subtest-reply", "i", 0xbaa);
76 if (lo_address_errno(a)) {
77 fprintf(stderr, "subtest error %d: %s\n", lo_address_errno(a),
78 lo_address_errstr(a));
79
80 exit(1);
81 }
82
83 for (i=0; i<10; i++) {
84 #ifdef WIN32
85 /* TODO: Wait time of 2.233 not easily doable in Windows */
86 Sleep(2);
87 #else
88 usleep(2233);
89 #endif
90 lo_send(a, "/subtest-reply", "i", 0xbaa+i);
91 }
92
93 return 0;
94 }
95
96 /* vi:set ts=8 sts=4 sw=4: */