From dd1adf83392838779b88bef9158f725056b61bd6 Mon Sep 17 00:00:00 2001 From: Timm Fitschen <t.fitschen@indiscale.com> Date: Thu, 12 Aug 2021 10:27:34 +0200 Subject: [PATCH] TST: add test for FileWriter and FileReader --- test/CMakeLists.txt | 1 + test/test_file_streaming.cpp | 42 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 test/test_file_streaming.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 389d5d9..566ddef 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -23,6 +23,7 @@ set(test_cases test_configuration test_connection test_entity + test_file_streaming test_info test_protobuf test_transaction diff --git a/test/test_file_streaming.cpp b/test/test_file_streaming.cpp new file mode 100644 index 0000000..b4d9a4a --- /dev/null +++ b/test/test_file_streaming.cpp @@ -0,0 +1,42 @@ +#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 { + +static const fs::path test_file_name("this_is_a_test_file_remove_me.dat"); + +class test_file_streaming : public ::testing::Test { +protected: + void SetUp() override {} + + 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 -- GitLab