This commit is contained in:
Andrey Potapov 2019-02-13 16:29:27 +01:00
commit 5db5031558
5 changed files with 203 additions and 196 deletions

8
tests/check.hpp Normal file
View file

@ -0,0 +1,8 @@
#ifndef CHECK_HPP
#define CHECK_HPP
#include <cstdlib>
#define ASSERT(cond) if (!(cond)) { std::abort(); }
#endif /* CHECK_HPP */

View file

@ -1,6 +1,6 @@
#include <cassert>
#include <vector> #include <vector>
#include "check.hpp"
#include "crypto.hpp" #include "crypto.hpp"
using namespace std; using namespace std;
@ -35,40 +35,40 @@ const vector<pair<string, string>> sha512_string_tests = {
int main() { int main() {
for(auto &string_test : base64_string_tests) { for(auto &string_test : base64_string_tests) {
assert(Crypto::Base64::encode(string_test.first) == string_test.second); ASSERT(Crypto::Base64::encode(string_test.first) == string_test.second);
assert(Crypto::Base64::decode(string_test.second) == string_test.first); ASSERT(Crypto::Base64::decode(string_test.second) == string_test.first);
} }
for(auto &string_test : md5_string_tests) { for(auto &string_test : md5_string_tests) {
assert(Crypto::to_hex_string(Crypto::md5(string_test.first)) == string_test.second); ASSERT(Crypto::to_hex_string(Crypto::md5(string_test.first)) == string_test.second);
stringstream ss(string_test.first); stringstream ss(string_test.first);
assert(Crypto::to_hex_string(Crypto::md5(ss)) == string_test.second); ASSERT(Crypto::to_hex_string(Crypto::md5(ss)) == string_test.second);
} }
for(auto &string_test : sha1_string_tests) { for(auto &string_test : sha1_string_tests) {
assert(Crypto::to_hex_string(Crypto::sha1(string_test.first)) == string_test.second); ASSERT(Crypto::to_hex_string(Crypto::sha1(string_test.first)) == string_test.second);
stringstream ss(string_test.first); stringstream ss(string_test.first);
assert(Crypto::to_hex_string(Crypto::sha1(ss)) == string_test.second); ASSERT(Crypto::to_hex_string(Crypto::sha1(ss)) == string_test.second);
} }
for(auto &string_test : sha256_string_tests) { for(auto &string_test : sha256_string_tests) {
assert(Crypto::to_hex_string(Crypto::sha256(string_test.first)) == string_test.second); ASSERT(Crypto::to_hex_string(Crypto::sha256(string_test.first)) == string_test.second);
stringstream ss(string_test.first); stringstream ss(string_test.first);
assert(Crypto::to_hex_string(Crypto::sha256(ss)) == string_test.second); ASSERT(Crypto::to_hex_string(Crypto::sha256(ss)) == string_test.second);
} }
for(auto &string_test : sha512_string_tests) { for(auto &string_test : sha512_string_tests) {
assert(Crypto::to_hex_string(Crypto::sha512(string_test.first)) == string_test.second); ASSERT(Crypto::to_hex_string(Crypto::sha512(string_test.first)) == string_test.second);
stringstream ss(string_test.first); stringstream ss(string_test.first);
assert(Crypto::to_hex_string(Crypto::sha512(ss)) == string_test.second); ASSERT(Crypto::to_hex_string(Crypto::sha512(ss)) == string_test.second);
} }
// Testing iterations // Testing iterations
assert(Crypto::to_hex_string(Crypto::sha1("Test", 1)) == "640ab2bae07bedc4c163f679a746f7ab7fb5d1fa"); ASSERT(Crypto::to_hex_string(Crypto::sha1("Test", 1)) == "640ab2bae07bedc4c163f679a746f7ab7fb5d1fa");
assert(Crypto::to_hex_string(Crypto::sha1("Test", 2)) == "af31c6cbdecd88726d0a9b3798c71ef41f1624d5"); ASSERT(Crypto::to_hex_string(Crypto::sha1("Test", 2)) == "af31c6cbdecd88726d0a9b3798c71ef41f1624d5");
stringstream ss("Test"); stringstream ss("Test");
assert(Crypto::to_hex_string(Crypto::sha1(ss, 2)) == "af31c6cbdecd88726d0a9b3798c71ef41f1624d5"); ASSERT(Crypto::to_hex_string(Crypto::sha1(ss, 2)) == "af31c6cbdecd88726d0a9b3798c71ef41f1624d5");
assert(Crypto::to_hex_string(Crypto::pbkdf2("Password", "Salt", 4096, 128 / 8)) == "f66df50f8aaa11e4d9721e1312ff2e66"); ASSERT(Crypto::to_hex_string(Crypto::pbkdf2("Password", "Salt", 4096, 128 / 8)) == "f66df50f8aaa11e4d9721e1312ff2e66");
assert(Crypto::to_hex_string(Crypto::pbkdf2("Password", "Salt", 8192, 512 / 8)) == "a941ccbc34d1ee8ebbd1d34824a419c3dc4eac9cbc7c36ae6c7ca8725e2b618a6ad22241e787af937b0960cf85aa8ea3a258f243e05d3cc9b08af5dd93be046c"); ASSERT(Crypto::to_hex_string(Crypto::pbkdf2("Password", "Salt", 8192, 512 / 8)) == "a941ccbc34d1ee8ebbd1d34824a419c3dc4eac9cbc7c36ae6c7ca8725e2b618a6ad22241e787af937b0960cf85aa8ea3a258f243e05d3cc9b08af5dd93be046c");
} }

View file

@ -1,7 +1,6 @@
#include "client_http.hpp" #include "client_http.hpp"
#include "server_http.hpp" #include "server_http.hpp"
#include "check.hpp"
#include <cassert>
using namespace std; using namespace std;
@ -18,29 +17,29 @@ int main() {
SimpleWeb::ScopeRunner scope_runner; SimpleWeb::ScopeRunner scope_runner;
std::thread cancel_thread; std::thread cancel_thread;
{ {
assert(scope_runner.count == 0); ASSERT(scope_runner.count == 0);
auto lock = scope_runner.continue_lock(); auto lock = scope_runner.continue_lock();
assert(lock); ASSERT(lock);
assert(scope_runner.count == 1); ASSERT(scope_runner.count == 1);
{ {
auto lock = scope_runner.continue_lock(); auto lock = scope_runner.continue_lock();
assert(lock); ASSERT(lock);
assert(scope_runner.count == 2); ASSERT(scope_runner.count == 2);
} }
assert(scope_runner.count == 1); ASSERT(scope_runner.count == 1);
cancel_thread = thread([&scope_runner] { cancel_thread = thread([&scope_runner] {
scope_runner.stop(); scope_runner.stop();
assert(scope_runner.count == -1); ASSERT(scope_runner.count == -1);
}); });
this_thread::sleep_for(chrono::milliseconds(500)); this_thread::sleep_for(chrono::milliseconds(500));
assert(scope_runner.count == 1); ASSERT(scope_runner.count == 1);
} }
cancel_thread.join(); cancel_thread.join();
assert(scope_runner.count == -1); ASSERT(scope_runner.count == -1);
auto lock = scope_runner.continue_lock(); auto lock = scope_runner.continue_lock();
assert(!lock); ASSERT(!lock);
scope_runner.stop(); scope_runner.stop();
assert(scope_runner.count == -1); ASSERT(scope_runner.count == -1);
scope_runner.count = 0; scope_runner.count = 0;
@ -48,12 +47,12 @@ int main() {
for(size_t c = 0; c < 100; ++c) { for(size_t c = 0; c < 100; ++c) {
threads.emplace_back([&scope_runner] { threads.emplace_back([&scope_runner] {
auto lock = scope_runner.continue_lock(); auto lock = scope_runner.continue_lock();
assert(scope_runner.count > 0); ASSERT(scope_runner.count > 0);
}); });
} }
for(auto &thread : threads) for(auto &thread : threads)
thread.join(); thread.join();
assert(scope_runner.count == 0); ASSERT(scope_runner.count == 0);
} }
HttpServer server; HttpServer server;
@ -65,8 +64,8 @@ int main() {
*response << "HTTP/1.1 200 OK\r\nContent-Length: " << content.length() << "\r\n\r\n" *response << "HTTP/1.1 200 OK\r\nContent-Length: " << content.length() << "\r\n\r\n"
<< content; << content;
assert(!request->remote_endpoint_address().empty()); ASSERT(!request->remote_endpoint_address().empty());
assert(request->remote_endpoint_port() != 0); ASSERT(request->remote_endpoint_port() != 0);
}; };
server.resource["^/string/dup$"]["POST"] = [](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) { server.resource["^/string/dup$"]["POST"] = [](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) {
@ -79,8 +78,8 @@ int main() {
*response << content; *response << content;
response->send(); response->send();
assert(!request->remote_endpoint_address().empty()); ASSERT(!request->remote_endpoint_address().empty());
assert(request->remote_endpoint_port() != 0); ASSERT(request->remote_endpoint_port() != 0);
}; };
server.resource["^/string2$"]["POST"] = [](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) { server.resource["^/string2$"]["POST"] = [](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) {
@ -130,18 +129,18 @@ int main() {
}; };
server.resource["^/query_string$"]["GET"] = [](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) { server.resource["^/query_string$"]["GET"] = [](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) {
assert(request->path == "/query_string"); ASSERT(request->path == "/query_string");
assert(request->query_string == "testing"); ASSERT(request->query_string == "testing");
auto queries = request->parse_query_string(); auto queries = request->parse_query_string();
auto it = queries.find("Testing"); auto it = queries.find("Testing");
assert(it != queries.end() && it->first == "testing" && it->second == ""); ASSERT(it != queries.end() && it->first == "testing" && it->second == "");
response->write(request->query_string); response->write(request->query_string);
}; };
server.resource["^/chunked$"]["POST"] = [](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) { server.resource["^/chunked$"]["POST"] = [](shared_ptr<HttpServer::Response> response, shared_ptr<HttpServer::Request> request) {
assert(request->path == "/chunked"); ASSERT(request->path == "/chunked");
assert(request->content.string() == "SimpleWeb in\r\n\r\nchunks."); ASSERT(request->content.string() == "SimpleWeb in\r\n\r\nchunks.");
response->write("6\r\nSimple\r\n3\r\nWeb\r\nE\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n", {{"Transfer-Encoding", "chunked"}}); response->write("6\r\nSimple\r\n3\r\nWeb\r\nE\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n", {{"Transfer-Encoding", "chunked"}});
}; };
@ -169,43 +168,43 @@ int main() {
{ {
stringstream output; stringstream output;
auto r = client.request("POST", "/string", "A string"); auto r = client.request("POST", "/string", "A string");
assert(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok); ASSERT(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok);
output << r->content.rdbuf(); output << r->content.rdbuf();
assert(output.str() == "A string"); ASSERT(output.str() == "A string");
} }
{ {
auto r = client.request("POST", "/string", "A string"); auto r = client.request("POST", "/string", "A string");
assert(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok); ASSERT(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok);
assert(r->content.string() == "A string"); ASSERT(r->content.string() == "A string");
} }
{ {
stringstream output; stringstream output;
auto r = client.request("POST", "/string2", "A string"); auto r = client.request("POST", "/string2", "A string");
assert(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok); ASSERT(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok);
output << r->content.rdbuf(); output << r->content.rdbuf();
assert(output.str() == "A string"); ASSERT(output.str() == "A string");
} }
{ {
stringstream output; stringstream output;
auto r = client.request("POST", "/string3", "A string"); auto r = client.request("POST", "/string3", "A string");
assert(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok); ASSERT(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok);
output << r->content.rdbuf(); output << r->content.rdbuf();
assert(output.str() == "A string"); ASSERT(output.str() == "A string");
} }
{ {
stringstream output; stringstream output;
auto r = client.request("POST", "/string4", "A string"); auto r = client.request("POST", "/string4", "A string");
assert(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::client_error_forbidden); ASSERT(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::client_error_forbidden);
assert(r->header.size() == 3); ASSERT(r->header.size() == 3);
assert(r->header.find("test1")->second == "test2"); ASSERT(r->header.find("test1")->second == "test2");
assert(r->header.find("tEst3")->second == "test4"); ASSERT(r->header.find("tEst3")->second == "test4");
assert(r->header.find("content-length")->second == "0"); ASSERT(r->header.find("content-length")->second == "0");
output << r->content.rdbuf(); output << r->content.rdbuf();
assert(output.str() == ""); ASSERT(output.str() == "");
} }
{ {
@ -213,7 +212,7 @@ int main() {
stringstream content("A string"); stringstream content("A string");
auto r = client.request("POST", "/string", content); auto r = client.request("POST", "/string", content);
output << r->content.rdbuf(); output << r->content.rdbuf();
assert(output.str() == "A string"); ASSERT(output.str() == "A string");
} }
{ {
@ -222,25 +221,25 @@ int main() {
stringstream content("A string\n"); stringstream content("A string\n");
auto r = client.request("POST", "/string/dup", content); auto r = client.request("POST", "/string/dup", content);
output << r->content.rdbuf(); output << r->content.rdbuf();
assert(output.str() == "A string\nA string\n"); ASSERT(output.str() == "A string\nA string\n");
} }
{ {
stringstream output; stringstream output;
auto r = client.request("GET", "/info", "", {{"Test Parameter", "test value"}}); auto r = client.request("GET", "/info", "", {{"Test Parameter", "test value"}});
output << r->content.rdbuf(); output << r->content.rdbuf();
assert(output.str() == "GET /info 1.1 test value"); ASSERT(output.str() == "GET /info 1.1 test value");
} }
{ {
stringstream output; stringstream output;
auto r = client.request("GET", "/match/123"); auto r = client.request("GET", "/match/123");
output << r->content.rdbuf(); output << r->content.rdbuf();
assert(output.str() == "123"); ASSERT(output.str() == "123");
} }
{ {
auto r = client.request("POST", "/chunked", "6\r\nSimple\r\n3\r\nWeb\r\nE\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n", {{"Transfer-Encoding", "chunked"}}); auto r = client.request("POST", "/chunked", "6\r\nSimple\r\n3\r\nWeb\r\nE\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n", {{"Transfer-Encoding", "chunked"}});
assert(r->content.string() == "SimpleWeb in\r\n\r\nchunks."); ASSERT(r->content.string() == "SimpleWeb in\r\n\r\nchunks.");
} }
} }
{ {
@ -253,8 +252,8 @@ int main() {
stringstream content("A string"); stringstream content("A string");
auto r = client.request("POST", "/string", content); auto r = client.request("POST", "/string", content);
output << r->content.rdbuf(); output << r->content.rdbuf();
assert(output.str() == "A string"); ASSERT(output.str() == "A string");
assert(client.connections.size() == 1); ASSERT(client.connections.size() == 1);
connection = client.connections.begin()->get(); connection = client.connections.begin()->get();
} }
@ -262,26 +261,26 @@ int main() {
stringstream output; stringstream output;
auto r = client.request("POST", "/string", "A string"); auto r = client.request("POST", "/string", "A string");
output << r->content.rdbuf(); output << r->content.rdbuf();
assert(output.str() == "A string"); ASSERT(output.str() == "A string");
assert(client.connections.size() == 1); ASSERT(client.connections.size() == 1);
assert(connection == client.connections.begin()->get()); ASSERT(connection == client.connections.begin()->get());
} }
{ {
stringstream output; stringstream output;
auto r = client.request("GET", "/header", "", {{"test1", "test"}, {"test2", "ing"}}); auto r = client.request("GET", "/header", "", {{"test1", "test"}, {"test2", "ing"}});
output << r->content.rdbuf(); output << r->content.rdbuf();
assert(output.str() == "testing"); ASSERT(output.str() == "testing");
assert(client.connections.size() == 1); ASSERT(client.connections.size() == 1);
assert(connection == client.connections.begin()->get()); ASSERT(connection == client.connections.begin()->get());
} }
{ {
stringstream output; stringstream output;
auto r = client.request("GET", "/query_string?testing"); auto r = client.request("GET", "/query_string?testing");
assert(r->content.string() == "testing"); ASSERT(r->content.string() == "testing");
assert(client.connections.size() == 1); ASSERT(client.connections.size() == 1);
assert(connection == client.connections.begin()->get()); ASSERT(connection == client.connections.begin()->get());
} }
} }
@ -290,14 +289,14 @@ int main() {
HttpClient client("localhost:8080"); HttpClient client("localhost:8080");
bool call = false; bool call = false;
client.request("GET", "/match/123", [&call](shared_ptr<HttpClient::Response> response, const SimpleWeb::error_code &ec) { client.request("GET", "/match/123", [&call](shared_ptr<HttpClient::Response> response, const SimpleWeb::error_code &ec) {
assert(!ec); ASSERT(!ec);
stringstream output; stringstream output;
output << response->content.rdbuf(); output << response->content.rdbuf();
assert(output.str() == "123"); ASSERT(output.str() == "123");
call = true; call = true;
}); });
client.io_service->run(); client.io_service->run();
assert(call); ASSERT(call);
{ {
vector<int> calls(100, 0); vector<int> calls(100, 0);
@ -305,22 +304,22 @@ int main() {
for(size_t c = 0; c < 100; ++c) { for(size_t c = 0; c < 100; ++c) {
threads.emplace_back([c, &client, &calls] { threads.emplace_back([c, &client, &calls] {
client.request("GET", "/match/123", [c, &calls](shared_ptr<HttpClient::Response> response, const SimpleWeb::error_code &ec) { client.request("GET", "/match/123", [c, &calls](shared_ptr<HttpClient::Response> response, const SimpleWeb::error_code &ec) {
assert(!ec); ASSERT(!ec);
stringstream output; stringstream output;
output << response->content.rdbuf(); output << response->content.rdbuf();
assert(output.str() == "123"); ASSERT(output.str() == "123");
calls[c] = 1; calls[c] = 1;
}); });
}); });
} }
for(auto &thread : threads) for(auto &thread : threads)
thread.join(); thread.join();
assert(client.connections.size() == 100); ASSERT(client.connections.size() == 100);
client.io_service->reset(); client.io_service->reset();
client.io_service->run(); client.io_service->run();
assert(client.connections.size() == 1); ASSERT(client.connections.size() == 1);
for(auto call : calls) for(auto call : calls)
assert(call); ASSERT(call);
} }
} }
@ -334,38 +333,38 @@ int main() {
threads.emplace_back([c, &client, &calls] { threads.emplace_back([c, &client, &calls] {
try { try {
auto r = client.request("GET", "/match/123"); auto r = client.request("GET", "/match/123");
assert(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok); ASSERT(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok);
assert(r->content.string() == "123"); ASSERT(r->content.string() == "123");
calls[c] = 1; calls[c] = 1;
} }
catch(...) { catch(...) {
assert(false); ASSERT(false);
} }
}); });
} }
for(auto &thread : threads) for(auto &thread : threads)
thread.join(); thread.join();
assert(client.connections.size() == 1); ASSERT(client.connections.size() == 1);
for(auto call : calls) for(auto call : calls)
assert(call); ASSERT(call);
} }
} }
// Test multiple requests through a persistent connection // Test multiple requests through a persistent connection
{ {
HttpClient client("localhost:8080"); HttpClient client("localhost:8080");
assert(client.connections.size() == 0); ASSERT(client.connections.size() == 0);
for(size_t c = 0; c < 5000; ++c) { for(size_t c = 0; c < 5000; ++c) {
auto r1 = client.request("POST", "/string", "A string"); auto r1 = client.request("POST", "/string", "A string");
assert(SimpleWeb::status_code(r1->status_code) == SimpleWeb::StatusCode::success_ok); ASSERT(SimpleWeb::status_code(r1->status_code) == SimpleWeb::StatusCode::success_ok);
assert(r1->content.string() == "A string"); ASSERT(r1->content.string() == "A string");
assert(client.connections.size() == 1); ASSERT(client.connections.size() == 1);
stringstream content("A string"); stringstream content("A string");
auto r2 = client.request("POST", "/string", content); auto r2 = client.request("POST", "/string", content);
assert(SimpleWeb::status_code(r2->status_code) == SimpleWeb::StatusCode::success_ok); ASSERT(SimpleWeb::status_code(r2->status_code) == SimpleWeb::StatusCode::success_ok);
assert(r2->content.string() == "A string"); ASSERT(r2->content.string() == "A string");
assert(client.connections.size() == 1); ASSERT(client.connections.size() == 1);
} }
} }
@ -374,18 +373,18 @@ int main() {
{ {
HttpClient client("localhost:8080"); HttpClient client("localhost:8080");
auto r = client.request("POST", "/string", "A string"); auto r = client.request("POST", "/string", "A string");
assert(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok); ASSERT(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok);
assert(r->content.string() == "A string"); ASSERT(r->content.string() == "A string");
assert(client.connections.size() == 1); ASSERT(client.connections.size() == 1);
} }
{ {
HttpClient client("localhost:8080"); HttpClient client("localhost:8080");
stringstream content("A string"); stringstream content("A string");
auto r = client.request("POST", "/string", content); auto r = client.request("POST", "/string", content);
assert(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok); ASSERT(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok);
assert(r->content.string() == "A string"); ASSERT(r->content.string() == "A string");
assert(client.connections.size() == 1); ASSERT(client.connections.size() == 1);
} }
} }
@ -397,7 +396,7 @@ int main() {
client.io_service = io_service; client.io_service = io_service;
client.request("GET", "/work", [&call](shared_ptr<HttpClient::Response> /*response*/, const SimpleWeb::error_code &ec) { client.request("GET", "/work", [&call](shared_ptr<HttpClient::Response> /*response*/, const SimpleWeb::error_code &ec) {
call = true; call = true;
assert(ec); ASSERT(ec);
}); });
thread thread([io_service] { thread thread([io_service] {
io_service->run(); io_service->run();
@ -406,7 +405,7 @@ int main() {
client.stop(); client.stop();
this_thread::sleep_for(chrono::milliseconds(100)); this_thread::sleep_for(chrono::milliseconds(100));
thread.join(); thread.join();
assert(call); ASSERT(call);
} }
// Test Client destructor that should cancel the client's request // Test Client destructor that should cancel the client's request
@ -416,7 +415,7 @@ int main() {
HttpClient client("localhost:8080"); HttpClient client("localhost:8080");
client.io_service = io_service; client.io_service = io_service;
client.request("GET", "/work", [](shared_ptr<HttpClient::Response> /*response*/, const SimpleWeb::error_code & /*ec*/) { client.request("GET", "/work", [](shared_ptr<HttpClient::Response> /*response*/, const SimpleWeb::error_code & /*ec*/) {
assert(false); ASSERT(false);
}); });
thread thread([io_service] { thread thread([io_service] {
io_service->run(); io_service->run();
@ -445,7 +444,7 @@ int main() {
this_thread::sleep_for(chrono::seconds(5)); this_thread::sleep_for(chrono::seconds(5));
response->write(SimpleWeb::StatusCode::success_ok, "test"); response->write(SimpleWeb::StatusCode::success_ok, "test");
response->send([](const SimpleWeb::error_code & /*ec*/) { response->send([](const SimpleWeb::error_code & /*ec*/) {
assert(false); ASSERT(false);
}); });
}); });
sleep_thread.detach(); sleep_thread.detach();
@ -460,7 +459,7 @@ int main() {
HttpClient client("localhost:8081"); HttpClient client("localhost:8081");
try { try {
auto r = client.request("GET", "/test"); auto r = client.request("GET", "/test");
assert(false); ASSERT(false);
} }
catch(...) { catch(...) {
client_catch = true; client_catch = true;
@ -470,8 +469,8 @@ int main() {
this_thread::sleep_for(chrono::seconds(1)); this_thread::sleep_for(chrono::seconds(1));
} }
this_thread::sleep_for(chrono::seconds(5)); this_thread::sleep_for(chrono::seconds(5));
assert(call); ASSERT(call);
assert(client_catch); ASSERT(client_catch);
io_service->stop(); io_service->stop();
} }
} }

View file

@ -1,6 +1,6 @@
#include "client_http.hpp" #include "client_http.hpp"
#include "server_http.hpp" #include "server_http.hpp"
#include <cassert> #include "check.hpp"
#include <iostream> #include <iostream>
using namespace std; using namespace std;
@ -23,29 +23,29 @@ public:
stream << "TestHeader3:test3b\r\n"; stream << "TestHeader3:test3b\r\n";
stream << "\r\n"; stream << "\r\n";
assert(RequestMessage::parse(session->request->content, session->request->method, session->request->path, ASSERT(RequestMessage::parse(session->request->content, session->request->method, session->request->path,
session->request->query_string, session->request->http_version, session->request->header)); session->request->query_string, session->request->http_version, session->request->header));
assert(session->request->method == "GET"); ASSERT(session->request->method == "GET");
assert(session->request->path == "/test/"); ASSERT(session->request->path == "/test/");
assert(session->request->http_version == "1.1"); ASSERT(session->request->http_version == "1.1");
assert(session->request->header.size() == 4); ASSERT(session->request->header.size() == 4);
auto header_it = session->request->header.find("TestHeader"); auto header_it = session->request->header.find("TestHeader");
assert(header_it != session->request->header.end() && header_it->second == "test"); ASSERT(header_it != session->request->header.end() && header_it->second == "test");
header_it = session->request->header.find("TestHeader2"); header_it = session->request->header.find("TestHeader2");
assert(header_it != session->request->header.end() && header_it->second == "test2"); ASSERT(header_it != session->request->header.end() && header_it->second == "test2");
header_it = session->request->header.find("testheader"); header_it = session->request->header.find("testheader");
assert(header_it != session->request->header.end() && header_it->second == "test"); ASSERT(header_it != session->request->header.end() && header_it->second == "test");
header_it = session->request->header.find("testheader2"); header_it = session->request->header.find("testheader2");
assert(header_it != session->request->header.end() && header_it->second == "test2"); ASSERT(header_it != session->request->header.end() && header_it->second == "test2");
auto range = session->request->header.equal_range("testheader3"); auto range = session->request->header.equal_range("testheader3");
auto first = range.first; auto first = range.first;
auto second = first; auto second = first;
++second; ++second;
assert(range.first != session->request->header.end() && range.second != session->request->header.end() && ASSERT(range.first != session->request->header.end() && range.second != session->request->header.end() &&
((first->second == "test3a" && second->second == "test3b") || ((first->second == "test3a" && second->second == "test3b") ||
(first->second == "test3b" && second->second == "test3a"))); (first->second == "test3b" && second->second == "test3a")));
} }
@ -62,13 +62,13 @@ public:
void connect(const std::shared_ptr<Session> &) noexcept override {} void connect(const std::shared_ptr<Session> &) noexcept override {}
void constructor_parse_test1() { void constructor_parse_test1() {
assert(host == "test.org"); ASSERT(host == "test.org");
assert(port == 8080); ASSERT(port == 8080);
} }
void constructor_parse_test2() { void constructor_parse_test2() {
assert(host == "test.org"); ASSERT(host == "test.org");
assert(port == 80); ASSERT(port == 80);
} }
void parse_response_header_test() { void parse_response_header_test() {
@ -85,66 +85,66 @@ public:
stream << "TestHeader6: \r\n"; stream << "TestHeader6: \r\n";
stream << "\r\n"; stream << "\r\n";
assert(ResponseMessage::parse(response->content, response->http_version, response->status_code, response->header)); ASSERT(ResponseMessage::parse(response->content, response->http_version, response->status_code, response->header));
assert(response->http_version == "1.1"); ASSERT(response->http_version == "1.1");
assert(response->status_code == "200 OK"); ASSERT(response->status_code == "200 OK");
assert(response->header.size() == 7); ASSERT(response->header.size() == 7);
auto header_it = response->header.find("TestHeader"); auto header_it = response->header.find("TestHeader");
assert(header_it != response->header.end() && header_it->second == "test"); ASSERT(header_it != response->header.end() && header_it->second == "test");
header_it = response->header.find("TestHeader2"); header_it = response->header.find("TestHeader2");
assert(header_it != response->header.end() && header_it->second == "test2"); ASSERT(header_it != response->header.end() && header_it->second == "test2");
header_it = response->header.find("testheader"); header_it = response->header.find("testheader");
assert(header_it != response->header.end() && header_it->second == "test"); ASSERT(header_it != response->header.end() && header_it->second == "test");
header_it = response->header.find("testheader2"); header_it = response->header.find("testheader2");
assert(header_it != response->header.end() && header_it->second == "test2"); ASSERT(header_it != response->header.end() && header_it->second == "test2");
auto range = response->header.equal_range("testheader3"); auto range = response->header.equal_range("testheader3");
auto first = range.first; auto first = range.first;
auto second = first; auto second = first;
++second; ++second;
assert(range.first != response->header.end() && range.second != response->header.end() && ASSERT(range.first != response->header.end() && range.second != response->header.end() &&
((first->second == "test3a" && second->second == "test3b") || ((first->second == "test3a" && second->second == "test3b") ||
(first->second == "test3b" && second->second == "test3a"))); (first->second == "test3b" && second->second == "test3a")));
header_it = response->header.find("TestHeader4"); header_it = response->header.find("TestHeader4");
assert(header_it != response->header.end() && header_it->second == ""); ASSERT(header_it != response->header.end() && header_it->second == "");
header_it = response->header.find("TestHeader5"); header_it = response->header.find("TestHeader5");
assert(header_it != response->header.end() && header_it->second == ""); ASSERT(header_it != response->header.end() && header_it->second == "");
header_it = response->header.find("TestHeader6"); header_it = response->header.find("TestHeader6");
assert(header_it != response->header.end() && header_it->second == ""); ASSERT(header_it != response->header.end() && header_it->second == "");
} }
}; };
int main() { int main() {
assert(case_insensitive_equal("Test", "tesT")); ASSERT(case_insensitive_equal("Test", "tesT"));
assert(case_insensitive_equal("tesT", "test")); ASSERT(case_insensitive_equal("tesT", "test"));
assert(!case_insensitive_equal("test", "tseT")); ASSERT(!case_insensitive_equal("test", "tseT"));
CaseInsensitiveEqual equal; CaseInsensitiveEqual equal;
assert(equal("Test", "tesT")); ASSERT(equal("Test", "tesT"));
assert(equal("tesT", "test")); ASSERT(equal("tesT", "test"));
assert(!equal("test", "tset")); ASSERT(!equal("test", "tset"));
CaseInsensitiveHash hash; CaseInsensitiveHash hash;
assert(hash("Test") == hash("tesT")); ASSERT(hash("Test") == hash("tesT"));
assert(hash("tesT") == hash("test")); ASSERT(hash("tesT") == hash("test"));
assert(hash("test") != hash("tset")); ASSERT(hash("test") != hash("tset"));
auto percent_decoded = "testing æøå !#$&'()*+,/:;=?@[]123-._~\r\n"; auto percent_decoded = "testing æøå !#$&'()*+,/:;=?@[]123-._~\r\n";
auto percent_encoded = "testing%20%C3%A6%C3%B8%C3%A5%20%21%23%24%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D123-._~%0D%0A"; auto percent_encoded = "testing%20%C3%A6%C3%B8%C3%A5%20%21%23%24%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D123-._~%0D%0A";
assert(Percent::encode(percent_decoded) == percent_encoded); ASSERT(Percent::encode(percent_decoded) == percent_encoded);
assert(Percent::decode(percent_encoded) == percent_decoded); ASSERT(Percent::decode(percent_encoded) == percent_decoded);
assert(Percent::decode(Percent::encode(percent_decoded)) == percent_decoded); ASSERT(Percent::decode(Percent::encode(percent_decoded)) == percent_decoded);
SimpleWeb::CaseInsensitiveMultimap fields = {{"test1", "æøå"}, {"test2", "!#$&'()*+,/:;=?@[]"}}; SimpleWeb::CaseInsensitiveMultimap fields = {{"test1", "æøå"}, {"test2", "!#$&'()*+,/:;=?@[]"}};
auto query_string1 = "test1=%C3%A6%C3%B8%C3%A5&test2=%21%23%24%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D"; auto query_string1 = "test1=%C3%A6%C3%B8%C3%A5&test2=%21%23%24%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D";
auto query_string2 = "test2=%21%23%24%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D&test1=%C3%A6%C3%B8%C3%A5"; auto query_string2 = "test2=%21%23%24%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D&test1=%C3%A6%C3%B8%C3%A5";
auto query_string_result = QueryString::create(fields); auto query_string_result = QueryString::create(fields);
assert(query_string_result == query_string1 || query_string_result == query_string2); ASSERT(query_string_result == query_string1 || query_string_result == query_string2);
auto fields_result1 = QueryString::parse(query_string1); auto fields_result1 = QueryString::parse(query_string1);
auto fields_result2 = QueryString::parse(query_string2); auto fields_result2 = QueryString::parse(query_string2);
assert(fields_result1 == fields_result2 && fields_result1 == fields); ASSERT(fields_result1 == fields_result2 && fields_result1 == fields);
auto serverTest = make_shared<ServerTest>(); auto serverTest = make_shared<ServerTest>();
serverTest->io_service = std::make_shared<asio::io_service>(); serverTest->io_service = std::make_shared<asio::io_service>();
@ -166,40 +166,40 @@ int main() {
{ {
request.query_string = ""; request.query_string = "";
auto queries = request.parse_query_string(); auto queries = request.parse_query_string();
assert(queries.empty()); ASSERT(queries.empty());
} }
{ {
request.query_string = "="; request.query_string = "=";
auto queries = request.parse_query_string(); auto queries = request.parse_query_string();
assert(queries.empty()); ASSERT(queries.empty());
} }
{ {
request.query_string = "=test"; request.query_string = "=test";
auto queries = request.parse_query_string(); auto queries = request.parse_query_string();
assert(queries.empty()); ASSERT(queries.empty());
} }
{ {
request.query_string = "a=1%202%20%203&b=3+4&c&d=æ%25ø%26å%3F"; request.query_string = "a=1%202%20%203&b=3+4&c&d=æ%25ø%26å%3F";
auto queries = request.parse_query_string(); auto queries = request.parse_query_string();
{ {
auto range = queries.equal_range("a"); auto range = queries.equal_range("a");
assert(range.first != range.second); ASSERT(range.first != range.second);
assert(range.first->second == "1 2 3"); ASSERT(range.first->second == "1 2 3");
} }
{ {
auto range = queries.equal_range("b"); auto range = queries.equal_range("b");
assert(range.first != range.second); ASSERT(range.first != range.second);
assert(range.first->second == "3 4"); ASSERT(range.first->second == "3 4");
} }
{ {
auto range = queries.equal_range("c"); auto range = queries.equal_range("c");
assert(range.first != range.second); ASSERT(range.first != range.second);
assert(range.first->second == ""); ASSERT(range.first->second == "");
} }
{ {
auto range = queries.equal_range("d"); auto range = queries.equal_range("d");
assert(range.first != range.second); ASSERT(range.first != range.second);
assert(range.first->second == "æ%ø&å?"); ASSERT(range.first->second == "æ%ø&å?");
} }
} }
@ -207,119 +207,119 @@ int main() {
SimpleWeb::CaseInsensitiveMultimap solution; SimpleWeb::CaseInsensitiveMultimap solution;
std::stringstream header; std::stringstream header;
auto parsed = SimpleWeb::HttpHeader::parse(header); auto parsed = SimpleWeb::HttpHeader::parse(header);
assert(parsed == solution); ASSERT(parsed == solution);
} }
{ {
SimpleWeb::CaseInsensitiveMultimap solution = {{"Content-Type", "application/json"}}; SimpleWeb::CaseInsensitiveMultimap solution = {{"Content-Type", "application/json"}};
std::stringstream header("Content-Type: application/json"); std::stringstream header("Content-Type: application/json");
auto parsed = SimpleWeb::HttpHeader::parse(header); auto parsed = SimpleWeb::HttpHeader::parse(header);
assert(parsed == solution); ASSERT(parsed == solution);
} }
{ {
SimpleWeb::CaseInsensitiveMultimap solution = {{"Content-Type", "application/json"}}; SimpleWeb::CaseInsensitiveMultimap solution = {{"Content-Type", "application/json"}};
std::stringstream header("Content-Type: application/json\r"); std::stringstream header("Content-Type: application/json\r");
auto parsed = SimpleWeb::HttpHeader::parse(header); auto parsed = SimpleWeb::HttpHeader::parse(header);
assert(parsed == solution); ASSERT(parsed == solution);
} }
{ {
SimpleWeb::CaseInsensitiveMultimap solution = {{"Content-Type", "application/json"}}; SimpleWeb::CaseInsensitiveMultimap solution = {{"Content-Type", "application/json"}};
std::stringstream header("Content-Type: application/json\r\n"); std::stringstream header("Content-Type: application/json\r\n");
auto parsed = SimpleWeb::HttpHeader::parse(header); auto parsed = SimpleWeb::HttpHeader::parse(header);
assert(parsed == solution); ASSERT(parsed == solution);
} }
{ {
{ {
SimpleWeb::CaseInsensitiveMultimap solution; SimpleWeb::CaseInsensitiveMultimap solution;
auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse(""); auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("");
assert(parsed == solution); ASSERT(parsed == solution);
} }
{ {
SimpleWeb::CaseInsensitiveMultimap solution = {{"a", ""}}; SimpleWeb::CaseInsensitiveMultimap solution = {{"a", ""}};
auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("a"); auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("a");
assert(parsed == solution); ASSERT(parsed == solution);
} }
{ {
SimpleWeb::CaseInsensitiveMultimap solution = {{"a", ""}, {"b", ""}}; SimpleWeb::CaseInsensitiveMultimap solution = {{"a", ""}, {"b", ""}};
{ {
auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("a; b"); auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("a; b");
assert(parsed == solution); ASSERT(parsed == solution);
} }
{ {
auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("a;b"); auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("a;b");
assert(parsed == solution); ASSERT(parsed == solution);
} }
} }
{ {
SimpleWeb::CaseInsensitiveMultimap solution = {{"a", ""}, {"b", "c"}}; SimpleWeb::CaseInsensitiveMultimap solution = {{"a", ""}, {"b", "c"}};
{ {
auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("a; b=c"); auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("a; b=c");
assert(parsed == solution); ASSERT(parsed == solution);
} }
{ {
auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("a;b=c"); auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("a;b=c");
assert(parsed == solution); ASSERT(parsed == solution);
} }
} }
{ {
SimpleWeb::CaseInsensitiveMultimap solution = {{"form-data", ""}}; SimpleWeb::CaseInsensitiveMultimap solution = {{"form-data", ""}};
auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data"); auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data");
assert(parsed == solution); ASSERT(parsed == solution);
} }
{ {
SimpleWeb::CaseInsensitiveMultimap solution = {{"form-data", ""}, {"test", ""}}; SimpleWeb::CaseInsensitiveMultimap solution = {{"form-data", ""}, {"test", ""}};
{ {
auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data; test"); auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data; test");
assert(parsed == solution); ASSERT(parsed == solution);
} }
} }
{ {
SimpleWeb::CaseInsensitiveMultimap solution = {{"form-data", ""}, {"name", "file"}}; SimpleWeb::CaseInsensitiveMultimap solution = {{"form-data", ""}, {"name", "file"}};
{ {
auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data; name=\"file\""); auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data; name=\"file\"");
assert(parsed == solution); ASSERT(parsed == solution);
} }
{ {
auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data; name=file"); auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data; name=file");
assert(parsed == solution); ASSERT(parsed == solution);
} }
} }
{ {
SimpleWeb::CaseInsensitiveMultimap solution = {{"form-data", ""}, {"name", "file"}, {"filename", "filename.png"}}; SimpleWeb::CaseInsensitiveMultimap solution = {{"form-data", ""}, {"name", "file"}, {"filename", "filename.png"}};
{ {
auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data; name=\"file\"; filename=\"filename.png\""); auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data; name=\"file\"; filename=\"filename.png\"");
assert(parsed == solution); ASSERT(parsed == solution);
} }
{ {
auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data;name=\"file\";filename=\"filename.png\""); auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data;name=\"file\";filename=\"filename.png\"");
assert(parsed == solution); ASSERT(parsed == solution);
} }
{ {
auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data; name=file; filename=filename.png"); auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data; name=file; filename=filename.png");
assert(parsed == solution); ASSERT(parsed == solution);
} }
{ {
auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data;name=file;filename=filename.png"); auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data;name=file;filename=filename.png");
assert(parsed == solution); ASSERT(parsed == solution);
} }
} }
{ {
SimpleWeb::CaseInsensitiveMultimap solution = {{"form-data", ""}, {"name", "fi le"}, {"filename", "file name.png"}}; SimpleWeb::CaseInsensitiveMultimap solution = {{"form-data", ""}, {"name", "fi le"}, {"filename", "file name.png"}};
{ {
auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data; name=\"fi le\"; filename=\"file name.png\""); auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data; name=\"fi le\"; filename=\"file name.png\"");
assert(parsed == solution); ASSERT(parsed == solution);
} }
{ {
auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data; name=\"fi%20le\"; filename=\"file%20name.png\""); auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data; name=\"fi%20le\"; filename=\"file%20name.png\"");
assert(parsed == solution); ASSERT(parsed == solution);
} }
{ {
auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data; name=fi le; filename=file name.png"); auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data; name=fi le; filename=file name.png");
assert(parsed == solution); ASSERT(parsed == solution);
} }
{ {
auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data; name=fi%20le; filename=file%20name.png"); auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data; name=fi%20le; filename=file%20name.png");
assert(parsed == solution); ASSERT(parsed == solution);
} }
} }
} }

