diff --git a/include/clinkahead.h b/include/clinkahead.h index eddc2dfb7fabddf67af2fc20276d9b45c68155cb..72ceb8bae82970358fe3169a9b8c96413a338781 100644 --- a/include/clinkahead.h +++ b/include/clinkahead.h @@ -33,37 +33,37 @@ extern "C" { /** * Return the constant linkahead::LIBLINKAHEAD_VERSION_MAJOR. */ -int caosdb_constants_LIBLINKAHEAD_VERSION_MAJOR(); +int dconstants_LIBLINKAHEAD_VERSION_MAJOR(); /** * Return the constant linkahead::LIBLINKAHEAD_VERSION_MINOR */ -int caosdb_constants_LIBLINKAHEAD_VERSION_MINOR(); +int dconstants_LIBLINKAHEAD_VERSION_MINOR(); /** * Return the constant linkahead::LIBLINKAHEAD_VERSION_PATCH. */ -int caosdb_constants_LIBLINKAHEAD_VERSION_PATCH(); +int dconstants_LIBLINKAHEAD_VERSION_PATCH(); /** * Return the constant linkahead::COMPATIBLE_SERVER_VERSION_MAJOR. */ -int caosdb_constants_COMPATIBLE_SERVER_VERSION_MAJOR(); +int dconstants_COMPATIBLE_SERVER_VERSION_MAJOR(); /** * Return the constant linkahead::COMPATIBLE_SERVER_VERSION_MINOR. */ -int caosdb_constants_COMPATIBLE_SERVER_VERSION_MINOR(); +int dconstants_COMPATIBLE_SERVER_VERSION_MINOR(); /** * Return the constant linkahead::COMPATIBLE_SERVER_VERSION_PATCH. */ -int caosdb_constants_COMPATIBLE_SERVER_VERSION_PATCH(); +int dconstants_COMPATIBLE_SERVER_VERSION_PATCH(); /** * Return the constant linkahead::COMPATIBLE_SERVER_VERSION_PRE_RELEASE. */ -const char *caosdb_constants_COMPATIBLE_SERVER_VERSION_PRE_RELEASE(); +const char *dconstants_COMPATIBLE_SERVER_VERSION_PRE_RELEASE(); /** * Return the status code reserved for errors in clients wrapping this * interface. */ -int caosdb_status_code_OTHER_CLIENT_ERROR(); +int dstatus_code_OTHER_CLIENT_ERROR(); /** * A wrapper of the C++ Connection class. @@ -72,10 +72,10 @@ int caosdb_status_code_OTHER_CLIENT_ERROR(); * capability for type checking in C even though the C++ class * Connection is opaque in C. */ -typedef struct caosdb_connection_connection { +typedef struct dconnection_connection { void *wrapped_connection; bool _deletable; -} caosdb_connection_connection; +} dconnection_connection; /** * A wrapper of the C++ ConnectionConfiguration class. @@ -84,10 +84,10 @@ typedef struct caosdb_connection_connection { * capability for type checking in C even though the C++ class * Connection is opaque in C. */ -typedef struct caosdb_connection_connection_configuration { +typedef struct dconnection_connection_configuration { void *wrapped_connection_configuration; bool _deletable; -} caosdb_connection_connection_configuration; +} dconnection_connection_configuration; /** * A wrapper of the C++ VersionInfo class. @@ -96,55 +96,55 @@ typedef struct caosdb_connection_connection_configuration { * capability for type checking in C even though the C++ class * Connection is opaque in C. */ -typedef struct caosdb_info_version_info { +typedef struct dinfo_version_info { int major; int minor; int patch; const char *pre_release; const char *build; -} caosdb_info_version_info; +} dinfo_version_info; -typedef struct caosdb_connection_certificate_provider { +typedef struct dconnection_certificate_provider { void *wrapped_certificate_provider; bool _deletable; -} caosdb_connection_certificate_provider; +} dconnection_certificate_provider; -typedef struct caosdb_authentication_authenticator { +typedef struct dauthentication_authenticator { void *wrapped_authenticator; bool _deletable; -} caosdb_authentication_authenticator; +} dauthentication_authenticator; /** * Return the environment variable of the given name. * * If the environment variable is not set, return the fallback instead. */ -const char *caosdb_utility_get_env_fallback(const char *name, const char *fallback); +const char *dutility_get_env_fallback(const char *name, const char *fallback); /** * Return a description of the status code. */ -const char *caosdb_get_status_description(int code); +const char *dget_status_description(int code); /** * Create a pem-file certificate provider. * * Use the destructor function - * `caosdb_connection_delete_certificate_provider` to free the wrapped + * `dconnection_delete_certificate_provider` to free the wrapped * provider. * * EXPERT USE ONLY. Memory management with this function is a bit tricky. * Only use it when you know what you are doing. */ -int caosdb_connection_create_pem_file_certificate_provider( - caosdb_connection_certificate_provider *out, const char *path); +int dconnection_create_pem_file_certificate_provider( + dconnection_certificate_provider *out, const char *path); /** * Destructor function for a certificate provider. * * EXPERT USE ONLY. Only use it when you know what you are doing. */ -int caosdb_connection_delete_certificate_provider(caosdb_connection_certificate_provider *provider); +int dconnection_delete_certificate_provider(dconnection_certificate_provider *provider); /** * Create a tls-secured connection configuration. @@ -152,43 +152,43 @@ int caosdb_connection_delete_certificate_provider(caosdb_connection_certificate_ * The configuration is needed to instantiate a connection. * * Use the destructor function - * `caosdb_connection_delete_connection_configuration` to free the wrapped + * `dconnection_delete_connection_configuration` to free the wrapped * configuration. * * EXPERT USE ONLY. Memory management with this function is a bit tricky. * Only use it when you know what you are doing. */ -int caosdb_connection_create_tls_connection_configuration( - caosdb_connection_connection_configuration *out, const char *host, const int port, - caosdb_authentication_authenticator *authenticator, - caosdb_connection_certificate_provider *provider); +int dconnection_create_tls_connection_configuration( + dconnection_connection_configuration *out, const char *host, const int port, + dauthentication_authenticator *authenticator, + dconnection_certificate_provider *provider); /** * Create a tls-secured connection configuration. * * The configuration is needed to instantiate a connection. * - * Use `caosdb_connection_create_tls_connection_configuration` for a + * Use `dconnection_create_tls_connection_configuration` for a * tls-secured connection which also supports authentication. * * Use the destructor function - * `caosdb_connection_delete_connection_configuration` to free the wrapped + * `dconnection_delete_connection_configuration` to free the wrapped * configuration. * * EXPERT USE ONLY. Memory management with this function is a bit tricky. * Only use it when you know what you are doing. */ -int caosdb_connection_create_insecure_connection_configuration( - caosdb_connection_connection_configuration *out, const char *host, const int port); +int dconnection_create_insecure_connection_configuration( + dconnection_connection_configuration *out, const char *host, const int port); /** - * Destructor function for the caosdb_connection_connection_configuration + * Destructor function for the dconnection_connection_configuration * struct. * * EXPERT USE ONLY. Only use it when you know what you are doing. */ -int caosdb_connection_delete_connection_configuration( - caosdb_connection_connection_configuration *configuration); +int dconnection_delete_connection_configuration( + dconnection_connection_configuration *configuration); /** * Add a public certificate of a trusted certificate authority to an @@ -196,28 +196,28 @@ int caosdb_connection_delete_connection_configuration( * * @param cacert path to a pem-file. */ -int caosdb_connection_configuration_add_cacert( - caosdb_connection_connection_configuration *configuration, const char *cacert); +int dconnection_configuration_add_cacert( + dconnection_connection_configuration *configuration, const char *cacert); /** * Create a plain password authenticator. * * Use the destructor function - * `caosdb_authentication_delete_authenticator` to free the wrapped + * `dauthentication_delete_authenticator` to free the wrapped * authenticator. * * EXPERT USE ONLY. Memory management with this function is a bit tricky. * Only use it when you know what you are doing. */ -int caosdb_authentication_create_plain_password_authenticator( - caosdb_authentication_authenticator *out, const char *username, const char *password); +int dauthentication_create_plain_password_authenticator( + dauthentication_authenticator *out, const char *username, const char *password); /** - * Destructor function for the caosdb_authentication_authenticator struct. + * Destructor function for the dauthentication_authenticator struct. * * EXPERT USE ONLY. Only use it when you know what you are doing. */ -int caosdb_authentication_delete_authenticator(caosdb_authentication_authenticator *authenticator); +int dauthentication_delete_authenticator(dauthentication_authenticator *authenticator); /** * Create a connection instance. @@ -226,274 +226,274 @@ int caosdb_authentication_delete_authenticator(caosdb_authentication_authenticat * interaction with a CaosDB server. * * Use the destructor function - * `caosdb_connection_delete_connection` to free the wrapped + * `dconnection_delete_connection` to free the wrapped * connection. * * EXPERT USE ONLY. Memory management with this function is a bit tricky. * Only use it when you know what you are doing. */ -int caosdb_connection_create_connection( - caosdb_connection_connection *out, - const caosdb_connection_connection_configuration *configuration); +int dconnection_create_connection( + dconnection_connection *out, + const dconnection_connection_configuration *configuration); /** - * Destructor function for the caosdb_connection_connection struct. + * Destructor function for the dconnection_connection struct. * * EXPERT USE ONLY. Only use it when you know what you are doing. */ -int caosdb_connection_delete_connection(caosdb_connection_connection *connection); +int dconnection_delete_connection(dconnection_connection *connection); /** * Request the version of the server. */ -int caosdb_connection_get_version_info(caosdb_info_version_info *out, - const caosdb_connection_connection *connection); +int dconnection_get_version_info(dinfo_version_info *out, + const dconnection_connection *connection); /** * Get the default connection from the ConnectionManager. * * The default connection is to be specified in a configuration file. */ -int caosdb_connection_connection_manager_get_default_connection(caosdb_connection_connection *out); +int dconnection_connection_manager_get_default_connection(dconnection_connection *out); /** * Get a named connection from the ConnectionManager. * * The named connection is to be specified in a configuration file. */ -int caosdb_connection_connection_manager_get_connection(caosdb_connection_connection *out, +int dconnection_connection_manager_get_connection(dconnection_connection *out, const char *name); /**************************************************************************** * ENTITY STUFF AND TRANSACTIONS ****************************************************************************/ -typedef struct caosdb_transaction_transaction { +typedef struct dtransaction_transaction { void *wrapped_transaction; bool _deletable; -} caosdb_transaction_transaction; +} dtransaction_transaction; /** * Create a transaction on an existing connection. * * This transaction has to be deleted manually by - * caosdb_transaction_delete_transaction() later on. + * dtransaction_delete_transaction() later on. */ -int caosdb_connection_connection_create_transaction(caosdb_connection_connection *connection, - caosdb_transaction_transaction *out); -int caosdb_transaction_delete_transaction(caosdb_transaction_transaction *transaction); -int caosdb_transaction_transaction_retrieve_by_id(caosdb_transaction_transaction *transaction, +int dconnection_connection_create_transaction(dconnection_connection *connection, + dtransaction_transaction *out); +int dtransaction_delete_transaction(dtransaction_transaction *transaction); +int dtransaction_transaction_retrieve_by_id(dtransaction_transaction *transaction, const char *id); -int caosdb_transaction_transaction_retrieve_and_download_file_by_id( - caosdb_transaction_transaction *transaction, const char *id, const char *path); -int caosdb_transaction_transaction_retrieve_by_ids(caosdb_transaction_transaction *transaction, +int dtransaction_transaction_retrieve_and_download_file_by_id( + dtransaction_transaction *transaction, const char *id, const char *path); +int dtransaction_transaction_retrieve_by_ids(dtransaction_transaction *transaction, const char *ids[], int length); -int caosdb_transaction_transaction_query(caosdb_transaction_transaction *transaction, +int dtransaction_transaction_query(dtransaction_transaction *transaction, const char *query); -int caosdb_transaction_transaction_execute(caosdb_transaction_transaction *transaction); +int dtransaction_transaction_execute(dtransaction_transaction *transaction); // TODO(fspreck) execute_asynchronously may be added as a separate // function once we actually support asynchronous execution. -typedef struct caosdb_transaction_result_set { +typedef struct dtransaction_result_set { void *wrapped_result_set; bool _deletable; -} caosdb_transaction_result_set; +} dtransaction_result_set; -typedef struct caosdb_entity_entity { +typedef struct dentity_entity { void *wrapped_entity; bool _deletable; -} caosdb_entity_entity; +} dentity_entity; -int caosdb_transaction_transaction_get_result_set(caosdb_transaction_transaction *transaction, - caosdb_transaction_result_set *out); +int dtransaction_transaction_get_result_set(dtransaction_transaction *transaction, + dtransaction_result_set *out); /** * Release the result set from the transaction. * * The transactions is spoiled after this action and should not be used anymore. * - * Note: The result_set has to be deleted via caosdb_transaction_delete_result_set. + * Note: The result_set has to be deleted via dtransaction_delete_result_set. * * EXPERT USE ONLY. Only use it when you know what you are doing. */ -int caosdb_transaction_transaction_release_result_set(caosdb_transaction_transaction *transaction, - caosdb_transaction_result_set *out); +int dtransaction_transaction_release_result_set(dtransaction_transaction *transaction, + dtransaction_result_set *out); /** * Release the entity from the result set. * * Each entity (each index) can be released once. The result set is spoiled * after this action and should not be used for anything else anymore. * - * Note: The result_set has to be deleted via caosdb_entity_delete_entity. + * Note: The result_set has to be deleted via dentity_delete_entity. * * EXPERT USE ONLY. Only use it when you know what you are doing. */ -int caosdb_transaction_result_set_release_at(caosdb_transaction_result_set *result_set, - caosdb_entity_entity *entity, int index); +int dtransaction_result_set_release_at(dtransaction_result_set *result_set, + dentity_entity *entity, int index); /** - * Destructor for caosdb_transaction_result_set. + * Destructor for dtransaction_result_set. * * EXPERT USE ONLY. Only use it when you know what you are doing. */ -int caosdb_transaction_delete_result_set(caosdb_transaction_result_set *result_set); +int dtransaction_delete_result_set(dtransaction_result_set *result_set); -int caosdb_transaction_transaction_get_count_result(caosdb_transaction_transaction *transaction, +int dtransaction_transaction_get_count_result(dtransaction_transaction *transaction, long *out); -int caosdb_transaction_result_set_at(caosdb_transaction_result_set *result_set, - caosdb_entity_entity *entity, int index); -int caosdb_transaction_result_set_size(caosdb_transaction_result_set *result_set, int *out); +int linkahead_transaction_result_set_at(linkahead_transaction_result_set *result_set, + linkahead_entity_entity *entity, int index); +int linkahead_transaction_result_set_size(linkahead_transaction_result_set *result_set, int *out); -int caosdb_transaction_transaction_insert_entity(caosdb_transaction_transaction *transaction, - caosdb_entity_entity *entity); -int caosdb_transaction_transaction_update_entity(caosdb_transaction_transaction *transaction, - caosdb_entity_entity *entity); -int caosdb_transaction_transaction_delete_by_id(caosdb_transaction_transaction *transaction, +int linkahead_transaction_transaction_insert_entity(linkahead_transaction_transaction *transaction, + linkahead_entity_entity *entity); +int linkahead_transaction_transaction_update_entity(linkahead_transaction_transaction *transaction, + linkahead_entity_entity *entity); +int linkahead_transaction_transaction_delete_by_id(linkahead_transaction_transaction *transaction, const char *id); -typedef struct caosdb_entity_property { +typedef struct linkahead_entity_property { void *wrapped_property; bool _deletable; -} caosdb_entity_property; +} linkahead_entity_property; -typedef struct caosdb_entity_parent { +typedef struct linkahead_entity_parent { void *wrapped_parent; bool _deletable; -} caosdb_entity_parent; +} linkahead_entity_parent; -typedef struct caosdb_entity_message { +typedef struct linkahead_entity_message { void *wrapped_message; bool _deletable; -} caosdb_entity_message; +} linkahead_entity_message; -typedef struct caosdb_entity_value { +typedef struct linkahead_entity_value { void *wrapped_value; bool _deletable; -} caosdb_entity_value; +} linkahead_entity_value; -typedef struct caosdb_entity_datatype { +typedef struct linkahead_entity_datatype { void *wrapped_datatype; bool _deletable; -} caosdb_entity_datatype; +} linkahead_entity_datatype; // GETTERS FOR EVERYTHING -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_name(caosdb_entity_entity *entity, char **out); -int caosdb_entity_entity_get_description(caosdb_entity_entity *entity, char **out); -int caosdb_entity_entity_get_local_path(caosdb_entity_entity *entity, char **out); -int caosdb_entity_entity_get_datatype(caosdb_entity_entity *entity, caosdb_entity_datatype *out); -int caosdb_entity_entity_get_unit(caosdb_entity_entity *entity, char **out); -int caosdb_entity_entity_get_value(caosdb_entity_entity *entity, caosdb_entity_value *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_error(caosdb_entity_entity *entity, caosdb_entity_message *out, +int linkahead_entity_entity_get_id(linkahead_entity_entity *entity, char **out); +int linkahead_entity_entity_get_role(linkahead_entity_entity *entity, char **out); +int linkahead_entity_entity_get_name(linkahead_entity_entity *entity, char **out); +int linkahead_entity_entity_get_description(linkahead_entity_entity *entity, char **out); +int linkahead_entity_entity_get_local_path(linkahead_entity_entity *entity, char **out); +int linkahead_entity_entity_get_datatype(linkahead_entity_entity *entity, linkahead_entity_datatype *out); +int linkahead_entity_entity_get_unit(linkahead_entity_entity *entity, char **out); +int linkahead_entity_entity_get_value(linkahead_entity_entity *entity, linkahead_entity_value *out); +int linkahead_entity_entity_get_version_id(linkahead_entity_entity *entity, char **out); +int linkahead_entity_entity_get_errors_size(linkahead_entity_entity *entity, int *out); +int linkahead_entity_entity_get_error(linkahead_entity_entity *entity, linkahead_entity_message *out, int index); -int caosdb_entity_entity_get_warnings_size(caosdb_entity_entity *entity, int *out); -int caosdb_entity_entity_get_warning(caosdb_entity_entity *entity, caosdb_entity_message *out, +int linkahead_entity_entity_get_warnings_size(linkahead_entity_entity *entity, int *out); +int linkahead_entity_entity_get_warning(linkahead_entity_entity *entity, linkahead_entity_message *out, int index); -int caosdb_entity_entity_get_infos_size(caosdb_entity_entity *entity, int *out); -int caosdb_entity_entity_get_info(caosdb_entity_entity *entity, caosdb_entity_message *out, +int linkahead_entity_entity_get_infos_size(linkahead_entity_entity *entity, int *out); +int linkahead_entity_entity_get_info(linkahead_entity_entity *entity, linkahead_entity_message *out, int index); -int caosdb_entity_entity_get_properties_size(caosdb_entity_entity *entity, int *out); -int caosdb_entity_entity_get_property(caosdb_entity_entity *entity, caosdb_entity_property *out, +int linkahead_entity_entity_get_properties_size(linkahead_entity_entity *entity, int *out); +int linkahead_entity_entity_get_property(linkahead_entity_entity *entity, linkahead_entity_property *out, int index); -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 linkahead_entity_entity_get_parents_size(linkahead_entity_entity *entity, int *out); +int linkahead_entity_entity_get_parent(linkahead_entity_entity *entity, linkahead_entity_parent *out, int index); -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_description(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, - caosdb_entity_datatype *out); -int caosdb_entity_property_get_unit(caosdb_entity_property *property, char **out); -int caosdb_entity_property_get_value(caosdb_entity_property *property, caosdb_entity_value *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_description(caosdb_entity_message *message, char **out); - -int caosdb_entity_datatype_is_undefined(caosdb_entity_datatype *datatype, bool *out); -int caosdb_entity_datatype_is_atomic(caosdb_entity_datatype *datatype, bool *out); -int caosdb_entity_datatype_is_reference(caosdb_entity_datatype *datatype, bool *out); -int caosdb_entity_datatype_is_list_of_atomic(caosdb_entity_datatype *datatype, bool *out); -int caosdb_entity_datatype_is_list_of_reference(caosdb_entity_datatype *datatype, bool *out); -int caosdb_entity_datatype_get_datatype_name(caosdb_entity_datatype *datatype, char **out); - -int caosdb_entity_value_is_null(caosdb_entity_value *value, bool *out); -int caosdb_entity_value_is_string(caosdb_entity_value *value, bool *out); -int caosdb_entity_value_is_double(caosdb_entity_value *value, bool *out); -int caosdb_entity_value_is_integer(caosdb_entity_value *value, bool *out); -int caosdb_entity_value_is_bool(caosdb_entity_value *value, bool *out); -int caosdb_entity_value_is_vector(caosdb_entity_value *value, bool *out); -int caosdb_entity_value_get_as_string(caosdb_entity_value *value, char **out); -int caosdb_entity_value_get_as_double(caosdb_entity_value *value, double *out); -int caosdb_entity_value_get_as_integer(caosdb_entity_value *value, int64_t *out); -int caosdb_entity_value_get_as_bool(caosdb_entity_value *value, bool *out); -int caosdb_entity_value_get_as_vector_size(caosdb_entity_value *value, int *out); -int caosdb_entity_value_get_as_vector_at(caosdb_entity_value *value, caosdb_entity_value *out, +int linkahead_entity_property_get_id(linkahead_entity_property *property, char **out); +int linkahead_entity_property_get_name(linkahead_entity_property *property, char **out); +int linkahead_entity_property_get_description(linkahead_entity_property *property, char **out); +int linkahead_entity_property_get_importance(linkahead_entity_property *property, char **out); +int linkahead_entity_property_get_datatype(linkahead_entity_property *property, + linkahead_entity_datatype *out); +int linkahead_entity_property_get_unit(linkahead_entity_property *property, char **out); +int linkahead_entity_property_get_value(linkahead_entity_property *property, linkahead_entity_value *out); +int linkahead_entity_parent_get_id(linkahead_entity_parent *parent, char **out); +int linkahead_entity_parent_get_name(linkahead_entity_parent *parent, char **out); +int linkahead_entity_parent_get_description(linkahead_entity_parent *parent, char **out); + +int linkahead_entity_message_get_code(linkahead_entity_message *message, int *out); +int linkahead_entity_message_get_description(linkahead_entity_message *message, char **out); + +int linkahead_entity_datatype_is_undefined(linkahead_entity_datatype *datatype, bool *out); +int linkahead_entity_datatype_is_atomic(linkahead_entity_datatype *datatype, bool *out); +int linkahead_entity_datatype_is_reference(linkahead_entity_datatype *datatype, bool *out); +int linkahead_entity_datatype_is_list_of_atomic(linkahead_entity_datatype *datatype, bool *out); +int linkahead_entity_datatype_is_list_of_reference(linkahead_entity_datatype *datatype, bool *out); +int linkahead_entity_datatype_get_datatype_name(linkahead_entity_datatype *datatype, char **out); + +int linkahead_entity_value_is_null(linkahead_entity_value *value, bool *out); +int linkahead_entity_value_is_string(linkahead_entity_value *value, bool *out); +int linkahead_entity_value_is_double(linkahead_entity_value *value, bool *out); +int linkahead_entity_value_is_integer(linkahead_entity_value *value, bool *out); +int linkahead_entity_value_is_bool(linkahead_entity_value *value, bool *out); +int linkahead_entity_value_is_vector(linkahead_entity_value *value, bool *out); +int linkahead_entity_value_get_as_string(linkahead_entity_value *value, char **out); +int linkahead_entity_value_get_as_double(linkahead_entity_value *value, double *out); +int linkahead_entity_value_get_as_integer(linkahead_entity_value *value, int64_t *out); +int linkahead_entity_value_get_as_bool(linkahead_entity_value *value, bool *out); +int linkahead_entity_value_get_as_vector_size(linkahead_entity_value *value, int *out); +int linkahead_entity_value_get_as_vector_at(linkahead_entity_value *value, linkahead_entity_value *out, const int index); // CONSTRUCTORS AND DESTRUCTORS -int caosdb_entity_create_entity(caosdb_entity_entity *out); -int caosdb_entity_delete_entity(caosdb_entity_entity *out); -int caosdb_entity_create_property(caosdb_entity_property *out); -int caosdb_entity_delete_property(caosdb_entity_property *out); -int caosdb_entity_create_parent(caosdb_entity_parent *out); -int caosdb_entity_delete_parent(caosdb_entity_parent *out); +int linkahead_entity_create_entity(linkahead_entity_entity *out); +int linkahead_entity_delete_entity(linkahead_entity_entity *out); +int linkahead_entity_create_property(linkahead_entity_property *out); +int linkahead_entity_delete_property(linkahead_entity_property *out); +int linkahead_entity_create_parent(linkahead_entity_parent *out); +int linkahead_entity_delete_parent(linkahead_entity_parent *out); // DATATYPE CONSTRUCTORS for atomic and reference datatypes and lists thereof -int caosdb_entity_create_atomic_datatype(caosdb_entity_datatype *out, const char *name); -int caosdb_entity_create_reference_datatype(caosdb_entity_datatype *out, const char *name); -int caosdb_entity_create_atomic_list_datatype(caosdb_entity_datatype *out, const char *name); -int caosdb_entity_create_reference_list_datatype(caosdb_entity_datatype *out, const char *name); -int caosdb_entity_delete_datatype(caosdb_entity_datatype *out); +int linkahead_entity_create_atomic_datatype(linkahead_entity_datatype *out, const char *name); +int linkahead_entity_create_reference_datatype(linkahead_entity_datatype *out, const char *name); +int linkahead_entity_create_atomic_list_datatype(linkahead_entity_datatype *out, const char *name); +int linkahead_entity_create_reference_list_datatype(linkahead_entity_datatype *out, const char *name); +int linkahead_entity_delete_datatype(linkahead_entity_datatype *out); // VALUE CONSTRUCTORS (resolve overloaded constructors) -int caosdb_entity_create_int_value(caosdb_entity_value *out, const int64_t value); -int caosdb_entity_create_string_value(caosdb_entity_value *out, const char *value); -int caosdb_entity_create_double_value(caosdb_entity_value *out, const double value); -int caosdb_entity_create_bool_value(caosdb_entity_value *out, const bool value); -int caosdb_entity_create_int_vector_value(caosdb_entity_value *out, const int64_t *value, +int linkahead_entity_create_int_value(linkahead_entity_value *out, const int64_t value); +int linkahead_entity_create_string_value(linkahead_entity_value *out, const char *value); +int linkahead_entity_create_double_value(linkahead_entity_value *out, const double value); +int linkahead_entity_create_bool_value(linkahead_entity_value *out, const bool value); +int linkahead_entity_create_int_vector_value(linkahead_entity_value *out, const int64_t *value, const int length); -int caosdb_entity_create_string_vector_value(caosdb_entity_value *out, const char **value, +int linkahead_entity_create_string_vector_value(linkahead_entity_value *out, const char **value, const int length); -int caosdb_entity_create_double_vector_value(caosdb_entity_value *out, const double *value, +int linkahead_entity_create_double_vector_value(linkahead_entity_value *out, const double *value, const int length); -int caosdb_entity_create_bool_vector_value(caosdb_entity_value *out, const bool *value, +int linkahead_entity_create_bool_vector_value(linkahead_entity_value *out, const bool *value, const int length); -int caosdb_entity_delete_value(caosdb_entity_value *out); +int linkahead_entity_delete_value(linkahead_entity_value *out); // SETTERS FOR EVERYTHING THAT MAY BE SET -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_description(caosdb_entity_entity *entity, const char *description); -int caosdb_entity_entity_set_local_path(caosdb_entity_entity *entity, const char *name); -int caosdb_entity_entity_set_file_path(caosdb_entity_entity *entity, const char *name); -int caosdb_entity_entity_set_datatype(caosdb_entity_entity *entity, - caosdb_entity_datatype *datatype); -int caosdb_entity_entity_set_unit(caosdb_entity_entity *entity, const char *unit); -int caosdb_entity_entity_set_value(caosdb_entity_entity *entity, caosdb_entity_value *value); - -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_append_property(caosdb_entity_entity *entity, - caosdb_entity_property *property); -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_name(caosdb_entity_property *property, const char *name); -int caosdb_entity_property_set_datatype(caosdb_entity_property *property, - caosdb_entity_datatype *datatype); -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_value(caosdb_entity_property *property, caosdb_entity_value *value); - -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 linkahead_entity_entity_set_role(linkahead_entity_entity *entity, const char *role); +int linkahead_entity_entity_set_name(linkahead_entity_entity *entity, const char *name); +int linkahead_entity_entity_set_description(linkahead_entity_entity *entity, const char *description); +int linkahead_entity_entity_set_local_path(linkahead_entity_entity *entity, const char *name); +int linkahead_entity_entity_set_file_path(linkahead_entity_entity *entity, const char *name); +int linkahead_entity_entity_set_datatype(linkahead_entity_entity *entity, + linkahead_entity_datatype *datatype); +int linkahead_entity_entity_set_unit(linkahead_entity_entity *entity, const char *unit); +int linkahead_entity_entity_set_value(linkahead_entity_entity *entity, linkahead_entity_value *value); + +int linkahead_entity_entity_append_parent(linkahead_entity_entity *entity, linkahead_entity_parent *parent); +int linkahead_entity_entity_remove_parent(linkahead_entity_entity *entity, int index); +int linkahead_entity_entity_append_property(linkahead_entity_entity *entity, + linkahead_entity_property *property); +int linkahead_entity_entity_remove_property(linkahead_entity_entity *entity, int index); + +int linkahead_entity_property_set_id(linkahead_entity_property *property, const char *id); +int linkahead_entity_property_set_name(linkahead_entity_property *property, const char *name); +int linkahead_entity_property_set_datatype(linkahead_entity_property *property, + linkahead_entity_datatype *datatype); +int linkahead_entity_property_set_importance(linkahead_entity_property *property, const char *importance); +int linkahead_entity_property_set_unit(linkahead_entity_property *property, const char *unit); +int linkahead_entity_property_set_value(linkahead_entity_property *property, linkahead_entity_value *value); + +int linkahead_entity_parent_set_id(linkahead_entity_parent *parent, const char *id); +int linkahead_entity_parent_set_name(linkahead_entity_parent *parent, const char *name); #ifdef __cplusplus } diff --git a/include/linkahead/logging.h b/include/linkahead/logging.h index bc6216b52def7405b36971e1128ec89ede1e8ccf..2df38dfbc6831073e317ba93ea7934b9b578bd89 100644 --- a/include/linkahead/logging.h +++ b/include/linkahead/logging.h @@ -203,27 +203,27 @@ private: /** * Convenience function for the C interface. */ -void caosdb_log_fatal(const char *channel, const char *msg); +void linkahead_log_fatal(const char *channel, const char *msg); /** * Convenience function for the C interface. */ -void caosdb_log_error(const char *channel, const char *msg); +void linkahead_log_error(const char *channel, const char *msg); /** * Convenience function for the C interface. */ -void caosdb_log_warn(const char *channel, const char *msg); +void linkahead_log_warn(const char *channel, const char *msg); /** * Convenience function for the C interface. */ -void caosdb_log_info(const char *channel, const char *msg); +void linkahead_log_info(const char *channel, const char *msg); /** * Convenience function for the C interface. */ -void caosdb_log_debug(const char *channel, const char *msg); +void linkahead_log_debug(const char *channel, const char *msg); /** * Convenience function for the C interface. */ -void caosdb_log_trace(const char *channel, const char *msg); +void linkahead_log_trace(const char *channel, const char *msg); } // namespace linkahead::logging diff --git a/src/clinkahead.cpp b/src/clinkahead.cpp index 3fcd6a3b333f16685b5b2a0f7c96ca19045b0b2d..8331bc5998436bab00452bdcbd249f05d26e5992 100644 --- a/src/clinkahead.cpp +++ b/src/clinkahead.cpp @@ -71,7 +71,7 @@ extern "C" { try { \ body \ } catch (const std::exception &exc) { \ - linkahead::logging::caosdb_log_fatal(CLINKAHEAD_LOGGER_NAME, exc.what()); \ + linkahead::logging::linkahead_log_fatal(CLINKAHEAD_LOGGER_NAME, exc.what()); \ return linkahead::StatusCode::code; \ } \ } @@ -82,7 +82,7 @@ extern "C" { #define LINKAHEAD_ENTITY_GET(element, GetFunction) \ ERROR_RETURN_CODE( \ GENERIC_ERROR, \ - int caosdb_entity_entity_get_##element(caosdb_entity_entity *entity, char **out), { \ + int linkahead_entity_entity_get_##element(linkahead_entity_entity *entity, char **out), { \ auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); \ auto *tmp = (char *)malloc(sizeof(char) * wrapped_entity->GetFunction.length() + 1); \ strcpy(tmp, wrapped_entity->GetFunction.c_str()); \ @@ -97,7 +97,7 @@ extern "C" { #define LINKAHEAD_ENTITY_SET(element, value, body_part) \ ERROR_RETURN_CODE( \ GENERIC_ERROR, \ - int caosdb_entity_entity_set_##element(caosdb_entity_entity *entity, const char *value), { \ + int linkahead_entity_entity_set_##element(linkahead_entity_entity *entity, const char *value), { \ auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); \ body_part return 0; \ }) @@ -108,7 +108,7 @@ extern "C" { #define LINKAHEAD_PROPERTY_GET(element, GetFunction) \ ERROR_RETURN_CODE( \ GENERIC_ERROR, \ - int caosdb_entity_property_get_##element(caosdb_entity_property *property, char **out), { \ + int linkahead_entity_property_get_##element(linkahead_entity_property *property, char **out), { \ auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); \ auto *tmp = (char *)malloc(sizeof(char) * wrapped_property->GetFunction.length() + 1); \ strcpy(tmp, wrapped_property->GetFunction.c_str()); \ @@ -123,7 +123,7 @@ extern "C" { #define LINKAHEAD_PROPERTY_SET(element, value, body_part) \ ERROR_RETURN_CODE( \ GENERIC_ERROR, \ - int caosdb_entity_property_set_##element(caosdb_entity_property *property, const char *value), \ + int linkahead_entity_property_set_##element(linkahead_entity_property *property, const char *value), \ { \ auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); \ body_part return 0; \ @@ -135,7 +135,7 @@ extern "C" { #define LINKAHEAD_PARENT_GET(element, GetFunction) \ ERROR_RETURN_CODE( \ GENERIC_ERROR, \ - int caosdb_entity_parent_get_##element(caosdb_entity_parent *parent, char **out), { \ + int linkahead_entity_parent_get_##element(linkahead_entity_parent *parent, char **out), { \ auto *wrapped_parent = WRAPPED_PARENT_CAST(parent); \ auto *tmp = (char *)malloc(sizeof(char) * wrapped_parent->GetFunction.length() + 1); \ strcpy(tmp, wrapped_parent->GetFunction.c_str()); \ @@ -150,7 +150,7 @@ extern "C" { #define LINKAHEAD_PARENT_SET(element, value, body_part) \ ERROR_RETURN_CODE( \ GENERIC_ERROR, \ - int caosdb_entity_parent_set_##element(caosdb_entity_parent *parent, const char *value), { \ + int linkahead_entity_parent_set_##element(linkahead_entity_parent *parent, const char *value), { \ auto *wrapped_parent = WRAPPED_PARENT_CAST(parent); \ body_part return 0; \ }) @@ -160,7 +160,7 @@ extern "C" { */ #define CREATE_VALUE(fname, arg) \ ERROR_RETURN_CODE(GENERIC_ERROR, \ - int caosdb_entity_create_##fname(caosdb_entity_value *out, arg), { \ + int linkahead_entity_create_##fname(linkahead_entity_value *out, arg), { \ out->wrapped_value = new linkahead::entity::Value(value); \ out->_deletable = true; \ return 0; \ @@ -171,7 +171,7 @@ extern "C" { #define CREATE_VECTOR_VALUE(fname, type, arg, assign) \ ERROR_RETURN_CODE( \ GENERIC_ERROR, \ - int caosdb_entity_create_##fname(caosdb_entity_value *out, arg, const int length), { \ + int linkahead_entity_create_##fname(linkahead_entity_value *out, arg, const int length), { \ std::vector<type> value_vec; \ for (int i = 0; i < length; i++) { \ value_vec.push_back(assign); \ @@ -186,7 +186,7 @@ extern "C" { */ #define VALUE_IS(fname, isfunction) \ ERROR_RETURN_CODE(GENERIC_ERROR, \ - int caosdb_entity_value_is_##fname(caosdb_entity_value *value, bool *out), { \ + int linkahead_entity_value_is_##fname(linkahead_entity_value *value, bool *out), { \ auto *wrapped_value = WRAPPED_VALUE_CAST(value); \ *out = wrapped_value->isfunction(); \ return 0; \ @@ -197,47 +197,47 @@ extern "C" { */ #define VALUE_GET_AS(fname, getfunction, arg) \ ERROR_RETURN_CODE(GENERIC_ERROR, \ - int caosdb_entity_value_get_as_##fname(caosdb_entity_value *value, arg), { \ + int linkahead_entity_value_get_as_##fname(linkahead_entity_value *value, arg), { \ auto *wrapped_value = WRAPPED_VALUE_CAST(value); \ *out = wrapped_value->getfunction(); \ return 0; \ }) -int caosdb_constants_LIBLINKAHEAD_VERSION_MAJOR() { return linkahead::LIBLINKAHEAD_VERSION_MAJOR; } +int linkahead_constants_LIBLINKAHEAD_VERSION_MAJOR() { return linkahead::LIBLINKAHEAD_VERSION_MAJOR; } -int caosdb_constants_LIBLINKAHEAD_VERSION_MINOR() { return linkahead::LIBLINKAHEAD_VERSION_MINOR; } +int linkahead_constants_LIBLINKAHEAD_VERSION_MINOR() { return linkahead::LIBLINKAHEAD_VERSION_MINOR; } -int caosdb_constants_LIBLINKAHEAD_VERSION_PATCH() { return linkahead::LIBLINKAHEAD_VERSION_PATCH; } +int linkahead_constants_LIBLINKAHEAD_VERSION_PATCH() { return linkahead::LIBLINKAHEAD_VERSION_PATCH; } -int caosdb_constants_COMPATIBLE_SERVER_VERSION_MAJOR() { +int linkahead_constants_COMPATIBLE_SERVER_VERSION_MAJOR() { return linkahead::COMPATIBLE_SERVER_VERSION_MAJOR; } -int caosdb_constants_COMPATIBLE_SERVER_VERSION_MINOR() { +int linkahead_constants_COMPATIBLE_SERVER_VERSION_MINOR() { return linkahead::COMPATIBLE_SERVER_VERSION_MINOR; } -int caosdb_constants_COMPATIBLE_SERVER_VERSION_PATCH() { +int linkahead_constants_COMPATIBLE_SERVER_VERSION_PATCH() { return linkahead::COMPATIBLE_SERVER_VERSION_PATCH; } -const char *caosdb_constants_COMPATIBLE_SERVER_VERSION_PRE_RELEASE() { +const char *linkahead_constants_COMPATIBLE_SERVER_VERSION_PRE_RELEASE() { return linkahead::COMPATIBLE_SERVER_VERSION_PRE_RELEASE; } -int caosdb_status_code_OTHER_CLIENT_ERROR() { return linkahead::StatusCode::OTHER_CLIENT_ERROR; } +int linkahead_status_code_OTHER_CLIENT_ERROR() { return linkahead::StatusCode::OTHER_CLIENT_ERROR; } -const char *caosdb_utility_get_env_fallback(const char *name, const char *fallback) { +const char *linkahead_utility_get_env_fallback(const char *name, const char *fallback) { return linkahead::utility::get_env_fallback(name, fallback); } -const char *caosdb_get_status_description(int code) { +const char *linkahead_get_status_description(int code) { return linkahead::get_status_description(code).c_str(); } ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_connection_create_pem_file_certificate_provider( - caosdb_connection_certificate_provider *out, const char *path), + int linkahead_connection_create_pem_file_certificate_provider( + linkahead_connection_certificate_provider *out, const char *path), { out->wrapped_certificate_provider = new linkahead::configuration::PemFileCertificateProvider(std::string(path)); @@ -246,8 +246,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_connection_delete_certificate_provider( - caosdb_connection_certificate_provider *provider), + int linkahead_connection_delete_certificate_provider( + linkahead_connection_certificate_provider *provider), { if (provider->_deletable && provider->wrapped_certificate_provider) { delete static_cast<linkahead::configuration::CertificateProvider *>( @@ -259,8 +259,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_authentication_create_plain_password_authenticator( - caosdb_authentication_authenticator *out, const char *username, + int linkahead_authentication_create_plain_password_authenticator( + linkahead_authentication_authenticator *out, const char *username, const char *password), { out->wrapped_authenticator = @@ -271,8 +271,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_authentication_delete_authenticator( - caosdb_authentication_authenticator *authenticator), + int linkahead_authentication_delete_authenticator( + linkahead_authentication_authenticator *authenticator), { if (authenticator->_deletable && authenticator->wrapped_authenticator) { delete static_cast<linkahead::authentication::Authenticator *>( @@ -285,10 +285,10 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_connection_create_tls_connection_configuration( - caosdb_connection_connection_configuration *out, const char *host, const int port, - caosdb_authentication_authenticator *authenticator, - caosdb_connection_certificate_provider *provider), + int linkahead_connection_create_tls_connection_configuration( + linkahead_connection_connection_configuration *out, const char *host, const int port, + linkahead_authentication_authenticator *authenticator, + linkahead_connection_certificate_provider *provider), { auto host_str = std::string(host); if (authenticator != nullptr && provider != nullptr) { @@ -319,8 +319,8 @@ ERROR_RETURN_CODE( }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_connection_create_insecure_connection_configuration( - caosdb_connection_connection_configuration *out, const char *host, + int linkahead_connection_create_insecure_connection_configuration( + linkahead_connection_connection_configuration *out, const char *host, const int port), { out->wrapped_connection_configuration = @@ -330,8 +330,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_connection_delete_connection_configuration( - caosdb_connection_connection_configuration *configuration), + int linkahead_connection_delete_connection_configuration( + linkahead_connection_connection_configuration *configuration), { if (configuration->_deletable && configuration->wrapped_connection_configuration) { @@ -344,9 +344,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_connection_create_connection( - caosdb_connection_connection *out, - const caosdb_connection_connection_configuration *configuration), + int linkahead_connection_create_connection( + linkahead_connection_connection *out, + const linkahead_connection_connection_configuration *configuration), { linkahead::configuration::ConnectionConfiguration *config = static_cast<linkahead::configuration::ConnectionConfiguration *>( @@ -357,7 +357,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_connection_delete_connection(caosdb_connection_connection *connection), + int linkahead_connection_delete_connection(linkahead_connection_connection *connection), { if (connection->_deletable && connection->wrapped_connection) { delete static_cast<linkahead::connection::Connection *>( @@ -370,8 +370,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_connection_get_version_info(caosdb_info_version_info *out, - const caosdb_connection_connection *connection), + int linkahead_connection_get_version_info(linkahead_info_version_info *out, + const linkahead_connection_connection *connection), { auto *wrapped_connection = static_cast<linkahead::connection::Connection *>(connection->wrapped_connection); @@ -400,8 +400,8 @@ ERROR_RETURN_CODE( }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_connection_connection_manager_get_default_connection( - caosdb_connection_connection *out), + int linkahead_connection_connection_manager_get_default_connection( + linkahead_connection_connection *out), { out->wrapped_connection = linkahead::connection::ConnectionManager::GetDefaultConnection().get(); @@ -411,7 +411,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_connection_connection_manager_get_connection(caosdb_connection_connection *out, + int linkahead_connection_connection_manager_get_connection(linkahead_connection_connection *out, const char *name), { out->wrapped_connection = @@ -426,8 +426,8 @@ ERROR_RETURN_CODE( * ENTITY STUFF AND TRANSACTIONS ****************************************************************************/ ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_connection_connection_create_transaction( - caosdb_connection_connection *connection, caosdb_transaction_transaction *out), + int linkahead_connection_connection_create_transaction( + linkahead_connection_connection *connection, linkahead_transaction_transaction *out), { auto *wrapped_connection = static_cast<linkahead::connection::Connection *>( connection->wrapped_connection); @@ -438,7 +438,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_transaction_delete_transaction(caosdb_transaction_transaction *transaction), { + int linkahead_transaction_delete_transaction(linkahead_transaction_transaction *transaction), { if (transaction->_deletable && transaction->wrapped_transaction) { delete static_cast<linkahead::transaction::Transaction *>(transaction->wrapped_transaction); } @@ -448,8 +448,8 @@ ERROR_RETURN_CODE( }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_transaction_transaction_retrieve_by_id( - caosdb_transaction_transaction *transaction, const char *id), + int linkahead_transaction_transaction_retrieve_by_id( + linkahead_transaction_transaction *transaction, const char *id), { auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>( transaction->wrapped_transaction); @@ -457,8 +457,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_transaction_transaction_retrieve_and_download_file_by_id( - caosdb_transaction_transaction *transaction, const char *id, const char *path), + int linkahead_transaction_transaction_retrieve_and_download_file_by_id( + linkahead_transaction_transaction *transaction, const char *id, const char *path), { auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>( transaction->wrapped_transaction); @@ -467,8 +467,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_transaction_transaction_retrieve_by_ids( - caosdb_transaction_transaction *transaction, const char *ids[], int length), + int linkahead_transaction_transaction_retrieve_by_ids( + linkahead_transaction_transaction *transaction, const char *ids[], int length), { auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>( transaction->wrapped_transaction); @@ -476,8 +476,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_transaction_transaction_query( - caosdb_transaction_transaction *transaction, const char *query), + int linkahead_transaction_transaction_query( + linkahead_transaction_transaction *transaction, const char *query), { auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>( transaction->wrapped_transaction); @@ -486,8 +486,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_transaction_transaction_insert_entity(caosdb_transaction_transaction *transaction, - caosdb_entity_entity *entity), + int linkahead_transaction_transaction_insert_entity(linkahead_transaction_transaction *transaction, + linkahead_entity_entity *entity), { auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>(transaction->wrapped_transaction); @@ -498,8 +498,8 @@ ERROR_RETURN_CODE( ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_transaction_transaction_update_entity(caosdb_transaction_transaction *transaction, - caosdb_entity_entity *entity), + int linkahead_transaction_transaction_update_entity(linkahead_transaction_transaction *transaction, + linkahead_entity_entity *entity), { auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>(transaction->wrapped_transaction); @@ -509,8 +509,8 @@ ERROR_RETURN_CODE( }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_transaction_transaction_delete_by_id( - caosdb_transaction_transaction *transaction, const char *id), + int linkahead_transaction_transaction_delete_by_id( + linkahead_transaction_transaction *transaction, const char *id), { auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>( transaction->wrapped_transaction); @@ -520,7 +520,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_transaction_transaction_execute(caosdb_transaction_transaction *transaction), { + int linkahead_transaction_transaction_execute(linkahead_transaction_transaction *transaction), { auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>(transaction->wrapped_transaction); wrapped_transaction->ExecuteAsynchronously(); @@ -530,8 +530,8 @@ ERROR_RETURN_CODE( ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_transaction_transaction_get_result_set(caosdb_transaction_transaction *transaction, - caosdb_transaction_result_set *out), + int linkahead_transaction_transaction_get_result_set(linkahead_transaction_transaction *transaction, + linkahead_transaction_result_set *out), { auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>(transaction->wrapped_transaction); @@ -542,8 +542,8 @@ ERROR_RETURN_CODE( ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_transaction_transaction_release_result_set(caosdb_transaction_transaction *transaction, - caosdb_transaction_result_set *out), + int linkahead_transaction_transaction_release_result_set(linkahead_transaction_transaction *transaction, + linkahead_transaction_result_set *out), { auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>(transaction->wrapped_transaction); @@ -555,7 +555,7 @@ ERROR_RETURN_CODE( ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_transaction_delete_result_set(caosdb_transaction_result_set *result_set), { + int linkahead_transaction_delete_result_set(linkahead_transaction_result_set *result_set), { if (result_set->_deletable && result_set->wrapped_result_set) { delete static_cast<linkahead::entity::Entity *>(result_set->wrapped_result_set); } @@ -565,8 +565,8 @@ ERROR_RETURN_CODE( }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_transaction_transaction_get_count_result( - caosdb_transaction_transaction *transaction, long *out), + int linkahead_transaction_transaction_get_count_result( + linkahead_transaction_transaction *transaction, long *out), { auto *wrapped_transaction = static_cast<linkahead::transaction::Transaction *>( transaction->wrapped_transaction); @@ -576,8 +576,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_transaction_result_set_at(caosdb_transaction_result_set *result_set, - caosdb_entity_entity *entity, int index), + int linkahead_transaction_result_set_at(linkahead_transaction_result_set *result_set, + linkahead_entity_entity *entity, int index), { auto *wrapped_result_set = static_cast<linkahead::transaction::MultiResultSet *>( @@ -588,8 +588,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_transaction_result_set_release_at(caosdb_transaction_result_set *result_set, - caosdb_entity_entity *entity, int index), + int linkahead_transaction_result_set_release_at(linkahead_transaction_result_set *result_set, + linkahead_entity_entity *entity, int index), { auto *wrapped_result_set = static_cast<linkahead::transaction::MultiResultSet *>(result_set->wrapped_result_set); @@ -601,7 +601,7 @@ ERROR_RETURN_CODE( ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_transaction_result_set_size(caosdb_transaction_result_set *result_set, int *out), { + int linkahead_transaction_result_set_size(linkahead_transaction_result_set *result_set, int *out), { auto *wrapped_result_set = static_cast<linkahead::transaction::MultiResultSet *>(result_set->wrapped_result_set); int size(wrapped_result_set->size()); @@ -609,13 +609,13 @@ ERROR_RETURN_CODE( return 0; }) -ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_create_entity(caosdb_entity_entity *out), { +ERROR_RETURN_CODE(GENERIC_ERROR, int linkahead_entity_create_entity(linkahead_entity_entity *out), { out->wrapped_entity = new linkahead::entity::Entity(); out->_deletable = true; return 0; }) -ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_entity(caosdb_entity_entity *out), { +ERROR_RETURN_CODE(GENERIC_ERROR, int linkahead_entity_delete_entity(linkahead_entity_entity *out), { if (out->_deletable && out->wrapped_entity) { delete static_cast<linkahead::entity::Entity *>(out->wrapped_entity); } @@ -624,13 +624,13 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_entity(caosdb_entity_e return 0; }) -ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_create_property(caosdb_entity_property *out), { +ERROR_RETURN_CODE(GENERIC_ERROR, int linkahead_entity_create_property(linkahead_entity_property *out), { out->wrapped_property = new linkahead::entity::Property(); out->_deletable = true; return 0; }) -ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_property(caosdb_entity_property *out), { +ERROR_RETURN_CODE(GENERIC_ERROR, int linkahead_entity_delete_property(linkahead_entity_property *out), { if (out->_deletable && out->wrapped_property) { delete static_cast<linkahead::entity::Property *>(out->wrapped_property); } @@ -639,13 +639,13 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_property(caosdb_entity return 0; }) -ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_create_parent(caosdb_entity_parent *out), { +ERROR_RETURN_CODE(GENERIC_ERROR, int linkahead_entity_create_parent(linkahead_entity_parent *out), { out->wrapped_parent = new linkahead::entity::Parent(); out->_deletable = true; return 0; }) -ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_parent(caosdb_entity_parent *out), { +ERROR_RETURN_CODE(GENERIC_ERROR, int linkahead_entity_delete_parent(linkahead_entity_parent *out), { if (out->_deletable && out->wrapped_parent) { delete static_cast<linkahead::entity::Parent *>(out->wrapped_parent); } @@ -655,7 +655,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_parent(caosdb_entity_p }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_create_atomic_datatype(caosdb_entity_datatype *out, + int linkahead_entity_create_atomic_datatype(linkahead_entity_datatype *out, const char *name), { try { @@ -664,12 +664,12 @@ ERROR_RETURN_CODE(GENERIC_ERROR, out->_deletable = true; return 0; } catch (const std::out_of_range &exc) { - linkahead::logging::caosdb_log_fatal(CLINKAHEAD_LOGGER_NAME, exc.what()); + linkahead::logging::linkahead_log_fatal(CLINKAHEAD_LOGGER_NAME, exc.what()); return linkahead::StatusCode::ENUM_MAPPING_ERROR; } }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_create_reference_datatype(caosdb_entity_datatype *out, + int linkahead_entity_create_reference_datatype(linkahead_entity_datatype *out, const char *name), { out->wrapped_datatype = new linkahead::entity::DataType(std::string(name)); @@ -677,7 +677,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_create_atomic_list_datatype(caosdb_entity_datatype *out, + int linkahead_entity_create_atomic_list_datatype(linkahead_entity_datatype *out, const char *name), { try { @@ -687,12 +687,12 @@ ERROR_RETURN_CODE(GENERIC_ERROR, out->_deletable = true; return 0; } catch (const std::out_of_range &exc) { - linkahead::logging::caosdb_log_fatal(CLINKAHEAD_LOGGER_NAME, exc.what()); + linkahead::logging::linkahead_log_fatal(CLINKAHEAD_LOGGER_NAME, exc.what()); return linkahead::StatusCode::ENUM_MAPPING_ERROR; } }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_create_reference_list_datatype(caosdb_entity_datatype *out, + int linkahead_entity_create_reference_list_datatype(linkahead_entity_datatype *out, const char *name), { out->wrapped_datatype = new linkahead::entity::DataType( @@ -701,7 +701,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return 0; }) -ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_datatype(caosdb_entity_datatype *out), { +ERROR_RETURN_CODE(GENERIC_ERROR, int linkahead_entity_delete_datatype(linkahead_entity_datatype *out), { if (out->_deletable && out->wrapped_datatype) { delete WRAPPED_DATATYPE_CAST(out); } @@ -719,7 +719,7 @@ CREATE_VECTOR_VALUE(string_vector_value, std::string, const char **value, std::s CREATE_VECTOR_VALUE(double_vector_value, double, const double *value, value[i]) CREATE_VECTOR_VALUE(bool_vector_value, bool, const bool *value, value[i]) -ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_value(caosdb_entity_value *out), { +ERROR_RETURN_CODE(GENERIC_ERROR, int linkahead_entity_delete_value(linkahead_entity_value *out), { if (out->_deletable && out->wrapped_value) { delete WRAPPED_VALUE_CAST(out); } @@ -730,7 +730,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_value(caosdb_entity_va LINKAHEAD_ENTITY_GET(id, GetId()) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_role(caosdb_entity_entity *entity, char **out), { + int linkahead_entity_entity_get_role(linkahead_entity_entity *entity, char **out), { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); std::string role_str = ENUM_NAME_FROM_VALUE(wrapped_entity->GetRole(), Role); auto *tmp = (char *)malloc(sizeof(char) * role_str.length() + 1); @@ -741,7 +741,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) LINKAHEAD_ENTITY_GET(name, GetName()) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_local_path(caosdb_entity_entity *entity, char **out), + int linkahead_entity_entity_get_local_path(linkahead_entity_entity *entity, char **out), { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); auto path = wrapped_entity->GetLocalPath().string(); @@ -754,8 +754,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, // LINKAHEAD_ENTITY_GET(file_path, GetFilePath()) TODO(henrik) LINKAHEAD_ENTITY_GET(description, GetDescription()) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_datatype(caosdb_entity_entity *entity, - caosdb_entity_datatype *out), + int linkahead_entity_entity_get_datatype(linkahead_entity_entity *entity, + linkahead_entity_datatype *out), { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); out->wrapped_datatype = (void *)(&(wrapped_entity->GetDataType())); @@ -763,8 +763,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_value(caosdb_entity_entity *entity, - caosdb_entity_value *out), + int linkahead_entity_entity_get_value(linkahead_entity_entity *entity, + linkahead_entity_value *out), { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); out->wrapped_value = (void *)(&(wrapped_entity->GetValue())); @@ -776,7 +776,7 @@ LINKAHEAD_ENTITY_GET(unit, GetUnit()) LINKAHEAD_ENTITY_GET(version_id, GetVersionId()) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_errors_size(caosdb_entity_entity *entity, int *out), + int linkahead_entity_entity_get_errors_size(linkahead_entity_entity *entity, int *out), { auto *wrapped_entity = static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); @@ -785,8 +785,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_error(caosdb_entity_entity *entity, - caosdb_entity_message *out, int index), + int linkahead_entity_entity_get_error(linkahead_entity_entity *entity, + linkahead_entity_message *out, int index), { auto *wrapped_entity = static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); @@ -796,7 +796,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_warnings_size(caosdb_entity_entity *entity, + int linkahead_entity_entity_get_warnings_size(linkahead_entity_entity *entity, int *out), { auto *wrapped_entity = @@ -806,8 +806,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_warning(caosdb_entity_entity *entity, - caosdb_entity_message *out, int index), + int linkahead_entity_entity_get_warning(linkahead_entity_entity *entity, + linkahead_entity_message *out, int index), { auto *wrapped_entity = static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); @@ -817,7 +817,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_infos_size(caosdb_entity_entity *entity, int *out), { + int linkahead_entity_entity_get_infos_size(linkahead_entity_entity *entity, int *out), { auto *wrapped_entity = static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); *out = wrapped_entity->GetInfos().size(); @@ -825,8 +825,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_info(caosdb_entity_entity *entity, - caosdb_entity_message *out, int index), + int linkahead_entity_entity_get_info(linkahead_entity_entity *entity, + linkahead_entity_message *out, int index), { auto *wrapped_entity = static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); @@ -836,7 +836,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_properties_size(caosdb_entity_entity *entity, + int linkahead_entity_entity_get_properties_size(linkahead_entity_entity *entity, int *out), { auto *wrapped_entity = @@ -846,8 +846,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_property(caosdb_entity_entity *entity, - caosdb_entity_property *out, int index), + int linkahead_entity_entity_get_property(linkahead_entity_entity *entity, + linkahead_entity_property *out, int index), { auto *wrapped_entity = static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); @@ -857,7 +857,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_parents_size(caosdb_entity_entity *entity, int *out), + int linkahead_entity_entity_get_parents_size(linkahead_entity_entity *entity, int *out), { auto *wrapped_entity = static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); @@ -866,8 +866,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_parent(caosdb_entity_entity *entity, - caosdb_entity_parent *out, int index), + int linkahead_entity_entity_get_parent(linkahead_entity_entity *entity, + linkahead_entity_parent *out, int index), { auto *wrapped_entity = static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); @@ -885,7 +885,7 @@ LINKAHEAD_PROPERTY_GET(name, GetName()) LINKAHEAD_PROPERTY_GET(description, GetDescription()) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_property_get_importance(caosdb_entity_property *property, + int linkahead_entity_property_get_importance(linkahead_entity_property *property, char **out), { auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); @@ -898,8 +898,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_property_get_datatype(caosdb_entity_property *property, - caosdb_entity_datatype *out), + int linkahead_entity_property_get_datatype(linkahead_entity_property *property, + linkahead_entity_datatype *out), { auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); out->wrapped_datatype = (void *)(&(wrapped_property->GetDataType())); @@ -907,8 +907,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_property_get_value(caosdb_entity_property *property, - caosdb_entity_value *out), + int linkahead_entity_property_get_value(linkahead_entity_property *property, + linkahead_entity_value *out), { auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); out->wrapped_value = (void *)(&(wrapped_property->GetValue())); @@ -918,7 +918,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, LINKAHEAD_PROPERTY_GET(unit, GetUnit()) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_message_get_code(caosdb_entity_message *message, int *out), { + int linkahead_entity_message_get_code(linkahead_entity_message *message, int *out), { auto *wrapped_message = static_cast<linkahead::entity::Message *>(message->wrapped_message); *out = wrapped_message->GetCode(); @@ -927,7 +927,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_entity_message_get_description(caosdb_entity_message *message, char **out), { + int linkahead_entity_message_get_description(linkahead_entity_message *message, char **out), { auto *wrapped_message = static_cast<linkahead::entity::Message *>(message->wrapped_message); auto *tmp = (char *)malloc(sizeof(char) * wrapped_message->GetDescription().length() + 1); strcpy(tmp, wrapped_message->GetDescription().c_str()); @@ -937,7 +937,7 @@ ERROR_RETURN_CODE( }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_datatype_is_undefined(caosdb_entity_datatype *datatype, + int linkahead_entity_datatype_is_undefined(linkahead_entity_datatype *datatype, bool *out), { auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); @@ -945,14 +945,14 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_datatype_is_atomic(caosdb_entity_datatype *datatype, bool *out), + int linkahead_entity_datatype_is_atomic(linkahead_entity_datatype *datatype, bool *out), { auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); *out = wrapped_datatype->IsAtomic(); return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_datatype_is_reference(caosdb_entity_datatype *datatype, + int linkahead_entity_datatype_is_reference(linkahead_entity_datatype *datatype, bool *out), { auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); @@ -960,7 +960,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_datatype_is_list_of_atomic(caosdb_entity_datatype *datatype, + int linkahead_entity_datatype_is_list_of_atomic(linkahead_entity_datatype *datatype, bool *out), { auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); @@ -973,7 +973,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_datatype_is_list_of_reference(caosdb_entity_datatype *datatype, + int linkahead_entity_datatype_is_list_of_reference(linkahead_entity_datatype *datatype, bool *out), { auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); @@ -987,7 +987,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE( GENERIC_ERROR, - int caosdb_entity_datatype_get_datatype_name(caosdb_entity_datatype *datatype, char **out), { + int linkahead_entity_datatype_get_datatype_name(linkahead_entity_datatype *datatype, char **out), { auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); std::string datatype_name; if (wrapped_datatype->IsList()) { @@ -1019,7 +1019,7 @@ VALUE_IS(bool, IsBool) VALUE_IS(vector, IsVector) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_value_get_as_string(caosdb_entity_value *value, char **out), { + int linkahead_entity_value_get_as_string(linkahead_entity_value *value, char **out), { auto *wrapped_value = WRAPPED_VALUE_CAST(value); auto *tmp = (char *)malloc(sizeof(char) * wrapped_value->GetAsString().length() + 1); @@ -1033,8 +1033,8 @@ VALUE_GET_AS(integer, GetAsInt64, int64_t *out) VALUE_GET_AS(bool, GetAsBool, bool *out) VALUE_GET_AS(vector_size, GetAsVector().size, int *out) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_value_get_as_vector_at(caosdb_entity_value *value, - caosdb_entity_value *out, + int linkahead_entity_value_get_as_vector_at(linkahead_entity_value *value, + linkahead_entity_value *out, const int index), { auto *wrapped_value = WRAPPED_VALUE_CAST(value); @@ -1043,7 +1043,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_set_role(caosdb_entity_entity *entity, const char *role), + int linkahead_entity_entity_set_role(linkahead_entity_entity *entity, const char *role), { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); try { @@ -1051,7 +1051,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, wrapped_entity->SetRole(enum_value); return 0; } catch (const std::out_of_range &exc) { - linkahead::logging::caosdb_log_fatal(CLINKAHEAD_LOGGER_NAME, exc.what()); + linkahead::logging::linkahead_log_fatal(CLINKAHEAD_LOGGER_NAME, exc.what()); return linkahead::StatusCode::ENUM_MAPPING_ERROR; } }) @@ -1063,8 +1063,8 @@ LINKAHEAD_ENTITY_SET(description, description, wrapped_entity->SetDescription(std::string(description));) LINKAHEAD_ENTITY_SET(unit, unit, wrapped_entity->SetUnit(std::string(unit));) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_set_datatype(caosdb_entity_entity *entity, - caosdb_entity_datatype *datatype), + int linkahead_entity_entity_set_datatype(linkahead_entity_entity *entity, + linkahead_entity_datatype *datatype), { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); @@ -1072,8 +1072,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return wrapped_entity->SetDataType(*wrapped_datatype); }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_set_value(caosdb_entity_entity *entity, - caosdb_entity_value *value), + int linkahead_entity_entity_set_value(linkahead_entity_entity *entity, + linkahead_entity_value *value), { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); auto *wrapped_value = WRAPPED_VALUE_CAST(value); @@ -1082,8 +1082,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_append_parent(caosdb_entity_entity *entity, - caosdb_entity_parent *parent), + int linkahead_entity_entity_append_parent(linkahead_entity_entity *entity, + linkahead_entity_parent *parent), { auto *wrapped_entity = static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); @@ -1094,7 +1094,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_remove_parent(caosdb_entity_entity *entity, int index), { + int linkahead_entity_entity_remove_parent(linkahead_entity_entity *entity, int index), { auto *wrapped_entity = static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); wrapped_entity->RemoveParent(index); @@ -1102,8 +1102,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_append_property(caosdb_entity_entity *entity, - caosdb_entity_property *property), + int linkahead_entity_entity_append_property(linkahead_entity_entity *entity, + linkahead_entity_property *property), { auto *wrapped_entity = static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); @@ -1113,7 +1113,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_remove_property(caosdb_entity_entity *entity, int index), + int linkahead_entity_entity_remove_property(linkahead_entity_entity *entity, int index), { auto *wrapped_entity = static_cast<linkahead::entity::Entity *>(entity->wrapped_entity); @@ -1127,8 +1127,8 @@ LINKAHEAD_PARENT_SET(name, name, wrapped_parent->SetName(std::string(name));) LINKAHEAD_PROPERTY_SET(name, name, wrapped_property->SetName(std::string(name));) LINKAHEAD_PROPERTY_SET(id, id, wrapped_property->SetId(std::string(id));) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_property_set_datatype(caosdb_entity_property *property, - caosdb_entity_datatype *datatype), + int linkahead_entity_property_set_datatype(linkahead_entity_property *property, + linkahead_entity_datatype *datatype), { auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); @@ -1136,8 +1136,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return wrapped_property->SetDataType(*wrapped_datatype); }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_property_set_value(caosdb_entity_property *property, - caosdb_entity_value *value), + int linkahead_entity_property_set_value(linkahead_entity_property *property, + linkahead_entity_value *value), { auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); auto *wrapped_value = WRAPPED_VALUE_CAST(value); @@ -1146,7 +1146,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_property_set_importance(caosdb_entity_property *property, + int linkahead_entity_property_set_importance(linkahead_entity_property *property, const char *importance), { auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); @@ -1155,7 +1155,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, wrapped_property->SetImportance(enum_value); return 0; } catch (const std::out_of_range &exc) { - linkahead::logging::caosdb_log_fatal(CLINKAHEAD_LOGGER_NAME, exc.what()); + linkahead::logging::linkahead_log_fatal(CLINKAHEAD_LOGGER_NAME, exc.what()); return linkahead::StatusCode::ENUM_MAPPING_ERROR; } }) diff --git a/src/clinkaheadcli.c b/src/clinkaheadcli.c index dc0d657f6a15cf80738b2c53aeb4acab92e0fd11..2f6ba7f551a2151344c59f9dea074addedebc2e5 100644 --- a/src/clinkaheadcli.c +++ b/src/clinkaheadcli.c @@ -1,5 +1,5 @@ #include "linkahead/constants.h" // for LIBLINKAHEAD_VERSION_MAJOR, LIBLINKAHEAD_VER... -#include "clinkahead.h" // for caosdb_info_version_info, caosdb_conne... +#include "clinkahead.h" // for linkahead_info_version_info, linkahead_conne... #include <stdio.h> // for printf int main(void) { @@ -7,17 +7,17 @@ int main(void) { printf("CaosDB C client (libcaosdb %d.%d.%d)\nWe don't miss the H of caos.\n\n", LIBLINKAHEAD_VERSION_MAJOR, LIBLINKAHEAD_VERSION_MINOR, LIBLINKAHEAD_VERSION_PATCH); - caosdb_connection_connection connection; - status = caosdb_connection_connection_manager_get_default_connection(&connection); + linkahead_connection_connection connection; + status = linkahead_connection_connection_manager_get_default_connection(&connection); if (status != 0) { - printf("An error occured: ERROR %d - %s\n", status, caosdb_get_status_description(status)); + printf("An error occured: ERROR %d - %s\n", status, linkahead_get_status_description(status)); return status; } - caosdb_info_version_info version_info; - status = caosdb_connection_get_version_info(&version_info, &connection); + linkahead_info_version_info version_info; + status = linkahead_connection_get_version_info(&version_info, &connection); if (status != 0) { - printf("An error occured: ERROR %d - %s\n", status, caosdb_get_status_description(status)); + printf("An error occured: ERROR %d - %s\n", status, linkahead_get_status_description(status)); return status; } diff --git a/src/linkahead/logging.cpp b/src/linkahead/logging.cpp index 7490529b59a1c1b20d1e63f6056f6256c5299371..642f2ae75c26c901704818ac633e419817c58cc7 100644 --- a/src/linkahead/logging.cpp +++ b/src/linkahead/logging.cpp @@ -242,27 +242,27 @@ auto initialize_logging(const LoggingConfiguration &configuration) -> void { LINKAHEAD_LOG_DEBUG(logger_name) << "Initialized logging with custom settings."; } -void caosdb_log_fatal(const char *channel, const char *msg) { +void linkahead_log_fatal(const char *channel, const char *msg) { LoggerOutputStream::get(channel, LINKAHEAD_LOG_LEVEL_FATAL) << msg; } -void caosdb_log_error(const char *channel, const char *msg) { +void linkahead_log_error(const char *channel, const char *msg) { LoggerOutputStream::get(channel, LINKAHEAD_LOG_LEVEL_ERROR) << msg; } -void caosdb_log_warn(const char *channel, const char *msg) { +void linkahead_log_warn(const char *channel, const char *msg) { LoggerOutputStream::get(channel, LINKAHEAD_LOG_LEVEL_WARN) << msg; } -void caosdb_log_info(const char *channel, const char *msg) { +void linkahead_log_info(const char *channel, const char *msg) { LoggerOutputStream::get(channel, LINKAHEAD_LOG_LEVEL_INFO) << msg; } -void caosdb_log_debug(const char *channel, const char *msg) { +void linkahead_log_debug(const char *channel, const char *msg) { LoggerOutputStream::get(channel, LINKAHEAD_LOG_LEVEL_DEBUG) << msg; } -void caosdb_log_trace(const char *channel, const char *msg) { +void linkahead_log_trace(const char *channel, const char *msg) { LoggerOutputStream::get(channel, LINKAHEAD_LOG_LEVEL_TRACE) << msg; } diff --git a/test/test_ccaosdb.cpp b/test/test_ccaosdb.cpp deleted file mode 100644 index 1eb844c43e910eb5ef16e1a45b384bfda3dfce0e..0000000000000000000000000000000000000000 --- a/test/test_ccaosdb.cpp +++ /dev/null @@ -1,1011 +0,0 @@ -/* - * - * This file is a part of the LinkAhead Project. - * - * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> - * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <https://www.gnu.org/licenses/>. - * - */ - -#include "linkahead/configuration.h" -#include "linkahead/status_code.h" // for StatusCode -#include "linkahead_test_utility.h" // for EXPECT_THROW_MESSAGE, TEST_DATA_DIR -#include "clinkahead.h" // for caosdb_utility_get_env_fallback -#include <cstdint> // for int64_t -#include <cstring> // for strcmp -#include <gtest/gtest.h> -#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, operator+, string,... - -class test_ccaosdb : public ::testing::Test { -protected: - void SetUp() override { - linkahead::configuration::ConfigurationManager::Clear(); - linkahead::configuration::ConfigurationManager::LoadSingleJSONConfiguration( - TEST_DATA_DIR + "/test_caosdb_client.json"); - } - - void TearDown() override { linkahead::configuration::ConfigurationManager::Clear(); } -}; - -TEST_F(test_ccaosdb, test_get_env_fallback) { - const char *const some_var = caosdb_utility_get_env_fallback("SOME_ENV_VAR", "fall-back"); - EXPECT_EQ("fall-back", some_var); -} - -TEST_F(test_ccaosdb, test_other_client_error) { - EXPECT_EQ(caosdb_status_code_OTHER_CLIENT_ERROR(), linkahead::StatusCode::OTHER_CLIENT_ERROR); -} - -TEST_F(test_ccaosdb, test_get_default_connection) { - caosdb_connection_connection out; - - caosdb_connection_connection_manager_get_default_connection(&out); - EXPECT_TRUE(out.wrapped_connection); -} - -TEST_F(test_ccaosdb, test_get_connection) { - caosdb_connection_connection out; - - caosdb_connection_connection_manager_get_connection(&out, "local-caosdb-admin"); - EXPECT_TRUE(out.wrapped_connection); -} - -TEST_F(test_ccaosdb, test_execute_transaction) { - caosdb_connection_connection connection; - caosdb_connection_connection_manager_get_connection(&connection, "local-caosdb-admin"); - - caosdb_transaction_transaction transaction; - caosdb_connection_connection_create_transaction(&connection, &transaction); - - EXPECT_TRUE(transaction.wrapped_transaction); - - int return_code(caosdb_transaction_transaction_retrieve_by_id(&transaction, "some_id")); - EXPECT_EQ(return_code, linkahead::StatusCode::GO_ON); - - return_code = caosdb_transaction_transaction_execute(&transaction); - EXPECT_EQ(return_code, linkahead::StatusCode::CONNECTION_ERROR); - - return_code = caosdb_transaction_delete_transaction(&transaction); - EXPECT_EQ(return_code, 0); - - 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 - return_code = caosdb_transaction_transaction_retrieve_by_ids(&multi_transaction, ids, 3); - EXPECT_EQ(return_code, linkahead::StatusCode::GO_ON); - - return_code = caosdb_transaction_delete_transaction(&multi_transaction); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_multi_retrieve) { - caosdb_connection_connection connection; - caosdb_connection_connection_manager_get_connection(&connection, "local-caosdb-admin"); - - 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 - int return_code(caosdb_transaction_transaction_retrieve_by_ids(&multi_transaction, ids, 3)); - EXPECT_EQ(return_code, linkahead::StatusCode::GO_ON); - - return_code = caosdb_transaction_delete_transaction(&multi_transaction); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_query) { - caosdb_connection_connection connection; - caosdb_connection_connection_manager_get_connection(&connection, "local-caosdb-admin"); - - caosdb_transaction_transaction transaction; - caosdb_connection_connection_create_transaction(&connection, &transaction); - - int return_code(caosdb_transaction_transaction_query(&transaction, "FIND ENTITY WITH id=123")); - EXPECT_EQ(return_code, linkahead::StatusCode::GO_ON); - - return_code = caosdb_transaction_delete_transaction(&transaction); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_datatype) { - - caosdb_entity_datatype atomic; - // check that this fails - int return_code(caosdb_entity_create_atomic_datatype(&atomic, "some type")); - EXPECT_EQ(return_code, linkahead::StatusCode::ENUM_MAPPING_ERROR); - - return_code = caosdb_entity_create_atomic_datatype(&atomic, "INTEGER"); - EXPECT_EQ(return_code, 0); - - caosdb_entity_datatype reference; - return_code = caosdb_entity_create_reference_datatype(&reference, "MyType"); - EXPECT_EQ(return_code, 0); - - caosdb_entity_datatype list_of_atomics; - return_code = caosdb_entity_create_atomic_list_datatype(&list_of_atomics, "DATETIME"); - EXPECT_EQ(return_code, 0); - - caosdb_entity_datatype list_of_references; - return_code = caosdb_entity_create_reference_list_datatype(&list_of_references, "MyType"); - EXPECT_EQ(return_code, 0); - - bool is_a(false); - return_code = caosdb_entity_datatype_is_undefined(&atomic, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_atomic(&atomic, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_TRUE(is_a); - return_code = caosdb_entity_datatype_is_reference(&atomic, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_atomic(&atomic, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_reference(&atomic, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - - return_code = caosdb_entity_datatype_is_atomic(&reference, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_reference(&reference, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_TRUE(is_a); - return_code = caosdb_entity_datatype_is_list_of_atomic(&reference, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_reference(&reference, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - - return_code = caosdb_entity_datatype_is_atomic(&list_of_atomics, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_reference(&list_of_atomics, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_atomic(&list_of_atomics, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_TRUE(is_a); - return_code = caosdb_entity_datatype_is_list_of_reference(&list_of_atomics, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - - return_code = caosdb_entity_datatype_is_atomic(&list_of_references, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_reference(&list_of_references, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_atomic(&list_of_references, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_reference(&list_of_references, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_TRUE(is_a); - - char *name = nullptr; // NOLINT - return_code = caosdb_entity_datatype_get_datatype_name(&atomic, &name); - EXPECT_EQ(return_code, 0); - EXPECT_STREQ(name, "INTEGER"); - - return_code = caosdb_entity_datatype_get_datatype_name(&reference, &name); - EXPECT_EQ(return_code, 0); - EXPECT_STREQ(name, "MyType"); - - return_code = caosdb_entity_datatype_get_datatype_name(&list_of_atomics, &name); - EXPECT_EQ(return_code, 0); - EXPECT_STREQ(name, "DATETIME"); - - return_code = caosdb_entity_datatype_get_datatype_name(&list_of_references, &name); - EXPECT_EQ(return_code, 0); - EXPECT_STREQ(name, "MyType"); - - return_code = caosdb_entity_delete_datatype(&atomic); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_datatype(&reference); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_datatype(&list_of_atomics); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_datatype(&list_of_references); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_value) { - - caosdb_entity_value string_value; - int return_code(caosdb_entity_create_string_value(&string_value, "value")); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value int_value; - return_code = caosdb_entity_create_int_value(&int_value, 27); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value bool_value; - return_code = caosdb_entity_create_bool_value(&bool_value, true); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value double_value; - return_code = caosdb_entity_create_double_value(&double_value, 2.7); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value string_vector_value; - const char *string_values[] = {"a", "b", "c"}; // NOLINT - return_code = caosdb_entity_create_string_vector_value(&string_vector_value, string_values, 3); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value int_vector_value; - const int64_t int_values[] = {1, 2, 3}; // NOLINT - return_code = caosdb_entity_create_int_vector_value(&int_vector_value, int_values, 3); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value double_vector_value; - const double double_values[] = {1.1, 2.2, 3.3}; // NOLINT - return_code = caosdb_entity_create_double_vector_value(&double_vector_value, double_values, 3); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value bool_vector_value; - const bool bool_values[] = {true, false, false}; // NOLINT - return_code = caosdb_entity_create_bool_vector_value(&bool_vector_value, bool_values, 3); - EXPECT_EQ(return_code, 0); - - // One thorough check, afterwards only the ones that should be true - bool is_a(false); - return_code = caosdb_entity_value_is_null(&string_value, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_value_is_string(&string_value, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_TRUE(is_a); - return_code = caosdb_entity_value_is_double(&string_value, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_value_is_integer(&string_value, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_value_is_bool(&string_value, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_value_is_vector(&string_value, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - - caosdb_entity_value_is_integer(&int_value, &is_a); - EXPECT_TRUE(is_a); - - caosdb_entity_value_is_bool(&bool_value, &is_a); - EXPECT_TRUE(is_a); - - caosdb_entity_value_is_double(&double_value, &is_a); - EXPECT_TRUE(is_a); - - caosdb_entity_value_is_vector(&string_vector_value, &is_a); - EXPECT_TRUE(is_a); - - caosdb_entity_value_is_vector(&int_vector_value, &is_a); - EXPECT_TRUE(is_a); - - caosdb_entity_value_is_vector(&double_vector_value, &is_a); - EXPECT_TRUE(is_a); - - caosdb_entity_value_is_vector(&bool_vector_value, &is_a); - EXPECT_TRUE(is_a); - - char *out_string = nullptr; // NOLINT - return_code = caosdb_entity_value_get_as_string(&string_value, &out_string); - EXPECT_EQ(return_code, 0); - EXPECT_STREQ(out_string, "value"); - - int64_t out_int(0); - return_code = caosdb_entity_value_get_as_integer(&int_value, &out_int); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(out_int, 27); - - bool out_bool(false); - return_code = caosdb_entity_value_get_as_bool(&bool_value, &out_bool); - EXPECT_EQ(return_code, 0); - EXPECT_TRUE(out_bool); - - double out_double(0); - return_code = caosdb_entity_value_get_as_double(&double_value, &out_double); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(out_double, 2.7); - - int list_length(0); - return_code = caosdb_entity_value_get_as_vector_size(&string_vector_value, &list_length); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(list_length, 3); - return_code = caosdb_entity_value_get_as_vector_size(&int_vector_value, &list_length); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(list_length, 3); - return_code = caosdb_entity_value_get_as_vector_size(&double_vector_value, &list_length); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(list_length, 3); - return_code = caosdb_entity_value_get_as_vector_size(&bool_vector_value, &list_length); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(list_length, 3); - - // Only check for one, rest should be covered by this + scalar values - caosdb_entity_value out_val; - return_code = caosdb_entity_value_get_as_vector_at(&string_vector_value, &out_val, 0); - EXPECT_EQ(return_code, 0); - caosdb_entity_value_get_as_string(&out_val, &out_string); - EXPECT_STREQ(out_string, "a"); - return_code = caosdb_entity_value_get_as_vector_at(&string_vector_value, &out_val, 1); - EXPECT_EQ(return_code, 0); - caosdb_entity_value_get_as_string(&out_val, &out_string); - EXPECT_STREQ(out_string, "b"); - return_code = caosdb_entity_value_get_as_vector_at(&string_vector_value, &out_val, 2); - EXPECT_EQ(return_code, 0); - caosdb_entity_value_get_as_string(&out_val, &out_string); - EXPECT_STREQ(out_string, "c"); - - return_code = caosdb_entity_delete_value(&string_value); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&int_value); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&bool_value); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&double_value); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&string_vector_value); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&int_vector_value); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&double_vector_value); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&bool_vector_value); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_entity) { - caosdb_entity_entity entity; - - int return_code(caosdb_entity_create_entity(&entity)); - EXPECT_EQ(return_code, 0); - - // cannot be created again without deletion - // return_code = caosdb_entity_create_entity(&entity); - // EXPECT_EQ(return_code, linkahead::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 - // the strings for the rest - return_code = caosdb_entity_entity_set_name(&entity, "length"); - EXPECT_EQ(return_code, 0); - char *out = nullptr; // NOLINT - return_code = caosdb_entity_entity_get_name(&entity, &out); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(strcmp(out, "length"), 0); - - // test call without validation of result - return_code = caosdb_entity_entity_set_role(&entity, "FILE"); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_entity_set_local_path( - &entity, (TEST_DATA_DIR + "/test_caosdb_client.json").c_str()); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_entity_get_local_path(&entity, &out); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(strcmp(out, (TEST_DATA_DIR + "/test_caosdb_client.json").c_str()), 0); - - // invalid role - return_code = caosdb_entity_entity_set_role(&entity, "Role does not exist"); - EXPECT_EQ(return_code, linkahead::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); - EXPECT_EQ(strcmp(out, "The length of an object"), 0); - - caosdb_entity_datatype in_type; - caosdb_entity_create_atomic_datatype(&in_type, "DOUBLE"); - caosdb_entity_entity_set_datatype(&entity, &in_type); - - // verify that this doesn't work ... - // return_code = caosdb_entity_entity_get_datatype(&entity, &in_type); - // EXPECT_EQ(return_code, linkahead::StatusCode::EXTERN_C_ASSIGNMENT_ERROR); - caosdb_entity_datatype out_type; - // ... but does with a clean property - return_code = caosdb_entity_entity_get_datatype(&entity, &out_type); - EXPECT_EQ(return_code, 0); - bool is_a(false); - return_code = caosdb_entity_datatype_is_atomic(&out_type, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_TRUE(is_a); - return_code = caosdb_entity_datatype_is_reference(&out_type, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_atomic(&out_type, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_reference(&out_type, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - - caosdb_entity_datatype_get_datatype_name(&out_type, &out); - EXPECT_STREQ(out, "DOUBLE"); - - caosdb_entity_value in_value; - return_code = caosdb_entity_create_double_value(&in_value, 5.0); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_entity_set_value(&entity, &in_value); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value out_value; - return_code = caosdb_entity_entity_get_value(&entity, &out_value); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value_is_double(&out_value, &is_a); - EXPECT_TRUE(is_a); - caosdb_entity_value_is_null(&out_value, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_value_is_string(&out_value, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_value_is_bool(&out_value, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_value_is_integer(&out_value, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_value_is_vector(&out_value, &is_a); - EXPECT_FALSE(is_a); - - double out_double(0); - caosdb_entity_value_get_as_double(&out_value, &out_double); - EXPECT_EQ(out_double, 5.0); - - // clear to re-use - return_code = caosdb_entity_delete_datatype(&in_type); - EXPECT_EQ(return_code, 0); - caosdb_entity_create_reference_list_datatype(&in_type, "Person"); - caosdb_entity_entity_set_datatype(&entity, &in_type); - - // works without clearing since datatype is managed by the owning entity - caosdb_entity_entity_get_datatype(&entity, &out_type); - return_code = caosdb_entity_datatype_is_atomic(&out_type, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_reference(&out_type, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_atomic(&out_type, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_FALSE(is_a); - return_code = caosdb_entity_datatype_is_list_of_reference(&out_type, &is_a); - EXPECT_EQ(return_code, 0); - EXPECT_TRUE(is_a); - - caosdb_entity_datatype_get_datatype_name(&out_type, &out); - EXPECT_STREQ(out, "Person"); - - caosdb_entity_entity_set_unit(&entity, "m"); - caosdb_entity_entity_get_unit(&entity, &out); - EXPECT_EQ(strcmp(out, "m"), 0); - - return_code = caosdb_entity_delete_entity(&entity); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_datatype(&in_type); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&in_value); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_parent) { - caosdb_entity_parent parent; - - int return_code(caosdb_entity_create_parent(&parent)); - EXPECT_EQ(return_code, 0); - - caosdb_entity_parent_set_id(&parent, "some_id"); - caosdb_entity_parent_set_name(&parent, "some_name"); - - 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); - EXPECT_EQ(strcmp(out, "some_name"), 0); - - return_code = caosdb_entity_delete_parent(&parent); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_property) { - caosdb_entity_property property; - - int return_code(caosdb_entity_create_property(&property)); - EXPECT_EQ(return_code, 0); - - caosdb_entity_property_set_id(&property, "some_id"); - caosdb_entity_property_set_name(&property, "some_name"); - - caosdb_entity_datatype in_type; - caosdb_entity_create_atomic_datatype(&in_type, "TEXT"); - caosdb_entity_property_set_datatype(&property, &in_type); - caosdb_entity_property_set_importance(&property, "FIX"); - caosdb_entity_property_set_unit(&property, "some_unit"); - caosdb_entity_value in_value; - caosdb_entity_create_string_value(&in_value, "some_value"); - caosdb_entity_property_set_value(&property, &in_value); - - 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); - EXPECT_EQ(strcmp(out, "some_name"), 0); - - caosdb_entity_datatype out_type; - return_code = caosdb_entity_property_get_datatype(&property, &out_type); - EXPECT_EQ(return_code, 0); - bool is_a(false); - - caosdb_entity_datatype_is_atomic(&out_type, &is_a); - EXPECT_TRUE(is_a); - caosdb_entity_datatype_is_reference(&out_type, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_datatype_is_list_of_atomic(&out_type, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_datatype_is_list_of_reference(&out_type, &is_a); - EXPECT_FALSE(is_a); - - caosdb_entity_datatype_get_datatype_name(&out_type, &out); - EXPECT_STREQ(out, "TEXT"); - - caosdb_entity_property_get_importance(&property, &out); - EXPECT_EQ(strcmp(out, "FIX"), 0); - - caosdb_entity_property_get_unit(&property, &out); - EXPECT_EQ(strcmp(out, "some_unit"), 0); - - caosdb_entity_value out_value; - return_code = caosdb_entity_property_get_value(&property, &out_value); - EXPECT_EQ(return_code, 0); - caosdb_entity_value_is_string(&out_value, &is_a); - EXPECT_TRUE(is_a); - caosdb_entity_value_get_as_string(&out_value, &out); - EXPECT_STREQ(out, "some_value"); - - return_code = caosdb_entity_delete_property(&property); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_datatype(&in_type); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&in_value); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_string_list_property) { - - caosdb_entity_property property; - int return_code(caosdb_entity_create_property(&property)); - EXPECT_EQ(return_code, 0); - - caosdb_entity_datatype in_type; - return_code = caosdb_entity_create_atomic_list_datatype(&in_type, "TEXT"); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_property_set_datatype(&property, &in_type); - EXPECT_EQ(return_code, 0); - - caosdb_entity_value in_value; - const char *value_list[] = {"val0", "val1", "val2"}; // NOLINT - return_code = caosdb_entity_create_string_vector_value(&in_value, value_list, 3); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_property_set_value(&property, &in_value); - EXPECT_EQ(return_code, 0); - - caosdb_entity_datatype out_type; - return_code = caosdb_entity_property_get_datatype(&property, &out_type); - EXPECT_EQ(return_code, 0); - - bool is_a(false); - caosdb_entity_datatype_is_atomic(&out_type, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_datatype_is_reference(&out_type, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_datatype_is_list_of_atomic(&out_type, &is_a); - EXPECT_TRUE(is_a); - caosdb_entity_datatype_is_list_of_reference(&out_type, &is_a); - EXPECT_FALSE(is_a); - char *out = nullptr; // NOLINT - caosdb_entity_datatype_get_datatype_name(&out_type, &out); - EXPECT_STREQ(out, "TEXT"); - - caosdb_entity_value out_value; - caosdb_entity_property_get_value(&property, &out_value); - caosdb_entity_value_is_vector(&out_value, &is_a); - EXPECT_TRUE(is_a); - int length(-1); - caosdb_entity_value_get_as_vector_size(&out_value, &length); - EXPECT_EQ(length, 3); - - caosdb_entity_value list_elt; - for (int i = 0; i < length; i++) { - return_code = caosdb_entity_value_get_as_vector_at(&out_value, &list_elt, i); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_value_get_as_string(&list_elt, &out); - EXPECT_EQ(return_code, 0); - EXPECT_STREQ(value_list[i], out); // NOLINT - } - - return_code = caosdb_entity_delete_property(&property); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_datatype(&in_type); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&in_value); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_int_list_property) { - - caosdb_entity_property property; - int return_code(caosdb_entity_create_property(&property)); - EXPECT_EQ(return_code, 0); - - caosdb_entity_datatype in_type; - caosdb_entity_create_atomic_list_datatype(&in_type, "INTEGER"); - return_code = caosdb_entity_property_set_datatype(&property, &in_type); - EXPECT_EQ(return_code, 0); - - const int64_t value_list[] = {1, 2, 3}; // NOLINT - caosdb_entity_value in_value; - caosdb_entity_create_int_vector_value(&in_value, value_list, 3); - return_code = caosdb_entity_property_set_value(&property, &in_value); - EXPECT_EQ(return_code, 0); - - caosdb_entity_datatype out_type; - return_code = caosdb_entity_property_get_datatype(&property, &out_type); - EXPECT_EQ(return_code, 0); - - bool is_a(false); - caosdb_entity_datatype_is_atomic(&out_type, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_datatype_is_reference(&out_type, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_datatype_is_list_of_atomic(&out_type, &is_a); - EXPECT_TRUE(is_a); - caosdb_entity_datatype_is_list_of_reference(&out_type, &is_a); - EXPECT_FALSE(is_a); - char *out = nullptr; // NOLINT - caosdb_entity_datatype_get_datatype_name(&out_type, &out); - EXPECT_STREQ(out, "INTEGER"); - - caosdb_entity_value out_value; - caosdb_entity_property_get_value(&property, &out_value); - caosdb_entity_value_is_vector(&out_value, &is_a); - EXPECT_TRUE(is_a); - int length(-1); - caosdb_entity_value_get_as_vector_size(&out_value, &length); - EXPECT_EQ(length, 3); - - int64_t out_int = -1; - caosdb_entity_value list_elt; - for (int i = 0; i < length; i++) { - return_code = caosdb_entity_value_get_as_vector_at(&out_value, &list_elt, i); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_value_get_as_integer(&list_elt, &out_int); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(value_list[i], out_int); // NOLINT - } - - return_code = caosdb_entity_delete_property(&property); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_datatype(&in_type); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&in_value); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_bool_list_property) { - - caosdb_entity_property property; - int return_code(caosdb_entity_create_property(&property)); - EXPECT_EQ(return_code, 0); - - caosdb_entity_datatype in_type; - caosdb_entity_create_atomic_list_datatype(&in_type, "BOOLEAN"); - return_code = caosdb_entity_property_set_datatype(&property, &in_type); - EXPECT_EQ(return_code, 0); - - const bool value_list[] = {true, true, false}; // NOLINT - caosdb_entity_value in_value; - caosdb_entity_create_bool_vector_value(&in_value, value_list, 3); - return_code = caosdb_entity_property_set_value(&property, &in_value); - EXPECT_EQ(return_code, 0); - - caosdb_entity_datatype out_type; - return_code = caosdb_entity_property_get_datatype(&property, &out_type); - EXPECT_EQ(return_code, 0); - - bool is_a(false); - caosdb_entity_datatype_is_atomic(&out_type, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_datatype_is_reference(&out_type, &is_a); - EXPECT_FALSE(is_a); - caosdb_entity_datatype_is_list_of_atomic(&out_type, &is_a); - EXPECT_TRUE(is_a); - caosdb_entity_datatype_is_list_of_reference(&out_type, &is_a); - EXPECT_FALSE(is_a); - char *out = nullptr; // NOLINT - caosdb_entity_datatype_get_datatype_name(&out_type, &out); - EXPECT_STREQ(out, "BOOLEAN"); - - caosdb_entity_value out_value; - caosdb_entity_property_get_value(&property, &out_value); - caosdb_entity_value_is_vector(&out_value, &is_a); - EXPECT_TRUE(is_a); - int length(-1); - caosdb_entity_value_get_as_vector_size(&out_value, &length); - EXPECT_EQ(length, 3); - - bool out_bool(false); - caosdb_entity_value list_elt; - for (int i = 0; i < length; i++) { - return_code = caosdb_entity_value_get_as_vector_at(&out_value, &list_elt, i); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_value_get_as_bool(&list_elt, &out_bool); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(value_list[i], out_bool); // NOLINT - } - - return_code = caosdb_entity_delete_property(&property); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_datatype(&in_type); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&in_value); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_entity_with_parent_and_property) { - caosdb_entity_parent input_parent; - int return_code(caosdb_entity_create_parent(&input_parent)); - EXPECT_EQ(return_code, 0); - - caosdb_entity_parent_set_id(&input_parent, "parent_id"); - caosdb_entity_parent_set_name(&input_parent, "parent_name"); - - caosdb_entity_property input_property; - return_code = caosdb_entity_create_property(&input_property); - EXPECT_EQ(return_code, 0); - - caosdb_entity_property_set_id(&input_property, "property_id"); - caosdb_entity_property_set_name(&input_property, "property_name"); - - caosdb_entity_datatype in_type; - caosdb_entity_create_atomic_datatype(&in_type, "TEXT"); - caosdb_entity_value in_value; - caosdb_entity_create_string_value(&in_value, "property_value"); - caosdb_entity_property_set_datatype(&input_property, &in_type); - caosdb_entity_property_set_value(&input_property, &in_value); - - caosdb_entity_entity entity; - return_code = caosdb_entity_create_entity(&entity); - EXPECT_EQ(return_code, 0); - - 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); - - int count[] = {0}; // NOLINT - return_code = caosdb_entity_entity_get_parents_size(&entity, count); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(*count, 1); - - return_code = caosdb_entity_entity_get_properties_size(&entity, count); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(*count, 1); - - char *in = nullptr; // NOLINT - char *out = nullptr; // NOLINT - - // cannot assign an already assigned property - // return_code = caosdb_entity_entity_get_property(&entity, &input_property, 0); - // EXPECT_EQ(return_code, linkahead::StatusCode::EXTERN_C_ASSIGNMENT_ERROR); - caosdb_entity_property output_property; - return_code = caosdb_entity_entity_get_property(&entity, &output_property, 0); - EXPECT_EQ(return_code, 0); - - 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); - EXPECT_EQ(strcmp(in, out), 0); - - caosdb_entity_datatype out_type; - caosdb_entity_property_get_datatype(&output_property, &out_type); - - bool in_is(false); - bool out_is(false); - caosdb_entity_datatype_is_atomic(&in_type, &in_is); - caosdb_entity_datatype_is_atomic(&out_type, &out_is); - EXPECT_EQ(in_is, out_is); - caosdb_entity_datatype_is_reference(&in_type, &in_is); - caosdb_entity_datatype_is_reference(&out_type, &out_is); - EXPECT_EQ(in_is, out_is); - caosdb_entity_datatype_is_list_of_atomic(&in_type, &in_is); - caosdb_entity_datatype_is_list_of_atomic(&out_type, &out_is); - EXPECT_EQ(in_is, out_is); - caosdb_entity_datatype_is_list_of_reference(&in_type, &in_is); - caosdb_entity_datatype_is_list_of_reference(&out_type, &out_is); - EXPECT_EQ(in_is, out_is); - - caosdb_entity_datatype_get_datatype_name(&in_type, &in); - caosdb_entity_datatype_get_datatype_name(&out_type, &out); - EXPECT_STREQ(in, out); - - caosdb_entity_value out_value; - caosdb_entity_property_get_value(&output_property, &out_value); - caosdb_entity_value_is_string(&in_value, &in_is); - EXPECT_TRUE(in_is); - caosdb_entity_value_is_string(&out_value, &out_is); - EXPECT_TRUE(out_is); - caosdb_entity_value_get_as_string(&in_value, &in); - caosdb_entity_value_get_as_string(&out_value, &out); - EXPECT_STREQ(in, out); - - caosdb_entity_parent output_parent; - return_code = caosdb_entity_entity_get_parent(&entity, &output_parent, 0); - EXPECT_EQ(return_code, 0); - - 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); - EXPECT_EQ(strcmp(in, out), 0); - - // Delete everything - return_code = caosdb_entity_delete_parent(&input_parent); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_property(&input_property); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_entity(&entity); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_datatype(&in_type); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_value(&in_value); - EXPECT_EQ(return_code, 0); - - // This tests the `_deletable` flag. The wrapped cpp objects of - // `output_parent` and `output_property` are owned by the entity, so - // they have been deleted together with the entity. With a wrong - // `_deletable` flag, the following would cause segfaults. - // - return_code = caosdb_entity_delete_parent(&output_parent); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_delete_property(&output_property); - EXPECT_EQ(return_code, 0); -} - -TEST_F(test_ccaosdb, test_remove_property) { - caosdb_entity_entity entity; - int return_code(caosdb_entity_create_entity(&entity)); - EXPECT_EQ(return_code, 0); - - // Create two properties with names - caosdb_entity_property in_prop_1; - return_code = caosdb_entity_create_property(&in_prop_1); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_property_set_name(&in_prop_1, "Property 1"); - EXPECT_EQ(return_code, 0); - - caosdb_entity_property in_prop_2; - return_code = caosdb_entity_create_property(&in_prop_2); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_property_set_name(&in_prop_2, "Property 2"); - EXPECT_EQ(return_code, 0); - - // Append them - return_code = caosdb_entity_entity_append_property(&entity, &in_prop_1); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_entity_append_property(&entity, &in_prop_2); - EXPECT_EQ(return_code, 0); - - // Delete one and see that the number of properties decreases by one - int count[] = {0}; // NOLINT - return_code = caosdb_entity_entity_get_properties_size(&entity, count); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(*count, 2); - - return_code = caosdb_entity_entity_remove_property(&entity, 0); - EXPECT_EQ(return_code, 0); - - return_code = caosdb_entity_entity_get_properties_size(&entity, count); - EXPECT_EQ(return_code, 0); - EXPECT_EQ(*count, 1); - - caosdb_entity_property out_prop; - return_code = caosdb_entity_entity_get_property(&entity, &out_prop, 0); - EXPECT_EQ(return_code, 0); - - 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); - EXPECT_EQ(return_code, 0); - return_code = caosdb_entity_property_get_name(&out_prop, &out); - EXPECT_EQ(return_code, 0); - - EXPECT_EQ(strcmp(in, out), 0); - - // Delete everything we have created - return_code = caosdb_entity_delete_property(&in_prop_2); - EXPECT_EQ(return_code, 0); - - return_code = caosdb_entity_delete_property(&in_prop_1); - EXPECT_EQ(return_code, 0); - - 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"); - caosdb_entity_entity_set_local_path(&entity, "some_name"); - caosdb_entity_entity_set_file_path(&entity, "some_name"); - - auto return_code = caosdb_transaction_transaction_insert_entity(&insert_transaction, &entity); - EXPECT_EQ(return_code, linkahead::StatusCode::GO_ON); - - 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, linkahead::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, linkahead::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); -} diff --git a/test/test_clinkahead.cpp b/test/test_clinkahead.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4ba352d0bf37084c0ce750a58f069f3114827755 --- /dev/null +++ b/test/test_clinkahead.cpp @@ -0,0 +1,1011 @@ +/* + * + * This file is a part of the LinkAhead Project. + * + * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2021-2024 IndiScale GmbH <info@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + */ + +#include "linkahead/configuration.h" +#include "linkahead/status_code.h" // for StatusCode +#include "linkahead_test_utility.h" // for EXPECT_THROW_MESSAGE, TEST_DATA_DIR +#include "clinkahead.h" // for linkahead_utility_get_env_fallback +#include <cstdint> // for int64_t +#include <cstring> // for strcmp +#include <gtest/gtest.h> +#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, operator+, string,... + +class test_ccaosdb : public ::testing::Test { +protected: + void SetUp() override { + linkahead::configuration::ConfigurationManager::Clear(); + linkahead::configuration::ConfigurationManager::LoadSingleJSONConfiguration( + TEST_DATA_DIR + "/test_linkahead_client.json"); + } + + void TearDown() override { linkahead::configuration::ConfigurationManager::Clear(); } +}; + +TEST_F(test_ccaosdb, test_get_env_fallback) { + const char *const some_var = linkahead_utility_get_env_fallback("SOME_ENV_VAR", "fall-back"); + EXPECT_EQ("fall-back", some_var); +} + +TEST_F(test_ccaosdb, test_other_client_error) { + EXPECT_EQ(linkahead_status_code_OTHER_CLIENT_ERROR(), linkahead::StatusCode::OTHER_CLIENT_ERROR); +} + +TEST_F(test_ccaosdb, test_get_default_connection) { + linkahead_connection_connection out; + + linkahead_connection_connection_manager_get_default_connection(&out); + EXPECT_TRUE(out.wrapped_connection); +} + +TEST_F(test_ccaosdb, test_get_connection) { + linkahead_connection_connection out; + + linkahead_connection_connection_manager_get_connection(&out, "local-caosdb-admin"); + EXPECT_TRUE(out.wrapped_connection); +} + +TEST_F(test_ccaosdb, test_execute_transaction) { + linkahead_connection_connection connection; + linkahead_connection_connection_manager_get_connection(&connection, "local-caosdb-admin"); + + linkahead_transaction_transaction transaction; + linkahead_connection_connection_create_transaction(&connection, &transaction); + + EXPECT_TRUE(transaction.wrapped_transaction); + + int return_code(linkahead_transaction_transaction_retrieve_by_id(&transaction, "some_id")); + EXPECT_EQ(return_code, linkahead::StatusCode::GO_ON); + + return_code = linkahead_transaction_transaction_execute(&transaction); + EXPECT_EQ(return_code, linkahead::StatusCode::CONNECTION_ERROR); + + return_code = linkahead_transaction_delete_transaction(&transaction); + EXPECT_EQ(return_code, 0); + + linkahead_transaction_transaction multi_transaction; + linkahead_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 + return_code = linkahead_transaction_transaction_retrieve_by_ids(&multi_transaction, ids, 3); + EXPECT_EQ(return_code, linkahead::StatusCode::GO_ON); + + return_code = linkahead_transaction_delete_transaction(&multi_transaction); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_ccaosdb, test_multi_retrieve) { + linkahead_connection_connection connection; + linkahead_connection_connection_manager_get_connection(&connection, "local-caosdb-admin"); + + linkahead_transaction_transaction multi_transaction; + linkahead_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 + int return_code(linkahead_transaction_transaction_retrieve_by_ids(&multi_transaction, ids, 3)); + EXPECT_EQ(return_code, linkahead::StatusCode::GO_ON); + + return_code = linkahead_transaction_delete_transaction(&multi_transaction); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_ccaosdb, test_query) { + linkahead_connection_connection connection; + linkahead_connection_connection_manager_get_connection(&connection, "local-caosdb-admin"); + + linkahead_transaction_transaction transaction; + linkahead_connection_connection_create_transaction(&connection, &transaction); + + int return_code(linkahead_transaction_transaction_query(&transaction, "FIND ENTITY WITH id=123")); + EXPECT_EQ(return_code, linkahead::StatusCode::GO_ON); + + return_code = linkahead_transaction_delete_transaction(&transaction); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_ccaosdb, test_datatype) { + + linkahead_entity_datatype atomic; + // check that this fails + int return_code(linkahead_entity_create_atomic_datatype(&atomic, "some type")); + EXPECT_EQ(return_code, linkahead::StatusCode::ENUM_MAPPING_ERROR); + + return_code = linkahead_entity_create_atomic_datatype(&atomic, "INTEGER"); + EXPECT_EQ(return_code, 0); + + linkahead_entity_datatype reference; + return_code = linkahead_entity_create_reference_datatype(&reference, "MyType"); + EXPECT_EQ(return_code, 0); + + linkahead_entity_datatype list_of_atomics; + return_code = linkahead_entity_create_atomic_list_datatype(&list_of_atomics, "DATETIME"); + EXPECT_EQ(return_code, 0); + + linkahead_entity_datatype list_of_references; + return_code = linkahead_entity_create_reference_list_datatype(&list_of_references, "MyType"); + EXPECT_EQ(return_code, 0); + + bool is_a(false); + return_code = linkahead_entity_datatype_is_undefined(&atomic, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_atomic(&atomic, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_TRUE(is_a); + return_code = linkahead_entity_datatype_is_reference(&atomic, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_atomic(&atomic, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_reference(&atomic, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + + return_code = linkahead_entity_datatype_is_atomic(&reference, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_reference(&reference, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_TRUE(is_a); + return_code = linkahead_entity_datatype_is_list_of_atomic(&reference, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_reference(&reference, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + + return_code = linkahead_entity_datatype_is_atomic(&list_of_atomics, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_reference(&list_of_atomics, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_atomic(&list_of_atomics, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_TRUE(is_a); + return_code = linkahead_entity_datatype_is_list_of_reference(&list_of_atomics, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + + return_code = linkahead_entity_datatype_is_atomic(&list_of_references, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_reference(&list_of_references, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_atomic(&list_of_references, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_reference(&list_of_references, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_TRUE(is_a); + + char *name = nullptr; // NOLINT + return_code = linkahead_entity_datatype_get_datatype_name(&atomic, &name); + EXPECT_EQ(return_code, 0); + EXPECT_STREQ(name, "INTEGER"); + + return_code = linkahead_entity_datatype_get_datatype_name(&reference, &name); + EXPECT_EQ(return_code, 0); + EXPECT_STREQ(name, "MyType"); + + return_code = linkahead_entity_datatype_get_datatype_name(&list_of_atomics, &name); + EXPECT_EQ(return_code, 0); + EXPECT_STREQ(name, "DATETIME"); + + return_code = linkahead_entity_datatype_get_datatype_name(&list_of_references, &name); + EXPECT_EQ(return_code, 0); + EXPECT_STREQ(name, "MyType"); + + return_code = linkahead_entity_delete_datatype(&atomic); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_datatype(&reference); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_datatype(&list_of_atomics); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_datatype(&list_of_references); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_ccaosdb, test_value) { + + linkahead_entity_value string_value; + int return_code(linkahead_entity_create_string_value(&string_value, "value")); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value int_value; + return_code = linkahead_entity_create_int_value(&int_value, 27); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value bool_value; + return_code = linkahead_entity_create_bool_value(&bool_value, true); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value double_value; + return_code = linkahead_entity_create_double_value(&double_value, 2.7); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value string_vector_value; + const char *string_values[] = {"a", "b", "c"}; // NOLINT + return_code = linkahead_entity_create_string_vector_value(&string_vector_value, string_values, 3); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value int_vector_value; + const int64_t int_values[] = {1, 2, 3}; // NOLINT + return_code = linkahead_entity_create_int_vector_value(&int_vector_value, int_values, 3); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value double_vector_value; + const double double_values[] = {1.1, 2.2, 3.3}; // NOLINT + return_code = linkahead_entity_create_double_vector_value(&double_vector_value, double_values, 3); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value bool_vector_value; + const bool bool_values[] = {true, false, false}; // NOLINT + return_code = linkahead_entity_create_bool_vector_value(&bool_vector_value, bool_values, 3); + EXPECT_EQ(return_code, 0); + + // One thorough check, afterwards only the ones that should be true + bool is_a(false); + return_code = linkahead_entity_value_is_null(&string_value, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_value_is_string(&string_value, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_TRUE(is_a); + return_code = linkahead_entity_value_is_double(&string_value, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_value_is_integer(&string_value, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_value_is_bool(&string_value, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_value_is_vector(&string_value, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + + linkahead_entity_value_is_integer(&int_value, &is_a); + EXPECT_TRUE(is_a); + + linkahead_entity_value_is_bool(&bool_value, &is_a); + EXPECT_TRUE(is_a); + + linkahead_entity_value_is_double(&double_value, &is_a); + EXPECT_TRUE(is_a); + + linkahead_entity_value_is_vector(&string_vector_value, &is_a); + EXPECT_TRUE(is_a); + + linkahead_entity_value_is_vector(&int_vector_value, &is_a); + EXPECT_TRUE(is_a); + + linkahead_entity_value_is_vector(&double_vector_value, &is_a); + EXPECT_TRUE(is_a); + + linkahead_entity_value_is_vector(&bool_vector_value, &is_a); + EXPECT_TRUE(is_a); + + char *out_string = nullptr; // NOLINT + return_code = linkahead_entity_value_get_as_string(&string_value, &out_string); + EXPECT_EQ(return_code, 0); + EXPECT_STREQ(out_string, "value"); + + int64_t out_int(0); + return_code = linkahead_entity_value_get_as_integer(&int_value, &out_int); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(out_int, 27); + + bool out_bool(false); + return_code = linkahead_entity_value_get_as_bool(&bool_value, &out_bool); + EXPECT_EQ(return_code, 0); + EXPECT_TRUE(out_bool); + + double out_double(0); + return_code = linkahead_entity_value_get_as_double(&double_value, &out_double); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(out_double, 2.7); + + int list_length(0); + return_code = linkahead_entity_value_get_as_vector_size(&string_vector_value, &list_length); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(list_length, 3); + return_code = linkahead_entity_value_get_as_vector_size(&int_vector_value, &list_length); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(list_length, 3); + return_code = linkahead_entity_value_get_as_vector_size(&double_vector_value, &list_length); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(list_length, 3); + return_code = linkahead_entity_value_get_as_vector_size(&bool_vector_value, &list_length); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(list_length, 3); + + // Only check for one, rest should be covered by this + scalar values + linkahead_entity_value out_val; + return_code = linkahead_entity_value_get_as_vector_at(&string_vector_value, &out_val, 0); + EXPECT_EQ(return_code, 0); + linkahead_entity_value_get_as_string(&out_val, &out_string); + EXPECT_STREQ(out_string, "a"); + return_code = linkahead_entity_value_get_as_vector_at(&string_vector_value, &out_val, 1); + EXPECT_EQ(return_code, 0); + linkahead_entity_value_get_as_string(&out_val, &out_string); + EXPECT_STREQ(out_string, "b"); + return_code = linkahead_entity_value_get_as_vector_at(&string_vector_value, &out_val, 2); + EXPECT_EQ(return_code, 0); + linkahead_entity_value_get_as_string(&out_val, &out_string); + EXPECT_STREQ(out_string, "c"); + + return_code = linkahead_entity_delete_value(&string_value); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&int_value); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&bool_value); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&double_value); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&string_vector_value); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&int_vector_value); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&double_vector_value); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&bool_vector_value); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_ccaosdb, test_entity) { + linkahead_entity_entity entity; + + int return_code(linkahead_entity_create_entity(&entity)); + EXPECT_EQ(return_code, 0); + + // cannot be created again without deletion + // return_code = linkahead_entity_create_entity(&entity); + // EXPECT_EQ(return_code, linkahead::StatusCode::EXTERN_C_ASSIGNMENT_ERROR); + + // deletion and re-creation is ok + return_code = linkahead_entity_delete_entity(&entity); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_create_entity(&entity); + EXPECT_EQ(return_code, 0); + + // In-depth check for one pair of setter and getter, just compare + // the strings for the rest + return_code = linkahead_entity_entity_set_name(&entity, "length"); + EXPECT_EQ(return_code, 0); + char *out = nullptr; // NOLINT + return_code = linkahead_entity_entity_get_name(&entity, &out); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(strcmp(out, "length"), 0); + + // test call without validation of result + return_code = linkahead_entity_entity_set_role(&entity, "FILE"); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_entity_set_local_path( + &entity, (TEST_DATA_DIR + "/test_linkahead_client.json").c_str()); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_entity_get_local_path(&entity, &out); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(strcmp(out, (TEST_DATA_DIR + "/test_linkahead_client.json").c_str()), 0); + + // invalid role + return_code = linkahead_entity_entity_set_role(&entity, "Role does not exist"); + EXPECT_EQ(return_code, linkahead::StatusCode::ENUM_MAPPING_ERROR); + + linkahead_entity_entity_set_role(&entity, "PROPERTY"); + linkahead_entity_entity_get_role(&entity, &out); + EXPECT_EQ(strcmp(out, "PROPERTY"), 0); + + linkahead_entity_entity_set_description(&entity, "The length of an object"); + linkahead_entity_entity_get_description(&entity, &out); + EXPECT_EQ(strcmp(out, "The length of an object"), 0); + + linkahead_entity_datatype in_type; + linkahead_entity_create_atomic_datatype(&in_type, "DOUBLE"); + linkahead_entity_entity_set_datatype(&entity, &in_type); + + // verify that this doesn't work ... + // return_code = linkahead_entity_entity_get_datatype(&entity, &in_type); + // EXPECT_EQ(return_code, linkahead::StatusCode::EXTERN_C_ASSIGNMENT_ERROR); + linkahead_entity_datatype out_type; + // ... but does with a clean property + return_code = linkahead_entity_entity_get_datatype(&entity, &out_type); + EXPECT_EQ(return_code, 0); + bool is_a(false); + return_code = linkahead_entity_datatype_is_atomic(&out_type, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_TRUE(is_a); + return_code = linkahead_entity_datatype_is_reference(&out_type, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_atomic(&out_type, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_reference(&out_type, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + + linkahead_entity_datatype_get_datatype_name(&out_type, &out); + EXPECT_STREQ(out, "DOUBLE"); + + linkahead_entity_value in_value; + return_code = linkahead_entity_create_double_value(&in_value, 5.0); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_entity_set_value(&entity, &in_value); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value out_value; + return_code = linkahead_entity_entity_get_value(&entity, &out_value); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value_is_double(&out_value, &is_a); + EXPECT_TRUE(is_a); + linkahead_entity_value_is_null(&out_value, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_value_is_string(&out_value, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_value_is_bool(&out_value, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_value_is_integer(&out_value, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_value_is_vector(&out_value, &is_a); + EXPECT_FALSE(is_a); + + double out_double(0); + linkahead_entity_value_get_as_double(&out_value, &out_double); + EXPECT_EQ(out_double, 5.0); + + // clear to re-use + return_code = linkahead_entity_delete_datatype(&in_type); + EXPECT_EQ(return_code, 0); + linkahead_entity_create_reference_list_datatype(&in_type, "Person"); + linkahead_entity_entity_set_datatype(&entity, &in_type); + + // works without clearing since datatype is managed by the owning entity + linkahead_entity_entity_get_datatype(&entity, &out_type); + return_code = linkahead_entity_datatype_is_atomic(&out_type, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_reference(&out_type, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_atomic(&out_type, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_FALSE(is_a); + return_code = linkahead_entity_datatype_is_list_of_reference(&out_type, &is_a); + EXPECT_EQ(return_code, 0); + EXPECT_TRUE(is_a); + + linkahead_entity_datatype_get_datatype_name(&out_type, &out); + EXPECT_STREQ(out, "Person"); + + linkahead_entity_entity_set_unit(&entity, "m"); + linkahead_entity_entity_get_unit(&entity, &out); + EXPECT_EQ(strcmp(out, "m"), 0); + + return_code = linkahead_entity_delete_entity(&entity); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_datatype(&in_type); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&in_value); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_ccaosdb, test_parent) { + linkahead_entity_parent parent; + + int return_code(linkahead_entity_create_parent(&parent)); + EXPECT_EQ(return_code, 0); + + linkahead_entity_parent_set_id(&parent, "some_id"); + linkahead_entity_parent_set_name(&parent, "some_name"); + + char *out = nullptr; // NOLINT + linkahead_entity_parent_get_id(&parent, &out); + EXPECT_EQ(strcmp(out, "some_id"), 0); + + linkahead_entity_parent_get_name(&parent, &out); + EXPECT_EQ(strcmp(out, "some_name"), 0); + + return_code = linkahead_entity_delete_parent(&parent); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_ccaosdb, test_property) { + linkahead_entity_property property; + + int return_code(linkahead_entity_create_property(&property)); + EXPECT_EQ(return_code, 0); + + linkahead_entity_property_set_id(&property, "some_id"); + linkahead_entity_property_set_name(&property, "some_name"); + + linkahead_entity_datatype in_type; + linkahead_entity_create_atomic_datatype(&in_type, "TEXT"); + linkahead_entity_property_set_datatype(&property, &in_type); + linkahead_entity_property_set_importance(&property, "FIX"); + linkahead_entity_property_set_unit(&property, "some_unit"); + linkahead_entity_value in_value; + linkahead_entity_create_string_value(&in_value, "some_value"); + linkahead_entity_property_set_value(&property, &in_value); + + char *out = nullptr; // NOLINT + linkahead_entity_property_get_id(&property, &out); + EXPECT_EQ(strcmp(out, "some_id"), 0); + + linkahead_entity_property_get_name(&property, &out); + EXPECT_EQ(strcmp(out, "some_name"), 0); + + linkahead_entity_datatype out_type; + return_code = linkahead_entity_property_get_datatype(&property, &out_type); + EXPECT_EQ(return_code, 0); + bool is_a(false); + + linkahead_entity_datatype_is_atomic(&out_type, &is_a); + EXPECT_TRUE(is_a); + linkahead_entity_datatype_is_reference(&out_type, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_datatype_is_list_of_atomic(&out_type, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_datatype_is_list_of_reference(&out_type, &is_a); + EXPECT_FALSE(is_a); + + linkahead_entity_datatype_get_datatype_name(&out_type, &out); + EXPECT_STREQ(out, "TEXT"); + + linkahead_entity_property_get_importance(&property, &out); + EXPECT_EQ(strcmp(out, "FIX"), 0); + + linkahead_entity_property_get_unit(&property, &out); + EXPECT_EQ(strcmp(out, "some_unit"), 0); + + linkahead_entity_value out_value; + return_code = linkahead_entity_property_get_value(&property, &out_value); + EXPECT_EQ(return_code, 0); + linkahead_entity_value_is_string(&out_value, &is_a); + EXPECT_TRUE(is_a); + linkahead_entity_value_get_as_string(&out_value, &out); + EXPECT_STREQ(out, "some_value"); + + return_code = linkahead_entity_delete_property(&property); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_datatype(&in_type); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&in_value); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_ccaosdb, test_string_list_property) { + + linkahead_entity_property property; + int return_code(linkahead_entity_create_property(&property)); + EXPECT_EQ(return_code, 0); + + linkahead_entity_datatype in_type; + return_code = linkahead_entity_create_atomic_list_datatype(&in_type, "TEXT"); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_property_set_datatype(&property, &in_type); + EXPECT_EQ(return_code, 0); + + linkahead_entity_value in_value; + const char *value_list[] = {"val0", "val1", "val2"}; // NOLINT + return_code = linkahead_entity_create_string_vector_value(&in_value, value_list, 3); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_property_set_value(&property, &in_value); + EXPECT_EQ(return_code, 0); + + linkahead_entity_datatype out_type; + return_code = linkahead_entity_property_get_datatype(&property, &out_type); + EXPECT_EQ(return_code, 0); + + bool is_a(false); + linkahead_entity_datatype_is_atomic(&out_type, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_datatype_is_reference(&out_type, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_datatype_is_list_of_atomic(&out_type, &is_a); + EXPECT_TRUE(is_a); + linkahead_entity_datatype_is_list_of_reference(&out_type, &is_a); + EXPECT_FALSE(is_a); + char *out = nullptr; // NOLINT + linkahead_entity_datatype_get_datatype_name(&out_type, &out); + EXPECT_STREQ(out, "TEXT"); + + linkahead_entity_value out_value; + linkahead_entity_property_get_value(&property, &out_value); + linkahead_entity_value_is_vector(&out_value, &is_a); + EXPECT_TRUE(is_a); + int length(-1); + linkahead_entity_value_get_as_vector_size(&out_value, &length); + EXPECT_EQ(length, 3); + + linkahead_entity_value list_elt; + for (int i = 0; i < length; i++) { + return_code = linkahead_entity_value_get_as_vector_at(&out_value, &list_elt, i); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_value_get_as_string(&list_elt, &out); + EXPECT_EQ(return_code, 0); + EXPECT_STREQ(value_list[i], out); // NOLINT + } + + return_code = linkahead_entity_delete_property(&property); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_datatype(&in_type); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&in_value); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_ccaosdb, test_int_list_property) { + + linkahead_entity_property property; + int return_code(linkahead_entity_create_property(&property)); + EXPECT_EQ(return_code, 0); + + linkahead_entity_datatype in_type; + linkahead_entity_create_atomic_list_datatype(&in_type, "INTEGER"); + return_code = linkahead_entity_property_set_datatype(&property, &in_type); + EXPECT_EQ(return_code, 0); + + const int64_t value_list[] = {1, 2, 3}; // NOLINT + linkahead_entity_value in_value; + linkahead_entity_create_int_vector_value(&in_value, value_list, 3); + return_code = linkahead_entity_property_set_value(&property, &in_value); + EXPECT_EQ(return_code, 0); + + linkahead_entity_datatype out_type; + return_code = linkahead_entity_property_get_datatype(&property, &out_type); + EXPECT_EQ(return_code, 0); + + bool is_a(false); + linkahead_entity_datatype_is_atomic(&out_type, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_datatype_is_reference(&out_type, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_datatype_is_list_of_atomic(&out_type, &is_a); + EXPECT_TRUE(is_a); + linkahead_entity_datatype_is_list_of_reference(&out_type, &is_a); + EXPECT_FALSE(is_a); + char *out = nullptr; // NOLINT + linkahead_entity_datatype_get_datatype_name(&out_type, &out); + EXPECT_STREQ(out, "INTEGER"); + + linkahead_entity_value out_value; + linkahead_entity_property_get_value(&property, &out_value); + linkahead_entity_value_is_vector(&out_value, &is_a); + EXPECT_TRUE(is_a); + int length(-1); + linkahead_entity_value_get_as_vector_size(&out_value, &length); + EXPECT_EQ(length, 3); + + int64_t out_int = -1; + linkahead_entity_value list_elt; + for (int i = 0; i < length; i++) { + return_code = linkahead_entity_value_get_as_vector_at(&out_value, &list_elt, i); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_value_get_as_integer(&list_elt, &out_int); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(value_list[i], out_int); // NOLINT + } + + return_code = linkahead_entity_delete_property(&property); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_datatype(&in_type); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&in_value); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_ccaosdb, test_bool_list_property) { + + linkahead_entity_property property; + int return_code(linkahead_entity_create_property(&property)); + EXPECT_EQ(return_code, 0); + + linkahead_entity_datatype in_type; + linkahead_entity_create_atomic_list_datatype(&in_type, "BOOLEAN"); + return_code = linkahead_entity_property_set_datatype(&property, &in_type); + EXPECT_EQ(return_code, 0); + + const bool value_list[] = {true, true, false}; // NOLINT + linkahead_entity_value in_value; + linkahead_entity_create_bool_vector_value(&in_value, value_list, 3); + return_code = linkahead_entity_property_set_value(&property, &in_value); + EXPECT_EQ(return_code, 0); + + linkahead_entity_datatype out_type; + return_code = linkahead_entity_property_get_datatype(&property, &out_type); + EXPECT_EQ(return_code, 0); + + bool is_a(false); + linkahead_entity_datatype_is_atomic(&out_type, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_datatype_is_reference(&out_type, &is_a); + EXPECT_FALSE(is_a); + linkahead_entity_datatype_is_list_of_atomic(&out_type, &is_a); + EXPECT_TRUE(is_a); + linkahead_entity_datatype_is_list_of_reference(&out_type, &is_a); + EXPECT_FALSE(is_a); + char *out = nullptr; // NOLINT + linkahead_entity_datatype_get_datatype_name(&out_type, &out); + EXPECT_STREQ(out, "BOOLEAN"); + + linkahead_entity_value out_value; + linkahead_entity_property_get_value(&property, &out_value); + linkahead_entity_value_is_vector(&out_value, &is_a); + EXPECT_TRUE(is_a); + int length(-1); + linkahead_entity_value_get_as_vector_size(&out_value, &length); + EXPECT_EQ(length, 3); + + bool out_bool(false); + linkahead_entity_value list_elt; + for (int i = 0; i < length; i++) { + return_code = linkahead_entity_value_get_as_vector_at(&out_value, &list_elt, i); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_value_get_as_bool(&list_elt, &out_bool); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(value_list[i], out_bool); // NOLINT + } + + return_code = linkahead_entity_delete_property(&property); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_datatype(&in_type); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&in_value); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_ccaosdb, test_entity_with_parent_and_property) { + linkahead_entity_parent input_parent; + int return_code(linkahead_entity_create_parent(&input_parent)); + EXPECT_EQ(return_code, 0); + + linkahead_entity_parent_set_id(&input_parent, "parent_id"); + linkahead_entity_parent_set_name(&input_parent, "parent_name"); + + linkahead_entity_property input_property; + return_code = linkahead_entity_create_property(&input_property); + EXPECT_EQ(return_code, 0); + + linkahead_entity_property_set_id(&input_property, "property_id"); + linkahead_entity_property_set_name(&input_property, "property_name"); + + linkahead_entity_datatype in_type; + linkahead_entity_create_atomic_datatype(&in_type, "TEXT"); + linkahead_entity_value in_value; + linkahead_entity_create_string_value(&in_value, "property_value"); + linkahead_entity_property_set_datatype(&input_property, &in_type); + linkahead_entity_property_set_value(&input_property, &in_value); + + linkahead_entity_entity entity; + return_code = linkahead_entity_create_entity(&entity); + EXPECT_EQ(return_code, 0); + + return_code = linkahead_entity_entity_append_parent(&entity, &input_parent); + EXPECT_EQ(return_code, 0); + + return_code = linkahead_entity_entity_append_property(&entity, &input_property); + EXPECT_EQ(return_code, 0); + + int count[] = {0}; // NOLINT + return_code = linkahead_entity_entity_get_parents_size(&entity, count); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(*count, 1); + + return_code = linkahead_entity_entity_get_properties_size(&entity, count); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(*count, 1); + + char *in = nullptr; // NOLINT + char *out = nullptr; // NOLINT + + // cannot assign an already assigned property + // return_code = linkahead_entity_entity_get_property(&entity, &input_property, 0); + // EXPECT_EQ(return_code, linkahead::StatusCode::EXTERN_C_ASSIGNMENT_ERROR); + linkahead_entity_property output_property; + return_code = linkahead_entity_entity_get_property(&entity, &output_property, 0); + EXPECT_EQ(return_code, 0); + + linkahead_entity_property_get_id(&input_property, &in); + linkahead_entity_property_get_id(&output_property, &out); + EXPECT_EQ(strcmp(in, out), 0); + + linkahead_entity_property_get_name(&input_property, &in); + linkahead_entity_property_get_name(&output_property, &out); + EXPECT_EQ(strcmp(in, out), 0); + + linkahead_entity_datatype out_type; + linkahead_entity_property_get_datatype(&output_property, &out_type); + + bool in_is(false); + bool out_is(false); + linkahead_entity_datatype_is_atomic(&in_type, &in_is); + linkahead_entity_datatype_is_atomic(&out_type, &out_is); + EXPECT_EQ(in_is, out_is); + linkahead_entity_datatype_is_reference(&in_type, &in_is); + linkahead_entity_datatype_is_reference(&out_type, &out_is); + EXPECT_EQ(in_is, out_is); + linkahead_entity_datatype_is_list_of_atomic(&in_type, &in_is); + linkahead_entity_datatype_is_list_of_atomic(&out_type, &out_is); + EXPECT_EQ(in_is, out_is); + linkahead_entity_datatype_is_list_of_reference(&in_type, &in_is); + linkahead_entity_datatype_is_list_of_reference(&out_type, &out_is); + EXPECT_EQ(in_is, out_is); + + linkahead_entity_datatype_get_datatype_name(&in_type, &in); + linkahead_entity_datatype_get_datatype_name(&out_type, &out); + EXPECT_STREQ(in, out); + + linkahead_entity_value out_value; + linkahead_entity_property_get_value(&output_property, &out_value); + linkahead_entity_value_is_string(&in_value, &in_is); + EXPECT_TRUE(in_is); + linkahead_entity_value_is_string(&out_value, &out_is); + EXPECT_TRUE(out_is); + linkahead_entity_value_get_as_string(&in_value, &in); + linkahead_entity_value_get_as_string(&out_value, &out); + EXPECT_STREQ(in, out); + + linkahead_entity_parent output_parent; + return_code = linkahead_entity_entity_get_parent(&entity, &output_parent, 0); + EXPECT_EQ(return_code, 0); + + linkahead_entity_parent_get_id(&input_parent, &in); + linkahead_entity_parent_get_id(&output_parent, &out); + EXPECT_EQ(strcmp(in, out), 0); + + linkahead_entity_parent_get_name(&input_parent, &in); + linkahead_entity_parent_get_name(&output_parent, &out); + EXPECT_EQ(strcmp(in, out), 0); + + // Delete everything + return_code = linkahead_entity_delete_parent(&input_parent); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_property(&input_property); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_entity(&entity); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_datatype(&in_type); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_value(&in_value); + EXPECT_EQ(return_code, 0); + + // This tests the `_deletable` flag. The wrapped cpp objects of + // `output_parent` and `output_property` are owned by the entity, so + // they have been deleted together with the entity. With a wrong + // `_deletable` flag, the following would cause segfaults. + // + return_code = linkahead_entity_delete_parent(&output_parent); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_delete_property(&output_property); + EXPECT_EQ(return_code, 0); +} + +TEST_F(test_ccaosdb, test_remove_property) { + linkahead_entity_entity entity; + int return_code(linkahead_entity_create_entity(&entity)); + EXPECT_EQ(return_code, 0); + + // Create two properties with names + linkahead_entity_property in_prop_1; + return_code = linkahead_entity_create_property(&in_prop_1); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_property_set_name(&in_prop_1, "Property 1"); + EXPECT_EQ(return_code, 0); + + linkahead_entity_property in_prop_2; + return_code = linkahead_entity_create_property(&in_prop_2); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_property_set_name(&in_prop_2, "Property 2"); + EXPECT_EQ(return_code, 0); + + // Append them + return_code = linkahead_entity_entity_append_property(&entity, &in_prop_1); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_entity_append_property(&entity, &in_prop_2); + EXPECT_EQ(return_code, 0); + + // Delete one and see that the number of properties decreases by one + int count[] = {0}; // NOLINT + return_code = linkahead_entity_entity_get_properties_size(&entity, count); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(*count, 2); + + return_code = linkahead_entity_entity_remove_property(&entity, 0); + EXPECT_EQ(return_code, 0); + + return_code = linkahead_entity_entity_get_properties_size(&entity, count); + EXPECT_EQ(return_code, 0); + EXPECT_EQ(*count, 1); + + linkahead_entity_property out_prop; + return_code = linkahead_entity_entity_get_property(&entity, &out_prop, 0); + EXPECT_EQ(return_code, 0); + + char *in = nullptr; // NOLINT + char *out = nullptr; // NOLINT + + // Deleted the first property, so the second one should remain. + return_code = linkahead_entity_property_get_name(&in_prop_2, &in); + EXPECT_EQ(return_code, 0); + return_code = linkahead_entity_property_get_name(&out_prop, &out); + EXPECT_EQ(return_code, 0); + + EXPECT_EQ(strcmp(in, out), 0); + + // Delete everything we have created + return_code = linkahead_entity_delete_property(&in_prop_2); + EXPECT_EQ(return_code, 0); + + return_code = linkahead_entity_delete_property(&in_prop_1); + EXPECT_EQ(return_code, 0); + + return_code = linkahead_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. + linkahead_connection_connection connection; + linkahead_connection_connection_manager_get_default_connection(&connection); + + linkahead_transaction_transaction insert_transaction; + linkahead_connection_connection_create_transaction(&connection, &insert_transaction); + + linkahead_entity_entity entity; + linkahead_entity_create_entity(&entity); + linkahead_entity_entity_set_name(&entity, "some_name"); + linkahead_entity_entity_set_local_path(&entity, "some_name"); + linkahead_entity_entity_set_file_path(&entity, "some_name"); + + auto return_code = linkahead_transaction_transaction_insert_entity(&insert_transaction, &entity); + EXPECT_EQ(return_code, linkahead::StatusCode::GO_ON); + + linkahead_transaction_transaction update_transaction; + linkahead_connection_connection_create_transaction(&connection, &update_transaction); + + return_code = linkahead_transaction_transaction_update_entity(&update_transaction, &entity); + // No ID, so this should be an error + EXPECT_EQ(return_code, linkahead::StatusCode::ORIGINAL_ENTITY_MISSING_ID); + + linkahead_transaction_transaction delete_transaction; + linkahead_connection_connection_create_transaction(&connection, &delete_transaction); + + return_code = linkahead_transaction_transaction_delete_by_id(&delete_transaction, "some_id"); + // Could add further deletions + EXPECT_EQ(return_code, linkahead::StatusCode::GO_ON); + + linkahead_entity_delete_entity(&entity); + linkahead_transaction_delete_transaction(&insert_transaction); + linkahead_transaction_delete_transaction(&update_transaction); + linkahead_transaction_delete_transaction(&delete_transaction); +}