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

DRAFT: Begin setters and getters for entities

parent 63da43ad
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 #11671 failed
This commit is part of merge request !8. Comments created here will be created in the context of that merge request.
......@@ -50,6 +50,34 @@ extern "C" {
} \
}
/**
* Macro for entity getters
*/
#define CAOSDB_ENTITY_GET(element, body_part) \
ERROR_RETURN_CODE( \
GENERIC_ERROR, \
int caosdb_entity_entity_get_##element(caosdb_entity_entity *entity, \
char *out), \
{ \
auto *wrapped_entity = \
static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); \
body_part return 0; \
})
/**
* Macro for entity setters
*/
#define CAOSDB_ENTITY_SET(element, value, body_part) \
ERROR_RETURN_CODE( \
GENERIC_ERROR, \
int caosdb_entity_entity_set_##element(caosdb_entity_entity *entity, \
const char *value), \
{ \
auto *wrapped_entity = \
static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); \
body_part return 0; \
})
int caosdb_constants_LIBCAOSDB_VERSION_MAJOR() {
return caosdb::LIBCAOSDB_VERSION_MAJOR;
}
......@@ -334,7 +362,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
static_cast<caosdb::transaction::Transaction *>(
transaction->wrapped_transaction);
wrapped_transaction->ExecuteAsynchronously();
auto status = wrapped_transaction->WaitForIt();
auto status = wrapped_transaction->WaitForIt();
return status.GetCode();
})
......@@ -394,8 +422,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
ERROR_RETURN_CODE(GENERIC_ERROR,
int caosdb_entity_create_entity(caosdb_entity_entity *out), {
auto entity = caosdb::entity::Entity();
out->wrapped_entity = (void *)(&entity);
out->wrapped_entity = new caosdb::entity::Entity();
return 0;
})
......@@ -405,4 +432,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
out->wrapped_entity);
return 0;
})
CAOSDB_ENTITY_GET(id, strcpy(out, wrapped_entity->GetId().c_str());)
CAOSDB_ENTITY_GET(name, strcpy(out, wrapped_entity->GetName().c_str());)
CAOSDB_ENTITY_SET(name, name, wrapped_entity->SetName(std::string(name));)
}
......@@ -24,10 +24,12 @@
#include "caosdb/status_code.h" // for StatusCode
#include "caosdb_test_utility.h" // for EXPECT_THROW_MESSAGE, TEST_DATA_DIR
#include "ccaosdb.h" // for caosdb_utility_get_env_var
#include <cstring> // for strcmp
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestFactoryImpl
#include <gtest/gtest_pred_impl.h> // for Test, TestInfo, EXPECT_EQ, TEST
#include <string> // for allocator
#include <iostream>
#include <string> // for allocator
class test_ccaosdb : public ::testing::Test {
protected:
......@@ -99,10 +101,12 @@ TEST_F(test_ccaosdb, test_execute_transaction) {
}
TEST_F(test_ccaosdb, test_multi_retrieve) {
std::cout << "Entering test_multi_retrieve ..." << std::endl;
caosdb_connection_connection connection;
caosdb_connection_connection_manager_get_connection(&connection,
"local-caosdb-admin");
std::cout << "Creating transaction" << std::endl;
caosdb_transaction_transaction multi_transaction;
caosdb_connection_connection_create_transaction(&connection,
&multi_transaction);
......@@ -110,10 +114,12 @@ TEST_F(test_ccaosdb, test_multi_retrieve) {
// We explicitely want to define a C-style array here, so we disable
// linting
const char *ids[] = {"id1", "id2", "id3"}; // NOLINT
std::cout << "Adding mutli retrieval ..." << std::endl;
int return_code(
caosdb_transaction_transaction_retrieve_by_ids(&multi_transaction, ids));
EXPECT_EQ(return_code, caosdb::StatusCode::GO_ON);
std::cout << "Deleting transaction ..." << std::endl;
return_code = caosdb_transaction_delete_transaction(&multi_transaction);
EXPECT_EQ(return_code, 0);
}
......@@ -140,6 +146,13 @@ TEST_F(test_ccaosdb, test_entity) {
int return_code(caosdb_entity_create_entity(&entity));
EXPECT_EQ(return_code, 0);
return_code = caosdb_entity_entity_set_name(&entity, "some_name");
EXPECT_EQ(return_code, 0);
char out[255] = {"a"}; // NOLINT
return_code = caosdb_entity_entity_get_name(&entity, out);
EXPECT_EQ(return_code, 0);
EXPECT_EQ(strcmp(out, "some_name"), 0);
return_code = caosdb_entity_delete_entity(&entity);
EXPECT_EQ(return_code, 0);
}
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