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
51c5b069
Verified
Commit
51c5b069
authored
2 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
More implementation for JsonValue
parent
1c5b0a5b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!42
Release 0.2.0
,
!39
F remove boost rdep
Pipeline
#24576
failed
2 years ago
Stage: info
Stage: setup
Stage: test
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/caosdb/utility.h
+8
-2
8 additions, 2 deletions
include/caosdb/utility.h
src/caosdb/utility.cpp
+16
-0
16 additions, 0 deletions
src/caosdb/utility.cpp
test/test_utility.cpp
+0
-15
0 additions, 15 deletions
test/test_utility.cpp
with
24 additions
and
17 deletions
include/caosdb/utility.h
+
8
−
2
View file @
51c5b069
...
...
@@ -98,6 +98,12 @@ inline auto get_env_fallback(const std::string &key, const std::string &fallback
*/
class
JsonValue
{
public:
/**
* Default Constructor.
*
* Creates an empty wrapper where `wrapped` is nullptr.
*/
JsonValue
()
:
JsonValue
(
nullptr
)
{}
/**
* Constructor.
*
...
...
@@ -124,14 +130,14 @@ public:
*
* Also copies the `wrapped` object.
*/
auto
operator
=
(
const
JsonValue
&
other
)
->
JsonValue
&
=
default
;
auto
operator
=
(
const
JsonValue
&
other
)
->
JsonValue
&
;
/**
* Move Constructor.
*
* Also moves the `wrapped` object.
*/
JsonValue
(
JsonValue
&&
other
);
JsonValue
(
JsonValue
&&
other
)
=
default
;
/**
* Move Assigment.
...
...
This diff is collapsed.
Click to expand it.
src/caosdb/utility.cpp
+
16
−
0
View file @
51c5b069
...
...
@@ -153,4 +153,20 @@ auto JsonValue::Reset() -> void {
this
->
wrapped
=
nullptr
;
}
JsonValue
::
JsonValue
(
const
JsonValue
&
other
)
:
wrapped
(
nullptr
)
{
if
(
!
other
.
IsNull
())
{
this
->
wrapped
=
new
value
(
*
static_cast
<
value
*>
(
other
.
wrapped
));
}
}
auto
JsonValue
::
operator
=
(
const
JsonValue
&
other
)
->
JsonValue
&
{
if
(
this
!=
&
other
)
{
Reset
();
if
(
!
other
.
IsNull
())
{
this
->
wrapped
=
new
value
(
*
static_cast
<
value
*>
(
other
.
wrapped
));
}
}
return
*
this
;
}
}
// namespace caosdb::utility
This diff is collapsed.
Click to expand it.
test/test_utility.cpp
+
0
−
15
View file @
51c5b069
...
...
@@ -20,10 +20,7 @@
*
*/
#include
"gmock/gmock-matchers.h"
// for ElementsAre, EXPECT_THAT
#include
"boost/beast/core/detail/base64.hpp"
// for encoded_size
#include
"boost/json/object.hpp"
// for object
#include
"boost/json/value.hpp"
// for value
#include
"caosdb/data_type.h"
// for atomicdatatype_names
#include
"caosdb/entity.h"
// for importance_names, role...
#include
"caosdb/status_code.h"
// for get_status_description
...
...
@@ -38,7 +35,6 @@
#include
<utility>
// for pair
namespace
caosdb
::
utility
{
using
::
testing
::
ElementsAre
;
TEST
(
test_utility
,
base64_encode
)
{
auto
test_plain
=
std
::
string
(
"admin:caosdb"
);
...
...
@@ -48,17 +44,6 @@ TEST(test_utility, base64_encode) {
EXPECT_EQ
(
test_encoded
,
base64_encode
(
test_plain
));
}
TEST
(
test_utility
,
test_load_json_file
)
{
auto
json
=
load_json_file
(
TEST_DATA_DIR
+
"/test.json"
).
as_object
();
EXPECT_EQ
(
json
[
"it"
],
"tests"
);
EXPECT_EQ
(
json
[
"null values"
],
nullptr
);
EXPECT_THAT
(
json
[
"this"
].
as_array
(),
ElementsAre
(
"is"
,
"a"
,
"test"
));
EXPECT_THAT
(
json
[
"numbers"
].
as_array
(),
ElementsAre
(
1
,
2
,
3.3
));
auto
sub
=
json
[
"arrays and objects"
].
as_object
();
EXPECT_THAT
(
sub
[
"see?"
].
as_array
(),
ElementsAre
(
true
,
false
));
}
TEST
(
test_utility
,
enum_names
)
{
// All working enums
for
(
const
auto
&
entry
:
caosdb
::
entity
::
importance_names
)
{
...
...
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