Skip to content
Snippets Groups Projects
Verified Commit 2b36f68d authored by Timm Fitschen's avatar Timm Fitschen
Browse files

Add tests for date time

parent a84b4694
No related branches found
No related tags found
2 merge requests!22F remove boost rdep,!19"TST: update tests"
Pipeline #18933 passed
This commit is part of merge request !19. Comments created here will be created in the context of that merge request.
......@@ -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
......@@ -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');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment