From 53d5776b68665acc65e2eeb921c12ed6c7331288 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sun, 16 Jun 2024 21:41:56 -0400 Subject: [PATCH] tests: add httpcommon tests Co-Authored-By: Mariotaku --- tests/unit/test_httpcommon.cpp | 53 ++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/unit/test_httpcommon.cpp diff --git a/tests/unit/test_httpcommon.cpp b/tests/unit/test_httpcommon.cpp new file mode 100644 index 00000000000..0365c1dd5a4 --- /dev/null +++ b/tests/unit/test_httpcommon.cpp @@ -0,0 +1,53 @@ +/** + * @file tests/test_httpcommon.cpp + * @brief Test src/httpcommon.*. + */ +#include + +#include + +class HttpCommonTest : public ::testing::TestWithParam> {}; + +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") + ) +);