diff --git a/conanfile.txt b/conanfile.txt index 73d40c4c18c07d61782b86f8399942a6fb8be0bf..387552f81d0bdc8a2187fede3a23ffe139688dfc 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,5 +1,5 @@ [requires] -caosdb/0.0.13 +caosdb/0.0.14 gtest/1.11.0 [generators] diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4e70ab9af108c9125fbe2d02f19fed848bd6312c..41e6bf3e29e115914f6732e87cb44818ed9c28ae 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -23,8 +23,9 @@ ####################################################################### set(test_cases test_connection - test_transaction test_list_properties + test_properties + test_transaction test_ccaosdb test_issues ) diff --git a/test/test_ccaosdb.cpp b/test/test_ccaosdb.cpp index c588d10aba92a055a1b7c784618c920802933051..bf3baf91749e1509cc5e8ba8db3b671a9809a760 100644 --- a/test/test_ccaosdb.cpp +++ b/test/test_ccaosdb.cpp @@ -18,19 +18,19 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include "caosdb/file_transmission/file_reader.h" // for FileReader #include "caosdb/file_transmission/file_writer.h" // for FileWriter -#include "caosdb/message_code.h" // for MessageCode -#include "caosdb/status_code.h" // for StatusCode -#include "ccaosdb.h" // for caosdb_info_version_info, caosdb_... -#include <boost/filesystem/path.hpp> // for path -#include <boost/filesystem/path_traits.hpp> // for filesystem -#include <cstring> // for strcmp -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for TestPartResult -#include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, SuiteApiResolver -#include <iostream> -#include <memory> // for allocator, unique_ptr +#include "caosdb/message_code.h" // for ENTITY_DOES_NOT_EXIST +#include "caosdb/status_code.h" // for GO_ON, StatusCode +#include "ccaosdb.h" // for caosdb_connection_... +#include <boost/filesystem/operations.hpp> // for remove +#include <boost/filesystem/path.hpp> // for path +#include <boost/filesystem/path_traits.hpp> // for filesystem +#include <cstring> // for strcmp +#include <gtest/gtest-message.h> // for Message +#include <gtest/gtest-test-part.h> // for TestPartResult +#include <gtest/gtest_pred_impl.h> // for EXPECT_EQ, TestInfo +#include <iostream> // for operator<<, endl +#include <string> // for allocator, string namespace fs = boost::filesystem; class test_ccaosdb : public ::testing::Test { diff --git a/test/test_issues.cpp b/test/test_issues.cpp index d8a39fdebf4fcc30ab9010936cc20e1a737283fd..4a2f67b742460750888aa6f6f172f5ddffb0a05c 100644 --- a/test/test_issues.cpp +++ b/test/test_issues.cpp @@ -1,56 +1,48 @@ -#include "caosdb/connection.h" // for Connection, ConnectionManager -#include "caosdb/data_type.h" // for AtomicDataType -#include "caosdb/entity.h" // for Entity, Messages, Message -#include "caosdb/file_transmission/file_reader.h" // for FileReader -#include "caosdb/file_transmission/file_writer.h" // for FileWriter -#include "caosdb/message_code.h" // for ENTITY_DOES_NOT_EXIST, Messag... -#include "caosdb/status_code.h" // for SUCCESS, StatusCode -#include "caosdb/transaction.h" // for Entity, Transaction,... -#include "caosdb/transaction_status.h" // for TransactionStatus, StatusCode -#include <boost/filesystem/operations.hpp> // for remove -#include <boost/filesystem/path.hpp> // for path -#include <boost/filesystem/path_traits.hpp> // for filesystem -#include <boost/lexical_cast.hpp> -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-spi.h> // for EXPECT_NONFATAL_FAILURE -#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver -#include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, AssertionResult -#include <iostream> -#include <memory> // for unique_ptr, allocator, __shar... -#include <string> // for string -#include <vector> // for vector - -namespace fs = boost::filesystem; +/* + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * Copyright (C) 2021 Daniel Hornung <d.hornung@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ +#include "caosdb/connection.h" // for Connection, Connec... +#include "caosdb/data_type.h" // for AtomicDataType +#include "caosdb/entity.h" // for Entity, Parent, Role +#include "caosdb/transaction.h" // for Transaction, Entity +#include "caosdb/transaction_status.h" // for TransactionStatus +#include <cstdint> // for int32_t +#include <gtest/gtest-message.h> // for Message +#include <gtest/gtest-spi.h> // for EXPECT_NONFATAL_FA... +#include <gtest/gtest-test-part.h> // for TestPartResult +#include <gtest/gtest_pred_impl.h> // for AssertionResult +#include <iostream> // for operator<<, endl +#include <memory> // for unique_ptr, allocator +#include <string> // for operator+, operator<< +#include <vector> // for vector + namespace caosdb::transaction { using caosdb::entity::AtomicDataType; using caosdb::entity::Entity; using caosdb::entity::Parent; using caosdb::entity::Role; -using caosdb::entity::Value; class test_issues : public ::testing::Test { public: // public utility functions // //////////////////////////////////////////////////////// - /** - * Generate a vector with useful values for testing. - */ - template <typename T> static auto generateValues() -> std::vector<T> { - std::vector<T> values = { - 0, 1, - // (T)6.91629132943846e-310, - std::numeric_limits<T>::max(), std::numeric_limits<T>::min(), - std::numeric_limits<T>::denorm_min(), std::numeric_limits<T>::lowest(), - std::numeric_limits<T>::epsilon() // 0 for integers, but who cares? - }; - - return values; - } - - template <typename T> static auto getValueAs(const Value & /*value*/) -> T { - throw std::logic_error("Template not implemented for this type."); - } static void DeleteEntities() { // delete all entities const auto &connection = @@ -71,31 +63,11 @@ public: } protected: - fs::path test_upload_file_1; - fs::path test_download_file_1; - // Fixture methods ////////////////////////////////////////////////////////// - void SetUp() override { - DeleteEntities(); - - test_upload_file_1 = fs::path("test_upload_file_1_delete_me.dat"); - test_download_file_1 = fs::path("test_download_file_1_delete_me.dat"); + void SetUp() override { DeleteEntities(); } - // fill the file that shall be uploaded - FileWriter writer(test_upload_file_1); - std::string buffer(1024, 'c'); - for (int i = 0; i < 8; i++) { - writer.write(buffer); - } - } - - void TearDown() override { - // delete files - fs::remove(test_upload_file_1); - fs::remove(test_download_file_1); - DeleteEntities(); - } + void TearDown() override { DeleteEntities(); } }; /* diff --git a/test/test_list_properties.cpp b/test/test_list_properties.cpp index ace6a93355761a53b92d7c93df8b115511acda36..89d3deae3e7c263a9cbce9c5f11e5f42b5979e03 100644 --- a/test/test_list_properties.cpp +++ b/test/test_list_properties.cpp @@ -110,7 +110,7 @@ TEST_F(test_list_properties, insert_list_of_text) { EXPECT_TRUE(value.IsList()); EXPECT_EQ(value.AsList().size(), 3); EXPECT_TRUE(value.AsList().at(1).IsString()); - EXPECT_EQ(value.AsList().at(1).AsString(), "item6"); + EXPECT_EQ(value.AsList().at(1).AsString(), "item5"); } } // namespace caosdb::entity diff --git a/test/test_properties.cpp b/test/test_properties.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4a6496a05c9bca0436ca1e15e47637cdf6d2b696 --- /dev/null +++ b/test/test_properties.cpp @@ -0,0 +1,106 @@ +/* + * This file is a part of the CaosDB Project. + * + * Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com> + * Copyright (C) 2021 IndiScale GmbH <info@indiscale.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + * + */ +#include "caosdb/connection.h" // for Connection, ConnectionManager +#include "caosdb/data_type.h" // for AtomicDataType, AtomicDataTyp... +#include "caosdb/entity.h" // for Entity, Properties, Property +#include "caosdb/transaction.h" // for Transaction, ResultSet, Resul... +#include "caosdb/transaction_status.h" // for TransactionStatus +#include <gtest/gtest-message.h> // for Message +#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver +#include <gtest/gtest_pred_impl.h> // for AssertionResult, EXPECT_EQ +#include <memory> // for unique_ptr, allocator, __shar... + +namespace caosdb::entity { + +class test_properties : public ::testing::Test { +protected: + void SetUp() override { DeleteEntities(); } + + void TearDown() override { DeleteEntities(); } + + static void DeleteEntities() { + const auto &connection = + caosdb::connection::ConnectionManager::GetDefaultConnection(); + auto query_transaction(connection->CreateTransaction()); + query_transaction->Query("FIND ENTITY WITH id > 99"); + query_transaction->Execute(); + if (query_transaction->GetResultSet().size() > 0) { + auto delete_transaction(connection->CreateTransaction()); + for (const Entity &entity : query_transaction->GetResultSet()) { + delete_transaction->DeleteById(entity.GetId()); + } + delete_transaction->Execute(); + } + } +}; + +TEST_F(test_properties, retrieve_unit) { + const auto &connection = + caosdb::connection::ConnectionManager::GetDefaultConnection(); + + auto insertion_prop(connection->CreateTransaction()); + + Entity abstract_property; + abstract_property.SetRole(Role::PROPERTY); + abstract_property.SetName("TestProp"); + abstract_property.SetDataType(AtomicDataType::DOUBLE); + abstract_property.SetUnit("V"); + + insertion_prop->InsertEntity(&abstract_property); + insertion_prop->Execute(); + EXPECT_TRUE(insertion_prop->GetStatus().IsTerminated()); + + auto insertion_rt(connection->CreateTransaction()); + + Property property; + property.SetId(insertion_prop->GetResultSet().at(0).GetId()); + + Entity entity; + entity.SetRole(Role::RECORD_TYPE); + entity.SetName("TestRT"); + entity.AppendProperty(property); + + insertion_rt->InsertEntity(&entity); + insertion_rt->Execute(); + EXPECT_TRUE(insertion_rt->GetStatus().IsTerminated()); + EXPECT_FALSE(insertion_rt->GetStatus().IsError()); + + // retrieve and check again + auto retrieval(connection->CreateTransaction()); + retrieval->RetrieveById(insertion_prop->GetResultSet().at(0).GetId()); + retrieval->RetrieveById(insertion_rt->GetResultSet().at(0).GetId()); + retrieval->ExecuteAsynchronously(); + retrieval->WaitForIt(); + + EXPECT_TRUE(retrieval->GetStatus().IsTerminated()); + EXPECT_FALSE(retrieval->GetStatus().IsError()); + + const auto &same_property = retrieval->GetResultSet().at(0); + EXPECT_EQ(same_property.GetDataType().AsAtomic(), AtomicDataType::DOUBLE); + EXPECT_EQ(same_property.GetUnit(), "V"); + + const auto &same_record_type = retrieval->GetResultSet().at(1); + EXPECT_EQ(same_record_type.GetProperties().at(0).GetDataType().AsAtomic(), + AtomicDataType::DOUBLE); + EXPECT_EQ(same_record_type.GetProperties().at(0).GetUnit(), "V"); +} + +} // namespace caosdb::entity diff --git a/test/test_transaction.cpp b/test/test_transaction.cpp index 683f85f600fde6f25f88867bf7ff4c6c388a7402..e0f6646a4b2498352864b59171c68718f0c3f81a 100644 --- a/test/test_transaction.cpp +++ b/test/test_transaction.cpp @@ -19,26 +19,30 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. * */ -#include "caosdb/connection.h" // for Connection, ConnectionManager -#include "caosdb/data_type.h" // for AtomicDataType -#include "caosdb/entity.h" // for Entity, Messages, Message -#include "caosdb/file_transmission/file_reader.h" // for FileReader +#include "caosdb/connection.h" // for Connection, Connec... +#include "caosdb/data_type.h" // for AtomicDataType +#include "caosdb/entity.h" // for Entity, Property +#include "caosdb/file_transmission/file_reader.h" // for path, FileReader #include "caosdb/file_transmission/file_writer.h" // for FileWriter -#include "caosdb/message_code.h" // for ENTITY_DOES_NOT_EXIST, Messag... -#include "caosdb/status_code.h" // for SUCCESS, StatusCode -#include "caosdb/transaction.h" // for Entity, Transaction,... -#include "caosdb/transaction_status.h" // for TransactionStatus, StatusCode -#include <boost/filesystem/operations.hpp> // for remove -#include <boost/filesystem/path.hpp> // for path -#include <boost/filesystem/path_traits.hpp> // for filesystem -#include <boost/lexical_cast.hpp> -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver -#include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, AssertionResult -#include <iostream> -#include <memory> // for unique_ptr, allocator, __shar... -#include <string> // for string -#include <vector> // for vector +#include "caosdb/message_code.h" // for MessageCode, ENTIT... +#include "caosdb/status_code.h" // for StatusCode, SUCCESS +#include "caosdb/transaction.h" // for Entity, Transaction +#include "caosdb/transaction_status.h" // for TransactionStatus +#include "caosdb/value.h" // for Value +#include <boost/filesystem/operations.hpp> // for remove +#include <boost/filesystem/path.hpp> // for path +#include <boost/filesystem/path_traits.hpp> // for filesystem +#include <cstddef> // for size_t +#include <cstdint> // for int32_t +#include <gtest/gtest-message.h> // for Message +#include <gtest/gtest-test-part.h> // for TestPartResult +#include <gtest/gtest_pred_impl.h> // for AssertionResult +#include <iostream> // for operator<<, endl +#include <limits> // for numeric_limits +#include <memory> // for unique_ptr, allocator +#include <stdexcept> // for logic_error +#include <string> // for string, operator+ +#include <vector> // for vector, operator!= namespace fs = boost::filesystem; namespace caosdb::transaction { @@ -61,10 +65,13 @@ public: */ template <typename T> static auto generateValues() -> std::vector<T> { std::vector<T> values = { - 0, 1, - // (T)6.91629132943846e-310, - std::numeric_limits<T>::max(), std::numeric_limits<T>::min(), - std::numeric_limits<T>::denorm_min(), std::numeric_limits<T>::lowest(), + static_cast<T>(0), + static_cast<T>(1), + static_cast<T>(6.91629132943846e-310), + std::numeric_limits<T>::max(), + std::numeric_limits<T>::min(), + std::numeric_limits<T>::denorm_min(), + std::numeric_limits<T>::lowest(), std::numeric_limits<T>::epsilon() // 0 for integers, but who cares? }; @@ -96,7 +103,8 @@ public: protected: fs::path test_upload_file_1; fs::path test_download_file_1; - size_t test_file_size_kib = 20; // We should test at least something over 16kiB + size_t test_file_size_kib = + 20; // We should test at least something over 16kiB // Fixture methods ////////////////////////////////////////////////////////// @@ -132,6 +140,11 @@ auto test_transaction::getValueAs<int32_t>(const Value &value) -> int32_t { return value.AsInteger(); } +template <> +auto test_transaction::getValueAs<bool>(const Value &value) -> bool { + return value.AsBool(); +} + /* * Test the retrieval of a non-existing entity * @@ -744,6 +757,8 @@ TEST_F(test_transaction, test_numeric_values) { test_numeric_values_impl<double>(AtomicDataType::DOUBLE); test_transaction::DeleteEntities(); test_numeric_values_impl<int32_t>(AtomicDataType::INTEGER); + test_transaction::DeleteEntities(); + test_numeric_values_impl<bool>(AtomicDataType::BOOLEAN); } // /* @@ -961,7 +976,7 @@ TEST_F(test_transaction, test_file_up_n_download) { std::string buffer_remote(1024, 'c'); std::cout << "Reading kiB chunk"; for (size_t i = 0; i < test_file_size_kib; i++) { - std::cout << " #" << i+1 << "/" << test_file_size_kib; + std::cout << " #" << i + 1 << "/" << test_file_size_kib; reader_remote.read(buffer_remote); EXPECT_EQ(buffer_remote, buffer_local); }