1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00
falk-werner_webfuse-provider/test/webfuse_provider/mocks/mock_request.cc
2020-06-16 23:39:45 +02:00

50 lines
1023 B
C++

#include "webfuse_provider/mocks/mock_request.hpp"
#include <cstdlib>
extern "C"
{
static void webfuse_test_MockRequest_respond(
json_t * response,
void * user_data)
{
auto * request = reinterpret_cast<webfuse_test::MockRequest*>(user_data);
json_t * result = json_object_get(response, "result");
json_t * error = json_object_get(response, "error");
json_t * id_holder = json_object_get(response, "id");
int id = -1;
if (json_is_integer(id_holder))
{
id = json_integer_value(id_holder);
}
if (nullptr != result)
{
request->respond(result, id);
}
else
{
request->respond_error(error, id);
}
}
}
namespace webfuse_test
{
struct wfp_request * MockRequest::create_request(int id)
{
auto * request = reinterpret_cast<wfp_request*>(malloc(sizeof(wfp_request)));
request->respond = &webfuse_test_MockRequest_respond;
request->user_data = reinterpret_cast<void*>(this);
request->id = id;
return request;
}
}