Skip to content

Commit

Permalink
tests: add httpcommon tests
Browse files Browse the repository at this point in the history
Co-Authored-By: Mariotaku <[email protected]>
  • Loading branch information
ReenigneArcher and mariotaku committed Jun 17, 2024
1 parent 0c0b4c4 commit 53d5776
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/unit/test_httpcommon.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @file tests/test_httpcommon.cpp
* @brief Test src/httpcommon.*.
*/
#include <src/httpcommon.h>

#include <tests/conftest.cpp>

class HttpCommonTest : public ::testing::TestWithParam<std::tuple<std::string, std::string>> {};

TEST_P(HttpCommonTest, UrlEscape) {
auto [input, expected] = GetParam();
ASSERT_EQ(http::url_escape(input), expected);
}

TEST_P(HttpCommonTest, UrlGetHost) {
auto [input, expected] = GetParam();
ASSERT_EQ(http::url_get_host(input), expected);
}

TEST_P(HttpCommonTest, DownloadFile) {
auto [url, filename] = GetParam();
ASSERT_TRUE(http::download_file(url, filename));
}

INSTANTIATE_TEST_SUITE_P(
UrlEscapeTests,
HttpCommonTest,
::testing::Values(
std::make_tuple("igdb_0123456789", "igdb_0123456789"),
std::make_tuple("../../../", "..%2F..%2F..%2F"),
std::make_tuple("..*\\", "..%2A%5C")
)
);

INSTANTIATE_TEST_SUITE_P(
UrlGetHostTests,
HttpCommonTest,
::testing::Values(
std::make_tuple("https://images.igdb.com/example.txt", "images.igdb.com"),
std::make_tuple("http://localhost:8080", "localhost"),
std::make_tuple("nonsense!!}{::", "")
)
);

INSTANTIATE_TEST_SUITE_P(
DownloadFileTests,
HttpCommonTest,
::testing::Values(
std::make_tuple("https://httpbin.org/base64/aGVsbG8h", "hello.txt"),
std::make_tuple("https://httpbin.org/redirect-to?url=/base64/aGVsbG8h", "hello-redirect.txt")
)
);

0 comments on commit 53d5776

Please sign in to comment.