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
# 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) ...@@ -54,6 +54,7 @@ add_subdirectory(test)
####################################################### #######################################################
option(AUTOFORMATTING "call clang-format at configure time" ON) option(AUTOFORMATTING "call clang-format at configure time" ON)
if(AUTOFORMATTING) if(AUTOFORMATTING)
message("Autoformatting is on. To disable, call cmake with '-D AUTOFORMATTING=OFF'.")
file(GLOB format_test_sources test/*.cpp test/*.h) file(GLOB format_test_sources test/*.cpp test/*.h)
execute_process(COMMAND clang-format -i --verbose ${format_test_sources} execute_process(COMMAND clang-format -i --verbose ${format_test_sources}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
......
...@@ -54,6 +54,7 @@ add_compiler_flag("-g") ...@@ -54,6 +54,7 @@ add_compiler_flag("-g")
####################################################### #######################################################
option(LINTING "clang-tidy and iwye" ON) option(LINTING "clang-tidy and iwye" ON)
if(LINTING) if(LINTING)
message("Linting is on. To disable, call cmake with '-D LINTING=OFF'.")
### set paranoid compiler flags ### set paranoid compiler flags
#add_compiler_flag("-Wall") #add_compiler_flag("-Wall")
#add_compiler_flag("-Wextra") #add_compiler_flag("-Wextra")
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,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 <boost/lexical_cast.hpp> #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-test-part.h> // for TestPartResult, SuiteApiResolver
#include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, AssertionResult #include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, AssertionResult
#include <iostream> #include <iostream>
...@@ -48,27 +48,31 @@ using caosdb::entity::MessageCode; ...@@ -48,27 +48,31 @@ using caosdb::entity::MessageCode;
using caosdb::entity::Parent; using caosdb::entity::Parent;
using caosdb::entity::Property; using caosdb::entity::Property;
using caosdb::entity::Role; using caosdb::entity::Role;
using caosdb::entity::Value;
class test_transaction : public ::testing::Test { class test_transaction : public ::testing::Test {
public: public:
// public utility functions
// public utility functions //////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////
/** /**
* Generate a vector with useful values for testing. * Generate a vector with useful values for testing.
*/ */
template <typename T> static auto generateValues() -> std::vector<T> { template <typename T> static auto generateValues() -> std::vector<T> {
std::vector<T> values = { std::vector<T> values = {
0, 0, 1,
1, // (T)6.91629132943846e-310,
std::numeric_limits<T>::max(), std::numeric_limits<T>::max(), std::numeric_limits<T>::min(),
std::numeric_limits<T>::min(), std::numeric_limits<T>::denorm_min(), std::numeric_limits<T>::lowest(),
std::numeric_limits<T>::lowest(), std::numeric_limits<T>::epsilon() // 0 for integers, but who cares?
std::numeric_limits<T>::epsilon() // 0 for integers, but who cares?
}; };
return values; 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() { static void DeleteEntities() {
// delete all entities // delete all entities
const auto &connection = const auto &connection =
...@@ -77,6 +81,9 @@ public: ...@@ -77,6 +81,9 @@ public:
query_transaction->Query("FIND ENTITY WITH id > 99"); query_transaction->Query("FIND ENTITY WITH id > 99");
query_transaction->Execute(); query_transaction->Execute();
if (query_transaction->GetResultSet().size() > 0) { if (query_transaction->GetResultSet().size() > 0) {
std::cout << "Cleanup: Deleting "
<< query_transaction->GetResultSet().size() << " entities."
<< std::endl;
auto delete_transaction(connection->CreateTransaction()); auto delete_transaction(connection->CreateTransaction());
for (const Entity &entity : query_transaction->GetResultSet()) { for (const Entity &entity : query_transaction->GetResultSet()) {
delete_transaction->DeleteById(entity.GetId()); delete_transaction->DeleteById(entity.GetId());
...@@ -85,7 +92,6 @@ public: ...@@ -85,7 +92,6 @@ public:
} }
} }
protected: protected:
fs::path test_upload_file_1; fs::path test_upload_file_1;
fs::path test_download_file_1; fs::path test_download_file_1;
...@@ -112,9 +118,18 @@ protected: ...@@ -112,9 +118,18 @@ protected:
fs::remove(test_download_file_1); fs::remove(test_download_file_1);
DeleteEntities(); 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 * Test the retrieval of a non-existing entity
* *
...@@ -667,49 +682,60 @@ TEST_F(test_transaction, test_query) { ...@@ -667,49 +682,60 @@ TEST_F(test_transaction, test_query) {
/** /**
* Test numeric values (template). * Test numeric values (template).
*/ */
template<typename T> template <typename T>
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();
// Insert entities // Insert entities
auto insert_transaction(connection->CreateTransaction());
auto values_orig = test_transaction::generateValues<T>(); auto values_orig = test_transaction::generateValues<T>();
auto props_orig = std::vector<Entity>(); auto props_orig = std::vector<Entity>();
size_t i = 0; size_t i = 0;
--i; --i;
for (auto value : values_orig) { for (auto value : values_orig) {
++i; ++i;
auto insert_transaction(connection->CreateTransaction());
Entity prop; Entity prop;
prop.SetRole(Role::PROPERTY); 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); prop.SetDataType(a_type);
std::cout << "Setting value " << value << std::endl;
prop.SetValue(value); prop.SetValue(value);
props_orig.push_back(prop); 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(); insert_transaction->ExecuteAsynchronously();
auto t_stat = insert_transaction->WaitForIt(); auto t_stat = insert_transaction->WaitForIt();
ASSERT_TRUE(t_stat.IsTerminated()); EXPECT_TRUE(t_stat.IsTerminated());
ASSERT_FALSE(t_stat.IsError()); EXPECT_FALSE(t_stat.IsError());
} }
// Retrieve and verify // Retrieve and verify
auto retrieve_transaction(connection->CreateTransaction());
i = 0; i = 0;
--i; --i;
for (auto value : values_orig) { for (const auto value : values_orig) {
++i; ++i;
auto prop = props_orig[i]; auto retrieve_transaction(connection->CreateTransaction());
auto name = std::string("Prop ") + boost::lexical_cast<std::string>(i); const auto prop = props_orig[i];
auto query = std::string("FIND ENTITY \"Prop ") + boost::lexical_cast<std::string>(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->Query(query);
retrieve_transaction->ExecuteAsynchronously(); retrieve_transaction->ExecuteAsynchronously();
auto t_stat = retrieve_transaction->WaitForIt(); const auto t_stat = retrieve_transaction->WaitForIt();
ASSERT_TRUE(t_stat.IsTerminated()); EXPECT_TRUE(t_stat.IsTerminated());
ASSERT_FALSE(t_stat.IsError()); EXPECT_FALSE(t_stat.IsError());
auto result = retrieve_transaction->GetResultSet().at(0); const auto result = retrieve_transaction->GetResultSet().at(0);
ASSERT_EQ(result.GetDataType(), a_type); 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 { ...@@ -718,26 +744,26 @@ auto test_numeric_values_impl(AtomicDataType a_type) -> void {
*/ */
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>(AtomicDataType::DOUBLE);
DeleteEntities(); test_transaction::DeleteEntities();
test_numeric_values_impl<int64_t>(AtomicDataType::INTEGER); test_numeric_values_impl<int32_t>(AtomicDataType::INTEGER);
} }
/* // /*
* test miscellaneous queries // * test miscellaneous queries
*/ // */
TEST_F(test_transaction, test_queries_misc) { // TEST_F(test_transaction, test_queries_misc) {
const auto &connection = // const auto &connection =
caosdb::connection::ConnectionManager::GetDefaultConnection(); // caosdb::connection::ConnectionManager::GetDefaultConnection();
auto query_transaction(connection->CreateTransaction()); // // query empty database
query_transaction->Query("FIND Property \"Prop *\""); // auto query_transaction(connection->CreateTransaction());
query_transaction->ExecuteAsynchronously(); // query_transaction->Query("FIND Property \"Prop *\"");
auto t_stat = query_transaction->WaitForIt(); // query_transaction->ExecuteAsynchronously();
std::cout << "status: " << t_stat.GetCode() << " // " // auto t_stat = query_transaction->WaitForIt();
<< t_stat.GetDescription() << std::endl; // std::cout << "status: " << t_stat.GetCode() << " // "
// << t_stat.GetDescription() << std::endl;
EXPECT_TRUE(t_stat.GetCode() >= 0); // EXPECT_TRUE(t_stat.GetCode() >= 0);
} // }
/* /*
* insert three recordtypes and the submit multiple queries in different * insert three recordtypes and the submit multiple queries in different
...@@ -1034,7 +1060,7 @@ TEST_F(test_transaction, test_full_workflow) { ...@@ -1034,7 +1060,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<int64_t>(6)); part_for_rt3.SetValue(static_cast<int32_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);
......
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