Skip to content
Snippets Groups Projects
Verified Commit 10398ee9 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: files

parent 9785bdb4
No related branches found
No related tags found
1 merge request!8F files
Pipeline #11913 failed
This commit is part of merge request !8. Comments created here will be created in the context of that merge request.
...@@ -82,7 +82,7 @@ if(LINTING) ...@@ -82,7 +82,7 @@ if(LINTING)
"--warnings-as-errors=*" "--warnings-as-errors=*"
"--fix") "--fix")
set(_CMAKE_CXX_CLANG_TIDY_CHECKS 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() endif()
else() else()
message(STATUS "LINTING is OFF") message(STATUS "LINTING is OFF")
......
...@@ -18,31 +18,52 @@ ...@@ -18,31 +18,52 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
* *
*/ */
#include "caosdb/connection.h" // for Connection, ConnectionManager #include "caosdb/connection.h" // for Connection, ConnectionManager
#include "caosdb/entity.h" // for Entity, Messages, Message #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/message_code.h" // for ENTITY_DOES_NOT_EXIST, Messag...
#include "caosdb/status_code.h" // for SUCCESS, StatusCode #include "caosdb/status_code.h" // for SUCCESS, StatusCode
#include "caosdb/transaction.h" // for Entity, Transaction, UniqueRe... #include "caosdb/transaction.h" // for Entity, Transaction, UniqueRe...
#include "caosdb/transaction_status.h" // for TransactionStatus, StatusCode #include "caosdb/transaction_status.h" // for TransactionStatus, StatusCode
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp> // for path
#include "gtest/gtest-message.h" // for Message #include <boost/filesystem/operations.hpp> // for remove
#include "gtest/gtest-test-part.h" // for TestPartResult, SuiteApiResolver #include <boost/filesystem/path_traits.hpp> // for filesystem
#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, AssertionResult #include <gtest/gtest-message.h> // for Message
#include <iostream> #include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver
#include <memory> // for unique_ptr, allocator, __shar... #include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, AssertionResult
#include <string> // for string #include <memory> // for unique_ptr, allocator, __shar...
#include <vector> // for vector #include <string> // for string
#include <vector> // for vector
namespace fs = boost::filesystem;
namespace caosdb::transaction { namespace caosdb::transaction {
using caosdb::entity::Entity; using caosdb::entity::Entity;
using caosdb::entity::MessageCode; using caosdb::entity::MessageCode;
using caosdb::entity::Parent; using caosdb::entity::Parent;
using caosdb::entity::Property; using caosdb::entity::Property;
using FileExchange::FileWriter;
class test_transaction : public ::testing::Test { class test_transaction : public ::testing::Test {
private:
fs::path test_upload_file_1;
fs::path test_download_file_1;
protected: 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 { void TearDown() override {
fs::remove(test_upload_file_1);
fs::remove(test_download_file_1);
const auto &connection = const auto &connection =
caosdb::connection::ConnectionManager::GetDefaultConnection(); caosdb::connection::ConnectionManager::GetDefaultConnection();
auto query_transaction(connection->CreateTransaction()); auto query_transaction(connection->CreateTransaction());
...@@ -665,7 +686,7 @@ TEST_F(test_transaction, test_file_upload) { ...@@ -665,7 +686,7 @@ TEST_F(test_transaction, test_file_upload) {
Entity file; Entity file;
file.SetRole("File"); file.SetRole("File");
file.SetFilePath("test.txt"); file.SetFilePath("test.txt");
file.SetLocalPath("test.txt"); file.SetLocalPath(test_upload_file_1);
auto insert_transaction(connection->CreateTransaction()); auto insert_transaction(connection->CreateTransaction());
insert_transaction->InsertEntity(&file); insert_transaction->InsertEntity(&file);
...@@ -691,7 +712,7 @@ TEST_F(test_transaction, test_file_download) { ...@@ -691,7 +712,7 @@ TEST_F(test_transaction, test_file_download) {
Entity file; Entity file;
file.SetRole("File"); file.SetRole("File");
file.SetFilePath("test.txt"); file.SetFilePath("test.txt");
file.SetLocalPath("test.txt"); file.SetLocalPath(test_upload_file_1);
auto insert_transaction(connection->CreateTransaction()); auto insert_transaction(connection->CreateTransaction());
insert_transaction->InsertEntity(&file); insert_transaction->InsertEntity(&file);
...@@ -704,8 +725,8 @@ TEST_F(test_transaction, test_file_download) { ...@@ -704,8 +725,8 @@ TEST_F(test_transaction, test_file_download) {
ASSERT_FALSE(inserted_file.HasErrors()); ASSERT_FALSE(inserted_file.HasErrors());
auto download_transaction(connection->CreateTransaction()); auto download_transaction(connection->CreateTransaction());
download_transaction->RetrieveAndDownloadFilesById(inserted_file.GetId(), download_transaction->RetrieveAndDownloadFilesById(
"downloaded.txt"); inserted_file.GetId(), test_download_file_1.string());
download_transaction->ExecuteAsynchronously(); download_transaction->ExecuteAsynchronously();
download_transaction->WaitForIt(); download_transaction->WaitForIt();
...@@ -715,7 +736,8 @@ TEST_F(test_transaction, test_file_download) { ...@@ -715,7 +736,8 @@ TEST_F(test_transaction, test_file_download) {
const auto &downloaded_file = download_results.At(0); const auto &downloaded_file = download_results.At(0);
ASSERT_FALSE(downloaded_file.GetId().empty()); ASSERT_FALSE(downloaded_file.GetId().empty());
ASSERT_FALSE(downloaded_file.HasErrors()); 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 } // namespace caosdb::transaction
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment