1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00
falk-werner_webfuse/test/webfuse/mocks/lookup_matcher.hpp

51 lines
1.2 KiB
C++
Raw Normal View History

2020-06-14 08:39:33 +00:00
#ifndef WF_LOOKUP_MATCHER_HPP
#define WF_LOOKUP_MATCHER_HPP
2020-07-19 07:52:25 +00:00
#include "webfuse/impl/json/node.h"
2020-06-14 08:39:33 +00:00
#include <gmock/gmock.h>
#include <cstring>
namespace webfuse_test
{
MATCHER_P2(Lookup, parent, name, "")
{
2020-07-19 07:52:25 +00:00
if (!wf_impl_json_is_array(arg))
2020-06-14 08:39:33 +00:00
{
*result_listener << "json array expected";
return false;
}
2020-07-19 07:52:25 +00:00
wf_json const * parent_ = wf_impl_json_array_get(arg, 1);
if (!wf_impl_json_is_int(parent_))
2020-06-14 08:39:33 +00:00
{
*result_listener << "parent is expected to be an integer";
return false;
}
2020-07-19 07:52:25 +00:00
if (parent != wf_impl_json_int_get(parent_))
2020-06-14 08:39:33 +00:00
{
*result_listener << "parent mismatch: expected " << parent
2020-07-19 07:52:25 +00:00
<< " but was " << wf_impl_json_int_get(parent_);
2020-06-14 08:39:33 +00:00
return false;
}
2020-07-19 07:52:25 +00:00
wf_json const * name_ = wf_impl_json_array_get(arg, 2);
if (!wf_impl_json_is_string(name_))
2020-06-14 08:39:33 +00:00
{
*result_listener << "name is expected to be a string";
return false;
}
2020-07-19 07:52:25 +00:00
if (0 != strcmp(name, wf_impl_json_string_get(name_)))
2020-06-14 08:39:33 +00:00
{
*result_listener << "name mismatch: expected \"" << name
2020-07-19 07:52:25 +00:00
<< "\" but was \"" << wf_impl_json_string_get(name_) << "\"";
2020-06-14 08:39:33 +00:00
return false;
}
return true;
}
}
#endif