Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • caosdb/src/caosdb-cpplib
1 result
Select Git revision
Loading items
Show changes
Showing
with 593 additions and 429 deletions
......@@ -48,12 +48,12 @@
*/
#include "caosdb/file_transmission/file_writer.h"
#include "caosdb/file_transmission/file_error.h" // for FileIOError
#include <boost/filesystem/path.hpp> // for path
#include <filesystem> // for path
#include <utility> // for move
namespace caosdb::transaction {
FileWriter::FileWriter(boost::filesystem::path filename) : filename_(std::move(filename)) {
FileWriter::FileWriter(std::filesystem::path filename) : filename_(std::move(filename)) {
this->openFile();
}
......
......@@ -52,7 +52,6 @@
#include "caosdb/status_code.h" // for GENERIC_RPC_E...
#include "caosdb/transaction_status.h" // for TransactionStatus
#include <algorithm> // for min
#include <boost/filesystem/path.hpp> // for operator<<, path
#include <boost/log/core/record.hpp> // for record
#include <boost/log/detail/attachable_sstream_buf.hpp> // for basic_ostring...
#include <boost/log/sources/record_ostream.hpp> // for basic_record_...
......@@ -61,6 +60,7 @@
#include <cstdint> // for uint64_t
#include <exception> // IWYU pragma: keep
// IWYU pragma: no_include <bits/exception.h>
#include <filesystem> // for operator<<, path
#include <google/protobuf/arena.h> // for Arena
#include <grpcpp/impl/codegen/async_stream.h> // for ClientAsyncWr...
#include <grpcpp/impl/codegen/call_op_set.h> // for WriteOptions
......@@ -68,7 +68,7 @@
#include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue
#include <grpcpp/impl/codegen/status.h> // for Status
#include <grpcpp/impl/codegen/status_code_enum.h> // for OK, UNAUTHENT...
#include <iostream> // for endl, streamsize
#include <sstream> // for streamsize
#include <string> // for basic_string
#include <utility> // for move
......
......@@ -19,23 +19,24 @@
*
*/
#include "caosdb/logging.h"
#include "boost/core/swap.hpp" // for swap
#include "boost/iterator/iterator_facade.hpp"
#include "boost/log/attributes/clock.hpp"
#include "boost/log/core/core.hpp" // for core
#include "boost/log/core/record.hpp"
#include "boost/log/sources/record_ostream.hpp"
#include "boost/log/utility/setup/from_settings.hpp"
#include "boost/log/utility/setup/settings.hpp"
#include "boost/move/utility_core.hpp" // for move
#include "boost/multi_index/detail/bidir_node_iterator.hpp"
#include "boost/operators.hpp"
#include "boost/preprocessor/seq/limits/enum_256.hpp"
#include "boost/preprocessor/seq/limits/size_256.hpp"
#include "boost/property_tree/detail/exception_implementation.hpp"
#include "boost/smart_ptr/shared_ptr.hpp"
#include "boost/tuple/detail/tuple_basic.hpp" // for get
#include "caosdb/log_level.h"
#include <boost/core/swap.hpp> // for swap
#include <boost/iterator/iterator_facade.hpp>
#include <boost/log/attributes/clock.hpp>
#include <boost/log/core/core.hpp> // for core
#include <boost/log/core/record.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/sources/severity_channel_logger.hpp>
#include <boost/log/utility/setup/from_settings.hpp>
#include <boost/log/utility/setup/settings.hpp>
#include <boost/move/utility_core.hpp> // for move
#include <boost/multi_index/detail/bidir_node_iterator.hpp>
#include <boost/operators.hpp>
#include <boost/preprocessor/seq/limits/enum_256.hpp>
#include <boost/preprocessor/seq/limits/size_256.hpp>
#include <boost/property_tree/detail/exception_implementation.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/tuple/detail/tuple_basic.hpp> // for get
#include <memory>
#include <sstream>
#include <string>
......@@ -44,10 +45,6 @@
namespace caosdb::logging {
BOOST_LOG_GLOBAL_LOGGER_INIT(logger, boost_logger_class) {
boost_logger_class lg;
return lg;
}
LoggingConfiguration::LoggingConfiguration(int level) : LevelConfiguration(level) {}
auto LoggingConfiguration::AddSink(const std::shared_ptr<SinkConfiguration> &sink) -> void {
......@@ -114,9 +111,12 @@ SyslogSinkConfiguration::SyslogSinkConfiguration(const std::string &name, int le
// Called if no custom logging settings are specified.
auto initialize_logging_defaults() -> int {
// first: turn everything off
boost::log::settings off_settings;
off_settings["Core.DisableLogging"] = true;
boost::log::init_from_settings(off_settings);
auto core = boost::log::core::get();
if (core->get_logging_enabled()) {
core->flush();
core->remove_all_sinks();
core->set_logging_enabled(false);
}
// now set everything up
const static std::vector<std::shared_ptr<SinkConfiguration>> default_sinks = {
......@@ -131,7 +131,6 @@ auto initialize_logging_defaults() -> int {
}
boost::log::init_from_settings(default_settings);
auto core = boost::log::core::get();
core->add_global_attribute("TimeStamp", boost::log::attributes::local_clock());
CAOSDB_LOG_DEBUG(logger_name) << "Initialized default settings.";
......@@ -142,20 +141,22 @@ auto initialize_logging_defaults() -> int {
// Called if custom logging settings are specified.
auto initialize_logging(const LoggingConfiguration &configuration) -> void {
// first: turn everything off
boost::log::settings off_settings;
off_settings["Core.DisableLogging"] = true;
boost::log::init_from_settings(off_settings);
// now set everything up
boost::log::settings new_settings;
auto core = boost::log::core::get();
if (core->get_logging_enabled()) {
core->flush();
core->remove_all_sinks();
core->set_logging_enabled(false);
}
if (configuration.GetLevel() == CAOSDB_LOG_LEVEL_OFF) {
new_settings["Core.DisableLogging"] = true;
// it is off
return;
} else {
new_settings["Core.DisableLogging"] = false;
}
// now set everything up
boost::log::settings new_settings;
new_settings["Core.DisableLogging"] = false;
for (const auto &sink : configuration.GetSinks()) {
sink->Configure(new_settings);
}
......
......@@ -19,15 +19,15 @@
*
*/
#include "caosdb/protobuf_helper.h"
#include "caosdb/configuration.h"
#include <google/protobuf/arena.h> // for Arena
namespace caosdb::utility {
using google::protobuf::Arena;
auto get_arena() -> Arena * {
static Arena arena;
return &arena;
}
auto get_arena() -> Arena * { return caosdb::configuration::ConfigurationManager::GetArena(); }
auto reset_arena() -> void { get_arena()->Reset(); }
} // namespace caosdb::utility
......@@ -131,8 +131,9 @@ auto get_status_description(int code) -> const std::string & {
"The transaction terminated unsuccessfully with transaction errors."},
{StatusCode::CONFIGURATION_ERROR,
"An error occurred during the configuration of the ConfigurationManager."},
{StatusCode::UNKNOWN_CONNECTION_ERROR,
"The ConnectionManager does not know any connection of this name."},
{StatusCode::CONNECTION_CONFIGURATION_ERROR,
"Either there is no connection of the given name or the given connection has a faulty "
"configuration"},
{StatusCode::TRANSACTION_STATUS_ERROR,
"The Transaction is in a wrong state for the attempted action."},
{StatusCode::TRANSACTION_TYPE_ERROR,
......@@ -151,9 +152,9 @@ auto get_status_description(int code) -> const std::string & {
{StatusCode::FILE_UPLOAD_ERROR, "The transaction failed during the upload of the files"},
{StatusCode::UNSUPPORTED_FEATURE,
"This feature is not available in the this client implementation."},
{StatusCode::EXTERN_C_ASSIGNMENT_ERROR,
"You tried to assign a new object to the wrapped void pointer. You have "
"to delete the old pointee first."},
//{StatusCode::EXTERN_C_ASSIGNMENT_ERROR,
//"You tried to assign a new object to the wrapped void pointer. You have "
//"to delete the old pointee first."},
{StatusCode::ENUM_MAPPING_ERROR,
"The role, importance, or datatype you specified does not exist."},
{StatusCode::SPOILED,
......
......@@ -18,8 +18,8 @@
*
*/
#include "caosdb/transaction.h"
#include "caosdb/entity/v1alpha1/main.grpc.pb.h" // for EntityTransac...
#include "caosdb/entity/v1alpha1/main.pb.h" // for TransactionRe...
#include "caosdb/entity/v1/main.grpc.pb.h" // for EntityTransac...
#include "caosdb/entity/v1/main.pb.h" // for TransactionRe...
#include "caosdb/file_transmission/download_request_handler.h" // Download...
#include "caosdb/file_transmission/file_reader.h" // for path
#include "caosdb/file_transmission/register_file_upload_handler.h" // for RegisterFileUploadHandler
......@@ -28,7 +28,6 @@
#include "caosdb/status_code.h" // for StatusCode
#include "caosdb/transaction_handler.h" // for EntityTransactionHandler
#include <algorithm> // for max
#include <boost/filesystem/path.hpp> // for operator<<, path
#include <boost/log/core/record.hpp> // for record
#include <boost/log/detail/attachable_sstream_buf.hpp> // for basic_ostring...
#include <boost/log/sources/record_ostream.hpp> // for basic_record_...
......@@ -36,26 +35,28 @@
#include <boost/preprocessor/seq/limits/size_256.hpp> // for BOOST_PP_SEQ_...
// IWYU pragma: no_include <bits/exception.h>
#include <exception> // IWYU pragma: keep
#include <filesystem> // for operator<<, path
#include <google/protobuf/arena.h> // for Arena
#include <grpc/impl/codegen/gpr_types.h> // for gpr_timespec
#include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue
#include <iosfwd> // for streamsize
#include <map> // for map, operator!=
#include <memory> // for unique_ptr
#include <random> // for mt19937, rand...
#include <sstream>
#include <utility> // for move, pair
namespace caosdb::transaction {
using caosdb::entity::v1alpha1::EntityTransactionService;
using caosdb::entity::v1alpha1::FileTransmissionService;
using caosdb::entity::v1alpha1::MultiTransactionRequest;
using caosdb::entity::v1alpha1::MultiTransactionResponse;
using TransactionResponseCase =
caosdb::entity::v1alpha1::TransactionResponse::TransactionResponseCase;
using RetrieveResponseCase = caosdb::entity::v1alpha1::RetrieveResponse::RetrieveResponseCase;
using ProtoEntity = caosdb::entity::v1alpha1::Entity;
using caosdb::entity::v1::EntityTransactionService;
using caosdb::entity::v1::FileTransmissionService;
using caosdb::entity::v1::MultiTransactionRequest;
using caosdb::entity::v1::MultiTransactionResponse;
using TransactionResponseCase = caosdb::entity::v1::TransactionResponse::TransactionResponseCase;
using RetrieveResponseCase = caosdb::entity::v1::RetrieveResponse::RetrieveResponseCase;
using ProtoEntity = caosdb::entity::v1::Entity;
using caosdb::entity::v1::EntityRequest;
using google::protobuf::Arena;
using NextStatus = grpc::CompletionQueue::NextStatus;
using RegistrationStatus = caosdb::entity::v1alpha1::RegistrationStatus;
using RegistrationStatus = caosdb::entity::v1::RegistrationStatus;
ResultSet::iterator::iterator(const ResultSet *result_set_param, int index)
: current_index(index), result_set(result_set_param) {}
......@@ -143,20 +144,39 @@ auto Transaction::DeleteById(const std::string &id) noexcept -> StatusCode {
return this->status.GetCode();
}
auto Transaction::InsertEntity(Entity *entity) noexcept -> StatusCode {
ASSERT_CAN_ADD_INSERTION
auto get_next_file_id() -> std::string {
const std::string str = "0123456789abcdef";
std::mt19937 generator(std::random_device{}());
std::uniform_int_distribution<int> distribution(0, 15); // NOLINT
std::string result(10, '\0'); // NOLINT
auto *entity_request =
this->request->add_requests()->mutable_insert_request()->mutable_entity_request();
auto *proto_entity = entity_request->mutable_entity();
for (auto &dis : result) {
dis = str[distribution(generator)];
}
return result;
}
// copy the original entity for the transaction
// only used in the next two functions.
auto add_entity_to_request(Entity *entity, EntityRequest *entity_request,
std::vector<FileDescriptor> *upload_files) -> void {
auto *proto_entity = entity_request->mutable_entity();
entity->CopyTo(proto_entity);
if (entity->HasFile()) {
auto *file_transmission_id = entity_request->mutable_upload_id();
file_transmission_id->set_file_id(get_next_file_id());
entity->SetFileTransmissionId(file_transmission_id);
upload_files.push_back(entity->GetFileDescriptor());
upload_files->push_back(entity->GetFileDescriptor());
}
}
auto Transaction::InsertEntity(Entity *entity) noexcept -> StatusCode {
ASSERT_CAN_ADD_INSERTION
auto *entity_request =
this->request->add_requests()->mutable_insert_request()->mutable_entity_request();
add_entity_to_request(entity, entity_request, &upload_files);
this->status = TransactionStatus::GO_ON();
return this->status.GetCode();
}
......@@ -166,14 +186,9 @@ auto Transaction::UpdateEntity(Entity *entity) noexcept -> StatusCode {
auto *entity_request =
this->request->add_requests()->mutable_update_request()->mutable_entity_request();
auto *proto_entity = entity_request->mutable_entity();
entity->CopyTo(proto_entity);
if (entity->HasFile()) {
auto *file_transmission_id = entity_request->mutable_upload_id();
entity->SetFileTransmissionId(file_transmission_id);
upload_files.push_back(entity->GetFileDescriptor());
}
add_entity_to_request(entity, entity_request, &upload_files);
this->status = TransactionStatus::GO_ON();
return this->status.GetCode();
}
......@@ -196,7 +211,7 @@ auto Transaction::ExecuteAsynchronously() noexcept -> StatusCode { // NOLINT
case MIXED_READ_AND_WRITE:
CAOSDB_LOG_ERROR_AND_RETURN_STATUS(
logger_name, StatusCode::UNSUPPORTED_FEATURE,
"MIXED_WRITE UNSUPPORTED: The current implementation does not support "
"MIXED_READ_AND_WRITE UNSUPPORTED: The current implementation does not support "
"mixed read and write transactions (containing retrievals, insertions, "
"deletions, and updates in one transaction).")
default:
......@@ -251,8 +266,9 @@ auto Transaction::ExecuteAsynchronously() noexcept -> StatusCode { // NOLINT
auto *entity_response =
sub_response.mutable_retrieve_response()->mutable_entity_response();
auto entity_id = entity_response->entity().id();
download_files[entity_id].file_transmission_id = entity_response->release_download_id();
// TODO(tf) handle error
download_files[entity_id].file_transmission_id =
Arena::CreateMessage<FileTransmissionId>(GetArena());
download_files[entity_id].file_transmission_id->CopyFrom(entity_response->download_id());
}
}
}
......@@ -290,7 +306,7 @@ auto Transaction::WaitForIt() const noexcept -> TransactionStatus { // NOLINT
switch (retrieve_response->retrieve_response_case()) {
case RetrieveResponseCase::kEntityResponse: {
auto *retrieve_entity_response = retrieve_response->release_entity_response();
auto *retrieve_entity_response = retrieve_response->mutable_entity_response();
result = std::make_unique<Entity>(retrieve_entity_response);
} break;
case RetrieveResponseCase::kSelectResult: {
......@@ -321,24 +337,24 @@ auto Transaction::WaitForIt() const noexcept -> TransactionStatus { // NOLINT
}
case TransactionResponseCase::kInsertResponse: {
auto *inserted_id_response = sub_response.mutable_insert_response()->release_id_response();
auto *inserted_id_response = sub_response.mutable_insert_response()->mutable_id_response();
result = std::make_unique<Entity>(inserted_id_response);
break;
}
case TransactionResponseCase::kDeleteResponse: {
auto *deleted_id_response = sub_response.mutable_delete_response()->release_id_response();
auto *deleted_id_response = sub_response.mutable_delete_response()->mutable_id_response();
result = std::make_unique<Entity>(deleted_id_response);
break;
}
case TransactionResponseCase::kUpdateResponse: {
auto *updated_id_response = sub_response.mutable_update_response()->release_id_response();
auto *updated_id_response = sub_response.mutable_update_response()->mutable_id_response();
result = std::make_unique<Entity>(updated_id_response);
break;
}
default:
CAOSDB_LOG_FATAL(logger_name) << "Received invalid TransactionResponseCase.";
break;
}
} // default to sub_response.transaction_response_case()
if (result != nullptr) {
if (result->HasErrors()) {
set_error = true;
......
This diff is collapsed.
......@@ -28,6 +28,13 @@
#include "caosdb/info.h" // for VersionInfo
#include "caosdb/logging.h" // for CAOSDB_LOG_TRACE
#include "caosdb/transaction.h" // for Transaction, ResultSet
#include "caosdb/transaction_status.h" // for TransactionSt...
#include <boost/log/core/record.hpp> // for record
#include <boost/log/detail/attachable_sstream_buf.hpp> // for basic_ostring...
#include <boost/log/sources/record_ostream.hpp> // for operator<<
#include <boost/preprocessor/seq/limits/enum_256.hpp> // for BOOST_PP_SEQ_...
#include <boost/preprocessor/seq/limits/size_256.hpp> // for BOOST_PP_SEQ_...
#include <exception> // for exception
#include <iostream> // for operator<<, basic_ostream, basic_ost...
#include <memory> // for unique_ptr, allocator, __shared_ptr_...
#include <string> // for operator<<, char_traits
......@@ -53,24 +60,14 @@ auto main() -> int {
// retrieve an entity
auto transaction(connection->CreateTransaction());
transaction->RetrieveById("120");
transaction->RetrieveById("21");
transaction->ExecuteAsynchronously();
auto t_stat = transaction->WaitForIt();
CAOSDB_LOG_INFO(logger_name) << "status: " << t_stat.GetCode() << " // "
<< t_stat.GetDescription();
const auto &result_set = transaction->GetResultSet();
if (result_set.size() > 0) {
// print information
const auto &ent = result_set.at(0);
const auto &props = ent.GetProperties();
std::cout << "Entity Name: " << ent.GetName() << std::endl;
std::cout << "Entity Description: " << ent.GetDescription() << std::endl;
std::cout << "Entity Properties: " << std::endl;
for (const auto &prop : props) {
std::cout << "----------\n" << prop.ToString() << std::endl;
}
} else {
std::cout << "No entity \"120\" retrieved, maybe it does not exist?\n" << std::endl;
for (const auto &entity : result_set) {
std::cout << entity.ToString() << std::endl;
}
// execute a query
......@@ -82,6 +79,11 @@ auto main() -> int {
t_stat = q_transaction->WaitForIt();
CAOSDB_LOG_INFO(logger_name) << "status: " << t_stat.GetCode() << " // "
<< t_stat.GetDescription();
const auto &result_set_2 = q_transaction->GetResultSet();
for (const auto &entity : result_set_2) {
std::cout << entity.ToString() << std::endl;
}
return 0;
} catch (const caosdb::exceptions::ConfigurationError &exc) {
std::cout << "ConfigurationError: " << exc.what() << std::endl;
......
......@@ -41,7 +41,7 @@ set(test_cases
# special linting for tests
set(_CMAKE_CXX_CLANG_TIDY_TEST_CHECKS
"${_CMAKE_CXX_CLANG_TIDY_CHECKS},-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"
"${_CMAKE_CXX_CLANG_TIDY_CHECKS},-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,-clang-analyzer-cplusplus.Move"
)
# add special cmake functions for gtest
......@@ -110,5 +110,10 @@ if (LCOV_PATH)
set_target_properties(ccaosdb PROPERTIES
COMPILE_FLAGS "${TARGET_CCAOSDB_COMPILE_FLAGS}")
else ()
if (NOT SKIP_CODE_COVERAGE)
message(WARNING "Could not generate code coverage report. Please install lcov.")
add_custom_target(unit_test_coverage ctest -L caosdb-cpplib-unit-tests
DEPENDS caosdb ccaosdb ${test_cases}
)
endif()
endif ()
......@@ -386,8 +386,8 @@ TEST_F(test_ccaosdb, test_entity) {
EXPECT_EQ(return_code, 0);
// cannot be created again without deletion
return_code = caosdb_entity_create_entity(&entity);
EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR);
// return_code = caosdb_entity_create_entity(&entity);
// EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR);
// deletion and re-creation is ok
return_code = caosdb_entity_delete_entity(&entity);
......@@ -431,8 +431,8 @@ TEST_F(test_ccaosdb, test_entity) {
caosdb_entity_entity_set_datatype(&entity, &in_type);
// verify that this doesn't work ...
return_code = caosdb_entity_entity_get_datatype(&entity, &in_type);
EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR);
// return_code = caosdb_entity_entity_get_datatype(&entity, &in_type);
// EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR);
caosdb_entity_datatype out_type;
// ... but does with a clean property
return_code = caosdb_entity_entity_get_datatype(&entity, &out_type);
......@@ -827,8 +827,8 @@ TEST_F(test_ccaosdb, test_entity_with_parent_and_property) {
char *out = nullptr; // NOLINT
// cannot assign an already assigned property
return_code = caosdb_entity_entity_get_property(&entity, &input_property, 0);
EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR);
// return_code = caosdb_entity_entity_get_property(&entity, &input_property, 0);
// EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR);
caosdb_entity_property output_property;
return_code = caosdb_entity_entity_get_property(&entity, &output_property, 0);
EXPECT_EQ(return_code, 0);
......
......@@ -22,11 +22,11 @@
#include "caosdb/certificate_provider.h" // for PemCertificateProvider
#include "caosdb/configuration.h" // for InsecureConnectionConfigura...
#include "caosdb/connection.h" // for ConnectionManager
#include "caosdb/exceptions.h" // for UnknownConnectionError
#include "caosdb/exceptions.h" // for ConnectionConfigurationError
#include "caosdb_test_utility.h" // for EXPECT_THROW_MESSAGE, TEST_...
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPartR...
#include "gtest/gtest_pred_impl.h" // for AssertionResult, TestInfo
#include <gtest/gtest_pred_impl.h> // for AssertionResult, TestInfo
#include <memory> // for allocator, operator!=, shar...
#include <string> // for operator+, string
......@@ -65,9 +65,16 @@ TEST_F(test_connection, configure_ssl_localhost_8080) {
}
TEST_F(test_connection, connection_manager_unknown_connection) {
EXPECT_THROW_MESSAGE(ConnectionManager::GetConnection("test"),
caosdb::exceptions::UnknownConnectionError,
"No connection named 'test' present.");
EXPECT_THROW_MESSAGE(
ConnectionManager::GetConnection("test"), caosdb::exceptions::ConnectionConfigurationError,
"Error with the connection named 'test': The connection 'test' has not been defined.");
}
TEST_F(test_connection, connection_missing_certificate) {
EXPECT_THROW_MESSAGE(ConnectionManager::GetConnection("missing"),
caosdb::exceptions::ConnectionConfigurationError,
std::string("Error with the connection named 'missing': ") +
"File does not exist (server_certificate_path): /missing");
}
TEST_F(test_connection, connection_manager_get_default_connection) {
......
......@@ -18,6 +18,16 @@
"username": "me",
"password": "secret!"
}
},
"missing": {
"host": "localhost",
"port": 8443,
"server_certificate_path": "/missing",
"authentication": {
"type": "plain",
"username": "me",
"password": "secret!"
}
}
},
"logging": {
......
......@@ -22,7 +22,7 @@
#include "caosdb/data_type.h" // for DataType, AtomicDataType
#include "caosdb/entity.h" // for Entity
#include "caosdb/entity/v1alpha1/main.pb.h" // for DataType, Ato...
#include "caosdb/entity/v1/main.pb.h" // for DataType, Ato...
#include "caosdb/logging.h" // for CAOSDB_LOG_DEBUG
#include "caosdb/protobuf_helper.h" // for CAOSDB_DEBUG_...
#include <boost/log/core/record.hpp> // for record
......@@ -39,10 +39,10 @@
#include <utility> // for pair
namespace caosdb::entity {
using ProtoEntity = caosdb::entity::v1alpha1::Entity;
using ProtoParent = caosdb::entity::v1alpha1::Parent;
using ProtoDataType = caosdb::entity::v1alpha1::DataType;
using ProtoAtomicDataType = caosdb::entity::v1alpha1::AtomicDataType;
using ProtoEntity = caosdb::entity::v1::Entity;
using ProtoParent = caosdb::entity::v1::Parent;
using ProtoDataType = caosdb::entity::v1::DataType;
using ProtoAtomicDataType = caosdb::entity::v1::AtomicDataType;
TEST(test_data_type, test_atomic) {
ProtoDataType proto_data_type;
......@@ -65,6 +65,7 @@ TEST(test_data_type, test_atomic) {
EXPECT_TRUE(data_type.IsAtomic());
EXPECT_EQ(data_type.GetAsAtomic(), map_el.first);
}
caosdb::utility::reset_arena();
}
TEST(test_data_type, test_reference) {
......@@ -129,4 +130,54 @@ TEST(test_data_type, test_data_type_to_string) {
EXPECT_EQ(data_type3.ToString(), "{\n \"atomicDataType\": \"ATOMIC_DATA_TYPE_INTEGER\"\n}\n");
}
TEST(test_data_type, data_type_copy_constructor) {
DataType data_type("person", true);
const auto dt_string = data_type.ToString();
// copy
const DataType copy_data_type(data_type); // NOLINT (explicit copy)
EXPECT_EQ(copy_data_type, data_type);
EXPECT_EQ(dt_string, copy_data_type.ToString());
}
TEST(test_data_type, data_type_move_constructor) {
DataType data_type("person", true);
const auto dt_string = data_type.ToString();
// copy for testing
const DataType copy_data_type(data_type);
// move
const DataType move_data_type(std::move(data_type)); // NOLINT
EXPECT_NE(data_type, copy_data_type); // NOLINT
EXPECT_NE(data_type.ToString(), dt_string); // NOLINT
EXPECT_EQ(copy_data_type, move_data_type);
EXPECT_EQ(move_data_type.ToString(), dt_string);
}
TEST(test_data_type, data_type_copy_assignment) {
DataType data_type("person", true);
const auto dt_string = data_type.ToString();
// copy
DataType copy_data_type = data_type; // NOLINT (explicit copy)
EXPECT_EQ(copy_data_type, data_type);
EXPECT_EQ(dt_string, copy_data_type.ToString());
}
TEST(test_data_type, data_type_move_assignment) {
DataType data_type("person", true);
const auto dt_string = data_type.ToString();
// copy for testing
const DataType copy_data_type(data_type);
// move
DataType move_data_type = std::move(data_type); // NOLINT
EXPECT_NE(data_type, copy_data_type); // NOLINT
EXPECT_NE(data_type.ToString(), dt_string); // NOLINT
EXPECT_EQ(copy_data_type, move_data_type);
EXPECT_EQ(move_data_type.ToString(), dt_string);
}
} // namespace caosdb::entity
......@@ -22,8 +22,8 @@
*/
#include "caosdb/data_type.h" // for DataType, AtomicDat...
#include "caosdb/entity.h" // for Entity, Property
#include "caosdb/entity/v1alpha1/main.grpc.pb.h" // for EntityTransactionSe...
#include "caosdb/entity/v1alpha1/main.pb.h" // for IdResponse, Message
#include "caosdb/entity/v1/main.grpc.pb.h" // for EntityTransactionSe...
#include "caosdb/entity/v1/main.pb.h" // for IdResponse, Message
#include "caosdb/message_code.h" // for MessageCode, ENTITY...
#include "caosdb/protobuf_helper.h" // for get_arena
#include "caosdb/status_code.h" // for StatusCode, FILE_DO...
......@@ -41,14 +41,14 @@
#include <utility> // for move
namespace caosdb::entity {
using caosdb::entity::v1alpha1::IdResponse;
using ProtoEntity = caosdb::entity::v1alpha1::Entity;
using ProtoParent = caosdb::entity::v1alpha1::Parent;
using ProtoProperty = caosdb::entity::v1alpha1::Property;
using ProtoAtomicDataType = caosdb::entity::v1alpha1::AtomicDataType;
using caosdb::entity::v1alpha1::EntityResponse;
using caosdb::entity::v1::IdResponse;
using ProtoEntity = caosdb::entity::v1::Entity;
using ProtoParent = caosdb::entity::v1::Parent;
using ProtoProperty = caosdb::entity::v1::Property;
using ProtoAtomicDataType = caosdb::entity::v1::AtomicDataType;
using caosdb::entity::v1::EntityResponse;
using caosdb::utility::get_arena;
using ProtoEntityRole = caosdb::entity::v1alpha1::EntityRole;
using ProtoEntityRole = caosdb::entity::v1::EntityRole;
TEST(test_entity, test_parent_setters) {
auto parent = Parent();
......@@ -142,34 +142,35 @@ TEST(test_entity, test_append_property) {
EXPECT_EQ(prop.GetDataType(), same_prop.GetDataType());
}
TEST(test_entity, test_copy_constructor) {
ProtoParent parent;
parent.set_description("the parent desc");
parent.set_id("the parent id");
parent.set_name("the parent name");
ProtoProperty property;
property.set_id("the-prop-id");
property.set_description("the prop-desc");
property.set_name("the-prop-name");
property.mutable_value()->mutable_list_values()->mutable_values()->Add()->set_double_value(25.5);
property.mutable_data_type()->mutable_list_data_type()->set_atomic_data_type(
TEST(test_entity, entity_copy_constructor) {
Arena arena;
auto *parent = Arena::CreateMessage<ProtoParent>(&arena);
parent->set_description("the parent desc");
parent->set_id("the parent id");
parent->set_name("the parent name");
auto *property = Arena::CreateMessage<ProtoProperty>(&arena);
property->set_id("the-prop-id");
property->set_description("the prop-desc");
property->set_name("the-prop-name");
property->mutable_value()->mutable_list_values()->mutable_values()->Add()->set_double_value(25.5);
property->mutable_data_type()->mutable_list_data_type()->set_atomic_data_type(
ProtoAtomicDataType::ATOMIC_DATA_TYPE_DOUBLE);
EntityResponse entity_response;
entity_response.mutable_entity()->set_id("the-id");
entity_response.mutable_entity()->set_name("the-name");
entity_response.mutable_entity()->set_role(ProtoEntityRole::ENTITY_ROLE_RECORD);
entity_response.mutable_entity()->set_description("the description");
entity_response.mutable_entity()->set_unit("the-unit");
entity_response.mutable_entity()->mutable_value()->mutable_scalar_value()->set_string_value(
auto *entity_response = Arena::CreateMessage<EntityResponse>(&arena);
entity_response->mutable_entity()->set_id("the-id");
entity_response->mutable_entity()->set_name("the-name");
entity_response->mutable_entity()->set_role(ProtoEntityRole::ENTITY_ROLE_RECORD);
entity_response->mutable_entity()->set_description("the description");
entity_response->mutable_entity()->set_unit("the-unit");
entity_response->mutable_entity()->mutable_value()->mutable_scalar_value()->set_string_value(
"the-value");
entity_response.mutable_entity()->mutable_version()->set_id("version-id");
entity_response.mutable_entity()->mutable_data_type()->mutable_reference_data_type()->set_name(
entity_response->mutable_entity()->mutable_version()->set_id("version-id");
entity_response->mutable_entity()->mutable_data_type()->mutable_reference_data_type()->set_name(
"refname");
entity_response.mutable_entity()->mutable_file_descriptor();
entity_response.mutable_entity()->mutable_properties()->Add()->CopyFrom(property);
entity_response.mutable_entity()->mutable_parents()->Add()->CopyFrom(parent);
entity_response->mutable_entity()->mutable_file_descriptor();
entity_response->mutable_entity()->mutable_properties()->Add()->CopyFrom(*property);
entity_response->mutable_entity()->mutable_parents()->Add()->CopyFrom(*parent);
Entity this_entity(&entity_response);
Entity this_entity(entity_response);
Entity copy_entity(this_entity);
EXPECT_EQ(this_entity, copy_entity);
......@@ -197,40 +198,41 @@ TEST(test_entity, test_copy_constructor) {
EXPECT_NE(this_entity.ToString(), copy_entity.ToString());
}
TEST(test_entity, test_move_constructor) {
ProtoParent parent;
parent.set_description("the parent desc");
parent.set_id("the parent id");
parent.set_name("the parent name");
ProtoProperty property;
property.set_id("the-prop-id");
property.set_description("the prop-desc");
property.set_name("the-prop-name");
property.mutable_value()->mutable_list_values()->mutable_values()->Add()->set_double_value(25.5);
property.mutable_data_type()->mutable_list_data_type()->set_atomic_data_type(
TEST(test_entity, entity_move_constructor) {
Arena arena;
auto *parent = Arena::CreateMessage<ProtoParent>(&arena);
parent->set_description("the parent desc");
parent->set_id("the parent id");
parent->set_name("the parent name");
auto *property = Arena::CreateMessage<ProtoProperty>(&arena);
property->set_id("the-prop-id");
property->set_description("the prop-desc");
property->set_name("the-prop-name");
property->mutable_value()->mutable_list_values()->mutable_values()->Add()->set_double_value(25.5);
property->mutable_data_type()->mutable_list_data_type()->set_atomic_data_type(
ProtoAtomicDataType::ATOMIC_DATA_TYPE_DOUBLE);
EntityResponse entity_response;
entity_response.mutable_errors()->Add()->set_code(25);
entity_response.mutable_errors()->Mutable(0)->set_description("asdf");
entity_response.mutable_warnings()->Add()->set_code(23);
entity_response.mutable_warnings()->Mutable(0)->set_description("asdgsafdg");
entity_response.mutable_infos()->Add()->set_code(235);
entity_response.mutable_infos()->Mutable(0)->set_description("asdfsad");
entity_response.mutable_entity()->set_id("the-id");
entity_response.mutable_entity()->set_name("the-name");
entity_response.mutable_entity()->set_role(ProtoEntityRole::ENTITY_ROLE_RECORD);
entity_response.mutable_entity()->set_description("the description");
entity_response.mutable_entity()->set_unit("the-unit");
entity_response.mutable_entity()->mutable_value()->mutable_scalar_value()->set_string_value(
auto *entity_response = Arena::CreateMessage<EntityResponse>(&arena);
entity_response->mutable_errors()->Add()->set_code(25);
entity_response->mutable_errors()->Mutable(0)->set_description("asdf");
entity_response->mutable_warnings()->Add()->set_code(23);
entity_response->mutable_warnings()->Mutable(0)->set_description("asdgsafdg");
entity_response->mutable_infos()->Add()->set_code(235);
entity_response->mutable_infos()->Mutable(0)->set_description("asdfsad");
entity_response->mutable_entity()->set_id("the-id");
entity_response->mutable_entity()->set_name("the-name");
entity_response->mutable_entity()->set_role(ProtoEntityRole::ENTITY_ROLE_RECORD);
entity_response->mutable_entity()->set_description("the description");
entity_response->mutable_entity()->set_unit("the-unit");
entity_response->mutable_entity()->mutable_value()->mutable_scalar_value()->set_string_value(
"the-value");
entity_response.mutable_entity()->mutable_version()->set_id("version-id");
entity_response.mutable_entity()->mutable_data_type()->mutable_reference_data_type()->set_name(
entity_response->mutable_entity()->mutable_version()->set_id("version-id");
entity_response->mutable_entity()->mutable_data_type()->mutable_reference_data_type()->set_name(
"refname");
entity_response.mutable_entity()->mutable_file_descriptor();
entity_response.mutable_entity()->mutable_properties()->Add()->CopyFrom(property);
entity_response.mutable_entity()->mutable_parents()->Add()->CopyFrom(parent);
entity_response->mutable_entity()->mutable_file_descriptor();
entity_response->mutable_entity()->mutable_properties()->Add()->CopyFrom(*property);
entity_response->mutable_entity()->mutable_parents()->Add()->CopyFrom(*parent);
Entity this_entity(&entity_response);
Entity this_entity(entity_response);
std::string original_string = this_entity.ToString();
Entity copy_entity(this_entity);
EXPECT_EQ(this_entity, copy_entity);
......@@ -263,7 +265,7 @@ TEST(test_entity, test_move_constructor) {
EXPECT_NE(move_entity.ToString(), copy_entity.ToString());
}
TEST(test_entity, test_property_copy_constructor) {
TEST(test_entity, property_copy_constructor) {
Property prop;
prop.SetName("prop_name");
prop.SetId("prop_id");
......@@ -283,7 +285,7 @@ TEST(test_entity, test_property_copy_constructor) {
EXPECT_EQ(prop.GetDataType(), other_prop.GetDataType());
}
TEST(test_entity, test_property_copy_assignment) {
TEST(test_entity, property_copy_assignment) {
Property prop;
prop.SetName("prop_name");
prop.SetId("prop_id");
......@@ -308,7 +310,7 @@ TEST(test_entity, test_property_copy_assignment) {
EXPECT_EQ(other_prop.GetName(), "other_prop_name");
}
TEST(test_entity, test_property_move_assignment) {
TEST(test_entity, property_move_assignment) {
Property prop;
prop.SetName("prop_name");
prop.SetId("prop_id");
......@@ -321,7 +323,7 @@ TEST(test_entity, test_property_move_assignment) {
// we compare the moved one with this one
const Property copy_prop(prop);
Property other_prop = std::move(prop);
Property other_prop = std::move(prop); // NOLINT
EXPECT_NE(prop, copy_prop); // NOLINT
EXPECT_NE(prop, other_prop); // NOLINT
EXPECT_NE(prop.ToString(), prop_string); // NOLINT
......@@ -343,6 +345,127 @@ TEST(test_entity, test_property_move_assignment) {
EXPECT_EQ(other_prop.GetName(), "other_prop_name");
}
TEST(test_entity, property_move_constructor) {
Property prop;
prop.SetName("prop_name");
prop.SetId("prop_id");
prop.SetImportance(Importance::RECOMMENDED);
prop.SetValue("prop_value");
prop.SetUnit("prop_unit");
prop.SetDataType("prop_dtype");
const auto prop_string = prop.ToString();
// we compare the moved one with this one
const Property copy_prop(prop);
Property other_prop(std::move(prop));
EXPECT_NE(prop, copy_prop); // NOLINT
EXPECT_NE(prop, other_prop); // NOLINT
EXPECT_NE(prop.ToString(), prop_string); // NOLINT
EXPECT_EQ(copy_prop.ToString(), prop_string);
EXPECT_EQ(other_prop.ToString(), prop_string);
EXPECT_EQ(copy_prop, other_prop);
EXPECT_EQ(copy_prop.GetName(), other_prop.GetName());
EXPECT_EQ(copy_prop.GetId(), other_prop.GetId());
EXPECT_EQ(copy_prop.GetImportance(), other_prop.GetImportance());
EXPECT_EQ(copy_prop.GetValue().ToString(), other_prop.GetValue().ToString());
EXPECT_EQ(copy_prop.GetUnit(), other_prop.GetUnit());
EXPECT_EQ(copy_prop.GetDataType(), other_prop.GetDataType());
other_prop.SetName("other_prop_name");
EXPECT_NE(copy_prop, other_prop);
EXPECT_NE(copy_prop.GetName(), other_prop.GetName());
EXPECT_EQ(copy_prop.GetName(), "prop_name");
EXPECT_EQ(other_prop.GetName(), "other_prop_name");
}
TEST(test_entity, parent_copy_constructor) {
Parent parent;
parent.SetId("par_id");
parent.SetName("par_name");
// copy
const Parent copy_parent(parent);
EXPECT_EQ(copy_parent, parent);
EXPECT_EQ(copy_parent.GetId(), parent.GetId());
EXPECT_EQ(copy_parent.GetName(), parent.GetName());
// change something
parent.SetName("new_name");
EXPECT_NE(copy_parent, parent);
EXPECT_EQ(copy_parent.GetId(), parent.GetId());
EXPECT_NE(copy_parent.GetName(), parent.GetName());
}
TEST(test_entity, parent_move_constructor) {
Parent parent;
parent.SetId("par_id");
parent.SetName("par_name");
const auto parent_string = parent.ToString();
// copy for testing
const Parent copy_parent = parent;
// move
Parent move_parent(std::move(parent));
EXPECT_NE(parent, copy_parent); // NOLINT
EXPECT_NE(parent, move_parent); // NOLINT
EXPECT_NE(parent.ToString(), parent_string); // NOLINT
EXPECT_EQ(copy_parent, move_parent);
EXPECT_EQ(copy_parent.GetId(), move_parent.GetId());
EXPECT_EQ(copy_parent.GetName(), move_parent.GetName());
// change something
move_parent.SetName("new_name");
EXPECT_NE(copy_parent, move_parent);
EXPECT_EQ(copy_parent.GetId(), move_parent.GetId());
EXPECT_NE(copy_parent.GetName(), move_parent.GetName());
}
TEST(test_entity, parent_copy_assignment) {
Parent parent;
parent.SetId("par_id");
parent.SetName("par_name");
// copy
const Parent copy_parent = parent;
EXPECT_EQ(copy_parent, parent);
EXPECT_EQ(copy_parent.GetId(), parent.GetId());
EXPECT_EQ(copy_parent.GetName(), parent.GetName());
// change something
parent.SetName("new_name");
EXPECT_NE(copy_parent, parent);
EXPECT_EQ(copy_parent.GetId(), parent.GetId());
EXPECT_NE(copy_parent.GetName(), parent.GetName());
}
TEST(test_entity, parent_move_assignment) {
Parent parent;
parent.SetId("par_id");
parent.SetName("par_name");
const auto parent_string = parent.ToString();
// copy for testing
const Parent copy_parent = parent;
// move
Parent move_parent = std::move(parent);
EXPECT_NE(parent, copy_parent); // NOLINT
EXPECT_NE(parent, move_parent); // NOLINT
EXPECT_NE(parent.ToString(), parent_string); // NOLINT
EXPECT_EQ(copy_parent, move_parent);
EXPECT_EQ(copy_parent.GetId(), move_parent.GetId());
EXPECT_EQ(copy_parent.GetName(), move_parent.GetName());
// change something
move_parent.SetName("new_name");
EXPECT_NE(copy_parent, move_parent);
EXPECT_EQ(copy_parent.GetId(), move_parent.GetId());
EXPECT_NE(copy_parent.GetName(), move_parent.GetName());
}
TEST(test_entity, test_copy_to) {
auto entity = Entity();
entity.SetRole(Role::RECORD);
......@@ -670,10 +793,11 @@ TEST(test_entity, test_description) {
entity.SetDescription("desc entity");
property.SetDescription("desc property");
// Parent has not setter
ProtoParent protoParent;
protoParent.set_description("desc parent");
parent = Parent(&protoParent);
// Parent has no setter
Arena arena;
auto *protoParent = Arena::CreateMessage<ProtoParent>(&arena);
protoParent->set_description("desc parent");
parent = Parent(protoParent);
EXPECT_EQ(entity.GetDescription(), "desc entity");
EXPECT_EQ(property.GetDescription(), "desc property");
......@@ -693,7 +817,7 @@ TEST(test_entity, test_add_file) {
EXPECT_EQ(entity.SetLocalPath(TEST_DATA_DIR + "/test.json"), StatusCode::SUCCESS);
}
TEST(test_entity, test_move_assign) {
TEST(test_entity, entity_move_assignment) {
Entity entity1;
entity1.SetRole(Role::RECORD_TYPE);
entity1.SetName("E1");
......@@ -757,8 +881,8 @@ TEST(test_entity, test_property_to_string) {
EXPECT_EQ(property.ToString(), "{}\n");
property.SetDataType(AtomicDataType::DOUBLE);
EXPECT_EQ(property.ToString(),
"{\n \"dataType\": {\n \"atomicDataType\": \"ATOMIC_DATA_TYPE_DOUBLE\"\n }\n}\n");
EXPECT_EQ(property.ToString(), "{\n \"dataType\": {\n \"atomicDataType\": "
"\"ATOMIC_DATA_TYPE_DOUBLE\"\n }\n}\n");
}
TEST(test_entity, test_parents_to_string) {
......@@ -780,13 +904,14 @@ TEST(test_entity, test_parent_to_string) {
}
TEST(test_entity, test_messages_to_string) {
IdResponse idResponse;
idResponse.set_id("entity_id");
auto *error = idResponse.add_errors();
Arena arena;
auto *idResponse = Arena::CreateMessage<IdResponse>(&arena);
idResponse->set_id("entity_id");
auto *error = idResponse->add_errors();
error->set_code(MessageCode::ENTITY_DOES_NOT_EXIST);
error->set_description("error_desc");
Entity entity(&idResponse);
Entity entity(idResponse);
// Messages are not printed, currently.
EXPECT_EQ(entity.ToString(), "{\n \"id\": \"entity_id\",\n \"version\": {}\n}\n");
......@@ -795,13 +920,14 @@ TEST(test_entity, test_messages_to_string) {
}
TEST(test_entity, test_message_to_string) {
IdResponse idResponse;
idResponse.set_id("entity_id");
auto *error = idResponse.add_errors();
Arena arena;
auto *idResponse = Arena::CreateMessage<IdResponse>(&arena);
idResponse->set_id("entity_id");
auto *error = idResponse->add_errors();
error->set_code(MessageCode::ENTITY_DOES_NOT_EXIST);
error->set_description("error_desc");
Entity entity(&idResponse);
Entity entity(idResponse);
// Messages are not printed, currently.
EXPECT_EQ(entity.ToString(), "{\n \"id\": \"entity_id\",\n \"version\": {}\n}\n");
......
......@@ -19,15 +19,14 @@
*/
#include "caosdb/file_transmission/file_writer.h"
#include "caosdb/file_transmission/file_reader.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 <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 = boost::filesystem;
namespace fs = std::filesystem;
namespace caosdb::transaction {
......
......@@ -21,14 +21,14 @@
*/
#include "caosdb/info.h" // for VersionInfo
#include "caosdb/info/v1alpha1/main.pb.h" // for VersionInfo
#include "caosdb/info/v1/main.pb.h" // for VersionInfo
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiRe...
#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, TEST
#include <memory> // for allocator
namespace caosdb::info {
using ProtoVersionInfo = caosdb::info::v1alpha1::VersionInfo;
using ProtoVersionInfo = caosdb::info::v1::VersionInfo;
TEST(test_info, create_info_from_proto_info) {
auto *origial = new ProtoVersionInfo();
......
......@@ -22,7 +22,7 @@
#include "caosdb/data_type.h" // for DataType, AtomicDataType
#include "caosdb/entity.h" // for Entity
#include "caosdb/entity/v1alpha1/main.pb.h" // for AtomicDataType, DataType
#include "caosdb/entity/v1/main.pb.h" // for AtomicDataType, DataType
#include "caosdb/value.h" // for Value
#include <cstdint> // for int64_t
#include <gtest/gtest-message.h> // for Message
......@@ -33,10 +33,10 @@
#include <vector> // for vector
namespace caosdb::entity {
using ProtoEntity = caosdb::entity::v1alpha1::Entity;
using ProtoParent = caosdb::entity::v1alpha1::Parent;
using ProtoDataType = caosdb::entity::v1alpha1::DataType;
using ProtoAtomicDataType = caosdb::entity::v1alpha1::AtomicDataType;
using ProtoEntity = caosdb::entity::v1::Entity;
using ProtoParent = caosdb::entity::v1::Parent;
using ProtoDataType = caosdb::entity::v1::DataType;
using ProtoAtomicDataType = caosdb::entity::v1::AtomicDataType;
TEST(test_list_property, test_list_of_text) {
Property list_property;
......
......@@ -21,87 +21,92 @@
*/
#include "caosdb/data_type.h" // for DataType, ReferenceDataType
#include "caosdb/entity.h" // for Entity
#include "caosdb/entity/v1alpha1/main.pb.h" // for RepeatedPtrField, Message
#include "caosdb/entity/v1/main.pb.h" // for RepeatedPtrField, Message
#include <google/protobuf/arena.h> // for Arena
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPa...
#include <gtest/gtest_pred_impl.h> // for Test, TestInfo, TEST
#include <memory> // for allocator
namespace caosdb {
using ProtoEntity = caosdb::entity::v1alpha1::Entity;
using ProtoEntity = caosdb::entity::v1::Entity;
using caosdb::entity::Entity;
using caosdb::entity::v1alpha1::Message;
using caosdb::entity::v1::Message;
using google::protobuf::Arena;
TEST(test_protobuf, test_swap_trivial) {
Message message_source;
message_source.set_code(1234);
message_source.set_description("desc");
Arena arena;
auto *message_source = Arena::CreateMessage<Message>(&arena);
message_source->set_code(1234);
message_source->set_description("desc");
Message message_destination;
auto *message_destination = Arena::CreateMessage<Message>(&arena);
EXPECT_EQ(message_source.code(), 1234);
EXPECT_EQ(message_source.description(), "desc");
EXPECT_EQ(message_destination.code(), 0);
EXPECT_EQ(message_destination.description(), "");
EXPECT_EQ(message_source->code(), 1234);
EXPECT_EQ(message_source->description(), "desc");
EXPECT_EQ(message_destination->code(), 0);
EXPECT_EQ(message_destination->description(), "");
message_source.Swap(&message_destination);
message_source->Swap(message_destination);
EXPECT_EQ(message_source.code(), 0);
EXPECT_EQ(message_source.description(), "");
EXPECT_EQ(message_destination.code(), 1234);
EXPECT_EQ(message_destination.description(), "desc");
EXPECT_EQ(message_source->code(), 0);
EXPECT_EQ(message_source->description(), "");
EXPECT_EQ(message_destination->code(), 1234);
EXPECT_EQ(message_destination->description(), "desc");
}
TEST(test_protobuf, test_swap_nested) {
ProtoEntity entity_source;
entity_source.set_id("entity_id");
auto *version_source = entity_source.mutable_version();
Arena arena;
auto *entity_source = Arena::CreateMessage<ProtoEntity>(&arena);
entity_source->set_id("entity_id");
auto *version_source = entity_source->mutable_version();
version_source->set_id("version_id");
ProtoEntity entity_destination;
auto *version_destination = entity_destination.mutable_version();
auto *entity_destination = Arena::CreateMessage<ProtoEntity>(&arena);
auto *version_destination = entity_destination->mutable_version();
EXPECT_EQ(entity_source.id(), "entity_id");
EXPECT_EQ(entity_source.version().id(), "version_id");
EXPECT_EQ(entity_source->id(), "entity_id");
EXPECT_EQ(entity_source->version().id(), "version_id");
EXPECT_EQ(version_source->id(), "version_id");
EXPECT_EQ(entity_destination.id(), "");
EXPECT_EQ(entity_destination.version().id(), "");
EXPECT_EQ(entity_destination->id(), "");
EXPECT_EQ(entity_destination->version().id(), "");
EXPECT_EQ(version_destination->id(), "");
entity_source.Swap(&entity_destination);
entity_source->Swap(entity_destination);
EXPECT_EQ(entity_source.id(), "");
EXPECT_EQ(entity_source.version().id(), "");
EXPECT_EQ(entity_destination.id(), "entity_id");
EXPECT_EQ(entity_destination.version().id(), "version_id");
EXPECT_EQ(entity_source->id(), "");
EXPECT_EQ(entity_source->version().id(), "");
EXPECT_EQ(entity_destination->id(), "entity_id");
EXPECT_EQ(entity_destination->version().id(), "version_id");
// has not been swapped!
EXPECT_EQ(version_source->id(), "version_id");
EXPECT_EQ(version_destination->id(), "");
// Member pointers to nested messages have been swapped
EXPECT_EQ(entity_source.mutable_version(), version_destination);
EXPECT_EQ(entity_destination.mutable_version(), version_source);
EXPECT_EQ(entity_source->mutable_version(), version_destination);
EXPECT_EQ(entity_destination->mutable_version(), version_source);
}
TEST(test_protobuf, test_copy_nested) {
ProtoEntity entity_source;
auto *data_type_source = entity_source.mutable_data_type();
Arena arena;
auto *entity_source = Arena::CreateMessage<ProtoEntity>(&arena);
auto *data_type_source = entity_source->mutable_data_type();
data_type_source->mutable_reference_data_type()->set_name("src_per");
ProtoEntity entity_destination;
auto *data_type_destination = entity_destination.mutable_data_type();
auto *entity_destination = Arena::CreateMessage<ProtoEntity>(&arena);
auto *data_type_destination = entity_destination->mutable_data_type();
data_type_destination->mutable_reference_data_type()->set_name("dest_per");
EXPECT_EQ(entity_source.data_type().reference_data_type().name(), "src_per");
EXPECT_EQ(entity_destination.data_type().reference_data_type().name(), "dest_per");
EXPECT_EQ(entity_source->data_type().reference_data_type().name(), "src_per");
EXPECT_EQ(entity_destination->data_type().reference_data_type().name(), "dest_per");
entity_destination.CopyFrom(entity_source);
entity_destination->CopyFrom(*entity_source);
EXPECT_EQ(entity_source.data_type().reference_data_type().name(), "src_per");
EXPECT_EQ(entity_destination.data_type().reference_data_type().name(), "src_per");
EXPECT_EQ(entity_source->data_type().reference_data_type().name(), "src_per");
EXPECT_EQ(entity_destination->data_type().reference_data_type().name(), "src_per");
Entity entity(&entity_destination);
Entity entity(entity_destination);
EXPECT_EQ(entity.GetDataType().GetAsReference().GetName(), "src_per");
const Entity &copy_entity(entity);
......
......@@ -20,13 +20,15 @@
#include "caosdb/configuration.h" // for InsecureConnectionConfig...
#include "caosdb/connection.h" // for Connection
#include "caosdb/entity.h" // for Entity
#include "caosdb/entity/v1alpha1/main.pb.h" // for Entity
#include "caosdb/entity/v1/main.pb.h" // for Entity
#include "caosdb/exceptions.h" // for ConnectionError
#include "caosdb/status_code.h"
#include "caosdb/status_code.h" // for StatusCode
#include "caosdb/transaction.h" // for Transaction
#include "caosdb/transaction_handler.h" // for MultiTransactionResponse
#include "caosdb/transaction_status.h" // for ConnectionError
#include "caosdb_test_utility.h" // for EXPECT_THROW_MESSAGE
#include <algorithm> // for max
#include <google/protobuf/arena.h> // for Arena
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPa...
#include <gtest/gtest_pred_impl.h> // for Test, TestInfo, TEST
......@@ -41,9 +43,9 @@ using caosdb::configuration::InsecureConnectionConfiguration;
using caosdb::connection::Connection;
using caosdb::entity::Entity;
using caosdb::exceptions::ConnectionError;
using ProtoEntity = caosdb::entity::v1alpha1::Entity;
using ProtoEntity = caosdb::entity::v1::Entity;
using caosdb::entity::Role;
using caosdb::entity::v1alpha1::RetrieveResponse;
using caosdb::entity::v1::RetrieveResponse;
TEST(test_transaction, create_transaction) {
const auto *host = "localhost";
......@@ -113,9 +115,10 @@ TEST(test_transaction, test_multi_result_set_empty) {
TEST(test_transaction, test_multi_result_iterator) {
std::vector<std::unique_ptr<Entity>> one_elem;
RetrieveResponse response;
response.mutable_entity_response()->mutable_entity()->set_id("100");
one_elem.push_back(std::make_unique<Entity>(response.release_entity_response()));
Arena arena;
auto *response = Arena::CreateMessage<RetrieveResponse>(&arena);
response->mutable_entity_response()->mutable_entity()->set_id("100");
one_elem.push_back(std::make_unique<Entity>(response->mutable_entity_response()));
MultiResultSet rs(std::move(one_elem));
EXPECT_EQ(rs.size(), 1);
......@@ -127,9 +130,10 @@ TEST(test_transaction, test_multi_result_iterator) {
TEST(test_transaction, test_multi_result_set_one) {
std::vector<std::unique_ptr<Entity>> one_elem;
RetrieveResponse response;
response.mutable_entity_response()->mutable_entity()->set_id("100");
one_elem.push_back(std::make_unique<Entity>(response.release_entity_response()));
Arena arena;
auto *response = Arena::CreateMessage<RetrieveResponse>(&arena);
response->mutable_entity_response()->mutable_entity()->set_id("100");
one_elem.push_back(std::make_unique<Entity>(response->mutable_entity_response()));
MultiResultSet rs(std::move(one_elem));
EXPECT_EQ(rs.size(), 1);
......@@ -139,27 +143,28 @@ TEST(test_transaction, test_multi_result_set_one) {
TEST(test_transaction, test_multi_result_set_three) {
std::vector<std::unique_ptr<Entity>> three_elem;
MultiTransactionResponse response;
response.add_responses()
Arena arena;
auto *response = Arena::CreateMessage<MultiTransactionResponse>(&arena);
response->add_responses()
->mutable_retrieve_response()
->mutable_entity_response()
->mutable_entity()
->set_id("100");
auto *entity_with_error =
response.add_responses()->mutable_retrieve_response()->mutable_entity_response();
response->add_responses()->mutable_retrieve_response()->mutable_entity_response();
entity_with_error->mutable_entity()->set_id("101");
entity_with_error->add_errors()->set_code(1);
response.add_responses()
response->add_responses()
->mutable_retrieve_response()
->mutable_entity_response()
->mutable_entity()
->set_id("102");
auto *responses = response.mutable_responses();
auto *responses = response->mutable_responses();
std::vector<std::unique_ptr<Entity>> entities;
for (auto sub_response : *responses) {
three_elem.push_back(std::make_unique<Entity>(
sub_response.mutable_retrieve_response()->release_entity_response()));
sub_response.mutable_retrieve_response()->mutable_entity_response()));
}
MultiResultSet rs(std::move(three_elem));
......
......@@ -21,7 +21,7 @@
*/
#include "caosdb/value.h" // for Value
#include "caosdb/entity/v1alpha1/main.pb.h" // for AtomicDataType, DataType
#include "caosdb/entity/v1/main.pb.h" // for AtomicDataType, DataType
#include "caosdb/protobuf_helper.h" // for ProtoMessageWrapper
#include <algorithm> // for max
#include <cmath> // for isnan
......@@ -33,11 +33,11 @@
#include <vector> // for vector
namespace caosdb::entity {
using ProtoValue = caosdb::entity::v1alpha1::Value;
using ProtoEntity = caosdb::entity::v1alpha1::Entity;
using ProtoParent = caosdb::entity::v1alpha1::Parent;
using ProtoDataType = caosdb::entity::v1alpha1::DataType;
using ProtoAtomicDataType = caosdb::entity::v1alpha1::AtomicDataType;
using ProtoValue = caosdb::entity::v1::Value;
using ProtoEntity = caosdb::entity::v1::Entity;
using ProtoParent = caosdb::entity::v1::Parent;
using ProtoDataType = caosdb::entity::v1::DataType;
using ProtoAtomicDataType = caosdb::entity::v1::AtomicDataType;
TEST(test_value, test_null) {
Value value;
......@@ -188,8 +188,8 @@ TEST(test_value, test_value_to_string) {
EXPECT_EQ(value3.ToString(), "{\n \"scalarValue\": {\n \"doubleValue\": 2.6\n }\n}\n");
Value value4(std::vector<bool>{true, false});
EXPECT_EQ(value4.ToString(),
"{\n \"listValues\": {\n \"values\": [\n {\n \"booleanValue\": true\n },\n "
EXPECT_EQ(value4.ToString(), "{\n \"listValues\": {\n \"values\": [\n {\n "
"\"booleanValue\": true\n },\n "
"{\n \"booleanValue\": false\n }\n ]\n }\n}\n");
}
......