~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): Noritada Kobayashi
  • Date: 2008-06-22 11:14:06 UTC
  • mfrom: (1.1.3 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080622111406-nd0er2lnkdpwqp16
Tags: 0.2.0-1
* New upstream version (Closes: #485025):
  - debian/copyright: Document that CuTest files are licensed under the
    zlib/libpng license.
  - debian/patches/*.diff: Refresh.
* Update Standards-Version to 3.8.0.
  - debian/control: Make binNMU-safe by using ${binary:Version} instead of
    ${Source-Version}.
  - debian/control: Add new Homepage field.
  - debian/copyright: Delete copy of /usr/share/common-licenses/Apache-2.0.
  - debian/README.source: New file explaining quilt.
* Update the debhelper compatibility level to 7.
  - debian/libserf-0-0-dev.install, debian/libserf-0-0.install:
    Do not begin with debian/tmp since it is assumed to be the source path.
* debian/control: Add new Vcs-Git, and Vcs-Browser fields.
* Install test programs as example ones for libserf-0-0-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2002-2007 Justin Erenkrantz and Greg Stein
 
2
 *
 
3
 * Licensed under the Apache License, Version 2.0 (the "License");
 
4
 * you may not use this file except in compliance with the License.
 
5
 * You may obtain a copy of the License at
 
6
 *
 
7
 *     http://www.apache.org/licenses/LICENSE-2.0
 
8
 *
 
9
 * Unless required by applicable law or agreed to in writing, software
 
10
 * distributed under the License is distributed on an "AS IS" BASIS,
 
11
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
12
 * See the License for the specific language governing permissions and
 
13
 * limitations under the License.
 
14
 */
 
15
 
 
16
#ifndef TEST_SERF_H
 
17
#define TEST_SERF_H
 
18
 
 
19
#include "CuTest.h"
 
20
 
 
21
#include <apr.h>
 
22
#include <apr_pools.h>
 
23
#include <apr_uri.h>
 
24
 
 
25
#include "serf.h"
 
26
 
 
27
/** These macros are provided by APR itself from version 1.3.
 
28
 * Definitions are provided here for when using older versions of APR.
 
29
 */
 
30
 
 
31
/** index into an apr_array_header_t */
 
32
#ifndef APR_ARRAY_IDX
 
33
#define APR_ARRAY_IDX(ary,i,type) (((type *)(ary)->elts)[i])
 
34
#endif
 
35
 
 
36
/** easier array-pushing syntax */
 
37
#ifndef APR_ARRAY_PUSH
 
38
#define APR_ARRAY_PUSH(ary,type) (*((type *)apr_array_push(ary)))
 
39
#endif
 
40
 
 
41
extern apr_pool_t *test_pool;
 
42
 
 
43
/* CuTest declarations */
 
44
CuSuite *getsuite(void);
 
45
 
 
46
CuSuite *test_context(void);
 
47
CuSuite *test_buckets(void);
 
48
CuSuite *test_ssl(void);
 
49
 
 
50
/* Test setup declarations */
 
51
 
 
52
#define CRLF "\r\n"
 
53
 
 
54
#define CHUNCKED_REQUEST(len, body)\
 
55
        "GET / HTTP/1.1" CRLF\
 
56
        "Transfer-Encoding: chunked" CRLF\
 
57
        CRLF\
 
58
        #len CRLF\
 
59
        body CRLF\
 
60
        "0" CRLF\
 
61
        CRLF
 
62
 
 
63
#define CHUNKED_RESPONSE(len, body)\
 
64
        "HTTP/1.1 200 OK" CRLF\
 
65
        "Transfer-Encoding: chunked" CRLF\
 
66
        CRLF\
 
67
        #len CRLF\
 
68
        body CRLF\
 
69
        "0" CRLF\
 
70
        CRLF
 
71
 
 
72
#define CHUNKED_EMPTY_RESPONSE\
 
73
        "HTTP/1.1 200 OK" CRLF\
 
74
        "Transfer-Encoding: chunked" CRLF\
 
75
        CRLF\
 
76
        "0" CRLF\
 
77
        CRLF
 
78
 
 
79
typedef struct
 
80
{
 
81
    enum {
 
82
        SERVER_RECV,
 
83
        SERVER_SEND,
 
84
        SERVER_KILL_CONNECTION
 
85
    } kind;
 
86
 
 
87
    const char *text;
 
88
} test_server_action_t;
 
89
 
 
90
typedef struct {
 
91
    /* Pool for resource allocation. */
 
92
    apr_pool_t *pool;
 
93
 
 
94
    serf_context_t *context;
 
95
    serf_connection_t *connection;
 
96
    serf_bucket_alloc_t *bkt_alloc;
 
97
    apr_int32_t options;
 
98
 
 
99
    /* Array of actions which server will replay when client connected. */
 
100
    test_server_action_t *action_list;
 
101
    /* Size of action_list array. */
 
102
    apr_size_t action_count;
 
103
    /* Index of current action. */
 
104
    apr_size_t cur_action;
 
105
 
 
106
    /* Position in action buffer. */
 
107
    apr_size_t action_buf_pos;
 
108
 
 
109
    /* Address for server binding. */
 
110
    apr_sockaddr_t *serv_addr;
 
111
    apr_socket_t *serv_sock;
 
112
 
 
113
    /* Accepted client socket. NULL if there is no client socket. */
 
114
    apr_socket_t *client_sock;
 
115
 
 
116
    /* An extra baton which can be freely used by tests. */
 
117
    void *user_baton;
 
118
 
 
119
} test_baton_t;
 
120
 
 
121
#define TEST_SERVER_DUMP 1
 
122
 
 
123
/* Default port for our test server. */
 
124
#define SERV_PORT 12345
 
125
#define SERV_PORT_STR "12345"
 
126
 
 
127
apr_status_t test_server_create(test_baton_t **tb,
 
128
                                test_server_action_t *action_list,
 
129
                                apr_size_t action_count,
 
130
                                apr_int32_t options,
 
131
                                const char *host_url,
 
132
                                apr_sockaddr_t *address,
 
133
                                serf_connection_setup_t conn_setup,
 
134
                                apr_pool_t *pool);
 
135
 
 
136
apr_status_t test_server_run(test_baton_t *tb,
 
137
                             apr_short_interval_time_t duration,
 
138
                             apr_pool_t *pool);
 
139
 
 
140
apr_status_t test_server_destroy(test_baton_t *tb, apr_pool_t *pool);
 
141
 
 
142
#ifndef APR_VERSION_AT_LEAST /* Introduced in APR 1.3.0 */
 
143
#define APR_VERSION_AT_LEAST(major,minor,patch)                  \
 
144
(((major) < APR_MAJOR_VERSION)                                       \
 
145
 || ((major) == APR_MAJOR_VERSION && (minor) < APR_MINOR_VERSION)    \
 
146
 || ((major) == APR_MAJOR_VERSION && (minor) == APR_MINOR_VERSION && \
 
147
     (patch) <= APR_PATCH_VERSION))
 
148
#endif /* APR_VERSION_AT_LEAST */
 
149
 
 
150
#endif /* TEST_SERF_H */