summaryrefslogtreecommitdiff
path: root/modules/remote/tests/remote_loopback.cpp
blob: bc04605c5a8d34b439c0fc28e477fe35807c81ec (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
#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">
>;

}

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

	event_loop loop;
	wait_scope wait{loop};

	remote<rmt::Loopback> rmt;

	using Schema = sch::Array<sch::Float64>;

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

	auto eo_srv = rmt.template data_listen<Schema, encode::Native>(*addr);
	SAW_EXPECT(eo_srv.is_value(), std::string{"Couldn't listen: "} + std::string{eo_srv.get_error().get_category()});
	auto& srv = eo_srv.get_value();

	auto cvr_client = rmt.template data_connect<Schema, encode::Native>(*addr);
	auto eo_client = cvr_client.take();
	SAW_EXPECT(eo_client.is_value(), "Couldn't connect.");
	auto& client = eo_client.get_value();

	data<Schema> foo{4};
	for(uint64_t i = 0; i < foo.size(); ++i){
		foo.at(i).set(i * 2.0);
	}
	id<Schema> 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.is_valid(), "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<Schema> alloc_id = [&](){
		auto eov = client.allocate(data<sch::FixedArray<sch::UInt64,1>>{{4}});
		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.is_valid(), "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().size() == 4u, "Wrong received value.");
	}
}

}