Skip to content
Snippets Groups Projects

F consolidation

Merged Timm Fitschen requested to merge f-consolidation into dev
2 files
+ 4
3
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 116
0
/*
*
* 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/data_type.h" // for DataType, AtomicDataType
#include "caosdb/entity.h" // for Entity
#include "caosdb/logging.h" // for CAOSDB_LOG_DEBUG
#include <boost/log/core/record.hpp> // for record
#include <boost/log/detail/attachable_sstream_buf.hpp> // for basic_ostring...
#include <boost/log/sources/record_ostream.hpp> // for operator<<
#include <boost/preprocessor/seq/limits/enum_256.hpp> // for BOOST_PP_SEQ_...
#include <boost/preprocessor/seq/limits/size_256.hpp> // for BOOST_PP_SEQ_...
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApi...
#include <gtest/gtest_pred_impl.h> // for AssertionResult, Test
#include <iosfwd> // for streamsize
#include <string> // for allocator
namespace caosdb::entity {
using ProtoEntity = caosdb::entity::v1alpha1::Entity;
using ProtoParent = caosdb::entity::v1alpha1::Parent;
using ProtoDataType = caosdb::entity::v1alpha1::DataType;
using ProtoAtomicDataType = caosdb::entity::v1alpha1::AtomicDataType;
TEST(test_data_type, test_atomic) {
ProtoDataType proto_data_type;
for (const auto &map_el : atomicdatatype_names) {
Entity entity;
entity.SetRole(Role::PROPERTY);
// the different AtomicDataType are associated with integers
entity.SetDataType(map_el.first);
EXPECT_TRUE(entity.GetDataType().IsAtomic());
EXPECT_EQ(entity.GetDataType().AsAtomic(), map_el.first);
proto_data_type.set_atomic_data_type(static_cast<ProtoAtomicDataType>(map_el.first));
DataType data_type(&proto_data_type);
entity.SetDataType(data_type);
EXPECT_FALSE(data_type.IsReference());
EXPECT_EQ(data_type.AsReference().GetName(), std::basic_string<char>(""));
EXPECT_FALSE(data_type.IsList());
EXPECT_TRUE(data_type.IsAtomic());
EXPECT_EQ(data_type.AsAtomic(), map_el.first);
}
}
TEST(test_data_type, test_reference) {
ProtoDataType proto_data_type;
Entity entity;
entity.SetRole(Role::PROPERTY);
entity.SetDataType("Person");
EXPECT_TRUE(entity.GetDataType().IsReference());
EXPECT_EQ(entity.GetDataType().AsReference().GetName(), "Person");
proto_data_type.mutable_reference_data_type()->set_name("Person");
DataType data_type(&proto_data_type);
entity.SetDataType(data_type);
EXPECT_TRUE(data_type.IsReference());
EXPECT_FALSE(data_type.IsList());
EXPECT_FALSE(data_type.IsAtomic());
EXPECT_EQ(data_type.AsReference().GetName(), "Person");
}
TEST(test_data_type, test_list_of_atomic) {
for (const auto &map_el : atomicdatatype_names) {
DataType data_type(map_el.first, true);
EXPECT_FALSE(data_type.IsReference());
EXPECT_FALSE(data_type.IsAtomic());
EXPECT_TRUE(data_type.IsList());
const auto &list_data_type = data_type.AsList();
EXPECT_EQ(list_data_type.GetReferenceDataType().GetName(), std::basic_string<char>(""));
EXPECT_TRUE(list_data_type.IsListOfAtomic());
EXPECT_FALSE(list_data_type.IsListOfReference());
EXPECT_EQ(list_data_type.GetAtomicDataType(), map_el.first);
}
}
TEST(test_data_type, test_list_of_reference) {
auto data_type = DataType("person", true);
EXPECT_FALSE(data_type.IsReference());
EXPECT_FALSE(data_type.IsAtomic());
EXPECT_TRUE(data_type.IsList());
const auto &list_data_type = data_type.AsList();
EXPECT_TRUE(list_data_type.IsListOfReference());
EXPECT_FALSE(list_data_type.IsListOfAtomic());
const auto *wrapped = list_data_type.GetReferenceDataType().GetWrapped();
CAOSDB_DEBUG_MESSAGE_STRING(*wrapped, out)
CAOSDB_LOG_DEBUG("caosdb::entity") << "wrapped " + out;
EXPECT_EQ(list_data_type.GetReferenceDataType().GetName(), "person");
}
} // namespace caosdb::entity
Loading