diff --git a/include/caosdb/entity.h b/include/caosdb/entity.h index 8a8a1d71f769c324103d6685f1c7e6257a2528d8..5f4c8990ee870c8af51253870263a9ff2b1aa8e7 100644 --- a/include/caosdb/entity.h +++ b/include/caosdb/entity.h @@ -45,11 +45,11 @@ #include <google/protobuf/message.h> // for RepeatedPtrField #include <google/protobuf/util/json_util.h> // for MessageToJson... #include <iosfwd> // for streamsize -#include <iterator> // for iterator, output_iterato... -#include <map> // for map -#include <random> // for mt19937, rand... -#include <stdexcept> // for out_of_range -#include <string> // for string, basic... +#include <iterator> // for iterator, output_iterato... +#include <map> // for map +#include <random> // for mt19937, rand... +#include <stdexcept> // for out_of_range +#include <string> // for string, basic... namespace caosdb::entity { using boost::filesystem::exists; @@ -113,11 +113,11 @@ public: /** * Return the current size of the container. */ - [[nodiscard]] inline auto Size() const -> int { return wrapped->size(); } + [[nodiscard]] inline auto size() const -> int { return wrapped->size(); } /** * Return a const reference to the element at the given index. */ - [[nodiscard]] inline auto At(int index) const -> const T & { + [[nodiscard]] inline auto at(int index) const -> const T & { return *mutable_at(index); } @@ -125,8 +125,8 @@ public: * Return a mutable pointer to the element at the given index. */ [[nodiscard]] inline auto mutable_at(int index) const -> T * { - if (index >= Size() || index < 0) { - throw std::out_of_range("Container has size " + std::to_string(Size())); + if (index >= size() || index < 0) { + throw std::out_of_range("Container has size " + std::to_string(size())); } if (cache.count(index) == 0) { cache.emplace(index, T(&(wrapped->at(index)))); @@ -186,7 +186,7 @@ protected: // shift all indices in the cache above index (such that the values do not // get deleted/copied because this could destroy pointers (c-interface). - for (int i = index + 1; i < Size(); i++) { + for (int i = index + 1; i < size(); i++) { if (cache.count(i) > 0) { auto handle = cache.extract(i); handle.key()--; @@ -254,7 +254,7 @@ auto RepeatedPtrFieldWrapper<T, P>::begin() template <typename T, typename P> auto RepeatedPtrFieldWrapper<T, P>::end() -> RepeatedPtrFieldWrapper<T, P>::iterator { - return RepeatedPtrFieldWrapper<T, P>::iterator(this, Size()); + return RepeatedPtrFieldWrapper<T, P>::iterator(this, size()); } template <typename T, typename P> @@ -266,7 +266,7 @@ auto RepeatedPtrFieldWrapper<T, P>::begin() const template <typename T, typename P> auto RepeatedPtrFieldWrapper<T, P>::end() const -> const RepeatedPtrFieldWrapper<T, P>::iterator { - return RepeatedPtrFieldWrapper<T, P>::iterator(this, Size()); + return RepeatedPtrFieldWrapper<T, P>::iterator(this, size()); } /** diff --git a/src/ccaosdb.cpp b/src/ccaosdb.cpp index e42d04b94adfdfc4c0e595b43a5e078ceea5f744..3765ddf815cd786cf22e4e0e9ea971423de4cede 100644 --- a/src/ccaosdb.cpp +++ b/src/ccaosdb.cpp @@ -589,12 +589,16 @@ ERROR_RETURN_CODE(GENERIC_ERROR, }) CAOSDB_ENTITY_GET(id, strcpy(out, wrapped_entity->GetId().c_str());) -CAOSDB_ENTITY_GET(role, strcpy(out, wrapped_entity->GetRole().c_str());) +// TODO(fspreck) +// CAOSDB_ENTITY_GET(role, strcpy(out, wrapped_entity->GetRole().c_str());) CAOSDB_ENTITY_GET(name, strcpy(out, wrapped_entity->GetName().c_str());) CAOSDB_ENTITY_GET(description, strcpy(out, wrapped_entity->GetDescription().c_str());) -CAOSDB_ENTITY_GET(datatype, strcpy(out, wrapped_entity->GetDatatype().c_str());) -CAOSDB_ENTITY_GET(value, strcpy(out, wrapped_entity->GetValue().c_str());) +// TODO(fspreck) +// CAOSDB_ENTITY_GET(datatype, strcpy(out, +// wrapped_entity->GetDatatype().c_str());) +// TODO(fspreck) +// CAOSDB_ENTITY_GET(value, strcpy(out, wrapped_entity->GetValue().c_str());) CAOSDB_ENTITY_GET(unit, strcpy(out, wrapped_entity->GetUnit().c_str());) CAOSDB_ENTITY_GET(version_id, strcpy(out, wrapped_entity->GetVersionId().c_str());) @@ -606,7 +610,7 @@ ERROR_RETURN_CODE( { auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); - *out = wrapped_entity->GetErrors().Size(); + *out = wrapped_entity->GetErrors().size(); return 0; }) @@ -632,7 +636,7 @@ ERROR_RETURN_CODE( { auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); - *out = wrapped_entity->GetWarnings().Size(); + *out = wrapped_entity->GetWarnings().size(); return 0; }) @@ -658,7 +662,7 @@ ERROR_RETURN_CODE( { auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); - *out = wrapped_entity->GetInfos().Size(); + *out = wrapped_entity->GetInfos().size(); return 0; }) @@ -684,7 +688,7 @@ ERROR_RETURN_CODE( { auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); - *out = wrapped_entity->GetProperties().Size(); + *out = wrapped_entity->GetProperties().size(); return 0; }) @@ -710,7 +714,7 @@ ERROR_RETURN_CODE( { auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); - *out = wrapped_entity->GetParents().Size(); + *out = wrapped_entity->GetParents().size(); return 0; }) @@ -738,12 +742,16 @@ CAOSDB_PROPERTY_GET(id, strcpy(out, wrapped_property->GetId().c_str());) CAOSDB_PROPERTY_GET(name, strcpy(out, wrapped_property->GetName().c_str());) CAOSDB_PROPERTY_GET(description, strcpy(out, wrapped_property->GetDescription().c_str());) -CAOSDB_PROPERTY_GET(importance, - strcpy(out, wrapped_property->GetImportance().c_str());) -CAOSDB_PROPERTY_GET(datatype, - strcpy(out, wrapped_property->GetDatatype().c_str());) +// TODO(fspreck) +// CAOSDB_PROPERTY_GET(importance, +// strcpy(out, wrapped_property->GetImportance().c_str());) +// TODO(fspreck) +// CAOSDB_PROPERTY_GET(datatype, +// strcpy(out, wrapped_property->GetDatatype().c_str());) CAOSDB_PROPERTY_GET(unit, strcpy(out, wrapped_property->GetUnit().c_str());) -CAOSDB_PROPERTY_GET(value, strcpy(out, wrapped_property->GetValue().c_str());) +// TODO(fspreck) +// CAOSDB_PROPERTY_GET(value, strcpy(out, +// wrapped_property->GetValue().c_str());) ERROR_RETURN_CODE( GENERIC_ERROR, @@ -766,14 +774,18 @@ ERROR_RETURN_CODE( return 0; }) -CAOSDB_ENTITY_SET(role, role, wrapped_entity->SetRole(std::string(role));) +// TODO(fspreck) +// CAOSDB_ENTITY_SET(role, role, wrapped_entity->SetRole(std::string(role));) CAOSDB_ENTITY_SET(name, name, wrapped_entity->SetName(std::string(name));) CAOSDB_ENTITY_SET(description, description, wrapped_entity->SetDescription(std::string(description));) -CAOSDB_ENTITY_SET(datatype, datatype, - wrapped_entity->SetDatatype(std::string(datatype));) +// TODO(fspreck) +// CAOSDB_ENTITY_SET(datatype, datatype, +// wrapped_entity->SetDataType(std::string(datatype));) CAOSDB_ENTITY_SET(unit, unit, wrapped_entity->SetUnit(std::string(unit));) -CAOSDB_ENTITY_SET(value, value, wrapped_entity->SetValue(std::string(value));) +// TODO(fspreck) +// CAOSDB_ENTITY_SET(value, value, +// wrapped_entity->SetValue(std::string(value));) ERROR_RETURN_CODE( GENERIC_ERROR, @@ -827,11 +839,14 @@ CAOSDB_PARENT_SET(name, name, wrapped_parent->SetName(std::string(name));) CAOSDB_PROPERTY_SET(name, name, wrapped_property->SetName(std::string(name));) CAOSDB_PROPERTY_SET(id, id, wrapped_property->SetId(std::string(id));) -CAOSDB_PROPERTY_SET(datatype, datatype, - wrapped_property->SetDatatype(std::string(datatype));) -CAOSDB_PROPERTY_SET(importance, importance, - wrapped_property->SetImportance(std::string(importance));) +// TODO(fspreck) +// CAOSDB_PROPERTY_SET(datatype, datatype, +// wrapped_property->SetDataType(std::string(datatype));) +// TODO(fspreck) +// CAOSDB_PROPERTY_SET(importance, importance, +// wrapped_property->SetImportance(std::string(importance));) CAOSDB_PROPERTY_SET(unit, unit, wrapped_property->SetUnit(std::string(unit));) -CAOSDB_PROPERTY_SET(value, value, - wrapped_property->SetValue(std::string(value));) +// TODO(fspreck) +// CAOSDB_PROPERTY_SET(value, value, +// wrapped_property->SetValue(std::string(value));) } diff --git a/test/test_ccaosdb.cpp b/test/test_ccaosdb.cpp index 1009cc5962c6a309052509e36d39c3f6ee97ea98..15d0ed651f8f88cc55508078dd32fc700ef1669b 100644 --- a/test/test_ccaosdb.cpp +++ b/test/test_ccaosdb.cpp @@ -170,25 +170,28 @@ TEST_F(test_ccaosdb, test_entity) { EXPECT_EQ(return_code, 0); EXPECT_EQ(strcmp(out, "length"), 0); - caosdb_entity_entity_set_role(&entity, "Property"); - caosdb_entity_entity_get_role(&entity, out); - EXPECT_EQ(strcmp(out, "Property"), 0); + // TODO(fspreck) + // 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_entity_set_datatype(&entity, "DOUBLE"); - caosdb_entity_entity_get_datatype(&entity, out); - EXPECT_EQ(strcmp(out, "DOUBLE"), 0); + // TODO(fspreck) + // caosdb_entity_entity_set_datatype(&entity, "DOUBLE"); + // caosdb_entity_entity_get_datatype(&entity, out); + // EXPECT_EQ(strcmp(out, "DOUBLE"), 0); caosdb_entity_entity_set_unit(&entity, "m"); caosdb_entity_entity_get_unit(&entity, out); EXPECT_EQ(strcmp(out, "m"), 0); - caosdb_entity_entity_set_value(&entity, "5.0"); - caosdb_entity_entity_get_value(&entity, out); - EXPECT_EQ(strcmp(out, "5.0"), 0); + // TODO(fspreck) + // caosdb_entity_entity_set_value(&entity, "5.0"); + // caosdb_entity_entity_get_value(&entity, out); + // EXPECT_EQ(strcmp(out, "5.0"), 0); return_code = caosdb_entity_delete_entity(&entity); EXPECT_EQ(return_code, 0); @@ -222,10 +225,13 @@ TEST_F(test_ccaosdb, test_property) { caosdb_entity_property_set_id(&property, "some_id"); caosdb_entity_property_set_name(&property, "some_name"); - caosdb_entity_property_set_datatype(&property, "some_datatype"); - caosdb_entity_property_set_importance(&property, "some_importance"); + // TODO(fspreck) + // caosdb_entity_property_set_datatype(&property, "some_datatype"); + // TODO(fspreck) + // caosdb_entity_property_set_importance(&property, "some_importance"); caosdb_entity_property_set_unit(&property, "some_unit"); - caosdb_entity_property_set_value(&property, "some_value"); + // TODO(fspreck) + // caosdb_entity_property_set_value(&property, "some_value"); char out[255] = {"a"}; // NOLINT caosdb_entity_property_get_id(&property, out); @@ -234,17 +240,20 @@ TEST_F(test_ccaosdb, test_property) { caosdb_entity_property_get_name(&property, out); EXPECT_EQ(strcmp(out, "some_name"), 0); - caosdb_entity_property_get_datatype(&property, out); - EXPECT_EQ(strcmp(out, "some_datatype"), 0); + // TODO(fspreck) + // caosdb_entity_property_get_datatype(&property, out); + // EXPECT_EQ(strcmp(out, "some_datatype"), 0); - caosdb_entity_property_get_importance(&property, out); - EXPECT_EQ(strcmp(out, "some_importance"), 0); + // TODO(fspreck) + // caosdb_entity_property_get_importance(&property, out); + // EXPECT_EQ(strcmp(out, "some_importance"), 0); caosdb_entity_property_get_unit(&property, out); EXPECT_EQ(strcmp(out, "some_unit"), 0); - caosdb_entity_property_get_value(&property, out); - EXPECT_EQ(strcmp(out, "some_value"), 0); + // TODO(fspreck) + // caosdb_entity_property_get_value(&property, out); + // EXPECT_EQ(strcmp(out, "some_value"), 0); return_code = caosdb_entity_delete_property(&property); EXPECT_EQ(return_code, 0); @@ -265,8 +274,10 @@ TEST_F(test_ccaosdb, test_entity_with_parent_and_property) { caosdb_entity_property_set_id(&input_property, "property_id"); caosdb_entity_property_set_name(&input_property, "property_name"); - caosdb_entity_property_set_datatype(&input_property, "property_datatype"); - caosdb_entity_property_set_value(&input_property, "property_value"); + // TODO(fspreck) + // caosdb_entity_property_set_datatype(&input_property, "property_datatype"); + // TODO(fspreck) + // caosdb_entity_property_set_value(&input_property, "property_value"); caosdb_entity_entity entity; return_code = caosdb_entity_create_entity(&entity); @@ -311,13 +322,15 @@ TEST_F(test_ccaosdb, test_entity_with_parent_and_property) { caosdb_entity_property_get_name(&output_property, out); EXPECT_EQ(strcmp(in, out), 0); - caosdb_entity_property_get_datatype(&input_property, in); - caosdb_entity_property_get_datatype(&output_property, out); - EXPECT_EQ(strcmp(in, out), 0); + // TODO(fspreck) + // caosdb_entity_property_get_datatype(&input_property, in); + // caosdb_entity_property_get_datatype(&output_property, out); + // EXPECT_EQ(strcmp(in, out), 0); - caosdb_entity_property_get_value(&input_property, in); - caosdb_entity_property_get_value(&output_property, out); - EXPECT_EQ(strcmp(in, out), 0); + // TODO(fspreck) + // caosdb_entity_property_get_value(&input_property, in); + // caosdb_entity_property_get_value(&output_property, out); + // EXPECT_EQ(strcmp(in, out), 0); std::cout << "Comparing parent..." << std::endl; caosdb_entity_parent output_parent; diff --git a/test/test_entity.cpp b/test/test_entity.cpp index 0d45f9d1bd6d3def95ce17d895681ca4c527ee4a..634e3c4c8345010e06bd2cf5cd124aebb81c4efd 100644 --- a/test/test_entity.cpp +++ b/test/test_entity.cpp @@ -40,8 +40,8 @@ #include <gtest/gtest-test-part.h> // for TestPartResult, Sui... #include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ #include <iostream> -#include <memory> // for allocator, shared_ptr -#include <string> // for operator+, string +#include <memory> // for allocator, shared_ptr +#include <string> // for operator+, string namespace caosdb::entity { using caosdb::entity::v1alpha1::IdResponse; @@ -105,7 +105,7 @@ TEST(test_entity, test_append_property) { entity.AppendProperty(prop); EXPECT_EQ(entity.GetProperties().size(), 1); - auto same_prop = entity.GetProperties().at(0); + auto &same_prop = entity.GetProperties().at(0); EXPECT_EQ(prop.GetName(), same_prop.GetName()); EXPECT_EQ(prop.GetId(), same_prop.GetId()); @@ -233,7 +233,7 @@ TEST(test_entity, test_insert_with_property) { EXPECT_EQ(entity.GetProperties().size(), 1); - auto inserted_prop = entity.GetProperties().at(0); + auto &inserted_prop = entity.GetProperties().at(0); EXPECT_EQ(prop.GetName(), inserted_prop.GetName()); EXPECT_EQ(prop.GetId(), inserted_prop.GetId()); @@ -314,7 +314,7 @@ TEST(test_entity, test_remove_property) { // not initializing the cache } - ASSERT_EQ(entity.GetProperties().Size(), 5); + ASSERT_EQ(entity.GetProperties().size(), 5); for (int i = 5; i < 10; i++) { auto name = "PROPERTY-" + std::to_string(i); @@ -326,16 +326,16 @@ TEST(test_entity, test_remove_property) { EXPECT_EQ(property.GetName(), name); // initializing the cache - const auto &property_2 = entity.GetProperties().At(i); + const auto &property_2 = entity.GetProperties().at(i); EXPECT_EQ(property_2.GetName(), name); } - ASSERT_EQ(entity.GetProperties().Size(), 10); + ASSERT_EQ(entity.GetProperties().size(), 10); for (int i = 5; i < 10; i++) { // double checking the cache auto name = "PROPERTY-" + std::to_string(i); - const auto &property = entity.GetProperties().At(i); + const auto &property = entity.GetProperties().at(i); EXPECT_EQ(property.GetName(), name); } @@ -350,7 +350,7 @@ TEST(test_entity, test_remove_property) { // ^ // P0,P1,P2, P4,P5,P6, P8,P9 entity.RemoveProperty(6); - ASSERT_EQ(entity.GetProperties().Size(), 8); + ASSERT_EQ(entity.GetProperties().size(), 8); // AppendProperty another property // P0,P1,P2, P4,P5,P6, P8,P9 @@ -359,27 +359,27 @@ TEST(test_entity, test_remove_property) { Property property10; property10.SetName("PROPERTY-10"); entity.AppendProperty(property10); - ASSERT_EQ(entity.GetProperties().Size(), 9); + ASSERT_EQ(entity.GetProperties().size(), 9); std::cout << "[" << std::endl; for (int i = 0; i < 9; i++) { - std::cout << " " << entity.GetProperties().At(i).GetName() << ",\n"; + std::cout << " " << entity.GetProperties().at(i).GetName() << ",\n"; } std::cout << "]" << std::endl; for (int i = 0; i < 3; i++) { auto name = "PROPERTY-" + std::to_string(i); - const auto &property = entity.GetProperties().At(i); + const auto &property = entity.GetProperties().at(i); EXPECT_EQ(property.GetName(), name); } for (int i = 3; i < 6; i++) { auto name = "PROPERTY-" + std::to_string(i + 1); - const auto &property = entity.GetProperties().At(i); + const auto &property = entity.GetProperties().at(i); EXPECT_EQ(property.GetName(), name); } for (int i = 6; i < 9; i++) { auto name = "PROPERTY-" + std::to_string(i + 2); - const auto &property = entity.GetProperties().At(i); + const auto &property = entity.GetProperties().at(i); EXPECT_EQ(property.GetName(), name); } } @@ -395,7 +395,7 @@ TEST(test_entity, test_property_iterator) { entity.AppendProperty(property); } - ASSERT_EQ(entity.GetProperties().Size(), 5); + ASSERT_EQ(entity.GetProperties().size(), 5); int counter = 0; for (auto &property : entity.GetProperties()) { auto name = "PROPERTY-" + std::to_string(counter); diff --git a/test/test_protobuf.cpp b/test/test_protobuf.cpp index 1fa8911785dd96ace73f3f5f8813b42fa4d31829..102de737a4c49d240e411ddf43be0c92883989e9 100644 --- a/test/test_protobuf.cpp +++ b/test/test_protobuf.cpp @@ -104,11 +104,9 @@ TEST(test_protobuf, test_copy_nested) { Entity entity(&entity_destination); EXPECT_EQ(entity.GetDataType().AsReference().GetName(), "src_per"); - EXPECT_EQ(entity.ToString(), ""); Entity copy_entity(entity); EXPECT_EQ(copy_entity.GetDataType().AsReference().GetName(), "src_per"); - EXPECT_EQ(copy_entity.ToString(), ""); } } // namespace caosdb