Skip to content
Snippets Groups Projects
Commit 03ae8eb0 authored by florian's avatar florian
Browse files

TST: Add unit tests for insert, update, and delete

parent f6c01c1f
No related branches found
No related tags found
1 merge request!15ENH: Allow insert/update/delete and files in Extern C
Pipeline #12161 failed
......@@ -471,7 +471,7 @@ ERROR_RETURN_CODE(
auto *wrapped_entity =
static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
return wrapped_transaction->InsertEntity(*wrapped_entity);
return wrapped_transaction->InsertEntity(wrapped_entity);
})
ERROR_RETURN_CODE(
......@@ -484,7 +484,7 @@ ERROR_RETURN_CODE(
auto *wrapped_entity =
static_cast<caosdb::entity::Entity *>(entity->wrapped_entity);
return wrapped_transaction->UpdateEntity(*wrapped_entity);
return wrapped_transaction->UpdateEntity(wrapped_entity);
})
ERROR_RETURN_CODE(GENERIC_ERROR,
......@@ -496,7 +496,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
static_cast<caosdb::transaction::Transaction *>(
transaction->wrapped_transaction);
return wrapped_transaction->DeleteById(std::string(id))
return wrapped_transaction->DeleteById(std::string(id));
})
ERROR_RETURN_CODE(GENERIC_ERROR,
......
......@@ -415,3 +415,46 @@ TEST_F(test_ccaosdb, test_remove_property) {
return_code = caosdb_entity_delete_entity(&entity);
EXPECT_EQ(return_code, 0);
}
TEST_F(test_ccaosdb, test_insert_update_delete) {
// Only test adding to a transaction, excution and results are
// tested in integration tests.
caosdb_connection_connection connection;
caosdb_connection_connection_manager_get_default_connection(&connection);
caosdb_transaction_transaction insert_transaction;
caosdb_connection_connection_create_transaction(&connection,
&insert_transaction);
caosdb_entity_entity entity;
caosdb_entity_create_entity(&entity);
caosdb_entity_entity_set_name(&entity, "some_name");
int return_code(
caosdb_transaction_transaction_insert_entity(&insert_transaction, &entity));
// For now, nothing further can be done here, so it should be READY
EXPECT_EQ(return_code, caosdb::StatusCode::READY);
caosdb_transaction_transaction update_transaction;
caosdb_connection_connection_create_transaction(&connection,
&update_transaction);
return_code =
caosdb_transaction_transaction_update_entity(&update_transaction, &entity);
// No ID, so this should be an error
EXPECT_EQ(return_code, caosdb::StatusCode::ORIGINAL_ENTITY_MISSING_ID);
caosdb_transaction_transaction delete_transaction;
caosdb_connection_connection_create_transaction(&connection,
&delete_transaction);
return_code =
caosdb_transaction_transaction_delete_by_id(&delete_transaction, "some_id");
// Could add further deletions
EXPECT_EQ(return_code, caosdb::StatusCode::GO_ON);
caosdb_entity_delete_entity(&entity);
caosdb_transaction_delete_transaction(&insert_transaction);
caosdb_transaction_delete_transaction(&update_transaction);
caosdb_transaction_delete_transaction(&delete_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