2015-10-15 13:04:57 +02:00
|
|
|
#pragma once
|
2015-03-19 05:37:44 +01:00
|
|
|
#ifndef MESSMER_FSPP_FSTEST_FSPPOPENFILETEST_H_
|
|
|
|
#define MESSMER_FSPP_FSTEST_FSPPOPENFILETEST_H_
|
|
|
|
|
2015-03-19 05:47:06 +01:00
|
|
|
#include "testutils/FileTest.h"
|
|
|
|
|
2015-03-19 05:37:44 +01:00
|
|
|
template<class ConcreteFileSystemTestFixture>
|
2017-01-21 19:16:35 +00:00
|
|
|
class FsppOpenFileTest: public FileSystemTest<ConcreteFileSystemTestFixture> {
|
2015-03-19 05:37:44 +01:00
|
|
|
public:
|
2018-09-13 22:38:05 -07:00
|
|
|
void IN_STAT(fspp::OpenFile *openFile, std::function<void (const fspp::OpenFile::stat_info&)> callback) {
|
|
|
|
auto st = openFile->stat();
|
2017-01-21 19:16:35 +00:00
|
|
|
callback(st);
|
|
|
|
}
|
|
|
|
|
2018-09-15 14:32:58 -07:00
|
|
|
void EXPECT_SIZE(fspp::num_bytes_t expectedSize, fspp::OpenFile *openFile) {
|
2018-09-13 22:38:05 -07:00
|
|
|
IN_STAT(openFile, [expectedSize] (const fspp::OpenFile::stat_info& st) {
|
2018-09-15 14:32:58 -07:00
|
|
|
EXPECT_EQ(expectedSize, st.size);
|
2017-01-21 19:16:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
EXPECT_NUMBYTES_READABLE(expectedSize, openFile);
|
|
|
|
}
|
|
|
|
|
2018-09-15 14:32:58 -07:00
|
|
|
void EXPECT_NUMBYTES_READABLE(fspp::num_bytes_t expectedSize, fspp::OpenFile *openFile) {
|
|
|
|
cpputils::Data data(expectedSize.value());
|
2017-01-21 19:16:35 +00:00
|
|
|
//Try to read one byte more than the expected size
|
2018-09-15 14:32:58 -07:00
|
|
|
fspp::num_bytes_t readBytes = openFile->read(data.data(), expectedSize+fspp::num_bytes_t(1), fspp::num_bytes_t(0));
|
2017-01-21 19:16:35 +00:00
|
|
|
//and check that it only read the expected size (but also not less)
|
2018-09-15 14:32:58 -07:00
|
|
|
EXPECT_EQ(expectedSize, readBytes);
|
2017-01-21 19:16:35 +00:00
|
|
|
}
|
2015-03-19 05:37:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
TYPED_TEST_CASE_P(FsppOpenFileTest);
|
|
|
|
|
2017-01-21 19:16:35 +00:00
|
|
|
TYPED_TEST_P(FsppOpenFileTest, CreatedFileIsEmpty) {
|
|
|
|
auto file = this->CreateFile("/myfile");
|
|
|
|
auto openFile = this->LoadFile("/myfile")->open(O_RDONLY);
|
2018-09-15 14:32:58 -07:00
|
|
|
this->EXPECT_SIZE(fspp::num_bytes_t(0), openFile.get());
|
2017-01-21 19:16:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TYPED_TEST_P(FsppOpenFileTest, FileIsFile) {
|
|
|
|
auto file = this->CreateFile("/myfile");
|
|
|
|
auto openFile = this->LoadFile("/myfile")->open(O_RDONLY);
|
2018-09-13 22:38:05 -07:00
|
|
|
this->IN_STAT(openFile.get(), [] (const fspp::OpenFile::stat_info& st) {
|
2018-09-14 02:34:11 -07:00
|
|
|
EXPECT_TRUE(st.mode.hasFileFlag());
|
2017-01-21 19:16:35 +00:00
|
|
|
});
|
2015-03-19 05:37:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
REGISTER_TYPED_TEST_CASE_P(FsppOpenFileTest,
|
2017-01-21 19:16:35 +00:00
|
|
|
CreatedFileIsEmpty,
|
|
|
|
FileIsFile
|
2015-03-19 05:37:44 +01:00
|
|
|
);
|
|
|
|
|
2015-03-19 05:38:00 +01:00
|
|
|
//TODO Test stat
|
|
|
|
//TODO Test truncate
|
|
|
|
//TODO Test read
|
|
|
|
//TODO Test write
|
|
|
|
//TODO Test flush
|
|
|
|
//TODO Test fsync
|
|
|
|
//TODO Test fdatasync
|
2016-03-23 18:03:30 +00:00
|
|
|
//TODO Test stat on file that was just created (i.e. the OpenFile instance returned by createAndOpenFile)
|
|
|
|
//TODO Test all operations do (or don't) affect file timestamps correctly
|
2015-03-19 05:38:00 +01:00
|
|
|
|
2015-03-19 05:37:44 +01:00
|
|
|
#endif
|