#define BOOST_TEST_MODULE http
#include <boost/test/included/unit_test.hpp>
#include <kooling/http/http.h>
#include <kooling/json/json.h>
#include <string_view>
BOOST_AUTO_TEST_SUITE(test_http)<--- There is an unknown macro here somewhere. Configuration is required. If BOOST_AUTO_TEST_SUITE is a macro then please configure it.
constexpr std::string_view endpoint{ "https://osm.kooling.net/api/interpreter" };
constexpr std::string_view param_key{ "data" };
constexpr std::string_view param_val{ "[out:json][timeout:25];(way['railway'='rail'](around:600,51.5347,0.1246););out tags;" };
BOOST_AUTO_TEST_CASE(test_http_get)
{
std::string out;
kooling::http::headers headers;
headers.push_back(std::make_pair(std::string{ param_key }, std::string{ param_val }));
std::string url{ endpoint };
url.append("/?").append(param_key).append("=").append(kooling::http::url_encode(param_val));
const auto read{ [&out](std::string&& s) { out = std::move(s); } };
const auto status{ kooling::http::send(kooling::http::get{}, url, {}, read) };
BOOST_TEST(*status == 200);
const auto response = json_t::parse(out);
BOOST_TEST(response["elements"].size() > 5UL);
}
BOOST_AUTO_TEST_CASE(test_http_post)
{
std::string out;
const auto write{ [](std::string& s) { s.append(param_key).append("=").append(param_val); } };
const auto read{ [&out](std::string&& s) { out = std::move(s); } };
const auto status{ kooling::http::send(kooling::http::post{}, endpoint, {}, write, read) };
BOOST_TEST(*status == 200);
const auto response = json_t::parse(out);
BOOST_TEST(response["elements"].size() > 5UL);
}
BOOST_AUTO_TEST_SUITE_END()