diff --git a/CMakeLists.txt b/CMakeLists.txt index 197553a13adeacb6e262ed49b0b066facfdb32b7..104a19503abee599aea0708c5ef51a8a7a4b06fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ cmake_minimum_required(VERSION 3.13) -set(libcaosdb_VERSION 0.0.14) +set(libcaosdb_VERSION 0.0.15) set(libcaosdb_COMPATIBLE_SERVER_VERSION_MAJOR 0) set(libcaosdb_COMPATIBLE_SERVER_VERSION_MINOR 5) set(libcaosdb_COMPATIBLE_SERVER_VERSION_PATCH 0) diff --git a/conanfile.py b/conanfile.py index aa006179037080582da29fd3242c7f5c1541abce..1b50a4511ca456f6f08b58b182e0d2493793a249 100644 --- a/conanfile.py +++ b/conanfile.py @@ -3,7 +3,7 @@ from conans import ConanFile, CMake, tools class CaosdbConan(ConanFile): name = "caosdb" - version = "0.0.14" + version = "0.0.15" license = "AGPL-3.0-or-later" author = "Timm C. Fitschen <t.fitschen@indiscale.com>" url = "https://gitlab.indiscale.com/caosdb/src/caosdb-cpplib.git" diff --git a/include/caosdb/entity.h b/include/caosdb/entity.h index b9718f45cd202ad456f4752d318340574adf3098..d66c377e57e9e23f61315d58fee647032f39b5a8 100644 --- a/include/caosdb/entity.h +++ b/include/caosdb/entity.h @@ -516,10 +516,12 @@ public: auto SetValue(const double value) -> StatusCode; auto SetValue(const std::vector<std::string> &values) -> StatusCode; auto SetValue(const std::vector<char *> &values) -> StatusCode; - auto SetValue(const std::vector<int32_t> &values) -> StatusCode; + auto SetValue(const std::vector<int64_t> &values) -> StatusCode; + auto SetValue(const std::vector<int> &values) -> StatusCode; auto SetValue(const std::vector<double> &values) -> StatusCode; auto SetValue(const std::vector<bool> &values) -> StatusCode; - auto SetValue(const int32_t value) -> StatusCode; + auto SetValue(const int64_t value) -> StatusCode; + auto SetValue(const int value) -> StatusCode; auto SetValue(const bool value) -> StatusCode; /** @@ -673,10 +675,12 @@ public: auto SetValue(const double value) -> StatusCode; auto SetValue(const std::vector<std::string> &values) -> StatusCode; auto SetValue(const std::vector<char *> &values) -> StatusCode; - auto SetValue(const std::vector<int32_t> &values) -> StatusCode; + auto SetValue(const std::vector<int64_t> &values) -> StatusCode; + auto SetValue(const std::vector<int> &values) -> StatusCode; auto SetValue(const std::vector<double> &values) -> StatusCode; auto SetValue(const std::vector<bool> &values) -> StatusCode; - auto SetValue(const int32_t value) -> StatusCode; + auto SetValue(const int64_t value) -> StatusCode; + auto SetValue(const int value) -> StatusCode; auto SetValue(const bool value) -> StatusCode; auto SetUnit(const std::string &unit) -> void; diff --git a/include/caosdb/message_code.h b/include/caosdb/message_code.h index 367b5e9be8c43887e85436ac5491545329de9f10..a277656cd3848931bdc6dff6d3a802dab8da3282 100644 --- a/include/caosdb/message_code.h +++ b/include/caosdb/message_code.h @@ -44,13 +44,22 @@ enum MessageCode { ENTITY_DOES_NOT_EXIST = caosdb::entity::v1alpha1::MessageCode::MESSAGE_CODE_ENTITY_DOES_NOT_EXIST, ENTITY_HAS_NO_PROPERTIES = caosdb::entity::v1alpha1::MessageCode::MESSAGE_CODE_ENTITY_HAS_NO_PROPERTIES, + INTEGER_VALUE_OUT_OF_RANGE = + caosdb::entity::v1alpha1::MessageCode::MESSAGE_CODE_INTEGER_VALUE_OUT_OF_RANGE, + ENTITY_HAS_BEEN_DELETED_SUCCESSFULLY = + caosdb::entity::v1alpha1::MessageCode::MESSAGE_CODE_ENTITY_HAS_BEEN_DELETED_SUCCESSFULLY, }; [[nodiscard]] inline auto get_message_code(int code) noexcept -> MessageCode { // TODO(tf) smarter, less forgot-it-prone implementation - static MessageCode all_codes[] = {MessageCode::UNSPECIFIED, MessageCode::UNKNOWN, - MessageCode::ENTITY_DOES_NOT_EXIST, - MessageCode::ENTITY_HAS_NO_PROPERTIES}; + static MessageCode all_codes[] = { + MessageCode::UNSPECIFIED, + MessageCode::UNKNOWN, + MessageCode::ENTITY_DOES_NOT_EXIST, + MessageCode::ENTITY_HAS_NO_PROPERTIES, + MessageCode::INTEGER_VALUE_OUT_OF_RANGE, + MessageCode::ENTITY_HAS_BEEN_DELETED_SUCCESSFULLY, + }; for (MessageCode known_code : all_codes) { if (known_code == code) { diff --git a/include/caosdb/value.h b/include/caosdb/value.h index 2ec817e54ba32561d2c66c843a5451c143beacf0..e6ca1f33bcd43ce41acd44e4244c8d3825b43ebe 100644 --- a/include/caosdb/value.h +++ b/include/caosdb/value.h @@ -110,7 +110,7 @@ public: explicit inline Value(int64_t value) : ProtoMessageWrapper<ProtoValue>() { this->wrapped->mutable_scalar_value()->set_integer_value(value); } - explicit inline Value(int value) : Value((int64_t)value) {} + explicit inline Value(int value) : Value(static_cast<int64_t>(value)) {} explicit inline Value(bool value) : ProtoMessageWrapper<ProtoValue>() { this->wrapped->mutable_scalar_value()->set_boolean_value(value); } diff --git a/include/ccaosdb.h b/include/ccaosdb.h index 38b5d5ea0c7540610d7d5b21003f50c35f84568a..a60189522dfa4f5493fa201f63c3eb3df0d992d7 100644 --- a/include/ccaosdb.h +++ b/include/ccaosdb.h @@ -20,7 +20,7 @@ * */ -#include <cstdint> // for uint32_t +#include <cstdint> // for int64_t #ifdef __cplusplus extern "C" { @@ -347,11 +347,11 @@ int caosdb_entity_entity_get_datatype(caosdb_entity_entity *entity, char **name, bool *is_list); int caosdb_entity_entity_get_unit(caosdb_entity_entity *entity, char **out); -int caosdb_entity_entity_get_int_value(caosdb_entity_entity *entity, int32_t *out); +int caosdb_entity_entity_get_int_value(caosdb_entity_entity *entity, int64_t *out); int caosdb_entity_entity_get_double_value(caosdb_entity_entity *entity, double *out); int caosdb_entity_entity_get_boolean_value(caosdb_entity_entity *entity, bool *out); int caosdb_entity_entity_get_string_value(caosdb_entity_entity *entity, char **out); -int caosdb_entity_entity_get_int_list_value_at(caosdb_entity_entity *entity, int32_t *out, +int caosdb_entity_entity_get_int_list_value_at(caosdb_entity_entity *entity, int64_t *out, const int index); int caosdb_entity_entity_get_double_list_value_at(caosdb_entity_entity *entity, double *out, const int index); @@ -389,11 +389,11 @@ int caosdb_entity_property_get_datatype(caosdb_entity_property *property, char * bool *is_list); int caosdb_entity_property_get_unit(caosdb_entity_property *property, char **out); -int caosdb_entity_property_get_int_value(caosdb_entity_property *property, int32_t *out); +int caosdb_entity_property_get_int_value(caosdb_entity_property *property, int64_t *out); int caosdb_entity_property_get_double_value(caosdb_entity_property *property, double *out); int caosdb_entity_property_get_boolean_value(caosdb_entity_property *property, bool *out); int caosdb_entity_property_get_string_value(caosdb_entity_property *property, char **out); -int caosdb_entity_property_get_int_list_value_at(caosdb_entity_property *property, int32_t *out, +int caosdb_entity_property_get_int_list_value_at(caosdb_entity_property *property, int64_t *out, const int index); int caosdb_entity_property_get_double_list_value_at(caosdb_entity_property *property, double *out, const int index); @@ -431,11 +431,11 @@ int caosdb_entity_entity_set_datatype(caosdb_entity_entity *entity, const char * const bool is_ref, const bool is_list); int caosdb_entity_entity_set_unit(caosdb_entity_entity *entity, const char *unit); // TODO(fspreck) replace by more specific setters -int caosdb_entity_entity_set_int_value(caosdb_entity_entity *entity, const int32_t value); +int caosdb_entity_entity_set_int_value(caosdb_entity_entity *entity, const int64_t value); int caosdb_entity_entity_set_double_value(caosdb_entity_entity *entity, const double value); int caosdb_entity_entity_set_boolean_value(caosdb_entity_entity *entity, const bool value); int caosdb_entity_entity_set_string_value(caosdb_entity_entity *entity, const char *value); -int caosdb_entity_entity_set_int_list_value(caosdb_entity_entity *entity, const int32_t *value, +int caosdb_entity_entity_set_int_list_value(caosdb_entity_entity *entity, const int64_t *value, const int length); int caosdb_entity_entity_set_double_list_value(caosdb_entity_entity *entity, const double *value, const int length); @@ -460,12 +460,12 @@ int caosdb_entity_property_set_datatype(caosdb_entity_property *property, const 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_int_value(caosdb_entity_property *property, const int32_t value); +int caosdb_entity_property_set_int_value(caosdb_entity_property *property, const int64_t value); int caosdb_entity_property_set_double_value(caosdb_entity_property *property, const double value); int caosdb_entity_property_set_boolean_value(caosdb_entity_property *property, const bool value); int caosdb_entity_property_set_string_value(caosdb_entity_property *property, const char *value); int caosdb_entity_property_set_int_list_value(caosdb_entity_property *property, - const int32_t *value, const int length); + const int64_t *value, const int length); int caosdb_entity_property_set_double_list_value(caosdb_entity_property *property, const double *value, const int length); int caosdb_entity_property_set_boolean_list_value(caosdb_entity_property *property, diff --git a/proto b/proto index 1857e2fe407810baf18641429f54e5eee7b71e6a..75e826bd318c39e63d324f71e035f08355ffc51f 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 1857e2fe407810baf18641429f54e5eee7b71e6a +Subproject commit 75e826bd318c39e63d324f71e035f08355ffc51f diff --git a/src/caosdb/entity.cpp b/src/caosdb/entity.cpp index 18c9cb525b97ba9f638b2b300908cbc404f51cae..293368b268bc44d6db1bbd5e5983b6421fe6fbbb 100644 --- a/src/caosdb/entity.cpp +++ b/src/caosdb/entity.cpp @@ -124,7 +124,11 @@ auto Property::SetValue(const std::vector<char *> &values) -> StatusCode { return SetValue(Value(values)); } -auto Property::SetValue(const std::vector<int32_t> &values) -> StatusCode { +auto Property::SetValue(const std::vector<int64_t> &values) -> StatusCode { + return SetValue(Value(values)); +} + +auto Property::SetValue(const std::vector<int> &values) -> StatusCode { return SetValue(Value(values)); } @@ -136,7 +140,9 @@ auto Property::SetValue(const std::vector<bool> &values) -> StatusCode { return SetValue(Value(values)); } -auto Property::SetValue(const int32_t value) -> StatusCode { return SetValue(Value(value)); } +auto Property::SetValue(const int64_t value) -> StatusCode { return SetValue(Value(value)); } + +auto Property::SetValue(const int value) -> StatusCode { return SetValue(Value(value)); } auto Property::SetValue(const bool value) -> StatusCode { return SetValue(Value(value)); } @@ -222,7 +228,11 @@ auto Entity::SetValue(const std::vector<char *> &values) -> StatusCode { return SetValue(Value(values)); } -auto Entity::SetValue(const std::vector<int32_t> &values) -> StatusCode { +auto Entity::SetValue(const std::vector<int64_t> &values) -> StatusCode { + return SetValue(Value(values)); +} + +auto Entity::SetValue(const std::vector<int> &values) -> StatusCode { return SetValue(Value(values)); } @@ -234,7 +244,9 @@ auto Entity::SetValue(const std::vector<bool> &values) -> StatusCode { return SetValue(Value(values)); } -auto Entity::SetValue(const int32_t value) -> StatusCode { return SetValue(Value(value)); } +auto Entity::SetValue(const int64_t value) -> StatusCode { return SetValue(Value(value)); } + +auto Entity::SetValue(const int value) -> StatusCode { return SetValue(Value(value)); } auto Entity::SetValue(const bool value) -> StatusCode { return SetValue(Value(value)); } diff --git a/src/ccaosdb.cpp b/src/ccaosdb.cpp index b4c7ea1aac3aae3fd5ac539815883d0ea905d56f..61a5ed18908da60beaac09891b7874b55ac75b4d 100644 --- a/src/ccaosdb.cpp +++ b/src/ccaosdb.cpp @@ -641,7 +641,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_entity_get_int_value(caosdb_entity_entity *entity, - int32_t *out), + int64_t *out), { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); *out = wrapped_entity->GetValue().AsInteger(); @@ -667,7 +667,7 @@ CAOSDB_ENTITY_GET(string_value, GetValue().AsString()) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_entity_get_int_list_value_at(caosdb_entity_entity *entity, - int32_t *out, const int index), + int64_t *out, const int index), { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); auto value_list = wrapped_entity->GetValue().AsList(); @@ -684,8 +684,8 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_boolean_value_list_value_at( - caosdb_entity_entity *entity, bool *out, const int index), + int caosdb_entity_entity_get_boolean_list_value_at(caosdb_entity_entity *entity, + bool *out, const int index), { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); auto value_list = wrapped_entity->GetValue().AsList(); @@ -896,7 +896,7 @@ CAOSDB_PROPERTY_GET(unit, GetUnit()) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_property_get_int_value(caosdb_entity_property *property, - int32_t *out), + int64_t *out), { auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); *out = wrapped_property->GetValue().AsInteger(); @@ -922,7 +922,7 @@ CAOSDB_PROPERTY_GET(string_value, GetValue().AsString()) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_property_get_int_list_value_at(caosdb_entity_property *property, - int32_t *out, const int index), + int64_t *out, const int index), { auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); auto value_list = wrapped_property->GetValue().AsList(); @@ -939,7 +939,7 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_property_get_boolean_value_list_value_at( + int caosdb_entity_property_get_boolean_list_value_at( caosdb_entity_property *property, bool *out, const int index), { auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); @@ -1039,7 +1039,7 @@ CAOSDB_ENTITY_SET(unit, unit, wrapped_entity->SetUnit(std::string(unit));) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_entity_set_int_value(caosdb_entity_entity *entity, - const int32_t value), + const int64_t value), { auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); @@ -1079,12 +1079,12 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_entity_set_int_list_value(caosdb_entity_entity *entity, - const int32_t *value, + const int64_t *value, const int length), { auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); - std::vector<int32_t> value_list; + std::vector<int64_t> value_list; for (int i = 0; i < length; i++) { value_list.push_back(value[i]); } @@ -1226,7 +1226,7 @@ CAOSDB_PROPERTY_SET(unit, unit, wrapped_property->SetUnit(std::string(unit));) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_property_set_int_value(caosdb_entity_property *property, - const int32_t value), + const int64_t value), { auto *wrapped_property = static_cast<caosdb::entity::Property *>(property->wrapped_property); @@ -1266,12 +1266,12 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_property_set_int_list_value(caosdb_entity_property *property, - const int32_t *value, + const int64_t *value, const int length), { auto *wrapped_property = static_cast<caosdb::entity::Property *>(property->wrapped_property); - std::vector<int32_t> value_list; + std::vector<int64_t> value_list; for (int i = 0; i < length; i++) { value_list.push_back(value[i]); } diff --git a/test/test_ccaosdb.cpp b/test/test_ccaosdb.cpp index 90e72e59ebf69102c1abd2edbde1c1cbebc9ab79..cbf595f821f45807d8dd780cadd94bde47544fe8 100644 --- a/test/test_ccaosdb.cpp +++ b/test/test_ccaosdb.cpp @@ -24,6 +24,7 @@ #include "caosdb/status_code.h" // for StatusCode #include "caosdb_test_utility.h" // for EXPECT_THROW_MESSAGE, TEST_DATA_DIR #include "ccaosdb.h" // for caosdb_utility_get_env_fallback +#include <cstdint> // for int64_t #include <cstring> // for strcmp #include <gtest/gtest-message.h> // for Message #include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestFactoryImpl @@ -263,7 +264,7 @@ TEST_F(test_ccaosdb, test_property) { EXPECT_EQ(return_code, 0); } -TEST_F(test_ccaosdb, test_list_property) { +TEST_F(test_ccaosdb, test_string_list_property) { caosdb_entity_property property; int return_code(caosdb_entity_create_property(&property)); @@ -285,12 +286,12 @@ TEST_F(test_ccaosdb, test_list_property) { EXPECT_FALSE(*is_ref); EXPECT_TRUE(*is_list); - int length[] = {0}; // NOLINT - return_code = caosdb_entity_property_get_value_list_length(&property, length); + int length = -1; // NOLINT + return_code = caosdb_entity_property_get_value_list_length(&property, &length); EXPECT_EQ(return_code, 0); - EXPECT_EQ(*length, 3); + EXPECT_EQ(length, 3); - for (int i = 0; i < *length; i++) { + 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 @@ -300,6 +301,82 @@ TEST_F(test_ccaosdb, test_list_property) { 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); + + return_code = caosdb_entity_property_set_datatype(&property, "INTEGER", false, true); + EXPECT_EQ(return_code, 0); + + const int64_t value_list[] = {1, 2, 3}; // NOLINT + return_code = caosdb_entity_property_set_int_list_value(&property, &(value_list)[0], 3); + EXPECT_EQ(return_code, 0); + + 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 + } + + return_code = caosdb_entity_delete_property(&property); + 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); + + return_code = caosdb_entity_property_set_datatype(&property, "BOOLEAN", false, true); + EXPECT_EQ(return_code, 0); + + const bool value_list[] = {true, true, false}; // NOLINT + return_code = caosdb_entity_property_set_boolean_list_value(&property, &(value_list)[0], 3); + EXPECT_EQ(return_code, 0); + + 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 + } + + return_code = caosdb_entity_delete_property(&property); + 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));