~ubuntu-branches/ubuntu/trusty/serf/trusty-security

« back to all changes in this revision

Viewing changes to test/test_serf.h

  • Committer: Bazaar Package Importer
  • Author(s): Peter Samuelson
  • Date: 2011-06-27 18:09:28 UTC
  • mfrom: (1.2.5 upstream)
  • mto: (3.3.1 sid)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: james.westby@ubuntu.com-20110627180928-ybwzd3hmx82nu3ir
Tags: 1.0.0~0+svn1514-1
* New upstream snapshot.
  - patches/abi-0.x: Remove as obsolete.
  - patches/kqueue: Forward-port.
  - Bump ABI: libserf0.7{,-dbg} -> libserf1{,-dbg}
  - patches/ip6-localhost: New patch: temporary (I hope) workaround for
    IPv4 / IPv6 confusion in testsuite.
* Implement Multi-Arch: same.
* libserf-dev Conflicts: libserf-0-0-dev, not Breaks.  Thanks, lintian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <apr_uri.h>
24
24
 
25
25
#include "serf.h"
 
26
#include "server/test_server.h"
26
27
 
27
28
/** These macros are provided by APR itself from version 1.3.
28
29
 * Definitions are provided here for when using older versions of APR.
38
39
#define APR_ARRAY_PUSH(ary,type) (*((type *)apr_array_push(ary)))
39
40
#endif
40
41
 
41
 
extern apr_pool_t *test_pool;
42
 
 
43
42
/* CuTest declarations */
44
43
CuSuite *getsuite(void);
45
44
 
51
50
 
52
51
#define CRLF "\r\n"
53
52
 
54
 
#define CHUNCKED_REQUEST(len, body)\
 
53
#define CHUNKED_REQUEST(len, body)\
55
54
        "GET / HTTP/1.1" CRLF\
 
55
        "Host: localhost:12345" CRLF\
56
56
        "Transfer-Encoding: chunked" CRLF\
57
57
        CRLF\
58
58
        #len CRLF\
76
76
        "0" CRLF\
77
77
        CRLF
78
78
 
79
 
typedef struct
80
 
{
81
 
    enum {
82
 
        SERVER_RECV,
83
 
        SERVER_SEND,
84
 
        SERVER_RESPOND,
85
 
        SERVER_IGNORE_AND_KILL_CONNECTION,
86
 
        SERVER_KILL_CONNECTION
87
 
    } kind;
88
 
 
89
 
    const char *text;
90
 
} test_server_action_t;
91
 
 
92
 
typedef struct
93
 
{
94
 
    const char *text;
95
 
} test_server_message_t;
96
 
 
97
79
typedef struct {
98
80
    /* Pool for resource allocation. */
99
81
    apr_pool_t *pool;
101
83
    serf_context_t *context;
102
84
    serf_connection_t *connection;
103
85
    serf_bucket_alloc_t *bkt_alloc;
104
 
    apr_int32_t options;
105
 
 
106
 
    /* Array of actions which server will replay when client connected. */
107
 
    test_server_action_t *action_list;
108
 
    /* Size of action_list array. */
109
 
    apr_size_t action_count;
110
 
    /* Index of current action. */
111
 
    apr_size_t cur_action;
112
 
 
113
 
    /* Array of messages the server will receive from the client. */
114
 
    test_server_message_t *message_list;
115
 
    /* Size of message_list array. */
116
 
    apr_size_t message_count;
117
 
    /* Index of current message. */
118
 
    apr_size_t cur_message;
119
 
 
120
 
    /* Number of messages received that the server didn't respond to yet. */
121
 
    apr_size_t outstanding_responses;
122
 
 
123
 
    /* Position in message buffer (incoming messages being read). */
124
 
    apr_size_t message_buf_pos;
125
 
 
126
 
    /* Position in action buffer. (outgoing messages being sent). */
127
 
    apr_size_t action_buf_pos;
128
 
 
129
 
    /* Address for server binding. */
 
86
 
 
87
    serv_ctx_t *serv_ctx;
130
88
    apr_sockaddr_t *serv_addr;
131
 
    apr_socket_t *serv_sock;
132
89
 
133
 
    /* Accepted client socket. NULL if there is no client socket. */
134
 
    apr_socket_t *client_sock;
 
90
    serv_ctx_t *proxy_ctx;
 
91
    apr_sockaddr_t *proxy_addr;
135
92
 
136
93
    /* An extra baton which can be freely used by tests. */
137
94
    void *user_baton;
138
95
 
139
96
} test_baton_t;
140
97
 
141
 
#define TEST_SERVER_DUMP 1
142
 
 
143
 
/* Default port for our test server. */
144
 
#define SERV_PORT 12345
145
 
#define SERV_PORT_STR "12345"
146
 
 
147
 
apr_status_t test_server_create(test_baton_t **tb,
148
 
                                test_server_message_t *message_list,
149
 
                                apr_size_t message_count,
150
 
                                test_server_action_t *action_list,
151
 
                                apr_size_t action_count,
152
 
                                apr_int32_t options,
153
 
                                const char *host_url,
154
 
                                apr_sockaddr_t *address,
155
 
                                serf_connection_setup_t conn_setup,
156
 
                                apr_pool_t *pool);
157
 
 
158
 
apr_status_t test_server_run(test_baton_t *tb,
159
 
                             apr_short_interval_time_t duration,
160
 
                             apr_pool_t *pool);
161
 
 
162
 
apr_status_t test_server_destroy(test_baton_t *tb, apr_pool_t *pool);
163
 
 
164
 
#ifndef APR_VERSION_AT_LEAST /* Introduced in APR 1.3.0 */
165
 
#define APR_VERSION_AT_LEAST(major,minor,patch)                  \
166
 
(((major) < APR_MAJOR_VERSION)                                       \
167
 
 || ((major) == APR_MAJOR_VERSION && (minor) < APR_MINOR_VERSION)    \
168
 
 || ((major) == APR_MAJOR_VERSION && (minor) == APR_MINOR_VERSION && \
169
 
     (patch) <= APR_PATCH_VERSION))
170
 
#endif /* APR_VERSION_AT_LEAST */
 
98
apr_status_t test_server_setup(test_baton_t **tb_p,
 
99
                               test_server_message_t *message_list,
 
100
                               apr_size_t message_count,
 
101
                               test_server_action_t *action_list,
 
102
                               apr_size_t action_count,
 
103
                               apr_int32_t options,
 
104
                               serf_connection_setup_t conn_setup,
 
105
                               apr_pool_t *pool);
 
106
 
 
107
apr_status_t test_server_proxy_setup(
 
108
                 test_baton_t **tb_p,
 
109
                 test_server_message_t *serv_message_list,
 
110
                 apr_size_t serv_message_count,
 
111
                 test_server_action_t *serv_action_list,
 
112
                 apr_size_t serv_action_count,
 
113
                 test_server_message_t *proxy_message_list,
 
114
                 apr_size_t proxy_message_count,
 
115
                 test_server_action_t *proxy_action_list,
 
116
                 apr_size_t proxy_action_count,
 
117
                 apr_int32_t options,
 
118
                 serf_connection_setup_t conn_setup,
 
119
                 apr_pool_t *pool);
 
120
 
 
121
apr_status_t test_server_teardown(test_baton_t *tb, apr_pool_t *pool);
 
122
 
 
123
apr_pool_t *test_setup();
 
124
void test_teardown(apr_pool_t *test_pool);
171
125
 
172
126
#endif /* TEST_SERF_H */