Skip to content

Commit

Permalink
Tests - Add WebTests
Browse files Browse the repository at this point in the history
  • Loading branch information
nlogozzo committed Dec 5, 2023
1 parent 3358ef1 commit 2d78d2a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
24 changes: 18 additions & 6 deletions src/helpers/webhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ namespace Nickvision::Aura
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true);
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
curl_easy_setopt(curl, CURLOPT_HEADER, false);
CURLcode code = curl_easy_perform(curl);
#ifdef _WIN32
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
#endif
CURLcode code{ curl_easy_perform(curl) };
curl_easy_cleanup(curl);
curl_global_cleanup();
return code == CURLE_OK;
Expand All @@ -39,21 +43,25 @@ namespace Nickvision::Aura
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, [](char* ptr, size_t size, size_t nmemb, void* data)
{
std::ofstream* stream{ (std::ofstream*)data };
std::ofstream* stream{ reinterpret_cast<std::ofstream*>(data) };
stream->write(ptr, size * nmemb);
return size * nmemb;
});
#ifdef _WIN32
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
#endif
if (progress)
{
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, false);
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &progress);
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, [](void* data, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
{
CurlProgressFunction& func{ *((CurlProgressFunction*)data) };
CurlProgressFunction& func{ *(reinterpret_cast<CurlProgressFunction*>(data)) };
return func(dltotal, dlnow, ultotal, ulnow);
});
}
CURLcode code = curl_easy_perform(curl);
CURLcode code{ curl_easy_perform(curl) };
curl_easy_cleanup(curl);
curl_global_cleanup();
return code == CURLE_OK;
Expand All @@ -77,11 +85,15 @@ namespace Nickvision::Aura
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, [](char* ptr, size_t size, size_t nmemb, void* data)
{
std::stringstream* stream{ (std::stringstream*)data };
std::stringstream* stream{ reinterpret_cast<std::stringstream*>(data) };
stream->write(ptr, size * nmemb);
return size * nmemb;
});
CURLcode code = curl_easy_perform(curl);
#ifdef _WIN32
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
#endif
CURLcode code{ curl_easy_perform(curl) };
curl_easy_cleanup(curl);
curl_slist_free_all(listHttpHeader);
curl_global_cleanup();
Expand Down
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ enable_testing()

add_executable(${PROJECT_NAME}
stringtests.cpp
versiontests.cpp)
versiontests.cpp
webtests.cpp)

target_link_libraries(${PROJECT_NAME} PRIVATE libaura-static)
find_package(GTest REQUIRED)
Expand Down
19 changes: 19 additions & 0 deletions tests/webtests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <gtest/gtest.h>
#include "helpers/webhelpers.h"

using namespace Nickvision::Aura;

TEST(WebTests, ValidWebsite1)
{
EXPECT_TRUE(WebHelpers::isValidWebsite("https://example.com"));
}

TEST(WebTests, ValidWebsite2)
{
EXPECT_FALSE(WebHelpers::isValidWebsite("https://www.sdfjsdfj.com"));
}

TEST(WebTests, DownloadFile1)
{
EXPECT_TRUE(WebHelpers::downloadFile("https://www.w3.org/TR/2003/REC-PNG-20031110/iso_8859-1.txt", "test.txt"));
}

0 comments on commit 2d78d2a

Please sign in to comment.