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
96b51ee7
Commit
96b51ee7
authored
3 years ago
by
Florian Spreckelsen
Browse files
Options
Downloads
Plain Diff
Merge branch 'f-int64' into 'dev'
Tests for f-int64 See merge request
!14
parents
02d697e1
7843b3e3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!14
Tests for f-int64
Pipeline
#13287
passed
3 years ago
Stage: info
Stage: setup
Stage: build
Stage: test
Changes
3
Pipelines
5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
conanfile.txt
+1
-1
1 addition, 1 deletion
conanfile.txt
test/test_list_properties.cpp
+113
-0
113 additions, 0 deletions
test/test_list_properties.cpp
test/test_transaction.cpp
+55
-14
55 additions, 14 deletions
test/test_transaction.cpp
with
169 additions
and
15 deletions
conanfile.txt
+
1
−
1
View file @
96b51ee7
[requires]
caosdb/0.0.1
4
caosdb/0.0.1
5
gtest/1.11.0
[generators]
...
...
This diff is collapsed.
Click to expand it.
test/test_list_properties.cpp
+
113
−
0
View file @
96b51ee7
...
...
@@ -24,6 +24,7 @@
#include
"caosdb/transaction.h"
// for Entity, Transaction,...
#include
"caosdb/transaction_status.h"
// for TransactionStatus, StatusCode
#include
"caosdb/value.h"
// for value
#include
<cstdint>
// for int64_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
...
...
@@ -113,4 +114,116 @@ TEST_F(test_list_properties, insert_list_of_text) {
EXPECT_EQ
(
value
.
AsList
().
at
(
1
).
AsString
(),
"item5"
);
}
TEST_F
(
test_list_properties
,
insert_list_of_int
)
{
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
::
INTEGER
));
abstract_list_property
.
SetValue
(
std
::
vector
<
int64_t
>
{
1
,
2
,
3
});
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
<
int64_t
>
{
4
,
5
,
6
});
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
::
INTEGER
);
EXPECT_TRUE
(
value
.
IsList
());
EXPECT_EQ
(
value
.
AsList
().
size
(),
3
);
EXPECT_TRUE
(
value
.
AsList
().
at
(
1
).
IsInteger
());
EXPECT_EQ
(
value
.
AsList
().
at
(
1
).
AsInteger
(),
5
);
}
TEST_F
(
test_list_properties
,
insert_list_of_bool
)
{
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
::
BOOLEAN
));
abstract_list_property
.
SetValue
(
std
::
vector
<
bool
>
{
true
,
true
,
false
});
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
<
bool
>
{
false
,
false
,
true
});
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
::
BOOLEAN
);
EXPECT_TRUE
(
value
.
IsList
());
EXPECT_EQ
(
value
.
AsList
().
size
(),
3
);
EXPECT_TRUE
(
value
.
AsList
().
at
(
1
).
IsBool
());
EXPECT_FALSE
(
value
.
AsList
().
at
(
1
).
AsBool
());
}
}
// namespace caosdb::entity
This diff is collapsed.
Click to expand it.
test/test_transaction.cpp
+
55
−
14
View file @
96b51ee7
...
...
@@ -33,7 +33,7 @@
#include
<boost/filesystem/path.hpp>
// for path
#include
<boost/filesystem/path_traits.hpp>
// for filesystem
#include
<cstddef>
// for size_t
#include
<cstdint>
// for int32_t
#include
<cstdint>
// for
int64_t,
int32_t
#include
<gtest/gtest-message.h>
// for Message
#include
<gtest/gtest-test-part.h>
// for TestPartResult
#include
<gtest/gtest_pred_impl.h>
// for AssertionResult
...
...
@@ -136,10 +136,15 @@ auto test_transaction::getValueAs<double>(const Value &value) -> double {
}
template
<
>
auto
test_transaction
::
getValueAs
<
int
32
_t
>
(
const
Value
&
value
)
->
int
32
_t
{
auto
test_transaction
::
getValueAs
<
int
64
_t
>
(
const
Value
&
value
)
->
int
64
_t
{
return
value
.
AsInteger
();
}
template
<
>
auto
test_transaction
::
getValueAs
<
int32_t
>
(
const
Value
&
value
)
->
int32_t
{
return
static_cast
<
int32_t
>
(
value
.
AsInteger
());
}
template
<
>
auto
test_transaction
::
getValueAs
<
bool
>
(
const
Value
&
value
)
->
bool
{
return
value
.
AsBool
();
...
...
@@ -697,7 +702,7 @@ TEST_F(test_transaction, test_query) {
/**
* Test numeric values (template).
*/
template
<
typename
T
>
template
<
typename
T
,
typename
S
>
auto
test_numeric_values_impl
(
AtomicDataType
a_type
)
->
void
{
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
...
...
@@ -715,7 +720,7 @@ auto test_numeric_values_impl(AtomicDataType a_type) -> void {
prop
.
SetName
(
name
);
prop
.
SetDataType
(
a_type
);
std
::
cout
<<
"Setting value "
<<
value
<<
std
::
endl
;
prop
.
SetValue
(
value
);
prop
.
SetValue
(
static_cast
<
S
>
(
value
)
)
;
props_orig
.
push_back
(
prop
);
auto
i_stat
=
insert_transaction
->
InsertEntity
(
&
prop
);
EXPECT_EQ
(
i_stat
,
StatusCode
::
READY
);
...
...
@@ -740,12 +745,14 @@ auto test_numeric_values_impl(AtomicDataType a_type) -> void {
EXPECT_TRUE
(
t_stat
.
IsTerminated
());
EXPECT_FALSE
(
t_stat
.
IsError
());
const
auto
result
=
retrieve_transaction
->
GetResultSet
().
at
(
0
);
EXPECT_EQ
(
result
.
GetDataType
(),
a_type
);
const
auto
&
retrieved_value
=
test_transaction
::
getValueAs
<
T
>
(
result
.
GetValue
());
// std::cout << "retrieved_value: " << retrieved_value << std::endl;
EXPECT_EQ
(
retrieved_value
,
value
);
if
(
retrieve_transaction
->
GetResultSet
().
size
()
>
0
)
{
const
auto
result
=
retrieve_transaction
->
GetResultSet
().
at
(
0
);
EXPECT_EQ
(
result
.
GetDataType
(),
a_type
);
const
auto
&
retrieved_value
=
test_transaction
::
getValueAs
<
T
>
(
result
.
GetValue
());
// std::cout << "retrieved_value: " << retrieved_value << std::endl;
EXPECT_EQ
(
retrieved_value
,
value
);
}
++
i
;
}
}
...
...
@@ -754,11 +761,45 @@ auto test_numeric_values_impl(AtomicDataType a_type) -> void {
* Test numeric values (wrapper for types).
*/
TEST_F
(
test_transaction
,
test_numeric_values
)
{
test_numeric_values_impl
<
double
>
(
AtomicDataType
::
DOUBLE
);
test_numeric_values_impl
<
double
,
double
>
(
AtomicDataType
::
DOUBLE
);
test_transaction
::
DeleteEntities
();
test_numeric_values_impl
<
int32_t
>
(
AtomicDataType
::
INTEGER
);
test_numeric_values_impl
<
int32_t
,
int64_t
>
(
AtomicDataType
::
INTEGER
);
test_transaction
::
DeleteEntities
();
test_numeric_values_impl
<
bool
>
(
AtomicDataType
::
BOOLEAN
);
test_numeric_values_impl
<
bool
,
bool
>
(
AtomicDataType
::
BOOLEAN
);
}
TEST_F
(
test_transaction
,
test_integer_out_of_range
)
{
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
// Insert entities
std
::
vector
<
int64_t
>
values
=
{
std
::
numeric_limits
<
int64_t
>::
max
(),
std
::
numeric_limits
<
int64_t
>::
min
()};
for
(
auto
value
:
values
)
{
auto
insert_transaction
(
connection
->
CreateTransaction
());
Entity
prop
;
prop
.
SetRole
(
Role
::
PROPERTY
);
const
auto
name
=
std
::
string
(
"Prop_"
)
+
std
::
to_string
(
value
);
prop
.
SetName
(
name
);
prop
.
SetDataType
(
AtomicDataType
::
INTEGER
);
prop
.
SetValue
(
value
);
auto
i_stat
=
insert_transaction
->
InsertEntity
(
&
prop
);
EXPECT_EQ
(
i_stat
,
StatusCode
::
READY
);
insert_transaction
->
ExecuteAsynchronously
();
auto
t_stat
=
insert_transaction
->
WaitForIt
();
EXPECT_TRUE
(
t_stat
.
IsTerminated
());
EXPECT_TRUE
(
t_stat
.
IsError
());
EXPECT_EQ
(
t_stat
.
GetCode
(),
StatusCode
::
GENERIC_TRANSACTION_ERROR
);
EXPECT_EQ
(
insert_transaction
->
GetResultSet
().
size
(),
1
);
EXPECT_TRUE
(
insert_transaction
->
GetResultSet
().
at
(
0
).
HasErrors
());
EXPECT_EQ
(
insert_transaction
->
GetResultSet
().
at
(
0
).
GetErrors
().
at
(
0
).
GetCode
(),
MessageCode
::
INTEGER_VALUE_OUT_OF_RANGE
);
}
}
// /*
...
...
@@ -1079,7 +1120,7 @@ TEST_F(test_transaction, test_full_workflow) {
experiment_rec
.
AppendProperty
(
volt_for_rt
);
notes_for_rt2
.
SetValue
(
"This is important!"
);
experiment_rec
.
AppendProperty
(
notes_for_rt2
);
part_for_rt3
.
SetValue
(
static_cast
<
int
32
_t
>
(
6
));
part_for_rt3
.
SetValue
(
static_cast
<
int
64
_t
>
(
6
));
experiment_rec
.
AppendProperty
(
part_for_rt3
);
succ_for_rt
.
SetValue
(
true
);
experiment_rec
.
AppendProperty
(
succ_for_rt
);
...
...
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