~ubuntu-branches/ubuntu/maverick/ncbi-tools6/maverick

« back to all changes in this revision

Viewing changes to connect/test/test_ncbi_service_connector.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2002-04-04 22:13:09 UTC
  • Revision ID: james.westby@ubuntu.com-20020404221309-vfze028rfnlrldct
Tags: upstream-6.1.20011220a
ImportĀ upstreamĀ versionĀ 6.1.20011220a

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  $Id: test_ncbi_service_connector.c,v 6.15 2001/09/24 20:36:22 lavr Exp $
 
2
 * ===========================================================================
 
3
 *
 
4
 *                            PUBLIC DOMAIN NOTICE
 
5
 *               National Center for Biotechnology Information
 
6
 *
 
7
 *  This software/database is a "United States Government Work" under the
 
8
 *  terms of the United States Copyright Act.  It was written as part of
 
9
 *  the author's official duties as a United States Government employee and
 
10
 *  thus cannot be copyrighted.  This software/database is freely available
 
11
 *  to the public for use. The National Library of Medicine and the U.S.
 
12
 *  Government have not placed any restriction on its use or reproduction.
 
13
 *
 
14
 *  Although all reasonable efforts have been taken to ensure the accuracy
 
15
 *  and reliability of the software and data, the NLM and the U.S.
 
16
 *  Government do not and cannot warrant the performance or results that
 
17
 *  may be obtained by using this software or data. The NLM and the U.S.
 
18
 *  Government disclaim all warranties, express or implied, including
 
19
 *  warranties of performance, merchantability or fitness for any particular
 
20
 *  purpose.
 
21
 *
 
22
 *  Please cite the author in any work or product based on this material.
 
23
 *
 
24
 * ===========================================================================
 
25
 *
 
26
 * Author:  Anton Lavrentiev
 
27
 *
 
28
 * File Description:
 
29
 *   Standard test for the service connector
 
30
 *
 
31
 * --------------------------------------------------------------------------
 
32
 * $Log: test_ncbi_service_connector.c,v $
 
33
 * Revision 6.15  2001/09/24 20:36:22  lavr
 
34
 * Adjusted parameters in SERVICE_CreateConnectorEx()
 
35
 *
 
36
 * Revision 6.14  2001/06/11 22:17:28  lavr
 
37
 * Wait-for-reading timeout made finite
 
38
 *
 
39
 * Revision 6.13  2001/06/07 17:53:47  lavr
 
40
 * Persistent reading from test connection
 
41
 *
 
42
 * Revision 6.12  2001/06/01 16:19:10  lavr
 
