diff --git a/Makefile b/Makefile index d1b947cb34b3fdae036eb136af95e2fe347cfd4d..214c6f224054ad9f8d6dd267f2adb82aac94a3a1 100644 --- a/Makefile +++ b/Makefile @@ -36,14 +36,13 @@ CLANG_TIDY_CMD = $(CLANG_TIDY) \ help: @echo "Targets:" @echo " conan-install - Install locally with Conan." - @echo " style - auto-format the source files." + @echo " format - auto-format the source files." conan-install: conan install . -s "compiler.libcxx=libstdc++11" .PHONY: conan-install -format: conan-install +format: $(CLANG_FORMAT) -i --verbose \ $$(find test/ -type f -iname "*.cpp" -o -iname "*.h" -o -iname "*.h.in") - $(CLANG_TIDY_CMD) $$(find test/ -type f -iname "*.cpp" -o -iname "*.h" -o -iname "*.h.in") .PHONY: format diff --git a/test/test_transaction.cpp b/test/test_transaction.cpp index c73469e7673dba73daac2fe09aeee7944e3c1d3f..270043e810d0fd2ed6a5776a113f8a5944edb15f 100644 --- a/test/test_transaction.cpp +++ b/test/test_transaction.cpp @@ -22,6 +22,7 @@ #include "caosdb/connection.h" // for Connection, Connec... #include "caosdb/data_type.h" // for AtomicDataType #include "caosdb/entity.h" // for Entity, Property +#include "caosdb/file_descriptor.h" // for FileDescriptor #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 MessageCode, ENTIT... @@ -60,6 +61,23 @@ public: // public utility functions // //////////////////////////////////////////////////////// + /** + * Generate a vector with useful values for testing. + */ + static auto generateDatetimeValues() -> std::vector<std::string> { + std::vector<std::string> values = { + // TODO(tf) (these work, but would need conversion here in the tests due + // to the time zone information) + //"2022-12-24T18:15:00.999999+0200", + //"2022-12-24T18:15:00.999999UTC", + //"2022-12-24T18:15:00", + //"2022-12-24T18:15:00.999999", + //"", + "2022", "2022-12", "2022-12-24"}; + + return values; + } + /** * Generate a vector with useful values for testing. */ @@ -722,14 +740,12 @@ template <typename T, typename S> auto test_numeric_values_impl(AtomicDataType a const auto t_stat = retrieve_transaction->WaitForIt(); EXPECT_TRUE(t_stat.IsTerminated()); EXPECT_FALSE(t_stat.IsError()); + ASSERT_EQ(retrieve_transaction->GetResultSet().size(), 1); - if (retrieve_transaction->GetResultSet().size() > 0) { - const auto result = retrieve_transaction->GetResultSet().at(0); - EXPECT_EQ(result.GetDataType(), a_type); - const auto &retrieved_value = test_transaction::getValueAs<T>(result.GetValue()); - // std::cout << "retrieved_value: " << retrieved_value << std::endl; - EXPECT_EQ(retrieved_value, value); - } + const auto result = retrieve_transaction->GetResultSet().at(0); + EXPECT_EQ(result.GetDataType(), a_type); + const auto &retrieved_value = test_transaction::getValueAs<T>(result.GetValue()); + EXPECT_EQ(retrieved_value, value); ++i; } } @@ -745,6 +761,61 @@ TEST_F(test_transaction, test_numeric_values) { test_numeric_values_impl<bool, bool>(AtomicDataType::BOOLEAN); } +/** + * Test date time values. + */ +TEST_F(test_transaction, test_datetime_values) { + const auto &connection = caosdb::connection::ConnectionManager::GetDefaultConnection(); + + // Insert entities + auto values_orig = test_transaction::generateDatetimeValues(); + auto props_orig = std::vector<Entity>(); + size_t i = 0; + for (const auto &value : values_orig) { + auto insert_transaction(connection->CreateTransaction()); + Entity prop; + prop.SetRole(Role::PROPERTY); + const auto name = std::string("Prop ") + std::to_string(i); + std::cout << "Creating: " << name << std::endl; + prop.SetName(name); + prop.SetDataType(AtomicDataType::DATETIME); + std::cout << "Setting value " << value << std::endl; + prop.SetValue(value); + props_orig.push_back(prop); + auto i_stat = insert_transaction->InsertEntity(&prop); + EXPECT_EQ(i_stat, StatusCode::GO_ON); + insert_transaction->ExecuteAsynchronously(); + auto t_stat = insert_transaction->WaitForIt(); + EXPECT_TRUE(t_stat.IsTerminated()); + EXPECT_FALSE(t_stat.IsError()); + ++i; + } + + // Retrieve and verify + i = 0; + for (const auto &value : values_orig) { + auto retrieve_transaction(connection->CreateTransaction()); + const auto prop = props_orig[i]; + const auto name = std::string("Prop ") + std::to_string(i); + std::cout << "Retrieving: " << name << std::endl; + const auto query = std::string("FIND ENTITY \"") + name + "\""; + retrieve_transaction->Query(query); + retrieve_transaction->ExecuteAsynchronously(); + const auto t_stat = retrieve_transaction->WaitForIt(); + EXPECT_TRUE(t_stat.IsTerminated()); + EXPECT_FALSE(t_stat.IsError()); + + if (retrieve_transaction->GetResultSet().size() > 0) { + const auto result = retrieve_transaction->GetResultSet().at(0); + EXPECT_EQ(result.GetDataType(), AtomicDataType::DATETIME); + const auto &retrieved_value = result.GetValue().GetAsString(); + // std::cout << "retrieved_value: " << retrieved_value << std::endl; + EXPECT_EQ(retrieved_value, value); + } + ++i; + } +} + TEST_F(test_transaction, test_integer_out_of_range) { const auto &connection = caosdb::connection::ConnectionManager::GetDefaultConnection(); @@ -1109,13 +1180,16 @@ TEST_F(test_transaction, test_file_up_n_download) { const auto &download_results = download_transaction->GetResultSet(); ASSERT_EQ(download_results.size(), 1); - const auto &downloaded_file = download_results.at(0); - ASSERT_FALSE(downloaded_file.GetId().empty()); - ASSERT_FALSE(downloaded_file.HasErrors()); - EXPECT_EQ(downloaded_file.GetLocalPath().string(), test_download_file_1.string()); + auto *downloaded_file = download_results.mutable_at(0); + ASSERT_FALSE(downloaded_file->GetId().empty()); + ASSERT_FALSE(downloaded_file->HasErrors()); + EXPECT_EQ(downloaded_file->GetLocalPath().string(), test_download_file_1.string()); EXPECT_EQ(fs::file_size(test_upload_file_1), fs::file_size(test_download_file_1)); - // test_download_file_1 + // Check FileDescriptor + EXPECT_EQ(downloaded_file->GetFileDescriptor().wrapped->path(), "test.txt"); + + // test_download_file_1 FileReader reader_remote(test_download_file_1); std::string buffer_local(1024, 'c'); std::string buffer_remote(1024, 'c');