You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.9 KiB
44 lines
1.9 KiB
|
9 years ago
|
#include <ServerContext.hpp>
|
||
|
|
|
||
|
|
std::string TestResponse::string() {
|
||
|
|
buffer = str();
|
||
|
|
return buffer;
|
||
|
|
}
|
||
|
|
std::string TestResponse::message() {
|
||
|
|
if (buffer.empty())
|
||
|
|
string();
|
||
|
|
auto msg = buffer.substr(13, buffer.find('\r') - 13);
|
||
|
|
return msg;
|
||
|
|
}
|
||
|
|
std::string TestResponse::code() {
|
||
|
|
if (buffer.empty())
|
||
|
|
string();
|
||
|
|
return buffer.substr(9, 3);
|
||
|
|
}
|
||
|
|
|
||
|
|
void CommonResponse::service_unavailable(std::shared_ptr<TestResponse> response) {
|
||
|
|
const std::string service_unavailable_json = "HTTP/1.1 503 Service Unavailable\r\nContent-Type: application/json\r\nContent-Length: 43\r\n\r\n{\"code\":503,\"status\":\"Service Unavailable\"}";
|
||
|
|
REQUIRE(response->string() == service_unavailable_json);
|
||
|
|
REQUIRE(response->code() == "503");
|
||
|
|
REQUIRE(response->message() == "Service Unavailable");
|
||
|
|
};
|
||
|
|
void CommonResponse::ok(std::shared_ptr<TestResponse> response, const nlohmann::json &data) {
|
||
|
|
std::string str(data.dump());
|
||
|
|
const std::string res = "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: " + std::to_string(str.size()) + "\r\n\r\n" + str;
|
||
|
|
REQUIRE(response->code() == "200");
|
||
|
|
REQUIRE(response->message() == "OK");
|
||
|
|
REQUIRE(response->string() == res);
|
||
|
|
};
|
||
|
|
void CommonResponse::bad_request(std::shared_ptr<TestResponse> response) {
|
||
|
|
const std::string bad_request_json = "HTTP/1.1 400 Bad Request\r\nContent-Type: application/json\r\nContent-Length: 35\r\n\r\n{\"code\":400,\"status\":\"Bad Request\"}";
|
||
|
|
REQUIRE(response->string() == bad_request_json);
|
||
|
|
REQUIRE(response->code() == "400");
|
||
|
|
REQUIRE(response->message() == "Bad Request");
|
||
|
|
};
|
||
|
|
void CommonResponse::accepted(std::shared_ptr<TestResponse> response) {
|
||
|
|
const std::string accepted = "HTTP/1.1 202 Accepted\r\nContent-Type: application/json\r\nContent-Length: 32\r\n\r\n{\"code\":202,\"status\":\"Accepted\"}";
|
||
|
|
REQUIRE(response->string() == accepted);
|
||
|
|
REQUIRE(response->code() == "202");
|
||
|
|
REQUIRE(response->message() == "Accepted");
|
||
|
|
};
|