Changed return type of client.

This commit is contained in:
yhirose 2012-10-02 23:24:23 -04:00
parent 42473b722f
commit f91cc98b89
2 changed files with 53 additions and 27 deletions

View file

@ -45,6 +45,13 @@ TEST(GetHeaderValueTest, DefaultValue)
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)
{
MultiMap map = {{"Content-Type","text/html"}, {"Dummy", "Dummy"}};
@ -52,35 +59,54 @@ TEST(GetHeaderValueTest, RegularValue)
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";
int port = 1914;
const char* url = "/hi";
const char* content = "Hello World!";
Server svr(host, port);
Server svr;
std::future<void> f;
};
svr.get(url, [&](httplib::Connection& c) {
c.response.set_content(content);
});
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);
}
auto f = async([&](){ svr.run(); });
{
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);
}
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