summaryrefslogtreecommitdiff
path: root/modules/remote/tests/remote_loopback.cpp
blob: 2895ee7e9091469741cd5387495aaa8542413bc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <forstio/test/suite.hpp>

#include "../c++/remote_loopback.hpp"

namespace {
namespace sch {
using namespace saw::schema;

using TestInterface = Interface<
	Member<Function<UInt32, Int64>, "foo">
>;

using GroupedSchemas = saw::tmpl_group<
	UInt64,
	String,
	Array<Int32>,
	Float64
>;
}

SAW_TEST("Remote Loopback Data"){
	using namespace saw;

	remote<rmt::Loopback> rmt;

	auto eov = rmt.parse_address();
	SAW_EXPECT(eov.is_value(), "Didn't parse correctly");
	auto& val = eov.get_value();

	interface<sch::TestInterface, encode::Native, storage::Default> iface{
		[](data<sch::UInt32>& foo){
			return foo.template cast_to<sch::Int64>();
		}
	};

	auto srv = data_server<sch::GroupedSchemas, encode::Native, rmt::Loopback>{};
	auto client = data_client<sch::GroupedSchemas, encode::Native, rmt::Loopback>{srv};

	data<sch::UInt64> foo{421};
	id<sch::UInt64> sent_id = [&](){
		auto eov = client.send(foo);
		SAW_EXPECT(eov.is_value(), "Failed send.");
		return eov.get_value();
	}();

	event_loop loop;
	wait_scope wait{loop};

	{
		auto conv = client.receive(sent_id);
		auto eov = conv.take();

		SAW_EXPECT(eov.is_value(), "Failed receive.");
		SAW_EXPECT(eov.get_value() == foo, "Wrong received value.");
	}
	{
		auto eov = client.find(sent_id);
		SAW_EXPECT(eov.is_value(), "Failed find.");
		auto& f_val = eov.get_value();
		SAW_EXPECT(f_val, "Nullptr in find.");
		SAW_EXPECT(*f_val == foo, "Wrong received value.");
	}
	{
		auto eov = client.erase(sent_id);
		SAW_EXPECT(eov.is_value(), "Failed erase.");
	}
	{
		auto conv = client.receive(sent_id);
		auto eov = conv.take();
		SAW_EXPECT(!eov.is_value(), "Failed receive. Value should already be erased.");
	}
}
}