Commit c4336998 authored by Dominik Charousset's avatar Dominik Charousset

Add initial BASP application unit tests

parent 04d918ed
......@@ -79,6 +79,10 @@ public:
static expected<std::vector<byte>> serialize(actor_system& sys,
const type_erased_tuple& x);
connection_state state() const noexcept {
return state_;
}
private:
// -- message handling -------------------------------------------------------
......@@ -91,7 +95,7 @@ private:
// -- member variables -------------------------------------------------------
/// Stores what we are expecting to receive next.
connection_state state_ = connection_state::shutdown;
connection_state state_ = connection_state::await_magic_number;
/// Caches the last header;we need to store it when waiting for the payload.
header hdr_;
......
......@@ -16,26 +16,68 @@
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#define CAF_SUITE application
#define CAF_SUITE basp.application
#include "caf/net/basp/application.hpp"
#include "caf/test/dsl.hpp"
#include <vector>
#include "caf/byte.hpp"
#include "caf/net/basp/connection_state.hpp"
#include "caf/net/basp/constants.hpp"
#include "caf/net/basp/ec.hpp"
#include "caf/none.hpp"
using namespace caf;
using namespace caf::net;
#define REQUIRE_OK(statement) \
if (auto err = statement) \
CAF_FAIL("failed to serialize data: " << sys.render(err));
namespace {
struct fixture {
struct fixture : test_coordinator_fixture<> {
using buffer_type = std::vector<byte>;
fixture() {
REQUIRE_OK(app.init(*this));
}
template <class... Ts>
void set_input(const Ts&...xs) {
serializer_impl<buffer_type> sink{nullptr, input};
REQUIRE_OK(sink(xs...));
}
buffer_type input;
buffer_type output;
basp::application app;
};
} // namespace
CAF_TEST_FIXTURE_SCOPE(application_tests, fixture)
CAF_TEST(todo) {
// implement me
CAF_TEST(invalid magic number) {
CAF_CHECK_EQUAL(app.state(), basp::connection_state::await_magic_number);
set_input(basp::magic_number + 1);
CAF_CHECK_EQUAL(app.handle_data(*this, input),
basp::ec::invalid_magic_number);
}
CAF_TEST(handshake sequence) {
basp::application app;
REQUIRE_OK(app.init(*this));
CAF_CHECK_EQUAL(app.state(), basp::connection_state::await_magic_number);
set_input(basp::magic_number);
REQUIRE_OK(app.handle_data(*this, input));
CAF_CHECK_EQUAL(app.state(), basp::connection_state::await_handshake_header);
}
CAF_TEST_FIXTURE_SCOPE_END()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment