353f287bde
* Added an option to create a mountpoint with a missing directory It skips the normal confirmation message, which makes cryfs easier to use in scripts, or can be aliased for quicker use. * separated basedir and mountpoint autocreate flags, and added tests * Werror and clang-tidy fixes added to the ChangeLog * fixed the bugs that clang-tidy caused never used clang before, so I don't really know what it did and why it caused compile errors
45 lines
1.6 KiB
C++
45 lines
1.6 KiB
C++
#include "testutils/FuseCreateAndOpenTest.h"
|
|
|
|
using ::testing::_;
|
|
using ::testing::Eq;
|
|
using ::testing::WithParamInterface;
|
|
using ::testing::Values;
|
|
using ::testing::Return;
|
|
using cpputils::unique_ref;
|
|
using cpputils::make_unique_ref;
|
|
|
|
class FuseCreateAndOpenFileDescriptorTest: public FuseCreateAndOpenTest, public WithParamInterface<int> {
|
|
public:
|
|
void CreateAndOpenAndReadFile(const char *filename) {
|
|
auto fs = TestFS();
|
|
|
|
auto fd = CreateAndOpenFile(fs.get(), filename);
|
|
ReadFile(fd->fd());
|
|
}
|
|
|
|
private:
|
|
unique_ref<OpenFileHandle> CreateAndOpenFile(const TempTestFS *fs, const char *filename) {
|
|
auto realpath = fs->mountDir() / filename;
|
|
auto fd = make_unique_ref<OpenFileHandle>(realpath.string().c_str(), O_RDONLY | O_CREAT, S_IRUSR | S_IRGRP | S_IROTH);
|
|
EXPECT_GE(fd->fd(), 0) << "Creating file failed";
|
|
return fd;
|
|
}
|
|
void ReadFile(int fd) {
|
|
uint8_t buf = 0;
|
|
int retval = ::read(fd, &buf, 1);
|
|
EXPECT_EQ(1, retval) << "Reading file failed";
|
|
}
|
|
};
|
|
INSTANTIATE_TEST_SUITE_P(FuseCreateAndOpenFileDescriptorTest, FuseCreateAndOpenFileDescriptorTest, Values(0, 2, 5, 1000, 1024*1024*1024));
|
|
|
|
TEST_P(FuseCreateAndOpenFileDescriptorTest, TestReturnedFileDescriptor) {
|
|
ReturnDoesntExistOnLstat(FILENAME);
|
|
EXPECT_CALL(*fsimpl, createAndOpenFile(Eq(FILENAME), _, _, _))
|
|
.Times(1).WillOnce(Return(GetParam()));
|
|
EXPECT_CALL(*fsimpl, read(GetParam(), _, _, _)).Times(1).WillOnce(Return(fspp::num_bytes_t(1)));
|
|
//For the syscall to succeed, we also need to give an fstat implementation.
|
|
ReturnIsFileOnFstatWithSize(GetParam(), fspp::num_bytes_t(1));
|
|
|
|
CreateAndOpenAndReadFile(FILENAME);
|
|
}
|