Skip to content

Commit

Permalink
[osc] Fix an issue in OSC lists + failing OSC tests on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Oct 31, 2022
1 parent c890e1e commit 2297086
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 40 deletions.
7 changes: 7 additions & 0 deletions src/ossia/network/osc/detail/osc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,19 @@ struct osc_inbound_visitor

struct osc_inbound_impulse_visitor
{
// If our address is any type, e.g. float, etc., we treat an "empty" message as a bang on it
template <typename T>
ossia::value operator()(T&& t) const
{
return ossia::value{std::forward<T>(t)};
}

// If the address is a list otoh, it means that we're getting an empty list
ossia::value operator()(const std::vector<ossia::value>& t) const
{
return ossia::value{std::vector<ossia::value>{}};
}

ossia::value operator()() const { return {}; }
};

Expand Down
87 changes: 60 additions & 27 deletions tests/Network/AsyncTestUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,73 @@ void push_all_values_async(
for(const ossia::value& val : value_to_test)
{
local_addr[i][j]->set_value_type(val.get_type());
ctx.context.poll();
local_addr[i][j]->push_value(val);
REQUIRE(local_addr[i][j]->value() == val);
j++;
ctx.context.poll();
}
ctx.context.poll();
}

ctx.context.run_for(std::chrono::milliseconds(100));

for(int i = 0; i < N; i++)
{
int j = 0;
for(const ossia::value& val : value_to_test)
{
REQUIRE(remote_addr[i][j]->value() == val);
remote_addr[i][j]->push_value(val);
ctx.context.poll();
j++;
}
ctx.context.poll();
}

int j = 0;
ctx.context.run_for(std::chrono::milliseconds(100));

// Check that nothing goes too wrong even if we change the origina value types
for(int i = 0; i < N; i++)
{
local_addr[i][j]->set_value_type((ossia::val_type) i);
local_addr[i][j]->push_value(ossia::init_value((ossia::val_type) i));
j++;
ctx.context.poll();
int jmax = std::min(int(local_addr[i].size()), (int)ossia::val_type::NONE);
for(int j = 0; j < jmax; j++)
{
local_addr[i][j]->set_value_type((ossia::val_type) i);
ctx.context.poll();
local_addr[i][j]->push_value(ossia::init_value((ossia::val_type) i));
ctx.context.poll();
}
}

ctx.context.run_for(std::chrono::milliseconds(100));


for(int i = 0; i < N; i++)
{
int j = 0;
for(const ossia::value& val : value_to_test)
{
remote_addr[i][j]->push_value(ossia::init_value((ossia::val_type) val.get_type()));
ctx.context.poll();
remote_addr[i][j]->push_value(1234);
ctx.context.poll();
j++;
}
}

ctx.context.run_for(std::chrono::milliseconds(100));

// Reset the local values in the initial state
for(int i = 0; i < N; i++)
{
int j = 0;
for(const ossia::value& val : value_to_test)
{
local_addr[i][j]->set_value_type((ossia::val_type) val.get_type());
ctx.context.poll();
local_addr[i][j]->push_value(val);
ctx.context.poll();
j++;
}
ctx.context.poll();
}
}

Expand All @@ -72,10 +102,11 @@ void push_all_values_domain_async(
for(const ossia::value& val : value_to_test)
{
local_addr[i][j]->set_value_type(val.get_type());
ctx.context.poll();
local_addr[i][j]->push_value(val);
ctx.context.poll();
j++;
}
ctx.context.poll();
}

for(int i = 0; i < N; i++)
Expand All @@ -84,18 +115,21 @@ void push_all_values_domain_async(
for(const ossia::value& val : value_to_test)
{
remote_addr[i][j]->push_value(val);
ctx.context.poll();
j++;
}
ctx.context.poll();
}

