mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-05 03:21:42 +00:00
SCRIPT namespace replacements
This commit is contained in:
committed by
Peter Johnson
parent
ae6c043632
commit
9aca8e0fd6
@@ -16,11 +16,11 @@
|
||||
class ConnectionListenerTest : public ::testing::Test {
|
||||
public:
|
||||
ConnectionListenerTest()
|
||||
: server_inst(nt::CreateInstance()), client_inst(nt::CreateInstance()) {}
|
||||
: server_inst(wpi::nt::CreateInstance()), client_inst(wpi::nt::CreateInstance()) {}
|
||||
|
||||
~ConnectionListenerTest() override {
|
||||
nt::DestroyInstance(server_inst);
|
||||
nt::DestroyInstance(client_inst);
|
||||
wpi::nt::DestroyInstance(server_inst);
|
||||
wpi::nt::DestroyInstance(client_inst);
|
||||
}
|
||||
|
||||
void Connect(const char* address, unsigned int port4);
|
||||
@@ -31,13 +31,13 @@ class ConnectionListenerTest : public ::testing::Test {
|
||||
};
|
||||
|
||||
void ConnectionListenerTest::Connect(const char* address, unsigned int port4) {
|
||||
nt::StartServer(server_inst, "connectionlistenertest.ini", address, port4);
|
||||
nt::StartClient(client_inst, "client");
|
||||
nt::SetServer(client_inst, address, port4);
|
||||
wpi::nt::StartServer(server_inst, "connectionlistenertest.ini", address, port4);
|
||||
wpi::nt::StartClient(client_inst, "client");
|
||||
wpi::nt::SetServer(client_inst, address, port4);
|
||||
|
||||
// wait for client to report it's connected, then wait another 0.1 sec
|
||||
int count = 0;
|
||||
while (!nt::IsConnected(client_inst)) {
|
||||
while (!wpi::nt::IsConnected(client_inst)) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
if (++count > 30) {
|
||||
FAIL() << "timed out waiting for client to start";
|
||||
@@ -48,10 +48,10 @@ void ConnectionListenerTest::Connect(const char* address, unsigned int port4) {
|
||||
|
||||
TEST_F(ConnectionListenerTest, Polled) {
|
||||
// set up the poller
|
||||
NT_ListenerPoller poller = nt::CreateListenerPoller(server_inst);
|
||||
NT_ListenerPoller poller = wpi::nt::CreateListenerPoller(server_inst);
|
||||
ASSERT_NE(poller, 0u);
|
||||
NT_Listener handle =
|
||||
nt::AddPolledListener(poller, server_inst, nt::EventFlags::kConnection);
|
||||
wpi::nt::AddPolledListener(poller, server_inst, wpi::nt::EventFlags::kConnection);
|
||||
ASSERT_NE(handle, 0u);
|
||||
|
||||
// trigger a connect event
|
||||
@@ -59,27 +59,27 @@ TEST_F(ConnectionListenerTest, Polled) {
|
||||
|
||||
// get the event
|
||||
bool timed_out = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timed_out));
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timed_out));
|
||||
ASSERT_FALSE(timed_out);
|
||||
auto result = nt::ReadListenerQueue(poller);
|
||||
auto result = wpi::nt::ReadListenerQueue(poller);
|
||||
ASSERT_EQ(result.size(), 1u);
|
||||
EXPECT_EQ(handle, result[0].listener);
|
||||
EXPECT_TRUE(result[0].GetConnectionInfo());
|
||||
EXPECT_EQ(result[0].flags, nt::EventFlags::kConnected);
|
||||
EXPECT_EQ(result[0].flags, wpi::nt::EventFlags::kConnected);
|
||||
|
||||
// trigger a disconnect event
|
||||
nt::StopClient(client_inst);
|
||||
wpi::nt::StopClient(client_inst);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
// get the event
|
||||
timed_out = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timed_out));
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timed_out));
|
||||
ASSERT_FALSE(timed_out);
|
||||
result = nt::ReadListenerQueue(poller);
|
||||
result = wpi::nt::ReadListenerQueue(poller);
|
||||
ASSERT_EQ(result.size(), 1u);
|
||||
EXPECT_EQ(handle, result[0].listener);
|
||||
EXPECT_TRUE(result[0].GetConnectionInfo());
|
||||
EXPECT_EQ(result[0].flags, nt::EventFlags::kDisconnected);
|
||||
EXPECT_EQ(result[0].flags, wpi::nt::EventFlags::kDisconnected);
|
||||
}
|
||||
|
||||
class ConnectionListenerVariantTest
|
||||
@@ -87,9 +87,9 @@ class ConnectionListenerVariantTest
|
||||
public ::testing::WithParamInterface<std::pair<const char*, int>> {};
|
||||
|
||||
TEST_P(ConnectionListenerVariantTest, Threaded) {
|
||||
wpi::mutex m;
|
||||
std::vector<nt::Event> result;
|
||||
auto handle = nt::AddListener(server_inst, nt::EventFlags::kConnection,
|
||||
wpi::util::mutex m;
|
||||
std::vector<wpi::nt::Event> result;
|
||||
auto handle = wpi::nt::AddListener(server_inst, wpi::nt::EventFlags::kConnection,
|
||||
[&](auto& event) {
|
||||
std::scoped_lock lock{m};
|
||||
result.push_back(event);
|
||||
@@ -99,7 +99,7 @@ TEST_P(ConnectionListenerVariantTest, Threaded) {
|
||||
Connect(GetParam().first, 20001 + GetParam().second);
|
||||
|
||||
bool timed_out = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(handle, 1.0, &timed_out));
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(handle, 1.0, &timed_out));
|
||||
ASSERT_FALSE(timed_out);
|
||||
|
||||
// get the event
|
||||
@@ -108,16 +108,16 @@ TEST_P(ConnectionListenerVariantTest, Threaded) {
|
||||
ASSERT_EQ(result.size(), 1u);
|
||||
EXPECT_EQ(handle, result[0].listener);
|
||||
EXPECT_TRUE(result[0].GetConnectionInfo());
|
||||
EXPECT_EQ(result[0].flags, nt::EventFlags::kConnected);
|
||||
EXPECT_EQ(result[0].flags, wpi::nt::EventFlags::kConnected);
|
||||
result.clear();
|
||||
}
|
||||
|
||||
// trigger a disconnect event
|
||||
nt::StopClient(client_inst);
|
||||
wpi::nt::StopClient(client_inst);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
// wait for thread
|
||||
nt::WaitForListenerQueue(server_inst, 1.0);
|
||||
wpi::nt::WaitForListenerQueue(server_inst, 1.0);
|
||||
|
||||
// get the event
|
||||
{
|
||||
@@ -125,7 +125,7 @@ TEST_P(ConnectionListenerVariantTest, Threaded) {
|
||||
ASSERT_EQ(result.size(), 1u);
|
||||
EXPECT_EQ(handle, result[0].listener);
|
||||
EXPECT_TRUE(result[0].GetConnectionInfo());
|
||||
EXPECT_EQ(result[0].flags, nt::EventFlags::kDisconnected);
|
||||
EXPECT_EQ(result[0].flags, wpi::nt::EventFlags::kDisconnected);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ using ::testing::IsEmpty;
|
||||
using ::testing::Property;
|
||||
using ::testing::Return;
|
||||
|
||||
namespace nt {
|
||||
namespace wpi::nt {
|
||||
|
||||
::testing::Matcher<const PubSubOptionsImpl&> IsPubSubOptions(
|
||||
const PubSubOptionsImpl& good) {
|
||||
@@ -80,7 +80,7 @@ TEST_F(LocalStorageTest, GetEntryEmptyName) {
|
||||
}
|
||||
|
||||
TEST_F(LocalStorageTest, GetEntryCached) {
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::SpanEq({std::string{"tocache"}}),
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"tocache"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
|
||||
auto entry1 = storage.GetEntry("tocache");
|
||||
@@ -109,8 +109,8 @@ TEST_F(LocalStorageTest, DefaultProps) {
|
||||
EXPECT_CALL(
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"boolean"},
|
||||
wpi::json::object(), IsDefaultPubSubOptions()));
|
||||
storage.Publish(fooTopic, NT_BOOLEAN, "boolean", wpi::json::object(), {});
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
storage.Publish(fooTopic, NT_BOOLEAN, "boolean", wpi::util::json::object(), {});
|
||||
|
||||
EXPECT_FALSE(storage.GetTopicPersistent(fooTopic));
|
||||
EXPECT_FALSE(storage.GetTopicRetained(fooTopic));
|
||||
@@ -121,8 +121,8 @@ TEST_F(LocalStorageTest, PublishNewNoProps) {
|
||||
EXPECT_CALL(
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"boolean"},
|
||||
wpi::json::object(), IsDefaultPubSubOptions()));
|
||||
storage.Publish(fooTopic, NT_BOOLEAN, "boolean", wpi::json::object(), {});
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
storage.Publish(fooTopic, NT_BOOLEAN, "boolean", wpi::util::json::object(), {});
|
||||
|
||||
auto info = storage.GetTopicInfo(fooTopic);
|
||||
EXPECT_EQ(info.properties, "{}");
|
||||
@@ -132,7 +132,7 @@ TEST_F(LocalStorageTest, PublishNewNoPropsNull) {
|
||||
EXPECT_CALL(
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"boolean"},
|
||||
wpi::json::object(), IsDefaultPubSubOptions()));
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
storage.Publish(fooTopic, NT_BOOLEAN, "boolean", {}, {});
|
||||
|
||||
auto info = storage.GetTopicInfo(fooTopic);
|
||||
@@ -140,7 +140,7 @@ TEST_F(LocalStorageTest, PublishNewNoPropsNull) {
|
||||
}
|
||||
|
||||
TEST_F(LocalStorageTest, PublishNew) {
|
||||
wpi::json properties = {{"persistent", true}};
|
||||
wpi::util::json properties = {{"persistent", true}};
|
||||
EXPECT_CALL(network, ClientPublish(_, std::string_view{"foo"},
|
||||
std::string_view{"boolean"}, properties,
|
||||
IsDefaultPubSubOptions()));
|
||||
@@ -159,14 +159,14 @@ TEST_F(LocalStorageTest, PublishNew) {
|
||||
}
|
||||
|
||||
TEST_F(LocalStorageTest, SubscribeNoTypeLocalPubPost) {
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::SpanEq({std::string{"foo"}}),
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
auto sub = storage.Subscribe(fooTopic, NT_UNASSIGNED, "", {});
|
||||
|
||||
EXPECT_CALL(
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"boolean"},
|
||||
wpi::json::object(), IsDefaultPubSubOptions()));
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
auto pub = storage.Publish(fooTopic, NT_BOOLEAN, "boolean", {}, {});
|
||||
|
||||
auto val = Value::MakeBoolean(true, 5);
|
||||
@@ -199,14 +199,14 @@ TEST_F(LocalStorageTest, SubscribeNoTypeLocalPubPre) {
|
||||
EXPECT_CALL(
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"boolean"},
|
||||
wpi::json::object(), IsDefaultPubSubOptions()));
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
auto pub = storage.Publish(fooTopic, NT_BOOLEAN, "boolean", {}, {});
|
||||
|
||||
auto val = Value::MakeBoolean(true, 5);
|
||||
EXPECT_CALL(network, ClientSetValue(Handle{pub}.GetIndex(), val));
|
||||
storage.SetEntryValue(pub, val);
|
||||
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::SpanEq({std::string{"foo"}}),
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
auto sub = storage.Subscribe(fooTopic, NT_UNASSIGNED, "", {});
|
||||
|
||||
@@ -221,7 +221,7 @@ TEST_F(LocalStorageTest, SubscribeNoTypeLocalPubPre) {
|
||||
}
|
||||
|
||||
TEST_F(LocalStorageTest, EntryNoTypeLocalSet) {
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::SpanEq({std::string{"foo"}}),
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
auto entry = storage.GetEntry(fooTopic, NT_UNASSIGNED, "", {});
|
||||
|
||||
@@ -230,7 +230,7 @@ TEST_F(LocalStorageTest, EntryNoTypeLocalSet) {
|
||||
EXPECT_CALL(
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"boolean"},
|
||||
wpi::json::object(), IsDefaultPubSubOptions()));
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
EXPECT_CALL(network, ClientSetValue(_, val));
|
||||
EXPECT_TRUE(storage.SetEntryValue(entry, val));
|
||||
|
||||
@@ -268,14 +268,14 @@ TEST_F(LocalStorageTest, EntryNoTypeLocalSet) {
|
||||
}
|
||||
|
||||
TEST_F(LocalStorageTest, PubUnpubPub) {
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::SpanEq({std::string{"foo"}}),
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
auto sub = storage.Subscribe(fooTopic, NT_INTEGER, "int", {});
|
||||
|
||||
EXPECT_CALL(
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"boolean"},
|
||||
wpi::json::object(), IsDefaultPubSubOptions()));
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
EXPECT_CALL(logger,
|
||||
Call(NT_LOG_INFO, _, _,
|
||||
std::string_view{
|
||||
@@ -302,7 +302,7 @@ TEST_F(LocalStorageTest, PubUnpubPub) {
|
||||
|
||||
EXPECT_CALL(network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"int"},
|
||||
wpi::json::object(), IsDefaultPubSubOptions()));
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
pub = storage.Publish(fooTopic, NT_INTEGER, "int", {}, {});
|
||||
|
||||
val = Value::MakeInteger(3, 5);
|
||||
@@ -320,7 +320,7 @@ TEST_F(LocalStorageTest, LocalPubConflict) {
|
||||
EXPECT_CALL(
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"boolean"},
|
||||
wpi::json::object(), IsDefaultPubSubOptions()));
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
auto pub1 = storage.Publish(fooTopic, NT_BOOLEAN, "boolean", {}, {});
|
||||
|
||||
EXPECT_CALL(
|
||||
@@ -343,7 +343,7 @@ TEST_F(LocalStorageTest, LocalPubConflict) {
|
||||
EXPECT_CALL(network, ClientUnpublish(Handle{pub1}.GetIndex()));
|
||||
EXPECT_CALL(network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"int"},
|
||||
wpi::json::object(), IsDefaultPubSubOptions()));
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
storage.Unpublish(pub1);
|
||||
|
||||
EXPECT_EQ(storage.GetTopicType(fooTopic), NT_INTEGER);
|
||||
@@ -360,10 +360,10 @@ TEST_F(LocalStorageTest, LocalSubConflict) {
|
||||
EXPECT_CALL(
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"boolean"},
|
||||
wpi::json::object(), IsDefaultPubSubOptions()));
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
storage.Publish(fooTopic, NT_BOOLEAN, "boolean", {}, {});
|
||||
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::SpanEq({std::string{"foo"}}),
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
EXPECT_CALL(logger,
|
||||
Call(NT_LOG_INFO, _, _,
|
||||
@@ -377,7 +377,7 @@ TEST_F(LocalStorageTest, RemotePubConflict) {
|
||||
EXPECT_CALL(
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"boolean"},
|
||||
wpi::json::object(), IsDefaultPubSubOptions()));
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
|
||||
storage.Publish(fooTopic, NT_BOOLEAN, "boolean", {}, {});
|
||||
|
||||
@@ -387,7 +387,7 @@ TEST_F(LocalStorageTest, RemotePubConflict) {
|
||||
"network announce of 'foo' overriding local publish "
|
||||
"(was 'boolean', now 'int')"}));
|
||||
|
||||
auto id = storage.ServerAnnounce("foo", 0, "int", wpi::json::object(),
|
||||
auto id = storage.ServerAnnounce("foo", 0, "int", wpi::util::json::object(),
|
||||
std::nullopt);
|
||||
|
||||
// network overrides local
|
||||
@@ -398,7 +398,7 @@ TEST_F(LocalStorageTest, RemotePubConflict) {
|
||||
EXPECT_CALL(
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"boolean"},
|
||||
wpi::json::object(), IsDefaultPubSubOptions()));
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
|
||||
storage.ServerUnannounce("foo", id);
|
||||
|
||||
@@ -409,14 +409,14 @@ TEST_F(LocalStorageTest, RemotePubConflict) {
|
||||
|
||||
TEST_F(LocalStorageTest, SubNonExist) {
|
||||
// makes sure no warning is emitted
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::SpanEq({std::string{"foo"}}),
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
storage.Subscribe(fooTopic, NT_BOOLEAN, "boolean", {});
|
||||
}
|
||||
|
||||
TEST_F(LocalStorageTest, SetDefaultSubscribe) {
|
||||
// no publish, no value on wire, this is just handled locally
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::SpanEq({std::string{"foo"}}),
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
auto sub = storage.Subscribe(fooTopic, NT_BOOLEAN, "boolean", {});
|
||||
EXPECT_TRUE(storage.SetDefaultEntryValue(sub, Value::MakeBoolean(true)));
|
||||
@@ -430,7 +430,7 @@ TEST_F(LocalStorageTest, SetDefaultPublish) {
|
||||
EXPECT_CALL(
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"boolean"},
|
||||
wpi::json::object(), IsDefaultPubSubOptions()));
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
auto pub = storage.Publish(fooTopic, NT_BOOLEAN, "boolean", {}, {});
|
||||
|
||||
// expect a value across the wire
|
||||
@@ -447,7 +447,7 @@ TEST_F(LocalStorageTest, SetDefaultPublish) {
|
||||
}
|
||||
|
||||
TEST_F(LocalStorageTest, SetDefaultEntry) {
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::SpanEq({std::string{"foo"}}),
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
auto entry = storage.GetEntry(fooTopic, NT_BOOLEAN, "boolean", {});
|
||||
|
||||
@@ -455,7 +455,7 @@ TEST_F(LocalStorageTest, SetDefaultEntry) {
|
||||
EXPECT_CALL(
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"boolean"},
|
||||
wpi::json::object(), IsDefaultPubSubOptions()));
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
auto expectVal = Value::MakeBoolean(true, 0);
|
||||
EXPECT_CALL(network, ClientSetValue(_, expectVal));
|
||||
EXPECT_TRUE(storage.SetDefaultEntryValue(entry, Value::MakeBoolean(true)));
|
||||
@@ -467,7 +467,7 @@ TEST_F(LocalStorageTest, SetDefaultEntry) {
|
||||
}
|
||||
|
||||
TEST_F(LocalStorageTest, SetDefaultEntryUnassigned) {
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::SpanEq({std::string{"foo"}}),
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
auto entry = storage.GetEntry(fooTopic, NT_UNASSIGNED, "", {});
|
||||
|
||||
@@ -475,7 +475,7 @@ TEST_F(LocalStorageTest, SetDefaultEntryUnassigned) {
|
||||
EXPECT_CALL(
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"boolean"},
|
||||
wpi::json::object(), IsDefaultPubSubOptions()));
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
auto expectVal = Value::MakeBoolean(true, 0);
|
||||
EXPECT_CALL(network, ClientSetValue(_, expectVal));
|
||||
EXPECT_TRUE(storage.SetDefaultEntryValue(entry, Value::MakeBoolean(true)));
|
||||
@@ -491,7 +491,7 @@ TEST_F(LocalStorageTest, SetDefaultEntryDiffType) {
|
||||
EXPECT_CALL(
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"string"},
|
||||
wpi::json::object(), IsDefaultPubSubOptions()));
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
auto pub = storage.Publish(fooTopic, NT_STRING, "string", {}, {});
|
||||
|
||||
EXPECT_FALSE(storage.SetDefaultEntryValue(pub, Value::MakeBoolean(true)));
|
||||
@@ -502,14 +502,14 @@ TEST_F(LocalStorageTest, SetValueEmptyValue) {
|
||||
EXPECT_CALL(
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"string"},
|
||||
wpi::json::object(), IsDefaultPubSubOptions()));
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
auto pub = storage.Publish(fooTopic, NT_STRING, "string", {}, {});
|
||||
|
||||
EXPECT_FALSE(storage.SetEntryValue(pub, {}));
|
||||
}
|
||||
|
||||
TEST_F(LocalStorageTest, SetValueEmptyUntypedEntry) {
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::SpanEq({std::string{"foo"}}),
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
auto entry = storage.GetEntry(fooTopic, NT_UNASSIGNED, "", {});
|
||||
EXPECT_FALSE(storage.SetEntryValue(entry, {}));
|
||||
@@ -546,14 +546,14 @@ void LocalStorageDuplicatesTest::SetupPubSub(bool keepPub, bool keepSub) {
|
||||
EXPECT_CALL(
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"double"},
|
||||
wpi::json::object(), IsPubSubOptions(pubOptions)));
|
||||
wpi::util::json::object(), IsPubSubOptions(pubOptions)));
|
||||
pub = storage.Publish(fooTopic, NT_DOUBLE, "double", {},
|
||||
{.keepDuplicates = keepPub});
|
||||
|
||||
PubSubOptionsImpl subOptions;
|
||||
subOptions.pollStorage = 10;
|
||||
subOptions.keepDuplicates = keepSub;
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::SpanEq({std::string{"foo"}}),
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsPubSubOptions(subOptions)));
|
||||
sub = storage.Subscribe(fooTopic, NT_DOUBLE, "double",
|
||||
{.pollStorage = 10, .keepDuplicates = keepSub});
|
||||
@@ -836,7 +836,7 @@ TEST_F(LocalStorageNumberVariantsTest, GetAtomic) {
|
||||
template <typename T, typename U>
|
||||
::testing::Matcher<const T&> TSSpanEq(std::span<U> value, int64_t time) {
|
||||
return AllOf(
|
||||
Field("value", &T::value, wpi::SpanEq(std::span<const U>(value))),
|
||||
Field("value", &T::value, wpi::util::SpanEq(std::span<const U>(value))),
|
||||
Field("time", &T::time, time));
|
||||
}
|
||||
|
||||
@@ -927,15 +927,15 @@ TEST_F(LocalStorageTest, MultiSubSpecial) {
|
||||
|
||||
EXPECT_CALL(
|
||||
listenerStorage,
|
||||
Notify(wpi::SpanEq(std::span<const NT_Listener>{{2}}), _, _, _, _));
|
||||
Notify(wpi::util::SpanEq(std::span<const NT_Listener>{{2}}), _, _, _, _));
|
||||
storage.SetEntryValue(pubspecial, Value::MakeDouble(1.0, 30));
|
||||
|
||||
EXPECT_CALL(
|
||||
listenerStorage,
|
||||
Notify(wpi::SpanEq(std::span<const NT_Listener>{{1}}), _, _, _, _));
|
||||
Notify(wpi::util::SpanEq(std::span<const NT_Listener>{{1}}), _, _, _, _));
|
||||
EXPECT_CALL(
|
||||
listenerStorage,
|
||||
Notify(wpi::SpanEq(std::span<const NT_Listener>{{2}}), _, _, _, _));
|
||||
Notify(wpi::util::SpanEq(std::span<const NT_Listener>{{2}}), _, _, _, _));
|
||||
storage.SetEntryValue(pubnormal, Value::MakeDouble(2.0, 40));
|
||||
}
|
||||
|
||||
@@ -943,7 +943,7 @@ TEST_F(LocalStorageTest, NetworkDuplicateDetect) {
|
||||
EXPECT_CALL(network, ClientPublish(_, _, _, _, _));
|
||||
auto pub = storage.Publish(fooTopic, NT_DOUBLE, "double", {}, {});
|
||||
auto remoteTopic = storage.ServerAnnounce("foo", 0, "double",
|
||||
wpi::json::object(), std::nullopt);
|
||||
wpi::util::json::object(), std::nullopt);
|
||||
|
||||
// local set
|
||||
EXPECT_CALL(network, ClientSetValue(_, _));
|
||||
@@ -969,7 +969,7 @@ TEST_F(LocalStorageTest, ReadQueueLocalRemote) {
|
||||
storage.Subscribe(fooTopic, NT_DOUBLE, "double", {.disableLocal = true});
|
||||
auto pub = storage.Publish(fooTopic, NT_DOUBLE, "double", {}, {});
|
||||
auto remoteTopic = storage.ServerAnnounce("foo", 0, "double",
|
||||
wpi::json::object(), std::nullopt);
|
||||
wpi::util::json::object(), std::nullopt);
|
||||
|
||||
// local set
|
||||
EXPECT_CALL(network, ClientSetValue(_, _));
|
||||
@@ -998,7 +998,7 @@ TEST_F(LocalStorageTest, SubExcludePub) {
|
||||
auto subExclude = storage.Subscribe(fooTopic, NT_DOUBLE, "double",
|
||||
{.excludePublisher = pub});
|
||||
auto remoteTopic = storage.ServerAnnounce("foo", 0, "double",
|
||||
wpi::json::object(), std::nullopt);
|
||||
wpi::util::json::object(), std::nullopt);
|
||||
|
||||
// local set
|
||||
EXPECT_CALL(network, ClientSetValue(_, _));
|
||||
@@ -1021,7 +1021,7 @@ TEST_F(LocalStorageTest, EntryExcludeSelf) {
|
||||
auto entry =
|
||||
storage.GetEntry(fooTopic, NT_DOUBLE, "double", {.excludeSelf = true});
|
||||
auto remoteTopic = storage.ServerAnnounce("foo", 0, "double",
|
||||
wpi::json::object(), std::nullopt);
|
||||
wpi::util::json::object(), std::nullopt);
|
||||
|
||||
// local set
|
||||
EXPECT_CALL(network, ClientPublish(_, _, _, _, _));
|
||||
@@ -1061,7 +1061,7 @@ TEST_F(LocalStorageTest, ReadQueueInitialRemote) {
|
||||
EXPECT_CALL(network, ClientSubscribe(_, _, _)).Times(3);
|
||||
|
||||
auto remoteTopic = storage.ServerAnnounce("foo", 0, "double",
|
||||
wpi::json::object(), std::nullopt);
|
||||
wpi::util::json::object(), std::nullopt);
|
||||
storage.ServerSetValue(remoteTopic, Value::MakeDouble(2.0, 60));
|
||||
|
||||
auto subBoth =
|
||||
@@ -1079,4 +1079,4 @@ TEST_F(LocalStorageTest, ReadQueueInitialRemote) {
|
||||
EXPECT_THAT(storage.ReadQueue<double>(subLocal), IsEmpty());
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
} // namespace wpi::nt
|
||||
|
||||
@@ -13,12 +13,12 @@
|
||||
|
||||
class LoggerTest : public ::testing::Test {
|
||||
public:
|
||||
LoggerTest() : m_inst(nt::CreateInstance()) {}
|
||||
LoggerTest() : m_inst(wpi::nt::CreateInstance()) {}
|
||||
|
||||
~LoggerTest() override { nt::DestroyInstance(m_inst); }
|
||||
~LoggerTest() override { wpi::nt::DestroyInstance(m_inst); }
|
||||
|
||||
void Generate();
|
||||
void Check(const std::vector<nt::Event>& events, NT_Listener handle,
|
||||
void Check(const std::vector<wpi::nt::Event>& events, NT_Listener handle,
|
||||
bool infoMsg, bool errMsg);
|
||||
|
||||
protected:
|
||||
@@ -27,21 +27,21 @@ class LoggerTest : public ::testing::Test {
|
||||
|
||||
void LoggerTest::Generate() {
|
||||
// generate info message
|
||||
nt::StartClient(m_inst, "");
|
||||
wpi::nt::StartClient(m_inst, "");
|
||||
|
||||
// generate error message
|
||||
nt::Publish(nt::Handle(nt::Handle{m_inst}.GetInst(), 5, nt::Handle::kTopic),
|
||||
wpi::nt::Publish(wpi::nt::Handle(wpi::nt::Handle{m_inst}.GetInst(), 5, wpi::nt::Handle::kTopic),
|
||||
NT_DOUBLE, "");
|
||||
}
|
||||
|
||||
void LoggerTest::Check(const std::vector<nt::Event>& events, NT_Listener handle,
|
||||
void LoggerTest::Check(const std::vector<wpi::nt::Event>& events, NT_Listener handle,
|
||||
bool infoMsg, bool errMsg) {
|
||||
size_t count = (infoMsg ? 1u : 0u) + (errMsg ? 1u : 0u);
|
||||
ASSERT_EQ(events.size(), count);
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
ASSERT_EQ(events[i].listener, handle);
|
||||
ASSERT_EQ(events[i].flags & nt::EventFlags::kLogMessage,
|
||||
nt::EventFlags::kLogMessage);
|
||||
ASSERT_EQ(events[i].flags & wpi::nt::EventFlags::kLogMessage,
|
||||
wpi::nt::EventFlags::kLogMessage);
|
||||
auto log = events[i].GetLogMessage();
|
||||
ASSERT_TRUE(log);
|
||||
if (infoMsg) {
|
||||
@@ -58,41 +58,41 @@ void LoggerTest::Check(const std::vector<nt::Event>& events, NT_Listener handle,
|
||||
}
|
||||
|
||||
TEST_F(LoggerTest, DefaultLogRange) {
|
||||
auto poller = nt::CreateListenerPoller(m_inst);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto handle =
|
||||
nt::AddPolledListener(poller, m_inst, nt::EventFlags::kLogMessage);
|
||||
wpi::nt::AddPolledListener(poller, m_inst, wpi::nt::EventFlags::kLogMessage);
|
||||
|
||||
Generate();
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = nt::ReadListenerQueue(poller);
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = wpi::nt::ReadListenerQueue(poller);
|
||||
|
||||
Check(events, handle, true, true);
|
||||
}
|
||||
|
||||
TEST_F(LoggerTest, InfoOnly) {
|
||||
auto poller = nt::CreateListenerPoller(m_inst);
|
||||
auto handle = nt::AddPolledLogger(poller, NT_LOG_INFO, NT_LOG_INFO);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto handle = wpi::nt::AddPolledLogger(poller, NT_LOG_INFO, NT_LOG_INFO);
|
||||
|
||||
Generate();
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = nt::ReadListenerQueue(poller);
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = wpi::nt::ReadListenerQueue(poller);
|
||||
|
||||
Check(events, handle, true, false);
|
||||
}
|
||||
|
||||
TEST_F(LoggerTest, Error) {
|
||||
auto poller = nt::CreateListenerPoller(m_inst);
|
||||
auto handle = nt::AddPolledLogger(poller, NT_LOG_ERROR, 100);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto handle = wpi::nt::AddPolledLogger(poller, NT_LOG_ERROR, 100);
|
||||
|
||||
Generate();
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = nt::ReadListenerQueue(poller);
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = wpi::nt::ReadListenerQueue(poller);
|
||||
|
||||
Check(events, handle, false, true);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include "IConnectionList.hpp"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
namespace nt {
|
||||
namespace wpi::nt {
|
||||
|
||||
class MockConnectionList : public IConnectionList {
|
||||
public:
|
||||
@@ -21,4 +21,4 @@ class MockConnectionList : public IConnectionList {
|
||||
MOCK_METHOD(bool, IsConnected, (), (const, override));
|
||||
};
|
||||
|
||||
} // namespace nt
|
||||
} // namespace wpi::nt
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "IListenerStorage.hpp"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
namespace nt {
|
||||
namespace wpi::nt {
|
||||
|
||||
class MockListenerStorage : public IListenerStorage {
|
||||
public:
|
||||
@@ -42,4 +42,4 @@ class MockListenerStorage : public IListenerStorage {
|
||||
(override));
|
||||
};
|
||||
|
||||
} // namespace nt
|
||||
} // namespace wpi::nt
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
namespace wpi {
|
||||
|
||||
class MockLogger : public Logger,
|
||||
class MockLogger : public wpi::util::Logger,
|
||||
public ::testing::MockFunction<void(
|
||||
unsigned int level, std::string_view file,
|
||||
unsigned int line, std::string_view msg)> {
|
||||
|
||||
@@ -14,94 +14,94 @@
|
||||
class NetworkTableTest : public ::testing::Test {};
|
||||
|
||||
TEST_F(NetworkTableTest, BasenameKey) {
|
||||
EXPECT_EQ("simple", nt::NetworkTable::BasenameKey("simple"));
|
||||
EXPECT_EQ("simple", nt::NetworkTable::BasenameKey("one/two/many/simple"));
|
||||
EXPECT_EQ("simple", wpi::nt::NetworkTable::BasenameKey("simple"));
|
||||
EXPECT_EQ("simple", wpi::nt::NetworkTable::BasenameKey("one/two/many/simple"));
|
||||
EXPECT_EQ("simple",
|
||||
nt::NetworkTable::BasenameKey("//////an/////awful/key////simple"));
|
||||
wpi::nt::NetworkTable::BasenameKey("//////an/////awful/key////simple"));
|
||||
}
|
||||
|
||||
TEST_F(NetworkTableTest, NormalizeKeySlash) {
|
||||
EXPECT_EQ("/", nt::NetworkTable::NormalizeKey("///"));
|
||||
EXPECT_EQ("/no/normal/req", nt::NetworkTable::NormalizeKey("/no/normal/req"));
|
||||
EXPECT_EQ("/", wpi::nt::NetworkTable::NormalizeKey("///"));
|
||||
EXPECT_EQ("/no/normal/req", wpi::nt::NetworkTable::NormalizeKey("/no/normal/req"));
|
||||
EXPECT_EQ("/no/leading/slash",
|
||||
nt::NetworkTable::NormalizeKey("no/leading/slash"));
|
||||
EXPECT_EQ("/what/an/awful/key/", nt::NetworkTable::NormalizeKey(
|
||||
wpi::nt::NetworkTable::NormalizeKey("no/leading/slash"));
|
||||
EXPECT_EQ("/what/an/awful/key/", wpi::nt::NetworkTable::NormalizeKey(
|
||||
"//////what////an/awful/////key///"));
|
||||
}
|
||||
|
||||
TEST_F(NetworkTableTest, NormalizeKeyNoSlash) {
|
||||
EXPECT_EQ("a", nt::NetworkTable::NormalizeKey("a", false));
|
||||
EXPECT_EQ("a", nt::NetworkTable::NormalizeKey("///a", false));
|
||||
EXPECT_EQ("a", wpi::nt::NetworkTable::NormalizeKey("a", false));
|
||||
EXPECT_EQ("a", wpi::nt::NetworkTable::NormalizeKey("///a", false));
|
||||
EXPECT_EQ("leading/slash",
|
||||
nt::NetworkTable::NormalizeKey("/leading/slash", false));
|
||||
wpi::nt::NetworkTable::NormalizeKey("/leading/slash", false));
|
||||
EXPECT_EQ("no/leading/slash",
|
||||
nt::NetworkTable::NormalizeKey("no/leading/slash", false));
|
||||
wpi::nt::NetworkTable::NormalizeKey("no/leading/slash", false));
|
||||
EXPECT_EQ("what/an/awful/key/",
|
||||
nt::NetworkTable::NormalizeKey("//////what////an/awful/////key///",
|
||||
wpi::nt::NetworkTable::NormalizeKey("//////what////an/awful/////key///",
|
||||
false));
|
||||
}
|
||||
|
||||
TEST_F(NetworkTableTest, GetHierarchyEmpty) {
|
||||
std::vector<std::string> expected{"/"};
|
||||
ASSERT_EQ(expected, nt::NetworkTable::GetHierarchy(""));
|
||||
ASSERT_EQ(expected, wpi::nt::NetworkTable::GetHierarchy(""));
|
||||
}
|
||||
|
||||
TEST_F(NetworkTableTest, GetHierarchyRoot) {
|
||||
std::vector<std::string> expected{"/"};
|
||||
ASSERT_EQ(expected, nt::NetworkTable::GetHierarchy("/"));
|
||||
ASSERT_EQ(expected, wpi::nt::NetworkTable::GetHierarchy("/"));
|
||||
}
|
||||
|
||||
TEST_F(NetworkTableTest, GetHierarchyNormal) {
|
||||
std::vector<std::string> expected{"/", "/foo", "/foo/bar", "/foo/bar/baz"};
|
||||
ASSERT_EQ(expected, nt::NetworkTable::GetHierarchy("/foo/bar/baz"));
|
||||
ASSERT_EQ(expected, wpi::nt::NetworkTable::GetHierarchy("/foo/bar/baz"));
|
||||
}
|
||||
|
||||
TEST_F(NetworkTableTest, GetHierarchyTrailingSlash) {
|
||||
std::vector<std::string> expected{"/", "/foo", "/foo/bar", "/foo/bar/"};
|
||||
ASSERT_EQ(expected, nt::NetworkTable::GetHierarchy("/foo/bar/"));
|
||||
ASSERT_EQ(expected, wpi::nt::NetworkTable::GetHierarchy("/foo/bar/"));
|
||||
}
|
||||
|
||||
TEST_F(NetworkTableTest, ContainsKey) {
|
||||
auto inst = nt::NetworkTableInstance::Create();
|
||||
auto inst = wpi::nt::NetworkTableInstance::Create();
|
||||
auto nt = inst.GetTable("containskey");
|
||||
ASSERT_FALSE(nt->ContainsKey("testkey"));
|
||||
nt->PutNumber("testkey", 5);
|
||||
ASSERT_TRUE(nt->ContainsKey("testkey"));
|
||||
ASSERT_TRUE(inst.GetEntry("/containskey/testkey").Exists());
|
||||
ASSERT_FALSE(inst.GetEntry("containskey/testkey").Exists());
|
||||
nt::NetworkTableInstance::Destroy(inst);
|
||||
wpi::nt::NetworkTableInstance::Destroy(inst);
|
||||
}
|
||||
|
||||
TEST_F(NetworkTableTest, LeadingSlash) {
|
||||
auto inst = nt::NetworkTableInstance::Create();
|
||||
auto inst = wpi::nt::NetworkTableInstance::Create();
|
||||
auto nt = inst.GetTable("leadingslash");
|
||||
auto nt2 = inst.GetTable("/leadingslash");
|
||||
ASSERT_FALSE(nt->ContainsKey("testkey"));
|
||||
nt2->PutNumber("testkey", 5);
|
||||
ASSERT_TRUE(nt->ContainsKey("testkey"));
|
||||
ASSERT_TRUE(inst.GetEntry("/leadingslash/testkey").Exists());
|
||||
nt::NetworkTableInstance::Destroy(inst);
|
||||
wpi::nt::NetworkTableInstance::Destroy(inst);
|
||||
}
|
||||
|
||||
TEST_F(NetworkTableTest, EmptyOrNoSlash) {
|
||||
auto inst = nt::NetworkTableInstance::Create();
|
||||
auto inst = wpi::nt::NetworkTableInstance::Create();
|
||||
auto nt = inst.GetTable("/");
|
||||
auto nt2 = inst.GetTable("");
|
||||
ASSERT_FALSE(nt->ContainsKey("testkey"));
|
||||
nt2->PutNumber("testkey", 5);
|
||||
ASSERT_TRUE(nt->ContainsKey("testkey"));
|
||||
ASSERT_TRUE(inst.GetEntry("/testkey").Exists());
|
||||
nt::NetworkTableInstance::Destroy(inst);
|
||||
wpi::nt::NetworkTableInstance::Destroy(inst);
|
||||
}
|
||||
|
||||
TEST_F(NetworkTableTest, ResetInstance) {
|
||||
auto inst = nt::NetworkTableInstance::Create();
|
||||
auto inst = wpi::nt::NetworkTableInstance::Create();
|
||||
auto nt = inst.GetTable("containskey");
|
||||
ASSERT_FALSE(nt->ContainsKey("testkey"));
|
||||
nt->PutNumber("testkey", 5);
|
||||
ASSERT_TRUE(nt->ContainsKey("testkey"));
|
||||
ASSERT_TRUE(inst.GetEntry("/containskey/testkey").Exists());
|
||||
nt::ResetInstance(inst.GetHandle());
|
||||
wpi::nt::ResetInstance(inst.GetHandle());
|
||||
ASSERT_FALSE(nt->ContainsKey("testkey"));
|
||||
nt::NetworkTableInstance::Destroy(inst);
|
||||
wpi::nt::NetworkTableInstance::Destroy(inst);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "TestPrinters.hpp"
|
||||
|
||||
namespace nt {
|
||||
namespace wpi::nt {
|
||||
|
||||
bool PubSubOptionsMatcher::MatchAndExplain(
|
||||
const PubSubOptionsImpl& val,
|
||||
@@ -40,4 +40,4 @@ void PubSubOptionsMatcher::DescribeNegationTo(::std::ostream* os) const {
|
||||
PrintTo(good, os);
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
} // namespace wpi::nt
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "PubSubOptions.hpp"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
namespace nt {
|
||||
namespace wpi::nt {
|
||||
|
||||
class PubSubOptionsMatcher
|
||||
: public ::testing::MatcherInterface<const PubSubOptionsImpl&> {
|
||||
@@ -32,4 +32,4 @@ inline ::testing::Matcher<const PubSubOptionsImpl&> PubSubOptionsEq(
|
||||
return ::testing::MakeMatcher(new PubSubOptionsMatcher(std::move(good)));
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
} // namespace wpi::nt
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "MockDispatcher.h"
|
||||
#include "Storage.h"
|
||||
|
||||
namespace nt {
|
||||
namespace wpi::nt {
|
||||
|
||||
class StorageTest {
|
||||
public:
|
||||
@@ -28,10 +28,10 @@ class StorageTest {
|
||||
|
||||
void HookOutgoing(bool server) { storage.SetDispatcher(&dispatcher, server); }
|
||||
|
||||
wpi::Logger logger;
|
||||
wpi::util::Logger logger;
|
||||
::testing::StrictMock<MockDispatcher> dispatcher;
|
||||
Storage storage;
|
||||
Storage::Entry tmp_entry;
|
||||
};
|
||||
|
||||
} // namespace nt
|
||||
} // namespace wpi::nt
|
||||
|
||||
@@ -45,85 +45,85 @@ struct Info1 {
|
||||
} // namespace
|
||||
|
||||
template <>
|
||||
struct wpi::Struct<Inner> {
|
||||
struct wpi::util::Struct<Inner> {
|
||||
static constexpr std::string_view GetTypeName() { return "Inner"; }
|
||||
static constexpr size_t GetSize() { return 8; }
|
||||
static constexpr std::string_view GetSchema() { return "int32 a; int32 b"; }
|
||||
|
||||
static Inner Unpack(std::span<const uint8_t> data) {
|
||||
return {wpi::UnpackStruct<int32_t, 0>(data),
|
||||
wpi::UnpackStruct<int32_t, 4>(data)};
|
||||
return {wpi::util::UnpackStruct<int32_t, 0>(data),
|
||||
wpi::util::UnpackStruct<int32_t, 4>(data)};
|
||||
}
|
||||
static void Pack(std::span<uint8_t> data, const Inner& value) {
|
||||
wpi::PackStruct<0>(data, value.a);
|
||||
wpi::PackStruct<4>(data, value.b);
|
||||
wpi::util::PackStruct<0>(data, value.a);
|
||||
wpi::util::PackStruct<4>(data, value.b);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct wpi::Struct<Outer> {
|
||||
struct wpi::util::Struct<Outer> {
|
||||
static constexpr std::string_view GetTypeName() { return "Outer"; }
|
||||
static constexpr size_t GetSize() { return wpi::GetStructSize<Inner>() + 4; }
|
||||
static constexpr size_t GetSize() { return wpi::util::GetStructSize<Inner>() + 4; }
|
||||
static constexpr std::string_view GetSchema() {
|
||||
return "Inner inner; int32 c";
|
||||
}
|
||||
|
||||
static Outer Unpack(std::span<const uint8_t> data) {
|
||||
constexpr size_t innerSize = wpi::GetStructSize<Inner>();
|
||||
return {wpi::UnpackStruct<Inner, 0>(data),
|
||||
wpi::UnpackStruct<int32_t, innerSize>(data)};
|
||||
constexpr size_t innerSize = wpi::util::GetStructSize<Inner>();
|
||||
return {wpi::util::UnpackStruct<Inner, 0>(data),
|
||||
wpi::util::UnpackStruct<int32_t, innerSize>(data)};
|
||||
}
|
||||
static void Pack(std::span<uint8_t> data, const Outer& value) {
|
||||
constexpr size_t innerSize = wpi::GetStructSize<Inner>();
|
||||
wpi::PackStruct<0>(data, value.inner);
|
||||
wpi::PackStruct<innerSize>(data, value.c);
|
||||
constexpr size_t innerSize = wpi::util::GetStructSize<Inner>();
|
||||
wpi::util::PackStruct<0>(data, value.inner);
|
||||
wpi::util::PackStruct<innerSize>(data, value.c);
|
||||
}
|
||||
static void ForEachNested(
|
||||
std::invocable<std::string_view, std::string_view> auto fn) {
|
||||
wpi::ForEachStructSchema<Inner>(fn);
|
||||
wpi::util::ForEachStructSchema<Inner>(fn);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct wpi::Struct<Inner2> {
|
||||
struct wpi::util::Struct<Inner2> {
|
||||
static std::string_view GetTypeName() { return "Inner2"; }
|
||||
static size_t GetSize() { return 8; }
|
||||
static std::string_view GetSchema() { return "int32 a; int32 b"; }
|
||||
|
||||
static Inner2 Unpack(std::span<const uint8_t> data) {
|
||||
return {wpi::UnpackStruct<int32_t, 0>(data),
|
||||
wpi::UnpackStruct<int32_t, 4>(data)};
|
||||
return {wpi::util::UnpackStruct<int32_t, 0>(data),
|
||||
wpi::util::UnpackStruct<int32_t, 4>(data)};
|
||||
}
|
||||
static void Pack(std::span<uint8_t> data, const Inner2& value) {
|
||||
wpi::PackStruct<0>(data, value.a);
|
||||
wpi::PackStruct<4>(data, value.b);
|
||||
wpi::util::PackStruct<0>(data, value.a);
|
||||
wpi::util::PackStruct<4>(data, value.b);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct wpi::Struct<Outer2> {
|
||||
struct wpi::util::Struct<Outer2> {
|
||||
static std::string_view GetTypeName() { return "Outer2"; }
|
||||
static size_t GetSize() { return wpi::GetStructSize<Inner>() + 4; }
|
||||
static size_t GetSize() { return wpi::util::GetStructSize<Inner>() + 4; }
|
||||
static std::string_view GetSchema() { return "Inner2 inner; int32 c"; }
|
||||
|
||||
static Outer2 Unpack(std::span<const uint8_t> data) {
|
||||
size_t innerSize = wpi::GetStructSize<Inner2>();
|
||||
return {wpi::UnpackStruct<Inner2, 0>(data),
|
||||
wpi::UnpackStruct<int32_t>(data.subspan(innerSize))};
|
||||
size_t innerSize = wpi::util::GetStructSize<Inner2>();
|
||||
return {wpi::util::UnpackStruct<Inner2, 0>(data),
|
||||
wpi::util::UnpackStruct<int32_t>(data.subspan(innerSize))};
|
||||
}
|
||||
static void Pack(std::span<uint8_t> data, const Outer2& value) {
|
||||
size_t innerSize = wpi::GetStructSize<Inner2>();
|
||||
wpi::PackStruct<0>(data, value.inner);
|
||||
wpi::PackStruct(data.subspan(innerSize), value.c);
|
||||
size_t innerSize = wpi::util::GetStructSize<Inner2>();
|
||||
wpi::util::PackStruct<0>(data, value.inner);
|
||||
wpi::util::PackStruct(data.subspan(innerSize), value.c);
|
||||
}
|
||||
static void ForEachNested(
|
||||
std::invocable<std::string_view, std::string_view> auto fn) {
|
||||
wpi::ForEachStructSchema<Inner2>(fn);
|
||||
wpi::util::ForEachStructSchema<Inner2>(fn);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct wpi::Struct<ThingA> {
|
||||
struct wpi::util::Struct<ThingA> {
|
||||
static constexpr std::string_view GetTypeName() { return "ThingA"; }
|
||||
static constexpr size_t GetSize() { return 1; }
|
||||
static constexpr std::string_view GetSchema() { return "uint8 value"; }
|
||||
@@ -136,7 +136,7 @@ struct wpi::Struct<ThingA> {
|
||||
};
|
||||
|
||||
template <>
|
||||
struct wpi::Struct<ThingB, Info1> {
|
||||
struct wpi::util::Struct<ThingB, Info1> {
|
||||
static constexpr std::string_view GetTypeName(const Info1&) {
|
||||
return "ThingB";
|
||||
}
|
||||
@@ -152,20 +152,20 @@ struct wpi::Struct<ThingB, Info1> {
|
||||
}
|
||||
};
|
||||
|
||||
namespace nt {
|
||||
namespace wpi::nt {
|
||||
|
||||
class StructTest : public ::testing::Test {
|
||||
public:
|
||||
StructTest() { inst = nt::NetworkTableInstance::Create(); }
|
||||
~StructTest() override { nt::NetworkTableInstance::Destroy(inst); }
|
||||
StructTest() { inst = wpi::nt::NetworkTableInstance::Create(); }
|
||||
~StructTest() override { wpi::nt::NetworkTableInstance::Destroy(inst); }
|
||||
|
||||
nt::NetworkTableInstance inst;
|
||||
wpi::nt::NetworkTableInstance inst;
|
||||
};
|
||||
|
||||
TEST_F(StructTest, InnerConstexpr) {
|
||||
nt::StructTopic<Inner> topic = inst.GetStructTopic<Inner>("inner");
|
||||
nt::StructPublisher<Inner> pub = topic.Publish();
|
||||
nt::StructSubscriber<Inner> sub = topic.Subscribe({});
|
||||
wpi::nt::StructTopic<Inner> topic = inst.GetStructTopic<Inner>("inner");
|
||||
wpi::nt::StructPublisher<Inner> pub = topic.Publish();
|
||||
wpi::nt::StructSubscriber<Inner> sub = topic.Subscribe({});
|
||||
|
||||
ASSERT_EQ(topic.GetTypeString(), "struct:Inner");
|
||||
|
||||
@@ -191,9 +191,9 @@ TEST_F(StructTest, InnerConstexpr) {
|
||||
}
|
||||
|
||||
TEST_F(StructTest, InnerNonconstexpr) {
|
||||
nt::StructTopic<Inner2> topic = inst.GetStructTopic<Inner2>("inner2");
|
||||
nt::StructPublisher<Inner2> pub = topic.Publish();
|
||||
nt::StructSubscriber<Inner2> sub = topic.Subscribe({});
|
||||
wpi::nt::StructTopic<Inner2> topic = inst.GetStructTopic<Inner2>("inner2");
|
||||
wpi::nt::StructPublisher<Inner2> pub = topic.Publish();
|
||||
wpi::nt::StructSubscriber<Inner2> sub = topic.Subscribe({});
|
||||
|
||||
ASSERT_EQ(topic.GetTypeString(), "struct:Inner2");
|
||||
|
||||
@@ -219,9 +219,9 @@ TEST_F(StructTest, InnerNonconstexpr) {
|
||||
}
|
||||
|
||||
TEST_F(StructTest, OuterConstexpr) {
|
||||
nt::StructTopic<Outer> topic = inst.GetStructTopic<Outer>("outer");
|
||||
nt::StructPublisher<Outer> pub = topic.Publish();
|
||||
nt::StructSubscriber<Outer> sub = topic.Subscribe({});
|
||||
wpi::nt::StructTopic<Outer> topic = inst.GetStructTopic<Outer>("outer");
|
||||
wpi::nt::StructPublisher<Outer> pub = topic.Publish();
|
||||
wpi::nt::StructSubscriber<Outer> sub = topic.Subscribe({});
|
||||
|
||||
ASSERT_EQ(topic.GetTypeString(), "struct:Outer");
|
||||
|
||||
@@ -251,9 +251,9 @@ TEST_F(StructTest, OuterConstexpr) {
|
||||
}
|
||||
|
||||
TEST_F(StructTest, OuterNonconstexpr) {
|
||||
nt::StructTopic<Outer2> topic = inst.GetStructTopic<Outer2>("outer2");
|
||||
nt::StructPublisher<Outer2> pub = topic.Publish();
|
||||
nt::StructSubscriber<Outer2> sub = topic.Subscribe({});
|
||||
wpi::nt::StructTopic<Outer2> topic = inst.GetStructTopic<Outer2>("outer2");
|
||||
wpi::nt::StructPublisher<Outer2> pub = topic.Publish();
|
||||
wpi::nt::StructSubscriber<Outer2> sub = topic.Subscribe({});
|
||||
|
||||
ASSERT_EQ(topic.GetTypeString(), "struct:Outer2");
|
||||
|
||||
@@ -283,9 +283,9 @@ TEST_F(StructTest, OuterNonconstexpr) {
|
||||
}
|
||||
|
||||
TEST_F(StructTest, InnerArrayConstexpr) {
|
||||
nt::StructArrayTopic<Inner> topic = inst.GetStructArrayTopic<Inner>("innerA");
|
||||
nt::StructArrayPublisher<Inner> pub = topic.Publish();
|
||||
nt::StructArraySubscriber<Inner> sub = topic.Subscribe({});
|
||||
wpi::nt::StructArrayTopic<Inner> topic = inst.GetStructArrayTopic<Inner>("innerA");
|
||||
wpi::nt::StructArrayPublisher<Inner> pub = topic.Publish();
|
||||
wpi::nt::StructArraySubscriber<Inner> sub = topic.Subscribe({});
|
||||
|
||||
ASSERT_EQ(topic.GetTypeString(), "struct:Inner[]");
|
||||
|
||||
@@ -309,10 +309,10 @@ TEST_F(StructTest, InnerArrayConstexpr) {
|
||||
}
|
||||
|
||||
TEST_F(StructTest, InnerArrayNonconstexpr) {
|
||||
nt::StructArrayTopic<Inner2> topic =
|
||||
wpi::nt::StructArrayTopic<Inner2> topic =
|
||||
inst.GetStructArrayTopic<Inner2>("innerA2");
|
||||
nt::StructArrayPublisher<Inner2> pub = topic.Publish();
|
||||
nt::StructArraySubscriber<Inner2> sub = topic.Subscribe({});
|
||||
wpi::nt::StructArrayPublisher<Inner2> pub = topic.Publish();
|
||||
wpi::nt::StructArraySubscriber<Inner2> sub = topic.Subscribe({});
|
||||
|
||||
ASSERT_EQ(topic.GetTypeString(), "struct:Inner2[]");
|
||||
|
||||
@@ -336,11 +336,11 @@ TEST_F(StructTest, InnerArrayNonconstexpr) {
|
||||
}
|
||||
|
||||
TEST_F(StructTest, StructA) {
|
||||
nt::StructTopic<ThingA> topic = inst.GetStructTopic<ThingA>("a");
|
||||
nt::StructPublisher<ThingA> pub = topic.Publish();
|
||||
nt::StructPublisher<ThingA> pub2 = topic.PublishEx({{}});
|
||||
nt::StructSubscriber<ThingA> sub = topic.Subscribe({});
|
||||
nt::StructEntry<ThingA> entry = topic.GetEntry({});
|
||||
wpi::nt::StructTopic<ThingA> topic = inst.GetStructTopic<ThingA>("a");
|
||||
wpi::nt::StructPublisher<ThingA> pub = topic.Publish();
|
||||
wpi::nt::StructPublisher<ThingA> pub2 = topic.PublishEx({{}});
|
||||
wpi::nt::StructSubscriber<ThingA> sub = topic.Subscribe({});
|
||||
wpi::nt::StructEntry<ThingA> entry = topic.GetEntry({});
|
||||
pub.SetDefault({});
|
||||
pub.Set({}, 5);
|
||||
sub.Get();
|
||||
@@ -353,11 +353,11 @@ TEST_F(StructTest, StructA) {
|
||||
}
|
||||
|
||||
TEST_F(StructTest, StructArrayA) {
|
||||
nt::StructArrayTopic<ThingA> topic = inst.GetStructArrayTopic<ThingA>("a");
|
||||
nt::StructArrayPublisher<ThingA> pub = topic.Publish();
|
||||
nt::StructArrayPublisher<ThingA> pub2 = topic.PublishEx({{}});
|
||||
nt::StructArraySubscriber<ThingA> sub = topic.Subscribe({});
|
||||
nt::StructArrayEntry<ThingA> entry = topic.GetEntry({});
|
||||
wpi::nt::StructArrayTopic<ThingA> topic = inst.GetStructArrayTopic<ThingA>("a");
|
||||
wpi::nt::StructArrayPublisher<ThingA> pub = topic.Publish();
|
||||
wpi::nt::StructArrayPublisher<ThingA> pub2 = topic.PublishEx({{}});
|
||||
wpi::nt::StructArraySubscriber<ThingA> sub = topic.Subscribe({});
|
||||
wpi::nt::StructArrayEntry<ThingA> entry = topic.GetEntry({});
|
||||
pub.SetDefault({{ThingA{}, ThingA{}}});
|
||||
pub.Set({{ThingA{}, ThingA{}}}, 5);
|
||||
sub.Get();
|
||||
@@ -370,12 +370,12 @@ TEST_F(StructTest, StructArrayA) {
|
||||
}
|
||||
|
||||
TEST_F(StructTest, StructFixedArrayA) {
|
||||
nt::StructTopic<std::array<ThingA, 2>> topic =
|
||||
wpi::nt::StructTopic<std::array<ThingA, 2>> topic =
|
||||
inst.GetStructTopic<std::array<ThingA, 2>>("a");
|
||||
nt::StructPublisher<std::array<ThingA, 2>> pub = topic.Publish();
|
||||
nt::StructPublisher<std::array<ThingA, 2>> pub2 = topic.PublishEx({{}});
|
||||
nt::StructSubscriber<std::array<ThingA, 2>> sub = topic.Subscribe({});
|
||||
nt::StructEntry<std::array<ThingA, 2>> entry = topic.GetEntry({});
|
||||
wpi::nt::StructPublisher<std::array<ThingA, 2>> pub = topic.Publish();
|
||||
wpi::nt::StructPublisher<std::array<ThingA, 2>> pub2 = topic.PublishEx({{}});
|
||||
wpi::nt::StructSubscriber<std::array<ThingA, 2>> sub = topic.Subscribe({});
|
||||
wpi::nt::StructEntry<std::array<ThingA, 2>> entry = topic.GetEntry({});
|
||||
std::array<ThingA, 2> arr;
|
||||
pub.SetDefault(arr);
|
||||
pub.Set(arr, 5);
|
||||
@@ -390,12 +390,12 @@ TEST_F(StructTest, StructFixedArrayA) {
|
||||
|
||||
TEST_F(StructTest, StructB) {
|
||||
Info1 info;
|
||||
nt::StructTopic<ThingB, Info1> topic =
|
||||
wpi::nt::StructTopic<ThingB, Info1> topic =
|
||||
inst.GetStructTopic<ThingB, Info1>("b", info);
|
||||
nt::StructPublisher<ThingB, Info1> pub = topic.Publish();
|
||||
nt::StructPublisher<ThingB, Info1> pub2 = topic.PublishEx({{}});
|
||||
nt::StructSubscriber<ThingB, Info1> sub = topic.Subscribe({});
|
||||
nt::StructEntry<ThingB, Info1> entry = topic.GetEntry({});
|
||||
wpi::nt::StructPublisher<ThingB, Info1> pub = topic.Publish();
|
||||
wpi::nt::StructPublisher<ThingB, Info1> pub2 = topic.PublishEx({{}});
|
||||
wpi::nt::StructSubscriber<ThingB, Info1> sub = topic.Subscribe({});
|
||||
wpi::nt::StructEntry<ThingB, Info1> entry = topic.GetEntry({});
|
||||
pub.SetDefault({});
|
||||
pub.Set({}, 5);
|
||||
sub.Get();
|
||||
@@ -409,12 +409,12 @@ TEST_F(StructTest, StructB) {
|
||||
|
||||
TEST_F(StructTest, StructArrayB) {
|
||||
Info1 info;
|
||||
nt::StructArrayTopic<ThingB, Info1> topic =
|
||||
wpi::nt::StructArrayTopic<ThingB, Info1> topic =
|
||||
inst.GetStructArrayTopic<ThingB, Info1>("b", info);
|
||||
nt::StructArrayPublisher<ThingB, Info1> pub = topic.Publish();
|
||||
nt::StructArrayPublisher<ThingB, Info1> pub2 = topic.PublishEx({{}});
|
||||
nt::StructArraySubscriber<ThingB, Info1> sub = topic.Subscribe({});
|
||||
nt::StructArrayEntry<ThingB, Info1> entry = topic.GetEntry({});
|
||||
wpi::nt::StructArrayPublisher<ThingB, Info1> pub = topic.Publish();
|
||||
wpi::nt::StructArrayPublisher<ThingB, Info1> pub2 = topic.PublishEx({{}});
|
||||
wpi::nt::StructArraySubscriber<ThingB, Info1> sub = topic.Subscribe({});
|
||||
wpi::nt::StructArrayEntry<ThingB, Info1> entry = topic.GetEntry({});
|
||||
pub.SetDefault({{ThingB{}, ThingB{}}});
|
||||
pub.Set({{ThingB{}, ThingB{}}}, 5);
|
||||
sub.Get();
|
||||
@@ -428,13 +428,13 @@ TEST_F(StructTest, StructArrayB) {
|
||||
|
||||
TEST_F(StructTest, StructFixedArrayB) {
|
||||
Info1 info;
|
||||
nt::StructTopic<std::array<ThingB, 2>, Info1> topic =
|
||||
wpi::nt::StructTopic<std::array<ThingB, 2>, Info1> topic =
|
||||
inst.GetStructTopic<std::array<ThingB, 2>, Info1>("b", info);
|
||||
nt::StructPublisher<std::array<ThingB, 2>, Info1> pub = topic.Publish();
|
||||
nt::StructPublisher<std::array<ThingB, 2>, Info1> pub2 =
|
||||
wpi::nt::StructPublisher<std::array<ThingB, 2>, Info1> pub = topic.Publish();
|
||||
wpi::nt::StructPublisher<std::array<ThingB, 2>, Info1> pub2 =
|
||||
topic.PublishEx({{}});
|
||||
nt::StructSubscriber<std::array<ThingB, 2>, Info1> sub = topic.Subscribe({});
|
||||
nt::StructEntry<std::array<ThingB, 2>, Info1> entry = topic.GetEntry({});
|
||||
wpi::nt::StructSubscriber<std::array<ThingB, 2>, Info1> sub = topic.Subscribe({});
|
||||
wpi::nt::StructEntry<std::array<ThingB, 2>, Info1> entry = topic.GetEntry({});
|
||||
std::array<ThingB, 2> arr;
|
||||
pub.SetDefault(arr);
|
||||
pub.Set(arr, 5);
|
||||
@@ -447,4 +447,4 @@ TEST_F(StructTest, StructFixedArrayB) {
|
||||
entry.Get(arr);
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
} // namespace wpi::nt
|
||||
|
||||
@@ -15,24 +15,24 @@
|
||||
using ::testing::_;
|
||||
|
||||
using MockTableEventListener = testing::MockFunction<void(
|
||||
nt::NetworkTable* table, std::string_view key, const nt::Event& event)>;
|
||||
wpi::nt::NetworkTable* table, std::string_view key, const wpi::nt::Event& event)>;
|
||||
using MockSubTableListener =
|
||||
testing::MockFunction<void(nt::NetworkTable* parent, std::string_view name,
|
||||
std::shared_ptr<nt::NetworkTable> table)>;
|
||||
testing::MockFunction<void(wpi::nt::NetworkTable* parent, std::string_view name,
|
||||
std::shared_ptr<wpi::nt::NetworkTable> table)>;
|
||||
|
||||
class TableListenerTest : public ::testing::Test {
|
||||
public:
|
||||
TableListenerTest() : m_inst(nt::NetworkTableInstance::Create()) {}
|
||||
TableListenerTest() : m_inst(wpi::nt::NetworkTableInstance::Create()) {}
|
||||
|
||||
~TableListenerTest() override { nt::NetworkTableInstance::Destroy(m_inst); }
|
||||
~TableListenerTest() override { wpi::nt::NetworkTableInstance::Destroy(m_inst); }
|
||||
|
||||
void PublishTopics();
|
||||
|
||||
protected:
|
||||
nt::NetworkTableInstance m_inst;
|
||||
nt::DoublePublisher m_foovalue;
|
||||
nt::DoublePublisher m_barvalue;
|
||||
nt::DoublePublisher m_bazvalue;
|
||||
wpi::nt::NetworkTableInstance m_inst;
|
||||
wpi::nt::DoublePublisher m_foovalue;
|
||||
wpi::nt::DoublePublisher m_barvalue;
|
||||
wpi::nt::DoublePublisher m_bazvalue;
|
||||
};
|
||||
|
||||
void TableListenerTest::PublishTopics() {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "wpi/nt/NetworkTableValue.hpp"
|
||||
#include "wpi/nt/ntcore_cpp.hpp"
|
||||
|
||||
namespace nt {
|
||||
namespace wpi::nt {
|
||||
|
||||
void PrintTo(const Event& event, std::ostream* os) {
|
||||
*os << "Event{listener=";
|
||||
@@ -105,4 +105,4 @@ void PrintTo(const PubSubOptionsImpl& options, std::ostream* os) {
|
||||
<< ", keepDuplicates=" << options.keepDuplicates << '}';
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
} // namespace wpi::nt
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
#include "wpi/util/TestPrinters.hpp"
|
||||
|
||||
namespace nt {
|
||||
namespace wpi::nt {
|
||||
|
||||
namespace net3 {
|
||||
class Message3;
|
||||
@@ -37,4 +37,4 @@ void PrintTo(const net::ServerMessage& msg, std::ostream* os);
|
||||
void PrintTo(const Value& value, std::ostream* os);
|
||||
void PrintTo(const PubSubOptionsImpl& options, std::ostream* os);
|
||||
|
||||
} // namespace nt
|
||||
} // namespace wpi::nt
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
|
||||
class TimeSyncTest : public ::testing::Test {
|
||||
public:
|
||||
TimeSyncTest() : m_inst(nt::NetworkTableInstance::Create()) {}
|
||||
TimeSyncTest() : m_inst(wpi::nt::NetworkTableInstance::Create()) {}
|
||||
|
||||
~TimeSyncTest() override { nt::NetworkTableInstance::Destroy(m_inst); }
|
||||
~TimeSyncTest() override { wpi::nt::NetworkTableInstance::Destroy(m_inst); }
|
||||
|
||||
protected:
|
||||
nt::NetworkTableInstance m_inst;
|
||||
wpi::nt::NetworkTableInstance m_inst;
|
||||
};
|
||||
|
||||
TEST_F(TimeSyncTest, TestLocal) {
|
||||
@@ -23,7 +23,7 @@ TEST_F(TimeSyncTest, TestLocal) {
|
||||
}
|
||||
|
||||
TEST_F(TimeSyncTest, TestServer) {
|
||||
nt::NetworkTableListenerPoller poller{m_inst};
|
||||
wpi::nt::NetworkTableListenerPoller poller{m_inst};
|
||||
poller.AddTimeSyncListener(false);
|
||||
|
||||
m_inst.StartServer("timesynctest.json", "127.0.0.1", 10030);
|
||||
|
||||
@@ -19,14 +19,14 @@
|
||||
class TopicListenerTest : public ::testing::Test {
|
||||
public:
|
||||
TopicListenerTest()
|
||||
: m_serverInst(nt::CreateInstance()), m_clientInst(nt::CreateInstance()) {
|
||||
: m_serverInst(wpi::nt::CreateInstance()), m_clientInst(wpi::nt::CreateInstance()) {
|
||||
#if 0
|
||||
nt::AddLogger(m_serverInst, 0, UINT_MAX, [](auto& event) {
|
||||
wpi::nt::AddLogger(m_serverInst, 0, UINT_MAX, [](auto& event) {
|
||||
if (auto msg = event.GetLogMessage()) {
|
||||
std::fprintf(stderr, "SERVER: %s\n", msg->message.c_str());
|
||||
}
|
||||
});
|
||||
nt::AddLogger(m_clientInst, 0, UINT_MAX, [](auto& event) {
|
||||
wpi::nt::AddLogger(m_clientInst, 0, UINT_MAX, [](auto& event) {
|
||||
if (auto msg = event.GetLogMessage()) {
|
||||
std::fprintf(stderr, "CLIENT: %s\n", msg.message.c_str());
|
||||
}
|
||||
@@ -35,13 +35,13 @@ class TopicListenerTest : public ::testing::Test {
|
||||
}
|
||||
|
||||
~TopicListenerTest() override {
|
||||
nt::DestroyInstance(m_serverInst);
|
||||
nt::DestroyInstance(m_clientInst);
|
||||
wpi::nt::DestroyInstance(m_serverInst);
|
||||
wpi::nt::DestroyInstance(m_clientInst);
|
||||
}
|
||||
|
||||
void Connect(unsigned int port);
|
||||
static void PublishTopics(NT_Inst inst);
|
||||
void CheckEvents(const std::vector<nt::Event>& events, NT_Listener handle,
|
||||
void CheckEvents(const std::vector<wpi::nt::Event>& events, NT_Listener handle,
|
||||
unsigned int flags, std::string_view topicName = "/foo/bar");
|
||||
|
||||
protected:
|
||||
@@ -50,26 +50,26 @@ class TopicListenerTest : public ::testing::Test {
|
||||
};
|
||||
|
||||
void TopicListenerTest::Connect(unsigned int port) {
|
||||
nt::StartServer(m_serverInst, "topiclistenertest.json", "127.0.0.1", port);
|
||||
nt::StartClient(m_clientInst, "client");
|
||||
nt::SetServer(m_clientInst, "127.0.0.1", port);
|
||||
wpi::nt::StartServer(m_serverInst, "topiclistenertest.json", "127.0.0.1", port);
|
||||
wpi::nt::StartClient(m_clientInst, "client");
|
||||
wpi::nt::SetServer(m_clientInst, "127.0.0.1", port);
|
||||
|
||||
// Use connection listener to ensure we've connected
|
||||
NT_ListenerPoller poller = nt::CreateListenerPoller(m_clientInst);
|
||||
nt::AddPolledListener(poller, m_clientInst, nt::EventFlags::kConnected);
|
||||
NT_ListenerPoller poller = wpi::nt::CreateListenerPoller(m_clientInst);
|
||||
wpi::nt::AddPolledListener(poller, m_clientInst, wpi::nt::EventFlags::kConnected);
|
||||
bool timedOut = false;
|
||||
if (!wpi::WaitForObject(poller, 1.0, &timedOut)) {
|
||||
if (!wpi::util::WaitForObject(poller, 1.0, &timedOut)) {
|
||||
FAIL() << "client didn't connect to server";
|
||||
}
|
||||
}
|
||||
|
||||
void TopicListenerTest::PublishTopics(NT_Inst inst) {
|
||||
nt::Publish(nt::GetTopic(inst, "/foo/bar"), NT_DOUBLE, "double");
|
||||
nt::Publish(nt::GetTopic(inst, "/foo"), NT_DOUBLE, "double");
|
||||
nt::Publish(nt::GetTopic(inst, "/baz"), NT_DOUBLE, "double");
|
||||
wpi::nt::Publish(wpi::nt::GetTopic(inst, "/foo/bar"), NT_DOUBLE, "double");
|
||||
wpi::nt::Publish(wpi::nt::GetTopic(inst, "/foo"), NT_DOUBLE, "double");
|
||||
wpi::nt::Publish(wpi::nt::GetTopic(inst, "/baz"), NT_DOUBLE, "double");
|
||||
}
|
||||
|
||||
void TopicListenerTest::CheckEvents(const std::vector<nt::Event>& events,
|
||||
void TopicListenerTest::CheckEvents(const std::vector<wpi::nt::Event>& events,
|
||||
NT_Listener handle, unsigned int flags,
|
||||
std::string_view topicName) {
|
||||
ASSERT_EQ(events.size(), 1u);
|
||||
@@ -77,21 +77,21 @@ void TopicListenerTest::CheckEvents(const std::vector<nt::Event>& events,
|
||||
ASSERT_EQ(events[0].flags, flags);
|
||||
auto topicInfo = events[0].GetTopicInfo();
|
||||
ASSERT_TRUE(topicInfo);
|
||||
ASSERT_EQ(topicInfo->topic, nt::GetTopic(m_serverInst, topicName));
|
||||
ASSERT_EQ(topicInfo->topic, wpi::nt::GetTopic(m_serverInst, topicName));
|
||||
ASSERT_EQ(topicInfo->name, topicName);
|
||||
}
|
||||
|
||||
TEST_F(TopicListenerTest, TopicNewLocal) {
|
||||
auto poller = nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle = nt::AddPolledListener(
|
||||
poller, nt::GetTopic(m_serverInst, "/foo"), nt::EventFlags::kPublish);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle = wpi::nt::AddPolledListener(
|
||||
poller, wpi::nt::GetTopic(m_serverInst, "/foo"), wpi::nt::EventFlags::kPublish);
|
||||
|
||||
PublishTopics(m_serverInst);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = nt::ReadListenerQueue(poller);
|
||||
CheckEvents(events, handle, nt::EventFlags::kPublish, "/foo");
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = wpi::nt::ReadListenerQueue(poller);
|
||||
CheckEvents(events, handle, wpi::nt::EventFlags::kPublish, "/foo");
|
||||
}
|
||||
|
||||
TEST_F(TopicListenerTest, DISABLED_TopicNewRemote) {
|
||||
@@ -99,65 +99,65 @@ TEST_F(TopicListenerTest, DISABLED_TopicNewRemote) {
|
||||
if (HasFatalFailure()) {
|
||||
return;
|
||||
}
|
||||
auto poller = nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle = nt::AddPolledListener(
|
||||
poller, nt::GetTopic(m_serverInst, "/foo"), nt::EventFlags::kPublish);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle = wpi::nt::AddPolledListener(
|
||||
poller, wpi::nt::GetTopic(m_serverInst, "/foo"), wpi::nt::EventFlags::kPublish);
|
||||
|
||||
PublishTopics(m_clientInst);
|
||||
|
||||
nt::Flush(m_clientInst);
|
||||
wpi::nt::Flush(m_clientInst);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = nt::ReadListenerQueue(poller);
|
||||
CheckEvents(events, handle, nt::EventFlags::kPublish, "/foo");
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = wpi::nt::ReadListenerQueue(poller);
|
||||
CheckEvents(events, handle, wpi::nt::EventFlags::kPublish, "/foo");
|
||||
}
|
||||
|
||||
TEST_F(TopicListenerTest, TopicPublishImm) {
|
||||
PublishTopics(m_serverInst);
|
||||
|
||||
auto poller = nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle = nt::AddPolledListener(
|
||||
poller, nt::GetTopic(m_serverInst, "/foo"),
|
||||
nt::EventFlags::kPublish | nt::EventFlags::kImmediate);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle = wpi::nt::AddPolledListener(
|
||||
poller, wpi::nt::GetTopic(m_serverInst, "/foo"),
|
||||
wpi::nt::EventFlags::kPublish | wpi::nt::EventFlags::kImmediate);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = nt::ReadListenerQueue(poller);
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = wpi::nt::ReadListenerQueue(poller);
|
||||
CheckEvents(events, handle,
|
||||
nt::EventFlags::kPublish | nt::EventFlags::kImmediate, "/foo");
|
||||
wpi::nt::EventFlags::kPublish | wpi::nt::EventFlags::kImmediate, "/foo");
|
||||
}
|
||||
|
||||
TEST_F(TopicListenerTest, TopicUnpublishPropsImm) {
|
||||
PublishTopics(m_serverInst);
|
||||
|
||||
auto poller = nt::CreateListenerPoller(m_serverInst);
|
||||
nt::AddPolledListener(poller, nt::GetTopic(m_serverInst, "/foo"),
|
||||
nt::EventFlags::kUnpublish |
|
||||
nt::EventFlags::kProperties |
|
||||
nt::EventFlags::kImmediate);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
wpi::nt::AddPolledListener(poller, wpi::nt::GetTopic(m_serverInst, "/foo"),
|
||||
wpi::nt::EventFlags::kUnpublish |
|
||||
wpi::nt::EventFlags::kProperties |
|
||||
wpi::nt::EventFlags::kImmediate);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_FALSE(wpi::WaitForObject(poller, 0.02, &timedOut));
|
||||
auto events = nt::ReadListenerQueue(poller);
|
||||
ASSERT_FALSE(wpi::util::WaitForObject(poller, 0.02, &timedOut));
|
||||
auto events = wpi::nt::ReadListenerQueue(poller);
|
||||
ASSERT_TRUE(events.empty());
|
||||
}
|
||||
|
||||
TEST_F(TopicListenerTest, TopicUnpublishLocal) {
|
||||
auto topic = nt::GetTopic(m_serverInst, "/foo");
|
||||
auto topic = wpi::nt::GetTopic(m_serverInst, "/foo");
|
||||
|
||||
auto poller = nt::CreateListenerPoller(m_serverInst);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle =
|
||||
nt::AddPolledListener(poller, topic, nt::EventFlags::kUnpublish);
|
||||
wpi::nt::AddPolledListener(poller, topic, wpi::nt::EventFlags::kUnpublish);
|
||||
|
||||
auto pub = nt::Publish(topic, NT_DOUBLE, "double");
|
||||
nt::Unpublish(pub);
|
||||
auto pub = wpi::nt::Publish(topic, NT_DOUBLE, "double");
|
||||
wpi::nt::Unpublish(pub);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = nt::ReadListenerQueue(poller);
|
||||
CheckEvents(events, handle, nt::EventFlags::kUnpublish, "/foo");
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = wpi::nt::ReadListenerQueue(poller);
|
||||
CheckEvents(events, handle, wpi::nt::EventFlags::kUnpublish, "/foo");
|
||||
}
|
||||
|
||||
TEST_F(TopicListenerTest, DISABLED_TopicUnpublishRemote) {
|
||||
@@ -165,39 +165,39 @@ TEST_F(TopicListenerTest, DISABLED_TopicUnpublishRemote) {
|
||||
if (HasFatalFailure()) {
|
||||
return;
|
||||
}
|
||||
auto poller = nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle = nt::AddPolledListener(
|
||||
poller, nt::GetTopic(m_serverInst, "/foo"), nt::EventFlags::kUnpublish);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle = wpi::nt::AddPolledListener(
|
||||
poller, wpi::nt::GetTopic(m_serverInst, "/foo"), wpi::nt::EventFlags::kUnpublish);
|
||||
|
||||
auto pub =
|
||||
nt::Publish(nt::GetTopic(m_clientInst, "/foo"), NT_DOUBLE, "double");
|
||||
nt::Flush(m_clientInst);
|
||||
wpi::nt::Publish(wpi::nt::GetTopic(m_clientInst, "/foo"), NT_DOUBLE, "double");
|
||||
wpi::nt::Flush(m_clientInst);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
nt::Unpublish(pub);
|
||||
wpi::nt::Unpublish(pub);
|
||||
|
||||
nt::Flush(m_clientInst);
|
||||
wpi::nt::Flush(m_clientInst);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = nt::ReadListenerQueue(poller);
|
||||
CheckEvents(events, handle, nt::EventFlags::kUnpublish, "/foo");
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = wpi::nt::ReadListenerQueue(poller);
|
||||
CheckEvents(events, handle, wpi::nt::EventFlags::kUnpublish, "/foo");
|
||||
}
|
||||
|
||||
TEST_F(TopicListenerTest, TopicPropertiesLocal) {
|
||||
auto topic = nt::GetTopic(m_serverInst, "/foo");
|
||||
auto topic = wpi::nt::GetTopic(m_serverInst, "/foo");
|
||||
|
||||
auto poller = nt::CreateListenerPoller(m_serverInst);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle =
|
||||
nt::AddPolledListener(poller, topic, nt::EventFlags::kProperties);
|
||||
wpi::nt::AddPolledListener(poller, topic, wpi::nt::EventFlags::kProperties);
|
||||
|
||||
nt::SetTopicProperty(topic, "foo", 5);
|
||||
wpi::nt::SetTopicProperty(topic, "foo", 5);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = nt::ReadListenerQueue(poller);
|
||||
CheckEvents(events, handle, nt::EventFlags::kProperties, "/foo");
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = wpi::nt::ReadListenerQueue(poller);
|
||||
CheckEvents(events, handle, wpi::nt::EventFlags::kProperties, "/foo");
|
||||
}
|
||||
|
||||
TEST_F(TopicListenerTest, DISABLED_TopicPropertiesRemote) {
|
||||
@@ -206,34 +206,34 @@ TEST_F(TopicListenerTest, DISABLED_TopicPropertiesRemote) {
|
||||
return;
|
||||
}
|
||||
// the topic needs to actually exist
|
||||
nt::Publish(nt::GetTopic(m_serverInst, "/foo"), NT_BOOLEAN, "boolean");
|
||||
wpi::nt::Publish(wpi::nt::GetTopic(m_serverInst, "/foo"), NT_BOOLEAN, "boolean");
|
||||
|
||||
auto poller = nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle = nt::AddPolledListener(
|
||||
poller, nt::GetTopic(m_serverInst, "/foo"), nt::EventFlags::kProperties);
|
||||
nt::FlushLocal(m_serverInst);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle = wpi::nt::AddPolledListener(
|
||||
poller, wpi::nt::GetTopic(m_serverInst, "/foo"), wpi::nt::EventFlags::kProperties);
|
||||
wpi::nt::FlushLocal(m_serverInst);
|
||||
|
||||
nt::SetTopicProperty(nt::GetTopic(m_clientInst, "/foo"), "foo", 5);
|
||||
nt::Flush(m_clientInst);
|
||||
wpi::nt::SetTopicProperty(wpi::nt::GetTopic(m_clientInst, "/foo"), "foo", 5);
|
||||
wpi::nt::Flush(m_clientInst);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = nt::ReadListenerQueue(poller);
|
||||
CheckEvents(events, handle, nt::EventFlags::kProperties, "/foo");
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = wpi::nt::ReadListenerQueue(poller);
|
||||
CheckEvents(events, handle, wpi::nt::EventFlags::kProperties, "/foo");
|
||||
}
|
||||
|
||||
TEST_F(TopicListenerTest, PrefixPublishLocal) {
|
||||
auto poller = nt::CreateListenerPoller(m_serverInst);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle =
|
||||
nt::AddPolledListener(poller, {{"/foo/"}}, nt::EventFlags::kPublish);
|
||||
wpi::nt::AddPolledListener(poller, {{"/foo/"}}, wpi::nt::EventFlags::kPublish);
|
||||
|
||||
PublishTopics(m_serverInst);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = nt::ReadListenerQueue(poller);
|
||||
CheckEvents(events, handle, nt::EventFlags::kPublish);
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = wpi::nt::ReadListenerQueue(poller);
|
||||
CheckEvents(events, handle, wpi::nt::EventFlags::kPublish);
|
||||
}
|
||||
|
||||
TEST_F(TopicListenerTest, DISABLED_PrefixPublishRemote) {
|
||||
@@ -241,47 +241,47 @@ TEST_F(TopicListenerTest, DISABLED_PrefixPublishRemote) {
|
||||
if (HasFatalFailure()) {
|
||||
return;
|
||||
}
|
||||
auto poller = nt::CreateListenerPoller(m_serverInst);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle =
|
||||
nt::AddPolledListener(poller, {{"/foo/"}}, nt::EventFlags::kPublish);
|
||||
wpi::nt::AddPolledListener(poller, {{"/foo/"}}, wpi::nt::EventFlags::kPublish);
|
||||
|
||||
PublishTopics(m_clientInst);
|
||||
|
||||
nt::Flush(m_clientInst);
|
||||
wpi::nt::Flush(m_clientInst);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = nt::ReadListenerQueue(poller);
|
||||
CheckEvents(events, handle, nt::EventFlags::kPublish);
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = wpi::nt::ReadListenerQueue(poller);
|
||||
CheckEvents(events, handle, wpi::nt::EventFlags::kPublish);
|
||||
}
|
||||
|
||||
TEST_F(TopicListenerTest, PrefixPublishImm) {
|
||||
PublishTopics(m_serverInst);
|
||||
|
||||
auto poller = nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle = nt::AddPolledListener(
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle = wpi::nt::AddPolledListener(
|
||||
poller, {{"/foo/"}},
|
||||
nt::EventFlags::kPublish | nt::EventFlags::kImmediate);
|
||||
wpi::nt::EventFlags::kPublish | wpi::nt::EventFlags::kImmediate);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = nt::ReadListenerQueue(poller);
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = wpi::nt::ReadListenerQueue(poller);
|
||||
CheckEvents(events, handle,
|
||||
nt::EventFlags::kPublish | nt::EventFlags::kImmediate);
|
||||
wpi::nt::EventFlags::kPublish | wpi::nt::EventFlags::kImmediate);
|
||||
}
|
||||
|
||||
TEST_F(TopicListenerTest, PrefixUnpublishPropsImm) {
|
||||
PublishTopics(m_serverInst);
|
||||
|
||||
auto poller = nt::CreateListenerPoller(m_serverInst);
|
||||
nt::AddPolledListener(poller, {{"/foo/"}},
|
||||
nt::EventFlags::kUnpublish |
|
||||
nt::EventFlags::kProperties |
|
||||
nt::EventFlags::kImmediate);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
wpi::nt::AddPolledListener(poller, {{"/foo/"}},
|
||||
wpi::nt::EventFlags::kUnpublish |
|
||||
wpi::nt::EventFlags::kProperties |
|
||||
wpi::nt::EventFlags::kImmediate);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_FALSE(wpi::WaitForObject(poller, 0.02, &timedOut));
|
||||
auto events = nt::ReadListenerQueue(poller);
|
||||
ASSERT_FALSE(wpi::util::WaitForObject(poller, 0.02, &timedOut));
|
||||
auto events = wpi::nt::ReadListenerQueue(poller);
|
||||
ASSERT_TRUE(events.empty());
|
||||
}
|
||||
|
||||
@@ -16,394 +16,394 @@ using ::testing::AnyNumber;
|
||||
using ::testing::IsNull;
|
||||
using ::testing::Return;
|
||||
|
||||
namespace nt {
|
||||
namespace wpi::nt {
|
||||
|
||||
// Test only local here; it's more reliable to mock the network
|
||||
class ValueListenerTest : public ::testing::Test {
|
||||
public:
|
||||
ValueListenerTest() : m_inst{nt::CreateInstance()} {}
|
||||
ValueListenerTest() : m_inst{wpi::nt::CreateInstance()} {}
|
||||
|
||||
~ValueListenerTest() override { nt::DestroyInstance(m_inst); }
|
||||
~ValueListenerTest() override { wpi::nt::DestroyInstance(m_inst); }
|
||||
|
||||
protected:
|
||||
NT_Inst m_inst;
|
||||
};
|
||||
|
||||
TEST_F(ValueListenerTest, MultiPollSub) {
|
||||
auto topic = nt::GetTopic(m_inst, "foo");
|
||||
auto pub = nt::Publish(topic, NT_DOUBLE, "double");
|
||||
auto sub = nt::Subscribe(topic, NT_DOUBLE, "double");
|
||||
auto topic = wpi::nt::GetTopic(m_inst, "foo");
|
||||
auto pub = wpi::nt::Publish(topic, NT_DOUBLE, "double");
|
||||
auto sub = wpi::nt::Subscribe(topic, NT_DOUBLE, "double");
|
||||
|
||||
auto poller1 = nt::CreateListenerPoller(m_inst);
|
||||
auto poller2 = nt::CreateListenerPoller(m_inst);
|
||||
auto poller3 = nt::CreateListenerPoller(m_inst);
|
||||
auto h1 = nt::AddPolledListener(poller1, sub, nt::EventFlags::kValueLocal);
|
||||
auto h2 = nt::AddPolledListener(poller2, sub, nt::EventFlags::kValueLocal);
|
||||
auto h3 = nt::AddPolledListener(poller3, sub, nt::EventFlags::kValueLocal);
|
||||
auto poller1 = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto poller2 = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto poller3 = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto h1 = wpi::nt::AddPolledListener(poller1, sub, wpi::nt::EventFlags::kValueLocal);
|
||||
auto h2 = wpi::nt::AddPolledListener(poller2, sub, wpi::nt::EventFlags::kValueLocal);
|
||||
auto h3 = wpi::nt::AddPolledListener(poller3, sub, wpi::nt::EventFlags::kValueLocal);
|
||||
|
||||
nt::SetDouble(pub, 0);
|
||||
wpi::nt::SetDouble(pub, 0);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller1, 1.0, &timedOut));
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller1, 1.0, &timedOut));
|
||||
ASSERT_FALSE(timedOut);
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller2, 1.0, &timedOut));
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller2, 1.0, &timedOut));
|
||||
ASSERT_FALSE(timedOut);
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller3, 1.0, &timedOut));
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller3, 1.0, &timedOut));
|
||||
ASSERT_FALSE(timedOut);
|
||||
auto results1 = nt::ReadListenerQueue(poller1);
|
||||
auto results2 = nt::ReadListenerQueue(poller2);
|
||||
auto results3 = nt::ReadListenerQueue(poller3);
|
||||
auto results1 = wpi::nt::ReadListenerQueue(poller1);
|
||||
auto results2 = wpi::nt::ReadListenerQueue(poller2);
|
||||
auto results3 = wpi::nt::ReadListenerQueue(poller3);
|
||||
|
||||
ASSERT_EQ(results1.size(), 1u);
|
||||
EXPECT_EQ(results1[0].flags, nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results1[0].flags, wpi::nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results1[0].listener, h1);
|
||||
auto valueData = results1[0].GetValueEventData();
|
||||
ASSERT_TRUE(valueData);
|
||||
EXPECT_EQ(valueData->subentry, sub);
|
||||
EXPECT_EQ(valueData->topic, topic);
|
||||
EXPECT_EQ(valueData->value, nt::Value::MakeDouble(0.0));
|
||||
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(0.0));
|
||||
|
||||
ASSERT_EQ(results2.size(), 1u);
|
||||
EXPECT_EQ(results2[0].flags, nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results2[0].flags, wpi::nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results2[0].listener, h2);
|
||||
valueData = results2[0].GetValueEventData();
|
||||
ASSERT_TRUE(valueData);
|
||||
EXPECT_EQ(valueData->subentry, sub);
|
||||
EXPECT_EQ(valueData->topic, topic);
|
||||
EXPECT_EQ(valueData->value, nt::Value::MakeDouble(0.0));
|
||||
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(0.0));
|
||||
|
||||
ASSERT_EQ(results3.size(), 1u);
|
||||
EXPECT_EQ(results3[0].flags, nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results3[0].flags, wpi::nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results3[0].listener, h3);
|
||||
valueData = results3[0].GetValueEventData();
|
||||
ASSERT_TRUE(valueData);
|
||||
EXPECT_EQ(valueData->subentry, sub);
|
||||
EXPECT_EQ(valueData->topic, topic);
|
||||
EXPECT_EQ(valueData->value, nt::Value::MakeDouble(0.0));
|
||||
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(0.0));
|
||||
}
|
||||
|
||||
TEST_F(ValueListenerTest, PollMultiSub) {
|
||||
auto topic = nt::GetTopic(m_inst, "foo");
|
||||
auto pub = nt::Publish(topic, NT_DOUBLE, "double");
|
||||
auto sub1 = nt::Subscribe(topic, NT_DOUBLE, "double");
|
||||
auto sub2 = nt::Subscribe(topic, NT_DOUBLE, "double");
|
||||
auto topic = wpi::nt::GetTopic(m_inst, "foo");
|
||||
auto pub = wpi::nt::Publish(topic, NT_DOUBLE, "double");
|
||||
auto sub1 = wpi::nt::Subscribe(topic, NT_DOUBLE, "double");
|
||||
auto sub2 = wpi::nt::Subscribe(topic, NT_DOUBLE, "double");
|
||||
|
||||
auto poller = nt::CreateListenerPoller(m_inst);
|
||||
auto h1 = nt::AddPolledListener(poller, sub1, nt::EventFlags::kValueLocal);
|
||||
auto h2 = nt::AddPolledListener(poller, sub2, nt::EventFlags::kValueLocal);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto h1 = wpi::nt::AddPolledListener(poller, sub1, wpi::nt::EventFlags::kValueLocal);
|
||||
auto h2 = wpi::nt::AddPolledListener(poller, sub2, wpi::nt::EventFlags::kValueLocal);
|
||||
|
||||
nt::SetDouble(pub, 0);
|
||||
wpi::nt::SetDouble(pub, 0);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
ASSERT_FALSE(timedOut);
|
||||
auto results = nt::ReadListenerQueue(poller);
|
||||
auto results = wpi::nt::ReadListenerQueue(poller);
|
||||
|
||||
ASSERT_EQ(results.size(), 2u);
|
||||
EXPECT_EQ(results[0].flags, nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[0].flags, wpi::nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[0].listener, h1);
|
||||
auto valueData = results[0].GetValueEventData();
|
||||
ASSERT_TRUE(valueData);
|
||||
EXPECT_EQ(valueData->subentry, sub1);
|
||||
EXPECT_EQ(valueData->topic, topic);
|
||||
EXPECT_EQ(valueData->value, nt::Value::MakeDouble(0.0));
|
||||
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(0.0));
|
||||
|
||||
EXPECT_EQ(results[1].flags, nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[1].flags, wpi::nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[1].listener, h2);
|
||||
valueData = results[1].GetValueEventData();
|
||||
ASSERT_TRUE(valueData);
|
||||
EXPECT_EQ(valueData->subentry, sub2);
|
||||
EXPECT_EQ(valueData->topic, topic);
|
||||
EXPECT_EQ(valueData->value, nt::Value::MakeDouble(0.0));
|
||||
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(0.0));
|
||||
}
|
||||
|
||||
TEST_F(ValueListenerTest, PollMultiSubTopic) {
|
||||
auto topic1 = nt::GetTopic(m_inst, "foo");
|
||||
auto topic2 = nt::GetTopic(m_inst, "bar");
|
||||
auto pub1 = nt::Publish(topic1, NT_DOUBLE, "double");
|
||||
auto pub2 = nt::Publish(topic2, NT_DOUBLE, "double");
|
||||
auto sub1 = nt::Subscribe(topic1, NT_DOUBLE, "double");
|
||||
auto sub2 = nt::Subscribe(topic2, NT_DOUBLE, "double");
|
||||
auto topic1 = wpi::nt::GetTopic(m_inst, "foo");
|
||||
auto topic2 = wpi::nt::GetTopic(m_inst, "bar");
|
||||
auto pub1 = wpi::nt::Publish(topic1, NT_DOUBLE, "double");
|
||||
auto pub2 = wpi::nt::Publish(topic2, NT_DOUBLE, "double");
|
||||
auto sub1 = wpi::nt::Subscribe(topic1, NT_DOUBLE, "double");
|
||||
auto sub2 = wpi::nt::Subscribe(topic2, NT_DOUBLE, "double");
|
||||
|
||||
auto poller = nt::CreateListenerPoller(m_inst);
|
||||
auto h1 = nt::AddPolledListener(poller, sub1, nt::EventFlags::kValueLocal);
|
||||
auto h2 = nt::AddPolledListener(poller, sub2, nt::EventFlags::kValueLocal);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto h1 = wpi::nt::AddPolledListener(poller, sub1, wpi::nt::EventFlags::kValueLocal);
|
||||
auto h2 = wpi::nt::AddPolledListener(poller, sub2, wpi::nt::EventFlags::kValueLocal);
|
||||
|
||||
nt::SetDouble(pub1, 0);
|
||||
nt::SetDouble(pub2, 1);
|
||||
wpi::nt::SetDouble(pub1, 0);
|
||||
wpi::nt::SetDouble(pub2, 1);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
ASSERT_FALSE(timedOut);
|
||||
auto results = nt::ReadListenerQueue(poller);
|
||||
auto results = wpi::nt::ReadListenerQueue(poller);
|
||||
|
||||
ASSERT_EQ(results.size(), 2u);
|
||||
EXPECT_EQ(results[0].flags, nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[0].flags, wpi::nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[0].listener, h1);
|
||||
auto valueData = results[0].GetValueEventData();
|
||||
ASSERT_TRUE(valueData);
|
||||
EXPECT_EQ(valueData->subentry, sub1);
|
||||
EXPECT_EQ(valueData->topic, topic1);
|
||||
EXPECT_EQ(valueData->value, nt::Value::MakeDouble(0.0));
|
||||
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(0.0));
|
||||
|
||||
EXPECT_EQ(results[1].flags, nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[1].flags, wpi::nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[1].listener, h2);
|
||||
valueData = results[1].GetValueEventData();
|
||||
ASSERT_TRUE(valueData);
|
||||
EXPECT_EQ(valueData->subentry, sub2);
|
||||
EXPECT_EQ(valueData->topic, topic2);
|
||||
EXPECT_EQ(valueData->value, nt::Value::MakeDouble(1.0));
|
||||
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(1.0));
|
||||
}
|
||||
|
||||
TEST_F(ValueListenerTest, PollSubMultiple) {
|
||||
auto topic1 = nt::GetTopic(m_inst, "foo/1");
|
||||
auto topic2 = nt::GetTopic(m_inst, "foo/2");
|
||||
auto pub1 = nt::Publish(topic1, NT_DOUBLE, "double");
|
||||
auto pub2 = nt::Publish(topic2, NT_DOUBLE, "double");
|
||||
auto sub = nt::SubscribeMultiple(m_inst, {{"foo"}});
|
||||
auto topic1 = wpi::nt::GetTopic(m_inst, "foo/1");
|
||||
auto topic2 = wpi::nt::GetTopic(m_inst, "foo/2");
|
||||
auto pub1 = wpi::nt::Publish(topic1, NT_DOUBLE, "double");
|
||||
auto pub2 = wpi::nt::Publish(topic2, NT_DOUBLE, "double");
|
||||
auto sub = wpi::nt::SubscribeMultiple(m_inst, {{"foo"}});
|
||||
|
||||
auto poller = nt::CreateListenerPoller(m_inst);
|
||||
auto h = nt::AddPolledListener(poller, sub, nt::EventFlags::kValueLocal);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto h = wpi::nt::AddPolledListener(poller, sub, wpi::nt::EventFlags::kValueLocal);
|
||||
|
||||
nt::SetDouble(pub1, 0);
|
||||
nt::SetDouble(pub2, 1);
|
||||
wpi::nt::SetDouble(pub1, 0);
|
||||
wpi::nt::SetDouble(pub2, 1);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
ASSERT_FALSE(timedOut);
|
||||
auto results = nt::ReadListenerQueue(poller);
|
||||
auto results = wpi::nt::ReadListenerQueue(poller);
|
||||
|
||||
ASSERT_EQ(results.size(), 2u);
|
||||
EXPECT_EQ(results[0].flags, nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[0].flags, wpi::nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[0].listener, h);
|
||||
auto valueData = results[0].GetValueEventData();
|
||||
ASSERT_TRUE(valueData);
|
||||
EXPECT_EQ(valueData->subentry, sub);
|
||||
EXPECT_EQ(valueData->topic, topic1);
|
||||
EXPECT_EQ(valueData->value, nt::Value::MakeDouble(0.0));
|
||||
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(0.0));
|
||||
|
||||
EXPECT_EQ(results[1].flags, nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[1].flags, wpi::nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[1].listener, h);
|
||||
valueData = results[1].GetValueEventData();
|
||||
ASSERT_TRUE(valueData);
|
||||
EXPECT_EQ(valueData->subentry, sub);
|
||||
EXPECT_EQ(valueData->topic, topic2);
|
||||
EXPECT_EQ(valueData->value, nt::Value::MakeDouble(1.0));
|
||||
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(1.0));
|
||||
}
|
||||
|
||||
TEST_F(ValueListenerTest, PollSubPrefixCreated) {
|
||||
auto poller = nt::CreateListenerPoller(m_inst);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto h =
|
||||
nt::AddPolledListener(poller, {{"foo"}}, nt::EventFlags::kValueLocal);
|
||||
wpi::nt::AddPolledListener(poller, {{"foo"}}, wpi::nt::EventFlags::kValueLocal);
|
||||
|
||||
auto topic1 = nt::GetTopic(m_inst, "foo/1");
|
||||
auto topic2 = nt::GetTopic(m_inst, "foo/2");
|
||||
auto topic3 = nt::GetTopic(m_inst, "bar/3");
|
||||
auto pub1 = nt::Publish(topic1, NT_DOUBLE, "double");
|
||||
auto pub2 = nt::Publish(topic2, NT_DOUBLE, "double");
|
||||
auto pub3 = nt::Publish(topic3, NT_DOUBLE, "double");
|
||||
auto topic1 = wpi::nt::GetTopic(m_inst, "foo/1");
|
||||
auto topic2 = wpi::nt::GetTopic(m_inst, "foo/2");
|
||||
auto topic3 = wpi::nt::GetTopic(m_inst, "bar/3");
|
||||
auto pub1 = wpi::nt::Publish(topic1, NT_DOUBLE, "double");
|
||||
auto pub2 = wpi::nt::Publish(topic2, NT_DOUBLE, "double");
|
||||
auto pub3 = wpi::nt::Publish(topic3, NT_DOUBLE, "double");
|
||||
|
||||
nt::SetDouble(pub1, 0);
|
||||
nt::SetDouble(pub2, 1);
|
||||
nt::SetDouble(pub3, 1);
|
||||
wpi::nt::SetDouble(pub1, 0);
|
||||
wpi::nt::SetDouble(pub2, 1);
|
||||
wpi::nt::SetDouble(pub3, 1);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
ASSERT_FALSE(timedOut);
|
||||
auto results = nt::ReadListenerQueue(poller);
|
||||
auto results = wpi::nt::ReadListenerQueue(poller);
|
||||
|
||||
ASSERT_EQ(results.size(), 2u);
|
||||
EXPECT_EQ(results[0].flags, nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[0].flags, wpi::nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[0].listener, h);
|
||||
auto valueData = results[0].GetValueEventData();
|
||||
ASSERT_TRUE(valueData);
|
||||
EXPECT_EQ(valueData->topic, topic1);
|
||||
EXPECT_EQ(valueData->value, nt::Value::MakeDouble(0.0));
|
||||
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(0.0));
|
||||
|
||||
EXPECT_EQ(results[1].flags, nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[1].flags, wpi::nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[1].listener, h);
|
||||
valueData = results[1].GetValueEventData();
|
||||
ASSERT_TRUE(valueData);
|
||||
EXPECT_EQ(valueData->topic, topic2);
|
||||
EXPECT_EQ(valueData->value, nt::Value::MakeDouble(1.0));
|
||||
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(1.0));
|
||||
}
|
||||
|
||||
TEST_F(ValueListenerTest, PollEntry) {
|
||||
auto entry = nt::GetEntry(m_inst, "foo");
|
||||
auto entry = wpi::nt::GetEntry(m_inst, "foo");
|
||||
|
||||
auto poller = nt::CreateListenerPoller(m_inst);
|
||||
auto h = nt::AddPolledListener(poller, entry, nt::EventFlags::kValueLocal);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto h = wpi::nt::AddPolledListener(poller, entry, wpi::nt::EventFlags::kValueLocal);
|
||||
|
||||
ASSERT_TRUE(nt::SetDouble(entry, 0));
|
||||
ASSERT_TRUE(wpi::nt::SetDouble(entry, 0));
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
ASSERT_FALSE(timedOut);
|
||||
auto results = nt::ReadListenerQueue(poller);
|
||||
auto results = wpi::nt::ReadListenerQueue(poller);
|
||||
|
||||
ASSERT_EQ(results.size(), 1u);
|
||||
EXPECT_EQ(results[0].flags, nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[0].flags, wpi::nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[0].listener, h);
|
||||
auto valueData = results[0].GetValueEventData();
|
||||
ASSERT_TRUE(valueData);
|
||||
EXPECT_EQ(valueData->subentry, entry);
|
||||
EXPECT_EQ(valueData->topic, nt::GetTopic(m_inst, "foo"));
|
||||
EXPECT_EQ(valueData->value, nt::Value::MakeDouble(0.0));
|
||||
EXPECT_EQ(valueData->topic, wpi::nt::GetTopic(m_inst, "foo"));
|
||||
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(0.0));
|
||||
}
|
||||
|
||||
TEST_F(ValueListenerTest, PollImmediate) {
|
||||
auto entry = nt::GetEntry(m_inst, "foo");
|
||||
ASSERT_TRUE(nt::SetDouble(entry, 0));
|
||||
auto entry = wpi::nt::GetEntry(m_inst, "foo");
|
||||
ASSERT_TRUE(wpi::nt::SetDouble(entry, 0));
|
||||
|
||||
auto poller = nt::CreateListenerPoller(m_inst);
|
||||
auto h = nt::AddPolledListener(
|
||||
poller, entry, nt::EventFlags::kValueLocal | nt::EventFlags::kImmediate);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto h = wpi::nt::AddPolledListener(
|
||||
poller, entry, wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
ASSERT_FALSE(timedOut);
|
||||
auto results = nt::ReadListenerQueue(poller);
|
||||
auto results = wpi::nt::ReadListenerQueue(poller);
|
||||
|
||||
ASSERT_EQ(results.size(), 1u);
|
||||
EXPECT_EQ(results[0].flags &
|
||||
(nt::EventFlags::kValueLocal | nt::EventFlags::kImmediate),
|
||||
nt::EventFlags::kValueLocal | nt::EventFlags::kImmediate);
|
||||
(wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate),
|
||||
wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
|
||||
EXPECT_EQ(results[0].listener, h);
|
||||
auto valueData = results[0].GetValueEventData();
|
||||
ASSERT_TRUE(valueData);
|
||||
EXPECT_EQ(valueData->subentry, entry);
|
||||
EXPECT_EQ(valueData->topic, nt::GetTopic(m_inst, "foo"));
|
||||
EXPECT_EQ(valueData->value, nt::Value::MakeDouble(0.0));
|
||||
EXPECT_EQ(valueData->topic, wpi::nt::GetTopic(m_inst, "foo"));
|
||||
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(0.0));
|
||||
}
|
||||
|
||||
TEST_F(ValueListenerTest, PollImmediateNoValue) {
|
||||
auto entry = nt::GetEntry(m_inst, "foo");
|
||||
auto entry = wpi::nt::GetEntry(m_inst, "foo");
|
||||
|
||||
auto poller = nt::CreateListenerPoller(m_inst);
|
||||
auto h = nt::AddPolledListener(
|
||||
poller, entry, nt::EventFlags::kValueLocal | nt::EventFlags::kImmediate);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto h = wpi::nt::AddPolledListener(
|
||||
poller, entry, wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_FALSE(wpi::WaitForObject(poller, 0.02, &timedOut));
|
||||
ASSERT_FALSE(wpi::util::WaitForObject(poller, 0.02, &timedOut));
|
||||
ASSERT_TRUE(timedOut);
|
||||
auto results = nt::ReadListenerQueue(poller);
|
||||
auto results = wpi::nt::ReadListenerQueue(poller);
|
||||
ASSERT_TRUE(results.empty());
|
||||
|
||||
// now set a value
|
||||
ASSERT_TRUE(nt::SetDouble(entry, 0));
|
||||
ASSERT_TRUE(wpi::nt::SetDouble(entry, 0));
|
||||
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
results = nt::ReadListenerQueue(poller);
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
results = wpi::nt::ReadListenerQueue(poller);
|
||||
ASSERT_FALSE(timedOut);
|
||||
|
||||
ASSERT_EQ(results.size(), 1u);
|
||||
EXPECT_EQ(results[0].flags, nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[0].flags, wpi::nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[0].listener, h);
|
||||
auto valueData = results[0].GetValueEventData();
|
||||
ASSERT_TRUE(valueData);
|
||||
EXPECT_EQ(valueData->subentry, entry);
|
||||
EXPECT_EQ(valueData->topic, nt::GetTopic(m_inst, "foo"));
|
||||
EXPECT_EQ(valueData->value, nt::Value::MakeDouble(0.0));
|
||||
EXPECT_EQ(valueData->topic, wpi::nt::GetTopic(m_inst, "foo"));
|
||||
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(0.0));
|
||||
}
|
||||
|
||||
TEST_F(ValueListenerTest, PollImmediateSubMultiple) {
|
||||
auto topic1 = nt::GetTopic(m_inst, "foo/1");
|
||||
auto topic2 = nt::GetTopic(m_inst, "foo/2");
|
||||
auto pub1 = nt::Publish(topic1, NT_DOUBLE, "double");
|
||||
auto pub2 = nt::Publish(topic2, NT_DOUBLE, "double");
|
||||
auto sub = nt::SubscribeMultiple(m_inst, {{"foo"}});
|
||||
nt::SetDouble(pub1, 0);
|
||||
nt::SetDouble(pub2, 1);
|
||||
auto topic1 = wpi::nt::GetTopic(m_inst, "foo/1");
|
||||
auto topic2 = wpi::nt::GetTopic(m_inst, "foo/2");
|
||||
auto pub1 = wpi::nt::Publish(topic1, NT_DOUBLE, "double");
|
||||
auto pub2 = wpi::nt::Publish(topic2, NT_DOUBLE, "double");
|
||||
auto sub = wpi::nt::SubscribeMultiple(m_inst, {{"foo"}});
|
||||
wpi::nt::SetDouble(pub1, 0);
|
||||
wpi::nt::SetDouble(pub2, 1);
|
||||
|
||||
auto poller = nt::CreateListenerPoller(m_inst);
|
||||
auto h = nt::AddPolledListener(
|
||||
poller, sub, nt::EventFlags::kValueLocal | nt::EventFlags::kImmediate);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto h = wpi::nt::AddPolledListener(
|
||||
poller, sub, wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
ASSERT_FALSE(timedOut);
|
||||
auto results = nt::ReadListenerQueue(poller);
|
||||
auto results = wpi::nt::ReadListenerQueue(poller);
|
||||
|
||||
ASSERT_EQ(results.size(), 2u);
|
||||
EXPECT_EQ(results[0].flags &
|
||||
(nt::EventFlags::kValueLocal | nt::EventFlags::kImmediate),
|
||||
nt::EventFlags::kValueLocal | nt::EventFlags::kImmediate);
|
||||
(wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate),
|
||||
wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
|
||||
EXPECT_EQ(results[0].listener, h);
|
||||
auto valueData = results[0].GetValueEventData();
|
||||
ASSERT_TRUE(valueData);
|
||||
EXPECT_EQ(valueData->subentry, sub);
|
||||
EXPECT_EQ(valueData->topic, topic1);
|
||||
EXPECT_EQ(valueData->value, nt::Value::MakeDouble(0.0));
|
||||
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(0.0));
|
||||
|
||||
EXPECT_EQ(results[1].flags &
|
||||
(nt::EventFlags::kValueLocal | nt::EventFlags::kImmediate),
|
||||
nt::EventFlags::kValueLocal | nt::EventFlags::kImmediate);
|
||||
(wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate),
|
||||
wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
|
||||
EXPECT_EQ(results[1].listener, h);
|
||||
valueData = results[1].GetValueEventData();
|
||||
ASSERT_TRUE(valueData);
|
||||
EXPECT_EQ(valueData->subentry, sub);
|
||||
EXPECT_EQ(valueData->topic, topic2);
|
||||
EXPECT_EQ(valueData->value, nt::Value::MakeDouble(1.0));
|
||||
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(1.0));
|
||||
}
|
||||
|
||||
TEST_F(ValueListenerTest, TwoSubOneListener) {
|
||||
auto topic = nt::GetTopic(m_inst, "foo");
|
||||
auto pub = nt::Publish(topic, NT_DOUBLE, "double");
|
||||
auto sub1 = nt::Subscribe(topic, NT_DOUBLE, "double");
|
||||
auto sub2 = nt::Subscribe(topic, NT_DOUBLE, "double");
|
||||
auto sub3 = nt::SubscribeMultiple(m_inst, {{"foo"}});
|
||||
auto topic = wpi::nt::GetTopic(m_inst, "foo");
|
||||
auto pub = wpi::nt::Publish(topic, NT_DOUBLE, "double");
|
||||
auto sub1 = wpi::nt::Subscribe(topic, NT_DOUBLE, "double");
|
||||
auto sub2 = wpi::nt::Subscribe(topic, NT_DOUBLE, "double");
|
||||
auto sub3 = wpi::nt::SubscribeMultiple(m_inst, {{"foo"}});
|
||||
|
||||
auto poller = nt::CreateListenerPoller(m_inst);
|
||||
auto h = nt::AddPolledListener(poller, sub1, nt::EventFlags::kValueLocal);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto h = wpi::nt::AddPolledListener(poller, sub1, wpi::nt::EventFlags::kValueLocal);
|
||||
(void)sub2;
|
||||
(void)sub3;
|
||||
|
||||
nt::SetDouble(pub, 0);
|
||||
wpi::nt::SetDouble(pub, 0);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
ASSERT_FALSE(timedOut);
|
||||
auto results = nt::ReadListenerQueue(poller);
|
||||
auto results = wpi::nt::ReadListenerQueue(poller);
|
||||
|
||||
ASSERT_EQ(results.size(), 1u);
|
||||
EXPECT_EQ(results[0].flags & nt::EventFlags::kValueLocal,
|
||||
nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[0].flags & wpi::nt::EventFlags::kValueLocal,
|
||||
wpi::nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[0].listener, h);
|
||||
auto valueData = results[0].GetValueEventData();
|
||||
ASSERT_TRUE(valueData);
|
||||
EXPECT_EQ(valueData->subentry, sub1);
|
||||
EXPECT_EQ(valueData->topic, topic);
|
||||
EXPECT_EQ(valueData->value, nt::Value::MakeDouble(0.0));
|
||||
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(0.0));
|
||||
}
|
||||
|
||||
TEST_F(ValueListenerTest, TwoSubOneMultiListener) {
|
||||
auto topic = nt::GetTopic(m_inst, "foo");
|
||||
auto pub = nt::Publish(topic, NT_DOUBLE, "double");
|
||||
auto sub1 = nt::Subscribe(topic, NT_DOUBLE, "double");
|
||||
auto sub2 = nt::Subscribe(topic, NT_DOUBLE, "double");
|
||||
auto sub3 = nt::SubscribeMultiple(m_inst, {{"foo"}});
|
||||
auto topic = wpi::nt::GetTopic(m_inst, "foo");
|
||||
auto pub = wpi::nt::Publish(topic, NT_DOUBLE, "double");
|
||||
auto sub1 = wpi::nt::Subscribe(topic, NT_DOUBLE, "double");
|
||||
auto sub2 = wpi::nt::Subscribe(topic, NT_DOUBLE, "double");
|
||||
auto sub3 = wpi::nt::SubscribeMultiple(m_inst, {{"foo"}});
|
||||
|
||||
auto poller = nt::CreateListenerPoller(m_inst);
|
||||
auto h = nt::AddPolledListener(poller, sub3, nt::EventFlags::kValueLocal);
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto h = wpi::nt::AddPolledListener(poller, sub3, wpi::nt::EventFlags::kValueLocal);
|
||||
(void)sub1;
|
||||
(void)sub2;
|
||||
|
||||
nt::SetDouble(pub, 0);
|
||||
wpi::nt::SetDouble(pub, 0);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::WaitForObject(poller, 1.0, &timedOut));
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
ASSERT_FALSE(timedOut);
|
||||
auto results = nt::ReadListenerQueue(poller);
|
||||
auto results = wpi::nt::ReadListenerQueue(poller);
|
||||
|
||||
ASSERT_EQ(results.size(), 1u);
|
||||
EXPECT_EQ(results[0].flags & nt::EventFlags::kValueLocal,
|
||||
nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[0].flags & wpi::nt::EventFlags::kValueLocal,
|
||||
wpi::nt::EventFlags::kValueLocal);
|
||||
EXPECT_EQ(results[0].listener, h);
|
||||
auto valueData = results[0].GetValueEventData();
|
||||
ASSERT_TRUE(valueData);
|
||||
EXPECT_EQ(valueData->subentry, sub3);
|
||||
EXPECT_EQ(valueData->topic, topic);
|
||||
EXPECT_EQ(valueData->value, nt::Value::MakeDouble(0.0));
|
||||
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(0.0));
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
} // namespace wpi::nt
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include "TestPrinters.hpp"
|
||||
|
||||
namespace nt {
|
||||
namespace wpi::nt {
|
||||
|
||||
bool ValueMatcher::MatchAndExplain(
|
||||
Value val, ::testing::MatchResultListener* listener) const {
|
||||
@@ -26,4 +26,4 @@ void ValueMatcher::DescribeNegationTo(::std::ostream* os) const {
|
||||
PrintTo(goodval, os);
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
} // namespace wpi::nt
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "gmock/gmock.h"
|
||||
#include "wpi/nt/NetworkTableValue.hpp"
|
||||
|
||||
namespace nt {
|
||||
namespace wpi::nt {
|
||||
|
||||
class ValueMatcher : public ::testing::MatcherInterface<Value> {
|
||||
public:
|
||||
@@ -30,4 +30,4 @@ inline ::testing::Matcher<Value> ValueEq(const Value& goodval) {
|
||||
return ::testing::MakeMatcher(new ValueMatcher(goodval));
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
} // namespace wpi::nt
|
||||
|
||||
@@ -26,7 +26,7 @@ inline bool operator==(std::span<T> lhs, std::span<U> rhs) {
|
||||
}
|
||||
} // namespace std
|
||||
|
||||
namespace nt {
|
||||
namespace wpi::nt {
|
||||
|
||||
class ValueTest : public ::testing::Test {};
|
||||
|
||||
@@ -87,7 +87,7 @@ TEST_F(ValueTest, String) {
|
||||
NT_InitValue(&cv);
|
||||
ConvertToC(v, &cv);
|
||||
ASSERT_EQ(NT_STRING, cv.type);
|
||||
ASSERT_EQ("hello"sv, wpi::to_string_view(&cv.data.v_string));
|
||||
ASSERT_EQ("hello"sv, wpi::util::to_string_view(&cv.data.v_string));
|
||||
ASSERT_EQ(5u, cv.data.v_string.len);
|
||||
|
||||
v = Value::MakeString("goodbye");
|
||||
@@ -96,7 +96,7 @@ TEST_F(ValueTest, String) {
|
||||
NT_DisposeValue(&cv);
|
||||
ConvertToC(v, &cv);
|
||||
ASSERT_EQ(NT_STRING, cv.type);
|
||||
ASSERT_EQ("goodbye"sv, wpi::to_string_view(&cv.data.v_string));
|
||||
ASSERT_EQ("goodbye"sv, wpi::util::to_string_view(&cv.data.v_string));
|
||||
ASSERT_EQ(7u, cv.data.v_string.len);
|
||||
|
||||
NT_DisposeValue(&cv);
|
||||
@@ -229,9 +229,9 @@ TEST_F(ValueTest, StringArray) {
|
||||
ConvertToC(v, &cv);
|
||||
ASSERT_EQ(NT_STRING_ARRAY, cv.type);
|
||||
ASSERT_EQ(3u, cv.data.arr_string.size);
|
||||
ASSERT_EQ("hello"sv, wpi::to_string_view(&cv.data.arr_string.arr[0]));
|
||||
ASSERT_EQ("goodbye"sv, wpi::to_string_view(&cv.data.arr_string.arr[1]));
|
||||
ASSERT_EQ("string"sv, wpi::to_string_view(&cv.data.arr_string.arr[2]));
|
||||
ASSERT_EQ("hello"sv, wpi::util::to_string_view(&cv.data.arr_string.arr[0]));
|
||||
ASSERT_EQ("goodbye"sv, wpi::util::to_string_view(&cv.data.arr_string.arr[1]));
|
||||
ASSERT_EQ("string"sv, wpi::util::to_string_view(&cv.data.arr_string.arr[2]));
|
||||
|
||||
// assign with same size
|
||||
vec.clear();
|
||||
@@ -248,9 +248,9 @@ TEST_F(ValueTest, StringArray) {
|
||||
ConvertToC(v, &cv);
|
||||
ASSERT_EQ(NT_STRING_ARRAY, cv.type);
|
||||
ASSERT_EQ(3u, cv.data.arr_string.size);
|
||||
ASSERT_EQ("s1"sv, wpi::to_string_view(&cv.data.arr_string.arr[0]));
|
||||
ASSERT_EQ("str2"sv, wpi::to_string_view(&cv.data.arr_string.arr[1]));
|
||||
ASSERT_EQ("string3"sv, wpi::to_string_view(&cv.data.arr_string.arr[2]));
|
||||
ASSERT_EQ("s1"sv, wpi::util::to_string_view(&cv.data.arr_string.arr[0]));
|
||||
ASSERT_EQ("str2"sv, wpi::util::to_string_view(&cv.data.arr_string.arr[1]));
|
||||
ASSERT_EQ("string3"sv, wpi::util::to_string_view(&cv.data.arr_string.arr[2]));
|
||||
|
||||
// assign with different size
|
||||
vec.clear();
|
||||
@@ -265,8 +265,8 @@ TEST_F(ValueTest, StringArray) {
|
||||
ConvertToC(v, &cv);
|
||||
ASSERT_EQ(NT_STRING_ARRAY, cv.type);
|
||||
ASSERT_EQ(2u, cv.data.arr_string.size);
|
||||
ASSERT_EQ("short"sv, wpi::to_string_view(&cv.data.arr_string.arr[0]));
|
||||
ASSERT_EQ("er"sv, wpi::to_string_view(&cv.data.arr_string.arr[1]));
|
||||
ASSERT_EQ("short"sv, wpi::util::to_string_view(&cv.data.arr_string.arr[0]));
|
||||
ASSERT_EQ("er"sv, wpi::util::to_string_view(&cv.data.arr_string.arr[1]));
|
||||
|
||||
NT_DisposeValue(&cv);
|
||||
}
|
||||
@@ -463,4 +463,4 @@ TEST_F(ValueTest, StringArrayComparison) {
|
||||
ASSERT_EQ(v1, v2);
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
} // namespace wpi::nt
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "wpi/util/timestamp.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
nt::AddLogger(nt::GetDefaultInstance(), 0, UINT_MAX, [](auto& event) {
|
||||
wpi::nt::AddLogger(wpi::nt::GetDefaultInstance(), 0, UINT_MAX, [](auto& event) {
|
||||
if (auto msg = event.GetLogMessage()) {
|
||||
std::fputs(msg->message.c_str(), stderr);
|
||||
std::fputc('\n', stderr);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "net/ClientMessageQueue.hpp"
|
||||
#include "net/Message.hpp"
|
||||
|
||||
namespace nt::net {
|
||||
namespace wpi::nt::net {
|
||||
|
||||
class MockClientMessageQueue : public net::ClientMessageQueue {
|
||||
public:
|
||||
@@ -30,4 +30,4 @@ class MockClientMessageQueue : public net::ClientMessageQueue {
|
||||
std::vector<ClientMessage> msgs;
|
||||
};
|
||||
|
||||
} // namespace nt::net
|
||||
} // namespace wpi::nt::net
|
||||
|
||||
@@ -11,17 +11,17 @@
|
||||
#include "net/MessageHandler.hpp"
|
||||
#include "wpi/util/json.hpp"
|
||||
|
||||
namespace nt::net {
|
||||
namespace wpi::nt::net {
|
||||
|
||||
class MockClientMessageHandler : public net::ClientMessageHandler {
|
||||
public:
|
||||
MOCK_METHOD(void, ClientPublish,
|
||||
(int pubuid, std::string_view name, std::string_view typeStr,
|
||||
const wpi::json& properties, const PubSubOptionsImpl& options),
|
||||
const wpi::util::json& properties, const PubSubOptionsImpl& options),
|
||||
(override));
|
||||
MOCK_METHOD(void, ClientUnpublish, (int pubuid), (override));
|
||||
MOCK_METHOD(void, ClientSetProperties,
|
||||
(std::string_view name, const wpi::json& update), (override));
|
||||
(std::string_view name, const wpi::util::json& update), (override));
|
||||
MOCK_METHOD(void, ClientSubscribe,
|
||||
(int subuid, std::span<const std::string> prefixes,
|
||||
const PubSubOptionsImpl& options),
|
||||
@@ -35,15 +35,15 @@ class MockServerMessageHandler : public net::ServerMessageHandler {
|
||||
public:
|
||||
MOCK_METHOD(int, ServerAnnounce,
|
||||
(std::string_view name, int id, std::string_view typeStr,
|
||||
const wpi::json& properties, std::optional<int> pubuid),
|
||||
const wpi::util::json& properties, std::optional<int> pubuid),
|
||||
(override));
|
||||
MOCK_METHOD(void, ServerUnannounce, (std::string_view name, int id),
|
||||
(override));
|
||||
MOCK_METHOD(void, ServerPropertiesUpdate,
|
||||
(std::string_view name, const wpi::json& update, bool ack),
|
||||
(std::string_view name, const wpi::util::json& update, bool ack),
|
||||
(override));
|
||||
MOCK_METHOD(void, ServerSetValue, (int topicuid, const Value& value),
|
||||
(override));
|
||||
};
|
||||
|
||||
} // namespace nt::net
|
||||
} // namespace wpi::nt::net
|
||||
|
||||
@@ -8,18 +8,18 @@
|
||||
#include "net/NetworkInterface.hpp"
|
||||
#include "wpi/util/json.hpp"
|
||||
|
||||
namespace nt::net {
|
||||
namespace wpi::nt::net {
|
||||
|
||||
class MockLocalStorage : public ILocalStorage {
|
||||
public:
|
||||
MOCK_METHOD(int, ServerAnnounce,
|
||||
(std::string_view name, int id, std::string_view typeStr,
|
||||
const wpi::json& properties, std::optional<int> pubuid),
|
||||
const wpi::util::json& properties, std::optional<int> pubuid),
|
||||
(override));
|
||||
MOCK_METHOD(void, ServerUnannounce, (std::string_view name, int id),
|
||||
(override));
|
||||
MOCK_METHOD(void, ServerPropertiesUpdate,
|
||||
(std::string_view name, const wpi::json& update, bool ack),
|
||||
(std::string_view name, const wpi::util::json& update, bool ack),
|
||||
(override));
|
||||
MOCK_METHOD(void, ServerSetValue, (int topicId, const Value& value),
|
||||
(override));
|
||||
@@ -27,4 +27,4 @@ class MockLocalStorage : public ILocalStorage {
|
||||
MOCK_METHOD(void, ClearNetwork, (), (override));
|
||||
};
|
||||
|
||||
} // namespace nt::net
|
||||
} // namespace wpi::nt::net
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "net/WireConnection.hpp"
|
||||
#include "wpi/util/raw_ostream.hpp"
|
||||
|
||||
namespace nt::net {
|
||||
namespace wpi::nt::net {
|
||||
|
||||
class MockWireConnection : public WireConnection {
|
||||
public:
|
||||
@@ -25,30 +25,30 @@ class MockWireConnection : public WireConnection {
|
||||
|
||||
MOCK_METHOD(bool, Ready, (), (const, override));
|
||||
|
||||
int WriteText(wpi::function_ref<void(wpi::raw_ostream& os)> writer) override {
|
||||
int WriteText(wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) override {
|
||||
std::string text;
|
||||
wpi::raw_string_ostream os{text};
|
||||
wpi::util::raw_string_ostream os{text};
|
||||
writer(os);
|
||||
return DoWriteText(text);
|
||||
}
|
||||
int WriteBinary(
|
||||
wpi::function_ref<void(wpi::raw_ostream& os)> writer) override {
|
||||
wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) override {
|
||||
std::vector<uint8_t> binary;
|
||||
wpi::raw_uvector_ostream os{binary};
|
||||
wpi::util::raw_uvector_ostream os{binary};
|
||||
writer(os);
|
||||
return DoWriteBinary(binary);
|
||||
}
|
||||
|
||||
void SendText(wpi::function_ref<void(wpi::raw_ostream& os)> writer) override {
|
||||
void SendText(wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) override {
|
||||
std::string text;
|
||||
wpi::raw_string_ostream os{text};
|
||||
wpi::util::raw_string_ostream os{text};
|
||||
writer(os);
|
||||
DoSendText(text);
|
||||
}
|
||||
void SendBinary(
|
||||
wpi::function_ref<void(wpi::raw_ostream& os)> writer) override {
|
||||
wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) override {
|
||||
std::vector<uint8_t> binary;
|
||||
wpi::raw_uvector_ostream os{binary};
|
||||
wpi::util::raw_uvector_ostream os{binary};
|
||||
writer(os);
|
||||
DoSendBinary(binary);
|
||||
}
|
||||
@@ -70,4 +70,4 @@ class MockWireConnection : public WireConnection {
|
||||
MOCK_METHOD(void, Disconnect, (std::string_view reason), (override));
|
||||
};
|
||||
|
||||
} // namespace nt::net
|
||||
} // namespace wpi::nt::net
|
||||
|
||||
@@ -23,7 +23,7 @@ using testing::_;
|
||||
using testing::MockFunction;
|
||||
using testing::StrictMock;
|
||||
|
||||
namespace nt {
|
||||
namespace wpi::nt {
|
||||
|
||||
class WireDecodeTextClientTest : public ::testing::Test {
|
||||
public:
|
||||
@@ -110,7 +110,7 @@ TEST_F(WireDecodeTextClientTest, ErrorUnknownMethod) {
|
||||
TEST_F(WireDecodeTextClientTest, PublishPropsEmpty) {
|
||||
EXPECT_CALL(handler, ClientPublish(5, std::string_view{"test"},
|
||||
std::string_view{"double"},
|
||||
wpi::json::object(), PubSubOptionsEq({})));
|
||||
wpi::util::json::object(), PubSubOptionsEq({})));
|
||||
net::WireDecodeText(
|
||||
"[{\"method\":\"publish\",\"params\":{"
|
||||
"\"name\":\"test\",\"properties\":{},\"pubuid\":5,\"type\":\"double\"}}]",
|
||||
@@ -118,7 +118,7 @@ TEST_F(WireDecodeTextClientTest, PublishPropsEmpty) {
|
||||
|
||||
EXPECT_CALL(handler, ClientPublish(5, std::string_view{"test"},
|
||||
std::string_view{"double"},
|
||||
wpi::json::object(), PubSubOptionsEq({})));
|
||||
wpi::util::json::object(), PubSubOptionsEq({})));
|
||||
net::WireDecodeText(
|
||||
"[{\"method\":\"publish\",\"params\":{"
|
||||
"\"name\":\"test\",\"pubuid\":5,\"type\":\"double\"}}]",
|
||||
@@ -126,7 +126,7 @@ TEST_F(WireDecodeTextClientTest, PublishPropsEmpty) {
|
||||
}
|
||||
|
||||
TEST_F(WireDecodeTextClientTest, PublishProps) {
|
||||
wpi::json props = {{"k", 6}};
|
||||
wpi::util::json props = {{"k", 6}};
|
||||
EXPECT_CALL(handler, ClientPublish(5, std::string_view{"test"},
|
||||
std::string_view{"double"}, props,
|
||||
PubSubOptionsEq({})));
|
||||
@@ -192,4 +192,4 @@ TEST_F(WireDecodeTextClientTest, UnpublishError) {
|
||||
logger);
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
} // namespace wpi::nt
|
||||
|
||||
@@ -22,23 +22,23 @@
|
||||
|
||||
using namespace std::string_view_literals;
|
||||
|
||||
namespace nt {
|
||||
namespace wpi::nt {
|
||||
|
||||
class WireEncoderTextTest : public ::testing::Test {
|
||||
protected:
|
||||
std::string out;
|
||||
wpi::raw_string_ostream os{out};
|
||||
wpi::json GetJson() { return wpi::json::parse(os.str()); }
|
||||
wpi::util::raw_string_ostream os{out};
|
||||
wpi::util::json GetJson() { return wpi::util::json::parse(os.str()); }
|
||||
};
|
||||
|
||||
class WireEncoderBinaryTest : public ::testing::Test {
|
||||
protected:
|
||||
std::vector<uint8_t> out;
|
||||
wpi::raw_uvector_ostream os{out};
|
||||
wpi::util::raw_uvector_ostream os{out};
|
||||
};
|
||||
|
||||
TEST_F(WireEncoderTextTest, PublishPropsEmpty) {
|
||||
net::WireEncodePublish(os, 5, "test", "double", wpi::json::object());
|
||||
net::WireEncodePublish(os, 5, "test", "double", wpi::util::json::object());
|
||||
ASSERT_EQ(
|
||||
os.str(),
|
||||
"{\"method\":\"publish\",\"params\":{"
|
||||
@@ -113,7 +113,7 @@ TEST_F(WireEncoderTextTest, Unsubscribe) {
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderTextTest, Announce) {
|
||||
net::WireEncodeAnnounce(os, "test", 5, "double", wpi::json::object(),
|
||||
net::WireEncodeAnnounce(os, "test", 5, "double", wpi::util::json::object(),
|
||||
std::nullopt);
|
||||
ASSERT_EQ(os.str(),
|
||||
"{\"method\":\"announce\",\"params\":{\"id\":5,\"name\":\"test\","
|
||||
@@ -128,7 +128,7 @@ TEST_F(WireEncoderTextTest, AnnounceProperties) {
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderTextTest, AnnouncePubuid) {
|
||||
net::WireEncodeAnnounce(os, "test", 5, "double", wpi::json::object(), 6);
|
||||
net::WireEncodeAnnounce(os, "test", 5, "double", wpi::util::json::object(), 6);
|
||||
ASSERT_EQ(os.str(),
|
||||
"{\"method\":\"announce\",\"params\":{\"id\":5,\"name\":\"test\","
|
||||
"\"properties\":{},\"pubuid\":6,\"type\":\"double\"}}");
|
||||
@@ -180,7 +180,7 @@ TEST_F(WireEncoderTextTest, MessageUnsubscribe) {
|
||||
|
||||
TEST_F(WireEncoderTextTest, MessageAnnounce) {
|
||||
net::ServerMessage msg{
|
||||
net::AnnounceMsg{"test", 5, "double", std::nullopt, wpi::json::object()}};
|
||||
net::AnnounceMsg{"test", 5, "double", std::nullopt, wpi::util::json::object()}};
|
||||
ASSERT_TRUE(net::WireEncodeText(os, msg));
|
||||
ASSERT_EQ(os.str(),
|
||||
"{\"method\":\"announce\",\"params\":{\"id\":5,\"name\":\"test\","
|
||||
@@ -198,7 +198,7 @@ TEST_F(WireEncoderTextTest, MessageAnnounceProperties) {
|
||||
|
||||
TEST_F(WireEncoderTextTest, MessageAnnouncePubuid) {
|
||||
net::ServerMessage msg{
|
||||
net::AnnounceMsg{"test", 5, "double", 6, wpi::json::object()}};
|
||||
net::AnnounceMsg{"test", 5, "double", 6, wpi::util::json::object()}};
|
||||
ASSERT_TRUE(net::WireEncodeText(os, msg));
|
||||
ASSERT_EQ(os.str(),
|
||||
"{\"method\":\"announce\",\"params\":{\"id\":5,\"name\":\"test\","
|
||||
@@ -224,49 +224,49 @@ TEST_F(WireEncoderTextTest, ServerMessageValue) {
|
||||
|
||||
TEST_F(WireEncoderBinaryTest, Boolean) {
|
||||
net::WireEncodeBinary(os, 5, 6, Value::MakeBoolean(true));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x94\x05\x06\x00\xc3"_us));
|
||||
ASSERT_THAT(out, wpi::util::SpanEq("\x94\x05\x06\x00\xc3"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderBinaryTest, Integer) {
|
||||
net::WireEncodeBinary(os, 5, 6, Value::MakeInteger(7));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x94\x05\x06\x02\x07"_us));
|
||||
ASSERT_THAT(out, wpi::util::SpanEq("\x94\x05\x06\x02\x07"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderBinaryTest, Float) {
|
||||
net::WireEncodeBinary(os, 5, 6, Value::MakeFloat(2.5));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x94\x05\x06\x03\xca\x40\x20\x00\x00"_us));
|
||||
ASSERT_THAT(out, wpi::util::SpanEq("\x94\x05\x06\x03\xca\x40\x20\x00\x00"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderBinaryTest, Double) {
|
||||
net::WireEncodeBinary(os, 5, 6, Value::MakeDouble(2.5));
|
||||
ASSERT_THAT(
|
||||
out,
|
||||
wpi::SpanEq("\x94\x05\x06\x01\xcb\x40\x04\x00\x00\x00\x00\x00\x00"_us));
|
||||
wpi::util::SpanEq("\x94\x05\x06\x01\xcb\x40\x04\x00\x00\x00\x00\x00\x00"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderBinaryTest, String) {
|
||||
net::WireEncodeBinary(os, 5, 6, Value::MakeString("hello"));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x94\x05\x06\x04\xa5hello"_us));
|
||||
ASSERT_THAT(out, wpi::util::SpanEq("\x94\x05\x06\x04\xa5hello"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderBinaryTest, Raw) {
|
||||
net::WireEncodeBinary(os, 5, 6, Value::MakeRaw("hello"_us));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x94\x05\x06\x05\xc4\x05hello"_us));
|
||||
ASSERT_THAT(out, wpi::util::SpanEq("\x94\x05\x06\x05\xc4\x05hello"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderBinaryTest, BooleanArray) {
|
||||
net::WireEncodeBinary(os, 5, 6, Value::MakeBooleanArray({true, false, true}));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x94\x05\x06\x10\x93\xc3\xc2\xc3"_us));
|
||||
ASSERT_THAT(out, wpi::util::SpanEq("\x94\x05\x06\x10\x93\xc3\xc2\xc3"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderBinaryTest, IntegerArray) {
|
||||
net::WireEncodeBinary(os, 5, 6, Value::MakeIntegerArray({1, 2, 4}));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x94\x05\x06\x12\x93\x01\x02\x04"_us));
|
||||
ASSERT_THAT(out, wpi::util::SpanEq("\x94\x05\x06\x12\x93\x01\x02\x04"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderBinaryTest, FloatArray) {
|
||||
net::WireEncodeBinary(os, 5, 6, Value::MakeFloatArray({1, 2, 3}));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x94\x05\x06\x13\x93"
|
||||
ASSERT_THAT(out, wpi::util::SpanEq("\x94\x05\x06\x13\x93"
|
||||
"\xca\x3f\x80\x00\x00"
|
||||
"\xca\x40\x00\x00\x00"
|
||||
"\xca\x40\x40\x00\x00"_us));
|
||||
@@ -274,7 +274,7 @@ TEST_F(WireEncoderBinaryTest, FloatArray) {
|
||||
|
||||
TEST_F(WireEncoderBinaryTest, DoubleArray) {
|
||||
net::WireEncodeBinary(os, 5, 6, Value::MakeDoubleArray({1, 2, 3}));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x94\x05\x06\x11\x93"
|
||||
ASSERT_THAT(out, wpi::util::SpanEq("\x94\x05\x06\x11\x93"
|
||||
"\xcb\x3f\xf0\x00\x00\x00\x00\x00\x00"
|
||||
"\xcb\x40\x00\x00\x00\x00\x00\x00\x00"
|
||||
"\xcb\x40\x08\x00\x00\x00\x00\x00\x00"_us));
|
||||
@@ -282,8 +282,8 @@ TEST_F(WireEncoderBinaryTest, DoubleArray) {
|
||||
|
||||
TEST_F(WireEncoderBinaryTest, StringArray) {
|
||||
net::WireEncodeBinary(os, 5, 6, Value::MakeStringArray({"hello", "bye"}));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x94\x05\x06\x14\x92\xa5hello\xa3"
|
||||
ASSERT_THAT(out, wpi::util::SpanEq("\x94\x05\x06\x14\x92\xa5hello\xa3"
|
||||
"bye"_us));
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
} // namespace wpi::nt
|
||||
|
||||
@@ -41,7 +41,7 @@ using MockSetPeriodicFunc = ::testing::MockFunction<void(uint32_t repeatMs)>;
|
||||
using MockConnected3Func =
|
||||
::testing::MockFunction<void(std::string_view name, uint16_t proto)>;
|
||||
|
||||
namespace nt {
|
||||
namespace wpi::nt {
|
||||
|
||||
class ServerImplTest : public ::testing::Test {
|
||||
public:
|
||||
@@ -85,7 +85,7 @@ TEST_F(ServerImplTest, AddClient3) {}
|
||||
template <typename T>
|
||||
static std::string EncodeText1(const T& msg) {
|
||||
std::string data;
|
||||
wpi::raw_string_ostream os{data};
|
||||
wpi::util::raw_string_ostream os{data};
|
||||
net::WireEncodeText(os, msg);
|
||||
return data;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ static std::string EncodeText1(const T& msg) {
|
||||
template <typename T>
|
||||
static std::string EncodeText(const T& msgs) {
|
||||
std::string data;
|
||||
wpi::raw_string_ostream os{data};
|
||||
wpi::util::raw_string_ostream os{data};
|
||||
bool first = true;
|
||||
for (auto&& msg : msgs) {
|
||||
if (first) {
|
||||
@@ -111,7 +111,7 @@ static std::string EncodeText(const T& msgs) {
|
||||
template <typename T>
|
||||
static std::vector<uint8_t> EncodeServerBinary1(const T& msg) {
|
||||
std::vector<uint8_t> data;
|
||||
wpi::raw_uvector_ostream os{data};
|
||||
wpi::util::raw_uvector_ostream os{data};
|
||||
if constexpr (std::same_as<T, net::ServerMessage>) {
|
||||
if (auto m = std::get_if<net::ServerValueMsg>(&msg.contents)) {
|
||||
net::WireEncodeBinary(os, m->topic, m->value.time(), m->value);
|
||||
@@ -128,7 +128,7 @@ static std::vector<uint8_t> EncodeServerBinary1(const T& msg) {
|
||||
template <typename T>
|
||||
static std::vector<uint8_t> EncodeServerBinary(const T& msgs) {
|
||||
std::vector<uint8_t> data;
|
||||
wpi::raw_uvector_ostream os{data};
|
||||
wpi::util::raw_uvector_ostream os{data};
|
||||
for (auto&& msg : msgs) {
|
||||
if constexpr (std::same_as<typename T::value_type, net::ServerMessage>) {
|
||||
if (auto m = std::get_if<net::ServerValueMsg>(&msg.contents)) {
|
||||
@@ -155,20 +155,20 @@ TEST_F(ServerImplTest, PublishLocal) {
|
||||
EXPECT_CALL(
|
||||
local,
|
||||
ServerAnnounce(std::string_view{"test"}, 0, std::string_view{"double"},
|
||||
wpi::json::object(), std::optional<int>{pubuid}));
|
||||
wpi::util::json::object(), std::optional<int>{pubuid}));
|
||||
EXPECT_CALL(
|
||||
local,
|
||||
ServerAnnounce(std::string_view{"test2"}, 0, std::string_view{"double"},
|
||||
wpi::json::object(), std::optional<int>{pubuid2}));
|
||||
wpi::util::json::object(), std::optional<int>{pubuid2}));
|
||||
EXPECT_CALL(
|
||||
local,
|
||||
ServerAnnounce(std::string_view{"test3"}, 0, std::string_view{"double"},
|
||||
wpi::json::object(), std::optional<int>{pubuid3}));
|
||||
wpi::util::json::object(), std::optional<int>{pubuid3}));
|
||||
}
|
||||
|
||||
{
|
||||
queue.msgs.emplace_back(net::ClientMessage{
|
||||
net::PublishMsg{pubuid, "test", "double", wpi::json::object(), {}}});
|
||||
net::PublishMsg{pubuid, "test", "double", wpi::util::json::object(), {}}});
|
||||
EXPECT_FALSE(server.ProcessLocalMessages(UINT_MAX));
|
||||
}
|
||||
|
||||
@@ -187,17 +187,17 @@ TEST_F(ServerImplTest, PublishLocal) {
|
||||
EXPECT_CALL(wire, Ready()).WillOnce(Return(true)); // SendControl()
|
||||
EXPECT_CALL(
|
||||
wire, DoWriteText(StrEq(EncodeText1(net::ServerMessage{net::AnnounceMsg{
|
||||
"test", 3, "double", std::nullopt, wpi::json::object()}}))))
|
||||
"test", 3, "double", std::nullopt, wpi::util::json::object()}}))))
|
||||
.WillOnce(Return(0));
|
||||
EXPECT_CALL(
|
||||
wire, DoWriteText(StrEq(EncodeText1(net::ServerMessage{net::AnnounceMsg{
|
||||
"test2", 8, "double", std::nullopt, wpi::json::object()}}))))
|
||||
"test2", 8, "double", std::nullopt, wpi::util::json::object()}}))))
|
||||
.WillOnce(Return(0));
|
||||
EXPECT_CALL(wire, Flush()).WillOnce(Return(0)); // SendControl()
|
||||
EXPECT_CALL(wire, Ready()).WillOnce(Return(true)); // SendControl()
|
||||
EXPECT_CALL(
|
||||
wire, DoWriteText(StrEq(EncodeText1(net::ServerMessage{net::AnnounceMsg{
|
||||
"test3", 11, "double", std::nullopt, wpi::json::object()}}))))
|
||||
"test3", 11, "double", std::nullopt, wpi::util::json::object()}}))))
|
||||
.WillOnce(Return(0));
|
||||
EXPECT_CALL(wire, Flush()).WillOnce(Return(0)); // SendControl()
|
||||
}
|
||||
@@ -215,7 +215,7 @@ TEST_F(ServerImplTest, PublishLocal) {
|
||||
// publish before send control
|
||||
{
|
||||
queue.msgs.emplace_back(net::ClientMessage{
|
||||
net::PublishMsg{pubuid2, "test2", "double", wpi::json::object(), {}}});
|
||||
net::PublishMsg{pubuid2, "test2", "double", wpi::util::json::object(), {}}});
|
||||
EXPECT_FALSE(server.ProcessLocalMessages(UINT_MAX));
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ TEST_F(ServerImplTest, PublishLocal) {
|
||||
// publish after send control
|
||||
{
|
||||
queue.msgs.emplace_back(net::ClientMessage{
|
||||
net::PublishMsg{pubuid3, "test3", "double", wpi::json::object(), {}}});
|
||||
net::PublishMsg{pubuid3, "test3", "double", wpi::util::json::object(), {}}});
|
||||
EXPECT_FALSE(server.ProcessLocalMessages(UINT_MAX));
|
||||
}
|
||||
|
||||
@@ -238,11 +238,11 @@ TEST_F(ServerImplTest, ClientSubTopicOnlyThenValue) {
|
||||
EXPECT_CALL(
|
||||
local,
|
||||
ServerAnnounce(std::string_view{"test"}, 0, std::string_view{"double"},
|
||||
wpi::json::object(), std::optional<int>{pubuid}));
|
||||
wpi::util::json::object(), std::optional<int>{pubuid}));
|
||||
|
||||
{
|
||||
queue.msgs.emplace_back(net::ClientMessage{
|
||||
net::PublishMsg{pubuid, "test", "double", wpi::json::object(), {}}});
|
||||
net::PublishMsg{pubuid, "test", "double", wpi::util::json::object(), {}}});
|
||||
queue.msgs.emplace_back(net::ClientMessage{
|
||||
net::ClientValueMsg{pubuid, Value::MakeDouble(1.0, 10)}});
|
||||
EXPECT_FALSE(server.ProcessLocalMessages(UINT_MAX));
|
||||
@@ -261,14 +261,14 @@ TEST_F(ServerImplTest, ClientSubTopicOnlyThenValue) {
|
||||
EXPECT_CALL(wire, Ready()).WillOnce(Return(true)); // SendValues()
|
||||
EXPECT_CALL(
|
||||
wire, DoWriteText(StrEq(EncodeText1(net::ServerMessage{net::AnnounceMsg{
|
||||
"test", 3, "double", std::nullopt, wpi::json::object()}}))))
|
||||
"test", 3, "double", std::nullopt, wpi::util::json::object()}}))))
|
||||
.WillOnce(Return(0));
|
||||
EXPECT_CALL(wire, Flush()).WillOnce(Return(0)); // SendValues()
|
||||
EXPECT_CALL(setPeriodic, Call(100)); // ClientSubscribe()
|
||||
// EXPECT_CALL(wire, Flush()).WillOnce(Return(0)); // ClientSubscribe()
|
||||
EXPECT_CALL(wire, Ready()).WillOnce(Return(true)); // SendValues()
|
||||
EXPECT_CALL(
|
||||
wire, DoWriteBinary(wpi::SpanEq(EncodeServerBinary1(net::ServerMessage{
|
||||
wire, DoWriteBinary(wpi::util::SpanEq(EncodeServerBinary1(net::ServerMessage{
|
||||
net::ServerValueMsg{3, Value::MakeDouble(1.0, 10)}}))))
|
||||
.WillOnce(Return(0));
|
||||
EXPECT_CALL(wire, Flush()); // SendValues()
|
||||
@@ -312,17 +312,17 @@ TEST_F(ServerImplTest, ClientDisconnectUnpublish) {
|
||||
EXPECT_CALL(
|
||||
local,
|
||||
ServerAnnounce(std::string_view{"test2"}, 0, std::string_view{"double"},
|
||||
wpi::json::object(), std::optional<int>{pubuidLocal}));
|
||||
wpi::util::json::object(), std::optional<int>{pubuidLocal}));
|
||||
EXPECT_CALL(
|
||||
local,
|
||||
ServerAnnounce(std::string_view{"test"}, 0, std::string_view{"double"},
|
||||
wpi::json::object(), std::optional<int>{}));
|
||||
wpi::util::json::object(), std::optional<int>{}));
|
||||
EXPECT_CALL(local, ServerUnannounce(std::string_view{"test"}, 0));
|
||||
}
|
||||
|
||||
{
|
||||
queue.msgs.emplace_back(net::ClientMessage{net::PublishMsg{
|
||||
pubuidLocal, "test2", "double", wpi::json::object(), {}}});
|
||||
pubuidLocal, "test2", "double", wpi::util::json::object(), {}}});
|
||||
queue.msgs.emplace_back(net::ClientMessage{
|
||||
net::ClientValueMsg{pubuidLocal, Value::MakeDouble(1.0, 10)}});
|
||||
EXPECT_FALSE(server.ProcessLocalMessages(UINT_MAX));
|
||||
@@ -344,7 +344,7 @@ TEST_F(ServerImplTest, ClientDisconnectUnpublish) {
|
||||
EXPECT_CALL(wire, Ready()).WillOnce(Return(true)); // SendValues()
|
||||
EXPECT_CALL(
|
||||
wire, DoWriteText(StrEq(EncodeText1(net::ServerMessage{net::AnnounceMsg{
|
||||
"test", 8, "double", 1, wpi::json::object()}}))))
|
||||
"test", 8, "double", 1, wpi::util::json::object()}}))))
|
||||
.WillOnce(Return(0));
|
||||
EXPECT_CALL(wire, Flush()); // SendValues()
|
||||
}
|
||||
@@ -358,7 +358,7 @@ TEST_F(ServerImplTest, ClientDisconnectUnpublish) {
|
||||
constexpr int pubuid = 1;
|
||||
std::vector<net::ClientMessage> msgs;
|
||||
msgs.emplace_back(net::ClientMessage{
|
||||
net::PublishMsg{pubuid, "test", "double", wpi::json::object(), {}}});
|
||||
net::PublishMsg{pubuid, "test", "double", wpi::util::json::object(), {}}});
|
||||
server.ProcessIncomingText(id, EncodeText(msgs));
|
||||
}
|
||||
|
||||
@@ -372,7 +372,7 @@ TEST_F(ServerImplTest, ZeroTimestampNegativeTime) {
|
||||
// publish before client connect
|
||||
server.SetLocal(&local, &queue);
|
||||
constexpr int pubuid = 1;
|
||||
NT_Topic topicHandle = nt::Handle{0, 1, nt::Handle::kTopic};
|
||||
NT_Topic topicHandle = wpi::nt::Handle{0, 1, wpi::nt::Handle::kTopic};
|
||||
constexpr int subuid = 1;
|
||||
Value defaultValue = Value::MakeDouble(1.0, 10);
|
||||
defaultValue.SetTime(0);
|
||||
@@ -383,7 +383,7 @@ TEST_F(ServerImplTest, ZeroTimestampNegativeTime) {
|
||||
EXPECT_CALL(
|
||||
local,
|
||||
ServerAnnounce(std::string_view{"test"}, 0, std::string_view{"double"},
|
||||
wpi::json::object(), std::optional<int>{pubuid}))
|
||||
wpi::util::json::object(), std::optional<int>{pubuid}))
|
||||
.WillOnce(Return(topicHandle));
|
||||
EXPECT_CALL(local, ServerSetValue(topicHandle, defaultValue));
|
||||
EXPECT_CALL(local, ServerSetValue(topicHandle, value));
|
||||
@@ -391,7 +391,7 @@ TEST_F(ServerImplTest, ZeroTimestampNegativeTime) {
|
||||
|
||||
{
|
||||
queue.msgs.emplace_back(net::ClientMessage{
|
||||
net::PublishMsg{pubuid, "test", "double", wpi::json::object(), {}}});
|
||||
net::PublishMsg{pubuid, "test", "double", wpi::util::json::object(), {}}});
|
||||
queue.msgs.emplace_back(
|
||||
net::ClientMessage{net::ClientValueMsg{pubuid, defaultValue}});
|
||||
queue.msgs.emplace_back(
|
||||
@@ -415,7 +415,7 @@ TEST_F(ServerImplTest, ZeroTimestampNegativeTime) {
|
||||
constexpr int pubuid2 = 2;
|
||||
std::vector<net::ClientMessage> msgs;
|
||||
msgs.emplace_back(net::ClientMessage{
|
||||
net::PublishMsg{pubuid2, "test", "double", wpi::json::object(), {}}});
|
||||
net::PublishMsg{pubuid2, "test", "double", wpi::util::json::object(), {}}});
|
||||
server.ProcessIncomingText(id, EncodeText(msgs));
|
||||
msgs.clear();
|
||||
msgs.emplace_back(net::ClientMessage{net::ClientValueMsg{pubuid2, value}});
|
||||
@@ -439,4 +439,4 @@ TEST_F(ServerImplTest, InvalidPubUid) {
|
||||
"\"myvalue\",\"pubuid\":2147483647,\"properties\":{}}}]");
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
} // namespace wpi::nt
|
||||
|
||||
Reference in New Issue
Block a user