Skip to content
Snippets Groups Projects

ENH: Add datatypes and value classes to Extern C interface

Merged Florian Spreckelsen requested to merge f-consolidate-c into dev
All threads resolved!
Files
2
+ 111
78
@@ -97,22 +97,18 @@ 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);
// 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, 3));
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);
}
@@ -151,33 +147,41 @@ TEST_F(test_ccaosdb, test_entity) {
// the strings for the rest
return_code = caosdb_entity_entity_set_name(&entity, "length");
EXPECT_EQ(return_code, 0);
char out[255] = {"a"}; // NOLINT
return_code = caosdb_entity_entity_get_name(&entity, out);
char *out = nullptr; // NOLINT
return_code = caosdb_entity_entity_get_name(&entity, &out);
EXPECT_EQ(return_code, 0);
EXPECT_EQ(strcmp(out, "length"), 0);
// TODO(fspreck)
// caosdb_entity_entity_set_role(&entity, "Property");
// caosdb_entity_entity_get_role(&entity, out);
// EXPECT_EQ(strcmp(out, "Property"), 0);
// invalid role
return_code = caosdb_entity_entity_set_role(&entity, "Role does not exist");
EXPECT_EQ(return_code, caosdb::StatusCode::ENUM_MAPPING_ERROR);
caosdb_entity_entity_set_role(&entity, "PROPERTY");
caosdb_entity_entity_get_role(&entity, &out);
EXPECT_EQ(strcmp(out, "PROPERTY"), 0);
caosdb_entity_entity_set_description(&entity, "The length of an object");
caosdb_entity_entity_get_description(&entity, out);
caosdb_entity_entity_get_description(&entity, &out);
EXPECT_EQ(strcmp(out, "The length of an object"), 0);
// TODO(fspreck)
// caosdb_entity_entity_set_datatype(&entity, "DOUBLE");
// caosdb_entity_entity_get_datatype(&entity, out);
// EXPECT_EQ(strcmp(out, "DOUBLE"), 0);
caosdb_entity_entity_set_datatype(&entity, "DOUBLE", false, false);
bool is_list[] = {false}; // NOLINT
bool is_ref[] = {false}; // NOLINT
caosdb_entity_entity_get_datatype(&entity, &out, is_ref, is_list);
EXPECT_EQ(strcmp(out, "DOUBLE"), 0);
EXPECT_FALSE(*is_list);
EXPECT_FALSE(*is_ref);
caosdb_entity_entity_set_unit(&entity, "m");
caosdb_entity_entity_get_unit(&entity, out);
caosdb_entity_entity_get_unit(&entity, &out);
EXPECT_EQ(strcmp(out, "m"), 0);
// TODO(fspreck)
// caosdb_entity_entity_set_value(&entity, "5.0");
// caosdb_entity_entity_get_value(&entity, out);
// EXPECT_EQ(strcmp(out, "5.0"), 0);
return_code = caosdb_entity_entity_set_double_value(&entity, 5.0);
EXPECT_EQ(return_code, 0);
double value[] = {0.0}; // NOLINT
return_code = caosdb_entity_entity_get_double_value(&entity, value);
EXPECT_EQ(return_code, 0);
EXPECT_EQ(*value, 5.0);
return_code = caosdb_entity_delete_entity(&entity);
EXPECT_EQ(return_code, 0);
@@ -192,11 +196,11 @@ TEST_F(test_ccaosdb, test_parent) {
caosdb_entity_parent_set_id(&parent, "some_id");
caosdb_entity_parent_set_name(&parent, "some_name");
char out[255] = {"a"}; // NOLINT
caosdb_entity_parent_get_id(&parent, out);
char *out = nullptr; // NOLINT
caosdb_entity_parent_get_id(&parent, &out);
EXPECT_EQ(strcmp(out, "some_id"), 0);
caosdb_entity_parent_get_name(&parent, out);
caosdb_entity_parent_get_name(&parent, &out);
EXPECT_EQ(strcmp(out, "some_name"), 0);
return_code = caosdb_entity_delete_parent(&parent);
@@ -211,42 +215,77 @@ TEST_F(test_ccaosdb, test_property) {
caosdb_entity_property_set_id(&property, "some_id");
caosdb_entity_property_set_name(&property, "some_name");
// TODO(fspreck)
// caosdb_entity_property_set_datatype(&property, "some_datatype");
// TODO(fspreck)
// caosdb_entity_property_set_importance(&property, "some_importance");
caosdb_entity_property_set_datatype(&property, "TEXT", false, false);
caosdb_entity_property_set_importance(&property, "FIX");
caosdb_entity_property_set_unit(&property, "some_unit");
// TODO(fspreck)
// caosdb_entity_property_set_value(&property, "some_value");
caosdb_entity_property_set_string_value(&property, "some_value");
char out[255] = {"a"}; // NOLINT
caosdb_entity_property_get_id(&property, out);
char *out = nullptr; // NOLINT
caosdb_entity_property_get_id(&property, &out);
EXPECT_EQ(strcmp(out, "some_id"), 0);
caosdb_entity_property_get_name(&property, out);
caosdb_entity_property_get_name(&property, &out);
EXPECT_EQ(strcmp(out, "some_name"), 0);
// TODO(fspreck)
// caosdb_entity_property_get_datatype(&property, out);
// EXPECT_EQ(strcmp(out, "some_datatype"), 0);
bool is_ref[] = {false}; // NOLINT
bool is_list[] = {false}; // NOLINT
caosdb_entity_property_get_datatype(&property, &out, is_ref, is_list);
EXPECT_EQ(strcmp(out, "TEXT"), 0);
EXPECT_FALSE(*is_ref);
EXPECT_FALSE(*is_list);
// TODO(fspreck)
// caosdb_entity_property_get_importance(&property, out);
// EXPECT_EQ(strcmp(out, "some_importance"), 0);
caosdb_entity_property_get_importance(&property, &out);
EXPECT_EQ(strcmp(out, "FIX"), 0);
caosdb_entity_property_get_unit(&property, out);
caosdb_entity_property_get_unit(&property, &out);
EXPECT_EQ(strcmp(out, "some_unit"), 0);
// TODO(fspreck)
// caosdb_entity_property_get_value(&property, out);
// EXPECT_EQ(strcmp(out, "some_value"), 0);
caosdb_entity_property_get_string_value(&property, &out);
EXPECT_EQ(strcmp(out, "some_value"), 0);
return_code = caosdb_entity_delete_property(&property);
EXPECT_EQ(return_code, 0);
}
TEST_F(test_ccaosdb, test_list_property) {
caosdb_entity_property property;
int return_code(caosdb_entity_create_property(&property));
EXPECT_EQ(return_code, 0);
return_code = caosdb_entity_property_set_datatype(&property, "TEXT", false, true);
EXPECT_EQ(return_code, 0);
const char *value_list[] = {"val0", "val1", "val2"}; // NOLINT
return_code = caosdb_entity_property_set_string_list_value(&property, value_list, 3);
EXPECT_EQ(return_code, 0);
char *out = nullptr; // NOLINT
bool is_ref[] = {false}; // NOLINT
bool is_list[] = {false}; // NOLINT
return_code = caosdb_entity_property_get_datatype(&property, &out, is_ref, is_list);
EXPECT_EQ(return_code, 0);
EXPECT_EQ(strcmp(out, "TEXT"), 0);
EXPECT_FALSE(*is_ref);
EXPECT_TRUE(*is_list);
int length[] = {0}; // NOLINT
return_code = caosdb_entity_property_get_value_list_length(&property, length);
EXPECT_EQ(return_code, 0);
EXPECT_EQ(*length, 3);
for (int i = 0; i < *length; i++) {
return_code = caosdb_entity_property_get_string_list_value_at(&property, &out, i);
EXPECT_EQ(return_code, 0);
EXPECT_EQ(strcmp(value_list[i], out), 0); // NOLINT
}
return_code = caosdb_entity_delete_property(&property);
EXPECT_EQ(return_code, 0);
}
TEST_F(test_ccaosdb, test_entity_with_parent_and_property) {
std::cout << "Creating objects ... " << std::endl;
caosdb_entity_parent input_parent;
int return_code(caosdb_entity_create_parent(&input_parent));
EXPECT_EQ(return_code, 0);
@@ -260,23 +299,20 @@ TEST_F(test_ccaosdb, test_entity_with_parent_and_property) {
caosdb_entity_property_set_id(&input_property, "property_id");
caosdb_entity_property_set_name(&input_property, "property_name");
// TODO(fspreck)
// caosdb_entity_property_set_datatype(&input_property, "property_datatype");
// TODO(fspreck)
// caosdb_entity_property_set_value(&input_property, "property_value");
caosdb_entity_property_set_datatype(&input_property, "TEXT", false, false);
caosdb_entity_property_set_string_value(&input_property, "property_value");
caosdb_entity_entity entity;
return_code = caosdb_entity_create_entity(&entity);
EXPECT_EQ(return_code, 0);
std::cout << "Appending parent and property ..." << std::endl;
return_code = caosdb_entity_entity_append_parent(&entity, &input_parent);
EXPECT_EQ(return_code, 0);
return_code = caosdb_entity_entity_append_property(&entity, &input_property);
EXPECT_EQ(return_code, 0);
std::cout << "Counting parents and properties ..." << std::endl;
int count[] = {0}; // NOLINT
return_code = caosdb_entity_entity_get_parents_size(&entity, count);
EXPECT_EQ(return_code, 0);
@@ -286,54 +322,51 @@ TEST_F(test_ccaosdb, test_entity_with_parent_and_property) {
EXPECT_EQ(return_code, 0);
EXPECT_EQ(*count, 1);
char in[255] = {"a"}; // NOLINT
char out[255] = {"b"}; // NOLINT
char *in = nullptr; // NOLINT
char *out = nullptr; // NOLINT
std::cout << "Comparing ..." << std::endl;
// 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);
caosdb_entity_property output_property;
return_code = caosdb_entity_entity_get_property(&entity, &output_property, 0);
std::cout << "Got output property." << std::endl;
EXPECT_EQ(return_code, 0);
caosdb_entity_property_get_id(&input_property, in);
std::cout << "Got input id." << std::endl;
caosdb_entity_property_get_id(&output_property, out);
std::cout << "Got output id." << std::endl;
caosdb_entity_property_get_id(&input_property, &in);
caosdb_entity_property_get_id(&output_property, &out);
EXPECT_EQ(strcmp(in, out), 0);
caosdb_entity_property_get_name(&input_property, in);
caosdb_entity_property_get_name(&output_property, out);
caosdb_entity_property_get_name(&input_property, &in);
caosdb_entity_property_get_name(&output_property, &out);
EXPECT_EQ(strcmp(in, out), 0);
// TODO(fspreck)
// caosdb_entity_property_get_datatype(&input_property, in);
// caosdb_entity_property_get_datatype(&output_property, out);
// EXPECT_EQ(strcmp(in, out), 0);
bool is_list[] = {false}; // NOLINT
bool is_ref[] = {false}; // NOLINT
caosdb_entity_property_get_datatype(&input_property, &in, is_ref, is_list);
EXPECT_FALSE(*is_list);
EXPECT_FALSE(*is_ref);
caosdb_entity_property_get_datatype(&output_property, &out, is_ref, is_list);
EXPECT_FALSE(*is_list);
EXPECT_FALSE(*is_ref);
EXPECT_EQ(strcmp(in, out), 0);
// TODO(fspreck)
// caosdb_entity_property_get_value(&input_property, in);
// caosdb_entity_property_get_value(&output_property, out);
// EXPECT_EQ(strcmp(in, out), 0);
caosdb_entity_property_get_string_value(&input_property, &in);
caosdb_entity_property_get_string_value(&output_property, &out);
EXPECT_EQ(strcmp(in, out), 0);
std::cout << "Comparing parent..." << std::endl;
caosdb_entity_parent output_parent;
return_code = caosdb_entity_entity_get_parent(&entity, &output_parent, 0);
std::cout << "Got output parent." << std::endl;
EXPECT_EQ(return_code, 0);
caosdb_entity_parent_get_id(&input_parent, in);
caosdb_entity_parent_get_id(&output_parent, out);
caosdb_entity_parent_get_id(&input_parent, &in);
caosdb_entity_parent_get_id(&output_parent, &out);
EXPECT_EQ(strcmp(in, out), 0);
caosdb_entity_parent_get_name(&input_parent, in);
caosdb_entity_parent_get_name(&output_parent, out);
caosdb_entity_parent_get_name(&input_parent, &in);
caosdb_entity_parent_get_name(&output_parent, &out);
EXPECT_EQ(strcmp(in, out), 0);
// Delete everything
std::cout << "Deleting ..." << std::endl;
return_code = caosdb_entity_delete_parent(&input_parent);
EXPECT_EQ(return_code, 0);
return_code = caosdb_entity_delete_property(&input_property);
@@ -393,13 +426,13 @@ TEST_F(test_ccaosdb, test_remove_property) {
return_code = caosdb_entity_entity_get_property(&entity, &out_prop, 0);
EXPECT_EQ(return_code, 0);
char in[255] = {"a"}; // NOLINT
char out[255] = {"b"}; // NOLINT
char *in = nullptr; // NOLINT
char *out = nullptr; // NOLINT
// Deleted the first property, so the second one should remain.
return_code = caosdb_entity_property_get_name(&in_prop_2, in);
return_code = caosdb_entity_property_get_name(&in_prop_2, &in);
EXPECT_EQ(return_code, 0);
return_code = caosdb_entity_property_get_name(&out_prop, out);
return_code = caosdb_entity_property_get_name(&out_prop, &out);
EXPECT_EQ(return_code, 0);
EXPECT_EQ(strcmp(in, out), 0);
Loading