#include "tile/base/internal/curl.h"

#include "gtest/gtest.h"

/**
 * @brief Test HttpGet function.
 * https://httpstat.us/
 */
namespace tile {
namespace internal {

namespace {
std::string
HttpGetTestURI(int code)
{
    static const std::string kHttpCodeTestURI = "http://httpstat.us/";
    return kHttpCodeTestURI + std::to_string(code);
}

constexpr auto kTimeout = std::chrono::seconds(5);
}// namespace

#define TEST_HTTP_GET_URI(uri, code)                                                                                   \
    do {                                                                                                               \
        auto test_anonymous_http_res = HttpGet(uri, kTimeout);                                                         \
        EXPECT_TRUE(code == 200 || !test_anonymous_http_res);                                                          \
        if (!test_anonymous_http_res) { EXPECT_EQ(test_anonymous_http_res.error(), code); }                            \
    } while (0);

#define TEST_HTTP_GET(code) TEST_HTTP_GET_URI(HttpGetTestURI(code), code)

TEST(CURL, Get)
{
    GTEST_SKIP_("Fix me.");
    // TEST_HTTP_GET_URI("http://baidu.com/", 200);
    // 1xx
    TEST_HTTP_GET(100);// Continue
    TEST_HTTP_GET(101);// Switching Protocols
    TEST_HTTP_GET(102);// Processing
    TEST_HTTP_GET(103);// Early Hints

    // 2xx
    TEST_HTTP_GET(200);// OK
    TEST_HTTP_GET(201);// Created
    TEST_HTTP_GET(202);// Accepted
    TEST_HTTP_GET(203);// Non-Authoritative Information
    TEST_HTTP_GET(204);// No Content
    TEST_HTTP_GET(205);// Reset Content
    TEST_HTTP_GET(206);// Partial Content
    TEST_HTTP_GET(207);// Multi-Status
    TEST_HTTP_GET(208);// Already Reported
    TEST_HTTP_GET(226);// IM Used

    // 3xx
    TEST_HTTP_GET(300);// Multiple Choices
    TEST_HTTP_GET(301);// Moved Permanently
    TEST_HTTP_GET(302);// Found
    TEST_HTTP_GET(303);// See Other
    TEST_HTTP_GET(304);// Not Modified
    TEST_HTTP_GET(305);// Use Proxy
    TEST_HTTP_GET(306);// Switch Proxy
    TEST_HTTP_GET(307);// Temporary Redirect
    TEST_HTTP_GET(308);// Permanent Redirect

    // 4xx
    TEST_HTTP_GET(400);// Bad Request
    TEST_HTTP_GET(401);// Unauthorized
    TEST_HTTP_GET(402);// Payment Required
    TEST_HTTP_GET(403);// Forbidden
    TEST_HTTP_GET(404);// Not Found
    TEST_HTTP_GET(405);// Method Not Allowed
    TEST_HTTP_GET(406);// Not Acceptable
    TEST_HTTP_GET(407);// Proxy Authentication Required
    TEST_HTTP_GET(408);// Request Timeout
    TEST_HTTP_GET(409);// Conflict
    TEST_HTTP_GET(410);// Gone
    TEST_HTTP_GET(411);// Length Required
    TEST_HTTP_GET(412);// Precondition Failed
    TEST_HTTP_GET(413);// Payload Too Large
    TEST_HTTP_GET(414);// URI Too Long
    TEST_HTTP_GET(415);// Unsupported Media Type
    TEST_HTTP_GET(416);// Range Not Satisfiable
    TEST_HTTP_GET(417);// Expectation Failed
    TEST_HTTP_GET(418);// I'm a teapot
    TEST_HTTP_GET(421);// Misdirected Request
    TEST_HTTP_GET(422);// Unprocessable Entity
    TEST_HTTP_GET(423);// Locked
    TEST_HTTP_GET(424);// Failed Dependency
    TEST_HTTP_GET(425);// Too Early
    TEST_HTTP_GET(426);// Upgrade Required
    TEST_HTTP_GET(428);// Precondition Required
    TEST_HTTP_GET(429);// Too Many Requests
    TEST_HTTP_GET(431);// Request Header Fields Too Large
    TEST_HTTP_GET(451);// Unavailable For Legal Reasons

    // txx
    TEST_HTTP_GET(500);// Internal Server error
    TEST_HTTP_GET(501);// Not Implemented
    TEST_HTTP_GET(502);// Bad Gateway
    TEST_HTTP_GET(503);// Service Unavailable
    TEST_HTTP_GET(504);// Gateway Timeout
    TEST_HTTP_GET(505);// HTTP Version Not Supported
    TEST_HTTP_GET(506);// Variant Also Negotiates
    TEST_HTTP_GET(507);// Insufficient Storage
    TEST_HTTP_GET(508);// Loop Detected
    TEST_HTTP_GET(510);// Not Extended
    TEST_HTTP_GET(511);// Network Authentication Required
}

}// namespace internal
}// namespace tile
