Skip to content
Snippets Groups Projects
Select Git revision
  • 5859bde00b2c91617bfabc2d9cfa9108d751d39e
  • main default protected
  • f-sss4grpc
  • dev
  • 108-implement-rpc-call-for-server-side-scripting
  • f-windows-conan-create
  • f-to-string
  • f-update-requirements
  • f-related-projects
  • f-role
  • f-remote-path
  • f-rel-path
  • f-consol-message
  • v0.3.0
  • v0.2.2
  • v0.2.1
  • v0.2.0
  • v0.1.2
  • v0.1.1
  • v0.1
  • v0.0.19
  • v0.0.18
  • v0.0.16
  • v0.0.15
  • v0.0.10
  • v0.0.9
  • v0.0.8
  • v0.0.7
  • v0.0.6
  • v0.0.5
  • v0.0.4
  • v0.0.3
  • v0.0.2
33 results

test_info.cpp

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    test_file_transmission.cpp 2.10 KiB
    /*
     * This file is a part of the CaosDB Project.
     *
     * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
     * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
     *
     * This program is free software: you can redistribute it and/or modify
     * it under the terms of the GNU Affero General Public License as
     * published by the Free Software Foundation, either version 3 of the
     * License, or (at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU Affero General Public License for more details.
     *
     * You should have received a copy of the GNU Affero General Public License
     * along with this program. If not, see <https://www.gnu.org/licenses/>.
     */
    #include "caosdb/file_transmission/file_writer.h"
    #include "caosdb/file_transmission/file_reader.h"
    #include <chrono>                  // for filesystem
    #include <filesystem>              // for path
    #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 = std::filesystem;
    
    namespace caosdb::transaction {
    
    class test_file_transmission : 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_transmission, 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 caosdb::transaction