Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
9f3f7385
Commit
9f3f7385
authored
Apr 29, 2021
by
Dominik Charousset
Committed by
Dominik Charousset
Apr 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make UUID inspectable
Relates #1253.
parent
b60ee497
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
1 deletion
+50
-1
libcaf_core/caf/uuid.hpp
libcaf_core/caf/uuid.hpp
+13
-0
libcaf_core/test/uuid.cpp
libcaf_core/test/uuid.cpp
+37
-1
No files found.
libcaf_core/caf/uuid.hpp
View file @
9f3f7385
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#include "caf/byte.hpp"
#include "caf/byte.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/detail/core_export.hpp"
#include "caf/error.hpp"
#include "caf/fwd.hpp"
#include "caf/fwd.hpp"
#include "caf/string_view.hpp"
#include "caf/string_view.hpp"
...
@@ -156,4 +157,16 @@ CAF_CORE_EXPORT std::string to_string(const uuid& x);
...
@@ -156,4 +157,16 @@ CAF_CORE_EXPORT std::string to_string(const uuid& x);
/// @relates uuid
/// @relates uuid
CAF_CORE_EXPORT
expected
<
uuid
>
make_uuid
(
string_view
str
);
CAF_CORE_EXPORT
expected
<
uuid
>
make_uuid
(
string_view
str
);
/// @relates uuid
template
<
class
Inspector
>
bool
inspect
(
Inspector
&
f
,
uuid
&
x
)
{
if
(
f
.
has_human_readable_format
())
{
auto
get
=
[
&
x
]
{
return
to_string
(
x
);
};
auto
set
=
[
&
x
](
std
::
string
str
)
{
return
parse
(
str
,
x
);
};
return
f
.
apply
(
get
,
set
);
}
else
{
return
f
.
apply
(
x
.
bytes
());
}
}
}
// namespace caf
}
// namespace caf
libcaf_core/test/uuid.cpp
View file @
9f3f7385
...
@@ -6,7 +6,10 @@
...
@@ -6,7 +6,10 @@
#include "caf/uuid.hpp"
#include "caf/uuid.hpp"
#include "caf/test/dsl.hpp"
#include "core-test.hpp"
#include "caf/json_reader.hpp"
#include "caf/json_writer.hpp"
using
namespace
caf
;
using
namespace
caf
;
...
@@ -125,4 +128,37 @@ CAF_TEST(version 1 defines UUIDs that are based on time) {
...
@@ -125,4 +128,37 @@ CAF_TEST(version 1 defines UUIDs that are based on time) {
}
}
}
}
SCENARIO
(
"UUIDs are inspectable"
)
{
auto
id
=
"2ee4ded7-69c0-4dd6-876d-02e446b21784"
_uuid
;
GIVEN
(
"a binary serializer"
)
{
byte_buffer
buf
;
binary_serializer
sink
{
nullptr
,
buf
};
WHEN
(
"applying an UUID to the serializer"
)
{
CHECK
(
sink
.
apply
(
id
));
THEN
(
"a binary deserializer reproduces the UUID"
)
{
binary_deserializer
source
{
nullptr
,
buf
};
uuid
id_copy
;
CHECK
(
source
.
apply
(
id_copy
));
CHECK_EQ
(
id
,
id_copy
);
}
}
}
GIVEN
(
"a JSON writer"
)
{
json_writer
sink
;
WHEN
(
"applying an UUID to the writer"
)
{
CHECK
(
sink
.
apply
(
id
));
THEN
(
"the writer renders the UUID as string"
)
{
CHECK_EQ
(
sink
.
str
(),
R"("2ee4ded7-69c0-4dd6-876d-02e446b21784")"
);
}
AND
(
"a JSON reader reproduces the UUID"
)
{
json_reader
source
;
uuid
id_copy
;
CHECK
(
source
.
load
(
sink
.
str
()));
CHECK
(
source
.
apply
(
id_copy
));
CHECK_EQ
(
id
,
id_copy
);
}
}
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
CAF_TEST_FIXTURE_SCOPE_END
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment