Skip to content
Snippets Groups Projects
Commit 7f07dded authored by florian's avatar florian
Browse files

TST: Check for deletability beffore assignement

parent 18e4973d
No related branches found
No related tags found
3 merge requests!12F consolidation,!9Draft: API: remove UniqueResult, lower-case at, size for ResultSet,!8ENH: Add retrieval and queries to Extern C interface
Pipeline #11824 passed
Pipeline: caosdb-cppinttest

#11825

    This commit is part of merge request !8. Comments created here will be created in the context of that merge request.
    ...@@ -177,6 +177,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ...@@ -177,6 +177,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
    caosdb_connection_certificate_provider *out, caosdb_connection_certificate_provider *out,
    const char *path), const char *path),
    { {
    if (out->_deletable) {
    return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR;
    }
    out->wrapped_certificate_provider = out->wrapped_certificate_provider =
    new caosdb::configuration::PemFileCertificateProvider( new caosdb::configuration::PemFileCertificateProvider(
    std::string(path)); std::string(path));
    ...@@ -202,6 +205,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ...@@ -202,6 +205,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
    caosdb_authentication_authenticator *out, caosdb_authentication_authenticator *out,
    const char *username, const char *password), const char *username, const char *password),
    { {
    if (out->_deletable) {
    return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR;
    }
    out->wrapped_authenticator = out->wrapped_authenticator =
    new caosdb::authentication::PlainPasswordAuthenticator( new caosdb::authentication::PlainPasswordAuthenticator(
    std::string(username), std::string(password)); std::string(username), std::string(password));
    ...@@ -229,6 +235,9 @@ ERROR_RETURN_CODE( ...@@ -229,6 +235,9 @@ ERROR_RETURN_CODE(
    const int port, caosdb_authentication_authenticator *authenticator, const int port, caosdb_authentication_authenticator *authenticator,
    caosdb_connection_certificate_provider *provider), caosdb_connection_certificate_provider *provider),
    { {
    if (out->_deletable) {
    return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR;
    }
    auto host_str = std::string(host); auto host_str = std::string(host);
    if (authenticator != nullptr && provider != nullptr) { if (authenticator != nullptr && provider != nullptr) {
    auto wrapped_provider = auto wrapped_provider =
    ...@@ -268,6 +277,9 @@ ERROR_RETURN_CODE( ...@@ -268,6 +277,9 @@ ERROR_RETURN_CODE(
    caosdb_connection_connection_configuration *out, const char *host, caosdb_connection_connection_configuration *out, const char *host,
    const int port), const int port),
    { {
    if (out->_deletable) {
    return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR;
    }
    out->wrapped_connection_configuration = out->wrapped_connection_configuration =
    new caosdb::configuration::InsecureConnectionConfiguration(host, port); new caosdb::configuration::InsecureConnectionConfiguration(host, port);
    out->_deletable = true; out->_deletable = true;
    ...@@ -293,6 +305,9 @@ ERROR_RETURN_CODE( ...@@ -293,6 +305,9 @@ ERROR_RETURN_CODE(
    caosdb_connection_connection *out, caosdb_connection_connection *out,
    const caosdb_connection_connection_configuration *configuration), const caosdb_connection_connection_configuration *configuration),
    { {
    if (out->_deletable) {
    return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR;
    }
    caosdb::configuration::ConnectionConfiguration *config = caosdb::configuration::ConnectionConfiguration *config =
    static_cast<caosdb::configuration::ConnectionConfiguration *>( static_cast<caosdb::configuration::ConnectionConfiguration *>(
    configuration->wrapped_connection_configuration); configuration->wrapped_connection_configuration);
    ...@@ -352,8 +367,12 @@ ERROR_RETURN_CODE( ...@@ -352,8 +367,12 @@ ERROR_RETURN_CODE(
    int caosdb_connection_connection_manager_get_default_connection( int caosdb_connection_connection_manager_get_default_connection(
    caosdb_connection_connection *out), caosdb_connection_connection *out),
    { {
    if (out->_deletable) {
    return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR;
    }
    out->wrapped_connection = out->wrapped_connection =
    caosdb::connection::ConnectionManager::GetDefaultConnection().get(); caosdb::connection::ConnectionManager::GetDefaultConnection().get();
    out->_deletable = false;
    return 0; return 0;
    }) })
    ...@@ -361,13 +380,16 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ...@@ -361,13 +380,16 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
    int caosdb_connection_connection_manager_get_connection( int caosdb_connection_connection_manager_get_connection(
    caosdb_connection_connection *out, const char *name), caosdb_connection_connection *out, const char *name),
    { {
    if (out->_deletable) {
    return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR;
    }
    out->wrapped_connection = out->wrapped_connection =
    caosdb::connection::ConnectionManager::GetConnection( caosdb::connection::ConnectionManager::GetConnection(
    std::string(name)) std::string(name))
    .get(); .get();
    // managed by the connection manager now, so not // managed by the connection manager now, so not
    // to be deleted manually // to be deleted manually
    out->_deletable = false; out->_deletable = false;
    return 0; return 0;
    }) })
    ...@@ -379,6 +401,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ...@@ -379,6 +401,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
    caosdb_connection_connection *connection, caosdb_connection_connection *connection,
    caosdb_transaction_transaction *out), caosdb_transaction_transaction *out),
    { {
    if (out->_deletable) {
    return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR;
    }
    auto *wrapped_connection = auto *wrapped_connection =
    static_cast<caosdb::connection::Connection *>( static_cast<caosdb::connection::Connection *>(
    connection->wrapped_connection); connection->wrapped_connection);
    ...@@ -449,11 +474,15 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ...@@ -449,11 +474,15 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
    caosdb_transaction_transaction *transaction, caosdb_transaction_transaction *transaction,
    caosdb_transaction_result_set *out), caosdb_transaction_result_set *out),
    { {
    if (out->_deletable) {
    return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR;
    }
    auto *wrapped_transaction = auto *wrapped_transaction =
    static_cast<caosdb::transaction::Transaction *>( static_cast<caosdb::transaction::Transaction *>(
    transaction->wrapped_transaction); transaction->wrapped_transaction);
    out->wrapped_result_set = out->wrapped_result_set =
    (void *)(&(wrapped_transaction->GetResultSet())); (void *)(&(wrapped_transaction->GetResultSet()));
    out->_deletable = false;
    return 0; return 0;
    }) })
    ...@@ -499,6 +528,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ...@@ -499,6 +528,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
    ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE(GENERIC_ERROR,
    int caosdb_entity_create_entity(caosdb_entity_entity *out), { 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->wrapped_entity = new caosdb::entity::Entity();
    out->_deletable = true; out->_deletable = true;
    return 0; return 0;
    ...@@ -517,6 +549,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ...@@ -517,6 +549,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
    ERROR_RETURN_CODE( ERROR_RETURN_CODE(
    GENERIC_ERROR, int caosdb_entity_create_property(caosdb_entity_property *out), 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->wrapped_property = new caosdb::entity::Property();
    out->_deletable = true; out->_deletable = true;
    return 0; return 0;
    ...@@ -534,6 +569,9 @@ ERROR_RETURN_CODE( ...@@ -534,6 +569,9 @@ ERROR_RETURN_CODE(
    ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE(GENERIC_ERROR,
    int caosdb_entity_create_parent(caosdb_entity_parent *out), { 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->wrapped_parent = new caosdb::entity::Parent();
    out->_deletable = true; out->_deletable = true;
    return 0; return 0;
    ...@@ -576,6 +614,9 @@ ERROR_RETURN_CODE( ...@@ -576,6 +614,9 @@ ERROR_RETURN_CODE(
    int caosdb_entity_entity_get_error(caosdb_entity_entity *entity, int caosdb_entity_entity_get_error(caosdb_entity_entity *entity,
    caosdb_entity_message *out, int index), caosdb_entity_message *out, int index),
    { {
    if (out->_deletable) {
    return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR;
    }
    auto *wrapped_entity = auto *wrapped_entity =
    static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
    out->wrapped_message = wrapped_entity->GetErrors().mutable_at(index); out->wrapped_message = wrapped_entity->GetErrors().mutable_at(index);
    ...@@ -599,6 +640,9 @@ ERROR_RETURN_CODE( ...@@ -599,6 +640,9 @@ ERROR_RETURN_CODE(
    int caosdb_entity_entity_get_warning(caosdb_entity_entity *entity, int caosdb_entity_entity_get_warning(caosdb_entity_entity *entity,
    caosdb_entity_message *out, int index), caosdb_entity_message *out, int index),
    { {
    if (out->_deletable) {
    return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR;
    }
    auto *wrapped_entity = auto *wrapped_entity =
    static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
    out->wrapped_message = wrapped_entity->GetWarnings().mutable_at(index); out->wrapped_message = wrapped_entity->GetWarnings().mutable_at(index);
    ...@@ -622,6 +666,9 @@ ERROR_RETURN_CODE( ...@@ -622,6 +666,9 @@ ERROR_RETURN_CODE(
    int caosdb_entity_entity_get_info(caosdb_entity_entity *entity, int caosdb_entity_entity_get_info(caosdb_entity_entity *entity,
    caosdb_entity_message *out, int index), caosdb_entity_message *out, int index),
    { {
    if (out->_deletable) {
    return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR;
    }
    auto *wrapped_entity = auto *wrapped_entity =
    static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
    out->wrapped_message = wrapped_entity->GetInfos().mutable_at(index); out->wrapped_message = wrapped_entity->GetInfos().mutable_at(index);
    ...@@ -645,6 +692,9 @@ ERROR_RETURN_CODE( ...@@ -645,6 +692,9 @@ ERROR_RETURN_CODE(
    int caosdb_entity_entity_get_property(caosdb_entity_entity *entity, int caosdb_entity_entity_get_property(caosdb_entity_entity *entity,
    caosdb_entity_property *out, int index), caosdb_entity_property *out, int index),
    { {
    if (out->_deletable) {
    return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR;
    }
    auto *wrapped_entity = auto *wrapped_entity =
    static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
    out->wrapped_property = wrapped_entity->GetProperties().mutable_at(index); out->wrapped_property = wrapped_entity->GetProperties().mutable_at(index);
    ...@@ -668,6 +718,9 @@ ERROR_RETURN_CODE( ...@@ -668,6 +718,9 @@ ERROR_RETURN_CODE(
    int caosdb_entity_entity_get_parent(caosdb_entity_entity *entity, int caosdb_entity_entity_get_parent(caosdb_entity_entity *entity,
    caosdb_entity_parent *out, int index), caosdb_entity_parent *out, int index),
    { {
    if (out->_deletable) {
    return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR;
    }
    auto *wrapped_entity = auto *wrapped_entity =
    static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
    out->wrapped_parent = wrapped_entity->GetParents().mutable_at(index); out->wrapped_parent = wrapped_entity->GetParents().mutable_at(index);
    ......
    ...@@ -146,6 +146,16 @@ TEST_F(test_ccaosdb, test_entity) { ...@@ -146,6 +146,16 @@ TEST_F(test_ccaosdb, test_entity) {
    int return_code(caosdb_entity_create_entity(&entity)); int return_code(caosdb_entity_create_entity(&entity));
    EXPECT_EQ(return_code, 0); 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 // In-depth check for one pair of setter and getter, just compare
    // the strings for the rest // the strings for the rest
    return_code = caosdb_entity_entity_set_name(&entity, "length"); return_code = caosdb_entity_entity_set_name(&entity, "length");
    ......
    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