View file

@ -1,26 +1,26 @@
#include "status_code.hpp" #include "status_code.hpp"
#include <cassert> #include "check.hpp"
using namespace SimpleWeb; using namespace SimpleWeb;
int main() { int main() {
assert(status_code("000 Error") == StatusCode::unknown); ASSERT(status_code("000 Error") == StatusCode::unknown);
assert(status_code(StatusCode::unknown) == ""); ASSERT(status_code(StatusCode::unknown) == "");
assert(status_code("100 Continue") == StatusCode::information_continue); ASSERT(status_code("100 Continue") == StatusCode::information_continue);
assert(status_code(StatusCode::information_continue) == "100 Continue"); ASSERT(status_code(StatusCode::information_continue) == "100 Continue");
assert(status_code("200 OK") == StatusCode::success_ok); ASSERT(status_code("200 OK") == StatusCode::success_ok);
assert(status_code(StatusCode::success_ok) == "200 OK"); ASSERT(status_code(StatusCode::success_ok) == "200 OK");
assert(status_code("208 Already Reported") == StatusCode::success_already_reported); ASSERT(status_code("208 Already Reported") == StatusCode::success_already_reported);
assert(status_code(StatusCode::success_already_reported) == "208 Already Reported"); ASSERT(status_code(StatusCode::success_already_reported) == "208 Already Reported");
assert(status_code("308 Permanent Redirect") == StatusCode::redirection_permanent_redirect); ASSERT(status_code("308 Permanent Redirect") == StatusCode::redirection_permanent_redirect);
assert(status_code(StatusCode::redirection_permanent_redirect) == "308 Permanent Redirect"); ASSERT(status_code(StatusCode::redirection_permanent_redirect) == "308 Permanent Redirect");
assert(status_code("404 Not Found") == StatusCode::client_error_not_found); ASSERT(status_code("404 Not Found") == StatusCode::client_error_not_found);
assert(status_code(StatusCode::client_error_not_found) == "404 Not Found"); ASSERT(status_code(StatusCode::client_error_not_found) == "404 Not Found");
assert(status_code("502 Bad Gateway") == StatusCode::server_error_bad_gateway); ASSERT(status_code("502 Bad Gateway") == StatusCode::server_error_bad_gateway);
assert(status_code(StatusCode::server_error_bad_gateway) == "502 Bad Gateway"); ASSERT(status_code(StatusCode::server_error_bad_gateway) == "502 Bad Gateway");
assert(status_code("504 Gateway Timeout") == StatusCode::server_error_gateway_timeout); ASSERT(status_code("504 Gateway Timeout") == StatusCode::server_error_gateway_timeout);
assert(status_code(StatusCode::server_error_gateway_timeout) == "504 Gateway Timeout"); ASSERT(status_code(StatusCode::server_error_gateway_timeout) == "504 Gateway Timeout");
assert(status_code("511 Network Authentication Required") == StatusCode::server_error_network_authentication_required); ASSERT(status_code("511 Network Authentication Required") == StatusCode::server_error_network_authentication_required);
assert(status_code(StatusCode::server_error_network_authentication_required) == "511 Network Authentication Required"); ASSERT(status_code(StatusCode::server_error_network_authentication_required) == "511 Network Authentication Required");
} }