Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-cppinttest
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-cppinttest
Commits
efa02509
Verified
Commit
efa02509
authored
3 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
TST: list property
parent
d3b07685
No related branches found
No related tags found
1 merge request
!9
F consolidation
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
test/CMakeLists.txt
+1
-0
1 addition, 0 deletions
test/CMakeLists.txt
test/test_list_properties.cpp
+114
-0
114 additions, 0 deletions
test/test_list_properties.cpp
test/test_transaction.cpp
+1
-1
1 addition, 1 deletion
test/test_transaction.cpp
with
116 additions
and
1 deletion
test/CMakeLists.txt
+
1
−
0
View file @
efa02509
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
set
(
test_cases
set
(
test_cases
test_connection
test_connection
test_transaction
test_transaction
test_list_properties
test_ccaosdb
test_ccaosdb
)
)
...
...
This diff is collapsed.
Click to expand it.
test/test_list_properties.cpp
0 → 100644
+
114
−
0
View file @
efa02509
/*
* 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
#include
"caosdb/entity.h"
// for Entity, Messages, Message
#include
"caosdb/transaction.h"
// for Entity, Transaction,...
#include
"caosdb/transaction_status.h"
// for TransactionStatus, StatusCode
#include
"caosdb/value.h"
// for value
#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
namespace
caosdb
::
entity
{
class
test_list_properties
:
public
::
testing
::
Test
{
protected:
void
SetUp
()
override
{}
void
TearDown
()
override
{
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_list_properties
,
insert_list_of_text
)
{
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
auto
insertion_prop
(
connection
->
CreateTransaction
());
Entity
abstract_list_property
;
abstract_list_property
.
SetRole
(
Role
::
PROPERTY
);
abstract_list_property
.
SetName
(
"TestProp"
);
abstract_list_property
.
SetDataType
(
DataType
::
ListOf
(
AtomicDataType
::
TEXT
));
abstract_list_property
.
SetValue
(
std
::
vector
<
std
::
string
>
{
"item1"
,
"item2"
,
"item3"
});
insertion_prop
->
InsertEntity
(
&
abstract_list_property
);
std
::
cout
<<
"response "
<<
insertion_prop
->
ResponseToString
();
insertion_prop
->
Execute
();
EXPECT_TRUE
(
insertion_prop
->
GetStatus
().
IsTerminated
());
auto
insertion_rt
(
connection
->
CreateTransaction
());
Property
list_property
;
list_property
.
SetId
(
insertion_prop
->
GetResultSet
().
at
(
0
).
GetId
());
list_property
.
SetValue
(
std
::
vector
<
std
::
string
>
{
"item4"
,
"item5"
,
"item6"
});
Entity
entity
;
entity
.
SetRole
(
Role
::
RECORD_TYPE
);
entity
.
SetName
(
"TestRT"
);
entity
.
AppendProperty
(
list_property
);
insertion_rt
->
InsertEntity
(
&
entity
);
std
::
cout
<<
"response "
<<
insertion_rt
->
ResponseToString
();
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_rt
->
GetResultSet
().
at
(
0
).
GetId
());
retrieval
->
Execute
();
EXPECT_TRUE
(
retrieval
->
GetStatus
().
IsTerminated
());
EXPECT_FALSE
(
retrieval
->
GetStatus
().
IsError
());
const
auto
&
same_entity
=
retrieval
->
GetResultSet
().
at
(
0
);
const
auto
&
data_type
=
same_entity
.
GetProperties
().
at
(
0
).
GetDataType
();
const
auto
&
value
=
same_entity
.
GetProperties
().
at
(
0
).
GetValue
();
EXPECT_TRUE
(
data_type
.
IsList
());
EXPECT_TRUE
(
data_type
.
AsList
().
IsListOfAtomic
());
EXPECT_EQ
(
data_type
.
AsList
().
GetAtomicDataType
(),
AtomicDataType
::
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"
);
}
}
// namespace caosdb::entity
This diff is collapsed.
Click to expand it.
test/test_transaction.cpp
+
1
−
1
View file @
efa02509
...
@@ -346,7 +346,7 @@ TEST_F(test_transaction, insert_delete_with_property) {
...
@@ -346,7 +346,7 @@ TEST_F(test_transaction, insert_delete_with_property) {
Property
prop_rec
;
Property
prop_rec
;
prop_rec
.
SetName
(
prop_ent
.
GetName
());
prop_rec
.
SetName
(
prop_ent
.
GetName
());
prop_rec
.
SetId
(
inserted_prop
.
GetId
());
prop_rec
.
SetId
(
inserted_prop
.
GetId
());
prop_rec
.
SetValue
(
"Test"
);
prop_rec
.
SetValue
(
std
::
string
(
"Test"
)
)
;
Entity
rec
;
Entity
rec
;
rec
.
SetName
(
"TestRec"
);
rec
.
SetName
(
"TestRec"
);
...
...
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