diff options
author | Antony Woods <acron1@gmail.com> | 2014-10-14 18:25:22 +0100 |
---|---|---|
committer | Antony Woods <acron1@gmail.com> | 2014-10-14 18:25:22 +0100 |
commit | 6a2def410cc2559aeb7a9d34821b5d195672fb3b (patch) | |
tree | de0733229c28f9ef706bafd5276d9d200c573281 /tests | |
parent | 06842721d7da53a2235e6e4071760588ec285f90 (diff) | |
parent | a5fab23f70e6e33c633ba4b646a41d0851169ad1 (diff) | |
download | crow-6a2def410cc2559aeb7a9d34821b5d195672fb3b.tar.gz crow-6a2def410cc2559aeb7a9d34821b5d195672fb3b.zip |
Fixed merge oddities
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittest.cpp | 78 |
1 files changed, 75 insertions, 3 deletions
diff --git a/tests/unittest.cpp b/tests/unittest.cpp index 87acb52..1a15742 100644 --- a/tests/unittest.cpp +++ b/tests/unittest.cpp @@ -250,6 +250,79 @@ TEST(handler_with_response) }); } +TEST(http_method) +{ + SimpleApp app; + + CROW_ROUTE(app, "/") + .methods("POST"_method, "GET"_method) + ([](const request& req){ + if (req.method == "GET"_method) + return "2"; + else + return "1"; + }); + + CROW_ROUTE(app, "/get_only") + .methods("GET"_method) + ([](const request& req){ + return "get"; + }); + CROW_ROUTE(app, "/post_only") + .methods("POST"_method) + ([](const request& req){ + return "post"; + }); + + + // cannot have multiple handlers for the same url + //CROW_ROUTE(app, "/") + //.methods("GET"_method) + //([]{ return "2"; }); + + { + request req; + response res; + + req.url = "/"; + app.handle(req, res); + + ASSERT_EQUAL("2", res.body); + } + { + request req; + response res; + + req.url = "/"; + req.method = "POST"_method; + app.handle(req, res); + + ASSERT_EQUAL("1", res.body); + } + + { + request req; + response res; + + req.url = "/get_only"; + app.handle(req, res); + + ASSERT_EQUAL("get", res.body); + } + + { + request req; + response res; + + req.url = "/get_only"; + req.method = "POST"_method; + app.handle(req, res); + + ASSERT_NOTEQUAL("get", res.body); + } + +} + TEST(server_handling_error_request) { static char buf[2048]; @@ -283,8 +356,8 @@ TEST(multi_server) { static char buf[2048]; SimpleApp app1, app2; - CROW_ROUTE(app1, "/")([]{return "A";}); - CROW_ROUTE(app2, "/")([]{return "B";}); + CROW_ROUTE(app1, "/").methods("GET"_method, "POST"_method)([]{return "A";}); + CROW_ROUTE(app2, "/").methods("GET"_method, "POST"_method)([]{return "B";}); Server<SimpleApp> server1(&app1, 45451); Server<SimpleApp> server2(&app2, 45452); @@ -298,7 +371,6 @@ TEST(multi_server) 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)); size_t recved = c.receive(asio::buffer(buf, 2048)); |