1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00
falk-werner_webfuse/test/mock_request.cc
Falk Werner fa78e23533
feat(webfuse): static file provider (#30)
* added API stub of static_filesystem

* added callback functions

* added basic directory listing

* resize filesystem if necessary

* added path stub

* adds imlementation and tests of path

* adds mock of wpf_request

* adds test implementation and some matchers

* added matcher of readdir results

* fixes default directory test

* adds implementation of static_filesystem_add and add_text

* added implementation of read

* adds implementation of filesystem_read

* corrects naming of some functions

* removes Flawfinder comments, since Flawfinder is disabled
2019-04-26 20:49:09 +02:00

55 lines
1003 B
C++

#include "mock_request.hpp"
#include <cstdlib>
namespace
{
extern "C" void
respond(
json_t * response,
void * user_data)
{
webfuse_test::Request * request = reinterpret_cast<webfuse_test::Request*>(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 *
request_create(
Request * req,
int id)
{
struct wfp_request * request = reinterpret_cast<struct wfp_request *>(malloc(sizeof(struct wfp_request)));
request->id = id;
request->user_data = reinterpret_cast<void*>(req);
request->respond = &respond;
return request;
}
}