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
968a6c61
Verified
Commit
968a6c61
authored
3 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Plain Diff
Merge branch 'dev' into f-value-and-unit
parents
578dd606
658562d7
No related branches found
No related tags found
1 merge request
!13
Tests for values and units
Pipeline
#12893
failed
3 years ago
Stage: info
Stage: setup
Stage: build
Stage: test
Changes
3
Pipelines
1
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_issues.cpp
+171
-0
171 additions, 0 deletions
test/test_issues.cpp
test/test_transaction.cpp
+2
-1
2 additions, 1 deletion
test/test_transaction.cpp
with
174 additions
and
1 deletion
test/CMakeLists.txt
+
1
−
0
View file @
968a6c61
...
@@ -27,6 +27,7 @@ set(test_cases
...
@@ -27,6 +27,7 @@ set(test_cases
test_properties
test_properties
test_transaction
test_transaction
test_ccaosdb
test_ccaosdb
test_issues
)
)
...
...
This diff is collapsed.
Click to expand it.
test/test_issues.cpp
0 → 100644
+
171
−
0
View file @
968a6c61
/*
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2021 Daniel Hornung <d.hornung@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, Connec...
#include
"caosdb/data_type.h"
// for AtomicDataType
#include
"caosdb/entity.h"
// for Entity, Parent, Role
#include
"caosdb/transaction.h"
// for Transaction, Entity
#include
"caosdb/transaction_status.h"
// for TransactionStatus
#include
<cstdint>
// for int32_t
#include
<gtest/gtest-message.h>
// for Message
#include
<gtest/gtest-spi.h>
// for EXPECT_NONFATAL_FA...
#include
<gtest/gtest-test-part.h>
// for TestPartResult
#include
<gtest/gtest_pred_impl.h>
// for AssertionResult
#include
<iostream>
// for operator<<, endl
#include
<memory>
// for unique_ptr, allocator
#include
<string>
// for operator+, operator<<
#include
<vector>
// for vector
namespace
caosdb
::
transaction
{
using
caosdb
::
entity
::
AtomicDataType
;
using
caosdb
::
entity
::
Entity
;
using
caosdb
::
entity
::
Parent
;
using
caosdb
::
entity
::
Role
;
class
test_issues
:
public
::
testing
::
Test
{
public:
// public utility functions
// ////////////////////////////////////////////////////////
static
void
DeleteEntities
()
{
// delete all entities
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
)
{
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
());
}
delete_transaction
->
Execute
();
}
}
protected
:
// Fixture methods //////////////////////////////////////////////////////////
void
SetUp
()
override
{
DeleteEntities
();
}
void
TearDown
()
override
{
DeleteEntities
();
}
};
/*
* test error-prone updates
*/
TEST_F
(
test_issues
,
server_issue_170
)
{
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
// Insert original
auto
insert_transaction
(
connection
->
CreateTransaction
());
Entity
original
;
original
.
SetRole
(
Role
::
PROPERTY
);
original
.
SetName
(
"Prop 1"
);
original
.
SetDataType
(
AtomicDataType
::
DOUBLE
);
insert_transaction
->
InsertEntity
(
&
original
);
insert_transaction
->
ExecuteAsynchronously
();
auto
insert_status
=
insert_transaction
->
WaitForIt
();
ASSERT_TRUE
(
insert_status
.
IsTerminated
());
ASSERT_FALSE
(
insert_status
.
IsError
());
const
auto
&
insert_result_set
=
insert_transaction
->
GetResultSet
();
auto
id
=
insert_result_set
.
at
(
0
).
GetId
();
EXPECT_FALSE
(
id
.
empty
());
// Retrieve original with ID
auto
retrieve_transaction
(
connection
->
CreateTransaction
());
retrieve_transaction
->
RetrieveById
(
id
);
retrieve_transaction
->
Execute
();
auto
update_entity
(
retrieve_transaction
->
GetResultSet
().
at
(
0
));
// UPDATE
auto
update_transaction
(
connection
->
CreateTransaction
());
update_entity
.
SetDataType
(
AtomicDataType
::
INTEGER
,
true
);
update_entity
.
SetValue
(
std
::
vector
<
int32_t
>
{
1
,
1
,
2
,
3
,
5
,
8
,
13
});
EXPECT_NONFATAL_FAILURE
(
{
update_transaction
->
UpdateEntity
(
&
update_entity
);
update_transaction
->
ExecuteAsynchronously
();
auto
update_status
=
update_transaction
->
WaitForIt
();
EXPECT_TRUE
(
update_status
.
IsTerminated
());
EXPECT_FALSE
(
update_status
.
IsError
());
},
"update_status.IsError"
);
}
/*
* Insert a Record with a parent, which has a wrong name.
*
* This must result in a server error.
*/
TEST_F
(
test_issues
,
server_issue_171
)
{
const
auto
&
connection
=
caosdb
::
connection
::
ConnectionManager
::
GetDefaultConnection
();
auto
insert_transaction
(
connection
->
CreateTransaction
());
// insert RT
Entity
rt
;
rt
.
SetRole
(
Role
::
RECORD_TYPE
);
rt
.
SetName
(
"Test_RT_Name"
);
insert_transaction
->
InsertEntity
(
&
rt
);
insert_transaction
->
ExecuteAsynchronously
();
auto
insert_status
=
insert_transaction
->
WaitForIt
();
ASSERT_TRUE
(
insert_status
.
IsTerminated
());
ASSERT_FALSE
(
insert_status
.
IsError
());
const
auto
&
insert_result_set
=
insert_transaction
->
GetResultSet
();
const
auto
&
inserted_rt
=
insert_result_set
.
at
(
0
);
// create Record with parent
Entity
rec
;
rec
.
SetRole
(
Role
::
RECORD
);
rec
.
SetName
(
"TestRec"
);
Parent
parent
;
parent
.
SetId
(
inserted_rt
.
GetId
());
parent
.
SetName
(
rt
.
GetName
()
+
"_wrong"
);
rec
.
AppendParent
(
parent
);
// insert Record
auto
rec_transaction
(
connection
->
CreateTransaction
());
rec_transaction
->
InsertEntity
(
&
rec
);
rec_transaction
->
ExecuteAsynchronously
();
auto
rec_insert_status
=
rec_transaction
->
WaitForIt
();
ASSERT_TRUE
(
rec_insert_status
.
IsTerminated
());
EXPECT_NONFATAL_FAILURE
({
EXPECT_TRUE
(
rec_insert_status
.
IsError
());
},
"rec_insert_status.IsError"
);
const
auto
&
rec_result_set
=
rec_transaction
->
GetResultSet
();
const
auto
&
inserted_rec
=
rec_result_set
.
at
(
0
);
std
::
cout
<<
inserted_rec
.
ToString
()
<<
std
::
endl
;
}
}
// namespace caosdb::transaction
This diff is collapsed.
Click to expand it.
test/test_transaction.cpp
+
2
−
1
View file @
968a6c61
/*
/*
* This file is a part of the CaosDB Project.
* 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>
* Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
* Copyright (C) 2021 Daniel Hornung <d.hornung@indiscale.com>
*
*
* This program is free software: you can redistribute it and/or modify
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* it under the terms of the GNU Affero General Public License as
...
...
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