43
 * Added (ifdef'ed out) an internal test connection to service ID1
 
44
 *
 
45
 * Revision 6.11  2001/05/11 16:05:41  lavr
 
46
 * Change log message corrected
 
47
 *
 
48
 * Revision 6.10  2001/05/11 15:38:01  lavr
 
49
 * Print connector type along with read data
 
50
 *
 
51
 * Revision 6.9  2001/04/24 21:42:43  lavr
 
52
 * Brushed code to use CORE_LOG facility only.
 
53
 *
 
54
 * Revision 6.8  2001/01/25 17:13:22  lavr
 
55
 * Added: close/free everything on program exit: useful to check memory leaks
 
56
 *
 
57
 * Revision 6.7  2001/01/23 23:22:34  lavr
 
58
 * debug_printout was given an enum value (instead of "boolean" 1)
 
59
 *
 
60
 * Revision 6.6  2001/01/09 15:35:20  lavr
 
61
 * Removed header <unistd.h>, unknown on WinNT
 
62
 *
 
63
 * Revision 6.5  2001/01/08 23:13:19  lavr
 
64
 * C/C++ -> C only
 
65
 *
 
66
 * Revision 6.4  2001/01/08 22:42:42  lavr
 
67
 * Further development of the test-suite
 
68
 *
 
69
 * Revision 6.3  2001/01/03 22:40:24  lavr
 
70
 * Minor adjustment
 
71
 *
 
72
 * Revision 6.2  2000/12/29 18:25:27  lavr
 
73
 * More tests added (still not yet complete).
 
74
 *
 
75
 * Revision 6.1  2000/10/20 17:31:07  lavr
 
76
 * Initial revision
 
77
 *
 
78
 * ==========================================================================
 
79
 */
 
80
 
 
81
#if defined(NDEBUG)
 
82
#  undef NDEBUG
 
83
#endif 
 
84
 
 
85
#include "../ncbi_priv.h"
 
86
#include <connect/ncbi_util.h>
 
87
#include <connect/ncbi_service_connector.h>
 
88
#include <assert.h>
 
89
#include <stdio.h>
 
90
#include <stdlib.h>
 
91
#include <string.h>
 
92
 
 
93
int main(int argc, const char* argv[])
 
94
{
 
95
    static char obuf[128] = "UUUUUZZZZZZUUUUUUZUZUZZUZUZUZUZUZ\n";
 
96
    const char* service = argc > 1 ? argv[1] : "bounce";
 
97
    const char* host = argc > 2 ? argv[2] : "ray";
 
98
    CONNECTOR connector;
 
99
    SConnNetInfo *info;
 
100
    STimeout  timeout;
 
101
    char ibuf[1024];
 
102
    CONN conn;
 
103
    size_t n;
 
104
 
 
105
    CORE_SetLOGFILE(stderr, 0/*false*/);
 
106
 
 
107
    info = ConnNetInfo_Create(service);
 
108
    strcpy(info->host, host);
 
109
    if (argc > 3) {
 
110
        strncpy(obuf, argv[3], sizeof(obuf) - 2);
 
111
        obuf[sizeof(obuf) - 2] = 0;
 
112
        obuf[n = strlen(obuf)] = '\n';
 
113
        obuf[++n]              = 0;
 
114
    }
 
115
 
 
116
    connector = SERVICE_CreateConnectorEx(service, fSERV_Any, info, 0);
 
117
    ConnNetInfo_Destroy(info);
 
118
 
 
119
    if (!connector)
 
120
        CORE_LOG(eLOG_Fatal, "Failed to create service connector");
 
121
 
 
122
    if (CONN_Create(connector, &conn) != eIO_Success)
 
123
        CORE_LOG(eLOG_Fatal, "Failed to create connection");
 
124
 
 
125
    timeout.sec  = 5;
 
126
    timeout.usec = 123456;
 
127
 
 
128
    CONN_SetTimeout(conn, eIO_ReadWrite, &timeout);
 
129
 
 
130
    if (CONN_Write(conn, obuf, strlen(obuf), &n) != eIO_Success ||
 
131
        n != strlen(obuf)) {
 
132
        CONN_Close(conn);
 
133
        CORE_LOG(eLOG_Fatal, "Error writing to connection");
 
134
    }
 
135
 
 
136
    if (CONN_Wait(conn, eIO_Read, &timeout) != eIO_Success) {
 
137
        CONN_Close(conn);
 
138
        CORE_LOG(eLOG_Fatal, "Error waiting for reading");
 
139
    }
 
140
 
 
141
    if (CONN_Read(conn, ibuf, n, &n, eIO_Persist) != eIO_Success) {
 
142
        CONN_Close(conn);
 
143
        CORE_LOG(n ? eLOG_Error : eLOG_Fatal, "Error reading from connection");
 
144
    }
 
145
 
 
146
    CORE_LOGF(eLOG_Note,
 
147
              ("%d bytes read from service (%s):\n%.*s",
 
148
               (int)n, CONN_GetType(conn), (int)n, ibuf));
 
149
    CONN_Close(conn);
 
150
 
 
151
#if 0
 
152
    CORE_LOG(eLOG_Note, "Trying ID1 service");
 
153
 
 
154
    info = ConnNetInfo_Create(service);
 
155
    connector = SERVICE_CreateConnectorEx("ID1", fSERV_Any, info);
 
156
    ConnNetInfo_Destroy(info);
 
157
 
 
158
    if (!connector)
 
159
        CORE_LOG(eLOG_Fatal, "Service ID1 not available");
 
160
 
 
161
    if (CONN_Create(connector, &conn) != eIO_Success)
 
162
        CORE_LOG(eLOG_Fatal, "Failed to create connection");
 
163
 
 
164
    if (CONN_Write(conn, "\xA4\x80\x02\x01\x02\x00\x00", 7, &n) !=
 
165
        eIO_Success || n != 7) {
 
166
        CONN_Close(conn);
 
167
        CORE_LOG(eLOG_Fatal, "Error writing to service ID1");
 
168
    }
 
169
 
 
170
    if (CONN_Read(conn, ibuf, sizeof(ibuf), &n, eIO_Plain) != eIO_Success) {
 
171
        CONN_Close(conn);
 
172
        CORE_LOG(eLOG_Fatal, "Error reading from service ID1");
 
173
    }
 
174
 
 
175
    CORE_LOGF(eLOG_Note, ("%d bytes read from service ID1", n));
 
176
    CONN_Close(conn);
 
177
#endif
 
178
 
 
179
    return 0/*okay*/;
 
180
}