2020-06-16 21:57:41 +00:00
|
|
|
#ifndef WFP_MOCK_REQUEST_HPP
|
|
|
|
#define WFP_MOCK_REQUEST_HPP
|
2019-04-26 18:49:09 +00:00
|
|
|
|
2020-07-12 11:06:00 +00:00
|
|
|
#include "webfuse_provider/impl/request.h"
|
|
|
|
#include "webfuse_provider/impl/json/node.h"
|
2019-04-26 18:49:09 +00:00
|
|
|
#include <gmock/gmock.h>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
|
|
|
|
namespace webfuse_test
|
|
|
|
{
|
|
|
|
|
2020-03-29 18:41:31 +00:00
|
|
|
class MockRequest
|
2019-04-26 18:49:09 +00:00
|
|
|
{
|
|
|
|
public:
|
2020-03-29 18:41:31 +00:00
|
|
|
struct wfp_request * create_request(int id);
|
2020-07-12 11:06:00 +00:00
|
|
|
MOCK_METHOD2(respond, void(wfp_json const * result, int id));
|
|
|
|
MOCK_METHOD2(respond_error, void(int error_code, int id));
|
2019-04-26 18:49:09 +00:00
|
|
|
};
|
|
|
|
|
2020-03-30 19:16:32 +00:00
|
|
|
MATCHER_P3(StatMatcher, inode, mode, file_type, "")
|
2019-04-26 18:49:09 +00:00
|
|
|
{
|
2020-07-12 11:06:00 +00:00
|
|
|
wfp_json const * inode_holder = wfp_impl_json_object_get(arg, "inode");
|
|
|
|
if ((!wfp_impl_json_is_int(inode_holder)) || (inode != wfp_impl_json_get_int(inode_holder)))
|
2019-04-26 18:49:09 +00:00
|
|
|
{
|
|
|
|
*result_listener << "missing inode";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-12 11:06:00 +00:00
|
|
|
wfp_json const * mode_holder = wfp_impl_json_object_get(arg, "mode");
|
|
|
|
if ((!wfp_impl_json_is_int(mode_holder)) || (mode != wfp_impl_json_get_int(mode_holder)))
|
2019-04-26 18:49:09 +00:00
|
|
|
{
|
|
|
|
*result_listener << "missing mode";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-12 11:06:00 +00:00
|
|
|
wfp_json const * type_holder = wfp_impl_json_object_get(arg, "type");
|
|
|
|
if ((!wfp_impl_json_is_string(type_holder)) || (0 != strcmp(file_type, wfp_impl_json_get_string(type_holder))))
|
2019-04-26 18:49:09 +00:00
|
|
|
{
|
|
|
|
*result_listener << "missing type";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-30 19:42:13 +00:00
|
|
|
MATCHER_P(OpenMatcher, handle, "")
|
|
|
|
{
|
2020-07-12 11:06:00 +00:00
|
|
|
wfp_json const * handle_holder = wfp_impl_json_object_get(arg, "handle");
|
|
|
|
if ((!wfp_impl_json_is_int(handle_holder)) || (handle != wfp_impl_json_get_int(handle_holder)))
|
2020-03-30 19:42:13 +00:00
|
|
|
{
|
|
|
|
*result_listener << "missing handle";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-30 20:25:14 +00:00
|
|
|
MATCHER_P3(ReadResultMatcher, data, format, count, "")
|
|
|
|
{
|
2020-07-12 11:06:00 +00:00
|
|
|
wfp_json const * format_holder = wfp_impl_json_object_get(arg, "format");
|
|
|
|
if ((!wfp_impl_json_is_string(format_holder)) || (0 != strcmp(format, wfp_impl_json_get_string(format_holder))))
|
2020-03-30 20:25:14 +00:00
|
|
|
{
|
2020-07-12 11:06:00 +00:00
|
|
|
*result_listener << "invalid or missing format: " << wfp_impl_json_get_string(format_holder);
|
2020-03-30 20:25:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-12 11:06:00 +00:00
|
|
|
wfp_json const * count_holder = wfp_impl_json_object_get(arg, "count");
|
|
|
|
if ((!wfp_impl_json_is_int(count_holder)) || (count != wfp_impl_json_get_int(count_holder)))
|
2020-03-30 20:25:14 +00:00
|
|
|
{
|
2020-07-12 11:06:00 +00:00
|
|
|
*result_listener << "invalid or missing count: " << wfp_impl_json_get_int(count_holder);
|
2020-03-30 20:25:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-12 11:06:00 +00:00
|
|
|
wfp_json const * data_holder = wfp_impl_json_object_get(arg, "data");
|
|
|
|
if ((!wfp_impl_json_is_string(data_holder)) || (0 != strcmp(data, wfp_impl_json_get_string(data_holder))))
|
2020-03-30 20:25:14 +00:00
|
|
|
{
|
2020-07-12 11:06:00 +00:00
|
|
|
*result_listener << "invalid or missing data: " << wfp_impl_json_get_string(data_holder);
|
2020-03-30 20:25:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-26 18:49:09 +00:00
|
|
|
MATCHER_P(ReaddirMatcher, contained_elements , "")
|
|
|
|
{
|
2020-07-12 11:06:00 +00:00
|
|
|
if (!wfp_impl_json_is_array(arg))
|
2019-04-26 18:49:09 +00:00
|
|
|
{
|
|
|
|
*result_listener << "result is not array";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-07-12 11:06:00 +00:00
|
|
|
for(size_t i = 0; i < wfp_impl_json_array_size(arg); i++)
|
2019-04-26 18:49:09 +00:00
|
|
|
{
|
2020-07-12 11:06:00 +00:00
|
|
|
wfp_json const * value = wfp_impl_json_array_get(arg, i);
|
|
|
|
wfp_json const * inode = wfp_impl_json_object_get(value, "inode");
|
|
|
|
wfp_json const * name = wfp_impl_json_object_get(value, "name");
|
2019-04-26 18:49:09 +00:00
|
|
|
|
2020-07-12 11:06:00 +00:00
|
|
|
if(!wfp_impl_json_is_int(inode))
|
2019-04-26 18:49:09 +00:00
|
|
|
{
|
|
|
|
*result_listener << "invalid result: missing inode";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-12 11:06:00 +00:00
|
|
|
if (!wfp_impl_json_is_string(name))
|
2019-04-26 18:49:09 +00:00
|
|
|
{
|
|
|
|
*result_listener << "invalid result: missing name";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(size_t i = 0; NULL != contained_elements[i]; i++)
|
|
|
|
{
|
|
|
|
char const * element = contained_elements[i];
|
|
|
|
bool found = false;
|
|
|
|
|
2020-07-12 11:06:00 +00:00
|
|
|
for(size_t j = 0; j < wfp_impl_json_array_size(arg); j++)
|
2019-04-26 18:49:09 +00:00
|
|
|
{
|
2020-07-12 11:06:00 +00:00
|
|
|
wfp_json const * value = wfp_impl_json_array_get(arg, j);
|
|
|
|
wfp_json const * name = wfp_impl_json_object_get(value, "name");
|
2019-04-26 18:49:09 +00:00
|
|
|
|
2020-07-12 11:06:00 +00:00
|
|
|
found = (0 == strcmp(element, wfp_impl_json_get_string(name)));
|
2019-04-26 18:49:09 +00:00
|
|
|
if (found)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
*result_listener << "missing required directory element: " << element;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|