X Tutup
Skip to content

Commit d73e44b

Browse files
author
Sebastiano Merlino
committed
Added some tests to the suite
1 parent 548dbcf commit d73e44b

File tree

2 files changed

+625
-0
lines changed

2 files changed

+625
-0
lines changed

test/basic.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "littletest.hpp"
2+
#include <curl/curl.h>
3+
#include "httpserver.hpp"
4+
5+
using namespace httpserver;
6+
7+
class simple_resource : public http_resource
8+
{
9+
public:
10+
virtual void render_GET(const http_request& req, http_response** res)
11+
{
12+
*res = new http_string_response("OK", 200, "text/plain");
13+
}
14+
};
15+
16+
LT_BEGIN_SUITE(basic_suite)
17+
18+
webserver* ws;
19+
simple_resource* res;
20+
21+
void set_up()
22+
{
23+
ws = new webserver(create_webserver(8080));
24+
res = new simple_resource();
25+
ws->register_resource("base", res);
26+
ws->start(false);
27+
}
28+
29+
void tier_down()
30+
{
31+
ws->stop();
32+
delete ws;
33+
delete res;
34+
}
35+
LT_END_SUITE(basic_suite)
36+
37+
LT_BEGIN_AUTO_TEST(basic_suite, read_body)
38+
curl_global_init(CURL_GLOBAL_ALL);
39+
CURL *curl = curl_easy_init();
40+
CURLcode res;
41+
curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/base");
42+
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
43+
res = curl_easy_perform(curl);
44+
45+
LT_ASSERT_EQ(res, 0);
46+
47+
LT_END_AUTO_TEST(read_body)
48+
49+
50+
LT_BEGIN_AUTO_TEST_ENV()
51+
AUTORUN_TESTS()
52+
LT_END_AUTO_TEST_ENV()

0 commit comments

Comments
 (0)
X Tutup