diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1bba969d6c30bcfcd293a19f91fae4df515daf73..4074d6b0549e8ef54036c9a17f137bd042fb08d3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -82,7 +82,7 @@ if(LINTING) "--warnings-as-errors=*" "--fix") set(_CMAKE_CXX_CLANG_TIDY_CHECKS - "--checks=*,-fuchsia-*,-llvmlibc-*,-cert-err58-cpp,-cppcoreguidelines-avoid-non-const-global-variables,-cppcoreguidelines-owning-memory,-modernize-use-trailing-return-type,-google-readability-avoid-underscore-in-googletest-name,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-cppcoreguidelines-avoid-goto,-hicpp-avoid-goto,-readability-function-cognitive-complexity") + "--checks=*,-fuchsia-*,-llvmlibc-*,-cert-err58-cpp,-cppcoreguidelines-avoid-non-const-global-variables,-cppcoreguidelines-owning-memory,-modernize-use-trailing-return-type,-google-readability-avoid-underscore-in-googletest-name,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-cppcoreguidelines-avoid-goto,-hicpp-avoid-goto,-readability-function-cognitive-complexity,-cppcoreguidelines-non-private-member-variables-in-classes,-misc-non-private-member-variables-in-classes") endif() else() message(STATUS "LINTING is OFF") diff --git a/test/test_transaction.cpp b/test/test_transaction.cpp index be750d979b260d04f7af609120e768b9dd5b57ac..e4de09832706ae97b794911050acbaf4b3781e73 100644 --- a/test/test_transaction.cpp +++ b/test/test_transaction.cpp @@ -18,31 +18,52 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#include "caosdb/connection.h" // for Connection, ConnectionManager -#include "caosdb/entity.h" // for Entity, Messages, Message +#include "caosdb/connection.h" // for Connection, ConnectionManager +#include "caosdb/entity.h" // for Entity, Messages, Message +#include "caosdb/filestreaming/FileWriter.h" // for FileWriter #include "caosdb/message_code.h" // for ENTITY_DOES_NOT_EXIST, Messag... #include "caosdb/status_code.h" // for SUCCESS, StatusCode #include "caosdb/transaction.h" // for Entity, Transaction, UniqueRe... #include "caosdb/transaction_status.h" // for TransactionStatus, StatusCode -#include <boost/filesystem/path.hpp> -#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 <iostream> -#include <memory> // for unique_ptr, allocator, __shar... -#include <string> // for string -#include <vector> // for vector +#include <boost/filesystem/path.hpp> // for path +#include <boost/filesystem/operations.hpp> // for remove +#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 <memory> // for unique_ptr, allocator, __shar... +#include <string> // for string +#include <vector> // for vector + +namespace fs = boost::filesystem; namespace caosdb::transaction { using caosdb::entity::Entity; using caosdb::entity::MessageCode; using caosdb::entity::Parent; using caosdb::entity::Property; +using FileExchange::FileWriter; class test_transaction : public ::testing::Test { +private: + fs::path test_upload_file_1; + fs::path test_download_file_1; + protected: - void SetUp() override {} + void SetUp() override { + test_upload_file_1 = fs::path("test_upload_file_1_delete_me.dat"); + test_download_file_1 = fs::path("test_download_file_1_delete_me.dat"); + + FileWriter writer(test_upload_file_1); + std::string buffer(1024, 'c'); + for (int i = 0; i < 8; i++) { + writer.write(buffer); + } + } void TearDown() override { + fs::remove(test_upload_file_1); + fs::remove(test_download_file_1); + const auto &connection = caosdb::connection::ConnectionManager::GetDefaultConnection(); auto query_transaction(connection->CreateTransaction()); @@ -665,7 +686,7 @@ TEST_F(test_transaction, test_file_upload) { Entity file; file.SetRole("File"); file.SetFilePath("test.txt"); - file.SetLocalPath("test.txt"); + file.SetLocalPath(test_upload_file_1); auto insert_transaction(connection->CreateTransaction()); insert_transaction->InsertEntity(&file); @@ -691,7 +712,7 @@ TEST_F(test_transaction, test_file_download) { Entity file; file.SetRole("File"); file.SetFilePath("test.txt"); - file.SetLocalPath("test.txt"); + file.SetLocalPath(test_upload_file_1); auto insert_transaction(connection->CreateTransaction()); insert_transaction->InsertEntity(&file); @@ -704,8 +725,8 @@ TEST_F(test_transaction, test_file_download) { ASSERT_FALSE(inserted_file.HasErrors()); auto download_transaction(connection->CreateTransaction()); - download_transaction->RetrieveAndDownloadFilesById(inserted_file.GetId(), - "downloaded.txt"); + download_transaction->RetrieveAndDownloadFilesById( + inserted_file.GetId(), test_download_file_1.string()); download_transaction->ExecuteAsynchronously(); download_transaction->WaitForIt(); @@ -715,7 +736,8 @@ TEST_F(test_transaction, test_file_download) { const auto &downloaded_file = download_results.At(0); ASSERT_FALSE(downloaded_file.GetId().empty()); ASSERT_FALSE(downloaded_file.HasErrors()); - EXPECT_EQ(downloaded_file.GetLocalPath().string(), "downloaded.txt"); + EXPECT_EQ(downloaded_file.GetLocalPath().string(), + test_download_file_1.string()); } } // namespace caosdb::transaction