cyphesis/tests/HttpCacheTest.cpp

172 lines
3.7 KiB
C++
Raw Permalink Normal View History

2010-07-30 15:38:50 +01:00
// Cyphesis Online RPG Server and AI Engine
// Copyright (C) 2010 Alistair Riddoch
//
// 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 2 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 Street, Fifth Floor, Boston, MA 02110-1301 USA
2011-02-15 09:30:46 +00:00
#ifdef NDEBUG
#undef NDEBUG
#endif
#ifndef DEBUG
#define DEBUG
#endif
2010-07-30 15:38:50 +01:00
#include "server/HttpCache.h"
#include "common/globals.h"
#include <varconf/config.h>
#include <cassert>
2010-07-30 16:10:56 +01:00
class TestHttpCache : public HttpCache
{
public:
void test_sendHeaders(std::ostream & io,
int status,
const std::string & type,
const std::string & msg) {
sendHeaders(io, status, type, msg);
}
void test_reportBadRequest(std::ostream & io,
int status,
const std::string & mesg) {
reportBadRequest(io, status, mesg);
}
};
2010-07-30 15:38:50 +01:00
int main()
{
global_conf = varconf::Config::inst();
2010-07-30 16:10:56 +01:00
{
HttpCache::instance();
HttpCache::del();
}
// No header, invalid
{
HttpCache *hc = HttpCache::instance();
hc->processQuery(std::cout, std::list<std::string>());
HttpCache::del();
}
// Bad request header
{
HttpCache *hc = HttpCache::instance();
std::list<std::string> headers;
headers.push_back("boo");
hc->processQuery(std::cout, headers);
HttpCache::del();
}
// Legacy HTTP (0.9??)
{
HttpCache *hc = HttpCache::instance();
std::list<std::string> headers;
headers.push_back("GET foo");
hc->processQuery(std::cout, headers);
HttpCache::del();
}
// HTTP (n.m??)
{
HttpCache *hc = HttpCache::instance();
std::list<std::string> headers;
headers.push_back("GET foo HTTP/1.0");
hc->processQuery(std::cout, headers);
HttpCache::del();
}
// HTTP get /config
{
HttpCache *hc = HttpCache::instance();
std::list<std::string> headers;
headers.push_back("GET /config HTTP/1.0");
hc->processQuery(std::cout, headers);
HttpCache::del();
}
// HTTP get /config with some config
{
HttpCache *hc = HttpCache::instance();
global_conf->setItem(instance, "bar", "value");
std::list<std::string> headers;
headers.push_back("GET /config HTTP/1.0");
hc->processQuery(std::cout, headers);
HttpCache::del();
}
// HTTP get /monitors
{
HttpCache *hc = HttpCache::instance();
std::list<std::string> headers;
headers.push_back("GET /monitors HTTP/1.0");
hc->processQuery(std::cout, headers);
HttpCache::del();
}
{
TestHttpCache hc;
hc.test_sendHeaders(std::cout, 200, "test/html", "OK");
}
{
TestHttpCache hc;
hc.test_reportBadRequest(std::cout, 200, "Bad request");
}
2010-07-30 15:38:50 +01:00
return 0;
}
// stubs
2015-04-09 14:50:45 +02:00
#include "stubs/common/stubMonitors.h"
2010-07-30 15:38:50 +01:00
2018-01-30 16:54:49 +01:00
varconf::Config * global_conf = nullptr;
2010-07-30 15:38:50 +01:00
std::string instance("test_instance");
namespace consts {
// Version of the software we are running
const char * version = "test_version";
}