Added more unit tests for the simple interface
This commit is contained in:
parent
f4c5d94d74
commit
2d67211183
78
test/test.cc
78
test/test.cc
@ -651,19 +651,6 @@ TEST(YahooRedirectTest, Redirect) {
|
|||||||
EXPECT_EQ(200, res->status);
|
EXPECT_EQ(200, res->status);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(YahooRedirectTest2, Redirect) {
|
|
||||||
httplib::Client2 cli("http://yahoo.com");
|
|
||||||
|
|
||||||
auto res = cli.Get("/");
|
|
||||||
ASSERT_TRUE(res != nullptr);
|
|
||||||
EXPECT_EQ(301, res->status);
|
|
||||||
|
|
||||||
cli.set_follow_location(true);
|
|
||||||
res = cli.Get("/");
|
|
||||||
ASSERT_TRUE(res != nullptr);
|
|
||||||
EXPECT_EQ(200, res->status);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(HttpsToHttpRedirectTest, Redirect) {
|
TEST(HttpsToHttpRedirectTest, Redirect) {
|
||||||
httplib::SSLClient cli("httpbin.org");
|
httplib::SSLClient cli("httpbin.org");
|
||||||
cli.set_follow_location(true);
|
cli.set_follow_location(true);
|
||||||
@ -673,16 +660,6 @@ TEST(HttpsToHttpRedirectTest, Redirect) {
|
|||||||
EXPECT_EQ(200, res->status);
|
EXPECT_EQ(200, res->status);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(HttpsToHttpRedirectTest2, Redirect) {
|
|
||||||
auto res =
|
|
||||||
httplib::Client2("https://httpbin.org")
|
|
||||||
.set_follow_location(true)
|
|
||||||
.Get("/redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302");
|
|
||||||
|
|
||||||
ASSERT_TRUE(res != nullptr);
|
|
||||||
EXPECT_EQ(200, res->status);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(RedirectToDifferentPort, Redirect) {
|
TEST(RedirectToDifferentPort, Redirect) {
|
||||||
Server svr8080;
|
Server svr8080;
|
||||||
Server svr8081;
|
Server svr8081;
|
||||||
@ -2887,13 +2864,6 @@ TEST(SSLClientServerTest, TrustDirOptional) {
|
|||||||
|
|
||||||
t.join();
|
t.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cannot test this case as there is no external access to SSL object to check
|
|
||||||
SSL_get_peer_certificate() == NULL TEST(SSLClientServerTest,
|
|
||||||
ClientCAPathRequired) { SSLServer svr(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE,
|
|
||||||
nullptr, CLIENT_CA_CERT_DIR);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -2902,3 +2872,51 @@ TEST(CleanupTest, WSACleanup) {
|
|||||||
ASSERT_EQ(0, ret);
|
ASSERT_EQ(0, ret);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
|
TEST(InvalidScheme, SimpleInterface) {
|
||||||
|
httplib::Client2 cli("scheme://yahoo.com");
|
||||||
|
ASSERT_FALSE(cli.is_valid());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(NoScheme, SimpleInterface) {
|
||||||
|
httplib::Client2 cli("yahoo.com");
|
||||||
|
ASSERT_FALSE(cli.is_valid());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(YahooRedirectTest2, SimpleInterface) {
|
||||||
|
httplib::Client2 cli("http://yahoo.com");
|
||||||
|
|
||||||
|
auto res = cli.Get("/");
|
||||||
|
ASSERT_TRUE(res != nullptr);
|
||||||
|
EXPECT_EQ(301, res->status);
|
||||||
|
|
||||||
|
cli.set_follow_location(true);
|
||||||
|
res = cli.Get("/");
|
||||||
|
ASSERT_TRUE(res != nullptr);
|
||||||
|
EXPECT_EQ(200, res->status);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(YahooRedirectTest3, SimpleInterface) {
|
||||||
|
httplib::Client2 cli("https://yahoo.com");
|
||||||
|
|
||||||
|
auto res = cli.Get("/");
|
||||||
|
ASSERT_TRUE(res != nullptr);
|
||||||
|
EXPECT_EQ(301, res->status);
|
||||||
|
|
||||||
|
cli.set_follow_location(true);
|
||||||
|
res = cli.Get("/");
|
||||||
|
ASSERT_TRUE(res != nullptr);
|
||||||
|
EXPECT_EQ(200, res->status);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(HttpsToHttpRedirectTest2, SimpleInterface) {
|
||||||
|
auto res =
|
||||||
|
httplib::Client2("https://httpbin.org")
|
||||||
|
.set_follow_location(true)
|
||||||
|
.Get("/redirect-to?url=http%3A%2F%2Fwww.google.com&status_code=302");
|
||||||
|
|
||||||
|
ASSERT_TRUE(res != nullptr);
|
||||||
|
EXPECT_EQ(200, res->status);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user