|
| 1 | +/* |
| 2 | + This file is part of libhttpserver |
| 3 | + Copyright (C) 2011, 2012, 2013, 2014, 2015 Sebastiano Merlino |
| 4 | +
|
| 5 | + This library is free software; you can redistribute it and/or |
| 6 | + modify it under the terms of the GNU Lesser General Public |
| 7 | + License as published by the Free Software Foundation; either |
| 8 | + version 2.1 of the License, or (at your option) any later version. |
| 9 | +
|
| 10 | + This library is distributed in the hope that it will be useful, |
| 11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + Lesser General Public License for more details. |
| 14 | +
|
| 15 | + You should have received a copy of the GNU Lesser General Public |
| 16 | + License along with this library; if not, write to the Free Software |
| 17 | + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 18 | + USA |
| 19 | +*/ |
| 20 | + |
| 21 | +#include "littletest.hpp" |
| 22 | +#include <curl/curl.h> |
| 23 | +#include <string> |
| 24 | +#include <map> |
| 25 | +#include "httpserver.hpp" |
| 26 | + |
| 27 | +using namespace httpserver; |
| 28 | +using namespace std; |
| 29 | + |
| 30 | +class ok_resource : public http_resource |
| 31 | +{ |
| 32 | + public: |
| 33 | + void render_GET(const http_request& req, http_response** res) |
| 34 | + { |
| 35 | + *res = new http_response(http_response_builder("OK", 200, "text/plain").string_response()); |
| 36 | + } |
| 37 | +}; |
| 38 | + |
| 39 | +LT_BEGIN_SUITE(threaded_suite) |
| 40 | + |
| 41 | + webserver* ws; |
| 42 | + |
| 43 | + void set_up() |
| 44 | + { |
| 45 | + ws = new webserver(create_webserver(8080).max_threads(5)); |
| 46 | + ws->start(false); |
| 47 | + } |
| 48 | + |
| 49 | + void tear_down() |
| 50 | + { |
| 51 | + ws->stop(); |
| 52 | + delete ws; |
| 53 | + } |
| 54 | +LT_END_SUITE(threaded_suite) |
| 55 | + |
| 56 | +LT_BEGIN_AUTO_TEST(threaded_suite, base) |
| 57 | + ok_resource* resource = new ok_resource(); |
| 58 | + ws->register_resource("base", resource); |
| 59 | + curl_global_init(CURL_GLOBAL_ALL); |
| 60 | + std::string s; |
| 61 | + CURL* curl; |
| 62 | + CURLcode res; |
| 63 | + |
| 64 | + curl = curl_easy_init(); |
| 65 | + curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/base"); |
| 66 | + curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); |
| 67 | + res = curl_easy_perform(curl); |
| 68 | + LT_ASSERT_EQ(res, 0); |
| 69 | + curl_easy_cleanup(curl); |
| 70 | +LT_END_AUTO_TEST(base) |
| 71 | + |
| 72 | +LT_BEGIN_AUTO_TEST_ENV() |
| 73 | + AUTORUN_TESTS() |
| 74 | +LT_END_AUTO_TEST_ENV() |
0 commit comments