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
73f52265
Commit
73f52265
authored
Jul 31, 2019
by
Jakob Otto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add receive test for scribe
parent
95b921d5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
65 deletions
+94
-65
libcaf_net/test/scribe.cpp
libcaf_net/test/scribe.cpp
+94
-7
libcaf_net/test/scribe_fixture.hpp
libcaf_net/test/scribe_fixture.hpp
+0
-58
No files found.
libcaf_net/test/scribe.cpp
View file @
73f52265
...
@@ -18,23 +18,110 @@
...
@@ -18,23 +18,110 @@
#define CAF_SUITE scribe_policy
#define CAF_SUITE scribe_policy
#include <caf/net/endpoint_manager_impl.hpp>
#include <caf/net/multiplexer.hpp>
#include <caf/net/make_endpoint_manager.hpp>
#include "caf/policy/scribe_policy.hpp"
#include "caf/policy/scribe_policy.hpp"
#include "caf/test/dsl.hpp"
#include "caf/test/dsl.hpp"
#include "host_fixture.hpp"
#include "scribe_fixture.hpp"
using
namespace
caf
;
using
namespace
caf
;
using
namespace
caf
::
net
;
using
namespace
caf
::
net
;
using
namespace
caf
::
policy
;
namespace
{
string_view
hello_manager
{
"hello manager!"
};
string_view
hello_test
{
"hello test!"
};
struct
fixture
:
test_coordinator_fixture
<>
,
host_fixture
{
fixture
()
{
mpx
=
std
::
make_shared
<
multiplexer
>
();
if
(
auto
err
=
mpx
->
init
())
CAF_FAIL
(
"mpx->init failed: "
<<
sys
.
render
(
err
));
}
bool
handle_io_event
()
override
{
mpx
->
handle_updates
();
return
mpx
->
poll_once
(
false
);
}
multiplexer_ptr
mpx
;
};
struct
dummy_application
{
dummy_application
(
std
::
shared_ptr
<
std
::
vector
<
char
>>
buf
)
:
buf_
(
buf
)
{};
~
dummy_application
()
=
default
;
template
<
class
Transport
>
void
prepare
(
std
::
unique_ptr
<
endpoint_manager
::
message
>
,
Transport
&
,
socket_manager
&
)
{
}
template
<
class
Transport
>
void
process
(
std
::
vector
<
char
>
payload
,
Transport
&
,
socket_manager
&
)
{
buf_
->
clear
();
buf_
->
insert
(
buf_
->
begin
(),
payload
.
begin
(),
payload
.
end
());
}
template
<
class
Transport
>
void
resolve
(
Transport
&
,
const
std
::
string
&
,
actor
)
{
// nop
}
CAF_TEST_FIXTURE_SCOPE
(
parent
,
parent_mock
<
application_mock
,
transport_mock
>
)
template
<
class
Transport
>
void
timeout
(
Transport
&
,
atom_value
,
uint64_t
)
{
// nop
}
CAF_TEST
(
scibe
build
test
)
{
void
handle_error
(
caf
::
sec
)
{
auto
socket_pair
=
make_stream_socket_pair
();
// nop
parent
<
application_mock
,
transport_mock
>
parent1
;
}
CAF_CHECK_EQUAL
(
true
,
true
);
static
caf
::
expected
<
std
::
vector
<
char
>>
serialize
(
actor_system
&
,
const
type_erased_tuple
&
)
{
return
std
::
vector
<
char
>
(
0
);
}
std
::
shared_ptr
<
std
::
vector
<
char
>>
buf_
;
};
CAF_TEST_FIXTURE_SCOPE
(
scribe_tests
,
fixture
)
CAF_TEST
(
send
)
{
std
::
vector
<
char
>
read_buf
(
1024
);
CAF_CHECK_EQUAL
(
mpx
->
num_socket_managers
(),
1u
);
auto
buf
=
std
::
make_shared
<
std
::
vector
<
char
>>
();
auto
sockets
=
unbox
(
make_stream_socket_pair
());
nonblocking
(
sockets
.
second
,
true
);
CAF_CHECK_EQUAL
(
read
(
sockets
.
second
,
read_buf
.
data
(),
read_buf
.
size
()),
sec
::
unavailable_or_would_block
);
auto
guard
=
detail
::
make_scope_guard
([
&
]
{
close
(
sockets
.
second
);
});
CAF_MESSAGE
(
"make new endpoint"
);
scribe_policy
scribe
{
sockets
.
first
};
scribe
.
configure_read
(
net
::
receive_policy
::
exactly
(
hello_manager
.
size
()));
auto
mgr
=
make_endpoint_manager
(
mpx
,
sys
,
scribe
,
dummy_application
{
buf
});
CAF_CHECK_EQUAL
(
mgr
->
init
(),
none
);
mpx
->
handle_updates
();
CAF_CHECK_EQUAL
(
mpx
->
num_socket_managers
(),
2u
);
CAF_MESSAGE
(
"transfer data from second to first socket"
);
CAF_CHECK_EQUAL
(
write
(
sockets
.
second
,
hello_manager
.
data
(),
hello_manager
.
size
()),
hello_manager
.
size
());
CAF_MESSAGE
(
"receive transferred data"
);
run
();
CAF_CHECK_EQUAL
(
string_view
(
buf
->
data
(),
buf
->
size
()),
hello_manager
);
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
CAF_TEST_FIXTURE_SCOPE_END
()
}
// namespace
\ No newline at end of file
libcaf_net/test/scribe_fixture.hpp
deleted
100644 → 0
View file @
95b921d5
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2019 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#pragma once
#include <stdexcept>
#include "caf/error.hpp"
namespace
{
struct
transport_mock
{
transport_mock
()
=
default
;
~
transport_mock
()
=
default
;
};
struct
application_mock
{
application_mock
()
=
default
;
~
application_mock
()
=
default
;
};
template
<
class
Application
,
class
Transport
>
struct
parent_mock
{
using
application_type
=
Application
;
using
transport_type
=
Transport
;
parent_mock
()
=
default
;
~
parent_mock
()
=
default
;
application_type
&
application
()
{
return
application_
;
};
transport_type
&
transport
()
{
return
transport_
;
}
private:
transport_type
transport_
;
application_type
application_
;
};
}
// namespace
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