diff --git a/include/caosdb/entity.h b/include/caosdb/entity.h index 2d098c54d3ba0e3730bcc552c4bb4616eab6c448..6d542d4f885f38eea214763754e3bbfebe624286 100644 --- a/include/caosdb/entity.h +++ b/include/caosdb/entity.h @@ -319,9 +319,10 @@ public: [[nodiscard]] inline auto HasErrors() const -> bool { return this->errors.wrapped->size() > 0; } - // TODO(fspreck) These two need implementations... - [[nodiscard]] auto GetWarnings() const -> const Messages &; - [[nodiscard]] auto GetInfos() const -> const Messages &; + [[nodiscard]] auto GetWarnings() const -> const Messages & { + return warnings; + } + [[nodiscard]] auto GetInfos() const -> const Messages & { return infos; } inline auto ToString() const -> const std::string { google::protobuf::util::JsonOptions options; diff --git a/include/caosdb/exceptions.h b/include/caosdb/exceptions.h index a1e7e40b4449e21147826655cd055ff197392f42..d60f7a162b6a36d803a37c1e40dfc43d21a3f172 100644 --- a/include/caosdb/exceptions.h +++ b/include/caosdb/exceptions.h @@ -64,9 +64,11 @@ public: * @brief The transaction terminated unsuccessfully. */ class TransactionError : public Exception { -public: +protected: TransactionError(StatusCode code, const std::string &what_arg) : Exception(code, what_arg) {} + +public: explicit TransactionError(const std::string &what_arg) : Exception(StatusCode::GENERIC_TRANSACTION_ERROR, what_arg) {} }; diff --git a/src/caosdb/configuration.cpp b/src/caosdb/configuration.cpp index c6c1e9ce9bf8e16e4d8c3b40fefac4de7aaad212..c24df459f5494232d2fadd2719a0be2d237b8f24 100644 --- a/src/caosdb/configuration.cpp +++ b/src/caosdb/configuration.cpp @@ -463,15 +463,18 @@ auto ConfigurationManager::GetConnection(const std::string &name) const "' has not been defined."); } -auto ConfigurationManager::InitializeDefaults() -> int { +// TODO(tf) This has apparently a cognitive complexity of 34>25 (threshold). +auto ConfigurationManager::InitializeDefaults() -> int { // NOLINT // find the configuration file... std::unique_ptr<path> configuration_file_path; - for (const std::string &configuration_file : + for (const char *const &configuration_file : caosdb::LIBCAOSDB_CONFIGURATION_FILES_PRECEDENCE) { - if (configuration_file == "$CAOSDB_CLIENT_CONFIGURATION") { + if (strcmp(configuration_file, "$CAOSDB_CLIENT_CONFIGURATION") == 0) { // user specified a file via the environment variable - const auto *from_env_var = getenv("CAOSDB_CLIENT_CONFIGURATION"); + // TODO(tf) make this thread-secure (concurrency-mt-unsafe) + const auto *from_env_var = + getenv("CAOSDB_CLIENT_CONFIGURATION"); // NOLINT if (from_env_var != nullptr) { configuration_file_path = std::make_unique<path>(from_env_var); if (exists(*configuration_file_path)) { diff --git a/src/caosdb/entity.cpp b/src/caosdb/entity.cpp index 0ef5172842eacde57f63f3c81ceb1876390dcee6..24fd3824aa20c35a253f4cdd6d2020e180e1a1c7 100644 --- a/src/caosdb/entity.cpp +++ b/src/caosdb/entity.cpp @@ -80,6 +80,9 @@ Entity::Entity() : wrapped(Entity::CreateProtoEntity()) { Entity::Entity(IdResponse *idResponse) : Entity() { this->wrapped->set_id(idResponse->id()); this->wrapped->mutable_errors()->Swap(idResponse->mutable_entity_errors()); + this->wrapped->mutable_warnings()->Swap( + idResponse->mutable_entity_warnings()); + this->wrapped->mutable_infos()->Swap(idResponse->mutable_entity_infos()); } auto Entity::SetId(const std::string &id) -> void { this->wrapped->set_id(id); } diff --git a/test/test_configuration.cpp b/test/test_configuration.cpp index abc797fbe97fb408e0ff05ea5deab2a8581f194a..3c047850e82da2a30039cc0c46361542284af38b 100644 --- a/test/test_configuration.cpp +++ b/test/test_configuration.cpp @@ -38,7 +38,8 @@ protected: void TearDown() override { ConfigurationManager::Clear(); } }; -TEST_F(test_configuration, load_json) { +// TODO(tf) cogintive complexity > 25 (threshold) +TEST_F(test_configuration, load_json) { // NOLINT ConfigurationManager::LoadSingleJSONConfiguration(TEST_DATA_DIR + "/test_caosdb_client.json"); EXPECT_THROW_MESSAGE( @@ -52,7 +53,9 @@ TEST_F(test_configuration, load_json) { ConfigurationManager::Clear(); } -TEST_F(test_configuration, get_default_connection_configuration_error) { +// TODO(tf) cognitive complexity again +TEST_F(test_configuration, // NOLINT + get_default_connection_configuration_error) { // NOLINT EXPECT_THROW_MESSAGE(ConfigurationManager::GetDefaultConnectionName(), ConfigurationError, "This CaosDB client has not been configured."); diff --git a/test/test_connection.cpp b/test/test_connection.cpp index 7c2efab9566d58c709c060e4206fc0d193ac75df..6c5fa0b58f224233a1826d7605a8c94e8270a7e9 100644 --- a/test/test_connection.cpp +++ b/test/test_connection.cpp @@ -65,7 +65,8 @@ TEST_F(test_connection, configure_ssl_localhost_8080) { EXPECT_TRUE(sslcc != nullptr); } -TEST_F(test_connection, connection_manager_unknown_connection) { +// TODO(tf) cognitive complexity > 25 (threshold) +TEST_F(test_connection, connection_manager_unknown_connection) { // NOLINT EXPECT_THROW_MESSAGE(ConnectionManager::GetConnection("test"), caosdb::exceptions::UnknownConnectionError, "No connection named 'test' present."); diff --git a/test/test_entity.cpp b/test/test_entity.cpp index 00ec73cafd7a94c87d36198dbc54e9d3a7102e50..1f3adf99b0702f7a369e20b42d2f8a3af3ea94dd 100644 --- a/test/test_entity.cpp +++ b/test/test_entity.cpp @@ -73,7 +73,8 @@ TEST(test_entity, test_insert_entity) { EXPECT_EQ(entity.GetVersionId(), "version_id"); } -TEST(test_entity, test_from_id_response) { +// TODO(tf) cognitive complexity > 25 (threshold) +TEST(test_entity, test_from_id_response) { // NOLINT IdResponse idResponse; idResponse.set_id("entity_id"); auto *error = idResponse.add_entity_errors(); @@ -88,6 +89,26 @@ TEST(test_entity, test_from_id_response) { EXPECT_EQ(entity.GetErrors().At(0).GetDescription(), "error_desc"); EXPECT_EQ(entity.GetErrors().At(0).GetCode(), MessageCode::ENTITY_DOES_NOT_EXIST); + + IdResponse idr_warnings_and_infos; + idr_warnings_and_infos.set_id("other_entity_id"); + auto *warning = idr_warnings_and_infos.add_entity_warnings(); + warning->set_description("warning_desc"); + warning->set_code(MessageCode::ENTITY_HAS_NO_PROPERTIES); + auto *info = idr_warnings_and_infos.add_entity_infos(); + info->set_description("info_desc"); + info->set_code(MessageCode::UNSPECIFIED); + + Entity other_ent(&idr_warnings_and_infos); + + EXPECT_EQ(other_ent.GetId(), "other_entity_id"); + EXPECT_EQ(other_ent.GetWarnings().Size(), 1); + EXPECT_EQ(other_ent.GetWarnings().At(0).GetDescription(), "warning_desc"); + EXPECT_EQ(other_ent.GetWarnings().At(0).GetCode(), + MessageCode::ENTITY_HAS_NO_PROPERTIES); + EXPECT_EQ(other_ent.GetInfos().Size(), 1); + EXPECT_EQ(other_ent.GetInfos().At(0).GetDescription(), "info_desc"); + EXPECT_EQ(other_ent.GetInfos().At(0).GetCode(), MessageCode::UNSPECIFIED); } } // namespace caosdb::entity diff --git a/test/test_protobuf.cpp b/test/test_protobuf.cpp index 9dc957a2f85cd95ce3ead5f59ab8c10868582003..61b85c89ae1fc1f5ee0a101ff4f8b4438275648f 100644 --- a/test/test_protobuf.cpp +++ b/test/test_protobuf.cpp @@ -29,7 +29,8 @@ namespace caosdb { using caosdb::entity::v1alpha1::Entity; using caosdb::entity::v1alpha1::Message; -TEST(test_protobuf, test_swap_trivial) { +// TODO(tf) cognitive complexity > 25 (threshold) +TEST(test_protobuf, test_swap_trivial) { // NOLINT Message message_source; message_source.set_code(1234); message_source.set_description("desc"); @@ -49,7 +50,8 @@ TEST(test_protobuf, test_swap_trivial) { EXPECT_EQ(message_destination.description(), "desc"); } -TEST(test_protobuf, test_swap_nested) { +// TODO(tf) cognitive complexity again +TEST(test_protobuf, test_swap_nested) { // NOLINT Entity entity_source; entity_source.set_id("entity_id"); auto *version_source = entity_source.mutable_version(); diff --git a/test/test_transaction.cpp b/test/test_transaction.cpp index 118208595ea5d100dacb8302be555772c8fcd80e..b0f77d074d5d3bbcef2c05d020378992061a98d5 100644 --- a/test/test_transaction.cpp +++ b/test/test_transaction.cpp @@ -41,7 +41,8 @@ using caosdb::exceptions::ConnectionError; using caosdb::transaction::UniqueResult; using ProtoEntity = caosdb::entity::v1alpha1::Entity; -TEST(test_transaction, create_transaction) { +// TODO(tf) cognitive complexity > 25 (threshold) +TEST(test_transaction, create_transaction) { // NOLINT const auto *host = "localhost"; auto configuration = InsecureConnectionConfiguration(host, 8000); Connection connection(configuration); diff --git a/test/test_utility.cpp b/test/test_utility.cpp index eec62641af4b2c704ad121cf83d3450cafc5aa2a..cb6021dc631c90b49ab8c3538f2b09fcc47723a3 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -20,12 +20,12 @@ * */ +#include "gmock/gmock-matchers.h" // for ElementsAre, EXPECT_THAT +#include "boost/beast/core/detail/base64.hpp" // for encoded_size #include "boost/json/object.hpp" // for object #include "boost/json/value.hpp" // for value #include "caosdb/utility.h" // for base64_encode, load_js... #include "caosdb_test_utility.h" // for TEST_DATA_DIR -#include "gmock/gmock-matchers.h" // for ElementsAre, EXPECT_THAT -#include <boost/beast/core/detail/base64.hpp> // for encoded_size #include <gtest/gtest-message.h> // for Message #include <gtest/gtest-test-part.h> // for TestPartResult, SuiteA... #include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, TestInfo