2022-01-29 17:14:15 +01:00
|
|
|
#include <hex/test/tests.hpp>
|
|
|
|
|
2023-04-19 21:56:34 +02:00
|
|
|
#include <hex/api_urls.hpp>
|
2023-03-23 11:23:07 +01:00
|
|
|
#include <hex/helpers/http_requests.hpp>
|
2023-03-13 09:25:07 +01:00
|
|
|
#include <wolv/io/file.hpp>
|
2022-01-29 17:14:15 +01:00
|
|
|
|
|
|
|
using namespace std::literals::string_literals;
|
|
|
|
|
|
|
|
TEST_SEQUENCE("StoreAPI") {
|
2023-03-23 11:23:07 +01:00
|
|
|
hex::HttpRequest request("GET", ImHexApiURL + "/store"s);
|
2022-01-29 17:14:15 +01:00
|
|
|
|
2023-03-23 11:23:07 +01:00
|
|
|
auto result = request.execute().get();
|
2022-01-29 17:14:15 +01:00
|
|
|
|
2023-03-23 11:23:07 +01:00
|
|
|
if (result.getStatusCode() != 200)
|
2022-01-29 17:14:15 +01:00
|
|
|
TEST_FAIL();
|
|
|
|
|
2023-03-23 11:23:07 +01:00
|
|
|
if (result.getData().empty())
|
2022-01-29 17:14:15 +01:00
|
|
|
TEST_FAIL();
|
|
|
|
|
|
|
|
TEST_SUCCESS();
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_SEQUENCE("TipsAPI") {
|
2023-03-23 11:23:07 +01:00
|
|
|
hex::HttpRequest request("GET", ImHexApiURL + "/tip"s);
|
2022-01-29 17:14:15 +01:00
|
|
|
|
2023-03-23 11:23:07 +01:00
|
|
|
auto result = request.execute().get();
|
2022-01-29 17:14:15 +01:00
|
|
|
|
2023-03-23 11:23:07 +01:00
|
|
|
if (result.getStatusCode() != 200)
|
2022-01-29 17:14:15 +01:00
|
|
|
TEST_FAIL();
|
|
|
|
|
2023-03-23 11:23:07 +01:00
|
|
|
if (result.getData().empty())
|
2022-01-29 17:14:15 +01:00
|
|
|
TEST_FAIL();
|
|
|
|
|
|
|
|
TEST_SUCCESS();
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_SEQUENCE("ContentAPI") {
|
2023-03-23 11:23:07 +01:00
|
|
|
hex::HttpRequest request("GET", "https://api.werwolv.net/content/imhex/patterns/elf.hexpat");
|
2022-01-29 17:14:15 +01:00
|
|
|
|
2022-03-04 14:34:37 +01:00
|
|
|
const auto FilePath = std::fs::current_path() / "elf.hexpat";
|
2022-01-29 17:14:15 +01:00
|
|
|
|
2023-03-23 11:23:07 +01:00
|
|
|
auto result = request.downloadFile(FilePath).get();
|
2022-01-29 17:14:15 +01:00
|
|
|
|
2023-03-23 11:23:07 +01:00
|
|
|
TEST_ASSERT(result.getStatusCode() == 200);
|
2022-01-29 17:14:15 +01:00
|
|
|
|
2023-03-13 09:25:07 +01:00
|
|
|
wolv::io::File file(FilePath, wolv::io::File::Mode::Read);
|
2022-01-29 17:14:15 +01:00
|
|
|
if (!file.isValid())
|
|
|
|
TEST_FAIL();
|
|
|
|
|
|
|
|
if (file.getSize() == 0)
|
|
|
|
TEST_FAIL();
|
|
|
|
|
|
|
|
TEST_SUCCESS();
|
|
|
|
};
|