Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-cpplib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-cpplib
Commits
fc4969d3
Commit
fc4969d3
authored
3 years ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
TST: Add unit tests for properties and CopyTo
parent
249dce56
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!4
ENH: Allow insertion and deletion of single entities
Pipeline
#11192
passed
3 years ago
Stage: info
Stage: setup
Stage: test
Stage: deploy
Pipeline: caosdb-cppinttest
#11194
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/test_entity.cpp
+78
-0
78 additions, 0 deletions
test/test_entity.cpp
with
78 additions
and
0 deletions
test/test_entity.cpp
+
78
−
0
View file @
fc4969d3
...
...
@@ -3,6 +3,7 @@
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
* Copyright (C) 2021 Florian Spreckelsen <f.spreckelsen@indiscale.com>
* Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
...
...
@@ -23,7 +24,9 @@
#include
"caosdb/entity/v1alpha1/main.grpc.pb.h"
// for EntityTransactionSe...
#include
"caosdb/entity/v1alpha1/main.pb.h"
// for IdResponse, Message
#include
"caosdb/message_code.h"
// for MessageCode
#include
"caosdb/protobuf_helper.h"
// for get_arena
#include
"caosdb/transaction.h"
// for Transaction
#include
"google/protobuf/arena.h"
// for Arena
#include
"gtest/gtest-message.h"
// for Message
#include
"gtest/gtest-test-part.h"
// for TestPartResult, Sui...
#include
"gtest/gtest_pred_impl.h"
// for Test, EXPECT_EQ
...
...
@@ -33,6 +36,8 @@
namespace
caosdb
::
entity
{
using
caosdb
::
entity
::
v1alpha1
::
IdResponse
;
using
ProtoEntity
=
caosdb
::
entity
::
v1alpha1
::
Entity
;
using
caosdb
::
utility
::
get_arena
;
TEST
(
test_entity
,
test_parent_setters
)
{
auto
parent
=
Parent
();
...
...
@@ -56,6 +61,79 @@ TEST(test_entity, test_append_parent) {
EXPECT_EQ
(
same_parent
.
GetId
(),
"some-id"
);
}
TEST
(
test_entity
,
test_property_setters
)
{
auto
prop
=
Property
();
prop
.
SetName
(
"prop_name"
);
prop
.
SetId
(
"prop_id"
);
prop
.
SetImportance
(
"prop_importance"
);
prop
.
SetValue
(
"prop_value"
);
prop
.
SetUnit
(
"prop_unit"
);
prop
.
SetDatatype
(
"prop_dtype"
);
EXPECT_EQ
(
prop
.
GetName
(),
"prop_name"
);
EXPECT_EQ
(
prop
.
GetId
(),
"prop_id"
);
EXPECT_EQ
(
prop
.
GetImportance
(),
"prop_importance"
);
EXPECT_EQ
(
prop
.
GetValue
(),
"prop_value"
);
EXPECT_EQ
(
prop
.
GetUnit
(),
"prop_unit"
);
EXPECT_EQ
(
prop
.
GetDatatype
(),
"prop_dtype"
);
}
// TODO(fspreck) cognitive complexity > 25 (threshold)
TEST
(
test_entity
,
test_append_property
)
{
// NOLINT
auto
entity
=
Entity
();
auto
prop
=
Property
();
prop
.
SetName
(
"prop_name"
);
prop
.
SetId
(
"prop_id"
);
prop
.
SetImportance
(
"prop_importance"
);
prop
.
SetValue
(
"prop_value"
);
prop
.
SetUnit
(
"prop_unit"
);
prop
.
SetDatatype
(
"prop_dtype"
);
EXPECT_EQ
(
entity
.
GetProperties
().
Size
(),
0
);
entity
.
AppendProperty
(
prop
);
EXPECT_EQ
(
entity
.
GetProperties
().
Size
(),
1
);
auto
same_prop
=
entity
.
GetProperties
().
At
(
0
);
EXPECT_EQ
(
prop
.
GetName
(),
same_prop
.
GetName
());
EXPECT_EQ
(
prop
.
GetId
(),
same_prop
.
GetId
());
EXPECT_EQ
(
prop
.
GetImportance
(),
same_prop
.
GetImportance
());
EXPECT_EQ
(
prop
.
GetValue
(),
same_prop
.
GetValue
());
EXPECT_EQ
(
prop
.
GetUnit
(),
same_prop
.
GetUnit
());
EXPECT_EQ
(
prop
.
GetDatatype
(),
same_prop
.
GetDatatype
());
}
TEST
(
test_entity
,
test_copy_to
)
{
auto
entity
=
Entity
();
entity
.
SetId
(
"original_id"
);
entity
.
SetName
(
"orignial_name"
);
auto
parent
=
Parent
();
parent
.
SetId
(
"parent_id"
);
parent
.
SetName
(
"parent_name"
);
entity
.
AppendParent
(
parent
);
auto
prop
=
Property
();
prop
.
SetId
(
"prop_id"
);
prop
.
SetName
(
"prop_name"
);
entity
.
AppendProperty
(
prop
);
// create protobuf entity to which all fields ae copied and then a
// CaoosDB entity from that protobuf entity.
auto
*
proto_copy
=
google
::
protobuf
::
Arena
::
CreateMessage
<
ProtoEntity
>
(
get_arena
());
entity
.
CopyTo
(
proto_copy
);
auto
copied
=
Entity
(
proto_copy
);
EXPECT_EQ
(
entity
.
GetId
(),
copied
.
GetId
());
EXPECT_EQ
(
entity
.
GetName
(),
copied
.
GetName
());
EXPECT_EQ
(
copied
.
GetParents
().
At
(
0
).
GetId
(),
parent
.
GetId
());
EXPECT_EQ
(
copied
.
GetParents
().
At
(
0
).
GetName
(),
parent
.
GetName
());
EXPECT_EQ
(
copied
.
GetProperties
().
At
(
0
).
GetId
(),
prop
.
GetId
());
EXPECT_EQ
(
copied
.
GetProperties
().
At
(
0
).
GetName
(),
prop
.
GetName
());
}
TEST
(
test_entity
,
test_insert_entity
)
{
auto
transaction
=
caosdb
::
transaction
::
Transaction
(
std
::
shared_ptr
<
transaction
::
EntityTransactionService
::
Stub
>
(
nullptr
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment