mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-15 01:08:27 +00:00
Added google test framework.
This commit is contained in:
parent
6818f18275
commit
4781156fa1
6 changed files with 28771 additions and 7 deletions
53
test/test.cc
Normal file
53
test/test.cc
Normal file
|
@ -0,0 +1,53 @@
|
|||
|
||||
#include <gtest/gtest.h>
|
||||
#include <httpsvrkit.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace httpsvrkit;
|
||||
|
||||
TEST(SplitTest, ParseQueryString)
|
||||
{
|
||||
string s = "key1=val1&key2=val2&key3=val3";
|
||||
map<string, string> dic;
|
||||
|
||||
split(&s[0], &s[s.size()], '&', [&](const char* b, const char* e) {
|
||||
string key, val;
|
||||
split(b, e, '=', [&](const char* b, const char* e) {
|
||||
if (key.empty()) {
|
||||
key.assign(b, e);
|
||||
} else {
|
||||
val.assign(b, e);
|
||||
}
|
||||
});
|
||||
dic[key] = val;
|
||||
});
|
||||
|
||||
ASSERT_EQ("val1", dic["key1"]);
|
||||
ASSERT_EQ("val2", dic["key2"]);
|
||||
ASSERT_EQ("val3", dic["key3"]);
|
||||
}
|
||||
|
||||
TEST(SocketTest, OpenClose)
|
||||
{
|
||||
socket_t sock = create_server_socket("localhost", 1914);
|
||||
ASSERT_NE(-1, sock);
|
||||
|
||||
auto ret = close_server_socket(sock);
|
||||
ASSERT_EQ(0, ret);
|
||||
}
|
||||
|
||||
TEST(GetHeaderValueTest, DefaultValue)
|
||||
{
|
||||
MultiMap map = {{"Dummy","Dummy"}};
|
||||
auto val = get_header_value(map, "Content-Type", "text/plain");
|
||||
ASSERT_STREQ("text/plain", val);
|
||||
}
|
||||
|
||||
TEST(GetHeaderValueTest, RegularValue)
|
||||
{
|
||||
MultiMap map = {{"Content-Type","text/html"}, {"Dummy", "Dummy"}};
|
||||
auto val = get_header_value(map, "Content-Type", "text/plain");
|
||||
ASSERT_STREQ("text/html", val);
|
||||
}
|
||||
|
||||
// vim: et ts=4 sw=4 cin cino={1s ff=unix
|
Loading…
Add table
Add a link
Reference in a new issue