2020-06-16 21:39:45 +00:00
|
|
|
#include "webfuse_provider/impl/operation/open.h"
|
|
|
|
#include "webfuse_provider/mocks/mock_request.hpp"
|
|
|
|
#include "webfuse_provider/mocks/mock_provider.hpp"
|
|
|
|
#include "webfuse_provider/mocks/fake_invokation_context.hpp"
|
2020-07-12 11:06:00 +00:00
|
|
|
#include "webfuse_provider/test_util/json_doc.hpp"
|
2020-03-30 19:42:13 +00:00
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
using ::webfuse_test::MockProvider;
|
|
|
|
using ::webfuse_test::MockRequest;
|
|
|
|
using ::webfuse_test::OpenMatcher;
|
|
|
|
using ::webfuse_test::create_context;
|
2020-07-12 11:06:00 +00:00
|
|
|
using ::webfuse_test::JsonDoc;
|
2020-03-30 19:42:13 +00:00
|
|
|
using ::testing::_;
|
|
|
|
using ::testing::Invoke;
|
|
|
|
using ::testing::StrEq;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
void free_request(wfp_request * request, ino_t, int)
|
|
|
|
{
|
2020-07-12 11:06:00 +00:00
|
|
|
wfp_impl_request_dispose(request);
|
2020-03-30 19:42:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(wfp_impl_open, invoke_provider)
|
|
|
|
{
|
|
|
|
MockProvider provider;
|
2020-07-12 11:06:00 +00:00
|
|
|
EXPECT_CALL(provider,open(_, 42, 0)).Times(1)
|
2020-03-30 19:42:13 +00:00
|
|
|
.WillOnce(Invoke(free_request));
|
|
|
|
|
|
|
|
wfp_request request = {nullptr, nullptr, 0};
|
|
|
|
wfp_impl_invokation_context context = create_context(provider, &request);
|
|
|
|
|
2020-07-12 11:06:00 +00:00
|
|
|
JsonDoc doc("[\"test.filesystem\",42,0]");
|
|
|
|
wfp_impl_open(&context, doc.root(), 42);
|
2020-03-30 19:42:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(wfp_impl_open, fail_invalid_param_count)
|
|
|
|
{
|
|
|
|
MockProvider provider;
|
|
|
|
EXPECT_CALL(provider,open(_, _, _)).Times(0);
|
|
|
|
|
|
|
|
wfp_request request = {nullptr, nullptr, 0};
|
|
|
|
wfp_impl_invokation_context context = create_context(provider, &request);
|
|
|
|
|
2020-07-12 11:06:00 +00:00
|
|
|
JsonDoc doc("[\"test.filesystem\", 23]");
|
|
|
|
wfp_impl_open(&context, doc.root(), 42);
|
2020-03-30 19:42:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(wfp_impl_open, fail_invalid_inode_type)
|
|
|
|
{
|
|
|
|
MockProvider provider;
|
|
|
|
EXPECT_CALL(provider,open(_, _, _)).Times(0);
|
|
|
|
|
|
|
|
wfp_request request = {nullptr, nullptr, 0};
|
|
|
|
wfp_impl_invokation_context context = create_context(provider, &request);
|
|
|
|
|
2020-07-12 11:06:00 +00:00
|
|
|
JsonDoc doc("[\"test.filesystem\", \"\", 0]");
|
|
|
|
wfp_impl_open(&context, doc.root(), 42);
|
2020-03-30 19:42:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(wfp_impl_open, fail_invalid_flags_type)
|
|
|
|
{
|
|
|
|
MockProvider provider;
|
|
|
|
EXPECT_CALL(provider,open(_, _, _)).Times(0);
|
|
|
|
|
|
|
|
wfp_request request = {nullptr, nullptr, 0};
|
|
|
|
wfp_impl_invokation_context context = create_context(provider, &request);
|
|
|
|
|
2020-07-12 11:06:00 +00:00
|
|
|
JsonDoc doc("[\"test.filesystem\", 23, \"\"]");
|
|
|
|
wfp_impl_open(&context, doc.root(), 42);
|
2020-03-30 19:42:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(wfp_impl_open, default_responds_error)
|
|
|
|
{
|
|
|
|
MockRequest request;
|
|
|
|
auto * req = request.create_request(42);
|
|
|
|
EXPECT_CALL(request, respond_error(_,42)).Times(1);
|
|
|
|
|
|
|
|
wfp_impl_open_default(req, 1, 0, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(wfp_impl_open, respond)
|
|
|
|
{
|
|
|
|
MockRequest request;
|
|
|
|
auto * req = request.create_request(42);
|
|
|
|
EXPECT_CALL(request, respond(OpenMatcher(23), 42)).Times(1);
|
|
|
|
|
|
|
|
wfp_impl_respond_open(req, 23);
|
|
|
|
}
|
|
|
|
|