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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-cppinttest
Commits
e279661d
Commit
e279661d
authored
Aug 26, 2021
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
TEST: Test for numeric values.
Also switched to 32 bit integer values.
parent
2dbd45c6
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!12
TEST: Test for numeric values.
Pipeline
#12637
failed
Aug 26, 2021
Stage: info
Stage: setup
Stage: build
Stage: test
Changes
4
Pipelines
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG.md
+22
-0
22 additions, 0 deletions
CHANGELOG.md
CMakeLists.txt
+1
-0
1 addition, 0 deletions
CMakeLists.txt
test/CMakeLists.txt
+1
-0
1 addition, 0 deletions
test/CMakeLists.txt
test/test_transaction.cpp
+74
-48
74 additions, 48 deletions
test/test_transaction.cpp
with
98 additions
and
48 deletions
CHANGELOG.md
0 → 100644
+
22
−
0
View file @
e279661d
# Changelog
All notable changes to this project will be documented in this file.
The format is based on
[
Keep a Changelog
](
https://keepachangelog.com/en/1.1.0/
)
,
and this project adheres to
[
Semantic Versioning
](
https://semver.org/spec/v2.0.0.html
)
.
## [Unreleased]
### Added
### Changed
*
Integer values are 32 bit now.
### Deprecated
### Removed
### Fixed
### Security
This diff is collapsed.
Click to expand it.
CMakeLists.txt
+
1
−
0
View file @
e279661d
...
...
@@ -54,6 +54,7 @@ add_subdirectory(test)
#######################################################
option
(
AUTOFORMATTING
"call clang-format at configure time"
ON
)
if
(
AUTOFORMATTING
)
message
(
"Autoformatting is on. To disable, call cmake with '-D AUTOFORMATTING=OFF'."
)
file
(
GLOB format_test_sources test/*.cpp test/*.h
)
execute_process
(
COMMAND clang-format -i --verbose
${
format_test_sources
}
WORKING_DIRECTORY
${
PROJECT_SOURCE_DIR
}
)
...
...
This diff is collapsed.
Click to expand it.
test/CMakeLists.txt
+
1
−
0
View file @
e279661d
...
...
@@ -54,6 +54,7 @@ add_compiler_flag("-g")
#######################################################
option
(
LINTING
"clang-tidy and iwye"
ON
)
if
(
LINTING
)
message
(
"Linting is on. To disable, call cmake with '-D LINTING=OFF'."
)
### set paranoid compiler flags
#add_compiler_flag("-Wall")
#add_compiler_flag("-Wextra")
...
...
This diff is collapsed.
Click to expand it.
test/test_transaction.cpp
+
74
−
48
View file @
e279661d
...
...
@@ -48,27 +48,31 @@ using caosdb::entity::MessageCode;
using
caosdb
::
entity
::
Parent
;
using
caosdb
::
entity
::
Property
;
using
caosdb
::
entity
::
Role
;
using
caosdb
::
entity
::
Value
;
class
test_transaction
:
public
::
testing
::
Test
{
public:
//
public utility functions
////////////////////////////////////////////////////////
// public utility functions
// ////////////////////////////////////////////////////////
/**
* Generate a vector with useful values for testing.
*/
template
<
typename
T
>
static
auto
generateValues
()
->
std
::
vector
<
T
>
{
std
::
vector
<
T
>
values
=
{
0
,
1
,
std
::
numeric_limits
<
T
>::
max
(),
std
::
numeric_limits
<
T
>::
min
(),
std
::
numeric_limits
<
T
>::
lowest
(),
0
,
1
,
// (T)6.91629132943846e-310,
std
::
numeric_limits
<
T
>::
max
(),
std
::
numeric_limits
<
T
>::
min
(),
std
::
numeric_limits
<
T
>::
denorm_min
(),
std
::
numeric_limits
<
T
>::
lowest
(),
std
::
numeric_limits
<
T
>::
epsilon
()
// 0 for integers, but who cares?
};
return
values
;
}
template
<
typename
T
>
static
auto
getValueAs
(
const
Value
&
value
)
->
T
{
throw
std
::
logic_error
(
"Template not implemented for this type."
);
}
static
void
DeleteEntities
()
{
// delete all entities
const
auto
&
connection
=
...
...
@@ -77,6 +81,9 @@ public:
query_transaction
->
Query
(
"FIND ENTITY WITH id > 99"
);
query_transaction
->
Execute
();
if
(
query_transaction
->
GetResultSet
().
size
()
>
0
)
{
std
::
cout
<<
"Cleanup: Deleting "
<<
query_transaction
->
GetResultSet
().
size
()
<<
" entities."
<<
std
::
endl
;
auto
delete_transaction
(
connection
->
CreateTransaction
());
for
(
const
Entity
&
entity
:
query_transaction
->
GetResultSet
())
{
delete_transaction
->
DeleteById
(
entity
.
GetId
());
...
...
@@ -85,7 +92,6 @@ public:
}
}
protected
:
fs
::
path
test_upload_file_1
;
fs
::
path
test_download_file_1
;
...
...
@@ -112,9 +118,18 @@ protected:
fs
::
remove
(
test_download_file_1
);
DeleteEntities
();
}
};
template
<
>
auto
test_transaction
::
getValueAs
<
double
>
(
const
Value
&
value
)
->
double
{
return
value
.
AsDouble
();
}
template
<
>
auto
test_transaction
::
getValueAs
<
int32_t
>
(
const
Value
&
value
)
->
int32_t
{
return
value
.
AsInteger
();
}
/*
* Test the retrieval of a non-existing entity
*
...
...
@@ -673,43 +688,54 @@ auto test_numeric_values_impl(AtomicDataType a_type) -> void {
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
// Insert entities
auto
insert_transaction
(
connection
->
CreateTransaction
());
auto
values_orig
=
test_transaction
::
generateValues
<
T
>
();
auto
props_orig
=
std
::
vector
<
Entity
>
();
size_t
i
=
0
;
--
i
;
for
(
auto
value
:
values_orig
)
{
++
i
;
auto
insert_transaction
(
connection
->
CreateTransaction
());
Entity
prop
;
prop
.
SetRole
(
Role
::
PROPERTY
);
prop
.
SetName
(
std
::
string
(
"Prop "
)
+
boost
::
lexical_cast
<
std
::
string
>
(
i
));
const
auto
name
=
std
::
string
(
"Prop "
)
+
boost
::
lexical_cast
<
std
::
string
>
(
i
);
std
::
cout
<<
"Creating: "
<<
name
<<
std
::
endl
;
prop
.
SetName
(
name
);
prop
.
SetDataType
(
a_type
);
std
::
cout
<<
"Setting value "
<<
value
<<
std
::
endl
;
prop
.
SetValue
(
value
);
props_orig
.
push_back
(
prop
);
insert_transaction
->
InsertEntity
(
&
prop
);
auto
i_stat
=
insert_transaction
->
InsertEntity
(
&
prop
);
EXPECT_EQ
(
i_stat
,
StatusCode
::
READY
);
insert_transaction
->
ExecuteAsynchronously
();
auto
t_stat
=
insert_transaction
->
WaitForIt
();
ASSER
T_TRUE
(
t_stat
.
IsTerminated
());
ASSER
T_FALSE
(
t_stat
.
IsError
());
EXPEC
T_TRUE
(
t_stat
.
IsTerminated
());
EXPEC
T_FALSE
(
t_stat
.
IsError
());
}
// Retrieve and verify
auto
retrieve_transaction
(
connection
->
CreateTransaction
());
i
=
0
;
--
i
;
for
(
auto
value
:
values_orig
)
{
for
(
const
auto
value
:
values_orig
)
{
++
i
;
auto
prop
=
props_orig
[
i
];
auto
name
=
std
::
string
(
"Prop "
)
+
boost
::
lexical_cast
<
std
::
string
>
(
i
);
auto
query
=
std
::
string
(
"FIND ENTITY
\"
Prop "
)
+
boost
::
lexical_cast
<
std
::
string
>
(
i
)
+
"
\"
"
;
auto
retrieve_transaction
(
connection
->
CreateTransaction
());
const
auto
prop
=
props_orig
[
i
];
const
auto
name
=
std
::
string
(
"Prop "
)
+
boost
::
lexical_cast
<
std
::
string
>
(
i
);
std
::
cout
<<
"Retrieving: "
<<
name
<<
std
::
endl
;
const
auto
query
=
std
::
string
(
"FIND ENTITY
\"
"
)
+
name
+
"
\"
"
;
retrieve_transaction
->
Query
(
query
);
retrieve_transaction
->
ExecuteAsynchronously
();
auto
t_stat
=
retrieve_transaction
->
WaitForIt
();
ASSERT_TRUE
(
t_stat
.
IsTerminated
());
ASSERT_FALSE
(
t_stat
.
IsError
());
auto
result
=
retrieve_transaction
->
GetResultSet
().
at
(
0
);
ASSERT_EQ
(
result
.
GetDataType
(),
a_type
);
const
auto
t_stat
=
retrieve_transaction
->
WaitForIt
();
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
);
}
}
...
...
@@ -718,26 +744,26 @@ auto test_numeric_values_impl(AtomicDataType a_type) -> void {
*/
TEST_F
(
test_transaction
,
test_numeric_values
)
{
test_numeric_values_impl
<
double
>
(
AtomicDataType
::
DOUBLE
);
DeleteEntities
();
test_numeric_values_impl
<
int
64
_t
>
(
AtomicDataType
::
INTEGER
);
test_transaction
::
DeleteEntities
();
test_numeric_values_impl
<
int
32
_t
>
(
AtomicDataType
::
INTEGER
);
}
/*
* test miscellaneous queries
*/
TEST_F
(
test_transaction
,
test_queries_misc
)
{
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
auto
query_transaction
(
connection
->
CreateTransaction
());
query_transaction
->
Query
(
"FIND Property
\"
Prop *
\"
"
);
query_transaction
->
ExecuteAsynchronously
(
);
auto
t_stat
=
query_transaction
->
WaitForIt
();
std
::
cout
<<
"status: "
<<
t_stat
.
GetCode
()
<<
" // "
<<
t_stat
.
GetDescription
()
<<
std
::
endl
;
EXPECT_TRUE
(
t_stat
.
GetCode
()
>=
0
);
}
//
/*
//
* test miscellaneous queries
//
*/
//
TEST_F(test_transaction, test_queries_misc) {
//
const auto &connection =
//
caosdb::connection::ConnectionManager::GetDefaultConnection();
// // query empty database
// auto
query_transaction
(connection->CreateTransaction()
);
//
query_transaction->
Query("FIND Property \"Prop *\""
);
//
query_transaction->
ExecuteAsynchronously
();
// auto t_stat = query_transaction->WaitForIt();
// std::cout << "status: " << t_stat.GetCode() << " // "
// << t_stat.GetDescription() << std::endl;
//
EXPECT_TRUE(t_stat.GetCode() >= 0);
//
}
/*
* insert three recordtypes and the submit multiple queries in different
...
...
@@ -1034,7 +1060,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
64
_t
>
(
6
));
part_for_rt3
.
SetValue
(
static_cast
<
int
32
_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