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

Merge branch 'f-value-and-unit' into 'dev'

Tests for values and units

See merge request !13
parents a01a35a7 c5e5b72c
No related branches found
No related tags found
1 merge request!13Tests for values and units
Pipeline #13047 passed
[requires]
caosdb/0.0.13
caosdb/0.0.14
gtest/1.11.0
[generators]
......
......@@ -23,8 +23,9 @@
#######################################################################
set(test_cases
test_connection
test_transaction
test_list_properties
test_properties
test_transaction
test_ccaosdb
test_issues
)
......
......@@ -18,19 +18,19 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "caosdb/file_transmission/file_reader.h" // for FileReader
#include "caosdb/file_transmission/file_writer.h" // for FileWriter
#include "caosdb/message_code.h" // for MessageCode
#include "caosdb/status_code.h" // for StatusCode
#include "ccaosdb.h" // for caosdb_info_version_info, caosdb_...
#include "caosdb/message_code.h" // for ENTITY_DOES_NOT_EXIST
#include "caosdb/status_code.h" // for GO_ON, StatusCode
#include "ccaosdb.h" // for caosdb_connection_...
#include <boost/filesystem/operations.hpp> // for remove
#include <boost/filesystem/path.hpp> // for path
#include <boost/filesystem/path_traits.hpp> // for filesystem
#include <cstring> // for strcmp
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for TestPartResult
#include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, SuiteApiResolver
#include <iostream>
#include <memory> // for allocator, unique_ptr
#include <gtest/gtest_pred_impl.h> // for EXPECT_EQ, TestInfo
#include <iostream> // for operator<<, endl
#include <string> // for allocator, string
namespace fs = boost::filesystem;
class test_ccaosdb : public ::testing::Test {
......
#include "caosdb/connection.h" // for Connection, ConnectionManager
/*
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2021 Daniel Hornung <d.hornung@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "caosdb/connection.h" // for Connection, Connec...
#include "caosdb/data_type.h" // for AtomicDataType
#include "caosdb/entity.h" // for Entity, Messages, Message
#include "caosdb/file_transmission/file_reader.h" // for FileReader
#include "caosdb/file_transmission/file_writer.h" // for FileWriter
#include "caosdb/message_code.h" // for ENTITY_DOES_NOT_EXIST, Messag...
#include "caosdb/status_code.h" // for SUCCESS, StatusCode
#include "caosdb/transaction.h" // for Entity, Transaction,...
#include "caosdb/transaction_status.h" // for TransactionStatus, StatusCode
#include <boost/filesystem/operations.hpp> // for remove
#include <boost/filesystem/path.hpp> // for path
#include <boost/filesystem/path_traits.hpp> // for filesystem
#include <boost/lexical_cast.hpp>
#include "caosdb/entity.h" // for Entity, Parent, Role
#include "caosdb/transaction.h" // for Transaction, Entity
#include "caosdb/transaction_status.h" // for TransactionStatus
#include <cstdint> // for int32_t
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-spi.h> // for EXPECT_NONFATAL_FAILURE
#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver
#include <gtest/gtest_pred_impl.h> // for Test, EXPECT_EQ, AssertionResult
#include <iostream>
#include <memory> // for unique_ptr, allocator, __shar...
#include <string> // for string
#include <gtest/gtest-spi.h> // for EXPECT_NONFATAL_FA...
#include <gtest/gtest-test-part.h> // for TestPartResult
#include <gtest/gtest_pred_impl.h> // for AssertionResult
#include <iostream> // for operator<<, endl
#include <memory> // for unique_ptr, allocator
#include <string> // for operator+, operator<<
#include <vector> // for vector
namespace fs = boost::filesystem;
namespace caosdb::transaction {
using caosdb::entity::AtomicDataType;
using caosdb::entity::Entity;
using caosdb::entity::Parent;
using caosdb::entity::Role;
using caosdb::entity::Value;
class test_issues : public ::testing::Test {
public:
// 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,
// (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 =
......@@ -71,31 +63,11 @@ public:
}
protected:
fs::path test_upload_file_1;
fs::path test_download_file_1;
// Fixture methods //////////////////////////////////////////////////////////
void SetUp() override {
DeleteEntities();
test_upload_file_1 = fs::path("test_upload_file_1_delete_me.dat");
test_download_file_1 = fs::path("test_download_file_1_delete_me.dat");
void SetUp() override { DeleteEntities(); }
// fill the file that shall be uploaded
FileWriter writer(test_upload_file_1);
std::string buffer(1024, 'c');
for (int i = 0; i < 8; i++) {
writer.write(buffer);
}
}
void TearDown() override {
// delete files
fs::remove(test_upload_file_1);
fs::remove(test_download_file_1);
DeleteEntities();
}
void TearDown() override { DeleteEntities(); }
};
/*
......
......@@ -110,7 +110,7 @@ TEST_F(test_list_properties, insert_list_of_text) {
EXPECT_TRUE(value.IsList());
EXPECT_EQ(value.AsList().size(), 3);
EXPECT_TRUE(value.AsList().at(1).IsString());
EXPECT_EQ(value.AsList().at(1).AsString(), "item6");
EXPECT_EQ(value.AsList().at(1).AsString(), "item5");
}
} // namespace caosdb::entity
/*
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
* Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include "caosdb/connection.h" // for Connection, ConnectionManager
#include "caosdb/data_type.h" // for AtomicDataType, AtomicDataTyp...
#include "caosdb/entity.h" // for Entity, Properties, Property
#include "caosdb/transaction.h" // for Transaction, ResultSet, Resul...
#include "caosdb/transaction_status.h" // for TransactionStatus
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver
#include <gtest/gtest_pred_impl.h> // for AssertionResult, EXPECT_EQ
#include <memory> // for unique_ptr, allocator, __shar...
namespace caosdb::entity {
class test_properties : public ::testing::Test {
protected:
void SetUp() override { DeleteEntities(); }
void TearDown() override { DeleteEntities(); }
static void DeleteEntities() {
const auto &connection =
caosdb::connection::ConnectionManager::GetDefaultConnection();
auto query_transaction(connection->CreateTransaction());
query_transaction->Query("FIND ENTITY WITH id > 99");
query_transaction->Execute();
if (query_transaction->GetResultSet().size() > 0) {
auto delete_transaction(connection->CreateTransaction());
for (const Entity &entity : query_transaction->GetResultSet()) {
delete_transaction->DeleteById(entity.GetId());
}
delete_transaction->Execute();
}
}
};
TEST_F(test_properties, retrieve_unit) {
const auto &connection =
caosdb::connection::ConnectionManager::GetDefaultConnection();
auto insertion_prop(connection->CreateTransaction());
Entity abstract_property;
abstract_property.SetRole(Role::PROPERTY);
abstract_property.SetName("TestProp");
abstract_property.SetDataType(AtomicDataType::DOUBLE);
abstract_property.SetUnit("V");
insertion_prop->InsertEntity(&abstract_property);
insertion_prop->Execute();
EXPECT_TRUE(insertion_prop->GetStatus().IsTerminated());
auto insertion_rt(connection->CreateTransaction());
Property property;
property.SetId(insertion_prop->GetResultSet().at(0).GetId());
Entity entity;
entity.SetRole(Role::RECORD_TYPE);
entity.SetName("TestRT");
entity.AppendProperty(property);
insertion_rt->InsertEntity(&entity);
insertion_rt->Execute();
EXPECT_TRUE(insertion_rt->GetStatus().IsTerminated());
EXPECT_FALSE(insertion_rt->GetStatus().IsError());
// retrieve and check again
auto retrieval(connection->CreateTransaction());
retrieval->RetrieveById(insertion_prop->GetResultSet().at(0).GetId());
retrieval->RetrieveById(insertion_rt->GetResultSet().at(0).GetId());
retrieval->ExecuteAsynchronously();
retrieval->WaitForIt();
EXPECT_TRUE(retrieval->GetStatus().IsTerminated());
EXPECT_FALSE(retrieval->GetStatus().IsError());
const auto &same_property = retrieval->GetResultSet().at(0);
EXPECT_EQ(same_property.GetDataType().AsAtomic(), AtomicDataType::DOUBLE);
EXPECT_EQ(same_property.GetUnit(), "V");
const auto &same_record_type = retrieval->GetResultSet().at(1);
EXPECT_EQ(same_record_type.GetProperties().at(0).GetDataType().AsAtomic(),
AtomicDataType::DOUBLE);
EXPECT_EQ(same_record_type.GetProperties().at(0).GetUnit(), "V");
}
} // namespace caosdb::entity
......@@ -19,26 +19,30 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include "caosdb/connection.h" // for Connection, ConnectionManager
#include "caosdb/connection.h" // for Connection, Connec...
#include "caosdb/data_type.h" // for AtomicDataType
#include "caosdb/entity.h" // for Entity, Messages, Message
#include "caosdb/file_transmission/file_reader.h" // for FileReader
#include "caosdb/entity.h" // for Entity, Property
#include "caosdb/file_transmission/file_reader.h" // for path, FileReader
#include "caosdb/file_transmission/file_writer.h" // for FileWriter
#include "caosdb/message_code.h" // for ENTITY_DOES_NOT_EXIST, Messag...
#include "caosdb/status_code.h" // for SUCCESS, StatusCode
#include "caosdb/transaction.h" // for Entity, Transaction,...
#include "caosdb/transaction_status.h" // for TransactionStatus, StatusCode
#include "caosdb/message_code.h" // for MessageCode, ENTIT...
#include "caosdb/status_code.h" // for StatusCode, SUCCESS
#include "caosdb/transaction.h" // for Entity, Transaction
#include "caosdb/transaction_status.h" // for TransactionStatus
#include "caosdb/value.h" // for Value
#include <boost/filesystem/operations.hpp> // for remove
#include <boost/filesystem/path.hpp> // for path
#include <boost/filesystem/path_traits.hpp> // for filesystem
#include <boost/lexical_cast.hpp>
#include <cstddef> // for size_t
#include <cstdint> // for int32_t
#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>
#include <memory> // for unique_ptr, allocator, __shar...
#include <string> // for string
#include <vector> // for vector
#include <gtest/gtest-test-part.h> // for TestPartResult
#include <gtest/gtest_pred_impl.h> // for AssertionResult
#include <iostream> // for operator<<, endl
#include <limits> // for numeric_limits
#include <memory> // for unique_ptr, allocator
#include <stdexcept> // for logic_error
#include <string> // for string, operator+
#include <vector> // for vector, operator!=
namespace fs = boost::filesystem;
namespace caosdb::transaction {
......@@ -61,10 +65,13 @@ public:
*/
template <typename T> static auto generateValues() -> std::vector<T> {
std::vector<T> values = {
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(),
static_cast<T>(0),
static_cast<T>(1),
static_cast<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?
};
......@@ -96,7 +103,8 @@ public:
protected:
fs::path test_upload_file_1;
fs::path test_download_file_1;
size_t test_file_size_kib = 20; // We should test at least something over 16kiB
size_t test_file_size_kib =
20; // We should test at least something over 16kiB
// Fixture methods //////////////////////////////////////////////////////////
......@@ -132,6 +140,11 @@ auto test_transaction::getValueAs<int32_t>(const Value &value) -> int32_t {
return value.AsInteger();
}
template <>
auto test_transaction::getValueAs<bool>(const Value &value) -> bool {
return value.AsBool();
}
/*
* Test the retrieval of a non-existing entity
*
......@@ -744,6 +757,8 @@ TEST_F(test_transaction, test_numeric_values) {
test_numeric_values_impl<double>(AtomicDataType::DOUBLE);
test_transaction::DeleteEntities();
test_numeric_values_impl<int32_t>(AtomicDataType::INTEGER);
test_transaction::DeleteEntities();
test_numeric_values_impl<bool>(AtomicDataType::BOOLEAN);
}
// /*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment