diff --git a/tests/check.hpp b/tests/check.hpp new file mode 100644 index 0000000..bfead5f --- /dev/null +++ b/tests/check.hpp @@ -0,0 +1,8 @@ +#ifndef CHECK_HPP +#define CHECK_HPP + +#include + +#define ASSERT(cond) if (!(cond)) { std::abort(); } + +#endif /* CHECK_HPP */ diff --git a/tests/crypto_test.cpp b/tests/crypto_test.cpp index 028f6e4..ed66001 100644 --- a/tests/crypto_test.cpp +++ b/tests/crypto_test.cpp @@ -1,6 +1,6 @@ -#include #include +#include "check.hpp" #include "crypto.hpp" using namespace std; @@ -35,40 +35,40 @@ const vector> sha512_string_tests = { int main() { for(auto &string_test : base64_string_tests) { - assert(Crypto::Base64::encode(string_test.first) == string_test.second); - assert(Crypto::Base64::decode(string_test.second) == string_test.first); + ASSERT(Crypto::Base64::encode(string_test.first) == string_test.second); + ASSERT(Crypto::Base64::decode(string_test.second) == string_test.first); } 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); - 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) { - 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); - 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) { - 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); - 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) { - 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); - assert(Crypto::to_hex_string(Crypto::sha512(ss)) == string_test.second); + ASSERT(Crypto::to_hex_string(Crypto::sha512(ss)) == string_test.second); } // Testing iterations - 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", 1)) == "640ab2bae07bedc4c163f679a746f7ab7fb5d1fa"); + ASSERT(Crypto::to_hex_string(Crypto::sha1("Test", 2)) == "af31c6cbdecd88726d0a9b3798c71ef41f1624d5"); 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", 8192, 512 / 8)) == "a941ccbc34d1ee8ebbd1d34824a419c3dc4eac9cbc7c36ae6c7ca8725e2b618a6ad22241e787af937b0960cf85aa8ea3a258f243e05d3cc9b08af5dd93be046c"); + 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"); } diff --git a/tests/io_test.cpp b/tests/io_test.cpp index 106d4df..6c1b949 100644 --- a/tests/io_test.cpp +++ b/tests/io_test.cpp @@ -1,7 +1,6 @@ #include "client_http.hpp" #include "server_http.hpp" - -#include +#include "check.hpp" using namespace std; @@ -18,29 +17,29 @@ int main() { SimpleWeb::ScopeRunner scope_runner; std::thread cancel_thread; { - assert(scope_runner.count == 0); + ASSERT(scope_runner.count == 0); auto lock = scope_runner.continue_lock(); - assert(lock); - assert(scope_runner.count == 1); + ASSERT(lock); + ASSERT(scope_runner.count == 1); { auto lock = scope_runner.continue_lock(); - assert(lock); - assert(scope_runner.count == 2); + ASSERT(lock); + ASSERT(scope_runner.count == 2); } - assert(scope_runner.count == 1); + ASSERT(scope_runner.count == 1); cancel_thread = thread([&scope_runner] { scope_runner.stop(); - assert(scope_runner.count == -1); + ASSERT(scope_runner.count == -1); }); this_thread::sleep_for(chrono::milliseconds(500)); - assert(scope_runner.count == 1); + ASSERT(scope_runner.count == 1); } cancel_thread.join(); - assert(scope_runner.count == -1); + ASSERT(scope_runner.count == -1); auto lock = scope_runner.continue_lock(); - assert(!lock); + ASSERT(!lock); scope_runner.stop(); - assert(scope_runner.count == -1); + ASSERT(scope_runner.count == -1); scope_runner.count = 0; @@ -48,12 +47,12 @@ int main() { for(size_t c = 0; c < 100; ++c) { threads.emplace_back([&scope_runner] { auto lock = scope_runner.continue_lock(); - assert(scope_runner.count > 0); + ASSERT(scope_runner.count > 0); }); } for(auto &thread : threads) thread.join(); - assert(scope_runner.count == 0); + ASSERT(scope_runner.count == 0); } HttpServer server; @@ -65,8 +64,8 @@ int main() { *response << "HTTP/1.1 200 OK\r\nContent-Length: " << content.length() << "\r\n\r\n" << content; - assert(!request->remote_endpoint_address().empty()); - assert(request->remote_endpoint_port() != 0); + ASSERT(!request->remote_endpoint_address().empty()); + ASSERT(request->remote_endpoint_port() != 0); }; server.resource["^/string/dup$"]["POST"] = [](shared_ptr response, shared_ptr request) { @@ -79,8 +78,8 @@ int main() { *response << content; response->send(); - assert(!request->remote_endpoint_address().empty()); - assert(request->remote_endpoint_port() != 0); + ASSERT(!request->remote_endpoint_address().empty()); + ASSERT(request->remote_endpoint_port() != 0); }; server.resource["^/string2$"]["POST"] = [](shared_ptr response, shared_ptr request) { @@ -130,18 +129,18 @@ int main() { }; server.resource["^/query_string$"]["GET"] = [](shared_ptr response, shared_ptr request) { - assert(request->path == "/query_string"); - assert(request->query_string == "testing"); + ASSERT(request->path == "/query_string"); + ASSERT(request->query_string == "testing"); auto queries = request->parse_query_string(); 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); }; server.resource["^/chunked$"]["POST"] = [](shared_ptr response, shared_ptr 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"}}); }; @@ -169,43 +168,43 @@ int main() { { stringstream output; 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(); - assert(output.str() == "A string"); + ASSERT(output.str() == "A string"); } { auto r = client.request("POST", "/string", "A string"); - assert(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok); - assert(r->content.string() == "A string"); + ASSERT(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok); + ASSERT(r->content.string() == "A string"); } { stringstream output; 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(); - assert(output.str() == "A string"); + ASSERT(output.str() == "A string"); } { stringstream output; 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(); - assert(output.str() == "A string"); + ASSERT(output.str() == "A string"); } { stringstream output; auto r = client.request("POST", "/string4", "A string"); - assert(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::client_error_forbidden); - assert(r->header.size() == 3); - assert(r->header.find("test1")->second == "test2"); - assert(r->header.find("tEst3")->second == "test4"); - assert(r->header.find("content-length")->second == "0"); + ASSERT(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::client_error_forbidden); + ASSERT(r->header.size() == 3); + ASSERT(r->header.find("test1")->second == "test2"); + ASSERT(r->header.find("tEst3")->second == "test4"); + ASSERT(r->header.find("content-length")->second == "0"); output << r->content.rdbuf(); - assert(output.str() == ""); + ASSERT(output.str() == ""); } { @@ -213,7 +212,7 @@ int main() { stringstream content("A string"); auto r = client.request("POST", "/string", content); 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"); auto r = client.request("POST", "/string/dup", content); output << r->content.rdbuf(); - assert(output.str() == "A string\nA string\n"); + ASSERT(output.str() == "A string\nA string\n"); } { stringstream output; auto r = client.request("GET", "/info", "", {{"Test Parameter", "test value"}}); output << r->content.rdbuf(); - assert(output.str() == "GET /info 1.1 test value"); + ASSERT(output.str() == "GET /info 1.1 test value"); } { stringstream output; auto r = client.request("GET", "/match/123"); 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"}}); - 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"); auto r = client.request("POST", "/string", content); output << r->content.rdbuf(); - assert(output.str() == "A string"); - assert(client.connections.size() == 1); + ASSERT(output.str() == "A string"); + ASSERT(client.connections.size() == 1); connection = client.connections.begin()->get(); } @@ -262,26 +261,26 @@ int main() { stringstream output; auto r = client.request("POST", "/string", "A string"); output << r->content.rdbuf(); - assert(output.str() == "A string"); - assert(client.connections.size() == 1); - assert(connection == client.connections.begin()->get()); + ASSERT(output.str() == "A string"); + ASSERT(client.connections.size() == 1); + ASSERT(connection == client.connections.begin()->get()); } { stringstream output; auto r = client.request("GET", "/header", "", {{"test1", "test"}, {"test2", "ing"}}); output << r->content.rdbuf(); - assert(output.str() == "testing"); - assert(client.connections.size() == 1); - assert(connection == client.connections.begin()->get()); + ASSERT(output.str() == "testing"); + ASSERT(client.connections.size() == 1); + ASSERT(connection == client.connections.begin()->get()); } { stringstream output; auto r = client.request("GET", "/query_string?testing"); - assert(r->content.string() == "testing"); - assert(client.connections.size() == 1); - assert(connection == client.connections.begin()->get()); + ASSERT(r->content.string() == "testing"); + ASSERT(client.connections.size() == 1); + ASSERT(connection == client.connections.begin()->get()); } } @@ -290,14 +289,14 @@ int main() { HttpClient client("localhost:8080"); bool call = false; client.request("GET", "/match/123", [&call](shared_ptr response, const SimpleWeb::error_code &ec) { - assert(!ec); + ASSERT(!ec); stringstream output; output << response->content.rdbuf(); - assert(output.str() == "123"); + ASSERT(output.str() == "123"); call = true; }); client.io_service->run(); - assert(call); + ASSERT(call); { vector calls(100, 0); @@ -305,22 +304,22 @@ int main() { for(size_t c = 0; c < 100; ++c) { threads.emplace_back([c, &client, &calls] { client.request("GET", "/match/123", [c, &calls](shared_ptr response, const SimpleWeb::error_code &ec) { - assert(!ec); + ASSERT(!ec); stringstream output; output << response->content.rdbuf(); - assert(output.str() == "123"); + ASSERT(output.str() == "123"); calls[c] = 1; }); }); } for(auto &thread : threads) thread.join(); - assert(client.connections.size() == 100); + ASSERT(client.connections.size() == 100); client.io_service->reset(); client.io_service->run(); - assert(client.connections.size() == 1); + ASSERT(client.connections.size() == 1); for(auto call : calls) - assert(call); + ASSERT(call); } } @@ -334,38 +333,38 @@ int main() { threads.emplace_back([c, &client, &calls] { try { auto r = client.request("GET", "/match/123"); - assert(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok); - assert(r->content.string() == "123"); + ASSERT(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok); + ASSERT(r->content.string() == "123"); calls[c] = 1; } catch(...) { - assert(false); + ASSERT(false); } }); } for(auto &thread : threads) thread.join(); - assert(client.connections.size() == 1); + ASSERT(client.connections.size() == 1); for(auto call : calls) - assert(call); + ASSERT(call); } } // Test multiple requests through a persistent connection { HttpClient client("localhost:8080"); - assert(client.connections.size() == 0); + ASSERT(client.connections.size() == 0); for(size_t c = 0; c < 5000; ++c) { auto r1 = client.request("POST", "/string", "A string"); - assert(SimpleWeb::status_code(r1->status_code) == SimpleWeb::StatusCode::success_ok); - assert(r1->content.string() == "A string"); - assert(client.connections.size() == 1); + ASSERT(SimpleWeb::status_code(r1->status_code) == SimpleWeb::StatusCode::success_ok); + ASSERT(r1->content.string() == "A string"); + ASSERT(client.connections.size() == 1); stringstream content("A string"); auto r2 = client.request("POST", "/string", content); - assert(SimpleWeb::status_code(r2->status_code) == SimpleWeb::StatusCode::success_ok); - assert(r2->content.string() == "A string"); - assert(client.connections.size() == 1); + ASSERT(SimpleWeb::status_code(r2->status_code) == SimpleWeb::StatusCode::success_ok); + ASSERT(r2->content.string() == "A string"); + ASSERT(client.connections.size() == 1); } } @@ -374,18 +373,18 @@ int main() { { HttpClient client("localhost:8080"); auto r = client.request("POST", "/string", "A string"); - assert(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok); - assert(r->content.string() == "A string"); - assert(client.connections.size() == 1); + ASSERT(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok); + ASSERT(r->content.string() == "A string"); + ASSERT(client.connections.size() == 1); } { HttpClient client("localhost:8080"); stringstream content("A string"); auto r = client.request("POST", "/string", content); - assert(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok); - assert(r->content.string() == "A string"); - assert(client.connections.size() == 1); + ASSERT(SimpleWeb::status_code(r->status_code) == SimpleWeb::StatusCode::success_ok); + ASSERT(r->content.string() == "A string"); + ASSERT(client.connections.size() == 1); } } @@ -397,7 +396,7 @@ int main() { client.io_service = io_service; client.request("GET", "/work", [&call](shared_ptr /*response*/, const SimpleWeb::error_code &ec) { call = true; - assert(ec); + ASSERT(ec); }); thread thread([io_service] { io_service->run(); @@ -406,7 +405,7 @@ int main() { client.stop(); this_thread::sleep_for(chrono::milliseconds(100)); thread.join(); - assert(call); + ASSERT(call); } // Test Client destructor that should cancel the client's request @@ -416,7 +415,7 @@ int main() { HttpClient client("localhost:8080"); client.io_service = io_service; client.request("GET", "/work", [](shared_ptr /*response*/, const SimpleWeb::error_code & /*ec*/) { - assert(false); + ASSERT(false); }); thread thread([io_service] { io_service->run(); @@ -445,7 +444,7 @@ int main() { this_thread::sleep_for(chrono::seconds(5)); response->write(SimpleWeb::StatusCode::success_ok, "test"); response->send([](const SimpleWeb::error_code & /*ec*/) { - assert(false); + ASSERT(false); }); }); sleep_thread.detach(); @@ -460,7 +459,7 @@ int main() { HttpClient client("localhost:8081"); try { auto r = client.request("GET", "/test"); - assert(false); + ASSERT(false); } catch(...) { client_catch = true; @@ -470,8 +469,8 @@ int main() { this_thread::sleep_for(chrono::seconds(1)); } this_thread::sleep_for(chrono::seconds(5)); - assert(call); - assert(client_catch); + ASSERT(call); + ASSERT(client_catch); io_service->stop(); } } diff --git a/tests/parse_test.cpp b/tests/parse_test.cpp index e324376..05a6138 100644 --- a/tests/parse_test.cpp +++ b/tests/parse_test.cpp @@ -1,6 +1,6 @@ #include "client_http.hpp" #include "server_http.hpp" -#include +#include "check.hpp" #include using namespace std; @@ -23,29 +23,29 @@ public: stream << "TestHeader3:test3b\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)); - assert(session->request->method == "GET"); - assert(session->request->path == "/test/"); - assert(session->request->http_version == "1.1"); + ASSERT(session->request->method == "GET"); + ASSERT(session->request->path == "/test/"); + 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"); - 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"); - 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"); - 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"); - 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 first = range.first; auto second = first; ++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 == "test3b" && second->second == "test3a"))); } @@ -62,13 +62,13 @@ public: void connect(const std::shared_ptr &) noexcept override {} void constructor_parse_test1() { - assert(host == "test.org"); - assert(port == 8080); + ASSERT(host == "test.org"); + ASSERT(port == 8080); } void constructor_parse_test2() { - assert(host == "test.org"); - assert(port == 80); + ASSERT(host == "test.org"); + ASSERT(port == 80); } void parse_response_header_test() { @@ -85,66 +85,66 @@ public: stream << "TestHeader6: \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->status_code == "200 OK"); + ASSERT(response->http_version == "1.1"); + ASSERT(response->status_code == "200 OK"); - assert(response->header.size() == 7); + ASSERT(response->header.size() == 7); 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"); - 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"); - 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"); - 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 first = range.first; auto second = first; ++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 == "test3b" && second->second == "test3a"))); 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"); - assert(header_it != response->header.end() && header_it->second == ""); + ASSERT(header_it != response->header.end() && header_it->second == ""); 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() { - assert(case_insensitive_equal("Test", "tesT")); - assert(case_insensitive_equal("tesT", "test")); - assert(!case_insensitive_equal("test", "tseT")); + ASSERT(case_insensitive_equal("Test", "tesT")); + ASSERT(case_insensitive_equal("tesT", "test")); + ASSERT(!case_insensitive_equal("test", "tseT")); CaseInsensitiveEqual equal; - assert(equal("Test", "tesT")); - assert(equal("tesT", "test")); - assert(!equal("test", "tset")); + ASSERT(equal("Test", "tesT")); + ASSERT(equal("tesT", "test")); + ASSERT(!equal("test", "tset")); CaseInsensitiveHash hash; - assert(hash("Test") == hash("tesT")); - assert(hash("tesT") == hash("test")); - assert(hash("test") != hash("tset")); + ASSERT(hash("Test") == hash("tesT")); + ASSERT(hash("tesT") == hash("test")); + ASSERT(hash("test") != hash("tset")); 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"; - assert(Percent::encode(percent_decoded) == percent_encoded); - assert(Percent::decode(percent_encoded) == percent_decoded); - assert(Percent::decode(Percent::encode(percent_decoded)) == percent_decoded); + ASSERT(Percent::encode(percent_decoded) == percent_encoded); + ASSERT(Percent::decode(percent_encoded) == percent_decoded); + ASSERT(Percent::decode(Percent::encode(percent_decoded)) == percent_decoded); 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_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); - 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_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->io_service = std::make_shared(); @@ -166,40 +166,40 @@ int main() { { request.query_string = ""; auto queries = request.parse_query_string(); - assert(queries.empty()); + ASSERT(queries.empty()); } { request.query_string = "="; auto queries = request.parse_query_string(); - assert(queries.empty()); + ASSERT(queries.empty()); } { request.query_string = "=test"; 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"; auto queries = request.parse_query_string(); { auto range = queries.equal_range("a"); - assert(range.first != range.second); - assert(range.first->second == "1 2 3"); + ASSERT(range.first != range.second); + ASSERT(range.first->second == "1 2 3"); } { auto range = queries.equal_range("b"); - assert(range.first != range.second); - assert(range.first->second == "3 4"); + ASSERT(range.first != range.second); + ASSERT(range.first->second == "3 4"); } { auto range = queries.equal_range("c"); - assert(range.first != range.second); - assert(range.first->second == ""); + ASSERT(range.first != range.second); + ASSERT(range.first->second == ""); } { auto range = queries.equal_range("d"); - assert(range.first != range.second); - assert(range.first->second == "æ%ø&å?"); + ASSERT(range.first != range.second); + ASSERT(range.first->second == "æ%ø&å?"); } } @@ -207,119 +207,119 @@ int main() { SimpleWeb::CaseInsensitiveMultimap solution; std::stringstream header; auto parsed = SimpleWeb::HttpHeader::parse(header); - assert(parsed == solution); + ASSERT(parsed == solution); } { SimpleWeb::CaseInsensitiveMultimap solution = {{"Content-Type", "application/json"}}; std::stringstream header("Content-Type: application/json"); auto parsed = SimpleWeb::HttpHeader::parse(header); - assert(parsed == solution); + ASSERT(parsed == solution); } { SimpleWeb::CaseInsensitiveMultimap solution = {{"Content-Type", "application/json"}}; std::stringstream header("Content-Type: application/json\r"); auto parsed = SimpleWeb::HttpHeader::parse(header); - assert(parsed == solution); + ASSERT(parsed == solution); } { SimpleWeb::CaseInsensitiveMultimap solution = {{"Content-Type", "application/json"}}; std::stringstream header("Content-Type: application/json\r\n"); auto parsed = SimpleWeb::HttpHeader::parse(header); - assert(parsed == solution); + ASSERT(parsed == solution); } { { SimpleWeb::CaseInsensitiveMultimap solution; auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse(""); - assert(parsed == solution); + ASSERT(parsed == solution); } { SimpleWeb::CaseInsensitiveMultimap solution = {{"a", ""}}; auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("a"); - assert(parsed == solution); + ASSERT(parsed == solution); } { SimpleWeb::CaseInsensitiveMultimap solution = {{"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"); - assert(parsed == solution); + ASSERT(parsed == solution); } } { SimpleWeb::CaseInsensitiveMultimap solution = {{"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"); - assert(parsed == solution); + ASSERT(parsed == solution); } } { SimpleWeb::CaseInsensitiveMultimap solution = {{"form-data", ""}}; auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data"); - assert(parsed == solution); + ASSERT(parsed == solution); } { SimpleWeb::CaseInsensitiveMultimap solution = {{"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"}}; { 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"); - assert(parsed == solution); + ASSERT(parsed == solution); } } { SimpleWeb::CaseInsensitiveMultimap solution = {{"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\""); - assert(parsed == solution); + ASSERT(parsed == solution); } { 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"); - assert(parsed == solution); + ASSERT(parsed == solution); } } { 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\""); - assert(parsed == solution); + ASSERT(parsed == solution); } { 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"); - assert(parsed == solution); + ASSERT(parsed == solution); } { auto parsed = SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse("form-data; name=fi%20le; filename=file%20name.png"); - assert(parsed == solution); + ASSERT(parsed == solution); } } } diff --git a/tests/status_code_test.cpp b/tests/status_code_test.cpp index 0157a2f..f9b623d 100644 --- a/tests/status_code_test.cpp +++ b/tests/status_code_test.cpp @@ -1,26 +1,26 @@ #include "status_code.hpp" -#include +#include "check.hpp" using namespace SimpleWeb; int main() { - assert(status_code("000 Error") == StatusCode::unknown); - assert(status_code(StatusCode::unknown) == ""); - assert(status_code("100 Continue") == StatusCode::information_continue); - assert(status_code(StatusCode::information_continue) == "100 Continue"); - assert(status_code("200 OK") == StatusCode::success_ok); - assert(status_code(StatusCode::success_ok) == "200 OK"); - assert(status_code("208 Already Reported") == StatusCode::success_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(StatusCode::redirection_permanent_redirect) == "308 Permanent Redirect"); - 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("502 Bad Gateway") == StatusCode::server_error_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(StatusCode::server_error_gateway_timeout) == "504 Gateway Timeout"); - 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("000 Error") == StatusCode::unknown); + ASSERT(status_code(StatusCode::unknown) == ""); + ASSERT(status_code("100 Continue") == StatusCode::information_continue); + ASSERT(status_code(StatusCode::information_continue) == "100 Continue"); + ASSERT(status_code("200 OK") == StatusCode::success_ok); + ASSERT(status_code(StatusCode::success_ok) == "200 OK"); + ASSERT(status_code("208 Already Reported") == StatusCode::success_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(StatusCode::redirection_permanent_redirect) == "308 Permanent Redirect"); + 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("502 Bad Gateway") == StatusCode::server_error_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(StatusCode::server_error_gateway_timeout) == "504 Gateway Timeout"); + 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"); }