diff --git a/test/test_transaction.cpp b/test/test_transaction.cpp index 844c829b78f0ebe76bbb7df4291a34764b2df303..5b889cb334c5aca6dc7adb66fb848b09072910f3 100644 --- a/test/test_transaction.cpp +++ b/test/test_transaction.cpp @@ -94,6 +94,7 @@ public: protected: fs::path test_upload_file_1; + fs::path test_empty_file_1; fs::path test_download_file_1; // Fixture methods ////////////////////////////////////////////////////////// @@ -102,6 +103,7 @@ protected: DeleteEntities(); test_upload_file_1 = fs::path("test_upload_file_1_delete_me.dat"); + test_empty_file_1 = fs::path("test_empty_file_1_delete_me.dat"); test_download_file_1 = fs::path("test_download_file_1_delete_me.dat"); // fill the file that shall be uploaded @@ -115,6 +117,7 @@ protected: void TearDown() override { // delete files fs::remove(test_upload_file_1); + //fs::remove(test_empty_file_1); fs::remove(test_download_file_1); DeleteEntities(); } @@ -955,13 +958,54 @@ TEST_F(test_transaction, test_file_up_n_download) { FileReader reader_remote(test_upload_file_1); std::string buffer_local(1024, 'c'); - std::string buffer_remote(1024, 'c'); + std::string buffer_remote(1024, '0'); for (int i = 0; i < 8; i++) { reader_remote.read(buffer_remote); EXPECT_EQ(buffer_remote, buffer_local); } } +/* + * create a file object, upload and then download it + */ +TEST_F(test_transaction, test_empyt_file) { + const auto &connection = + caosdb::connection::ConnectionManager::GetDefaultConnection(); + + Entity file; + file.SetRole(Role::FILE); + file.SetFilePath("test.txt"); + file.SetLocalPath(test_empty_file_1); + + auto insert_transaction(connection->CreateTransaction()); + insert_transaction->InsertEntity(&file); + insert_transaction->Execute(); + + const auto &insert_results = insert_transaction->GetResultSet(); + + const auto &inserted_file = insert_results.at(0); + ASSERT_FALSE(inserted_file.GetId().empty()); + ASSERT_FALSE(inserted_file.HasErrors()); + + auto download_transaction(connection->CreateTransaction()); + download_transaction->RetrieveAndDownloadFileById( + inserted_file.GetId(), test_download_file_1.string()); + download_transaction->ExecuteAsynchronously(); + ASSERT_EQ(download_transaction->WaitForIt().GetCode(), StatusCode::SUCCESS); + + const auto &download_results = download_transaction->GetResultSet(); + ASSERT_EQ(download_results.size(), 1); + + 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(), + test_download_file_1.string()); + + //checkfile size??/ +} + + /* * Test a small worklfow */