From 083478f91a83605f5678ac1a2a165d8c2ad9e2d5 Mon Sep 17 00:00:00 2001 From: florian <f.spreckelsen@inidscale.com> Date: Thu, 16 Sep 2021 14:30:54 +0200 Subject: [PATCH] ENH: Finalize get_value and get_datatype --- include/ccaosdb.h | 2 +- src/ccaosdb.cpp | 10 +- test/test_ccaosdb.cpp | 251 ++++++++++++++++++++++++++---------------- 3 files changed, 163 insertions(+), 100 deletions(-) diff --git a/include/ccaosdb.h b/include/ccaosdb.h index 38ed90e..b929634 100644 --- a/include/ccaosdb.h +++ b/include/ccaosdb.h @@ -415,7 +415,7 @@ int caosdb_entity_message_get_description(caosdb_entity_message *message, char * 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_refernce(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); diff --git a/src/ccaosdb.cpp b/src/ccaosdb.cpp index e966ecd..a18c56d 100644 --- a/src/ccaosdb.cpp +++ b/src/ccaosdb.cpp @@ -1020,8 +1020,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_datatype_is_list_of_refernce(caosdb_entity_datatype *datatype, - bool *out), + int caosdb_entity_datatype_is_list_of_reference(caosdb_entity_datatype *datatype, + bool *out), { auto *wrapped_datatype = WRAPPED_DATATYPE_CAST(datatype); if (wrapped_datatype->IsList()) { @@ -1128,11 +1128,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); auto *wrapped_value = WRAPPED_VALUE_CAST(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; + return wrapped_entity->SetValue(*wrapped_value); }) ERROR_RETURN_CODE(GENERIC_ERROR, diff --git a/test/test_ccaosdb.cpp b/test/test_ccaosdb.cpp index 317cd8f..361b091 100644 --- a/test/test_ccaosdb.cpp +++ b/test/test_ccaosdb.cpp @@ -159,7 +159,7 @@ TEST_F(test_ccaosdb, test_datatype) { 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_refernce(&atomic, &is_a); + return_code = caosdb_entity_datatype_is_list_of_reference(&atomic, &is_a); EXPECT_EQ(return_code, 0); EXPECT_FALSE(is_a); @@ -172,7 +172,7 @@ TEST_F(test_ccaosdb, test_datatype) { 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_refernce(&reference, &is_a); + return_code = caosdb_entity_datatype_is_list_of_reference(&reference, &is_a); EXPECT_EQ(return_code, 0); EXPECT_FALSE(is_a); @@ -185,7 +185,7 @@ TEST_F(test_ccaosdb, test_datatype) { 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_refernce(&list_of_atomics, &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); @@ -198,7 +198,7 @@ TEST_F(test_ccaosdb, test_datatype) { 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_refernce(&list_of_references, &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); @@ -444,7 +444,7 @@ TEST_F(test_ccaosdb, test_entity) { 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); + return_code = caosdb_entity_datatype_is_list_of_reference(&out_type, &is_a); EXPECT_EQ(return_code, 0); EXPECT_FALSE(is_a); @@ -495,7 +495,7 @@ TEST_F(test_ccaosdb, test_entity) { 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); + return_code = caosdb_entity_datatype_is_list_of_reference(&out_type, &is_a); EXPECT_EQ(return_code, 0); EXPECT_TRUE(is_a); @@ -559,13 +559,22 @@ TEST_F(test_ccaosdb, test_property) { caosdb_entity_property_get_name(&property, &out); EXPECT_EQ(strcmp(out, "some_name"), 0); - // TODO(fspreck) - // bool is_ref[] = {false}; // NOLINT - // bool is_list[] = {false}; // NOLINT - // caosdb_entity_property_get_datatype(&property, &out, is_ref, is_list); - // EXPECT_EQ(strcmp(out, "TEXT"), 0); - // EXPECT_FALSE(*is_ref); - // EXPECT_FALSE(*is_list); + 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); @@ -573,9 +582,13 @@ TEST_F(test_ccaosdb, test_property) { caosdb_entity_property_get_unit(&property, &out); EXPECT_EQ(strcmp(out, "some_unit"), 0); - // TODO(fspreck) - // caosdb_entity_property_get_string_value(&property, &out); - // EXPECT_EQ(strcmp(out, "some_value"), 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); @@ -585,7 +598,6 @@ TEST_F(test_ccaosdb, test_property) { EXPECT_EQ(return_code, 0); } -// TODO(fspreck) TEST_F(test_ccaosdb, test_string_list_property) { caosdb_entity_property property; @@ -605,26 +617,39 @@ TEST_F(test_ccaosdb, test_string_list_property) { return_code = caosdb_entity_property_set_value(&property, &in_value); EXPECT_EQ(return_code, 0); - // TODO(fspreck) - // char *out = nullptr; // NOLINT - // bool is_ref[] = {false}; // NOLINT - // bool is_list[] = {false}; // NOLINT - // return_code = caosdb_entity_property_get_datatype(&property, &out, is_ref, is_list); - // EXPECT_EQ(return_code, 0); - // EXPECT_EQ(strcmp(out, "TEXT"), 0); - // EXPECT_FALSE(*is_ref); - // EXPECT_TRUE(*is_list); + caosdb_entity_datatype out_type; + return_code = caosdb_entity_property_get_datatype(&property, &out_type); + EXPECT_EQ(return_code, 0); - // int length = -1; // NOLINT - // return_code = caosdb_entity_property_get_value_list_length(&property, &length); - // EXPECT_EQ(return_code, 0); - // EXPECT_EQ(length, 3); + 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"); - // for (int i = 0; i < length; i++) { - // return_code = caosdb_entity_property_get_string_list_value_at(&property, &out, i); - // EXPECT_EQ(return_code, 0); - // EXPECT_EQ(strcmp(value_list[i], out), 0); // NOLINT - // } + 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); @@ -651,27 +676,40 @@ TEST_F(test_ccaosdb, test_int_list_property) { return_code = caosdb_entity_property_set_value(&property, &in_value); EXPECT_EQ(return_code, 0); - // TODO(fspreck) - // char *dt_out = nullptr; // NOLINT - // bool is_ref[] = {false}; // NOLINT - // bool is_list[] = {false}; // NOLINT - // return_code = caosdb_entity_property_get_datatype(&property, &dt_out, is_ref, is_list); - // EXPECT_EQ(return_code, 0); - // EXPECT_STREQ(dt_out, "INTEGER"); - // EXPECT_FALSE(*is_ref); - // EXPECT_TRUE(*is_list); - - // int length = -1; // NOLINT - // return_code = caosdb_entity_property_get_value_list_length(&property, &length); - // EXPECT_EQ(return_code, 0); - // EXPECT_EQ(length, 3); - - // for (int i = 0; i < length; i++) { - // int64_t out = -1; - // return_code = caosdb_entity_property_get_int_list_value_at(&property, &out, i); - // EXPECT_EQ(return_code, 0); - // EXPECT_EQ(value_list[i], out); // NOLINT - // } + 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); @@ -698,27 +736,40 @@ TEST_F(test_ccaosdb, test_bool_list_property) { return_code = caosdb_entity_property_set_value(&property, &in_value); EXPECT_EQ(return_code, 0); - // TODO(fspreck) - // char *dt_out = nullptr; // NOLINT - // bool is_ref[] = {false}; // NOLINT - // bool is_list[] = {false}; // NOLINT - // return_code = caosdb_entity_property_get_datatype(&property, &dt_out, is_ref, is_list); - // EXPECT_EQ(return_code, 0); - // EXPECT_STREQ(dt_out, "BOOLEAN"); - // EXPECT_FALSE(*is_ref); - // EXPECT_TRUE(*is_list); - - // int length = -1; // NOLINT - // return_code = caosdb_entity_property_get_value_list_length(&property, &length); - // EXPECT_EQ(return_code, 0); - // EXPECT_EQ(length, 3); - - // for (int i = 0; i < length; i++) { - // bool out = true; - // return_code = caosdb_entity_property_get_boolean_list_value_at(&property, &out, i); - // EXPECT_EQ(return_code, 0); - // EXPECT_EQ(value_list[i], out); // NOLINT - // } + 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); @@ -787,21 +838,37 @@ TEST_F(test_ccaosdb, test_entity_with_parent_and_property) { caosdb_entity_property_get_name(&output_property, &out); EXPECT_EQ(strcmp(in, out), 0); - // TODO(fspreck) - // bool is_list[] = {false}; // NOLINT - // bool is_ref[] = {false}; // NOLINT - // caosdb_entity_property_get_datatype(&input_property, &in, is_ref, is_list); - // EXPECT_FALSE(*is_list); - // EXPECT_FALSE(*is_ref); - // caosdb_entity_property_get_datatype(&output_property, &out, is_ref, is_list); - // EXPECT_FALSE(*is_list); - // EXPECT_FALSE(*is_ref); - // EXPECT_EQ(strcmp(in, out), 0); - - // TODO(fspreck) - // caosdb_entity_property_get_string_value(&input_property, &in); - // caosdb_entity_property_get_string_value(&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); -- GitLab