forked from etr/libhttpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.cpp
More file actions
52 lines (41 loc) · 1.1 KB
/
Copy pathbasic.cpp
File metadata and controls
52 lines (41 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "littletest.hpp"
#include <curl/curl.h>
#include "httpserver.hpp"
using namespace httpserver;
class simple_resource : public http_resource
{
public:
virtual void render_GET(const http_request& req, http_response** res)
{
*res = new http_string_response("OK", 200, "text/plain");
}
};
LT_BEGIN_SUITE(basic_suite)
webserver* ws;
simple_resource* res;
void set_up()
{
ws = new webserver(create_webserver(8080));
res = new simple_resource();
ws->register_resource("base", res);
ws->start(false);
}
void tier_down()
{
ws->stop();
delete ws;
delete res;
}
LT_END_SUITE(basic_suite)
LT_BEGIN_AUTO_TEST(basic_suite, read_body)
curl_global_init(CURL_GLOBAL_ALL);
CURL *curl = curl_easy_init();
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/base");
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
res = curl_easy_perform(curl);
LT_ASSERT_EQ(res, 0);
LT_END_AUTO_TEST(read_body)
LT_BEGIN_AUTO_TEST_ENV()
AUTORUN_TESTS()
LT_END_AUTO_TEST_ENV()