Annotation of OpenXM/src/ox_math/testclient.c, Revision 1.6
1.1 ohara 1: /* -*- mode: C; coding: euc-japan -*- */
1.6 ! ohara 2: /* $OpenXM: OpenXM/src/ox_math/testclient.c,v 1.5 1999/12/14 09:31:56 ohara Exp $ */
1.1 ohara 3:
4: #include <stdio.h>
5: #include <stdlib.h>
6: #include <unistd.h>
7: #include <string.h>
8: #include <errno.h>
9: #include <fcntl.h>
10: #include "ox.h"
11:
12: ox_file_t sv;
13:
14: int dumpx(int fd, int n)
15: {
16: unsigned char buff[2048];
17: int i;
18: int len = read(fd, buff, n);
19:
20: fprintf(stderr, "I have read %d byte from socket.\n", len);
21: for(i = 0; i < len; i++) {
22: fprintf(stderr, "%02x ", buff[i]);
23: if (i%20 == 19) {
24: fprintf(stderr, "\n");
25: }
26: }
27: fprintf(stderr, "\n");
28: return len;
29: }
30:
1.4 ohara 31: /* 平成11年11月7日 */
32: #define VERSION 0x11110700
33: #define ID_STRING "testclient version 0.11110700"
1.1 ohara 34:
35: int prompt()
36: {
1.3 ohara 37: printf("> ");
1.1 ohara 38: }
39:
1.4 ohara 40: int test_0()
1.1 ohara 41: {
42: cmo* c = NULL;
1.5 ohara 43: #ifdef DEBUG
44: fprintf(stderr, "testclient:: calling ox_mathcap().\n");
45: c = ox_mathcap(sv);
46: fprintf(stderr, "testclient:: cmo received.(%p)\n", c);
47: #else
48: c = ox_mathcap(sv);
49: #endif
50: print_cmo(c);
51: fflush(stderr);
52: send_ox_cmo(sv->stream, make_mathcap_object(VERSION, ID_STRING));
1.1 ohara 53:
54: ox_reset(sv);
55: send_ox_cmo(sv->stream, new_cmo_string("N[ArcTan[1]]"));
56: send_ox_command(sv->stream, SM_executeStringByLocalParser);
57: send_ox_command(sv->stream, SM_popCMO);
58: receive_ox_tag(sv->stream);
59: c = receive_cmo(sv->stream);
1.3 ohara 60: fprintf(stderr, "testclient:: cmo received.\n");
1.1 ohara 61: print_cmo(c);
1.4 ohara 62: }
63:
1.5 ohara 64: int test_1()
65: {
66: cmo *c = NULL;
67: cmo *m = make_mathcap_object(1000, "test!");
68: fprintf(stderr, "testclient:: test cmo_mathcap.\n");
69: send_ox_cmo(sv->stream, m);
70: send_ox_command(sv->stream, SM_popCMO);
71: receive_ox_tag(sv->stream);
72: c = receive_cmo(sv->stream);
73: fprintf(stderr, "testclient:: cmo received.(%p)\n", c);
74: print_cmo(c);
75: fputc('\n', stderr);
76: }
77:
1.4 ohara 78: int main(int argc, char* argv[])
79: {
80: ox* m = NULL;
81: cmo* c = NULL;
82: int code;
83: char *server = "ox_sm1";
84:
85: setbuf(stderr, NULL);
86:
87: if (argc>1) {
88: server = argv[1];
89: }
90: fprintf(stderr, "testclient:: I use %s as an OX server.\n", server);
91: sv = ox_start("localhost", "ox", server);
92: if (sv == NULL) {
93: fprintf(stderr, "testclient:: I cannot connect to servers.\n");
94: exit(1);
95: }
96:
1.6 ! ohara 97: if (strcmp(server, "ox_math")==0) {
1.5 ohara 98: test_1();
1.4 ohara 99: }
1.1 ohara 100:
101: while(prompt(), (m = parse()) != NULL) {
1.5 ohara 102: send_ox(sv->stream, m);
1.1 ohara 103: if (m->tag == OX_COMMAND) {
104: code = ((ox_command *)m)->command;
105: if (code >= 1024) {
106: break;
107: }else if (code == SM_popCMO || code == SM_popString) {
108: receive_ox_tag(sv->stream);
109: c = receive_cmo(sv->stream);
1.3 ohara 110: fprintf(stderr, "testclient:: cmo received.\n");
1.1 ohara 111: print_cmo(c);
112: }
113: }
114: }
115:
116: ox_reset(sv);
1.3 ohara 117: fprintf(stderr, "The testclient resets.\n");
1.1 ohara 118: ox_close(sv);
1.3 ohara 119: fprintf(stderr, "The testclient halts.\n");
1.1 ohara 120:
121: return 0;
122: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>