⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_http.cpp

📁 gnash 在pc和嵌入式下开发需要的源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
 // //   Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.// // This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 3 of the License, or// (at your option) any later version.// // This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.// // You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA#ifdef HAVE_CONFIG_H#include "gnashconfig.h"#endif#ifdef HAVE_DEJAGNU_H#include <string>#include <unistd.h>#ifdef HAVE_GETOPT_H# include <getopt.h>#endif#ifndef __GNUC__extern int optind, getopt(int, char *const *, const char *);#endif#include <sys/types.h>#include <iostream>#include <string>#include <vector>#include <regex.h>#include "log.h"#include "http.h"#include "dejagnu.h"using namespace cygnal;using namespace gnash;using namespace std;static void usage (void);static TestState runtest;LogFile& dbglogfile = LogFile::getDefaultInstance();intmain(int argc, char *argv[]){    int c;        while ((c = getopt (argc, argv, "hdvsm:")) != -1) {        switch (c) {          case 'h':              usage ();              break;                        case 'v':              dbglogfile.setVerbosity();              break;                        default:              usage ();              break;        }    }    HTTP http;    http.clearHeader();    http.formatDate();//    cerr << "FIXME: " << http.getHeader() << endl;    regex_t regex_pat;    // Check the Date field    // The date should look something like this:    //     Date: Mon, 10 Dec 2007  GMT    regcomp (&regex_pat, "Date: [A-Z][a-z]*, [0-9]* [A-Z][a-z]* [0-9]* [0-9:]* *GMT$",             REG_NOSUB|REG_NEWLINE);    if (regexec (&regex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {        runtest.fail ("HTTP::formatDate()");        cerr << http.getHeader().c_str() << endl;    } else {        runtest.pass ("HTTP::formatDate()");    }    regfree(&regex_pat);    // Check the Content-Length field    http.clearHeader();    http.formatContentLength(12345);//    cerr << "FIXME: " << http.getHeader() << endl;    regcomp (&regex_pat, "Content-Length: [0-9]*$",             REG_NOSUB|REG_NEWLINE);    if (regexec (&regex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {        runtest.fail ("HTTP::formatContentLength()");    } else {        runtest.pass ("HTTP::formatContentLength()");    }    regfree(&regex_pat);    // Check the Connection field//     bool formatConnection(const char *data);    http.clearHeader();    const char *data = "Keep-Alive";    http.formatConnection(data);//    cerr << "FIXME: " << http.getHeader() << endl;    regcomp (&regex_pat, "Connection: [A-za-z-]*",             REG_NOSUB|REG_NEWLINE);    if (regexec (&regex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {        runtest.fail ("HTTP::formatConnection()");    } else {        runtest.pass ("HTTP::formatConnection()");    }    regfree(&regex_pat);    // Check the Server field    http.clearHeader();    http.formatServer();//    cerr << "FIXME: " << http.getHeader() << endl;    regcomp (&regex_pat, "Server: Cygnal (GNU/Linux)$",             REG_NOSUB|REG_NEWLINE);    if (regexec (&regex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {        runtest.fail ("HTTP::formatServer()");    } else {        runtest.pass ("HTTP::formatServer()");    }    regfree(&regex_pat);    // Check the Host field//     bool formatHost(const char *data);    http.clearHeader();    data = "localhost:4080";    http.formatHost(data);//    cerr << "FIXME: " << http.getHeader() << endl;    regcomp (&regex_pat, "Host: [A-za-z-]*:[0-9]*$",             REG_NOSUB|REG_NEWLINE);    if (regexec (&regex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {        runtest.fail ("HTTP::formatHost()");    } else {        runtest.pass ("HTTP::formatHost()");    }    regfree(&regex_pat);// Check the Language field//     bool formatLanguage(const char *data);    http.clearHeader();    data = "en-US,en;q=0.9";    http.formatLanguage(data);//    cerr << "FIXME: " << http.getHeader() << endl;    regcomp (&regex_pat, "Accept-Language: en-US,en;q=0.9$",             REG_NOSUB|REG_NEWLINE);    if (regexec (&regex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {        runtest.fail ("HTTP::formatLanguage()");    } else {        runtest.pass ("HTTP::formatLanguage()");    }    regfree(&regex_pat);//     bool formatCharset(const char *data);// Accept-Charset: iso-8859-1, utf-8, utf-16, *;q=0.1\r    http.clearHeader();    data = "iso-8859-1, utf-8, utf-16, *;q=0.1";    http.formatCharset(data);//    cerr << "FIXME: " << http.getHeader() << endl;    regcomp (&regex_pat, "Accept-Charset: iso-8859-1.*$",             REG_NOSUB|REG_NEWLINE);    if (regexec (&regex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {        runtest.fail ("HTTP::formatCharset()");    } else {        runtest.pass ("HTTP::formatCharset()");    }    regfree(&regex_pat);        //     bool formatEncoding(const char *data);    http.clearHeader();    data = "deflate, gzip, x-gzip, identity, *;q=0";    http.formatEncoding(data);//    cerr << "FIXME: " << http.getHeader() << endl;    regcomp (&regex_pat, "Accept-Encoding: deflate, gzip.*$",             REG_NOSUB|REG_NEWLINE);    if (regexec (&regex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {        runtest.fail ("HTTP::formatEncoding()");    } else {        runtest.pass ("HTTP::formatEncoding()");    }    regfree(&regex_pat);                //     bool formatTE(const char *data);    http.clearHeader();    data = "deflate, gzip, chunked, identity, trailers";    http.formatTE(data);//    cerr << "FIXME: " << http.getHeader() << endl;    regcomp (&regex_pat, "TE: deflate, gzip,.*$",             REG_NOSUB|REG_NEWLINE);    if (regexec (&regex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {        runtest.fail ("HTTP::formatTE()");    } else {        runtest.pass ("HTTP::formatTE()");    }    regfree(&regex_pat);//     bool formatAgent(const char *data);    http.clearHeader();    data = "Gnash 0.8.1-cvs (X11; Linux i686; U; en)";    http.formatAgent(data);//    cerr << "FIXME: " << http.getHeader() << endl;    regcomp (&regex_pat, "User-Agent: Gnash 0.8.1-cvs.*$",             REG_NOSUB|REG_NEWLINE);    if (regexec (&regex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {        runtest.fail ("HTTP::formatAgent()");    } else {        runtest.pass ("HTTP::formatAgent()");    }    regfree(&regex_pat);    // Check the Content Type field. First we check with a    // specified field, then next to see if the default works.//     bool formatContentType();    http.clearHeader();    http.formatContentType(HTTP::SWF);//    cerr << "FIXME: " << http.getHeader() << endl;    regcomp (&regex_pat, "Content-Type: application/x-shockwave-flash.*$",             REG_NOSUB|REG_NEWLINE);    if (regexec (&regex_pat, http.getHeader().c_str(), 0, (regmatch_t *)0, 0)) {        runtest.fail ("HTTP::formatContentType(type)");    } else {        runtest.pass ("HTTP::formatContentType(type)");    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -