2020-02-20 16:15:13 +00:00
|
|
|
#include "webfuse/mocks/mock_request.hpp"
|
2019-04-26 18:49:09 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
|
2020-03-29 18:41:31 +00:00
|
|
|
extern "C"
|
2019-04-26 18:49:09 +00:00
|
|
|
{
|
|
|
|
|
2020-03-29 18:41:31 +00:00
|
|
|
static void webfuse_test_MockRequest_respond(
|
2019-04-26 18:49:09 +00:00
|
|
|
json_t * response,
|
|
|
|
void * user_data)
|
|
|
|
{
|
2020-03-29 18:41:31 +00:00
|
|
|
auto * request = reinterpret_cast<webfuse_test::MockRequest*>(user_data);
|
2019-04-26 18:49:09 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
2020-03-29 18:41:31 +00:00
|
|
|
struct wfp_request * MockRequest::create_request(int id)
|
2019-04-26 18:49:09 +00:00
|
|
|
{
|
2020-03-29 18:41:31 +00:00
|
|
|
auto * request = reinterpret_cast<wfp_request*>(malloc(sizeof(wfp_request)));
|
|
|
|
request->respond = &webfuse_test_MockRequest_respond;
|
|
|
|
request->user_data = reinterpret_cast<void*>(this);
|
2019-04-26 18:49:09 +00:00
|
|
|
request->id = id;
|
|
|
|
|
|
|
|
return request;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|