summaryrefslogtreecommitdiff
path: root/modules/remote/tests/remote_loopback.cpp
blob: 2430029e903e733d2554fa1134854503ee7acc09 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#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;

	event_loop loop;
	wait_scope wait{loop};

	remote<rmt::Loopback> rmt;

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

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

	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();
	}();

	{
		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.");
	}
	
	id<sch::UInt64> alloc_id = [&](){
		auto eov = client.allocate<sch::UInt64>(data<sch::Void>{});
		SAW_EXPECT(eov.is_value(), "Failed send.");
		return eov.get_value();
	}();
	{
		auto eov = client.find(alloc_id);
		SAW_EXPECT(eov.is_value(), "Failed find.");
		auto& f_val = eov.get_value();
		SAW_EXPECT(f_val, "Nullptr in find.");
		f_val->set(5u);
	}
	{
		auto conv = client.receive(alloc_id);
		auto eov = conv.take();
		SAW_EXPECT(eov.is_value(), "Failed receive.");
		SAW_EXPECT(eov.get_value().get() == 5u, "Wrong received value.");
	}

	data<sch::FixedArray<sch::UInt64,1>> arr_meta{{128u}};
	
	id<sch::Array<sch::Int32>> arr_alloc_id = [&](){
		auto eov = client.allocate<sch::Array<sch::Int32>>(arr_meta);
		SAW_EXPECT(eov.is_value(), "Failed send.");
		return eov.get_value();
	}();
	{
		auto eov = client.find(arr_alloc_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->size() == arr_meta.at(0).get(), "Wrong initialized size.");
	}
}
}