diff --git a/include/caosdb/data_type.h b/include/caosdb/data_type.h index ced4399936e387823e944b5bf5794b9840e7e1e2..771ca8c0859c3b462d5fbf6575e2e2569af2d61f 100644 --- a/include/caosdb/data_type.h +++ b/include/caosdb/data_type.h @@ -158,8 +158,7 @@ public: DataType(ProtoDataType *wrapped) : ScalarProtoMessageWrapper<ProtoDataType>(wrapped) {} DataType() : ScalarProtoMessageWrapper<ProtoDataType>(static_cast<ProtoDataType *>(nullptr)) {} /** - * Create an AtomicDataType typed DataType. For references, use the - * std::string constructor. + * Create an AtomicDataType typed DataType. For references, use the std::string constructor. */ DataType(AtomicDataType data_type, bool list_type = false) : ScalarProtoMessageWrapper<ProtoDataType>() { @@ -182,6 +181,8 @@ public: } } + ~DataType() = default; + inline static auto ListOf(const AtomicDataType &atomic_data_type) -> DataType { return DataType(atomic_data_type, true); } diff --git a/include/caosdb/entity.h b/include/caosdb/entity.h index 0c8892dee990f613b3bd5e0fe8473a313b1f3ffc..0e34e43092652e05f495b3715dc337b9de6f6989 100644 --- a/include/caosdb/entity.h +++ b/include/caosdb/entity.h @@ -388,20 +388,19 @@ public: /** * Copy constructor. */ - inline Parent(const Parent &other) : Parent(ProtoMessageWrapper<ProtoParent>::CopyProtoMessage(other.wrapped)) { } + inline Parent(const Parent &other) + : Parent(ProtoMessageWrapper<ProtoParent>::CopyProtoMessage(other.wrapped)) {} /** * Move constructor. */ - inline Parent(Parent &&other) : Parent(other.wrapped) { - other.wrapped = nullptr; - } + inline Parent(Parent &&other) : Parent(other.wrapped) { other.wrapped = nullptr; } /** * Copy assignment operator. */ inline auto operator=(const Parent &other) -> Parent & { - if(this != &other) { + if (this != &other) { this->wrapped->CopyFrom(*other.wrapped); } return *this; @@ -416,8 +415,6 @@ public: return *this; } - - /** * Return the id of the parent entity. */ @@ -684,17 +681,17 @@ private: * Overview of the Constructors: * * <li> Entity() - Calls Entity(ProtoEntity *) with a fresh ProtoEntity - * <li> Entity(Entity) - Copy constructor, calls Entity(ProtoEntity *) after - * copying wrapped ProtoEntity of the original, then also copies all Messages. + * <li> Entity(const Entity&) - Copy constructor, calls Entity(ProtoEntity *) after + * copying wrapped ProtoEntity of the original, then also copies all Messages. * <li> Entity(ProtoEntity *) - The workhorse of the constructors. Initializes - * everything and does not call other Entity constructors. <li> - * Entity(EntityResponse *) - Constructor which is used by the Transaction class - * to create an Entity from the server's response, calls Entity(ProtoEntity). - * <li> Entity(IdResponse - * *) - Constructor which is used by the Transaction class to create an Entity - * from the servers's response. calls Entity(), then moves the data to the - * wrapped ProtoEntity. - * + * everything and does not call other Entity constructors. + * <li> Entity(EntityResponse *) - Constructor which is used by the Transaction class + * to create an Entity from the server's response, calls Entity(ProtoEntity). + * <li> Entity(IdResponse *) - Constructor which is used by the Transaction + * class to create an Entity from the servers's response. calls Entity(), + * then moves the data to the wrapped ProtoEntity. + * <li> Entity(Entity&&) - Move constructor, calls Entity(ProtoEntity *), then + * moves the messages and resets the original, */ class Entity : public ScalarProtoMessageWrapper<ProtoEntity> { public: @@ -746,8 +743,8 @@ public: original.wrapped = nullptr; original.value.wrapped = nullptr; original.data_type.wrapped = nullptr; - this->properties = std::move(original.properties); - this->parents = std::move(original.parents); + original.properties.wrapped = nullptr; + original.parents.wrapped = nullptr; this->errors = std::move(original.errors); this->warnings = std::move(original.warnings); this->infos = std::move(original.infos); diff --git a/test/test_data_type.cpp b/test/test_data_type.cpp index 5ea3a295d4c912f25f6db624241a9147b61610cd..cc59a6592fcc49a7d2b62413a8354bb9e3ba79e6 100644 --- a/test/test_data_type.cpp +++ b/test/test_data_type.cpp @@ -136,15 +136,47 @@ TEST(test_data_type, data_type_copy_constructor) { // copy const DataType copy_data_type(data_type); EXPECT_EQ(copy_data_type, data_type); + EXPECT_EQ(dt_string, copy_data_type.ToString()); } -// TEST(test_data_type, data_type_move_constructor) { -//} +TEST(test_data_type, data_type_move_constructor) { + DataType data_type("person", true); + const auto dt_string = data_type.ToString(); + + // copy for testing + const DataType copy_data_type(data_type); + // move + const DataType move_data_type(std::move(data_type)); + EXPECT_NE(data_type, copy_data_type); // NOLINT + EXPECT_NE(data_type.ToString(), dt_string); // NOLINT + + EXPECT_EQ(copy_data_type, move_data_type); + EXPECT_EQ(move_data_type.ToString(), dt_string); +} + +TEST(test_data_type, data_type_copy_assignment) { + DataType data_type("person", true); + const auto dt_string = data_type.ToString(); -// TEST(test_data_type, data_type_copy_assignment) { -//} + // copy + DataType copy_data_type = data_type; + EXPECT_EQ(copy_data_type, data_type); + EXPECT_EQ(dt_string, copy_data_type.ToString()); +} -// TEST(test_data_type, data_type_move_assignment) { -//} +TEST(test_data_type, data_type_move_assignment) { + DataType data_type("person", true); + const auto dt_string = data_type.ToString(); + + // copy for testing + const DataType copy_data_type(data_type); + // move + DataType move_data_type = std::move(data_type); + EXPECT_NE(data_type, copy_data_type); // NOLINT + EXPECT_NE(data_type.ToString(), dt_string); // NOLINT + + EXPECT_EQ(copy_data_type, move_data_type); + EXPECT_EQ(move_data_type.ToString(), dt_string); +} } // namespace caosdb::entity diff --git a/test/test_entity.cpp b/test/test_entity.cpp index eb02abb25b539d1576502d764b04b8ab6c9762d1..f66ee3f7185ee594f8465adde2e59fba2b62a328 100644 --- a/test/test_entity.cpp +++ b/test/test_entity.cpp @@ -109,8 +109,7 @@ TEST(test_entity, test_list_property_setters) { EXPECT_FALSE(dtype.IsAtomic()); // Should not be true anymore. EXPECT_FALSE(dtype.IsReference()); EXPECT_TRUE(dtype.IsList()); - EXPECT_NE(dtype.GetAsAtomic(), - AtomicDataType::DATETIME); // Should be overwritten. + EXPECT_NE(dtype.GetAsAtomic(), AtomicDataType::DATETIME); // Should be overwritten. EXPECT_TRUE(dtype.GetAsList().IsListOfAtomic()); EXPECT_EQ(dtype.GetAsList().GetAtomicDataType(), AtomicDataType::DOUBLE); }