Create truncate Test
This commit is contained in:
parent
10142c2a36
commit
1197990539
@ -6,7 +6,7 @@ using ::testing::WithParamInterface;
|
|||||||
using ::testing::Values;
|
using ::testing::Values;
|
||||||
using ::testing::Return;
|
using ::testing::Return;
|
||||||
|
|
||||||
class FuseCreateAndOpenFlagsTest: public FuseCreateAndOpenTest, public WithParamInterface<unsigned int> {
|
class FuseCreateAndOpenFlagsTest: public FuseCreateAndOpenTest, public WithParamInterface<mode_t> {
|
||||||
};
|
};
|
||||||
INSTANTIATE_TEST_CASE_P(FuseCreateAndOpenFlagsTest, FuseCreateAndOpenFlagsTest, Values(O_RDWR, O_RDONLY, O_WRONLY));
|
INSTANTIATE_TEST_CASE_P(FuseCreateAndOpenFlagsTest, FuseCreateAndOpenFlagsTest, Values(O_RDWR, O_RDONLY, O_WRONLY));
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifndef TEST_FSPP_FUSE_OPENFILE_TESTUTILS_FUSECREATEANDOPENTEST_H_
|
#ifndef TEST_FSPP_FUSE_CREATEANDOPENFILE_TESTUTILS_FUSECREATEANDOPENTEST_H_
|
||||||
#define TEST_FSPP_FUSE_OPENFILE_TESTUTILS_FUSECREATEANDOPENTEST_H_
|
#define TEST_FSPP_FUSE_CREATEANDOPENFILE_TESTUTILS_FUSECREATEANDOPENTEST_H_
|
||||||
|
|
||||||
#include "test/testutils/FuseTest.h"
|
#include "test/testutils/FuseTest.h"
|
||||||
|
|
||||||
|
27
src/test/fspp/fuse/truncate/FuseTruncateErrorTest.cpp
Normal file
27
src/test/fspp/fuse/truncate/FuseTruncateErrorTest.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include "testutils/FuseTruncateTest.h"
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include "gmock/gmock.h"
|
||||||
|
|
||||||
|
#include "fspp/impl/FuseErrnoException.h"
|
||||||
|
|
||||||
|
using ::testing::_;
|
||||||
|
using ::testing::StrEq;
|
||||||
|
using ::testing::Throw;
|
||||||
|
using ::testing::WithParamInterface;
|
||||||
|
using ::testing::Values;
|
||||||
|
|
||||||
|
using namespace fspp;
|
||||||
|
|
||||||
|
class FuseTruncateErrorTest: public FuseTruncateTest, public WithParamInterface<int> {
|
||||||
|
};
|
||||||
|
INSTANTIATE_TEST_CASE_P(FuseTruncateErrorTest, FuseTruncateErrorTest, Values(EACCES, EFAULT, EFBIG, EINTR, EINVAL, EIO, EISDIR, ELOOP, ENAMETOOLONG, ENOENT, ENOTDIR, EPERM, EROFS, ETXTBSY));
|
||||||
|
|
||||||
|
TEST_P(FuseTruncateErrorTest, TruncateFile) {
|
||||||
|
ReturnIsFileOnLstat(FILENAME);
|
||||||
|
EXPECT_CALL(fsimpl, truncate(StrEq(FILENAME), _))
|
||||||
|
.Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
|
||||||
|
|
||||||
|
int fd = TruncateFileAllowError(FILENAME, 0);
|
||||||
|
EXPECT_EQ(GetParam(), errno);
|
||||||
|
EXPECT_EQ(-1, fd);
|
||||||
|
}
|
38
src/test/fspp/fuse/truncate/FuseTruncateFilenameTest.cpp
Normal file
38
src/test/fspp/fuse/truncate/FuseTruncateFilenameTest.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include "testutils/FuseTruncateTest.h"
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include "gmock/gmock.h"
|
||||||
|
|
||||||
|
|
||||||
|
using ::testing::_;
|
||||||
|
using ::testing::StrEq;
|
||||||
|
using ::testing::Return;
|
||||||
|
|
||||||
|
class FuseTruncateFilenameTest: public FuseTruncateTest {
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(FuseTruncateFilenameTest, TruncateFile) {
|
||||||
|
ReturnIsFileOnLstat("/myfile");
|
||||||
|
EXPECT_CALL(fsimpl, truncate(StrEq("/myfile"), _))
|
||||||
|
.Times(1).WillOnce(Return());
|
||||||
|
|
||||||
|
TruncateFile("/myfile", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(FuseTruncateFilenameTest, TruncateFileNested) {
|
||||||
|
ReturnIsDirOnLstat("/mydir");
|
||||||
|
ReturnIsFileOnLstat("/mydir/myfile");
|
||||||
|
EXPECT_CALL(fsimpl, truncate(StrEq("/mydir/myfile"), _))
|
||||||
|
.Times(1).WillOnce(Return());
|
||||||
|
|
||||||
|
TruncateFile("/mydir/myfile", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(FuseTruncateFilenameTest, TruncateFileNested2) {
|
||||||
|
ReturnIsDirOnLstat("/mydir");
|
||||||
|
ReturnIsDirOnLstat("/mydir/mydir2");
|
||||||
|
ReturnIsFileOnLstat("/mydir/mydir2/myfile");
|
||||||
|
EXPECT_CALL(fsimpl, truncate(StrEq("/mydir/mydir2/myfile"), _))
|
||||||
|
.Times(1).WillOnce(Return());
|
||||||
|
|
||||||
|
TruncateFile("/mydir/mydir2/myfile", 0);
|
||||||
|
}
|
23
src/test/fspp/fuse/truncate/FuseTruncateSizeTest.cpp
Normal file
23
src/test/fspp/fuse/truncate/FuseTruncateSizeTest.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include "testutils/FuseTruncateTest.h"
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include "gmock/gmock.h"
|
||||||
|
|
||||||
|
|
||||||
|
using ::testing::_;
|
||||||
|
using ::testing::StrEq;
|
||||||
|
using ::testing::Return;
|
||||||
|
using ::testing::WithParamInterface;
|
||||||
|
using ::testing::Values;
|
||||||
|
|
||||||
|
class FuseTruncateSizeTest: public FuseTruncateTest, public WithParamInterface<off_t> {
|
||||||
|
};
|
||||||
|
INSTANTIATE_TEST_CASE_P(FuseTruncateSizeTest, FuseTruncateSizeTest, Values(0, 1, 10, 1024, 1024*1024*1024));
|
||||||
|
|
||||||
|
|
||||||
|
TEST_P(FuseTruncateSizeTest, TruncateFile) {
|
||||||
|
ReturnIsFileOnLstat(FILENAME);
|
||||||
|
EXPECT_CALL(fsimpl, truncate(StrEq(FILENAME), GetParam()))
|
||||||
|
.Times(1).WillOnce(Return());
|
||||||
|
|
||||||
|
TruncateFile(FILENAME, GetParam());
|
||||||
|
}
|
13
src/test/fspp/fuse/truncate/testutils/FuseTruncateTest.cpp
Normal file
13
src/test/fspp/fuse/truncate/testutils/FuseTruncateTest.cpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#include "FuseTruncateTest.h"
|
||||||
|
|
||||||
|
void FuseTruncateTest::TruncateFile(const char *filename, off_t size) {
|
||||||
|
int retval = TruncateFileAllowError(filename, size);
|
||||||
|
EXPECT_EQ(0, retval);
|
||||||
|
}
|
||||||
|
|
||||||
|
int FuseTruncateTest::TruncateFileAllowError(const char *filename, off_t size) {
|
||||||
|
auto fs = TestFS();
|
||||||
|
|
||||||
|
auto realpath = fs->mountDir() / filename;
|
||||||
|
return ::truncate(realpath.c_str(), size);
|
||||||
|
}
|
15
src/test/fspp/fuse/truncate/testutils/FuseTruncateTest.h
Normal file
15
src/test/fspp/fuse/truncate/testutils/FuseTruncateTest.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifndef TEST_FSPP_FUSE_TRUNCATE_TESTUTILS_FUSETRUNCATETEST_H_
|
||||||
|
#define TEST_FSPP_FUSE_TRUNCATE_TESTUTILS_FUSETRUNCATETEST_H_
|
||||||
|
|
||||||
|
#include "test/testutils/FuseTest.h"
|
||||||
|
|
||||||
|
class FuseTruncateTest: public FuseTest {
|
||||||
|
public:
|
||||||
|
const char *FILENAME = "/myfile";
|
||||||
|
|
||||||
|
void TruncateFile(const char *filename, off_t size);
|
||||||
|
int TruncateFileAllowError(const char *filename, off_t size);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user