2
// Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4
// This program is free software; you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation; either version 3 of the License, or
7
// (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
#include "gnashconfig.h"
32
extern int optind, getopt(int, char *const *, const char *);
35
#include <sys/types.h>
45
using namespace cygnal;
46
using namespace gnash;
49
static void usage (void);
51
static TestState runtest;
53
LogFile& dbglogfile = LogFile::getDefaultInstance();
56
main(int argc, char *argv[])
60
while ((c = getopt (argc, argv, "hdvsm:")) != -1) {
67
dbglogfile.setVerbosity();
80
// cerr << "FIXME: " << http.getHeader() << endl;
84
// Check the Date field
85
// The date should look something like this:
86
// Date: Mon, 10 Dec 2007 GMT
87
regcomp (®ex_pat, "Date: [A-Z][a-z]*, [0-9]* [A-Z][a-z]* [0-9]* [0-9:]* *GMT$",
88
REG_NOSUB|REG_NEWLINE);
89
if (regexec (®ex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {
90
runtest.fail ("HTTP::formatDate()");
91
cerr << http.getHeader().c_str() << endl;
93
runtest.pass ("HTTP::formatDate()");
97
// Check the Content-Length field
99
http.formatContentLength(12345);
100
// cerr << "FIXME: " << http.getHeader() << endl;
101
regcomp (®ex_pat, "Content-Length: [0-9]*$",
102
REG_NOSUB|REG_NEWLINE);
103
if (regexec (®ex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {
104
runtest.fail ("HTTP::formatContentLength()");
106
runtest.pass ("HTTP::formatContentLength()");
111
// Check the Connection field
112
// bool formatConnection(const char *data);
114
const char *data = "Keep-Alive";
115
http.formatConnection(data);
116
// cerr << "FIXME: " << http.getHeader() << endl;
117
regcomp (®ex_pat, "Connection: [A-za-z-]*",
118
REG_NOSUB|REG_NEWLINE);
119
if (regexec (®ex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {
120
runtest.fail ("HTTP::formatConnection()");
122
runtest.pass ("HTTP::formatConnection()");
126
// Check the Server field
129
// cerr << "FIXME: " << http.getHeader() << endl;
130
regcomp (®ex_pat, "Server: Cygnal (GNU/Linux)$",
131
REG_NOSUB|REG_NEWLINE);
132
if (regexec (®ex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {
133
runtest.fail ("HTTP::formatServer()");
135
runtest.pass ("HTTP::formatServer()");
139
// Check the Host field
140
// bool formatHost(const char *data);
142
data = "localhost:4080";
143
http.formatHost(data);
144
// cerr << "FIXME: " << http.getHeader() << endl;
145
regcomp (®ex_pat, "Host: [A-za-z-]*:[0-9]*$",
146
REG_NOSUB|REG_NEWLINE);
147
if (regexec (®ex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {
148
runtest.fail ("HTTP::formatHost()");
150
runtest.pass ("HTTP::formatHost()");
154
// Check the Language field
155
// bool formatLanguage(const char *data);
157
data = "en-US,en;q=0.9";
158
http.formatLanguage(data);
159
// cerr << "FIXME: " << http.getHeader() << endl;
160
regcomp (®ex_pat, "Accept-Language: en-US,en;q=0.9$",
161
REG_NOSUB|REG_NEWLINE);
162
if (regexec (®ex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {
163
runtest.fail ("HTTP::formatLanguage()");
165
runtest.pass ("HTTP::formatLanguage()");
169
// bool formatCharset(const char *data);
170
// Accept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r
172
data = "iso-8859-1, utf-8, utf-16, *;q=0.1";
173
http.formatCharset(data);
174
// cerr << "FIXME: " << http.getHeader() << endl;
175
regcomp (®ex_pat, "Accept-Charset: iso-8859-1.*$",
176
REG_NOSUB|REG_NEWLINE);
177
if (regexec (®ex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {
178
runtest.fail ("HTTP::formatCharset()");
180
runtest.pass ("HTTP::formatCharset()");
184
// bool formatEncoding(const char *data);
186
data = "deflate, gzip, x-gzip, identity, *;q=0";
187
http.formatEncoding(data);
188
// cerr << "FIXME: " << http.getHeader() << endl;
189
regcomp (®ex_pat, "Accept-Encoding: deflate, gzip.*$",
190
REG_NOSUB|REG_NEWLINE);
191
if (regexec (®ex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {
192
runtest.fail ("HTTP::formatEncoding()");
194
runtest.pass ("HTTP::formatEncoding()");
199
// bool formatTE(const char *data);
201
data = "deflate, gzip, chunked, identity, trailers";
203
// cerr << "FIXME: " << http.getHeader() << endl;
204
regcomp (®ex_pat, "TE: deflate, gzip,.*$",
205
REG_NOSUB|REG_NEWLINE);
206
if (regexec (®ex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {
207
runtest.fail ("HTTP::formatTE()");
209
runtest.pass ("HTTP::formatTE()");
213
// bool formatAgent(const char *data);
215
data = "Gnash 0.8.1-cvs (X11; Linux i686; U; en)";
216
http.formatAgent(data);
217
// cerr << "FIXME: " << http.getHeader() << endl;
218
regcomp (®ex_pat, "User-Agent: Gnash 0.8.1-cvs.*$",
219
REG_NOSUB|REG_NEWLINE);
220
if (regexec (®ex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {
221
runtest.fail ("HTTP::formatAgent()");
223
runtest.pass ("HTTP::formatAgent()");
227
// Check the Content Type field. First we check with a
228
// specified field, then next to see if the default works.
229
// bool formatContentType();
231
http.formatContentType(HTTP::SWF);
232
// cerr << "FIXME: " << http.getHeader() << endl;
233
regcomp (®ex_pat, "Content-Type: application/x-shockwave-flash.*$",
234
REG_NOSUB|REG_NEWLINE);
235
if (regexec (®ex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {
236
runtest.fail ("HTTP::formatContentType(type)");
238
runtest.pass ("HTTP::formatContentType(type)");
243
http.formatContentType();
244
// cerr << "FIXME: " << http.getHeader() << endl;
245
regcomp (®ex_pat, "Content-Type: text/html.*$",
246
REG_NOSUB|REG_NEWLINE);
247
if (regexec (®ex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {
248
runtest.fail ("HTTP::formatContentType()");
250
runtest.pass ("HTTP::formatContenType()");
254
// bool formatReferer(const char *data);
256
data = "http://localhost/software/gnash/tests/index.html";
257
http.formatReferer(data);
258
// cerr << "FIXME: " << http.getHeader() << endl;
259
regcomp (®ex_pat, "Referer: http://localhost.*index.html.*$",
260
REG_NOSUB|REG_NEWLINE);
261
if (regexec (®ex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {
262
runtest.fail ("HTTP::formatReferer()");
264
runtest.pass ("HTTP::formatReferer()");
268
// Check formatHeader()
270
http.formatHeader(RTMP);
271
// cerr << "FIXME: " << http.getHeader() << endl;
272
regcomp (®ex_pat, "HTTP/1.1 200 OK.*Date:.*Connection:.*-Length.*-Type:.*$",
273
REG_NOSUB); // note that we do want to look for NL
274
if (regexec (®ex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {
275
runtest.fail ("HTTP::formatHeader(port)");
277
runtest.pass ("HTTP::formatheader(port)");
281
// Check the Server field
283
http.formatErrorResponse(HTTP::NOT_FOUND);
284
// cerr << "FIXME: " << http.getHeader() << endl;
285
// cerr << "FIXME: " << http.getBody() << endl;
286
regcomp (®ex_pat, "Date:.*Server:.*Content-Length:.*Connection:.*Content-Type:.*$",
287
REG_NOSUB); // note that we do want to look for NL
288
if (regexec (®ex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {
289
runtest.fail ("HTTP::formatErrorResponse(header)");
291
runtest.pass ("HTTP::formatErrorResponse(header)");
294
regcomp (®ex_pat, "DOCTYPE.*<title>404 Not Found</title>.*$",
295
REG_NOSUB); // note that we do want to look for NL
296
if (regexec (®ex_pat, http.getBody().c_str(), 0, (regmatch_t *)0, 0)) {
297
runtest.fail ("HTTP::formatErrorResponse(body)");
299
runtest.pass ("HTTP::formatErrorResponse(body)");
304
// Decoding tests for HTTP
307
const char *buffer = "GET /software/gnash/tests/flvplayer.swf?file=http://localhost/software/gnash/tests/Ouray_Ice_Festival_Climbing_Competition.flv HTTP/1.1\r\n"
308
"User-Agent: Gnash/0.8.1-cvs (X11; Linux i686; U; en)\r\n"
309
"Host: localhost:4080\r\n"
310
"Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\n"
311
"Accept-Language: en-US,en;q=0.9\r\n"
312
"Accept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r\n"
313
"Accept-Encoding: deflate, gzip, x-gzip, identity, *;q=0\r\n"
314
"If-Modified-Since: Mon, 10 Dec 2007 02:26:31 GMT\r\n"
315
"If-None-Match: \"4cc434-e266-52ff63c0\"\r\n"
316
"Connection: Keep-Alive, TE\r\n"
317
"Referer: http://localhost/software/gnash/tests/index.html\r\n"
318
"TE: deflate, gzip, chunked, identity, trailers\r\n"
321
// GET /software/gnash/tests/ HTTP/1.1
322
// Host: localhost:4080
323
// User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.5) Gecko/20070718 Fedora/2.0.0.5-1.fc7 Firefox/2.0.0.5
324
// Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
325
// Accept-Language: en-us,en;q=0.5
326
// Accept-Encoding: gzip,deflate
327
// Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
329
// Connection: keep-alive
331
// User Agent: Lynx/2.8.6rel.2 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.8b
333
// Some browsers have a different synatax, of course, to keep things
335
const char *buffer2 = "GET /software/gnash/tests/flvplayer.swf?file=http://localhost/software/gnash/tests/Ouray_Ice_Festival_Climbing_Competition.flv HTTP/1.1\r\n"
336
"Content-Language: en-US,en;q=0.9\r\n"
337
"Content-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r\n"
338
"Content-Encoding: deflate, gzip, x-gzip, identity, *;q=0\r\n";
339
// http.extractMethod(buffer);
341
result = http.extractReferer(buffer);
342
if (result == "http://localhost/software/gnash/tests/index.html") {
343
runtest.fail ("HTTP::extractReferer()");
345
runtest.pass ("HTTP::extractReferer()");
347
result = http.extractHost(buffer);
348
if (result == "localhost:4080") {
349
runtest.fail ("HTTP::extractHost()");
351
runtest.pass ("HTTP::extractHost()");
354
result = http.extractAgent(buffer);
355
if (result == "Gnash/0.8.1-cvs (X11; Linux i686; U; en)") {
356
runtest.fail ("HTTP::extractAgent()");
358
runtest.pass ("HTTP::extractAgent()");
362
count = http.extractLanguage(buffer);
363
std::vector<std::string> language = http.getLanguage();
365
(language[0] == "en-US") &&
366
(language[1] == "en")) {
367
runtest.fail ("HTTP::extractLanguage(Accept-)");
369
runtest.pass ("HTTP::extractLanguage(Accept-)");
371
count = http.extractLanguage(buffer2);
372
language = http.getLanguage();
374
(language[0] == "en-US") &&
375
(language[1] == "en")) {
376
runtest.fail ("HTTP::extractLanguage(Content-)");
378
runtest.pass ("HTTP::extractLanguage(Content-)");
381
result = http.extractCharset(buffer);
382
std::vector<std::string> charsets = http.getCharset();
384
(charsets[0] == "iso-8859-1") &&
385
(charsets[1] == "utf-8") &&
386
(charsets[2] == "utf-16")) {
387
runtest.fail ("HTTP::extractCharset(Accept-)");
389
runtest.pass ("HTTP::extractCharset(Accept-)");
391
count = http.extractCharset(buffer2);
392
charsets = http.getCharset();
394
(charsets[0] == "iso-8859-1") &&
395
(charsets[1] == "utf-8") &&
396
(charsets[2] == "utf-16")) {
397
runtest.fail ("HTTP::extractCharset(Content-)");
399
runtest.pass ("HTTP::extractCharset(Content-)");
402
count = http.extractConnection(buffer);
403
std::vector<std::string> connections = http.getConnection();
405
(connections[0] == "Keep-Alive") &&
406
(connections[1] == "TE")) {
407
runtest.pass ("HTTP::extractConnection()");
409
runtest.fail ("HTTP::extractConnection()");
412
count = http.extractEncoding(buffer);
413
std::vector<std::string> encoding = http.getEncoding();
415
(encoding[0] == "deflate") &&
416
(encoding[1] == "gzip") &&
417
(encoding[2] == "chunked") &&
418
(encoding[3] == "identity")) {
419
runtest.fail ("HTTP::extractEncoding(Accept-)");
421
runtest.pass ("HTTP::extractEncoding(Accept-)");
424
count = http.extractTE(buffer);
425
std::vector<std::string> te = http.getTE();
427
(te[0] == "deflate") &&
429
(te[2] == "chunked") &&
430
(te[3] == "identity") &&
431
(te[4] == "trailers")) {
432
runtest.pass ("HTTP::extractTE()");
434
runtest.fail ("HTTP::extractTE()");
437
// http.formatHeader(666, RTMP);
438
// http.formatRequest("http://localhost:4080", HTTP::GET);
440
// bool formatMethod(const char *data);
443
// void *out = amf_obj.encodeNumber(*num);
445
// if (memcmp(out, buf, 9) == 0) {
446
// runtest.pass("Encoded AMF Number");
448
// runtest.fail("Encoded AMF Number");
454
if (dbglogfile.getVerbosity() > 0) {
461
cerr << "This program tests HTTP protocol support." << endl;
462
cerr << "Usage: test_http [hv]" << endl;
463
cerr << "-h\tHelp" << endl;
464
cerr << "-v\tVerbose" << endl;
468
#else // no DejaGnu support
471
main(int /*argc*/, char /* *argv[]*/)