Skip to content
Snippets Groups Projects
Commit e279661d authored by Daniel Hornung's avatar Daniel Hornung
Browse files

TEST: Test for numeric values.

Also switched to 32 bit integer values.
parent 2dbd45c6
No related branches found
No related tags found
1 merge request!12TEST: Test for numeric values.
Pipeline #12637 failed
This commit is part of merge request !12. Comments created here will be created in the context of that merge request.
CHANGELOG.md 0 → 100644
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
### Changed
* Integer values are 32 bit now.
### Deprecated
### Removed
### Fixed
### Security
......@@ -54,6 +54,7 @@ add_subdirectory(test)
#######################################################
option(AUTOFORMATTING "call clang-format at configure time" ON)
if(AUTOFORMATTING)
message("Autoformatting is on. To disable, call cmake with '-D AUTOFORMATTING=OFF'.")
file(GLOB format_test_sources test/*.cpp test/*.h)
execute_process(COMMAND clang-format -i --verbose ${format_test_sources}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
......
......@@ -54,6 +54,7 @@ add_compiler_flag("-g")
#######################################################
option(LINTING "clang-tidy and iwye" ON)
if(LINTING)
message("Linting is on. To disable, call cmake with '-D LINTING=OFF'.")
### set paranoid compiler flags
#add_compiler_flag("-Wall")
#add_compiler_flag("-Wextra")
......
......@@ -31,7 +31,7 @@
#include <boost/filesystem/path.hpp> // for path
#include <boost/filesystem/path_traits.hpp> // for filesystem
#include <boost/lexical_cast.hpp>
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver
#include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, AssertionResult
#include <iostream>
......@@ -48,27 +48,31 @@ using caosdb::entity::MessageCode;
using caosdb::entity::Parent;
using caosdb::entity::Property;
using caosdb::entity::Role;
using caosdb::entity::Value;
class test_transaction : public ::testing::Test {
public:
// public utility functions ////////////////////////////////////////////////////////
// public utility functions
// ////////////////////////////////////////////////////////
/**
* Generate a vector with useful values for testing.
*/
template <typename T> static auto generateValues() -> std::vector<T> {
std::vector<T> values = {
0,
1,
std::numeric_limits<T>::max(),
std::numeric_limits<T>::min(),
std::numeric_limits<T>::lowest(),
std::numeric_limits<T>::epsilon() // 0 for integers, but who cares?
0, 1,
// (T)6.91629132943846e-310,
std::numeric_limits<T>::max(), std::numeric_limits<T>::min(),
std::numeric_limits<T>::denorm_min(), std::numeric_limits<T>::lowest(),
std::numeric_limits<T>::epsilon() // 0 for integers, but who cares?
};
return values;
}
template <typename T> static auto getValueAs(const Value &value) -> T {
throw std::logic_error("Template not implemented for this type.");
}
static void DeleteEntities() {
// delete all entities
const auto &connection =
......@@ -77,6 +81,9 @@ public:
query_transaction->Query("FIND ENTITY WITH id > 99");
query_transaction->Execute();
if (query_transaction->GetResultSet().size() > 0) {
std::cout << "Cleanup: Deleting "
<< query_transaction->GetResultSet().size() << " entities."
<< std::endl;
auto delete_transaction(connection->CreateTransaction());
for (const Entity &entity : query_transaction->GetResultSet()) {
delete_transaction->DeleteById(entity.GetId());
......@@ -85,7 +92,6 @@ public:
}
}
protected:
fs::path test_upload_file_1;
fs::path test_download_file_1;
......@@ -112,9 +118,18 @@ protected:
fs::remove(test_download_file_1);
DeleteEntities();
}
};
template <>
auto test_transaction::getValueAs<double>(const Value &value) -> double {
return value.AsDouble();
}
template <>
auto test_transaction::getValueAs<int32_t>(const Value &value) -> int32_t {
return value.AsInteger();
}
/*
* Test the retrieval of a non-existing entity
*
......@@ -667,49 +682,60 @@ TEST_F(test_transaction, test_query) {
/**
* Test numeric values (template).
*/
template<typename T>
template <typename T>
auto test_numeric_values_impl(AtomicDataType a_type) -> void {
const auto &connection =
caosdb::connection::ConnectionManager::GetDefaultConnection();
caosdb::connection::ConnectionManager::GetDefaultConnection();
// Insert entities
auto insert_transaction(connection->CreateTransaction());
auto values_orig = test_transaction::generateValues<T>();
auto props_orig = std::vector<Entity>();
size_t i = 0;
--i;
for (auto value : values_orig) {
++i;
auto insert_transaction(connection->CreateTransaction());
Entity prop;
prop.SetRole(Role::PROPERTY);
prop.SetName(std::string("Prop ") + boost::lexical_cast<std::string>(i));
const auto name =
std::string("Prop ") + boost::lexical_cast<std::string>(i);
std::cout << "Creating: " << name << std::endl;
prop.SetName(name);
prop.SetDataType(a_type);
std::cout << "Setting value " << value << std::endl;
prop.SetValue(value);
props_orig.push_back(prop);
insert_transaction->InsertEntity(&prop);
auto i_stat = insert_transaction->InsertEntity(&prop);
EXPECT_EQ(i_stat, StatusCode::READY);
insert_transaction->ExecuteAsynchronously();
auto t_stat = insert_transaction->WaitForIt();
ASSERT_TRUE(t_stat.IsTerminated());
ASSERT_FALSE(t_stat.IsError());
EXPECT_TRUE(t_stat.IsTerminated());
EXPECT_FALSE(t_stat.IsError());
}
// Retrieve and verify
auto retrieve_transaction(connection->CreateTransaction());
i = 0;
--i;
for (auto value : values_orig) {
for (const auto value : values_orig) {
++i;
auto prop = props_orig[i];
auto name = std::string("Prop ") + boost::lexical_cast<std::string>(i);
auto query = std::string("FIND ENTITY \"Prop ") + boost::lexical_cast<std::string>(i) + "\"";
auto retrieve_transaction(connection->CreateTransaction());
const auto prop = props_orig[i];
const auto name =
std::string("Prop ") + boost::lexical_cast<std::string>(i);
std::cout << "Retrieving: " << name << std::endl;
const auto query = std::string("FIND ENTITY \"") + name + "\"";
retrieve_transaction->Query(query);
retrieve_transaction->ExecuteAsynchronously();
auto t_stat = retrieve_transaction->WaitForIt();
ASSERT_TRUE(t_stat.IsTerminated());
ASSERT_FALSE(t_stat.IsError());
auto result = retrieve_transaction->GetResultSet().at(0);
ASSERT_EQ(result.GetDataType(), a_type);
const auto t_stat = retrieve_transaction->WaitForIt();
EXPECT_TRUE(t_stat.IsTerminated());
EXPECT_FALSE(t_stat.IsError());
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);
}
}
......@@ -718,26 +744,26 @@ auto test_numeric_values_impl(AtomicDataType a_type) -> void {
*/
TEST_F(test_transaction, test_numeric_values) {
test_numeric_values_impl<double>(AtomicDataType::DOUBLE);
DeleteEntities();
test_numeric_values_impl<int64_t>(AtomicDataType::INTEGER);
test_transaction::DeleteEntities();
test_numeric_values_impl<int32_t>(AtomicDataType::INTEGER);
}
/*
* test miscellaneous queries
*/
TEST_F(test_transaction, test_queries_misc) {
const auto &connection =
caosdb::connection::ConnectionManager::GetDefaultConnection();
auto query_transaction(connection->CreateTransaction());
query_transaction->Query("FIND Property \"Prop *\"");
query_transaction->ExecuteAsynchronously();
auto t_stat = query_transaction->WaitForIt();
std::cout << "status: " << t_stat.GetCode() << " // "
<< t_stat.GetDescription() << std::endl;
EXPECT_TRUE(t_stat.GetCode() >= 0);
}
// /*
// * test miscellaneous queries
// */
// TEST_F(test_transaction, test_queries_misc) {
// const auto &connection =
// caosdb::connection::ConnectionManager::GetDefaultConnection();
// // query empty database
// auto query_transaction(connection->CreateTransaction());
// query_transaction->Query("FIND Property \"Prop *\"");
// query_transaction->ExecuteAsynchronously();
// auto t_stat = query_transaction->WaitForIt();
// std::cout << "status: " << t_stat.GetCode() << " // "
// << t_stat.GetDescription() << std::endl;
// EXPECT_TRUE(t_stat.GetCode() >= 0);
// }
/*
* insert three recordtypes and the submit multiple queries in different
......@@ -1034,7 +1060,7 @@ TEST_F(test_transaction, test_full_workflow) {
experiment_rec.AppendProperty(volt_for_rt);
notes_for_rt2.SetValue("This is important!");
experiment_rec.AppendProperty(notes_for_rt2);
part_for_rt3.SetValue(static_cast<int64_t>(6));
part_for_rt3.SetValue(static_cast<int32_t>(6));
experiment_rec.AppendProperty(part_for_rt3);
succ_for_rt.SetValue(true);
experiment_rec.AppendProperty(succ_for_rt);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment