2015-10-15 13:04:57 +02:00
|
|
|
#pragma once
|
2015-03-19 05:47:06 +01:00
|
|
|
#ifndef MESSMER_FSPP_FSTEST_TESTUTILS_FILETEST_H_
|
|
|
|
#define MESSMER_FSPP_FSTEST_TESTUTILS_FILETEST_H_
|
|
|
|
|
|
|
|
#include "FileSystemTest.h"
|
2015-04-25 03:36:30 +02:00
|
|
|
#include <messmer/cpp-utils/data/Data.h>
|
2015-06-21 17:44:30 +02:00
|
|
|
#include <messmer/cpp-utils/pointer/unique_ref.h>
|
2015-03-19 05:47:06 +01:00
|
|
|
|
|
|
|
template<class ConcreteFileSystemTestFixture>
|
|
|
|
class FileTest: public FileSystemTest<ConcreteFileSystemTestFixture> {
|
|
|
|
public:
|
2015-10-17 21:34:15 +02:00
|
|
|
FileTest(): file_root(), file_nested() {
|
2015-04-25 03:36:30 +02:00
|
|
|
this->LoadDir("/")->createAndOpenFile("myfile", this->MODE_PUBLIC, 0, 0);
|
2015-06-18 19:30:52 +02:00
|
|
|
file_root = cpputils::to_unique_ptr(this->LoadFile("/myfile"));
|
2015-03-19 05:47:06 +01:00
|
|
|
|
2015-04-25 03:36:30 +02:00
|
|
|
this->LoadDir("/")->createDir("mydir", this->MODE_PUBLIC, 0, 0);
|
|
|
|
this->LoadDir("/mydir")->createAndOpenFile("mynestedfile", this->MODE_PUBLIC, 0, 0);
|
2015-06-18 19:30:52 +02:00
|
|
|
file_nested = cpputils::to_unique_ptr(this->LoadFile("/mydir/mynestedfile"));
|
2015-03-19 05:47:06 +01:00
|
|
|
}
|
|
|
|
std::unique_ptr<fspp::File> file_root;
|
|
|
|
std::unique_ptr<fspp::File> file_nested;
|
|
|
|
|
|
|
|
void EXPECT_SIZE(uint64_t expectedSize, const fspp::File &file) {
|
|
|
|
EXPECT_SIZE_IN_FILE(expectedSize, file);
|
|
|
|
auto openFile = file.open(O_RDONLY);
|
|
|
|
EXPECT_SIZE_IN_OPEN_FILE(expectedSize, *openFile);
|
|
|
|
EXPECT_NUMBYTES_READABLE(expectedSize, *openFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EXPECT_SIZE_IN_FILE(uint64_t expectedSize, const fspp::File &file) {
|
|
|
|
struct stat st;
|
|
|
|
file.stat(&st);
|
|
|
|
EXPECT_EQ(expectedSize, st.st_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EXPECT_SIZE_IN_OPEN_FILE(uint64_t expectedSize, const fspp::OpenFile &file) {
|
|
|
|
struct stat st;
|
|
|
|
file.stat(&st);
|
|
|
|
EXPECT_EQ(expectedSize, st.st_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EXPECT_NUMBYTES_READABLE(uint64_t expectedSize, const fspp::OpenFile &file) {
|
2015-04-25 03:26:59 +02:00
|
|
|
cpputils::Data data(expectedSize);
|
2015-03-19 05:47:06 +01:00
|
|
|
//Try to read one byte more than the expected size
|
|
|
|
ssize_t readBytes = file.read(data.data(), expectedSize+1, 0);
|
|
|
|
//and check that it only read the expected size (but also not less)
|
|
|
|
EXPECT_EQ(expectedSize, readBytes);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|