-
Timm Fitschen authoredTimm Fitschen authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
test_file_streaming.cpp 1.35 KiB
#include "caosdb/filestreaming/FileWriter.h"
#include "caosdb/filestreaming/FileReader.h"
#include <boost/filesystem/operations.hpp> // for exists, file_size, remove
#include <boost/filesystem/path.hpp> // for path
#include <boost/filesystem/path_traits.hpp> // for filesystem
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver
#include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, AssertionResult
#include <string> // for string
namespace fs = boost::filesystem;
namespace FileExchange {
class test_file_streaming : public ::testing::Test {
protected:
fs::path test_file_name;
void SetUp() override {
test_file_name = fs::path("this_is_a_test_file_remove_me.dat");
}
void TearDown() override { fs::remove(test_file_name); }
};
TEST_F(test_file_streaming, test_file_writer_reader) {
ASSERT_FALSE(fs::exists(test_file_name));
FileWriter writer(test_file_name);
std::string buffer_out(1024, 'c');
for (int i = 0; i < 8; i++) {
writer.write(buffer_out);
EXPECT_EQ(fs::file_size(test_file_name), 1024 * (i + 1));
}
FileReader reader(test_file_name);
std::string buffer_in(1024, '\0');
for (int i = 0; i < 8; i++) {
reader.read(buffer_in);
EXPECT_EQ(buffer_in, std::string(1024, 'c'));
}
}
} // namespace FileExchange