Skip to content
Snippets Groups Projects
Verified Commit 163860ce authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: consolidation

parent 4f7c96c0
No related branches found
No related tags found
1 merge request!12F consolidation
......@@ -304,10 +304,9 @@ private:
*/
class Property {
public:
explicit inline Property(ProtoProperty *wrapped) : wrapped(wrapped), data_type(nullptr), value(nullptr) {
data_type.wrapped = this->wrapped->mutable_data_type();
value.wrapped = this->wrapped->mutable_value();
};
explicit inline Property(ProtoProperty *wrapped)
: wrapped(wrapped), data_type(DataType(wrapped->mutable_data_type())),
value(Value(wrapped->mutable_value())){};
Property();
/**
......@@ -449,7 +448,9 @@ class Entity {
public:
Entity();
inline Entity(const Entity &original)
: wrapped(CreateProtoEntity()), data_type(nullptr), value(nullptr) {
: wrapped(CreateProtoEntity()),
data_type(DataType(wrapped->mutable_data_type())),
value(Value(wrapped->mutable_value())) {
this->wrapped->CopyFrom(*original.wrapped);
data_type.wrapped = this->wrapped->mutable_data_type();
value.wrapped = this->wrapped->mutable_value();
......@@ -460,8 +461,11 @@ public:
infos.wrapped = CreateMessagesField();
};
explicit Entity(IdResponse *id_response);
explicit Entity(ProtoEntity *wrapped) : wrapped(wrapped), data_type(nullptr) {
explicit Entity(ProtoEntity *wrapped)
: wrapped(wrapped), data_type(DataType(wrapped->mutable_data_type())),
value(Value(wrapped->mutable_value())) {
data_type.wrapped = this->wrapped->mutable_data_type();
value.wrapped = this->wrapped->mutable_value();
properties.wrapped = this->wrapped->mutable_properties();
parents.wrapped = this->wrapped->mutable_parents();
errors.wrapped = CreateMessagesField();
......
......@@ -34,8 +34,8 @@
#include <boost/log/sources/record_ostream.hpp> // for basic_record_o...
#include <boost/preprocessor/seq/limits/enum_256.hpp> // for BOOST_PP_SEQ_E...
#include <boost/preprocessor/seq/limits/size_256.hpp> // for BOOST_PP_SEQ_S...
#include <google/protobuf/generated_message_util.h> // for CreateMessage...
#include <google/protobuf/arena.h> // for Arena
#include <google/protobuf/generated_message_util.h> // for CreateMessage...
#include <google/protobuf/util/json_util.h> // for MessageToJsonS...
#include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue
#include <iterator> // for iterator, next
......
......@@ -23,6 +23,8 @@
#define CAOSDB_VALUE_H
#include "caosdb/protobuf_helper.h" // for ProtoMessageWrapper
#include "caosdb/entity/v1alpha1/main.pb.h" // for RepeatedPtrField, Message
#include <google/protobuf/util/json_util.h> // for MessageToJson...
#include <memory> // for unique_ptr
#include <string> // for string
#include <vector> // for vector
......@@ -210,6 +212,11 @@ public:
other.wrapped->SerializeAsString();
}
inline auto ToString() const noexcept -> const std::string {
CAOSDB_DEBUG_MESSAGE_STRING(*wrapped, out)
return out;
}
friend class Entity;
friend class Property;
......
......@@ -209,7 +209,14 @@ auto Entity::SetVersionId(const std::string &id) -> void {
}
auto Entity::CopyTo(ProtoEntity *target) -> void {
CAOSDB_DEBUG_MESSAGE_STRING(*(this->wrapped), out);
CAOSDB_LOG_DEBUG(logger_name) << "COPY ENTITY: " << out;
CAOSDB_DEBUG_MESSAGE_STRING(*target, out_2);
CAOSDB_LOG_DEBUG(logger_name) << "COPY ENTITY TO: " << out_2;
target->Clear();
target->CopyFrom(*(this->wrapped));
CAOSDB_DEBUG_MESSAGE_STRING(*target, out_3);
CAOSDB_LOG_DEBUG(logger_name) << "COPY ENTITY FINAL: " << out_3;
}
auto Entity::SetRole(Role role) -> void {
......
......@@ -25,6 +25,7 @@
#include "caosdb/file_transmission/register_file_upload_handler.h"
#include "caosdb/file_transmission/upload_request_handler.h" // Upload...
#include "caosdb/logging.h" // for CAOSDB_LOG_FATAL
#include "caosdb/protobuf_helper.h"
#include "caosdb/status_code.h" // for StatusCode
#include "caosdb/transaction_handler.h"
#include <algorithm> // for max
......@@ -37,6 +38,8 @@
// IWYU pragma: no_include <bits/exception.h>
#include <exception> // IWYU pragma: keep
#include <google/protobuf/arena.h> // for Arena
#include <google/protobuf/generated_message_util.h> // for CreateMessage...
#include <google/protobuf/util/json_util.h>
#include <grpc/impl/codegen/gpr_types.h>
#include <grpcpp/impl/codegen/completion_queue.h> // for CompletionQueue
#include <iosfwd> // for streamsize
......@@ -222,6 +225,8 @@ auto Transaction::InsertEntity(Entity *entity) noexcept -> StatusCode {
// copy the original entity for the transaction
entity->CopyTo(proto_entity);
CAOSDB_DEBUG_MESSAGE_STRING(*proto_entity, out);
CAOSDB_LOG_DEBUG(logger_name) << "INSERT ENTITY: " << out;
if (entity->HasFile()) {
auto *file_transmission_id = entity_request->mutable_upload_id();
entity->SetFileTransmissionId(file_transmission_id);
......
......@@ -71,38 +71,22 @@ TEST(test_entity, test_append_parent) {
}
TEST(test_entity, test_property_setters) {
CAOSDB_LOG_DEBUG(logger_name) << "HERE 1";
auto prop = Property();
CAOSDB_LOG_DEBUG(logger_name) << "HERE 2";
prop.SetName("prop_name");
CAOSDB_LOG_DEBUG(logger_name) << "HERE 3";
prop.SetId("prop_id");
CAOSDB_LOG_DEBUG(logger_name) << "HERE 4";
prop.SetImportance(Importance::OBLIGATORY);
CAOSDB_LOG_DEBUG(logger_name) << "HERE 5";
prop.SetValue("prop_value");
CAOSDB_LOG_DEBUG(logger_name) << "HERE 6";
prop.SetUnit("prop_unit");
CAOSDB_LOG_DEBUG(logger_name) << "HERE 7";
prop.SetDataType("prop_dtype");
CAOSDB_LOG_DEBUG(logger_name) << "HERE 8";
EXPECT_EQ(prop.GetName(), "prop_name");
CAOSDB_LOG_DEBUG(logger_name) << "HERE 1";
EXPECT_EQ(prop.GetId(), "prop_id");
CAOSDB_LOG_DEBUG(logger_name) << "HERE 2";
EXPECT_EQ(prop.GetImportance(), Importance::OBLIGATORY);
CAOSDB_LOG_DEBUG(logger_name) << "HERE 3";
EXPECT_TRUE(prop.GetValue().IsString());
CAOSDB_LOG_DEBUG(logger_name) << "HERE 4";
EXPECT_EQ(prop.GetValue().AsString(), "prop_value");
CAOSDB_LOG_DEBUG(logger_name) << "HERE 5";
EXPECT_EQ(prop.GetUnit(), "prop_unit");
CAOSDB_LOG_DEBUG(logger_name) << "HERE 6";
EXPECT_TRUE(prop.GetDataType().IsReference());
CAOSDB_LOG_DEBUG(logger_name) << "HERE 7";
EXPECT_EQ(prop.GetDataType().AsReference().GetName(), "prop_dtype");
CAOSDB_LOG_DEBUG(logger_name) << "HERE 8";
}
TEST(test_entity, test_append_property) {
......@@ -238,7 +222,7 @@ TEST(test_entity, test_insert_with_property) {
prop.SetName("prop_name");
prop.SetId("prop_id");
prop.SetImportance(Importance::FIX);
prop.SetValue("prop_value");
prop.SetValue(Value("prop_value"));
prop.SetUnit("prop_unit");
prop.SetDataType("prop_dtype");
......@@ -253,6 +237,7 @@ TEST(test_entity, test_insert_with_property) {
EXPECT_EQ(prop.GetName(), inserted_prop.GetName());
EXPECT_EQ(prop.GetId(), inserted_prop.GetId());
EXPECT_EQ(prop.GetImportance(), inserted_prop.GetImportance());
EXPECT_EQ(prop.GetValue().ToString(), inserted_prop.GetValue().ToString());
EXPECT_EQ(prop.GetValue(), inserted_prop.GetValue());
EXPECT_EQ(prop.GetUnit(), inserted_prop.GetUnit());
EXPECT_EQ(prop.GetDataType(), inserted_prop.GetDataType());
......
......@@ -20,13 +20,15 @@
*
*/
#include "caosdb/entity/v1alpha1/main.pb.h" // for RepeatedPtrField, Message
#include "caosdb/entity.h"
#include "gtest/gtest-message.h" // for Message
#include "gtest/gtest-test-part.h" // for SuiteApiResolver, TestPa...
#include "gtest/gtest_pred_impl.h" // for Test, TestInfo, TEST
#include <memory> // for allocator
namespace caosdb {
using caosdb::entity::v1alpha1::Entity;
using ProtoEntity = caosdb::entity::v1alpha1::Entity;
using caosdb::entity::Entity;
using caosdb::entity::v1alpha1::Message;
TEST(test_protobuf, test_swap_trivial) {
......@@ -50,12 +52,12 @@ TEST(test_protobuf, test_swap_trivial) {
}
TEST(test_protobuf, test_swap_nested) {
Entity entity_source;
ProtoEntity entity_source;
entity_source.set_id("entity_id");
auto *version_source = entity_source.mutable_version();
version_source->set_id("version_id");
Entity entity_destination;
ProtoEntity entity_destination;
auto *version_destination = entity_destination.mutable_version();
EXPECT_EQ(entity_source.id(), "entity_id");
......@@ -81,4 +83,32 @@ TEST(test_protobuf, test_swap_nested) {
EXPECT_EQ(entity_destination.mutable_version(), version_source);
}
TEST(test_protobuf, test_copy_nested) {
ProtoEntity entity_source;
auto *data_type_source = entity_source.mutable_data_type();
data_type_source->mutable_reference_data_type()->set_name("src_per");
ProtoEntity entity_destination;
auto *data_type_destination = entity_destination.mutable_data_type();
data_type_destination->mutable_reference_data_type()->set_name("dest_per");
EXPECT_EQ(entity_source.data_type().reference_data_type().name(), "src_per");
EXPECT_EQ(entity_destination.data_type().reference_data_type().name(),
"dest_per");
entity_destination.CopyFrom(entity_source);
EXPECT_EQ(entity_source.data_type().reference_data_type().name(), "src_per");
EXPECT_EQ(entity_destination.data_type().reference_data_type().name(),
"src_per");
Entity entity(&entity_destination);
EXPECT_EQ(entity.GetDataType().AsReference().GetName(), "src_per");
EXPECT_EQ(entity.ToString(), "");
Entity copy_entity(entity);
EXPECT_EQ(copy_entity.GetDataType().AsReference().GetName(), "src_per");
EXPECT_EQ(copy_entity.ToString(), "");
}
} // namespace caosdb
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment