Add test cases for symlinks
This commit is contained in:
parent
8092bfef8e
commit
a974f4f5c0
@ -6,12 +6,14 @@
|
||||
#include "FsppDeviceTest.h"
|
||||
#include "FsppDirTest.h"
|
||||
#include "FsppFileTest.h"
|
||||
#include "FsppSymlinkTest.h"
|
||||
#include "FsppOpenFileTest.h"
|
||||
|
||||
#define FSPP_ADD_FILESYTEM_TESTS(FS_NAME, FIXTURE) \
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(FS_NAME, FsppDeviceTest, FIXTURE); \
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(FS_NAME, FsppDirTest, FIXTURE); \
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(FS_NAME, FsppFileTest, FIXTURE); \
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(FS_NAME, FsppSymlinkTest, FIXTURE); \
|
||||
INSTANTIATE_TYPED_TEST_CASE_P(FS_NAME, FsppOpenFileTest, FIXTURE); \
|
||||
|
||||
#endif
|
||||
|
78
fstest/FsppSymlinkTest.h
Normal file
78
fstest/FsppSymlinkTest.h
Normal file
@ -0,0 +1,78 @@
|
||||
#pragma once
|
||||
#ifndef MESSMER_FSPP_FSTEST_FSPPSYMLINKTEST_H_
|
||||
#define MESSMER_FSPP_FSTEST_FSPPSYMLINKTEST_H_
|
||||
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "testutils/FileSystemTest.h"
|
||||
|
||||
template<class ConcreteFileSystemTestFixture>
|
||||
class FsppSymlinkTest: public FileSystemTest<ConcreteFileSystemTestFixture> {
|
||||
public:
|
||||
void CreateSymlink(const std::string &source, const boost::filesystem::path &target) {
|
||||
this->LoadDir("/")->createSymlink(source, target, 0, 0);
|
||||
}
|
||||
|
||||
void Test_Create_AbsolutePath() {
|
||||
CreateSymlink("mysymlink", "/my/symlink/target");
|
||||
}
|
||||
|
||||
void Test_Create_RelativePath() {
|
||||
CreateSymlink("mysymlink", "../target");
|
||||
}
|
||||
|
||||
void Test_Read_AbsolutePath() {
|
||||
CreateSymlink("mysymlink", "/my/symlink/target");
|
||||
EXPECT_EQ("/my/symlink/target", this->LoadSymlink("/mysymlink")->target());
|
||||
}
|
||||
|
||||
void Test_Read_RelativePath() {
|
||||
CreateSymlink("mysymlink", "../target");
|
||||
EXPECT_EQ("../target", this->LoadSymlink("/mysymlink")->target());
|
||||
}
|
||||
|
||||
void Test_Delete() {
|
||||
CreateSymlink("mysymlink", "/my/symlink/target");
|
||||
std::cerr << "1" << std::endl;
|
||||
EXPECT_NE(boost::none, this->device->Load("/mysymlink"));
|
||||
std::cerr << "2" << std::endl;
|
||||
this->LoadSymlink("/mysymlink")->remove();
|
||||
std::cerr << "3" << std::endl;
|
||||
EXPECT_EQ(boost::none, this->device->Load("/mysymlink"));
|
||||
}
|
||||
};
|
||||
|
||||
TYPED_TEST_CASE_P(FsppSymlinkTest);
|
||||
|
||||
TYPED_TEST_P(FsppSymlinkTest, Create_AbsolutePath) {
|
||||
this->Test_Create_AbsolutePath();
|
||||
}
|
||||
|
||||
TYPED_TEST_P(FsppSymlinkTest, Create_RelativePath) {
|
||||
this->Test_Create_RelativePath();
|
||||
}
|
||||
|
||||
TYPED_TEST_P(FsppSymlinkTest, Read_AbsolutePath) {
|
||||
this->Test_Read_AbsolutePath();
|
||||
}
|
||||
|
||||
TYPED_TEST_P(FsppSymlinkTest, Read_RelativePath) {
|
||||
this->Test_Read_RelativePath();
|
||||
}
|
||||
|
||||
TYPED_TEST_P(FsppSymlinkTest, Delete) {
|
||||
this->Test_Delete();
|
||||
}
|
||||
|
||||
REGISTER_TYPED_TEST_CASE_P(FsppSymlinkTest,
|
||||
Create_AbsolutePath,
|
||||
Create_RelativePath,
|
||||
Read_AbsolutePath,
|
||||
Read_RelativePath,
|
||||
Delete
|
||||
);
|
||||
|
||||
//TODO Other tests?
|
||||
|
||||
#endif
|
@ -11,6 +11,7 @@
|
||||
#include "../../fs_interface/Device.h"
|
||||
#include "../../fs_interface/Dir.h"
|
||||
#include "../../fs_interface/File.h"
|
||||
#include "../../fs_interface/Symlink.h"
|
||||
#include "../../fs_interface/OpenFile.h"
|
||||
|
||||
class FileSystemTestFixture {
|
||||
@ -49,6 +50,14 @@ public:
|
||||
EXPECT_NE(boost::none, file);
|
||||
return std::move(*file);
|
||||
}
|
||||
|
||||
cpputils::unique_ref<fspp::Symlink> LoadSymlink(const boost::filesystem::path &path) {
|
||||
auto loaded = device->Load(path);
|
||||
EXPECT_NE(boost::none, loaded);
|
||||
auto symlink = cpputils::dynamic_pointer_move<fspp::Symlink>(*loaded);
|
||||
EXPECT_NE(boost::none, symlink);
|
||||
return std::move(*symlink);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user