From 7f07dded5183b1b019b7ffb040e971d7fb68b0fe Mon Sep 17 00:00:00 2001 From: florian <f.spreckelsen@inidscale.com> Date: Thu, 12 Aug 2021 11:43:54 +0200 Subject: [PATCH] TST: Check for deletability beffore assignement --- src/ccaosdb.cpp | 59 ++++++++++++++++++++++++++++++++++++++++--- test/test_ccaosdb.cpp | 10 ++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/ccaosdb.cpp b/src/ccaosdb.cpp index 23a4dc2..ef9eaa6 100644 --- a/src/ccaosdb.cpp +++ b/src/ccaosdb.cpp @@ -177,6 +177,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR, caosdb_connection_certificate_provider *out, const char *path), { + if (out->_deletable) { + return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; + } out->wrapped_certificate_provider = new caosdb::configuration::PemFileCertificateProvider( std::string(path)); @@ -202,6 +205,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR, caosdb_authentication_authenticator *out, const char *username, const char *password), { + if (out->_deletable) { + return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; + } out->wrapped_authenticator = new caosdb::authentication::PlainPasswordAuthenticator( std::string(username), std::string(password)); @@ -229,6 +235,9 @@ ERROR_RETURN_CODE( const int port, caosdb_authentication_authenticator *authenticator, caosdb_connection_certificate_provider *provider), { + if (out->_deletable) { + return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; + } auto host_str = std::string(host); if (authenticator != nullptr && provider != nullptr) { auto wrapped_provider = @@ -268,6 +277,9 @@ ERROR_RETURN_CODE( caosdb_connection_connection_configuration *out, const char *host, const int port), { + if (out->_deletable) { + return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; + } out->wrapped_connection_configuration = new caosdb::configuration::InsecureConnectionConfiguration(host, port); out->_deletable = true; @@ -293,6 +305,9 @@ ERROR_RETURN_CODE( caosdb_connection_connection *out, const caosdb_connection_connection_configuration *configuration), { + if (out->_deletable) { + return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; + } caosdb::configuration::ConnectionConfiguration *config = static_cast<caosdb::configuration::ConnectionConfiguration *>( configuration->wrapped_connection_configuration); @@ -352,8 +367,12 @@ ERROR_RETURN_CODE( int caosdb_connection_connection_manager_get_default_connection( caosdb_connection_connection *out), { + if (out->_deletable) { + return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; + } out->wrapped_connection = caosdb::connection::ConnectionManager::GetDefaultConnection().get(); + out->_deletable = false; return 0; }) @@ -361,13 +380,16 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_connection_connection_manager_get_connection( caosdb_connection_connection *out, const char *name), { + if (out->_deletable) { + return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; + } out->wrapped_connection = caosdb::connection::ConnectionManager::GetConnection( std::string(name)) .get(); - // managed by the connection manager now, so not - // to be deleted manually - out->_deletable = false; + // managed by the connection manager now, so not + // to be deleted manually + out->_deletable = false; return 0; }) @@ -379,6 +401,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR, caosdb_connection_connection *connection, caosdb_transaction_transaction *out), { + if (out->_deletable) { + return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; + } auto *wrapped_connection = static_cast<caosdb::connection::Connection *>( connection->wrapped_connection); @@ -449,11 +474,15 @@ ERROR_RETURN_CODE(GENERIC_ERROR, caosdb_transaction_transaction *transaction, caosdb_transaction_result_set *out), { + if (out->_deletable) { + return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; + } auto *wrapped_transaction = static_cast<caosdb::transaction::Transaction *>( transaction->wrapped_transaction); out->wrapped_result_set = (void *)(&(wrapped_transaction->GetResultSet())); + out->_deletable = false; return 0; }) @@ -499,6 +528,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_create_entity(caosdb_entity_entity *out), { + if (out->_deletable) { + return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; + } out->wrapped_entity = new caosdb::entity::Entity(); out->_deletable = true; return 0; @@ -517,6 +549,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE( GENERIC_ERROR, int caosdb_entity_create_property(caosdb_entity_property *out), { + if (out->_deletable) { + return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; + } out->wrapped_property = new caosdb::entity::Property(); out->_deletable = true; return 0; @@ -534,6 +569,9 @@ ERROR_RETURN_CODE( ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_create_parent(caosdb_entity_parent *out), { + if (out->_deletable) { + return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; + } out->wrapped_parent = new caosdb::entity::Parent(); out->_deletable = true; return 0; @@ -576,6 +614,9 @@ ERROR_RETURN_CODE( int caosdb_entity_entity_get_error(caosdb_entity_entity *entity, caosdb_entity_message *out, int index), { + if (out->_deletable) { + return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; + } auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); out->wrapped_message = wrapped_entity->GetErrors().mutable_at(index); @@ -599,6 +640,9 @@ ERROR_RETURN_CODE( int caosdb_entity_entity_get_warning(caosdb_entity_entity *entity, caosdb_entity_message *out, int index), { + if (out->_deletable) { + return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; + } auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); out->wrapped_message = wrapped_entity->GetWarnings().mutable_at(index); @@ -622,6 +666,9 @@ ERROR_RETURN_CODE( int caosdb_entity_entity_get_info(caosdb_entity_entity *entity, caosdb_entity_message *out, int index), { + if (out->_deletable) { + return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; + } auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); out->wrapped_message = wrapped_entity->GetInfos().mutable_at(index); @@ -645,6 +692,9 @@ ERROR_RETURN_CODE( int caosdb_entity_entity_get_property(caosdb_entity_entity *entity, caosdb_entity_property *out, int index), { + if (out->_deletable) { + return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; + } auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); out->wrapped_property = wrapped_entity->GetProperties().mutable_at(index); @@ -668,6 +718,9 @@ ERROR_RETURN_CODE( int caosdb_entity_entity_get_parent(caosdb_entity_entity *entity, caosdb_entity_parent *out, int index), { + if (out->_deletable) { + return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; + } auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); out->wrapped_parent = wrapped_entity->GetParents().mutable_at(index); diff --git a/test/test_ccaosdb.cpp b/test/test_ccaosdb.cpp index 0943702..6559167 100644 --- a/test/test_ccaosdb.cpp +++ b/test/test_ccaosdb.cpp @@ -146,6 +146,16 @@ TEST_F(test_ccaosdb, test_entity) { int return_code(caosdb_entity_create_entity(&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); + + // deletion and re-creation is ok + return_code = caosdb_entity_delete_entity(&entity); + EXPECT_EQ(return_code, 0); + return_code = caosdb_entity_create_entity(&entity); + EXPECT_EQ(return_code, 0); + // In-depth check for one pair of setter and getter, just compare // the strings for the rest return_code = caosdb_entity_entity_set_name(&entity, "length"); -- GitLab