~ubuntu-branches/ubuntu/maverick/libtorrent-rasterbar/maverick

« back to all changes in this revision

Viewing changes to test/test_http_connection.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Sauthier
  • Date: 2010-08-10 12:59:37 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810125937-jbcmmf17y8yo9hgz
Tags: 0.15.0-0ubuntu1
* New upstream version.
* debian/patches/100_fix_html_docs.patch: refreshed.
* debian/control: bump up standards-version to 3.9.1 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
{
67
67
        ++connect_handler_called;
68
68
        TEST_CHECK(c.socket().is_open());
69
 
        std::cerr << "connected to: " << c.socket().remote_endpoint() << std::endl;
70
 
        TEST_CHECK(c.socket().remote_endpoint().address() == address::from_string("127.0.0.1"));
 
69
        error_code ec;
 
70
        std::cerr << "connected to: " << c.socket().remote_endpoint(ec) << std::endl;
 
71
        TEST_CHECK(c.socket().remote_endpoint(ec).address() == address::from_string("127.0.0.1", ec));
71
72
}
72
73
 
73
74
void http_handler(error_code const& ec, http_parser const& parser
104
105
 
105
106
        std::cerr << " ===== TESTING: " << url << " =====" << std::endl;
106
107
 
 
108
        std::cerr << " expecting: size: " << size
 
109
                << " status: " << status
 
110
                << " connected: " << connected
 
111
                << " error: " << (ec?ec->message():"no error") << std::endl;
 
112
 
107
113
        boost::shared_ptr<http_connection> h(new http_connection(ios, cq
108
114
                , &::http_handler, true, &::http_connect_handler));
109
115
        h->get(url, seconds(1), 0, &ps);
110
116
        ios.reset();
111
 
        ios.run();
 
117
        error_code e;
 
118
        ios.run(e);
112
119
 
113
120
        std::cerr << "connect_handler_called: " << connect_handler_called << std::endl;
114
121
        std::cerr << "handler_called: " << handler_called << std::endl;
122
129
        TEST_CHECK(http_status == status || status == -1);
123
130
}
124
131
 
125
 
void run_suite(std::string const& protocol, proxy_settings const& ps)
 
132
void run_suite(std::string const& protocol, proxy_settings const& ps, int port)
126
133
{
127
134
        if (ps.type != proxy_settings::none)
128
135
        {
137
144
        // this requires the hosts file to be modified
138
145
//      run_test(protocol + "://test.dns.ts:8001/test_file", 3216, 200, 1, error_code(), ps);
139
146
 
140
 
        run_test(protocol + "://127.0.0.1:8001/relative/redirect", 3216, 200, 2, error_code(), ps);
141
 
        run_test(protocol + "://127.0.0.1:8001/redirect", 3216, 200, 2, error_code(), ps);
142
 
        run_test(protocol + "://127.0.0.1:8001/infinite_redirect", 0, 301, 6, error_code(), ps);
143
 
        run_test(protocol + "://127.0.0.1:8001/test_file", 3216, 200, 1, error_code(), ps);
144
 
        run_test(protocol + "://127.0.0.1:8001/test_file.gz", 3216, 200, 1, error_code(), ps);
145
 
        run_test(protocol + "://127.0.0.1:8001/non-existing-file", -1, 404, 1, err(), ps);
 
147
        char url[256];
 
148
        snprintf(url, sizeof(url), "%s://127.0.0.1:%d/", protocol.c_str(), port);
 
149
        std::string url_base(url);
 
150
 
 
151
        run_test(url_base + "relative/redirect", 3216, 200, 2, error_code(), ps);
 
152
        run_test(url_base + "redirect", 3216, 200, 2, error_code(), ps);
 
153
        run_test(url_base + "infinite_redirect", 0, 301, 6, error_code(), ps);
 
154
        run_test(url_base + "test_file", 3216, 200, 1, error_code(), ps);
 
155
        run_test(url_base + "test_file.gz", 3216, 200, 1, error_code(), ps);
 
156
        run_test(url_base + "non-existing-file", -1, 404, 1, err(), ps);
146
157
        // if we're going through an http proxy, we won't get the same error as if the hostname
147
158
        // resolution failed
148
159
        if ((ps.type == proxy_settings::http || ps.type == proxy_settings::http_pw) && protocol != "https")
170
181
        ps.username = "testuser";
171
182
        ps.password = "testpass";
172
183
        
173
 
        start_web_server(8001);
 
184
        int port = start_web_server();
174
185
        for (int i = 0; i < 5; ++i)
175
186
        {
176
187
                ps.type = (proxy_settings::proxy_type)i;
177
 
                run_suite("http", ps);
 
188
                run_suite("http", ps, port);
178
189
        }
179
 
        stop_web_server(8001);
 
190
        stop_web_server();
180
191
 
181
192
#ifdef TORRENT_USE_OPENSSL
182
 
        start_web_server(8001, true);
 
193
        port = start_web_server(true);
183
194
        for (int i = 0; i < 5; ++i)
184
195
        {
185
196
                ps.type = (proxy_settings::proxy_type)i;
186
 
                run_suite("https", ps);
 
197
                run_suite("https", ps, port);
187
198
        }
188
 
        stop_web_server(8001);
 
199
        stop_web_server();
189
200
#endif
190
201
 
191
202
        std::remove("test_file");