diff options
author | ipknHama <ipknhama@gmail.com> | 2014-04-22 20:19:03 +0900 |
---|---|---|
committer | ipknHama <ipknhama@gmail.com> | 2014-04-22 20:19:03 +0900 |
commit | 89bfe52f09ca583afc56e2fb31c6a79c5b6e55ac (patch) | |
tree | e884babffb936286ec1f5f58aabe67e885e40308 /unittest.cpp | |
parent | dd74354a7bfc34b1c347083c4565ebbd80ff94c0 (diff) | |
download | crow-89bfe52f09ca583afc56e2fb31c6a79c5b6e55ac.tar.gz crow-89bfe52f09ca583afc56e2fb31c6a79c5b6e55ac.zip |
increasing unittest coverage; fix crash bug while parsing headers
Diffstat (limited to 'unittest.cpp')
-rw-r--r-- | unittest.cpp | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/unittest.cpp b/unittest.cpp index d10c2e3..ddd69a3 100644 --- a/unittest.cpp +++ b/unittest.cpp @@ -1,3 +1,4 @@ +//#define FLASK_ENABLE_LOGGING #include <iostream> #include <vector> #include "routing.h" @@ -217,6 +218,35 @@ TEST(simple_response_routing_params) ASSERT_EQUAL("hello", rp.get<string>(0)); } +TEST(server_handling_error_request) +{ + static char buf[2048]; + Flask app; + FLASK_ROUTE(app, "/")([]{return "A";}); + Server<Flask> server(&app, 45451); + auto _ = async(launch::async, [&]{server.run();}); + std::string sendmsg = "POX"; + asio::io_service is; + { + asio::ip::tcp::socket c(is); + c.connect(asio::ip::tcp::endpoint(asio::ip::address::from_string("127.0.0.1"), 45451)); + + + c.send(asio::buffer(sendmsg)); + + try + { + c.receive(asio::buffer(buf, 2048)); + fail(); + } + catch(std::exception& e) + { + std::cerr << e.what() << std::endl; + } + } + server.stop(); +} + TEST(multi_server) { static char buf[2048]; @@ -230,12 +260,12 @@ TEST(multi_server) auto _ = async(launch::async, [&]{server1.run();}); auto _2 = async(launch::async, [&]{server2.run();}); + std::string sendmsg = "POST /\r\nContent-Length:3\r\nX-HeaderTest: 123\r\n\r\nA=B\r\n"; asio::io_service is; { asio::ip::tcp::socket c(is); c.connect(asio::ip::tcp::endpoint(asio::ip::address::from_string("127.0.0.1"), 45451)); - std::string sendmsg = "GET /\r\n\r\n"; c.send(asio::buffer(sendmsg)); @@ -247,9 +277,12 @@ TEST(multi_server) asio::ip::tcp::socket c(is); c.connect(asio::ip::tcp::endpoint(asio::ip::address::from_string("127.0.0.1"), 45452)); - std::string sendmsg = "GET /\r\n\r\n"; - - c.send(asio::buffer(sendmsg)); + for(auto ch:sendmsg) + { + char buf[1] = {ch}; + std::cerr << ch << '(' << (int)ch<<')'<<std::endl; + c.send(asio::buffer(buf)); + } size_t recved = c.receive(asio::buffer(buf, 2048)); ASSERT_EQUAL('B', buf[recved-1]); |