diff --git a/CMakeLists.txt b/CMakeLists.txt index 495723b9..5f8a45f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ project(fastafs) # Do this once in a while - find different compiler warnings #set(CMAKE_CXX_COMPILER "clang++") -set(PROJECT_VERSION "1.9.0") +set(PROJECT_VERSION "1.10.0") set(PACKAGE_URL "https://github.com/yhoogstrate/fastafs") set(PACKAGE_BUGREPORT "${PACKAGE_URL}/issues") diff --git a/Changelog b/Changelog index 25524c01..502ac8aa 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,10 @@ +2023-01-22 + * v.10.0 + * Better ninja/meson support + * Code clean-ups + * Restructured the chunked_reader class and subclasses according to + the desgin patterns philisopy + 2020-04-29 Youri Hoogstrate * v1.9.0 diff --git a/include/chunked_reader.hpp b/include/chunked_reader.hpp index d47b7533..5d9e615a 100644 --- a/include/chunked_reader.hpp +++ b/include/chunked_reader.hpp @@ -30,55 +30,6 @@ enum compression_type : signed char { // dit is State //url: https://refactoring.guru/design-patterns/state - -class chunked_reader_old // dit is Context -{ -private: - std::ifstream *fh_flat; - ZSTD_seekable_decompress_init_data* fh_zstd; - - std::string filename; // try doing this with inode - - compression_type filetype; - - char buffer[READ_BUFFER_SIZE + 1]; - size_t buffer_i; - size_t buffer_n; - - off_t file_i; - - -public: - chunked_reader_old(char *); // filename - chunked_reader_old(const char *); // filename - ~chunked_reader_old(); - - void init(); // generic tasks needed for init - - void update_flat_buffer(); - void update_zstd_buffer(); - - - void find_filetype(); - - void set_filetype(compression_type); - compression_type get_filetype() - { - return this->filetype ; - }; - - size_t read(char *, size_t);// @deprecate - size_t read(unsigned char *, size_t); - unsigned char read(); - - void seek(off_t); - size_t tell(); - //size_t size(); -}; - - - - class chunked_reader; class State diff --git a/src/chunked_reader.cpp b/src/chunked_reader.cpp index 6d138c79..5cada62b 100644 --- a/src/chunked_reader.cpp +++ b/src/chunked_reader.cpp @@ -3,255 +3,6 @@ -chunked_reader_old::chunked_reader_old(char * afilename) : - fh_flat(nullptr), fh_zstd(nullptr), buffer_i(0), buffer_n(0), file_i(0) -{ - this->filename = realpath_cpp(afilename); - this->init(); -} - -chunked_reader_old::chunked_reader_old(const char * afilename) : - fh_flat(nullptr), fh_zstd(nullptr), buffer_i(0), buffer_n(0), file_i(0) -{ - this->filename = realpath_cpp(afilename); - this->init(); -} - -chunked_reader_old::~chunked_reader_old() -{ - if(this->fh_flat != nullptr) { - if(this->fh_flat->is_open()) { - this->fh_flat->close(); - } - - delete this->fh_flat; - } - - if(this->fh_zstd != nullptr) { - //ZSTD_seekable_free(this->fh_zstd->seekable); - fclose_orDie(this->fh_zstd->fin); - - //delete this->fh_zstd->seekable; - //delete this->fh_zstd->fin; - - delete this->fh_zstd; - } -} - -void chunked_reader_old::init() -{ - this->find_filetype(); - - switch(this->filetype) { - - case uncompressed: - this->fh_flat = new std::ifstream; - this->fh_flat->open(this->filename.c_str(), std::ios::in | std::ios::binary | std::ios::ate); - - if(this->fh_flat->is_open()) { - this->fh_flat->seekg(0, std::ios::beg); - this->update_flat_buffer(); - } else { - throw std::runtime_error("[chunked_reader_old::init] Cannot open file for reading.\n"); - } - break; - - case zstd: - //printf("[chunked_reader_old::init()] - init ZSTD_seekable_decompress_init_data* fh_zstd; \n"); - this->fh_zstd = ZSTD_seekable_decompressFile_init(this->filename.c_str()); - // make zstd handle - to be implemented later on - //ZSTD_seekable_decompress_data - break; - - default: - throw std::runtime_error("[chunked_reader_old::init] Should never happen - but avoids compiler warning.\n"); - break; - } -} - -void chunked_reader_old::find_filetype() -{ - if(is_zstd_file((const char*) this->filename.c_str())) { - this->set_filetype(zstd); - } else { - this->set_filetype(uncompressed); - } -} - -void chunked_reader_old::set_filetype(compression_type arg_filetype) -{ - this->filetype = arg_filetype; -} - - -void set_filtetype(compression_type &filetype_arg); - - -size_t chunked_reader_old::read(char *arg_buffer, size_t buffer_size) -{ - buffer_size = std::min(buffer_size, (size_t) READ_BUFFER_SIZE); - size_t written = 0; - - while(this->buffer_i < this->buffer_n and written < buffer_size) { - arg_buffer[written++] = this->buffer[this->buffer_i++]; - } - - - - /* - size_t n = std::min(this->buffer_n - this->buffer_i, buffer_size - written); - memcpy(&arg_buffer[written], &this->buffer[this->buffer_i] , n); - written += n; - this->buffer_i += n; - */ - - if(written < buffer_size) { - // overwrite buffer - switch(this->filetype) { - case uncompressed: - this->update_flat_buffer(); - break; - case zstd: - this->update_zstd_buffer(); - break; - default: - throw std::runtime_error("[chunked_reader_old::read] reading from uninitialized object\n"); - break; - } - - // same loop again - while(this->buffer_i < this->buffer_n and written < buffer_size) { - arg_buffer[written++] = this->buffer[this->buffer_i++]; - } - /* - somehow memcpy is slightly slower - test again @ mom laptop - size_t n = std::min(this->buffer_n - this->buffer_i, buffer_size - written); - memcpy(&arg_buffer[written], &this->buffer[this->buffer_i] , n); - written += n; - this->buffer_i += n; - */ - } - - return written; -} - - - - - -size_t chunked_reader_old::read(unsigned char *arg_buffer, size_t buffer_size) -{ - - - buffer_size = std::min(buffer_size, (size_t) READ_BUFFER_SIZE); - size_t written = 0; - - while(this->buffer_i < this->buffer_n and written < buffer_size) { - arg_buffer[written++] = this->buffer[this->buffer_i++]; - } - - - if(written < buffer_size) { - // overwrite buffer - switch(this->filetype) { - case uncompressed: - this->update_flat_buffer(); - break; - case zstd: - this->update_zstd_buffer(); - break; - default: - throw std::runtime_error("[chunked_reader_old::read] reading from uninitialized object\n"); - break; - } - - // same loop again - while(this->buffer_i < this->buffer_n and written < buffer_size) { - arg_buffer[written++] = this->buffer[this->buffer_i++]; - } - } - - return written; -} - - - -// reads single byte from the buffer -unsigned char chunked_reader_old::read() -{ - if(this->buffer_i >= this->buffer_n) { - switch(this->filetype) { - case uncompressed: - this->update_flat_buffer(); - break; - case zstd: - this->update_zstd_buffer(); - break; - default: - throw std::runtime_error("[chunked_reader_old::read] reading from uninitialized object\n"); - break; - } - } - - return this->buffer[this->buffer_i++]; -} - - - - -void chunked_reader_old::update_flat_buffer() -{ - this->fh_flat->read(this->buffer, READ_BUFFER_SIZE); - - this->buffer_i = 0; - this->buffer_n = (size_t) this->fh_flat->gcount(); - this->file_i += this->buffer_n; -} - - -void chunked_reader_old::update_zstd_buffer() -{ - //size_t written = ZSTD_seekable_decompressFile_orDie(this->filename.c_str(), this->file_i, this->buffer, this->file_i + READ_BUFFER_SIZE); - size_t written = ZSTD_seekable_decompressFile_orDie(this->fh_zstd, this->file_i, this->buffer, this->file_i + READ_BUFFER_SIZE); - - this->buffer_i = 0; - this->buffer_n = written; - this->file_i += written; -} - - - -void chunked_reader_old::seek(off_t offset) -{ - this->file_i = offset; - - switch(this->filetype) { - case uncompressed: - this->fh_flat->clear(); // reset error state - - if(!this->fh_flat->is_open()) { - this->fh_flat->open(this->filename.c_str(), std::ios::in | std::ios::binary | std::ios::ate); - } - - this->fh_flat->seekg(offset, std::ios::beg); - this->update_flat_buffer(); - break; - default: - this->update_zstd_buffer(); - break; - } -} - - -size_t chunked_reader_old::tell() -{ - //@todo decide what to return when out of bound - //e.g. when exceeding file size - - return this->file_i - this->buffer_n + this->buffer_i; -} - - - void State::set_context(chunked_reader *arg_context) { this->context = arg_context; diff --git a/src/fuse.cpp b/src/fuse.cpp index 1b9c11a7..1a4dd8e8 100644 --- a/src/fuse.cpp +++ b/src/fuse.cpp @@ -168,7 +168,7 @@ static int do_getattr(const char *path, struct stat *st) -static int do_readdir(const char *path, void *buffer, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) +static int do_readdir(const char *path, void *buffer, fuse_fill_dir_t filler, __attribute__((__unused__)) off_t offset, __attribute__((__unused__)) struct fuse_file_info *fi) { fuse_instance *ffi = static_cast(fuse_get_context()->private_data); @@ -272,7 +272,7 @@ static int do_open(const char *path, struct fuse_file_info *fi) return 0; } -static int do_flush(const char *path, struct fuse_file_info *fi) +static int do_flush(const char *path, __attribute__((__unused__)) struct fuse_file_info *fi) { return 0; } diff --git a/test/chunked_reader/test_chunked_reader.cpp b/test/chunked_reader/test_chunked_reader.cpp index dfcecc99..db8b11be 100644 --- a/test/chunked_reader/test_chunked_reader.cpp +++ b/test/chunked_reader/test_chunked_reader.cpp @@ -55,9 +55,6 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__small_file) std::string reference3 = "\x0a\x46\x53\x00"s; { - // old init - chunked_reader_old r_flat = chunked_reader_old(fastafs_file.c_str()); - // Context equivalent - uncompressed chunked_reader c1(fastafs_file.c_str()); c1.fopen(0); @@ -71,15 +68,6 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__small_file) BOOST_CHECK(c2.typeid_state() != typeid(ContextUncompressed)); - - BOOST_CHECK_EQUAL(r_flat.tell(), 0); - written = r_flat.read((char*) &buffer[0], 1024); - BOOST_CHECK_EQUAL(written, 403); - std_buffer = std::string(reinterpret_cast(&buffer), written); - BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference1), 0, "Difference in content"); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); - BOOST_CHECK_EQUAL(r_flat.tell(), 403); - // Context equivalent - uncompressed { BOOST_CHECK_EQUAL(c1.tell(), 0); @@ -112,16 +100,6 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__small_file) } - // test what happens when file is closed (twice) - written = r_flat.read((char*) &buffer[0], 1024); - BOOST_CHECK_EQUAL(written, 0); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); - BOOST_CHECK_EQUAL(r_flat.tell(), 403); - - written = r_flat.read((char*) &buffer[0], 1024); - BOOST_CHECK_EQUAL(written, 0); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); - BOOST_CHECK_EQUAL(r_flat.tell(), 403); // Context equivalent - uncompressed { @@ -150,17 +128,8 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__small_file) } - // test seek stuff - BOOST_CHECK_EQUAL(r_flat.tell(), 403); - r_flat.seek(0); - BOOST_CHECK_EQUAL(r_flat.tell(), 0); - r_flat.seek(1); - BOOST_CHECK_EQUAL(r_flat.tell(), 1); - r_flat.seek(402); - BOOST_CHECK_EQUAL(r_flat.tell(), 402); - - // Context equivalent - uncompressed { + // Context equivalent - uncompressed BOOST_CHECK_EQUAL(c1.tell(), 403); c1.seek(0); BOOST_CHECK_EQUAL(c1.tell(), 0); @@ -169,9 +138,8 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__small_file) c1.seek(402); BOOST_CHECK_EQUAL(c1.tell(), 402); } - - // Context equivalent - compressed zstd { + // Context equivalent - compressed zstd BOOST_CHECK_EQUAL(c2.tell(), 403); c2.seek(0); BOOST_CHECK_EQUAL(c2.tell(), 0); @@ -182,16 +150,8 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__small_file) } - r_flat.seek(0); - written = r_flat.read((char*) &buffer[0], 4); - BOOST_CHECK_EQUAL(written, 4); - BOOST_CHECK_EQUAL(r_flat.tell(), 4); - std_buffer = std::string(reinterpret_cast(&buffer), written); - BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference2), 0, "Difference in content"); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); - - // Context equivalent - uncompressed { + // Context equivalent - uncompressed c1.seek(0); BOOST_CHECK_EQUAL(c1.tell(), 0); written = c1.read(buffer, 4); @@ -202,10 +162,8 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__small_file) BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference2), 0, "Difference in content"); flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - - - // Context equivalent - compressed zstd { + // Context equivalent - compressed zstd c2.seek(0); BOOST_CHECK_EQUAL(c2.tell(), 0); written = c2.read(buffer, 4); @@ -218,18 +176,10 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__small_file) } - r_flat.seek(1); // reset to first pos in file - BOOST_CHECK_EQUAL(r_flat.tell(), 1); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); - written = r_flat.read((char*) &buffer[0], 4); - BOOST_CHECK_EQUAL(written, 4); - BOOST_CHECK_EQUAL(r_flat.tell(), 5); - std_buffer = std::string(reinterpret_cast(&buffer), written); - BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference3), 0, "Difference in content"); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); - // Context equivalent - uncompressed + { + // Context equivalent - uncompressed c1.seek(1); BOOST_CHECK_EQUAL(c1.tell(), 1); flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); @@ -238,11 +188,17 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__small_file) BOOST_CHECK_EQUAL(c1.tell(), 5); std_buffer = std::string(reinterpret_cast(&buffer), written); BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference3), 0, "Difference in content"); + if(std_buffer.compare(reference3) != 0) { + printf("%u != %u\n", (unsigned int) reference3.size(), (unsigned int) std_buffer.size()); + printf("%s != %s\n", reference3.c_str(), std_buffer.c_str()); + + printf("[%u][%u][%u][%u]\n", (unsigned char) reference3[0], reference3[1], reference3[2], reference3[3]); + printf("[%u][%u][%u][%u]\n", (unsigned char) buffer[0], buffer[1], buffer[2], buffer[3]); + } flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - - // Context equivalent - compressed zstd { + // Context equivalent - compressed zstd c2.seek(1); BOOST_CHECK_EQUAL(c2.tell(), 1); @@ -259,29 +215,22 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__small_file) printf("[%u][%u][%u][%u]\n", (unsigned char) reference3[0], reference3[1], reference3[2], reference3[3]); printf("[%u][%u][%u][%u]\n", (unsigned char) buffer[0], buffer[1], buffer[2], buffer[3]); - //printf("[%c][%c][%c][%c]\n"); } flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - //@todo should trigger error!? - r_flat.seek(1024 * 1024); // trigger out of bound - - // Context equivalent - uncompressed { + // Context equivalent - uncompressed c1.seek(1024 * 1024); } - - // Context equivalent - compressed zstd { + // Context equivalent - compressed zstd c2.seek(1024 * 1024); } } { - chunked_reader_old r_zstd = chunked_reader_old(fastafs_file_zstd.c_str()); - // Context equivalent - uncompressed chunked_reader c1(fastafs_file.c_str()); c1.fopen(0); @@ -296,21 +245,16 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__small_file) - written = r_zstd.read(buffer, 1024); - BOOST_CHECK_EQUAL(written, 403); - std_buffer = std::string(reinterpret_cast(&buffer), written); - BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference1), 0, "Difference in content"); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); - { + // C1 written = c1.read(buffer, 1024); BOOST_CHECK_EQUAL(written, 403); std_buffer = std::string(reinterpret_cast(&buffer), written); BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference1), 0, "Difference in content"); flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - { + // C2 written = c2.read(buffer, 1024); BOOST_CHECK_EQUAL(written, 403); std_buffer = std::string(reinterpret_cast(&buffer), written); @@ -318,61 +262,52 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__small_file) flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - written = r_zstd.read(buffer, 1024); - BOOST_CHECK_EQUAL(written, 0); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); + { + // C1 written = c1.read(buffer, 1024); BOOST_CHECK_EQUAL(written, 0); flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - { + // C2 written = c2.read(buffer, 1024); BOOST_CHECK_EQUAL(written, 0); flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } // test what happens when file is closed - written = r_zstd.read(buffer, 1024); - BOOST_CHECK_EQUAL(written, 0); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); - { + // C1 written = c1.read(buffer, 1024); BOOST_CHECK_EQUAL(written, 0); flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - { + // C2 written = c2.read(buffer, 1024); BOOST_CHECK_EQUAL(written, 0); flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - // test seek stuff - r_zstd.seek(0); // reset to first pos in file - BOOST_REQUIRE_EQUAL(r_zstd.tell(), 0); + // test seek stuff { + // C1 c1.seek(0); // reset to first pos in file BOOST_REQUIRE_EQUAL(c1.tell(), 0); } - { + // C2 c2.seek(0); // reset to first pos in file BOOST_REQUIRE_EQUAL(c2.tell(), 0); } - written = r_zstd.read(buffer, 4); - BOOST_CHECK_EQUAL(written, 4); - BOOST_CHECK_EQUAL(r_zstd.tell(), 4); - std_buffer = std::string(reinterpret_cast(&buffer), written); - BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference2), 0, "Difference in content"); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); + { + // C1 written = c1.read(buffer, 4); BOOST_CHECK_EQUAL(written, 4); BOOST_CHECK_EQUAL(c1.tell(), 4); @@ -380,8 +315,8 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__small_file) BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference2), 0, "Difference in content"); flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - { + // C2 written = c2.read(buffer, 4); BOOST_CHECK_EQUAL(written, 4); BOOST_CHECK_EQUAL(c2.tell(), 4); @@ -390,30 +325,25 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__small_file) flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - r_zstd.seek(1); // reset to first pos in file - BOOST_CHECK_EQUAL(r_zstd.tell(), 1); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); + { + // C1 c1.seek(1); // reset to first pos in file BOOST_CHECK_EQUAL(c1.tell(), 1); flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - { + // C2 c2.seek(1); // reset to first pos in file BOOST_CHECK_EQUAL(c2.tell(), 1); flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - written = r_zstd.read(buffer, 4); - BOOST_CHECK_EQUAL(written, 4); - BOOST_CHECK_EQUAL(r_zstd.tell(), 5); - std_buffer = std::string(reinterpret_cast(&buffer), written); - BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference3), 0, "Difference in content"); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); + { + // C1 written = c1.read(buffer, 4); BOOST_CHECK_EQUAL(written, 4); BOOST_CHECK_EQUAL(c1.tell(), 5); @@ -421,8 +351,8 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__small_file) BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference3), 0, "Difference in content"); flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - { + // C2 written = c2.read(buffer, 4); BOOST_CHECK_EQUAL(written, 4); BOOST_CHECK_EQUAL(c2.tell(), 5); @@ -464,8 +394,6 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__large_file) { - chunked_reader_old r_flat = chunked_reader_old(fastafs_file.c_str()); - // Context equivalent - uncompressed chunked_reader c1(fastafs_file.c_str()); c1.fopen(0); @@ -479,13 +407,6 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__large_file) BOOST_CHECK(c2.typeid_state() != typeid(ContextUncompressed)); - - written = r_flat.read((char*) &buffer[0], 1024); - BOOST_CHECK_EQUAL(written, 1024); - std_buffer = std::string(reinterpret_cast(&buffer), written); - BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference1), 0, "Difference in content 1st read"); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); - { // C1 written = c1.read(buffer, 1024); @@ -494,7 +415,6 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__large_file) BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference1), 0, "Difference in content 1st read"); flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - { // C2 written = c2.read(buffer, 1024); @@ -505,11 +425,6 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__large_file) } - written = r_flat.read((char*) &buffer[0], 1024); - BOOST_CHECK_EQUAL(written, 569); - std_buffer = std::string(reinterpret_cast(&buffer), written); - BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference2), 0, "Difference in content 2nd read"); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); { // C1 @@ -529,9 +444,7 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__large_file) flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - written = r_flat.read((char*) &buffer[0], 1024); - BOOST_CHECK_EQUAL(written, 0); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); + { // C1 @@ -539,7 +452,6 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__large_file) BOOST_CHECK_EQUAL(written, 0); flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - { // C2 written = c2.read(buffer, 1024); @@ -547,9 +459,7 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__large_file) flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - written = r_flat.read((char*) &buffer[0], 1024); - BOOST_CHECK_EQUAL(written, 0); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); + { // C1 @@ -557,7 +467,6 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__large_file) BOOST_CHECK_EQUAL(written, 0); flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - { // C2 written = c2.read(buffer, 1024); @@ -566,35 +475,28 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__large_file) } - // set back - r_flat.seek(1024); - + // set back / seek { // C1 c1.seek(1024); } - { // C2 c2.seek(1024); } - written = r_flat.read((char*) &buffer[0], 1024); - BOOST_CHECK_EQUAL(written, 569); - std_buffer = std::string(reinterpret_cast(&buffer), written); - BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference2), 0, "Difference in content 2nd read"); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); - { // C1 + { + // C1 written = c1.read(buffer, 1024); BOOST_CHECK_EQUAL(written, 569); std_buffer = std::string(reinterpret_cast(&buffer), written); BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference2), 0, "Difference in content 2nd read"); flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - - { // C2 + { + // C2 written = c2.read(buffer, 1024); BOOST_CHECK_EQUAL(written, 569); std_buffer = std::string(reinterpret_cast(&buffer), written); @@ -603,32 +505,28 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__large_file) } - // set back - r_flat.seek(4); - { // C1 + { + // C1 c1.seek(4); } - - { // C2 + { + // C2 c2.seek(4); } - written = r_flat.read((char*) &buffer[0], 1024);// reads across two buffers? - BOOST_CHECK_EQUAL(written, 1024); - std_buffer = std::string(reinterpret_cast(&buffer), written); - BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference3), 0, "Difference in content 2nd read"); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); - { // C1 + + { + // C1 written = c1.read(buffer, 1024);// reads across two buffers? BOOST_CHECK_EQUAL(written, 1024); std_buffer = std::string(reinterpret_cast(&buffer), written); BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference3), 0, "Difference in content 2nd read"); flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - - { // C2 + { + // C2 written = c2.read(buffer, 1024);// reads across two buffers? BOOST_CHECK_EQUAL(written, 1024); std_buffer = std::string(reinterpret_cast(&buffer), written); @@ -637,21 +535,16 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__large_file) } - written = r_flat.read((char*) &buffer[0], 1024);// reads across two buffers? - BOOST_CHECK_EQUAL(written, 565); - std_buffer = std::string(reinterpret_cast(&buffer), written); - BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference4), 0, "Difference in content 2nd read"); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); - - { // C1 + { + // C1 written = c1.read(buffer, 1024);// reads across two buffers? BOOST_CHECK_EQUAL(written, 565); std_buffer = std::string(reinterpret_cast(&buffer), written); BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference4), 0, "Difference in content 2nd read"); flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - - { // C2 + { + // C2 written = c2.read(buffer, 1024);// reads across two buffers? BOOST_CHECK_EQUAL(written, 565); std_buffer = std::string(reinterpret_cast(&buffer), written); @@ -660,32 +553,27 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__large_file) } - r_flat.seek(4); - - { // C1 + { + // C1 c1.seek(4); } - - { // C2 + { + // C2 c2.seek(4); } - written = r_flat.read((char*) &buffer[0], 4);// reads across two buffers? - BOOST_CHECK_EQUAL(written, 4); - std_buffer = std::string(reinterpret_cast(&buffer), written); - BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference5), 0, "Difference in content 2nd read"); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); - { // C1 + { + // C1 written = c1.read(buffer, 4);// reads across two buffers? BOOST_CHECK_EQUAL(written, 4); std_buffer = std::string(reinterpret_cast(&buffer), written); BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference5), 0, "Difference in content 2nd read"); flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - - { // C2 + { + // C2 written = c2.read(buffer, 4);// reads across two buffers? BOOST_CHECK_EQUAL(written, 4); std_buffer = std::string(reinterpret_cast(&buffer), written); @@ -694,21 +582,17 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__large_file) } - written = r_flat.read((char*) &buffer[0], 1024);// reads across two buffers? - BOOST_CHECK_EQUAL(written, 1024); - std_buffer = std::string(reinterpret_cast(&buffer), written); - BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference6), 0, "Difference in content 2nd read"); - flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); - { // C1 + { + // C1 written = c1.read(buffer, 1024);// reads across two buffers? BOOST_CHECK_EQUAL(written, 1024); std_buffer = std::string(reinterpret_cast(&buffer), written); BOOST_CHECK_EQUAL_MESSAGE(std_buffer.compare(reference6), 0, "Difference in content 2nd read"); flush_buffer(buffer, READ_BUFFER_SIZE + 1, '\0'); } - - { // C2 + { + // C2 written = c2.read(buffer, 1024);// reads across two buffers? BOOST_CHECK_EQUAL(written, 1024); std_buffer = std::string(reinterpret_cast(&buffer), written); @@ -755,7 +639,8 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__new_style) chunked_reader c2 = chunked_reader(fastafs_file_zstd.c_str()); c2.fopen(0); // open file handle and load buffer - { // C1 + { + // C1 written = c1.read(buffer, 1000); buffer[written] = '\0'; BOOST_CHECK_EQUAL(written, 1000); @@ -765,7 +650,8 @@ BOOST_AUTO_TEST_CASE(test_chunked_reader_old__new_style) BOOST_CHECK_EQUAL(written, 593); } - { // C2 + { + // C2 written = c2.read(buffer, 1000); buffer[written] = '\0'; BOOST_CHECK_EQUAL(written, 1000);