Skip to content
Snippets Groups Projects
Commit 23e737ad authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

Merge branch 'f-consolidate-c' into 'dev'

ENH: Add datatypes and value classes to Extern C interface

See merge request !13
parents 4afa0be5 315952bf
No related branches found
No related tags found
1 merge request!13ENH: Add datatypes and value classes to Extern C interface
Pipeline #12414 passed
Pipeline: caosdb-cppinttest

#12419

    ...@@ -9,7 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -9,7 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
    ### Added ### Added
    - New functions getEnumNameFromValue() and getEnumValueFromName(). * New functions getEnumNameFromValue() and getEnumValueFromName().
    * Extern C now supports datatypes, roles, and importances as enums,
    and typed property values
    ### Changed ### Changed
    ......
    ...@@ -61,6 +61,7 @@ enum StatusCode { ...@@ -61,6 +61,7 @@ enum StatusCode {
    FILE_DOES_NOT_EXIST_LOCALLY = 34, FILE_DOES_NOT_EXIST_LOCALLY = 34,
    FILE_UPLOAD_ERROR = 35, FILE_UPLOAD_ERROR = 35,
    FILE_DOWNLOAD_ERROR = 36, FILE_DOWNLOAD_ERROR = 36,
    ENUM_MAPPING_ERROR = 37,
    OTHER_CLIENT_ERROR = 9999, OTHER_CLIENT_ERROR = 9999,
    }; };
    ......
    ...@@ -321,14 +321,32 @@ typedef struct { ...@@ -321,14 +321,32 @@ typedef struct {
    } caosdb_entity_message; } caosdb_entity_message;
    // GETTERS FOR EVERYTHING // GETTERS FOR EVERYTHING
    int caosdb_entity_entity_get_id(caosdb_entity_entity *entity, char *out); int caosdb_entity_entity_get_id(caosdb_entity_entity *entity, char **out);
    int caosdb_entity_entity_get_role(caosdb_entity_entity *entity, char *out); int caosdb_entity_entity_get_role(caosdb_entity_entity *entity, char **out);
    int caosdb_entity_entity_get_name(caosdb_entity_entity *entity, char *out); int caosdb_entity_entity_get_name(caosdb_entity_entity *entity, char **out);
    int caosdb_entity_entity_get_description(caosdb_entity_entity *entity, char *out); int caosdb_entity_entity_get_description(caosdb_entity_entity *entity, char **out);
    int caosdb_entity_entity_get_datatype(caosdb_entity_entity *entity, char *out); /**
    int caosdb_entity_entity_get_unit(caosdb_entity_entity *entity, char *out); * Get the name of the entity's datatype, whether it is a reference, and whether it is a list.
    int caosdb_entity_entity_get_value(caosdb_entity_entity *entity, char *out); */
    int caosdb_entity_entity_get_version_id(caosdb_entity_entity *entity, char *out); int caosdb_entity_entity_get_datatype(caosdb_entity_entity *entity, char **name, bool *is_ref,
    bool *is_list);
    int caosdb_entity_entity_get_unit(caosdb_entity_entity *entity, char **out);
    int caosdb_entity_entity_get_int_value(caosdb_entity_entity *entity, long *out);
    int caosdb_entity_entity_get_double_value(caosdb_entity_entity *entity, double *out);
    int caosdb_entity_entity_get_boolean_value(caosdb_entity_entity *entity, bool *out);
    int caosdb_entity_entity_get_string_value(caosdb_entity_entity *entity, char **out);
    int caosdb_entity_entity_get_int_list_value_at(caosdb_entity_entity *entity, long *out,
    const int index);
    int caosdb_entity_entity_get_double_list_value_at(caosdb_entity_entity *entity, double *out,
    const int index);
    int caosdb_entity_entity_get_boolean_list_value_at(caosdb_entity_entity *entity, bool *out,
    const int index);
    int caosdb_entity_entity_get_string_list_value_at(caosdb_entity_entity *entity, char **out,
    const int index);
    int caosdb_entity_entity_get_value_list_length(caosdb_entity_entity *entity, int *out);
    int caosdb_entity_entity_get_version_id(caosdb_entity_entity *entity, char **out);
    int caosdb_entity_entity_get_errors_size(caosdb_entity_entity *entity, int *out); int caosdb_entity_entity_get_errors_size(caosdb_entity_entity *entity, int *out);
    int caosdb_entity_entity_get_error(caosdb_entity_entity *entity, caosdb_entity_message *out, int caosdb_entity_entity_get_error(caosdb_entity_entity *entity, caosdb_entity_message *out,
    int index); int index);
    ...@@ -345,20 +363,37 @@ int caosdb_entity_entity_get_parents_size(caosdb_entity_entity *entity, int *out ...@@ -345,20 +363,37 @@ int caosdb_entity_entity_get_parents_size(caosdb_entity_entity *entity, int *out
    int caosdb_entity_entity_get_parent(caosdb_entity_entity *entity, caosdb_entity_parent *out, int caosdb_entity_entity_get_parent(caosdb_entity_entity *entity, caosdb_entity_parent *out,
    int index); int index);
    int caosdb_entity_property_get_id(caosdb_entity_property *property, char *out); int caosdb_entity_property_get_id(caosdb_entity_property *property, char **out);
    int caosdb_entity_property_get_name(caosdb_entity_property *property, char *out); int caosdb_entity_property_get_name(caosdb_entity_property *property, char **out);
    int caosdb_entity_property_get_description(caosdb_entity_property *property, char *out); int caosdb_entity_property_get_description(caosdb_entity_property *property, char **out);
    int caosdb_entity_property_get_importance(caosdb_entity_property *property, char *out); int caosdb_entity_property_get_importance(caosdb_entity_property *property, char **out);
    int caosdb_entity_property_get_datatype(caosdb_entity_property *property, char *out); /**
    int caosdb_entity_property_get_unit(caosdb_entity_property *property, char *out); * Get the name of the property's datatype, whether it is a reference, and whether it is a list.
    int caosdb_entity_property_get_value(caosdb_entity_property *property, char *out); */
    int caosdb_entity_property_get_datatype(caosdb_entity_property *property, char **name, bool *is_ref,
    int caosdb_entity_parent_get_id(caosdb_entity_parent *parent, char *out); bool *is_list);
    int caosdb_entity_parent_get_name(caosdb_entity_parent *parent, char *out); int caosdb_entity_property_get_unit(caosdb_entity_property *property, char **out);
    int caosdb_entity_parent_get_description(caosdb_entity_parent *parent, char *out);
    int caosdb_entity_property_get_int_value(caosdb_entity_property *property, long *out);
    int caosdb_entity_property_get_double_value(caosdb_entity_property *property, double *out);
    int caosdb_entity_property_get_boolean_value(caosdb_entity_property *property, bool *out);
    int caosdb_entity_property_get_string_value(caosdb_entity_property *property, char **out);
    int caosdb_entity_property_get_int_list_value_at(caosdb_entity_property *property, long *out,
    const int index);
    int caosdb_entity_property_get_double_list_value_at(caosdb_entity_property *property, double *out,
    const int index);
    int caosdb_entity_property_get_boolean_list_value_at(caosdb_entity_property *property, bool *out,
    const int index);
    int caosdb_entity_property_get_string_list_value_at(caosdb_entity_property *property, char **out,
    const int index);
    int caosdb_entity_property_get_value_list_length(caosdb_entity_property *property, int *out);
    int caosdb_entity_parent_get_id(caosdb_entity_parent *parent, char **out);
    int caosdb_entity_parent_get_name(caosdb_entity_parent *parent, char **out);
    int caosdb_entity_parent_get_description(caosdb_entity_parent *parent, char **out);
    int caosdb_entity_message_get_code(caosdb_entity_message *message, int *out); int caosdb_entity_message_get_code(caosdb_entity_message *message, int *out);
    int caosdb_entity_message_get_description(caosdb_entity_message *message, char *out); int caosdb_entity_message_get_description(caosdb_entity_message *message, char **out);
    // CONSTRUCTORS AND DESTRUCTORS // CONSTRUCTORS AND DESTRUCTORS
    int caosdb_entity_create_entity(caosdb_entity_entity *out); int caosdb_entity_create_entity(caosdb_entity_entity *out);
    ...@@ -372,9 +407,26 @@ int caosdb_entity_delete_parent(caosdb_entity_parent *out); ...@@ -372,9 +407,26 @@ int caosdb_entity_delete_parent(caosdb_entity_parent *out);
    int caosdb_entity_entity_set_role(caosdb_entity_entity *entity, const char *role); int caosdb_entity_entity_set_role(caosdb_entity_entity *entity, const char *role);
    int caosdb_entity_entity_set_name(caosdb_entity_entity *entity, const char *name); int caosdb_entity_entity_set_name(caosdb_entity_entity *entity, const char *name);
    int caosdb_entity_entity_set_description(caosdb_entity_entity *entity, const char *description); int caosdb_entity_entity_set_description(caosdb_entity_entity *entity, const char *description);
    int caosdb_entity_entity_set_datatype(caosdb_entity_entity *entity, const char *datatype); /**
    * Set the entity's datatype by name, and whether it is a reference or a list.
    */
    int caosdb_entity_entity_set_datatype(caosdb_entity_entity *entity, const char *datatype,
    const bool is_ref, const bool is_list);
    int caosdb_entity_entity_set_unit(caosdb_entity_entity *entity, const char *unit); int caosdb_entity_entity_set_unit(caosdb_entity_entity *entity, const char *unit);
    int caosdb_entity_entity_set_value(caosdb_entity_entity *entity, const char *value); // TODO(fspreck) replace by more specific setters
    int caosdb_entity_entity_set_int_value(caosdb_entity_entity *entity, const long value);
    int caosdb_entity_entity_set_double_value(caosdb_entity_entity *entity, const double value);
    int caosdb_entity_entity_set_boolean_value(caosdb_entity_entity *entity, const bool value);
    int caosdb_entity_entity_set_string_value(caosdb_entity_entity *entity, const char *value);
    int caosdb_entity_entity_set_int_list_value(caosdb_entity_entity *entity, const long *value,
    const int length);
    int caosdb_entity_entity_set_double_list_value(caosdb_entity_entity *entity, const double *value,
    const int length);
    int caosdb_entity_entity_set_boolean_list_value(caosdb_entity_entity *entity, const bool *value,
    const int length);
    int caosdb_entity_entity_set_string_list_value(caosdb_entity_entity *entity, const char **value,
    const int length);
    int caosdb_entity_entity_append_parent(caosdb_entity_entity *entity, caosdb_entity_parent *parent); int caosdb_entity_entity_append_parent(caosdb_entity_entity *entity, caosdb_entity_parent *parent);
    int caosdb_entity_entity_remove_parent(caosdb_entity_entity *entity, int index); int caosdb_entity_entity_remove_parent(caosdb_entity_entity *entity, int index);
    int caosdb_entity_entity_append_property(caosdb_entity_entity *entity, int caosdb_entity_entity_append_property(caosdb_entity_entity *entity,
    ...@@ -383,10 +435,26 @@ int caosdb_entity_entity_remove_property(caosdb_entity_entity *entity, int index ...@@ -383,10 +435,26 @@ int caosdb_entity_entity_remove_property(caosdb_entity_entity *entity, int index
    int caosdb_entity_property_set_id(caosdb_entity_property *property, const char *id); int caosdb_entity_property_set_id(caosdb_entity_property *property, const char *id);
    int caosdb_entity_property_set_name(caosdb_entity_property *property, const char *name); int caosdb_entity_property_set_name(caosdb_entity_property *property, const char *name);
    int caosdb_entity_property_set_datatype(caosdb_entity_property *property, const char *datatype); /**
    * Set the property's datatype by name, and whether it is a reference or a list.
    */
    int caosdb_entity_property_set_datatype(caosdb_entity_property *property, const char *datatype,
    const bool is_ref, const bool is_list);
    int caosdb_entity_property_set_importance(caosdb_entity_property *property, const char *importance); int caosdb_entity_property_set_importance(caosdb_entity_property *property, const char *importance);
    int caosdb_entity_property_set_unit(caosdb_entity_property *property, const char *unit); int caosdb_entity_property_set_unit(caosdb_entity_property *property, const char *unit);
    int caosdb_entity_property_set_value(caosdb_entity_property *property, const char *value);
    int caosdb_entity_property_set_int_value(caosdb_entity_property *property, const long value);
    int caosdb_entity_property_set_double_value(caosdb_entity_property *property, const double value);
    int caosdb_entity_property_set_boolean_value(caosdb_entity_property *property, const bool value);
    int caosdb_entity_property_set_string_value(caosdb_entity_property *property, const char *value);
    int caosdb_entity_property_set_int_list_value(caosdb_entity_property *property, const long *value,
    const int length);
    int caosdb_entity_property_set_double_list_value(caosdb_entity_property *property,
    const double *value, const int length);
    int caosdb_entity_property_set_boolean_list_value(caosdb_entity_property *property,
    const bool *value, const int length);
    int caosdb_entity_property_set_string_list_value(caosdb_entity_property *property,
    const char **value, const int length);
    int caosdb_entity_parent_set_id(caosdb_entity_parent *parent, const char *id); int caosdb_entity_parent_set_id(caosdb_entity_parent *parent, const char *id);
    int caosdb_entity_parent_set_name(caosdb_entity_parent *parent, const char *name); int caosdb_entity_parent_set_name(caosdb_entity_parent *parent, const char *name);
    ......
    ...@@ -96,6 +96,8 @@ auto get_status_description(int code) -> const std::string & { ...@@ -96,6 +96,8 @@ auto get_status_description(int code) -> const std::string & {
    {StatusCode::EXTERN_C_ASSIGNMENT_ERROR, {StatusCode::EXTERN_C_ASSIGNMENT_ERROR,
    "You tried to assign a new object to the wrapped void pointer. You have " "You tried to assign a new object to the wrapped void pointer. You have "
    "to delete the old pointee first."}, "to delete the old pointee first."},
    {StatusCode::ENUM_MAPPING_ERROR,
    "The role, importance, or datatype you specified does not exist."},
    {StatusCode::OTHER_CLIENT_ERROR, {StatusCode::OTHER_CLIENT_ERROR,
    "This is code is reserved to errors raised by other clients wrapping the " "This is code is reserved to errors raised by other clients wrapping the "
    "C++ client (or its Extern C interface). This should never occur when " "C++ client (or its Extern C interface). This should never occur when "
    ......
    This diff is collapsed.
    ...@@ -97,22 +97,18 @@ TEST_F(test_ccaosdb, test_execute_transaction) { ...@@ -97,22 +97,18 @@ TEST_F(test_ccaosdb, test_execute_transaction) {
    } }
    TEST_F(test_ccaosdb, test_multi_retrieve) { TEST_F(test_ccaosdb, test_multi_retrieve) {
    std::cout << "Entering test_multi_retrieve ..." << std::endl;
    caosdb_connection_connection connection; caosdb_connection_connection connection;
    caosdb_connection_connection_manager_get_connection(&connection, "local-caosdb-admin"); caosdb_connection_connection_manager_get_connection(&connection, "local-caosdb-admin");
    std::cout << "Creating transaction" << std::endl;
    caosdb_transaction_transaction multi_transaction; caosdb_transaction_transaction multi_transaction;
    caosdb_connection_connection_create_transaction(&connection, &multi_transaction); caosdb_connection_connection_create_transaction(&connection, &multi_transaction);
    // We explicitely want to define a C-style array here, so we disable // We explicitely want to define a C-style array here, so we disable
    // linting // linting
    const char *ids[] = {"id1", "id2", "id3"}; // NOLINT 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)); int return_code(caosdb_transaction_transaction_retrieve_by_ids(&multi_transaction, ids, 3));
    EXPECT_EQ(return_code, caosdb::StatusCode::GO_ON); EXPECT_EQ(return_code, caosdb::StatusCode::GO_ON);
    std::cout << "Deleting transaction ..." << std::endl;
    return_code = caosdb_transaction_delete_transaction(&multi_transaction); return_code = caosdb_transaction_delete_transaction(&multi_transaction);
    EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
    } }
    ...@@ -151,33 +147,41 @@ TEST_F(test_ccaosdb, test_entity) { ...@@ -151,33 +147,41 @@ TEST_F(test_ccaosdb, test_entity) {
    // 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");
    EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
    char out[255] = {"a"}; // NOLINT char *out = nullptr; // NOLINT
    return_code = caosdb_entity_entity_get_name(&entity, out); return_code = caosdb_entity_entity_get_name(&entity, &out);
    EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
    EXPECT_EQ(strcmp(out, "length"), 0); EXPECT_EQ(strcmp(out, "length"), 0);
    // TODO(fspreck) // invalid role
    // caosdb_entity_entity_set_role(&entity, "Property"); return_code = caosdb_entity_entity_set_role(&entity, "Role does not exist");
    // caosdb_entity_entity_get_role(&entity, out); EXPECT_EQ(return_code, caosdb::StatusCode::ENUM_MAPPING_ERROR);
    // EXPECT_EQ(strcmp(out, "Property"), 0);
    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_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); EXPECT_EQ(strcmp(out, "The length of an object"), 0);
    // TODO(fspreck) caosdb_entity_entity_set_datatype(&entity, "DOUBLE", false, false);
    // caosdb_entity_entity_set_datatype(&entity, "DOUBLE"); bool is_list[] = {false}; // NOLINT
    // caosdb_entity_entity_get_datatype(&entity, out); bool is_ref[] = {false}; // NOLINT
    // EXPECT_EQ(strcmp(out, "DOUBLE"), 0); 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_set_unit(&entity, "m");
    caosdb_entity_entity_get_unit(&entity, out); caosdb_entity_entity_get_unit(&entity, &out);
    EXPECT_EQ(strcmp(out, "m"), 0); EXPECT_EQ(strcmp(out, "m"), 0);
    // TODO(fspreck) return_code = caosdb_entity_entity_set_double_value(&entity, 5.0);
    // caosdb_entity_entity_set_value(&entity, "5.0"); EXPECT_EQ(return_code, 0);
    // caosdb_entity_entity_get_value(&entity, out); double value[] = {0.0}; // NOLINT
    // EXPECT_EQ(strcmp(out, "5.0"), 0); 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); return_code = caosdb_entity_delete_entity(&entity);
    EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
    ...@@ -192,11 +196,11 @@ TEST_F(test_ccaosdb, test_parent) { ...@@ -192,11 +196,11 @@ TEST_F(test_ccaosdb, test_parent) {
    caosdb_entity_parent_set_id(&parent, "some_id"); caosdb_entity_parent_set_id(&parent, "some_id");
    caosdb_entity_parent_set_name(&parent, "some_name"); caosdb_entity_parent_set_name(&parent, "some_name");
    char out[255] = {"a"}; // NOLINT char *out = nullptr; // NOLINT
    caosdb_entity_parent_get_id(&parent, out); caosdb_entity_parent_get_id(&parent, &out);
    EXPECT_EQ(strcmp(out, "some_id"), 0); 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); EXPECT_EQ(strcmp(out, "some_name"), 0);
    return_code = caosdb_entity_delete_parent(&parent); return_code = caosdb_entity_delete_parent(&parent);
    ...@@ -211,42 +215,77 @@ TEST_F(test_ccaosdb, test_property) { ...@@ -211,42 +215,77 @@ TEST_F(test_ccaosdb, test_property) {
    caosdb_entity_property_set_id(&property, "some_id"); caosdb_entity_property_set_id(&property, "some_id");
    caosdb_entity_property_set_name(&property, "some_name"); caosdb_entity_property_set_name(&property, "some_name");
    // TODO(fspreck)
    // caosdb_entity_property_set_datatype(&property, "some_datatype"); caosdb_entity_property_set_datatype(&property, "TEXT", false, false);
    // TODO(fspreck) caosdb_entity_property_set_importance(&property, "FIX");
    // caosdb_entity_property_set_importance(&property, "some_importance");
    caosdb_entity_property_set_unit(&property, "some_unit"); caosdb_entity_property_set_unit(&property, "some_unit");
    // TODO(fspreck) caosdb_entity_property_set_string_value(&property, "some_value");
    // caosdb_entity_property_set_value(&property, "some_value");
    char out[255] = {"a"}; // NOLINT char *out = nullptr; // NOLINT
    caosdb_entity_property_get_id(&property, out); caosdb_entity_property_get_id(&property, &out);
    EXPECT_EQ(strcmp(out, "some_id"), 0); 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); EXPECT_EQ(strcmp(out, "some_name"), 0);
    // TODO(fspreck) bool is_ref[] = {false}; // NOLINT
    // caosdb_entity_property_get_datatype(&property, out); bool is_list[] = {false}; // NOLINT
    // EXPECT_EQ(strcmp(out, "some_datatype"), 0); 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);
    // caosdb_entity_property_get_importance(&property, out); EXPECT_EQ(strcmp(out, "FIX"), 0);
    // EXPECT_EQ(strcmp(out, "some_importance"), 0);
    caosdb_entity_property_get_unit(&property, out); caosdb_entity_property_get_unit(&property, &out);
    EXPECT_EQ(strcmp(out, "some_unit"), 0); EXPECT_EQ(strcmp(out, "some_unit"), 0);
    // TODO(fspreck) caosdb_entity_property_get_string_value(&property, &out);
    // caosdb_entity_property_get_value(&property, out); EXPECT_EQ(strcmp(out, "some_value"), 0);
    // 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); return_code = caosdb_entity_delete_property(&property);
    EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
    } }
    TEST_F(test_ccaosdb, test_entity_with_parent_and_property) { TEST_F(test_ccaosdb, test_entity_with_parent_and_property) {
    std::cout << "Creating objects ... " << std::endl;
    caosdb_entity_parent input_parent; caosdb_entity_parent input_parent;
    int return_code(caosdb_entity_create_parent(&input_parent)); int return_code(caosdb_entity_create_parent(&input_parent));
    EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
    ...@@ -260,23 +299,20 @@ TEST_F(test_ccaosdb, test_entity_with_parent_and_property) { ...@@ -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_id(&input_property, "property_id");
    caosdb_entity_property_set_name(&input_property, "property_name"); caosdb_entity_property_set_name(&input_property, "property_name");
    // TODO(fspreck)
    // caosdb_entity_property_set_datatype(&input_property, "property_datatype"); caosdb_entity_property_set_datatype(&input_property, "TEXT", false, false);
    // TODO(fspreck) caosdb_entity_property_set_string_value(&input_property, "property_value");
    // caosdb_entity_property_set_value(&input_property, "property_value");
    caosdb_entity_entity entity; caosdb_entity_entity entity;
    return_code = caosdb_entity_create_entity(&entity); return_code = caosdb_entity_create_entity(&entity);
    EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
    std::cout << "Appending parent and property ..." << std::endl;
    return_code = caosdb_entity_entity_append_parent(&entity, &input_parent); return_code = caosdb_entity_entity_append_parent(&entity, &input_parent);
    EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
    return_code = caosdb_entity_entity_append_property(&entity, &input_property); return_code = caosdb_entity_entity_append_property(&entity, &input_property);
    EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
    std::cout << "Counting parents and properties ..." << std::endl;
    int count[] = {0}; // NOLINT int count[] = {0}; // NOLINT
    return_code = caosdb_entity_entity_get_parents_size(&entity, count); return_code = caosdb_entity_entity_get_parents_size(&entity, count);
    EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
    ...@@ -286,54 +322,51 @@ TEST_F(test_ccaosdb, test_entity_with_parent_and_property) { ...@@ -286,54 +322,51 @@ TEST_F(test_ccaosdb, test_entity_with_parent_and_property) {
    EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
    EXPECT_EQ(*count, 1); EXPECT_EQ(*count, 1);
    char in[255] = {"a"}; // NOLINT char *in = nullptr; // NOLINT
    char out[255] = {"b"}; // NOLINT char *out = nullptr; // NOLINT
    std::cout << "Comparing ..." << std::endl;
    // cannot assign an already assigned property // cannot assign an already assigned property
    return_code = caosdb_entity_entity_get_property(&entity, &input_property, 0); return_code = caosdb_entity_entity_get_property(&entity, &input_property, 0);
    EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR); EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR);
    caosdb_entity_property output_property; caosdb_entity_property output_property;
    return_code = caosdb_entity_entity_get_property(&entity, &output_property, 0); return_code = caosdb_entity_entity_get_property(&entity, &output_property, 0);
    std::cout << "Got output property." << std::endl;
    EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
    caosdb_entity_property_get_id(&input_property, in); caosdb_entity_property_get_id(&input_property, &in);
    std::cout << "Got input id." << std::endl; caosdb_entity_property_get_id(&output_property, &out);
    caosdb_entity_property_get_id(&output_property, out);
    std::cout << "Got output id." << std::endl;
    EXPECT_EQ(strcmp(in, out), 0); EXPECT_EQ(strcmp(in, out), 0);
    caosdb_entity_property_get_name(&input_property, in); caosdb_entity_property_get_name(&input_property, &in);
    caosdb_entity_property_get_name(&output_property, out); caosdb_entity_property_get_name(&output_property, &out);
    EXPECT_EQ(strcmp(in, out), 0); EXPECT_EQ(strcmp(in, out), 0);
    // TODO(fspreck) bool is_list[] = {false}; // NOLINT
    // caosdb_entity_property_get_datatype(&input_property, in); bool is_ref[] = {false}; // NOLINT
    // caosdb_entity_property_get_datatype(&output_property, out); caosdb_entity_property_get_datatype(&input_property, &in, is_ref, is_list);
    // EXPECT_EQ(strcmp(in, out), 0); 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_string_value(&input_property, &in);
    // caosdb_entity_property_get_value(&input_property, in); caosdb_entity_property_get_string_value(&output_property, &out);
    // caosdb_entity_property_get_value(&output_property, out); EXPECT_EQ(strcmp(in, out), 0);
    // EXPECT_EQ(strcmp(in, out), 0);
    std::cout << "Comparing parent..." << std::endl;
    caosdb_entity_parent output_parent; caosdb_entity_parent output_parent;
    return_code = caosdb_entity_entity_get_parent(&entity, &output_parent, 0); return_code = caosdb_entity_entity_get_parent(&entity, &output_parent, 0);
    std::cout << "Got output parent." << std::endl;
    EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
    caosdb_entity_parent_get_id(&input_parent, in); caosdb_entity_parent_get_id(&input_parent, &in);
    caosdb_entity_parent_get_id(&output_parent, out); caosdb_entity_parent_get_id(&output_parent, &out);
    EXPECT_EQ(strcmp(in, out), 0); EXPECT_EQ(strcmp(in, out), 0);
    caosdb_entity_parent_get_name(&input_parent, in); caosdb_entity_parent_get_name(&input_parent, &in);
    caosdb_entity_parent_get_name(&output_parent, out); caosdb_entity_parent_get_name(&output_parent, &out);
    EXPECT_EQ(strcmp(in, out), 0); EXPECT_EQ(strcmp(in, out), 0);
    // Delete everything // Delete everything
    std::cout << "Deleting ..." << std::endl;
    return_code = caosdb_entity_delete_parent(&input_parent); return_code = caosdb_entity_delete_parent(&input_parent);
    EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
    return_code = caosdb_entity_delete_property(&input_property); return_code = caosdb_entity_delete_property(&input_property);
    ...@@ -393,13 +426,13 @@ TEST_F(test_ccaosdb, test_remove_property) { ...@@ -393,13 +426,13 @@ TEST_F(test_ccaosdb, test_remove_property) {
    return_code = caosdb_entity_entity_get_property(&entity, &out_prop, 0); return_code = caosdb_entity_entity_get_property(&entity, &out_prop, 0);
    EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
    char in[255] = {"a"}; // NOLINT char *in = nullptr; // NOLINT
    char out[255] = {"b"}; // NOLINT char *out = nullptr; // NOLINT
    // Deleted the first property, so the second one should remain. // 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); 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(return_code, 0);
    EXPECT_EQ(strcmp(in, out), 0); EXPECT_EQ(strcmp(in, out), 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