int j = 0;
for(int i = 0; i < N; i++)
{
local_addr[i][j]->set_value_type((ossia::val_type) i);
local_addr[i][j]->push_value(ossia::init_value((ossia::val_type) i));
j++;
ctx.context.poll();
int jmax = std::min(int(local_addr[i].size()), (int)ossia::val_type::NONE);
for(int j = 0; j < jmax; j++)
{
local_addr[i][j]->set_value_type((ossia::val_type) i);
ctx.context.poll();
local_addr[i][j]->push_value(ossia::init_value((ossia::val_type) i));
ctx.context.poll();
}
}

for(int i = 0; i < N; i++)
Expand All @@ -104,9 +138,9 @@ void push_all_values_domain_async(
for(const ossia::value& val : value_to_test)
{
remote_addr[i][j]->push_value(ossia::init_value((ossia::val_type) val.get_type()));
ctx.context.poll();
j++;
}
ctx.context.poll();
}
}

Expand All @@ -118,7 +152,7 @@ void test_comm_generic_async(
FunProto2 remote_proto,
ossia::net::network_context& ctx)
{
int N = 10;
int N = NUM_ADDRESSES_TO_TEST;
remote_data rem{std::move(local_proto), std::move(remote_proto)};

// Connect is async, it runs there
Expand Down Expand Up @@ -151,51 +185,50 @@ void test_comm_generic_async(
{
for(int access_i = 0; access_i < 3; access_i++)
{
for(int i = 0; i < N; i++)
INFO(fmt::format("Access: {}", access_i));
for(auto param : vec)
{
vec[i]->set_access(access_mode(access_i));
param->set_access(access_mode(access_i));
}

push_all_values_domain_async(N, local_addr, remote_addr, ctx);

for(int bounding_i = 0 ; bounding_i < 6; bounding_i++)
{
for(int i = 0; i < N; i++)
INFO(fmt::format("Bounding: {}", bounding_i));
for(auto param : vec)
{
vec[i]->set_bounding(bounding_mode(bounding_i));
param->set_bounding(bounding_mode(bounding_i));
}

push_all_values_domain_async(N, local_addr, remote_addr, ctx);

for(int domain_i = 0; domain_i < N; domain_i++)
for(int domain_i = 0; domain_i < std::min(N, (int)vec.size()); domain_i++)
{
vec[domain_i]->set_domain(init_domain(ossia::val_type(domain_i)));
}

push_all_values_domain_async(N, local_addr, remote_addr, ctx);


for(int domain_i = 0; domain_i < N; domain_i++)
for(int domain_i = 0; domain_i < std::min(N, (int)vec.size()); domain_i++)
{
auto val = ossia::init_value((ossia::val_type) domain_i);
auto dom = ossia::make_domain(val, val);
vec[domain_i]->set_domain(dom);
}

push_all_values_domain_async(N, local_addr, remote_addr, ctx);

}
}
};

int k = 0;

for(auto& vec : local_addr)
{
test_all_values(vec);
}


k = 0;
for(auto& vec : remote_addr)
{
test_all_values(vec);
Expand Down
6 changes: 4 additions & 2 deletions tests/Network/OSC_TCP_SizeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ using namespace ossia;
auto make_client(ossia::net::network_context_ptr ctx)
{
using conf = ossia::net::osc_protocol_configuration;
return ossia::net::make_osc_protocol(
auto proto = ossia::net::make_osc_protocol(
ctx, {conf::MIRROR, conf::OSC1_1, conf::SIZE_PREFIX,
ossia::net::tcp_configuration{{"127.0.0.1", 1234}}});
return proto;
}

auto make_server(ossia::net::network_context_ptr ctx)
{
using conf = ossia::net::osc_protocol_configuration;
return ossia::net::make_osc_protocol(
auto proto = ossia::net::make_osc_protocol(
ctx, {conf::HOST, conf::OSC1_1, conf::SIZE_PREFIX,
ossia::net::tcp_configuration{{"0.0.0.0", 1234}}});
return proto;
}

TEST_CASE("test_comm_osc_tcp_server_client", "test_comm_osc_tcp_server_client")
Expand Down
23 changes: 12 additions & 11 deletions tests/Network/ProtocolTestUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ template<>
struct matching_domain<ossia::val_type::VEC4F>
{ using type = ossia::vecf_domain<4>; };

static constexpr int NUM_ADDRESSES_TO_TEST = ((int) ossia::val_type::MAP);
const std::vector<ossia::value> value_to_test{
ossia::impulse{},
int32_t{0},
Expand All @@ -56,7 +57,7 @@ const std::vector<ossia::value> value_to_test{
char{'a'},
std::string{""},
std::string{"Welcome to the wonderful ossia world!"},
std::vector<ossia::value>{},
ossia::value(std::vector<ossia::value>{}),
std::vector<ossia::value>{ossia::impulse{}},
std::vector<ossia::value>{ossia::impulse{}, ossia::impulse{}},
std::vector<ossia::value>{int32_t{0}},
Expand All @@ -81,7 +82,7 @@ struct remote_data
local_device{local_proto(), "score" },
remote_device{remote_proto(), "score-remote"}
{
int N = 10;
int N = NUM_ADDRESSES_TO_TEST;

for(int i = 0; i < N; i++)
{
Expand Down Expand Up @@ -121,10 +122,10 @@ struct remote_data


void push_all_values(
int N,
std::vector<std::vector<ossia::net::parameter_base*>>& local_addr,
std::vector<std::vector<ossia::net::parameter_base*>> & remote_addr)
{
int N = NUM_ADDRESSES_TO_TEST;
for(int i = 0; i < N; i++)
{
int j = 0;
Expand Down Expand Up @@ -176,10 +177,10 @@ void push_all_values(
// In this case we don't do checking yet as there are a lot of possible cases -
// the parameters are set with their default domains
void push_all_values_domain(
int N,
std::vector<std::vector<ossia::net::parameter_base*>>& local_addr,
std::vector<std::vector<ossia::net::parameter_base*>> & remote_addr)
{
int N = NUM_ADDRESSES_TO_TEST;
for(int i = 0; i < N; i++)
{
int j = 0;
Expand Down Expand Up @@ -230,13 +231,13 @@ void test_comm_generic(
FunProto1 local_proto,
FunProto2 remote_proto)
{
int N = 10;
int N = NUM_ADDRESSES_TO_TEST;
remote_data rem{std::move(local_proto), std::move(remote_proto)};
auto& local_addr = rem.local_addr;
auto& remote_addr = rem.remote_addr;


push_all_values(N, local_addr, remote_addr);
push_all_values(local_addr, remote_addr);


for(const auto& vec : local_addr)
Expand All @@ -254,7 +255,7 @@ void test_comm_generic(
}
}

push_all_values(N, local_addr, remote_addr);
push_all_values(local_addr, remote_addr);


auto test_all_values = [&] (std::vector<ossia::net::parameter_base*>& vec)
Expand All @@ -266,22 +267,22 @@ void test_comm_generic(
vec[i]->set_access(access_mode(access_i));
}

push_all_values_domain(N, local_addr, remote_addr);
push_all_values_domain(local_addr, remote_addr);
for(int bounding_i = 0 ; bounding_i < 6; bounding_i++)
{
for(int i = 0; i < N; i++)
{
vec[i]->set_bounding(bounding_mode(bounding_i));
}

push_all_values_domain(N, local_addr, remote_addr);
push_all_values_domain(local_addr, remote_addr);

for(int domain_i = 0; domain_i < N; domain_i++)
{
vec[domain_i]->set_domain(init_domain(ossia::val_type(domain_i)));
}

push_all_values_domain(N, local_addr, remote_addr);
push_all_values_domain(local_addr, remote_addr);


for(int domain_i = 0; domain_i < N; domain_i++)
Expand All @@ -291,7 +292,7 @@ void test_comm_generic(
vec[domain_i]->set_domain(dom);
}

push_all_values_domain(N, local_addr, remote_addr);
push_all_values_domain(local_addr, remote_addr);

}
}
Expand Down

0 comments on commit 2297086

Please sign in to comment.