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

WIP: test integer out of range

parent 4059f544
No related branches found
No related tags found
1 merge request!14Tests for f-int64
Pipeline #12870 failed
This commit is part of merge request !14. Comments created here will be created in the context of that merge request.
......@@ -142,7 +142,6 @@ auto test_transaction::getValueAs<int32_t>(const Value &value) -> int32_t {
return static_cast<int32_t>(value.AsInteger());
}
template <>
auto test_transaction::getValueAs<bool>(const Value &value) -> bool {
return value.AsBool();
......@@ -700,8 +699,8 @@ TEST_F(test_transaction, test_query) {
/**
* Test numeric values (template).
*/
template <typename T>
auto test_numeric_values_impl(AtomicDataType a_type, bool cast_to_int64) -> void {
template <typename T, typename S>
auto test_numeric_values_impl(AtomicDataType a_type) -> void {
const auto &connection =
caosdb::connection::ConnectionManager::GetDefaultConnection();
......@@ -718,11 +717,7 @@ auto test_numeric_values_impl(AtomicDataType a_type, bool cast_to_int64) -> void
prop.SetName(name);
prop.SetDataType(a_type);
std::cout << "Setting value " << value << std::endl;
if(cast_to_int64) {
prop.SetValue(static_cast<int64_t>(value));
} else {
prop.SetValue(value);
}
prop.SetValue(static_cast<S>(value));
props_orig.push_back(prop);
auto i_stat = insert_transaction->InsertEntity(&prop);
EXPECT_EQ(i_stat, StatusCode::READY);
......@@ -747,12 +742,14 @@ auto test_numeric_values_impl(AtomicDataType a_type, bool cast_to_int64) -> void
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(), 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);
}
++i;
}
}
......@@ -761,13 +758,45 @@ auto test_numeric_values_impl(AtomicDataType a_type, bool cast_to_int64) -> void
* Test numeric values (wrapper for types).
*/
TEST_F(test_transaction, test_numeric_values) {
test_numeric_values_impl<double>(AtomicDataType::DOUBLE, false);
test_transaction::DeleteEntities();
test_numeric_values_impl<int32_t>(AtomicDataType::INTEGER, true);
test_numeric_values_impl<double, double>(AtomicDataType::DOUBLE);
test_transaction::DeleteEntities();
test_numeric_values_impl<bool>(AtomicDataType::BOOLEAN, false);
test_numeric_values_impl<int32_t, int64_t>(AtomicDataType::INTEGER);
test_transaction::DeleteEntities();
test_numeric_values_impl<int64_t>(AtomicDataType::INTEGER, false);
test_numeric_values_impl<bool, bool>(AtomicDataType::BOOLEAN);
}
TEST_F(test_transaction, test_integer_out_of_range) {
const auto &connection =
caosdb::connection::ConnectionManager::GetDefaultConnection();
// Insert entities
std::vector<int64_t> values = {std::numeric_limits<int64_t>::max(),
std::numeric_limits<int64_t>::min()};
for (auto value : values) {
auto insert_transaction(connection->CreateTransaction());
Entity prop;
prop.SetRole(Role::PROPERTY);
const auto name = std::string("Prop_") + std::to_string(value);
prop.SetName(name);
prop.SetDataType(AtomicDataType::INTEGER);
prop.SetValue(value);
auto i_stat = insert_transaction->InsertEntity(&prop);
EXPECT_EQ(i_stat, StatusCode::READY);
insert_transaction->ExecuteAsynchronously();
auto t_stat = insert_transaction->WaitForIt();
EXPECT_TRUE(t_stat.IsTerminated());
EXPECT_TRUE(t_stat.IsError());
EXPECT_EQ(t_stat.GetCode(), StatusCode::GENERIC_TRANSACTION_ERROR);
EXPECT_EQ(insert_transaction->GetResultSet().size(), 1);
EXPECT_TRUE(insert_transaction->GetResultSet().at(0).HasErrors());
EXPECT_EQ(
insert_transaction->GetResultSet().at(0).GetErrors().at(0).GetCode(),
MessageCode::INTEGER_VALUE_OUT_OF_RANGE);
}
}
// /*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment