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

DRAFT: Re-implement getting of values and datatypes

parent 98e25351
No related branches found
No related tags found
1 merge request!24API: Introduce value and datatype structs to Extern C
Pipeline #13676 failed
...@@ -377,10 +377,8 @@ int caosdb_entity_entity_get_role(caosdb_entity_entity *entity, char **out); ...@@ -377,10 +377,8 @@ int caosdb_entity_entity_get_role(caosdb_entity_entity *entity, char **out);
int caosdb_entity_entity_get_name(caosdb_entity_entity *entity, char **out); int caosdb_entity_entity_get_name(caosdb_entity_entity *entity, char **out);
int caosdb_entity_entity_get_description(caosdb_entity_entity *entity, char **out); int caosdb_entity_entity_get_description(caosdb_entity_entity *entity, char **out);
int caosdb_entity_entity_get_local_path(caosdb_entity_entity *entity, char **out); int caosdb_entity_entity_get_local_path(caosdb_entity_entity *entity, char **out);
// TODO(fspreck) implementation
int caosdb_entity_entity_get_datatype(caosdb_entity_entity *entity, caosdb_entity_datatype *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_unit(caosdb_entity_entity *entity, char **out);
// TODO(fspreck) implementation
int caosdb_entity_entity_get_value(caosdb_entity_entity *entity, caosdb_entity_value *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_version_id(caosdb_entity_entity *entity, char **out);
int caosdb_entity_entity_get_errors_size(caosdb_entity_entity *entity, int *out); int caosdb_entity_entity_get_errors_size(caosdb_entity_entity *entity, int *out);
...@@ -403,11 +401,9 @@ int caosdb_entity_property_get_id(caosdb_entity_property *property, char **out); ...@@ -403,11 +401,9 @@ int caosdb_entity_property_get_id(caosdb_entity_property *property, char **out);
int caosdb_entity_property_get_name(caosdb_entity_property *property, char **out); int caosdb_entity_property_get_name(caosdb_entity_property *property, char **out);
int caosdb_entity_property_get_description(caosdb_entity_property *property, char **out); int caosdb_entity_property_get_description(caosdb_entity_property *property, char **out);
int caosdb_entity_property_get_importance(caosdb_entity_property *property, char **out); int caosdb_entity_property_get_importance(caosdb_entity_property *property, char **out);
// TODO(fspreck) implementation
int caosdb_entity_property_get_datatype(caosdb_entity_property *property, int caosdb_entity_property_get_datatype(caosdb_entity_property *property,
caosdb_entity_datatype *out); caosdb_entity_datatype *out);
int caosdb_entity_property_get_unit(caosdb_entity_property *property, char **out); int caosdb_entity_property_get_unit(caosdb_entity_property *property, char **out);
// TODO(fspreck) implementation
int caosdb_entity_property_get_value(caosdb_entity_property *property, caosdb_entity_value *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_id(caosdb_entity_parent *parent, char **out);
int caosdb_entity_parent_get_name(caosdb_entity_parent *parent, char **out); int caosdb_entity_parent_get_name(caosdb_entity_parent *parent, char **out);
......
...@@ -789,41 +789,26 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ...@@ -789,41 +789,26 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
}) })
// CAOSDB_ENTITY_GET(file_path, GetFilePath()) TODO(henrik) // CAOSDB_ENTITY_GET(file_path, GetFilePath()) TODO(henrik)
CAOSDB_ENTITY_GET(description, GetDescription()) CAOSDB_ENTITY_GET(description, GetDescription())
// TODO(fspreck) ERROR_RETURN_CODE(GENERIC_ERROR,
// ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_entity_get_datatype(caosdb_entity_entity *entity,
// int caosdb_entity_entity_get_datatype(caosdb_entity_entity *entity, char caosdb_entity_datatype *out),
// **name, {
// bool *is_ref, bool *is_list), RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE(out)
// { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity);
// auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); out->wrapped_datatype = (void *)(&(wrapped_entity->GetDataType()));
// const auto &datatype = wrapped_entity->GetDataType(); out->_deletable = false;
// *is_list = datatype.IsList(); return 0;
// std::string datatype_name; })
// if (*is_list) { ERROR_RETURN_CODE(GENERIC_ERROR,
// const auto &list_datatype = datatype.AsList(); int caosdb_entity_entity_get_value(caosdb_entity_entity *entity,
// *is_ref = list_datatype.IsListOfReference(); caosdb_entity_value *out),
// if (*is_ref) { {
// datatype_name = list_datatype.GetReferenceDataType().GetName(); RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE(out)
// } else { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity);
// datatype_name = out->wrapped_value = (void *)(&(wrapped_entity->GetValue()));
// ENUM_NAME_FROM_VALUE(list_datatype.GetAtomicDataType(), out->_deletable = false;
// AtomicDataType); return 0;
// } })
// } else {
// *is_ref = datatype.IsReference();
// if (*is_ref) {
// datatype_name = datatype.AsReference().GetName();
// } else {
// datatype_name = ENUM_NAME_FROM_VALUE(datatype.AsAtomic(),
// AtomicDataType);
// }
// }
// char *tmp = (char *)malloc(sizeof(char) * datatype_name.length() + 1);
// strcpy(tmp, datatype_name.c_str());
// delete[] * name;
// *name = tmp;
// return 0;
// })
CAOSDB_ENTITY_GET(unit, GetUnit()) CAOSDB_ENTITY_GET(unit, GetUnit())
CAOSDB_ENTITY_GET(version_id, GetVersionId()) CAOSDB_ENTITY_GET(version_id, GetVersionId())
...@@ -965,43 +950,26 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ...@@ -965,43 +950,26 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
*out = tmp; *out = tmp;
return 0; return 0;
}) })
ERROR_RETURN_CODE(GENERIC_ERROR,
// TODO(fspreck) int caosdb_entity_property_get_datatype(caosdb_entity_property *property,
// ERROR_RETURN_CODE(GENERIC_ERROR, caosdb_entity_datatype *out),
// int caosdb_entity_property_get_datatype(caosdb_entity_property *property, {
// char **name, bool *is_ref, bool RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE(out)
// *is_list), auto *wrapped_property = WRAPPED_PROPERTY_CAST(property);
// { out->wrapped_datatype = (void *)(&(wrapped_property->GetDataType()));
// auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); out->_deletable = false;
// const auto &datatype = wrapped_property->GetDataType(); return 0;
// *is_list = datatype.IsList(); })
// std::string datatype_name; ERROR_RETURN_CODE(GENERIC_ERROR,
// if (*is_list) { int caosdb_entity_property_get_value(caosdb_entity_property *property,
// const auto &list_datatype = datatype.AsList(); caosdb_entity_value *out),
// *is_ref = list_datatype.IsListOfReference(); {
// if (*is_ref) { RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE(out)
// datatype_name = list_datatype.GetReferenceDataType().GetName(); auto *wrapped_property = WRAPPED_PROPERTY_CAST(property);
// } else { out->wrapped_value = (void *)(&(wrapped_property->GetValue()));
// datatype_name = out->_deletable = false;
// ENUM_NAME_FROM_VALUE(list_datatype.GetAtomicDataType(), return 0;
// AtomicDataType); })
// }
// } else {
// *is_ref = datatype.IsReference();
// if (*is_ref) {
// datatype_name = datatype.AsReference().GetName();
// } else {
// datatype_name = ENUM_NAME_FROM_VALUE(datatype.AsAtomic(),
// AtomicDataType);
// }
// }
// char *tmp = (char *)malloc(sizeof(char) * datatype_name.length() + 1);
// strcpy(tmp, datatype_name.c_str());
// delete[] * name;
// *name = tmp;
// return 0;
// })
CAOSDB_PROPERTY_GET(unit, GetUnit()) CAOSDB_PROPERTY_GET(unit, GetUnit())
ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE(GENERIC_ERROR,
...@@ -1160,7 +1128,11 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ...@@ -1160,7 +1128,11 @@ ERROR_RETURN_CODE(GENERIC_ERROR,
auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity);
auto *wrapped_value = WRAPPED_VALUE_CAST(value); auto *wrapped_value = WRAPPED_VALUE_CAST(value);
return wrapped_entity->SetValue(*wrapped_value); std::cout << wrapped_entity->ToString() << std::endl;
int return_value(wrapped_entity->SetValue(*wrapped_value));
std::cout << wrapped_entity->ToString() << std::endl;
return return_value;
}) })
ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE(GENERIC_ERROR,
......
...@@ -426,40 +426,86 @@ TEST_F(test_ccaosdb, test_entity) { ...@@ -426,40 +426,86 @@ TEST_F(test_ccaosdb, test_entity) {
caosdb_entity_datatype in_type; caosdb_entity_datatype in_type;
caosdb_entity_create_atomic_datatype(&in_type, "DOUBLE"); caosdb_entity_create_atomic_datatype(&in_type, "DOUBLE");
caosdb_entity_entity_set_datatype(&entity, &in_type); caosdb_entity_entity_set_datatype(&entity, &in_type);
// TODO(fspreck)
// bool is_list[] = {false}; // NOLINT // verify that this doesn't work ...
// bool is_ref[] = {false}; // NOLINT return_code = caosdb_entity_entity_get_datatype(&entity, &in_type);
// caosdb_entity_entity_get_datatype(&entity, &out, is_ref, is_list); EXPECT_EQ(return_code, caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR);
// EXPECT_EQ(strcmp(out, "DOUBLE"), 0); caosdb_entity_datatype out_type;
// EXPECT_FALSE(*is_list); // ... but does with a clean property
// EXPECT_FALSE(*is_ref); 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_refernce(&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 // clear to re-use
return_code = caosdb_entity_delete_datatype(&in_type); return_code = caosdb_entity_delete_datatype(&in_type);
EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
caosdb_entity_create_reference_list_datatype(&in_type, "Person"); caosdb_entity_create_reference_list_datatype(&in_type, "Person");
caosdb_entity_entity_set_datatype(&entity, &in_type); caosdb_entity_entity_set_datatype(&entity, &in_type);
// TODO(fspreck)
// caosdb_entity_entity_get_datatype(&entity, &out, is_ref, is_list); // works without clearing since datatype is managed by the owning entity
// EXPECT_EQ(strcmp(out, "Person"), 0); caosdb_entity_entity_get_datatype(&entity, &out_type);
// EXPECT_TRUE(*is_list); return_code = caosdb_entity_datatype_is_atomic(&out_type, &is_a);
// EXPECT_TRUE(*is_ref); 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_refernce(&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_set_unit(&entity, "m");
caosdb_entity_entity_get_unit(&entity, &out); caosdb_entity_entity_get_unit(&entity, &out);
EXPECT_EQ(strcmp(out, "m"), 0); EXPECT_EQ(strcmp(out, "m"), 0);
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);
// TODO(fspreck)
// double value[] = {0.0}; // NOLINT
// return_code = caosdb_entity_entity_get_double_value(&entity, value);
// EXPECT_EQ(return_code, 0);
// EXPECT_EQ(*value, 5.0);
return_code = caosdb_entity_delete_entity(&entity); return_code = caosdb_entity_delete_entity(&entity);
EXPECT_EQ(return_code, 0); EXPECT_EQ(return_code, 0);
return_code = caosdb_entity_delete_datatype(&in_type); return_code = caosdb_entity_delete_datatype(&in_type);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment