diff --git a/include/caosdb/data_type.h b/include/caosdb/data_type.h index c084a338272532db652b4d7df85cfa42940c6bb1..ced4399936e387823e944b5bf5794b9840e7e1e2 100644 --- a/include/caosdb/data_type.h +++ b/include/caosdb/data_type.h @@ -158,7 +158,8 @@ 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>() { diff --git a/include/caosdb/entity.h b/include/caosdb/entity.h index 2f6e4ed96670f3c3e16749f3a2a590d491b29abe..0c8892dee990f613b3bd5e0fe8473a313b1f3ffc 100644 --- a/include/caosdb/entity.h +++ b/include/caosdb/entity.h @@ -383,6 +383,40 @@ class Parent : public ScalarProtoMessageWrapper<ProtoParent> { public: explicit inline Parent(ProtoParent *wrapped) : ScalarProtoMessageWrapper<ProtoParent>(wrapped){}; Parent() : ScalarProtoMessageWrapper<ProtoParent>(){}; + ~Parent() = default; + + /** + * Copy constructor. + */ + inline Parent(const Parent &other) : Parent(ProtoMessageWrapper<ProtoParent>::CopyProtoMessage(other.wrapped)) { } + + /** + * Move constructor. + */ + inline Parent(Parent &&other) : Parent(other.wrapped) { + other.wrapped = nullptr; + } + + /** + * Copy assignment operator. + */ + inline auto operator=(const Parent &other) -> Parent & { + if(this != &other) { + this->wrapped->CopyFrom(*other.wrapped); + } + return *this; + } + + /** + * Move assignment operator. + */ + inline auto operator=(Parent &&other) -> Parent & { + this->wrapped = other.wrapped; + other.wrapped = nullptr; + return *this; + } + + /** * Return the id of the parent entity. @@ -497,6 +531,8 @@ public: : ScalarProtoMessageWrapper<ProtoProperty>(), value(static_cast<ProtoValue *>(nullptr)), data_type(static_cast<ProtoDataType *>(nullptr)){}; + ~Property() = default; + /** * Return the id of this property */ @@ -648,13 +684,16 @@ 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(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. + * <li> Entity(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. * */ class Entity : public ScalarProtoMessageWrapper<ProtoEntity> { @@ -698,6 +737,8 @@ public: parents.wrapped = this->wrapped->mutable_parents(); }; + ~Entity() = default; + /** * Move constructor. */ diff --git a/include/caosdb/transaction.h b/include/caosdb/transaction.h index 634c7a0d01b613e4fb6ad4d56e037693d9abc2c2..28942df1d9163aa6b931ad4d0b8fc41e833104dc 100644 --- a/include/caosdb/transaction.h +++ b/include/caosdb/transaction.h @@ -379,8 +379,8 @@ public: * * A client may request the current status at any time via GetStatus(). * - * Use WaitForIt() to join the back-ground execution of this transaction, otherwise the behaviour - * of getting the ResultSet is undefined. + * Use WaitForIt() to join the back-ground execution of this transaction, + * otherwise the behaviour of getting the ResultSet is undefined. */ auto ExecuteAsynchronously() noexcept -> StatusCode; @@ -388,8 +388,8 @@ public: * Join the background execution and return the status when the execution * terminates. * - * Use this after ExecuteAsynchronously(), otherwise the TransactionStatus still remains - * EXECUTING. + * Use this after ExecuteAsynchronously(), otherwise the TransactionStatus + * still remains EXECUTING. */ [[nodiscard]] auto WaitForIt() const noexcept -> TransactionStatus; @@ -409,7 +409,8 @@ public: [[nodiscard]] inline auto GetResultSet() const noexcept -> const ResultSet & { if (!this->result_set) { CAOSDB_LOG_ERROR(logger_name) - << "GetResultSet was called before the transaction has terminated. This is a programming " + << "GetResultSet was called before the transaction has terminated. " + "This is a programming " "error of the code which uses the transaction."; // TODO(tf) This is a really bad SegFault factory. When the transaction // terminates and the result_set is being overriden, the unique_ptr @@ -426,7 +427,8 @@ public: * This method releases the ResultSet from the transaction leaving it in a * currupted state. * - * This method can be called only once and only after the transaction has terminated. + * This method can be called only once and only after the transaction has + * terminated. * * Otherwise, this method has undefined behavior. */ diff --git a/include/caosdb/utility.h b/include/caosdb/utility.h index 5af1b491c0b5b9d48606ba6b46130b3ef3de1d9c..b7f775ada8f0635e670b0953ceac6d066cdc5253 100644 --- a/include/caosdb/utility.h +++ b/include/caosdb/utility.h @@ -49,7 +49,8 @@ using boost::json::stream_parser; using boost::json::value; /** - * @brief Get the name of the enum value. May be useful for higher-order CaosDB clients. + * @brief Get the name of the enum value. May be useful for higher-order CaosDB + * clients. */ template <typename Enum> auto getEnumNameFromValue(Enum v) -> std::string { if (std::is_same_v<std::underlying_type_t<Enum>, int>) { @@ -69,7 +70,8 @@ template <> auto getEnumNameFromValue<caosdb::entity::Role>(caosdb::entity::Role /** * @brief Get the enum value from a string. * - * @detail May be useful for higher-order CaosDB clients and only makes sense if specialized. + * @detail May be useful for higher-order CaosDB clients and only makes sense if + * specialized. */ template <typename Enum> auto getEnumValueFromName(const std::string &name) -> Enum; diff --git a/include/ccaosdb.h b/include/ccaosdb.h index 4d1b99dd151fbf09a53d9b80c0963ee3d3368c67..9f56134eab016244238c277b0f9c8437a5daa8d0 100644 --- a/include/ccaosdb.h +++ b/include/ccaosdb.h @@ -307,7 +307,8 @@ int caosdb_transaction_transaction_get_result_set(caosdb_transaction_transaction * * The transactions is spoiled after this action and should not be used anymore. * - * Note: The result_set has to be deleted via caosdb_transaction_delete_result_set. + * Note: The result_set has to be deleted via + * caosdb_transaction_delete_result_set. * * EXPERT USE ONLY. Only use it when you know what you are doing. */ diff --git a/requirements.txt b/requirements.txt index 4bf95a29fc3c9d28931a25664c2456f22041be3f..76372a8dce89684cb0c5490ff3d5afa916ea2f9c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,28 +1,29 @@ attrs==21.2.0 bottle==0.12.19 -certifi==2021.5.30 +certifi==2021.10.8 chardet==4.0.0 +charset-normalizer==2.0.7 colorama==0.4.4 -conan==1.40.3 -deprecation==2.0.7 -distro==1.5.0 +conan==1.41.0 +deprecation==2.1.0 +distro==1.6.0 fasteners==0.16.3 future==0.18.2 -idna==2.10 +idna==3.2 Jinja2==2.11.3 -jsonschema==3.2.0 +jsonschema==4.1.0 MarkupSafe==2.0.1 node-semver==0.6.1 -packaging==20.9 +packaging==21.0 patch-ng==1.17.4 pluginbase==1.0.1 -Pygments==2.9.0 +Pygments==2.10.0 PyJWT==1.7.1 pyparsing==2.4.7 pyrsistent==0.18.0 -python-dateutil==2.8.1 +python-dateutil==2.8.2 PyYAML==5.4.1 -requests==2.25.1 -six==1.15.0 -tqdm==4.61.1 -urllib3==1.25.11 +requests==2.26.0 +six==1.16.0 +tqdm==4.62.3 +urllib3==1.26.7 diff --git a/src/caosdb/status_code_description.cpp b/src/caosdb/status_code_description.cpp index d5e08e7820ca0f7380723087570f838465a9c261..b1134422cd4ac972b8d2df5b7bb7b9185451a9d5 100644 --- a/src/caosdb/status_code_description.cpp +++ b/src/caosdb/status_code_description.cpp @@ -64,56 +64,86 @@ auto get_status_description(int code) -> const std::string & { {StatusCode::CANCELLED, "The operation was canceled (typically by the caller)."}, {StatusCode::UNKNOWN, "Unknown error. This is typically a bug (server or client)."}, {StatusCode::INVALID_ARGUMENT, - "Client specified an invalid argument. Note that this differs from FAILED_PRECONDITION. " - "INVALID_ARGUMENT indicates arguments that are problematic regardless of the state of the " + "Client specified an invalid argument. Note that this differs from " + "FAILED_PRECONDITION. " + "INVALID_ARGUMENT indicates arguments that are problematic regardless of " + "the state of the " "system (e.g., a malformed file name)."}, {StatusCode::DEADLINE_EXCEEDED, - "Deadline expired before operation could complete. For operations that change the state of " - "the system, this error may be returned even if the operation has completed successfully. For " - "example, a successful response from a server could have been delayed long enough for the " + "Deadline expired before operation could complete. For operations that " + "change the state of " + "the system, this error may be returned even if the operation has " + "completed successfully. For " + "example, a successful response from a server could have been delayed " + "long enough for the " "deadline to expire."}, {StatusCode::NOT_FOUND, "Some requested entity (e.g., file or directory) was not found."}, - {StatusCode::ALREADY_EXISTS, - "Some entity that we attempted to create (e.g., file or directory) already exists."}, + {StatusCode::ALREADY_EXISTS, "Some entity that we attempted to create " + "(e.g., file or directory) already exists."}, {StatusCode::PERMISSION_DENIED, - "The caller does not have permission to execute the specified operation. PERMISSION_DENIED " - "must not be used for rejections caused by exhausting some resource (use RESOURCE_EXHAUSTED " - "instead for those errors). PERMISSION_DENIED must not be used if the caller can not be " + "The caller does not have permission to execute the specified operation. " + "PERMISSION_DENIED " + "must not be used for rejections caused by exhausting some resource (use " + "RESOURCE_EXHAUSTED " + "instead for those errors). PERMISSION_DENIED must not be used if the " + "caller can not be " "identified (use UNAUTHENTICATED instead for those errors)."}, {StatusCode::RESOURCE_EXHAUSTED, "Some resource has been exhausted, perhaps a per-user quota, " "or perhaps the entire file system is out of space."}, {StatusCode::FAILED_PRECONDITION, - "Operation was rejected because the system is not in a state required for the operation's " - "execution. For example, directory to be deleted may be non-empty, an rmdir operation is " - "applied to a non-directory, etc. A litmus test that may help a service implementor in " - "deciding between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE: (a) Use UNAVAILABLE if the " - "client can retry just the failing call. (b) Use ABORTED if the client should retry at a " - "higher-level (e.g., restarting a read-modify-write sequence). (c) Use FAILED_PRECONDITION if " - "the client should not retry until the system state has been explicitly fixed. E.g., if an " - "'rmdir' fails because the directory is non-empty, FAILED_PRECONDITION should be returned " - "since the client should not retry unless they have first fixed up the directory by deleting " - "files from it. (d) Use FAILED_PRECONDITION if the client performs conditional REST " - "Get/Update/Delete on a resource and the resource on the server does not match the condition. " + "Operation was rejected because the system is not in a state required for " + "the operation's " + "execution. For example, directory to be deleted may be non-empty, an " + "rmdir operation is " + "applied to a non-directory, etc. A litmus test that may help a service " + "implementor in " + "deciding between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE: (a) Use " + "UNAVAILABLE if the " + "client can retry just the failing call. (b) Use ABORTED if the client " + "should retry at a " + "higher-level (e.g., restarting a read-modify-write sequence). (c) Use " + "FAILED_PRECONDITION if " + "the client should not retry until the system state has been explicitly " + "fixed. E.g., if an " + "'rmdir' fails because the directory is non-empty, FAILED_PRECONDITION " + "should be returned " + "since the client should not retry unless they have first fixed up the " + "directory by deleting " + "files from it. (d) Use FAILED_PRECONDITION if the client performs " + "conditional REST " + "Get/Update/Delete on a resource and the resource on the server does not " + "match the condition. " "E.g., conflicting read-modify-write on the same resource."}, - {StatusCode::ABORTED, - "The operation was aborted, typically due to a concurrency issue like sequencer check " - "failures, transaction aborts, etc. See litmus test above for deciding between " - "FAILED_PRECONDITION, ABORTED, and UNAVAILABLE."}, + {StatusCode::ABORTED, "The operation was aborted, typically due to a " + "concurrency issue like sequencer check " + "failures, transaction aborts, etc. See litmus test " + "above for deciding between " + "FAILED_PRECONDITION, ABORTED, and UNAVAILABLE."}, {StatusCode::OUT_OF_RANGE, - "Operation was attempted past the valid range. E.g., seeking or reading past end of file. " - "Unlike INVALID_ARGUMENT, this error indicates a problem that may be fixed if the system " - "state changes. For example, a 32-bit file system will generate INVALID_ARGUMENT if asked to " - "read at an offset that is not in the range [0,2^32-1], but it will generate OUT_OF_RANGE if " - "asked to read from an offset past the current file size. There is a fair bit of overlap " - "between FAILED_PRECONDITION and OUT_OF_RANGE. We recommend using OUT_OF_RANGE (the more " - "specific error) when it applies so that callers who are iterating through a space can easily " + "Operation was attempted past the valid range. E.g., seeking or reading " + "past end of file. " + "Unlike INVALID_ARGUMENT, this error indicates a problem that may be " + "fixed if the system " + "state changes. For example, a 32-bit file system will generate " + "INVALID_ARGUMENT if asked to " + "read at an offset that is not in the range [0,2^32-1], but it will " + "generate OUT_OF_RANGE if " + "asked to read from an offset past the current file size. There is a fair " + "bit of overlap " + "between FAILED_PRECONDITION and OUT_OF_RANGE. We recommend using " + "OUT_OF_RANGE (the more " + "specific error) when it applies so that callers who are iterating " + "through a space can easily " "look for an OUT_OF_RANGE error to detect when they are done."}, {StatusCode::UNIMPLEMENTED, - "Operation is not implemented or not supported/enabled in this service. In contrast to " - "UNSUPPORTED_FEATURE (which is a client error) this error indicates that the server does not " + "Operation is not implemented or not supported/enabled in this service. " + "In contrast to " + "UNSUPPORTED_FEATURE (which is a client error) this error indicates that " + "the server does not " "support this operation."}, {StatusCode::INTERNAL, - "Internal errors. Means some invariants expected by underlying System has been broken. If you " + "Internal errors. Means some invariants expected by underlying System has " + "been broken. If you " "see one of these errors, Something is very broken. "}, {StatusCode::DATA_LOSS, "Unrecoverable data loss or corruption."}, @@ -156,9 +186,10 @@ auto get_status_description(int code) -> const std::string & { "to delete the old pointee first."}, {StatusCode::ENUM_MAPPING_ERROR, "The role, importance, or datatype you specified does not exist."}, - {StatusCode::SPOILED, - "The object has been used in a way that left it in a corrupted state. This does not indicate " - "any form of misuse. It just indicates that the object is spoiled for further use now."}, + {StatusCode::SPOILED, "The object has been used in a way that left it in a " + "corrupted state. This does not indicate " + "any form of misuse. It just indicates that the " + "object is spoiled for further use now."}, {StatusCode::OTHER_CLIENT_ERROR, "This is code is reserved to errors raised by other clients wrapping the " "C++ client (or its Extern C interface). This should never occur when " diff --git a/src/caosdb/utility.cpp b/src/caosdb/utility.cpp index a4ed293adb6bd4fbfb10860e03185aeb567de163..85c4e733b0f023f01f145f0aae3af1eb4cd69ddc 100644 --- a/src/caosdb/utility.cpp +++ b/src/caosdb/utility.cpp @@ -57,7 +57,8 @@ template <> auto getEnumValueFromName<Importance>(const std::string &name) -> Im // TODO (dh): Whereas this does not? // auto result = std::find(caosdb::entity::importance_names.cbegin(), // caosdb::entity::importance_names.cend(), - // [name](const auto& entry){ return entry.second == name; }); + // [name](const auto& entry){ return entry.second == + // name; }); // Workaround: plaint old iteration: for (auto const &entry : caosdb::entity::importance_names) { if (entry.second == name) { diff --git a/src/ccaosdb.cpp b/src/ccaosdb.cpp index 77759fce1d216f215dfccd343aa8202b2ec911fa..06606521a544b92858fb635e1b92f3c79357c8b3 100644 --- a/src/ccaosdb.cpp +++ b/src/ccaosdb.cpp @@ -574,7 +574,8 @@ ERROR_RETURN_CODE( auto *wrapped_transaction = static_cast<caosdb::transaction::Transaction *>(transaction->wrapped_transaction); out->wrapped_result_set = (void *)(wrapped_transaction->ReleaseResultSet()); - // out is the owner now, that are the semantics of ReleaseResultSet + // out is the owner now, that are the semantics of + // ReleaseResultSet out->_deletable = true; return 0; }) @@ -621,7 +622,8 @@ ERROR_RETURN_CODE( auto *wrapped_result_set = static_cast<caosdb::transaction::MultiResultSet *>(result_set->wrapped_result_set); entity->wrapped_entity = wrapped_result_set->release_at(index); - // entity is the owner now. That are the semantics of release_at. + // entity is the owner now. That are the semantics of + // release_at. entity->_deletable = true; return 0; }) diff --git a/src/ccaosdbcli.c b/src/ccaosdbcli.c index e3ce7dea431441b5ef6f827f02f8741681f631c2..e06dff51bcc62fcc8ae2bc4e2db53647d6c3de06 100644 --- a/src/ccaosdbcli.c +++ b/src/ccaosdbcli.c @@ -4,25 +4,30 @@ int main(void) { int status = 0; // last function return value - printf("CaosDB C client (libcaosdb %d.%d.%d)\nWe don't miss the H of caos.\n\n", - LIBCAOSDB_VERSION_MAJOR, LIBCAOSDB_VERSION_MINOR, LIBCAOSDB_VERSION_PATCH); + printf( + "CaosDB C client (libcaosdb %d.%d.%d)\nWe don't miss the H of caos.\n\n", + LIBCAOSDB_VERSION_MAJOR, LIBCAOSDB_VERSION_MINOR, LIBCAOSDB_VERSION_PATCH); caosdb_connection_connection connection; - status = caosdb_connection_connection_manager_get_default_connection(&connection); + status = + caosdb_connection_connection_manager_get_default_connection(&connection); if (status != 0) { - printf("An error occured: ERROR %d - %s\n", status, caosdb_get_status_description(status)); + printf("An error occured: ERROR %d - %s\n", status, + caosdb_get_status_description(status)); return status; } caosdb_info_version_info version_info; status = caosdb_connection_get_version_info(&version_info, &connection); if (status != 0) { - printf("An error occured: ERROR %d - %s\n", status, caosdb_get_status_description(status)); + printf("An error occured: ERROR %d - %s\n", status, + caosdb_get_status_description(status)); return status; } - printf("Server version: %d.%d.%d-%s-%s\n", version_info.major, version_info.minor, - version_info.patch, version_info.pre_release, version_info.build); + printf("Server version: %d.%d.%d-%s-%s\n", version_info.major, + version_info.minor, version_info.patch, version_info.pre_release, + version_info.build); return 0; } diff --git a/test/test_data_type.cpp b/test/test_data_type.cpp index 78e5100f3ce984ece46918df4aca9ffb8f1d2522..5ea3a295d4c912f25f6db624241a9147b61610cd 100644 --- a/test/test_data_type.cpp +++ b/test/test_data_type.cpp @@ -129,4 +129,22 @@ TEST(test_data_type, test_data_type_to_string) { EXPECT_EQ(data_type3.ToString(), "{\n \"atomicDataType\": \"ATOMIC_DATA_TYPE_INTEGER\"\n}\n"); } +TEST(test_data_type, data_type_copy_constructor) { + DataType data_type("person", true); + const auto dt_string = data_type.ToString(); + + // copy + const DataType copy_data_type(data_type); + EXPECT_EQ(copy_data_type, data_type); +} + +// TEST(test_data_type, data_type_move_constructor) { +//} + +// TEST(test_data_type, data_type_copy_assignment) { +//} + +// TEST(test_data_type, data_type_move_assignment) { +//} + } // namespace caosdb::entity diff --git a/test/test_entity.cpp b/test/test_entity.cpp index 2b9a8d900864617abc23bdd1d05782a1eb65c60b..eb02abb25b539d1576502d764b04b8ab6c9762d1 100644 --- a/test/test_entity.cpp +++ b/test/test_entity.cpp @@ -109,7 +109,8 @@ 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); } @@ -142,7 +143,7 @@ TEST(test_entity, test_append_property) { EXPECT_EQ(prop.GetDataType(), same_prop.GetDataType()); } -TEST(test_entity, test_copy_constructor) { +TEST(test_entity, entity_copy_constructor) { ProtoParent parent; parent.set_description("the parent desc"); parent.set_id("the parent id"); @@ -197,7 +198,7 @@ TEST(test_entity, test_copy_constructor) { EXPECT_NE(this_entity.ToString(), copy_entity.ToString()); } -TEST(test_entity, test_move_constructor) { +TEST(test_entity, entity_move_constructor) { ProtoParent parent; parent.set_description("the parent desc"); parent.set_id("the parent id"); @@ -263,7 +264,7 @@ TEST(test_entity, test_move_constructor) { EXPECT_NE(move_entity.ToString(), copy_entity.ToString()); } -TEST(test_entity, test_property_copy_constructor) { +TEST(test_entity, property_copy_constructor) { Property prop; prop.SetName("prop_name"); prop.SetId("prop_id"); @@ -283,7 +284,7 @@ TEST(test_entity, test_property_copy_constructor) { EXPECT_EQ(prop.GetDataType(), other_prop.GetDataType()); } -TEST(test_entity, test_property_copy_assignment) { +TEST(test_entity, property_copy_assignment) { Property prop; prop.SetName("prop_name"); prop.SetId("prop_id"); @@ -308,7 +309,7 @@ TEST(test_entity, test_property_copy_assignment) { EXPECT_EQ(other_prop.GetName(), "other_prop_name"); } -TEST(test_entity, test_property_move_assignment) { +TEST(test_entity, property_move_assignment) { Property prop; prop.SetName("prop_name"); prop.SetId("prop_id"); @@ -343,6 +344,127 @@ TEST(test_entity, test_property_move_assignment) { EXPECT_EQ(other_prop.GetName(), "other_prop_name"); } +TEST(test_entity, property_move_constructor) { + Property prop; + prop.SetName("prop_name"); + prop.SetId("prop_id"); + prop.SetImportance(Importance::RECOMMENDED); + prop.SetValue("prop_value"); + prop.SetUnit("prop_unit"); + prop.SetDataType("prop_dtype"); + const auto prop_string = prop.ToString(); + + // we compare the moved one with this one + const Property copy_prop(prop); + + Property other_prop(std::move(prop)); + EXPECT_NE(prop, copy_prop); // NOLINT + EXPECT_NE(prop, other_prop); // NOLINT + EXPECT_NE(prop.ToString(), prop_string); // NOLINT + + EXPECT_EQ(copy_prop.ToString(), prop_string); + EXPECT_EQ(other_prop.ToString(), prop_string); + EXPECT_EQ(copy_prop, other_prop); + EXPECT_EQ(copy_prop.GetName(), other_prop.GetName()); + EXPECT_EQ(copy_prop.GetId(), other_prop.GetId()); + EXPECT_EQ(copy_prop.GetImportance(), other_prop.GetImportance()); + EXPECT_EQ(copy_prop.GetValue().ToString(), other_prop.GetValue().ToString()); + EXPECT_EQ(copy_prop.GetUnit(), other_prop.GetUnit()); + EXPECT_EQ(copy_prop.GetDataType(), other_prop.GetDataType()); + + other_prop.SetName("other_prop_name"); + EXPECT_NE(copy_prop, other_prop); + EXPECT_NE(copy_prop.GetName(), other_prop.GetName()); + EXPECT_EQ(copy_prop.GetName(), "prop_name"); + EXPECT_EQ(other_prop.GetName(), "other_prop_name"); +} + +TEST(test_entity, parent_copy_constructor) { + Parent parent; + parent.SetId("par_id"); + parent.SetName("par_name"); + + // copy + const Parent copy_parent(parent); + EXPECT_EQ(copy_parent, parent); + EXPECT_EQ(copy_parent.GetId(), parent.GetId()); + EXPECT_EQ(copy_parent.GetName(), parent.GetName()); + + // change something + parent.SetName("new_name"); + EXPECT_NE(copy_parent, parent); + EXPECT_EQ(copy_parent.GetId(), parent.GetId()); + EXPECT_NE(copy_parent.GetName(), parent.GetName()); +} + +TEST(test_entity, parent_move_constructor) { + Parent parent; + parent.SetId("par_id"); + parent.SetName("par_name"); + const auto parent_string = parent.ToString(); + + // copy for testing + const Parent copy_parent = parent; + // move + Parent move_parent(std::move(parent)); + EXPECT_NE(parent, copy_parent); // NOLINT + EXPECT_NE(parent, move_parent); // NOLINT + EXPECT_NE(parent.ToString(), parent_string); // NOLINT + + EXPECT_EQ(copy_parent, move_parent); + EXPECT_EQ(copy_parent.GetId(), move_parent.GetId()); + EXPECT_EQ(copy_parent.GetName(), move_parent.GetName()); + + // change something + move_parent.SetName("new_name"); + EXPECT_NE(copy_parent, move_parent); + EXPECT_EQ(copy_parent.GetId(), move_parent.GetId()); + EXPECT_NE(copy_parent.GetName(), move_parent.GetName()); +} + +TEST(test_entity, parent_copy_assignment) { + Parent parent; + parent.SetId("par_id"); + parent.SetName("par_name"); + + // copy + const Parent copy_parent = parent; + EXPECT_EQ(copy_parent, parent); + EXPECT_EQ(copy_parent.GetId(), parent.GetId()); + EXPECT_EQ(copy_parent.GetName(), parent.GetName()); + + // change something + parent.SetName("new_name"); + EXPECT_NE(copy_parent, parent); + EXPECT_EQ(copy_parent.GetId(), parent.GetId()); + EXPECT_NE(copy_parent.GetName(), parent.GetName()); +} + +TEST(test_entity, parent_move_assignment) { + Parent parent; + parent.SetId("par_id"); + parent.SetName("par_name"); + const auto parent_string = parent.ToString(); + + // copy for testing + const Parent copy_parent = parent; + // move + Parent move_parent = std::move(parent); + EXPECT_NE(parent, copy_parent); // NOLINT + EXPECT_NE(parent, move_parent); // NOLINT + EXPECT_NE(parent.ToString(), parent_string); // NOLINT + + EXPECT_EQ(copy_parent, move_parent); + EXPECT_EQ(copy_parent.GetId(), move_parent.GetId()); + EXPECT_EQ(copy_parent.GetName(), move_parent.GetName()); + + // change something + move_parent.SetName("new_name"); + EXPECT_NE(copy_parent, move_parent); + EXPECT_EQ(copy_parent.GetId(), move_parent.GetId()); + EXPECT_NE(copy_parent.GetName(), move_parent.GetName()); +} + TEST(test_entity, test_copy_to) { auto entity = Entity(); entity.SetRole(Role::RECORD); @@ -693,7 +815,7 @@ TEST(test_entity, test_add_file) { EXPECT_EQ(entity.SetLocalPath(TEST_DATA_DIR + "/test.json"), StatusCode::SUCCESS); } -TEST(test_entity, test_move_assign) { +TEST(test_entity, entity_move_assignment) { Entity entity1; entity1.SetRole(Role::RECORD_TYPE); entity1.SetName("E1"); @@ -757,8 +879,8 @@ TEST(test_entity, test_property_to_string) { EXPECT_EQ(property.ToString(), "{}\n"); property.SetDataType(AtomicDataType::DOUBLE); - EXPECT_EQ(property.ToString(), - "{\n \"dataType\": {\n \"atomicDataType\": \"ATOMIC_DATA_TYPE_DOUBLE\"\n }\n}\n"); + EXPECT_EQ(property.ToString(), "{\n \"dataType\": {\n \"atomicDataType\": " + "\"ATOMIC_DATA_TYPE_DOUBLE\"\n }\n}\n"); } TEST(test_entity, test_parents_to_string) { diff --git a/test/test_value.cpp b/test/test_value.cpp index 241f2bd0ce2a7291184a79cdaa0612f2b99fa204..ecf87d01f816048ebce95a0f63262a38fe8c8244 100644 --- a/test/test_value.cpp +++ b/test/test_value.cpp @@ -188,9 +188,9 @@ TEST(test_value, test_value_to_string) { EXPECT_EQ(value3.ToString(), "{\n \"scalarValue\": {\n \"doubleValue\": 2.6\n }\n}\n"); Value value4(std::vector<bool>{true, false}); - EXPECT_EQ(value4.ToString(), - "{\n \"listValues\": {\n \"values\": [\n {\n \"booleanValue\": true\n },\n " - "{\n \"booleanValue\": false\n }\n ]\n }\n}\n"); + EXPECT_EQ(value4.ToString(), "{\n \"listValues\": {\n \"values\": [\n {\n " + "\"booleanValue\": true\n },\n " + "{\n \"booleanValue\": false\n }\n ]\n }\n}\n"); } } // namespace caosdb::entity