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
b62599d8
Commit
b62599d8
authored
3 years ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Implement creators and destructor for datatypes
parent
f9147bbd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!24
API: Introduce value and datatype structs to Extern C
Pipeline
#13621
passed
3 years ago
Stage: info
Stage: setup
Stage: test
Stage: deploy
Pipeline: caosdb-cppinttest
#13623
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/ccaosdb.cpp
+42
-8
42 additions, 8 deletions
src/ccaosdb.cpp
test/test_ccaosdb.cpp
+32
-1
32 additions, 1 deletion
test/test_ccaosdb.cpp
with
74 additions
and
9 deletions
src/ccaosdb.cpp
+
42
−
8
View file @
b62599d8
...
@@ -48,7 +48,7 @@ extern "C" {
...
@@ -48,7 +48,7 @@ extern "C" {
#define WRAPPED_MESSAGE_CAST(name) static_cast<caosdb::entity::Message *>(name->wrapped_message)
#define WRAPPED_MESSAGE_CAST(name) static_cast<caosdb::entity::Message *>(name->wrapped_message)
#define WRAPPED_DATATYPE_CAST(name) static_cast<caosdb::entity::Data
t
ype *>(name->wrapped_datatype)
#define WRAPPED_DATATYPE_CAST(name) static_cast<caosdb::entity::Data
T
ype *>(name->wrapped_datatype)
#define WRAPPED_VALUE_CAST(name) static_cast<caosdb::entity::AbstractValue *>(name->wrapped_value)
#define WRAPPED_VALUE_CAST(name) static_cast<caosdb::entity::AbstractValue *>(name->wrapped_value)
...
@@ -163,9 +163,7 @@ extern "C" {
...
@@ -163,9 +163,7 @@ extern "C" {
#define CREATE_VALUE(fname, arg) \
#define CREATE_VALUE(fname, arg) \
ERROR_RETURN_CODE(GENERIC_ERROR, \
ERROR_RETURN_CODE(GENERIC_ERROR, \
int caosdb_entity_create_##fname(caosdb_entity_value *out, arg), { \
int caosdb_entity_create_##fname(caosdb_entity_value *out, arg), { \
if (out->_deletable) { \
RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE(out) \
return caosdb::StatusCode::EXTERN_C_ASSIGNMENT_ERROR; \
} \
out->wrapped_value = new caosdb::entity::Value(value); \
out->wrapped_value = new caosdb::entity::Value(value); \
out->_deletable = true; \
out->_deletable = true; \
return 0; \
return 0; \
...
@@ -693,19 +691,55 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_parent(caosdb_entity_p
...
@@ -693,19 +691,55 @@ ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_delete_parent(caosdb_entity_p
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
int
caosdb_entity_create_atomic_datatype
(
caosdb_entity_datatype
*
out
,
int
caosdb_entity_create_atomic_datatype
(
caosdb_entity_datatype
*
out
,
const
char
*
name
),
const
char
*
name
),
{})
{
RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE
(
out
)
try
{
auto
enum_value
=
ENUM_VALUE_FROM_NAME
(
std
::
string
(
name
),
AtomicDataType
);
out
->
wrapped_datatype
=
new
caosdb
::
entity
::
DataType
(
enum_value
);
out
->
_deletable
=
true
;
return
0
;
}
catch
(
const
std
::
out_of_range
&
exc
)
{
caosdb
::
logging
::
caosdb_log_fatal
(
CCAOSDB_LOGGER_NAME
,
exc
.
what
());
return
caosdb
::
StatusCode
::
ENUM_MAPPING_ERROR
;
}
})
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
int
caosdb_entity_create_reference_datatype
(
caosdb_entity_datatype
*
out
,
int
caosdb_entity_create_reference_datatype
(
caosdb_entity_datatype
*
out
,
const
char
*
name
),
const
char
*
name
),
{})
{
RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE
(
out
)
out
->
wrapped_datatype
=
new
caosdb
::
entity
::
DataType
(
std
::
string
(
name
));
out
->
_deletable
=
true
;
return
0
;
})
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
int
caosdb_entity_create_atomic_list_datatype
(
caosdb_entity_datatype
*
out
,
int
caosdb_entity_create_atomic_list_datatype
(
caosdb_entity_datatype
*
out
,
const
char
*
name
),
const
char
*
name
),
{})
{
RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE
(
out
)
try
{
auto
enum_value
=
ENUM_VALUE_FROM_NAME
(
std
::
string
(
name
),
AtomicDataType
);
out
->
wrapped_datatype
=
new
caosdb
::
entity
::
DataType
();
auto
*
wrapped_datatype
=
WRAPPED_DATATYPE_CAST
(
out
);
wrapped_datatype
->
ListOf
(
enum_value
);
out
->
_deletable
=
true
;
return
0
;
}
catch
(
const
std
::
out_of_range
&
exc
)
{
caosdb
::
logging
::
caosdb_log_fatal
(
CCAOSDB_LOGGER_NAME
,
exc
.
what
());
return
caosdb
::
StatusCode
::
ENUM_MAPPING_ERROR
;
}
})
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
int
caosdb_entity_create_reference_list_datatype
(
caosdb_entity_datatype
*
out
,
int
caosdb_entity_create_reference_list_datatype
(
caosdb_entity_datatype
*
out
,
const
char
*
name
),
const
char
*
name
),
{})
{
RETURN_ASSIGNEMENT_ERROR_IF_DELETABLE
(
out
)
out
->
wrapped_datatype
=
new
caosdb
::
entity
::
DataType
();
auto
*
wrapped_datatype
=
WRAPPED_DATATYPE_CAST
(
out
);
wrapped_datatype
->
ListOf
(
std
::
string
(
name
));
out
->
_deletable
=
true
;
return
0
;
})
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
int
caosdb_entity_delete_datatype
(
caosdb_entity_datatype
*
out
),
{
ERROR_RETURN_CODE
(
GENERIC_ERROR
,
int
caosdb_entity_delete_datatype
(
caosdb_entity_datatype
*
out
),
{
if
(
out
->
_deletable
)
{
if
(
out
->
_deletable
)
{
...
...
This diff is collapsed.
Click to expand it.
test/test_ccaosdb.cpp
+
32
−
1
View file @
b62599d8
...
@@ -127,6 +127,38 @@ TEST_F(test_ccaosdb, test_query) {
...
@@ -127,6 +127,38 @@ TEST_F(test_ccaosdb, test_query) {
EXPECT_EQ
(
return_code
,
0
);
EXPECT_EQ
(
return_code
,
0
);
}
}
TEST_F
(
test_ccaosdb
,
test_datatype
)
{
caosdb_entity_datatype
atomic
;
// check that this fails
int
return_code
(
caosdb_entity_create_atomic_datatype
(
&
atomic
,
"some type"
));
EXPECT_EQ
(
return_code
,
caosdb
::
StatusCode
::
ENUM_MAPPING_ERROR
);
return_code
=
caosdb_entity_create_atomic_datatype
(
&
atomic
,
"INTEGER"
);
EXPECT_EQ
(
return_code
,
0
);
caosdb_entity_datatype
reference
;
return_code
=
caosdb_entity_create_reference_datatype
(
&
reference
,
"MyType"
);
EXPECT_EQ
(
return_code
,
0
);
caosdb_entity_datatype
list_of_atomics
;
return_code
=
caosdb_entity_create_reference_datatype
(
&
list_of_atomics
,
"DATETIME"
);
EXPECT_EQ
(
return_code
,
0
);
caosdb_entity_datatype
list_of_references
;
return_code
=
caosdb_entity_create_reference_datatype
(
&
list_of_references
,
"MyType"
);
EXPECT_EQ
(
return_code
,
0
);
return_code
=
caosdb_entity_delete_datatype
(
&
atomic
);
EXPECT_EQ
(
return_code
,
0
);
return_code
=
caosdb_entity_delete_datatype
(
&
reference
);
EXPECT_EQ
(
return_code
,
0
);
return_code
=
caosdb_entity_delete_datatype
(
&
list_of_atomics
);
EXPECT_EQ
(
return_code
,
0
);
return_code
=
caosdb_entity_delete_datatype
(
&
list_of_references
);
EXPECT_EQ
(
return_code
,
0
);
}
TEST_F
(
test_ccaosdb
,
test_value
)
{
TEST_F
(
test_ccaosdb
,
test_value
)
{
caosdb_entity_value
string_value
;
caosdb_entity_value
string_value
;
...
@@ -207,7 +239,6 @@ TEST_F(test_ccaosdb, test_value) {
...
@@ -207,7 +239,6 @@ TEST_F(test_ccaosdb, test_value) {
caosdb_entity_value_is_vector
(
&
bool_vector_value
,
&
is_a
);
caosdb_entity_value_is_vector
(
&
bool_vector_value
,
&
is_a
);
EXPECT_TRUE
(
is_a
);
EXPECT_TRUE
(
is_a
);
// TODO(fspreck) Test as... functions
char
*
out_string
=
nullptr
;
// NOLINT
char
*
out_string
=
nullptr
;
// NOLINT
return_code
=
caosdb_entity_value_get_as_string
(
&
string_value
,
&
out_string
);
return_code
=
caosdb_entity_value_get_as_string
(
&
string_value
,
&
out_string
);
EXPECT_EQ
(
return_code
,
0
);
EXPECT_EQ
(
return_code
,
0
);
...
...
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