mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-05 03:21:42 +00:00
SCRIPT: wpiformat
This commit is contained in:
committed by
Peter Johnson
parent
ae6bdc9d25
commit
2109161534
@@ -16,7 +16,8 @@
|
||||
class ConnectionListenerTest : public ::testing::Test {
|
||||
public:
|
||||
ConnectionListenerTest()
|
||||
: server_inst(wpi::nt::CreateInstance()), client_inst(wpi::nt::CreateInstance()) {}
|
||||
: server_inst(wpi::nt::CreateInstance()),
|
||||
client_inst(wpi::nt::CreateInstance()) {}
|
||||
|
||||
~ConnectionListenerTest() override {
|
||||
wpi::nt::DestroyInstance(server_inst);
|
||||
@@ -31,7 +32,8 @@ class ConnectionListenerTest : public ::testing::Test {
|
||||
};
|
||||
|
||||
void ConnectionListenerTest::Connect(const char* address, unsigned int port4) {
|
||||
wpi::nt::StartServer(server_inst, "connectionlistenertest.ini", address, port4);
|
||||
wpi::nt::StartServer(server_inst, "connectionlistenertest.ini", address,
|
||||
port4);
|
||||
wpi::nt::StartClient(client_inst, "client");
|
||||
wpi::nt::SetServer(client_inst, address, port4);
|
||||
|
||||
@@ -50,8 +52,8 @@ TEST_F(ConnectionListenerTest, Polled) {
|
||||
// set up the poller
|
||||
NT_ListenerPoller poller = wpi::nt::CreateListenerPoller(server_inst);
|
||||
ASSERT_NE(poller, 0u);
|
||||
NT_Listener handle =
|
||||
wpi::nt::AddPolledListener(poller, server_inst, wpi::nt::EventFlags::kConnection);
|
||||
NT_Listener handle = wpi::nt::AddPolledListener(
|
||||
poller, server_inst, wpi::nt::EventFlags::kConnection);
|
||||
ASSERT_NE(handle, 0u);
|
||||
|
||||
// trigger a connect event
|
||||
@@ -89,11 +91,11 @@ class ConnectionListenerVariantTest
|
||||
TEST_P(ConnectionListenerVariantTest, Threaded) {
|
||||
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);
|
||||
});
|
||||
auto handle = wpi::nt::AddListener(
|
||||
server_inst, wpi::nt::EventFlags::kConnection, [&](auto& event) {
|
||||
std::scoped_lock lock{m};
|
||||
result.push_back(event);
|
||||
});
|
||||
|
||||
// trigger a connect event
|
||||
Connect(GetParam().first, 20001 + GetParam().second);
|
||||
|
||||
@@ -80,8 +80,9 @@ TEST_F(LocalStorageTest, GetEntryEmptyName) {
|
||||
}
|
||||
|
||||
TEST_F(LocalStorageTest, GetEntryCached) {
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"tocache"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
EXPECT_CALL(network,
|
||||
ClientSubscribe(_, wpi::util::SpanEq({std::string{"tocache"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
|
||||
auto entry1 = storage.GetEntry("tocache");
|
||||
EXPECT_EQ(entry1, storage.GetEntry("tocache"));
|
||||
@@ -110,7 +111,8 @@ TEST_F(LocalStorageTest, DefaultProps) {
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"boolean"},
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
storage.Publish(fooTopic, NT_BOOLEAN, "boolean", wpi::util::json::object(), {});
|
||||
storage.Publish(fooTopic, NT_BOOLEAN, "boolean", wpi::util::json::object(),
|
||||
{});
|
||||
|
||||
EXPECT_FALSE(storage.GetTopicPersistent(fooTopic));
|
||||
EXPECT_FALSE(storage.GetTopicRetained(fooTopic));
|
||||
@@ -122,7 +124,8 @@ TEST_F(LocalStorageTest, PublishNewNoProps) {
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"boolean"},
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
storage.Publish(fooTopic, NT_BOOLEAN, "boolean", wpi::util::json::object(), {});
|
||||
storage.Publish(fooTopic, NT_BOOLEAN, "boolean", wpi::util::json::object(),
|
||||
{});
|
||||
|
||||
auto info = storage.GetTopicInfo(fooTopic);
|
||||
EXPECT_EQ(info.properties, "{}");
|
||||
@@ -159,8 +162,9 @@ TEST_F(LocalStorageTest, PublishNew) {
|
||||
}
|
||||
|
||||
TEST_F(LocalStorageTest, SubscribeNoTypeLocalPubPost) {
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
EXPECT_CALL(network,
|
||||
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
auto sub = storage.Subscribe(fooTopic, NT_UNASSIGNED, "", {});
|
||||
|
||||
EXPECT_CALL(
|
||||
@@ -206,8 +210,9 @@ TEST_F(LocalStorageTest, SubscribeNoTypeLocalPubPre) {
|
||||
EXPECT_CALL(network, ClientSetValue(Handle{pub}.GetIndex(), val));
|
||||
storage.SetEntryValue(pub, val);
|
||||
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
EXPECT_CALL(network,
|
||||
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
auto sub = storage.Subscribe(fooTopic, NT_UNASSIGNED, "", {});
|
||||
|
||||
EXPECT_EQ(storage.GetTopicType(fooTopic), NT_BOOLEAN);
|
||||
@@ -221,8 +226,9 @@ TEST_F(LocalStorageTest, SubscribeNoTypeLocalPubPre) {
|
||||
}
|
||||
|
||||
TEST_F(LocalStorageTest, EntryNoTypeLocalSet) {
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
EXPECT_CALL(network,
|
||||
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
auto entry = storage.GetEntry(fooTopic, NT_UNASSIGNED, "", {});
|
||||
|
||||
// results in a publish and value set
|
||||
@@ -268,8 +274,9 @@ TEST_F(LocalStorageTest, EntryNoTypeLocalSet) {
|
||||
}
|
||||
|
||||
TEST_F(LocalStorageTest, PubUnpubPub) {
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
EXPECT_CALL(network,
|
||||
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
auto sub = storage.Subscribe(fooTopic, NT_INTEGER, "int", {});
|
||||
|
||||
EXPECT_CALL(
|
||||
@@ -300,9 +307,10 @@ TEST_F(LocalStorageTest, PubUnpubPub) {
|
||||
EXPECT_EQ(storage.GetTopicTypeString(fooTopic), "");
|
||||
EXPECT_FALSE(storage.GetTopicExists(fooTopic));
|
||||
|
||||
EXPECT_CALL(network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"int"},
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
EXPECT_CALL(
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"int"},
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
pub = storage.Publish(fooTopic, NT_INTEGER, "int", {}, {});
|
||||
|
||||
val = Value::MakeInteger(3, 5);
|
||||
@@ -341,9 +349,10 @@ TEST_F(LocalStorageTest, LocalPubConflict) {
|
||||
|
||||
// unpublishing pub1 will publish pub2 to the network
|
||||
EXPECT_CALL(network, ClientUnpublish(Handle{pub1}.GetIndex()));
|
||||
EXPECT_CALL(network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"int"},
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
EXPECT_CALL(
|
||||
network,
|
||||
ClientPublish(_, std::string_view{"foo"}, std::string_view{"int"},
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
storage.Unpublish(pub1);
|
||||
|
||||
EXPECT_EQ(storage.GetTopicType(fooTopic), NT_INTEGER);
|
||||
@@ -363,8 +372,9 @@ TEST_F(LocalStorageTest, LocalSubConflict) {
|
||||
wpi::util::json::object(), IsDefaultPubSubOptions()));
|
||||
storage.Publish(fooTopic, NT_BOOLEAN, "boolean", {}, {});
|
||||
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
EXPECT_CALL(network,
|
||||
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
EXPECT_CALL(logger,
|
||||
Call(NT_LOG_INFO, _, _,
|
||||
std::string_view{
|
||||
@@ -409,15 +419,17 @@ TEST_F(LocalStorageTest, RemotePubConflict) {
|
||||
|
||||
TEST_F(LocalStorageTest, SubNonExist) {
|
||||
// makes sure no warning is emitted
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
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::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
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)));
|
||||
auto val = storage.GetEntryValue(sub);
|
||||
@@ -447,8 +459,9 @@ TEST_F(LocalStorageTest, SetDefaultPublish) {
|
||||
}
|
||||
|
||||
TEST_F(LocalStorageTest, SetDefaultEntry) {
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
EXPECT_CALL(network,
|
||||
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
auto entry = storage.GetEntry(fooTopic, NT_BOOLEAN, "boolean", {});
|
||||
|
||||
// expect a publish and value
|
||||
@@ -467,8 +480,9 @@ TEST_F(LocalStorageTest, SetDefaultEntry) {
|
||||
}
|
||||
|
||||
TEST_F(LocalStorageTest, SetDefaultEntryUnassigned) {
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
EXPECT_CALL(network,
|
||||
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
auto entry = storage.GetEntry(fooTopic, NT_UNASSIGNED, "", {});
|
||||
|
||||
// expect a publish and value
|
||||
@@ -509,8 +523,9 @@ TEST_F(LocalStorageTest, SetValueEmptyValue) {
|
||||
}
|
||||
|
||||
TEST_F(LocalStorageTest, SetValueEmptyUntypedEntry) {
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
EXPECT_CALL(network,
|
||||
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsDefaultPubSubOptions()));
|
||||
auto entry = storage.GetEntry(fooTopic, NT_UNASSIGNED, "", {});
|
||||
EXPECT_FALSE(storage.SetEntryValue(entry, {}));
|
||||
}
|
||||
@@ -553,8 +568,9 @@ void LocalStorageDuplicatesTest::SetupPubSub(bool keepPub, bool keepSub) {
|
||||
PubSubOptionsImpl subOptions;
|
||||
subOptions.pollStorage = 10;
|
||||
subOptions.keepDuplicates = keepSub;
|
||||
EXPECT_CALL(network, ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsPubSubOptions(subOptions)));
|
||||
EXPECT_CALL(network,
|
||||
ClientSubscribe(_, wpi::util::SpanEq({std::string{"foo"}}),
|
||||
IsPubSubOptions(subOptions)));
|
||||
sub = storage.Subscribe(fooTopic, NT_DOUBLE, "double",
|
||||
{.pollStorage = 10, .keepDuplicates = keepSub});
|
||||
}
|
||||
@@ -942,8 +958,8 @@ TEST_F(LocalStorageTest, MultiSubSpecial) {
|
||||
TEST_F(LocalStorageTest, NetworkDuplicateDetect) {
|
||||
EXPECT_CALL(network, ClientPublish(_, _, _, _, _));
|
||||
auto pub = storage.Publish(fooTopic, NT_DOUBLE, "double", {}, {});
|
||||
auto remoteTopic = storage.ServerAnnounce("foo", 0, "double",
|
||||
wpi::util::json::object(), std::nullopt);
|
||||
auto remoteTopic = storage.ServerAnnounce(
|
||||
"foo", 0, "double", wpi::util::json::object(), std::nullopt);
|
||||
|
||||
// local set
|
||||
EXPECT_CALL(network, ClientSetValue(_, _));
|
||||
@@ -968,8 +984,8 @@ TEST_F(LocalStorageTest, ReadQueueLocalRemote) {
|
||||
auto subRemote =
|
||||
storage.Subscribe(fooTopic, NT_DOUBLE, "double", {.disableLocal = true});
|
||||
auto pub = storage.Publish(fooTopic, NT_DOUBLE, "double", {}, {});
|
||||
auto remoteTopic = storage.ServerAnnounce("foo", 0, "double",
|
||||
wpi::util::json::object(), std::nullopt);
|
||||
auto remoteTopic = storage.ServerAnnounce(
|
||||
"foo", 0, "double", wpi::util::json::object(), std::nullopt);
|
||||
|
||||
// local set
|
||||
EXPECT_CALL(network, ClientSetValue(_, _));
|
||||
@@ -997,8 +1013,8 @@ TEST_F(LocalStorageTest, SubExcludePub) {
|
||||
auto subActive = storage.Subscribe(fooTopic, NT_DOUBLE, "double", {});
|
||||
auto subExclude = storage.Subscribe(fooTopic, NT_DOUBLE, "double",
|
||||
{.excludePublisher = pub});
|
||||
auto remoteTopic = storage.ServerAnnounce("foo", 0, "double",
|
||||
wpi::util::json::object(), std::nullopt);
|
||||
auto remoteTopic = storage.ServerAnnounce(
|
||||
"foo", 0, "double", wpi::util::json::object(), std::nullopt);
|
||||
|
||||
// local set
|
||||
EXPECT_CALL(network, ClientSetValue(_, _));
|
||||
@@ -1020,8 +1036,8 @@ TEST_F(LocalStorageTest, EntryExcludeSelf) {
|
||||
|
||||
auto entry =
|
||||
storage.GetEntry(fooTopic, NT_DOUBLE, "double", {.excludeSelf = true});
|
||||
auto remoteTopic = storage.ServerAnnounce("foo", 0, "double",
|
||||
wpi::util::json::object(), std::nullopt);
|
||||
auto remoteTopic = storage.ServerAnnounce(
|
||||
"foo", 0, "double", wpi::util::json::object(), std::nullopt);
|
||||
|
||||
// local set
|
||||
EXPECT_CALL(network, ClientPublish(_, _, _, _, _));
|
||||
@@ -1060,8 +1076,8 @@ TEST_F(LocalStorageTest, ReadQueueInitialLocal) {
|
||||
TEST_F(LocalStorageTest, ReadQueueInitialRemote) {
|
||||
EXPECT_CALL(network, ClientSubscribe(_, _, _)).Times(3);
|
||||
|
||||
auto remoteTopic = storage.ServerAnnounce("foo", 0, "double",
|
||||
wpi::util::json::object(), std::nullopt);
|
||||
auto remoteTopic = storage.ServerAnnounce(
|
||||
"foo", 0, "double", wpi::util::json::object(), std::nullopt);
|
||||
storage.ServerSetValue(remoteTopic, Value::MakeDouble(2.0, 60));
|
||||
|
||||
auto subBoth =
|
||||
|
||||
@@ -30,12 +30,13 @@ void LoggerTest::Generate() {
|
||||
wpi::nt::StartClient(m_inst, "");
|
||||
|
||||
// generate error message
|
||||
wpi::nt::Publish(wpi::nt::Handle(wpi::nt::Handle{m_inst}.GetInst(), 5, wpi::nt::Handle::kTopic),
|
||||
NT_DOUBLE, "");
|
||||
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<wpi::nt::Event>& events, NT_Listener handle,
|
||||
bool infoMsg, bool errMsg) {
|
||||
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) {
|
||||
@@ -59,8 +60,8 @@ void LoggerTest::Check(const std::vector<wpi::nt::Event>& events, NT_Listener ha
|
||||
|
||||
TEST_F(LoggerTest, DefaultLogRange) {
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto handle =
|
||||
wpi::nt::AddPolledListener(poller, m_inst, wpi::nt::EventFlags::kLogMessage);
|
||||
auto handle = wpi::nt::AddPolledListener(poller, m_inst,
|
||||
wpi::nt::EventFlags::kLogMessage);
|
||||
|
||||
Generate();
|
||||
|
||||
|
||||
@@ -15,14 +15,16 @@ class NetworkTableTest : public ::testing::Test {};
|
||||
|
||||
TEST_F(NetworkTableTest, BasenameKey) {
|
||||
EXPECT_EQ("simple", wpi::nt::NetworkTable::BasenameKey("simple"));
|
||||
EXPECT_EQ("simple", wpi::nt::NetworkTable::BasenameKey("one/two/many/simple"));
|
||||
EXPECT_EQ("simple",
|
||||
wpi::nt::NetworkTable::BasenameKey("//////an/////awful/key////simple"));
|
||||
wpi::nt::NetworkTable::BasenameKey("one/two/many/simple"));
|
||||
EXPECT_EQ("simple", wpi::nt::NetworkTable::BasenameKey(
|
||||
"//////an/////awful/key////simple"));
|
||||
}
|
||||
|
||||
TEST_F(NetworkTableTest, NormalizeKeySlash) {
|
||||
EXPECT_EQ("/", wpi::nt::NetworkTable::NormalizeKey("///"));
|
||||
EXPECT_EQ("/no/normal/req", wpi::nt::NetworkTable::NormalizeKey("/no/normal/req"));
|
||||
EXPECT_EQ("/no/normal/req",
|
||||
wpi::nt::NetworkTable::NormalizeKey("/no/normal/req"));
|
||||
EXPECT_EQ("/no/leading/slash",
|
||||
wpi::nt::NetworkTable::NormalizeKey("no/leading/slash"));
|
||||
EXPECT_EQ("/what/an/awful/key/", wpi::nt::NetworkTable::NormalizeKey(
|
||||
@@ -37,8 +39,8 @@ TEST_F(NetworkTableTest, NormalizeKeyNoSlash) {
|
||||
EXPECT_EQ("no/leading/slash",
|
||||
wpi::nt::NetworkTable::NormalizeKey("no/leading/slash", false));
|
||||
EXPECT_EQ("what/an/awful/key/",
|
||||
wpi::nt::NetworkTable::NormalizeKey("//////what////an/awful/////key///",
|
||||
false));
|
||||
wpi::nt::NetworkTable::NormalizeKey(
|
||||
"//////what////an/awful/////key///", false));
|
||||
}
|
||||
|
||||
TEST_F(NetworkTableTest, GetHierarchyEmpty) {
|
||||
|
||||
@@ -63,7 +63,9 @@ struct wpi::util::Struct<Inner> {
|
||||
template <>
|
||||
struct wpi::util::Struct<Outer> {
|
||||
static constexpr std::string_view GetTypeName() { return "Outer"; }
|
||||
static constexpr size_t GetSize() { return wpi::util::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";
|
||||
}
|
||||
@@ -283,7 +285,8 @@ TEST_F(StructTest, OuterNonconstexpr) {
|
||||
}
|
||||
|
||||
TEST_F(StructTest, InnerArrayConstexpr) {
|
||||
wpi::nt::StructArrayTopic<Inner> topic = inst.GetStructArrayTopic<Inner>("innerA");
|
||||
wpi::nt::StructArrayTopic<Inner> topic =
|
||||
inst.GetStructArrayTopic<Inner>("innerA");
|
||||
wpi::nt::StructArrayPublisher<Inner> pub = topic.Publish();
|
||||
wpi::nt::StructArraySubscriber<Inner> sub = topic.Subscribe({});
|
||||
|
||||
@@ -353,7 +356,8 @@ TEST_F(StructTest, StructA) {
|
||||
}
|
||||
|
||||
TEST_F(StructTest, StructArrayA) {
|
||||
wpi::nt::StructArrayTopic<ThingA> topic = inst.GetStructArrayTopic<ThingA>("a");
|
||||
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({});
|
||||
@@ -433,7 +437,8 @@ TEST_F(StructTest, StructFixedArrayB) {
|
||||
wpi::nt::StructPublisher<std::array<ThingB, 2>, Info1> pub = topic.Publish();
|
||||
wpi::nt::StructPublisher<std::array<ThingB, 2>, Info1> pub2 =
|
||||
topic.PublishEx({{}});
|
||||
wpi::nt::StructSubscriber<std::array<ThingB, 2>, Info1> sub = topic.Subscribe({});
|
||||
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);
|
||||
|
||||
@@ -15,16 +15,19 @@
|
||||
using ::testing::_;
|
||||
|
||||
using MockTableEventListener = testing::MockFunction<void(
|
||||
wpi::nt::NetworkTable* table, std::string_view key, const wpi::nt::Event& event)>;
|
||||
using MockSubTableListener =
|
||||
testing::MockFunction<void(wpi::nt::NetworkTable* parent, std::string_view name,
|
||||
std::shared_ptr<wpi::nt::NetworkTable> table)>;
|
||||
wpi::nt::NetworkTable* table, std::string_view key,
|
||||
const wpi::nt::Event& event)>;
|
||||
using MockSubTableListener = 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(wpi::nt::NetworkTableInstance::Create()) {}
|
||||
|
||||
~TableListenerTest() override { wpi::nt::NetworkTableInstance::Destroy(m_inst); }
|
||||
~TableListenerTest() override {
|
||||
wpi::nt::NetworkTableInstance::Destroy(m_inst);
|
||||
}
|
||||
|
||||
void PublishTopics();
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
class TopicListenerTest : public ::testing::Test {
|
||||
public:
|
||||
TopicListenerTest()
|
||||
: m_serverInst(wpi::nt::CreateInstance()), m_clientInst(wpi::nt::CreateInstance()) {
|
||||
: m_serverInst(wpi::nt::CreateInstance()),
|
||||
m_clientInst(wpi::nt::CreateInstance()) {
|
||||
#if 0
|
||||
wpi::nt::AddLogger(m_serverInst, 0, UINT_MAX, [](auto& event) {
|
||||
if (auto msg = event.GetLogMessage()) {
|
||||
@@ -41,8 +42,9 @@ class TopicListenerTest : public ::testing::Test {
|
||||
|
||||
void Connect(unsigned int port);
|
||||
static void PublishTopics(NT_Inst inst);
|
||||
void CheckEvents(const std::vector<wpi::nt::Event>& events, NT_Listener handle,
|
||||
unsigned int flags, std::string_view topicName = "/foo/bar");
|
||||
void CheckEvents(const std::vector<wpi::nt::Event>& events,
|
||||
NT_Listener handle, unsigned int flags,
|
||||
std::string_view topicName = "/foo/bar");
|
||||
|
||||
protected:
|
||||
NT_Inst m_serverInst;
|
||||
@@ -50,13 +52,15 @@ class TopicListenerTest : public ::testing::Test {
|
||||
};
|
||||
|
||||
void TopicListenerTest::Connect(unsigned int port) {
|
||||
wpi::nt::StartServer(m_serverInst, "topiclistenertest.json", "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 = wpi::nt::CreateListenerPoller(m_clientInst);
|
||||
wpi::nt::AddPolledListener(poller, m_clientInst, wpi::nt::EventFlags::kConnected);
|
||||
wpi::nt::AddPolledListener(poller, m_clientInst,
|
||||
wpi::nt::EventFlags::kConnected);
|
||||
bool timedOut = false;
|
||||
if (!wpi::util::WaitForObject(poller, 1.0, &timedOut)) {
|
||||
FAIL() << "client didn't connect to server";
|
||||
@@ -84,7 +88,8 @@ void TopicListenerTest::CheckEvents(const std::vector<wpi::nt::Event>& events,
|
||||
TEST_F(TopicListenerTest, TopicNewLocal) {
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle = wpi::nt::AddPolledListener(
|
||||
poller, wpi::nt::GetTopic(m_serverInst, "/foo"), wpi::nt::EventFlags::kPublish);
|
||||
poller, wpi::nt::GetTopic(m_serverInst, "/foo"),
|
||||
wpi::nt::EventFlags::kPublish);
|
||||
|
||||
PublishTopics(m_serverInst);
|
||||
|
||||
@@ -101,7 +106,8 @@ TEST_F(TopicListenerTest, DISABLED_TopicNewRemote) {
|
||||
}
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle = wpi::nt::AddPolledListener(
|
||||
poller, wpi::nt::GetTopic(m_serverInst, "/foo"), wpi::nt::EventFlags::kPublish);
|
||||
poller, wpi::nt::GetTopic(m_serverInst, "/foo"),
|
||||
wpi::nt::EventFlags::kPublish);
|
||||
|
||||
PublishTopics(m_clientInst);
|
||||
|
||||
@@ -126,7 +132,8 @@ TEST_F(TopicListenerTest, TopicPublishImm) {
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
auto events = wpi::nt::ReadListenerQueue(poller);
|
||||
CheckEvents(events, handle,
|
||||
wpi::nt::EventFlags::kPublish | wpi::nt::EventFlags::kImmediate, "/foo");
|
||||
wpi::nt::EventFlags::kPublish | wpi::nt::EventFlags::kImmediate,
|
||||
"/foo");
|
||||
}
|
||||
|
||||
TEST_F(TopicListenerTest, TopicUnpublishPropsImm) {
|
||||
@@ -134,9 +141,9 @@ TEST_F(TopicListenerTest, TopicUnpublishPropsImm) {
|
||||
|
||||
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);
|
||||
wpi::nt::EventFlags::kUnpublish |
|
||||
wpi::nt::EventFlags::kProperties |
|
||||
wpi::nt::EventFlags::kImmediate);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_FALSE(wpi::util::WaitForObject(poller, 0.02, &timedOut));
|
||||
@@ -148,8 +155,8 @@ TEST_F(TopicListenerTest, TopicUnpublishLocal) {
|
||||
auto topic = wpi::nt::GetTopic(m_serverInst, "/foo");
|
||||
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle =
|
||||
wpi::nt::AddPolledListener(poller, topic, wpi::nt::EventFlags::kUnpublish);
|
||||
auto handle = wpi::nt::AddPolledListener(poller, topic,
|
||||
wpi::nt::EventFlags::kUnpublish);
|
||||
|
||||
auto pub = wpi::nt::Publish(topic, NT_DOUBLE, "double");
|
||||
wpi::nt::Unpublish(pub);
|
||||
@@ -167,10 +174,11 @@ TEST_F(TopicListenerTest, DISABLED_TopicUnpublishRemote) {
|
||||
}
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle = wpi::nt::AddPolledListener(
|
||||
poller, wpi::nt::GetTopic(m_serverInst, "/foo"), wpi::nt::EventFlags::kUnpublish);
|
||||
poller, wpi::nt::GetTopic(m_serverInst, "/foo"),
|
||||
wpi::nt::EventFlags::kUnpublish);
|
||||
|
||||
auto pub =
|
||||
wpi::nt::Publish(wpi::nt::GetTopic(m_clientInst, "/foo"), NT_DOUBLE, "double");
|
||||
auto pub = 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));
|
||||
|
||||
@@ -189,8 +197,8 @@ TEST_F(TopicListenerTest, TopicPropertiesLocal) {
|
||||
auto topic = wpi::nt::GetTopic(m_serverInst, "/foo");
|
||||
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle =
|
||||
wpi::nt::AddPolledListener(poller, topic, wpi::nt::EventFlags::kProperties);
|
||||
auto handle = wpi::nt::AddPolledListener(poller, topic,
|
||||
wpi::nt::EventFlags::kProperties);
|
||||
|
||||
wpi::nt::SetTopicProperty(topic, "foo", 5);
|
||||
|
||||
@@ -206,11 +214,13 @@ TEST_F(TopicListenerTest, DISABLED_TopicPropertiesRemote) {
|
||||
return;
|
||||
}
|
||||
// the topic needs to actually exist
|
||||
wpi::nt::Publish(wpi::nt::GetTopic(m_serverInst, "/foo"), NT_BOOLEAN, "boolean");
|
||||
wpi::nt::Publish(wpi::nt::GetTopic(m_serverInst, "/foo"), NT_BOOLEAN,
|
||||
"boolean");
|
||||
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle = wpi::nt::AddPolledListener(
|
||||
poller, wpi::nt::GetTopic(m_serverInst, "/foo"), wpi::nt::EventFlags::kProperties);
|
||||
poller, wpi::nt::GetTopic(m_serverInst, "/foo"),
|
||||
wpi::nt::EventFlags::kProperties);
|
||||
wpi::nt::FlushLocal(m_serverInst);
|
||||
|
||||
wpi::nt::SetTopicProperty(wpi::nt::GetTopic(m_clientInst, "/foo"), "foo", 5);
|
||||
@@ -225,8 +235,8 @@ TEST_F(TopicListenerTest, DISABLED_TopicPropertiesRemote) {
|
||||
|
||||
TEST_F(TopicListenerTest, PrefixPublishLocal) {
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle =
|
||||
wpi::nt::AddPolledListener(poller, {{"/foo/"}}, wpi::nt::EventFlags::kPublish);
|
||||
auto handle = wpi::nt::AddPolledListener(poller, {{"/foo/"}},
|
||||
wpi::nt::EventFlags::kPublish);
|
||||
|
||||
PublishTopics(m_serverInst);
|
||||
|
||||
@@ -242,8 +252,8 @@ TEST_F(TopicListenerTest, DISABLED_PrefixPublishRemote) {
|
||||
return;
|
||||
}
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
auto handle =
|
||||
wpi::nt::AddPolledListener(poller, {{"/foo/"}}, wpi::nt::EventFlags::kPublish);
|
||||
auto handle = wpi::nt::AddPolledListener(poller, {{"/foo/"}},
|
||||
wpi::nt::EventFlags::kPublish);
|
||||
|
||||
PublishTopics(m_clientInst);
|
||||
|
||||
@@ -276,9 +286,9 @@ TEST_F(TopicListenerTest, PrefixUnpublishPropsImm) {
|
||||
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_serverInst);
|
||||
wpi::nt::AddPolledListener(poller, {{"/foo/"}},
|
||||
wpi::nt::EventFlags::kUnpublish |
|
||||
wpi::nt::EventFlags::kProperties |
|
||||
wpi::nt::EventFlags::kImmediate);
|
||||
wpi::nt::EventFlags::kUnpublish |
|
||||
wpi::nt::EventFlags::kProperties |
|
||||
wpi::nt::EventFlags::kImmediate);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_FALSE(wpi::util::WaitForObject(poller, 0.02, &timedOut));
|
||||
|
||||
@@ -37,9 +37,12 @@ TEST_F(ValueListenerTest, MultiPollSub) {
|
||||
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);
|
||||
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);
|
||||
|
||||
wpi::nt::SetDouble(pub, 0);
|
||||
|
||||
@@ -89,8 +92,10 @@ TEST_F(ValueListenerTest, PollMultiSub) {
|
||||
auto sub2 = wpi::nt::Subscribe(topic, NT_DOUBLE, "double");
|
||||
|
||||
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);
|
||||
auto h1 = wpi::nt::AddPolledListener(poller, sub1,
|
||||
wpi::nt::EventFlags::kValueLocal);
|
||||
auto h2 = wpi::nt::AddPolledListener(poller, sub2,
|
||||
wpi::nt::EventFlags::kValueLocal);
|
||||
|
||||
wpi::nt::SetDouble(pub, 0);
|
||||
|
||||
@@ -126,8 +131,10 @@ TEST_F(ValueListenerTest, PollMultiSubTopic) {
|
||||
auto sub2 = wpi::nt::Subscribe(topic2, NT_DOUBLE, "double");
|
||||
|
||||
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);
|
||||
auto h1 = wpi::nt::AddPolledListener(poller, sub1,
|
||||
wpi::nt::EventFlags::kValueLocal);
|
||||
auto h2 = wpi::nt::AddPolledListener(poller, sub2,
|
||||
wpi::nt::EventFlags::kValueLocal);
|
||||
|
||||
wpi::nt::SetDouble(pub1, 0);
|
||||
wpi::nt::SetDouble(pub2, 1);
|
||||
@@ -163,7 +170,8 @@ TEST_F(ValueListenerTest, PollSubMultiple) {
|
||||
auto sub = wpi::nt::SubscribeMultiple(m_inst, {{"foo"}});
|
||||
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto h = wpi::nt::AddPolledListener(poller, sub, wpi::nt::EventFlags::kValueLocal);
|
||||
auto h =
|
||||
wpi::nt::AddPolledListener(poller, sub, wpi::nt::EventFlags::kValueLocal);
|
||||
|
||||
wpi::nt::SetDouble(pub1, 0);
|
||||
wpi::nt::SetDouble(pub2, 1);
|
||||
@@ -193,8 +201,8 @@ TEST_F(ValueListenerTest, PollSubMultiple) {
|
||||
|
||||
TEST_F(ValueListenerTest, PollSubPrefixCreated) {
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto h =
|
||||
wpi::nt::AddPolledListener(poller, {{"foo"}}, wpi::nt::EventFlags::kValueLocal);
|
||||
auto h = wpi::nt::AddPolledListener(poller, {{"foo"}},
|
||||
wpi::nt::EventFlags::kValueLocal);
|
||||
|
||||
auto topic1 = wpi::nt::GetTopic(m_inst, "foo/1");
|
||||
auto topic2 = wpi::nt::GetTopic(m_inst, "foo/2");
|
||||
@@ -232,7 +240,8 @@ TEST_F(ValueListenerTest, PollEntry) {
|
||||
auto entry = wpi::nt::GetEntry(m_inst, "foo");
|
||||
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto h = wpi::nt::AddPolledListener(poller, entry, wpi::nt::EventFlags::kValueLocal);
|
||||
auto h = wpi::nt::AddPolledListener(poller, entry,
|
||||
wpi::nt::EventFlags::kValueLocal);
|
||||
|
||||
ASSERT_TRUE(wpi::nt::SetDouble(entry, 0));
|
||||
|
||||
@@ -257,7 +266,8 @@ TEST_F(ValueListenerTest, PollImmediate) {
|
||||
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto h = wpi::nt::AddPolledListener(
|
||||
poller, entry, wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
|
||||
poller, entry,
|
||||
wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
@@ -265,8 +275,8 @@ TEST_F(ValueListenerTest, PollImmediate) {
|
||||
auto results = wpi::nt::ReadListenerQueue(poller);
|
||||
|
||||
ASSERT_EQ(results.size(), 1u);
|
||||
EXPECT_EQ(results[0].flags &
|
||||
(wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate),
|
||||
EXPECT_EQ(results[0].flags & (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();
|
||||
@@ -281,7 +291,8 @@ TEST_F(ValueListenerTest, PollImmediateNoValue) {
|
||||
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto h = wpi::nt::AddPolledListener(
|
||||
poller, entry, wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
|
||||
poller, entry,
|
||||
wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_FALSE(wpi::util::WaitForObject(poller, 0.02, &timedOut));
|
||||
@@ -317,7 +328,8 @@ TEST_F(ValueListenerTest, PollImmediateSubMultiple) {
|
||||
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto h = wpi::nt::AddPolledListener(
|
||||
poller, sub, wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
|
||||
poller, sub,
|
||||
wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate);
|
||||
|
||||
bool timedOut = false;
|
||||
ASSERT_TRUE(wpi::util::WaitForObject(poller, 1.0, &timedOut));
|
||||
@@ -325,8 +337,8 @@ TEST_F(ValueListenerTest, PollImmediateSubMultiple) {
|
||||
auto results = wpi::nt::ReadListenerQueue(poller);
|
||||
|
||||
ASSERT_EQ(results.size(), 2u);
|
||||
EXPECT_EQ(results[0].flags &
|
||||
(wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate),
|
||||
EXPECT_EQ(results[0].flags & (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();
|
||||
@@ -335,8 +347,8 @@ TEST_F(ValueListenerTest, PollImmediateSubMultiple) {
|
||||
EXPECT_EQ(valueData->topic, topic1);
|
||||
EXPECT_EQ(valueData->value, wpi::nt::Value::MakeDouble(0.0));
|
||||
|
||||
EXPECT_EQ(results[1].flags &
|
||||
(wpi::nt::EventFlags::kValueLocal | wpi::nt::EventFlags::kImmediate),
|
||||
EXPECT_EQ(results[1].flags & (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();
|
||||
@@ -354,7 +366,8 @@ TEST_F(ValueListenerTest, TwoSubOneListener) {
|
||||
auto sub3 = wpi::nt::SubscribeMultiple(m_inst, {{"foo"}});
|
||||
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto h = wpi::nt::AddPolledListener(poller, sub1, wpi::nt::EventFlags::kValueLocal);
|
||||
auto h = wpi::nt::AddPolledListener(poller, sub1,
|
||||
wpi::nt::EventFlags::kValueLocal);
|
||||
(void)sub2;
|
||||
(void)sub3;
|
||||
|
||||
@@ -384,7 +397,8 @@ TEST_F(ValueListenerTest, TwoSubOneMultiListener) {
|
||||
auto sub3 = wpi::nt::SubscribeMultiple(m_inst, {{"foo"}});
|
||||
|
||||
auto poller = wpi::nt::CreateListenerPoller(m_inst);
|
||||
auto h = wpi::nt::AddPolledListener(poller, sub3, wpi::nt::EventFlags::kValueLocal);
|
||||
auto h = wpi::nt::AddPolledListener(poller, sub3,
|
||||
wpi::nt::EventFlags::kValueLocal);
|
||||
(void)sub1;
|
||||
(void)sub2;
|
||||
|
||||
|
||||
@@ -10,12 +10,13 @@
|
||||
#include "wpi/util/timestamp.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
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);
|
||||
}
|
||||
});
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
int ret = RUN_ALL_TESTS();
|
||||
return ret;
|
||||
|
||||
@@ -17,11 +17,13 @@ class MockClientMessageHandler : public net::ClientMessageHandler {
|
||||
public:
|
||||
MOCK_METHOD(void, ClientPublish,
|
||||
(int pubuid, std::string_view name, std::string_view typeStr,
|
||||
const wpi::util::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::util::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),
|
||||
|
||||
@@ -25,28 +25,30 @@ class MockWireConnection : public WireConnection {
|
||||
|
||||
MOCK_METHOD(bool, Ready, (), (const, override));
|
||||
|
||||
int WriteText(wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) override {
|
||||
int WriteText(wpi::util::function_ref<void(wpi::util::raw_ostream& os)>
|
||||
writer) override {
|
||||
std::string text;
|
||||
wpi::util::raw_string_ostream os{text};
|
||||
writer(os);
|
||||
return DoWriteText(text);
|
||||
}
|
||||
int WriteBinary(
|
||||
wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) override {
|
||||
int WriteBinary(wpi::util::function_ref<void(wpi::util::raw_ostream& os)>
|
||||
writer) override {
|
||||
std::vector<uint8_t> binary;
|
||||
wpi::util::raw_uvector_ostream os{binary};
|
||||
writer(os);
|
||||
return DoWriteBinary(binary);
|
||||
}
|
||||
|
||||
void SendText(wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) override {
|
||||
void SendText(wpi::util::function_ref<void(wpi::util::raw_ostream& os)>
|
||||
writer) override {
|
||||
std::string text;
|
||||
wpi::util::raw_string_ostream os{text};
|
||||
writer(os);
|
||||
DoSendText(text);
|
||||
}
|
||||
void SendBinary(
|
||||
wpi::util::function_ref<void(wpi::util::raw_ostream& os)> writer) override {
|
||||
void SendBinary(wpi::util::function_ref<void(wpi::util::raw_ostream& os)>
|
||||
writer) override {
|
||||
std::vector<uint8_t> binary;
|
||||
wpi::util::raw_uvector_ostream os{binary};
|
||||
writer(os);
|
||||
|
||||
@@ -108,17 +108,19 @@ TEST_F(WireDecodeTextClientTest, ErrorUnknownMethod) {
|
||||
}
|
||||
|
||||
TEST_F(WireDecodeTextClientTest, PublishPropsEmpty) {
|
||||
EXPECT_CALL(handler, ClientPublish(5, std::string_view{"test"},
|
||||
std::string_view{"double"},
|
||||
wpi::util::json::object(), PubSubOptionsEq({})));
|
||||
EXPECT_CALL(
|
||||
handler,
|
||||
ClientPublish(5, std::string_view{"test"}, std::string_view{"double"},
|
||||
wpi::util::json::object(), PubSubOptionsEq({})));
|
||||
net::WireDecodeText(
|
||||
"[{\"method\":\"publish\",\"params\":{"
|
||||
"\"name\":\"test\",\"properties\":{},\"pubuid\":5,\"type\":\"double\"}}]",
|
||||
handler, logger);
|
||||
|
||||
EXPECT_CALL(handler, ClientPublish(5, std::string_view{"test"},
|
||||
std::string_view{"double"},
|
||||
wpi::util::json::object(), PubSubOptionsEq({})));
|
||||
EXPECT_CALL(
|
||||
handler,
|
||||
ClientPublish(5, std::string_view{"test"}, std::string_view{"double"},
|
||||
wpi::util::json::object(), PubSubOptionsEq({})));
|
||||
net::WireDecodeText(
|
||||
"[{\"method\":\"publish\",\"params\":{"
|
||||
"\"name\":\"test\",\"pubuid\":5,\"type\":\"double\"}}]",
|
||||
|
||||
@@ -128,7 +128,8 @@ TEST_F(WireEncoderTextTest, AnnounceProperties) {
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderTextTest, AnnouncePubuid) {
|
||||
net::WireEncodeAnnounce(os, "test", 5, "double", wpi::util::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\"}}");
|
||||
@@ -179,8 +180,8 @@ TEST_F(WireEncoderTextTest, MessageUnsubscribe) {
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderTextTest, MessageAnnounce) {
|
||||
net::ServerMessage msg{
|
||||
net::AnnounceMsg{"test", 5, "double", std::nullopt, wpi::util::json::object()}};
|
||||
net::ServerMessage msg{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\","
|
||||
@@ -234,14 +235,15 @@ TEST_F(WireEncoderBinaryTest, Integer) {
|
||||
|
||||
TEST_F(WireEncoderBinaryTest, Float) {
|
||||
net::WireEncodeBinary(os, 5, 6, Value::MakeFloat(2.5));
|
||||
ASSERT_THAT(out, wpi::util::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::util::SpanEq("\x94\x05\x06\x01\xcb\x40\x04\x00\x00\x00\x00\x00\x00"_us));
|
||||
ASSERT_THAT(out,
|
||||
wpi::util::SpanEq(
|
||||
"\x94\x05\x06\x01\xcb\x40\x04\x00\x00\x00\x00\x00\x00"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderBinaryTest, String) {
|
||||
@@ -267,23 +269,24 @@ TEST_F(WireEncoderBinaryTest, IntegerArray) {
|
||||
TEST_F(WireEncoderBinaryTest, FloatArray) {
|
||||
net::WireEncodeBinary(os, 5, 6, Value::MakeFloatArray({1, 2, 3}));
|
||||
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));
|
||||
"\xca\x3f\x80\x00\x00"
|
||||
"\xca\x40\x00\x00\x00"
|
||||
"\xca\x40\x40\x00\x00"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderBinaryTest, DoubleArray) {
|
||||
net::WireEncodeBinary(os, 5, 6, Value::MakeDoubleArray({1, 2, 3}));
|
||||
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));
|
||||
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));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderBinaryTest, StringArray) {
|
||||
net::WireEncodeBinary(os, 5, 6, Value::MakeStringArray({"hello", "bye"}));
|
||||
ASSERT_THAT(out, wpi::util::SpanEq("\x94\x05\x06\x14\x92\xa5hello\xa3"
|
||||
"bye"_us));
|
||||
"bye"_us));
|
||||
}
|
||||
|
||||
} // namespace wpi::nt
|
||||
|
||||
@@ -167,8 +167,8 @@ TEST_F(ServerImplTest, PublishLocal) {
|
||||
}
|
||||
|
||||
{
|
||||
queue.msgs.emplace_back(net::ClientMessage{
|
||||
net::PublishMsg{pubuid, "test", "double", wpi::util::json::object(), {}}});
|
||||
queue.msgs.emplace_back(net::ClientMessage{net::PublishMsg{
|
||||
pubuid, "test", "double", wpi::util::json::object(), {}}});
|
||||
EXPECT_FALSE(server.ProcessLocalMessages(UINT_MAX));
|
||||
}
|
||||
|
||||
@@ -186,18 +186,21 @@ TEST_F(ServerImplTest, PublishLocal) {
|
||||
EXPECT_CALL(wire, SendPing(100));
|
||||
EXPECT_CALL(wire, Ready()).WillOnce(Return(true)); // SendControl()
|
||||
EXPECT_CALL(
|
||||
wire, DoWriteText(StrEq(EncodeText1(net::ServerMessage{net::AnnounceMsg{
|
||||
"test", 3, "double", std::nullopt, wpi::util::json::object()}}))))
|
||||
wire,
|
||||
DoWriteText(StrEq(EncodeText1(net::ServerMessage{net::AnnounceMsg{
|
||||
"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::util::json::object()}}))))
|
||||
wire,
|
||||
DoWriteText(StrEq(EncodeText1(net::ServerMessage{net::AnnounceMsg{
|
||||
"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::util::json::object()}}))))
|
||||
wire,
|
||||
DoWriteText(StrEq(EncodeText1(net::ServerMessage{net::AnnounceMsg{
|
||||
"test3", 11, "double", std::nullopt, wpi::util::json::object()}}))))
|
||||
.WillOnce(Return(0));
|
||||
EXPECT_CALL(wire, Flush()).WillOnce(Return(0)); // SendControl()
|
||||
}
|
||||
@@ -214,8 +217,8 @@ TEST_F(ServerImplTest, PublishLocal) {
|
||||
|
||||
// publish before send control
|
||||
{
|
||||
queue.msgs.emplace_back(net::ClientMessage{
|
||||
net::PublishMsg{pubuid2, "test2", "double", wpi::util::json::object(), {}}});
|
||||
queue.msgs.emplace_back(net::ClientMessage{net::PublishMsg{
|
||||
pubuid2, "test2", "double", wpi::util::json::object(), {}}});
|
||||
EXPECT_FALSE(server.ProcessLocalMessages(UINT_MAX));
|
||||
}
|
||||
|
||||
@@ -223,8 +226,8 @@ TEST_F(ServerImplTest, PublishLocal) {
|
||||
|
||||
// publish after send control
|
||||
{
|
||||
queue.msgs.emplace_back(net::ClientMessage{
|
||||
net::PublishMsg{pubuid3, "test3", "double", wpi::util::json::object(), {}}});
|
||||
queue.msgs.emplace_back(net::ClientMessage{net::PublishMsg{
|
||||
pubuid3, "test3", "double", wpi::util::json::object(), {}}});
|
||||
EXPECT_FALSE(server.ProcessLocalMessages(UINT_MAX));
|
||||
}
|
||||
|
||||
@@ -241,8 +244,8 @@ TEST_F(ServerImplTest, ClientSubTopicOnlyThenValue) {
|
||||
wpi::util::json::object(), std::optional<int>{pubuid}));
|
||||
|
||||
{
|
||||
queue.msgs.emplace_back(net::ClientMessage{
|
||||
net::PublishMsg{pubuid, "test", "double", wpi::util::json::object(), {}}});
|
||||
queue.msgs.emplace_back(net::ClientMessage{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));
|
||||
@@ -260,16 +263,18 @@ TEST_F(ServerImplTest, ClientSubTopicOnlyThenValue) {
|
||||
EXPECT_CALL(wire, SendPing(100));
|
||||
EXPECT_CALL(wire, Ready()).WillOnce(Return(true)); // SendValues()
|
||||
EXPECT_CALL(
|
||||
wire, DoWriteText(StrEq(EncodeText1(net::ServerMessage{net::AnnounceMsg{
|
||||
"test", 3, "double", std::nullopt, wpi::util::json::object()}}))))
|
||||
wire,
|
||||
DoWriteText(StrEq(EncodeText1(net::ServerMessage{net::AnnounceMsg{
|
||||
"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::util::SpanEq(EncodeServerBinary1(net::ServerMessage{
|
||||
net::ServerValueMsg{3, Value::MakeDouble(1.0, 10)}}))))
|
||||
wire,
|
||||
DoWriteBinary(wpi::util::SpanEq(EncodeServerBinary1(net::ServerMessage{
|
||||
net::ServerValueMsg{3, Value::MakeDouble(1.0, 10)}}))))
|
||||
.WillOnce(Return(0));
|
||||
EXPECT_CALL(wire, Flush()); // SendValues()
|
||||
}
|
||||
@@ -309,10 +314,10 @@ TEST_F(ServerImplTest, ClientDisconnectUnpublish) {
|
||||
constexpr int subuid = 1;
|
||||
{
|
||||
::testing::InSequence seq;
|
||||
EXPECT_CALL(
|
||||
local,
|
||||
ServerAnnounce(std::string_view{"test2"}, 0, std::string_view{"double"},
|
||||
wpi::util::json::object(), std::optional<int>{pubuidLocal}));
|
||||
EXPECT_CALL(local, ServerAnnounce(std::string_view{"test2"}, 0,
|
||||
std::string_view{"double"},
|
||||
wpi::util::json::object(),
|
||||
std::optional<int>{pubuidLocal}));
|
||||
EXPECT_CALL(
|
||||
local,
|
||||
ServerAnnounce(std::string_view{"test"}, 0, std::string_view{"double"},
|
||||
@@ -357,8 +362,8 @@ TEST_F(ServerImplTest, ClientDisconnectUnpublish) {
|
||||
{
|
||||
constexpr int pubuid = 1;
|
||||
std::vector<net::ClientMessage> msgs;
|
||||
msgs.emplace_back(net::ClientMessage{
|
||||
net::PublishMsg{pubuid, "test", "double", wpi::util::json::object(), {}}});
|
||||
msgs.emplace_back(net::ClientMessage{net::PublishMsg{
|
||||
pubuid, "test", "double", wpi::util::json::object(), {}}});
|
||||
server.ProcessIncomingText(id, EncodeText(msgs));
|
||||
}
|
||||
|
||||
@@ -390,8 +395,8 @@ TEST_F(ServerImplTest, ZeroTimestampNegativeTime) {
|
||||
}
|
||||
|
||||
{
|
||||
queue.msgs.emplace_back(net::ClientMessage{
|
||||
net::PublishMsg{pubuid, "test", "double", wpi::util::json::object(), {}}});
|
||||
queue.msgs.emplace_back(net::ClientMessage{net::PublishMsg{
|
||||
pubuid, "test", "double", wpi::util::json::object(), {}}});
|
||||
queue.msgs.emplace_back(
|
||||
net::ClientMessage{net::ClientValueMsg{pubuid, defaultValue}});
|
||||
queue.msgs.emplace_back(
|
||||
@@ -414,8 +419,8 @@ TEST_F(ServerImplTest, ZeroTimestampNegativeTime) {
|
||||
{
|
||||
constexpr int pubuid2 = 2;
|
||||
std::vector<net::ClientMessage> msgs;
|
||||
msgs.emplace_back(net::ClientMessage{
|
||||
net::PublishMsg{pubuid2, "test", "double", wpi::util::json::object(), {}}});
|
||||
msgs.emplace_back(net::ClientMessage{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}});
|
||||
|
||||
Reference in New Issue
Block a user