Skip to content
Snippets Groups Projects

Tests for f-int64

Files

+ 55
14
@@ -33,7 +33,7 @@
@@ -33,7 +33,7 @@
#include <boost/filesystem/path.hpp> // for path
#include <boost/filesystem/path.hpp> // for path
#include <boost/filesystem/path_traits.hpp> // for filesystem
#include <boost/filesystem/path_traits.hpp> // for filesystem
#include <cstddef> // for size_t
#include <cstddef> // for size_t
#include <cstdint> // for int32_t
#include <cstdint> // for int64_t, int32_t
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for TestPartResult
#include <gtest/gtest-test-part.h> // for TestPartResult
#include <gtest/gtest_pred_impl.h> // for AssertionResult
#include <gtest/gtest_pred_impl.h> // for AssertionResult
@@ -136,10 +136,15 @@ auto test_transaction::getValueAs<double>(const Value &value) -> double {
@@ -136,10 +136,15 @@ auto test_transaction::getValueAs<double>(const Value &value) -> double {
}
}
template <>
template <>
auto test_transaction::getValueAs<int32_t>(const Value &value) -> int32_t {
auto test_transaction::getValueAs<int64_t>(const Value &value) -> int64_t {
return value.AsInteger();
return value.AsInteger();
}
}
 
template <>
 
auto test_transaction::getValueAs<int32_t>(const Value &value) -> int32_t {
 
return static_cast<int32_t>(value.AsInteger());
 
}
 
template <>
template <>
auto test_transaction::getValueAs<bool>(const Value &value) -> bool {
auto test_transaction::getValueAs<bool>(const Value &value) -> bool {
return value.AsBool();
return value.AsBool();
@@ -697,7 +702,7 @@ TEST_F(test_transaction, test_query) {
@@ -697,7 +702,7 @@ TEST_F(test_transaction, test_query) {
/**
/**
* Test numeric values (template).
* Test numeric values (template).
*/
*/
template <typename T>
template <typename T, typename S>
auto test_numeric_values_impl(AtomicDataType a_type) -> void {
auto test_numeric_values_impl(AtomicDataType a_type) -> void {
const auto &connection =
const auto &connection =
caosdb::connection::ConnectionManager::GetDefaultConnection();
caosdb::connection::ConnectionManager::GetDefaultConnection();
@@ -715,7 +720,7 @@ auto test_numeric_values_impl(AtomicDataType a_type) -> void {
@@ -715,7 +720,7 @@ auto test_numeric_values_impl(AtomicDataType a_type) -> void {
prop.SetName(name);
prop.SetName(name);
prop.SetDataType(a_type);
prop.SetDataType(a_type);
std::cout << "Setting value " << value << std::endl;
std::cout << "Setting value " << value << std::endl;
prop.SetValue(value);
prop.SetValue(static_cast<S>(value));
props_orig.push_back(prop);
props_orig.push_back(prop);
auto i_stat = insert_transaction->InsertEntity(&prop);
auto i_stat = insert_transaction->InsertEntity(&prop);
EXPECT_EQ(i_stat, StatusCode::READY);
EXPECT_EQ(i_stat, StatusCode::READY);
@@ -740,12 +745,14 @@ auto test_numeric_values_impl(AtomicDataType a_type) -> void {
@@ -740,12 +745,14 @@ auto test_numeric_values_impl(AtomicDataType a_type) -> void {
EXPECT_TRUE(t_stat.IsTerminated());
EXPECT_TRUE(t_stat.IsTerminated());
EXPECT_FALSE(t_stat.IsError());
EXPECT_FALSE(t_stat.IsError());
const auto result = retrieve_transaction->GetResultSet().at(0);
if (retrieve_transaction->GetResultSet().size() > 0) {
EXPECT_EQ(result.GetDataType(), a_type);
const auto result = retrieve_transaction->GetResultSet().at(0);
const auto &retrieved_value =
EXPECT_EQ(result.GetDataType(), a_type);
test_transaction::getValueAs<T>(result.GetValue());
const auto &retrieved_value =
// std::cout << "retrieved_value: " << retrieved_value << std::endl;
test_transaction::getValueAs<T>(result.GetValue());
EXPECT_EQ(retrieved_value, value);
// std::cout << "retrieved_value: " << retrieved_value << std::endl;
 
EXPECT_EQ(retrieved_value, value);
 
}
++i;
++i;
}
}
}
}
@@ -754,11 +761,45 @@ auto test_numeric_values_impl(AtomicDataType a_type) -> void {
@@ -754,11 +761,45 @@ auto test_numeric_values_impl(AtomicDataType a_type) -> void {
* Test numeric values (wrapper for types).
* Test numeric values (wrapper for types).
*/
*/
TEST_F(test_transaction, test_numeric_values) {
TEST_F(test_transaction, test_numeric_values) {
test_numeric_values_impl<double>(AtomicDataType::DOUBLE);
test_numeric_values_impl<double, double>(AtomicDataType::DOUBLE);
test_transaction::DeleteEntities();
test_transaction::DeleteEntities();
test_numeric_values_impl<int32_t>(AtomicDataType::INTEGER);
test_numeric_values_impl<int32_t, int64_t>(AtomicDataType::INTEGER);
test_transaction::DeleteEntities();
test_transaction::DeleteEntities();
test_numeric_values_impl<bool>(AtomicDataType::BOOLEAN);
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);
 
}
}
}
// /*
// /*
@@ -1079,7 +1120,7 @@ TEST_F(test_transaction, test_full_workflow) {
@@ -1079,7 +1120,7 @@ TEST_F(test_transaction, test_full_workflow) {
experiment_rec.AppendProperty(volt_for_rt);
experiment_rec.AppendProperty(volt_for_rt);
notes_for_rt2.SetValue("This is important!");
notes_for_rt2.SetValue("This is important!");
experiment_rec.AppendProperty(notes_for_rt2);
experiment_rec.AppendProperty(notes_for_rt2);
part_for_rt3.SetValue(static_cast<int32_t>(6));
part_for_rt3.SetValue(static_cast<int64_t>(6));
experiment_rec.AppendProperty(part_for_rt3);
experiment_rec.AppendProperty(part_for_rt3);
succ_for_rt.SetValue(true);
succ_for_rt.SetValue(true);
experiment_rec.AppendProperty(succ_for_rt);
experiment_rec.AppendProperty(succ_for_rt);
Loading