|
@@ -45,6 +45,13 @@ TEST(GetHeaderValueTest, DefaultValue)
|
|
|
ASSERT_STREQ("text/plain", val);
|
|
ASSERT_STREQ("text/plain", val);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+TEST(GetHeaderValueTest, DefaultValueInt)
|
|
|
|
|
+{
|
|
|
|
|
+ MultiMap map = {{"Dummy","Dummy"}};
|
|
|
|
|
+ auto val = get_header_value_int(map, "Content-Length", 100);
|
|
|
|
|
+ ASSERT_EQ(100, val);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
TEST(GetHeaderValueTest, RegularValue)
|
|
TEST(GetHeaderValueTest, RegularValue)
|
|
|
{
|
|
{
|
|
|
MultiMap map = {{"Content-Type","text/html"}, {"Dummy", "Dummy"}};
|
|
MultiMap map = {{"Content-Type","text/html"}, {"Dummy", "Dummy"}};
|
|
@@ -52,35 +59,54 @@ TEST(GetHeaderValueTest, RegularValue)
|
|
|
ASSERT_STREQ("text/html", val);
|
|
ASSERT_STREQ("text/html", val);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-TEST(ServerTest, GetMethod)
|
|
|
|
|
|
|
+TEST(GetHeaderValueTest, RegularValueInt)
|
|
|
{
|
|
{
|
|
|
|
|
+ MultiMap map = {{"Content-Length","100"}, {"Dummy", "Dummy"}};
|
|
|
|
|
+ auto val = get_header_value_int(map, "Content-Length", 0);
|
|
|
|
|
+ ASSERT_EQ(100, val);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+class ServerTest : public ::testing::Test {
|
|
|
|
|
+protected:
|
|
|
|
|
+ ServerTest() : svr(host, port) {
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ virtual void SetUp() {
|
|
|
|
|
+ svr.get(url, [&](httplib::Connection& c) {
|
|
|
|
|
+ c.response.set_content(content);
|
|
|
|
|
+ });
|
|
|
|
|
+ f = async([&](){ svr.run(); });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ virtual void TearDown() {
|
|
|
|
|
+ svr.stop();
|
|
|
|
|
+ f.get();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const char* host = "localhost";
|
|
const char* host = "localhost";
|
|
|
int port = 1914;
|
|
int port = 1914;
|
|
|
const char* url = "/hi";
|
|
const char* url = "/hi";
|
|
|
const char* content = "Hello World!";
|
|
const char* content = "Hello World!";
|
|
|
|
|
|
|
|
- Server svr(host, port);
|
|
|
|
|
-
|
|
|
|
|
- svr.get(url, [&](httplib::Connection& c) {
|
|
|
|
|
- c.response.set_content(content);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- auto f = async([&](){ svr.run(); });
|
|
|
|
|
|
|
+ Server svr;
|
|
|
|
|
+ std::future<void> f;
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
- {
|
|
|
|
|
- Response res;
|
|
|
|
|
- Client(host, port).get(url, res);
|
|
|
|
|
- EXPECT_EQ(200, res.status);
|
|
|
|
|
- EXPECT_EQ(content, res.body);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- {
|
|
|
|
|
- Response res;
|
|
|
|
|
- Client(host, port).get("/invalid", res);
|
|
|
|
|
- EXPECT_EQ(404, res.status);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+TEST_F(ServerTest, GetMethod200)
|
|
|
|
|
+{
|
|
|
|
|
+ Response res;
|
|
|
|
|
+ bool ret = Client(host, port).get(url, res);
|
|
|
|
|
+ ASSERT_EQ(true, ret);
|
|
|
|
|
+ ASSERT_EQ(200, res.status);
|
|
|
|
|
+ ASSERT_EQ(content, res.body);
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- svr.stop();
|
|
|
|
|
|
|
+TEST_F(ServerTest, GetMethod404)
|
|
|
|
|
+{
|
|
|
|
|
+ Response res;
|
|
|
|
|
+ bool ret = Client(host, port).get("/invalid", res);
|
|
|
|
|
+ ASSERT_EQ(false, ret);
|
|
|
|
|
+ ASSERT_EQ(404, res.status);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// vim: et ts=4 sw=4 cin cino={1s ff=unix
|
|
// vim: et ts=4 sw=4 cin cino={1s ff=unix
|