From 2b36f68d932171d7a6ff6a332ed9da504c9d828d Mon Sep 17 00:00:00 2001 From: Timm Fitschen <t.fitschen@indiscale.com> Date: Mon, 31 Jan 2022 18:14:34 +0100 Subject: [PATCH] Add tests for date time --- test/test_issues.cpp | 3 +- test/test_transaction.cpp | 88 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 84 insertions(+), 7 deletions(-) diff --git a/test/test_issues.cpp b/test/test_issues.cpp index ddfee8b..9935eb1 100644 --- a/test/test_issues.cpp +++ b/test/test_issues.cpp @@ -180,8 +180,7 @@ TEST_F(test_issues, server_issue_174) { auto insert_status = insert_transaction->WaitForIt(); ASSERT_TRUE(insert_status.IsTerminated()); - // TODO(tf) Remove the EXPECT_NONFATAL_FAILURE after fixing #174. - EXPECT_NONFATAL_FAILURE(EXPECT_FALSE(insert_status.IsError()), ""); + EXPECT_FALSE(insert_status.IsError()); } } // namespace caosdb::transaction diff --git a/test/test_transaction.cpp b/test/test_transaction.cpp index c73469e..865e18e 100644 --- a/test/test_transaction.cpp +++ b/test/test_transaction.cpp @@ -60,6 +60,26 @@ 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. */ @@ -745,6 +765,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 +1184,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'); -- GitLab