mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
Update for jart/json.cpp change
This commit is contained in:
@@ -144,11 +144,12 @@ TEST_F(LocalStorageTest, PublishNewNoPropsNull) {
|
||||
}
|
||||
|
||||
TEST_F(LocalStorageTest, PublishNew) {
|
||||
wpi::util::json properties = {{"persistent", true}};
|
||||
auto properties = wpi::util::json::object("persistent", true);
|
||||
EXPECT_CALL(network, ClientPublish(_, std::string_view{"foo"},
|
||||
std::string_view{"boolean"}, properties,
|
||||
IsDefaultPubSubOptions()));
|
||||
storage.Publish(fooTopic, NT_BOOLEAN, "boolean", {{"persistent", true}}, {});
|
||||
storage.Publish(fooTopic, NT_BOOLEAN, "boolean",
|
||||
wpi::util::json::object("persistent", true), {});
|
||||
|
||||
auto info = storage.GetTopicInfo(fooTopic);
|
||||
EXPECT_EQ(info.topic, fooTopic);
|
||||
@@ -645,7 +646,8 @@ TEST_F(LocalStorageDuplicatesTest, FromNetworkDefault) {
|
||||
SetupPubSub(false, false);
|
||||
|
||||
// incoming from the network are treated like a normal local publish
|
||||
auto topic = storage.ServerAnnounce("foo", 0, "double", {{}}, std::nullopt);
|
||||
auto topic = storage.ServerAnnounce("foo", 0, "double",
|
||||
wpi::util::json::object(), std::nullopt);
|
||||
storage.ServerSetValue(topic, val1);
|
||||
storage.ServerSetValue(topic, val2);
|
||||
// verify the timestamp was updated
|
||||
@@ -665,7 +667,8 @@ TEST_F(LocalStorageDuplicatesTest, FromNetworkKeepPub) {
|
||||
SetupPubSub(true, false);
|
||||
|
||||
// incoming from the network are treated like a normal local publish
|
||||
auto topic = storage.ServerAnnounce("foo", 0, "double", {{}}, std::nullopt);
|
||||
auto topic = storage.ServerAnnounce("foo", 0, "double",
|
||||
wpi::util::json::object(), std::nullopt);
|
||||
storage.ServerSetValue(topic, val1);
|
||||
storage.ServerSetValue(topic, val2);
|
||||
// verify the timestamp was updated
|
||||
@@ -684,7 +687,8 @@ TEST_F(LocalStorageDuplicatesTest, FromNetworkKeepSub) {
|
||||
SetupPubSub(false, true);
|
||||
|
||||
// incoming from the network are treated like a normal local publish
|
||||
auto topic = storage.ServerAnnounce("foo", 0, "double", {{}}, std::nullopt);
|
||||
auto topic = storage.ServerAnnounce("foo", 0, "double",
|
||||
wpi::util::json::object(), std::nullopt);
|
||||
storage.ServerSetValue(topic, val1);
|
||||
storage.ServerSetValue(topic, val2);
|
||||
// verify the timestamp was updated
|
||||
@@ -706,7 +710,8 @@ TEST_F(LocalStorageDuplicatesTest, FromNetworkKeepPubSub) {
|
||||
SetupPubSub(true, true);
|
||||
|
||||
// incoming from the network are treated like a normal local publish
|
||||
auto topic = storage.ServerAnnounce("foo", 0, "double", {{}}, std::nullopt);
|
||||
auto topic = storage.ServerAnnounce("foo", 0, "double",
|
||||
wpi::util::json::object(), std::nullopt);
|
||||
storage.ServerSetValue(topic, val1);
|
||||
storage.ServerSetValue(topic, val2);
|
||||
// verify the timestamp was updated
|
||||
|
||||
@@ -342,7 +342,8 @@ TEST_F(StructTest, InnerArrayNonconstexpr) {
|
||||
TEST_F(StructTest, StructA) {
|
||||
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::StructPublisher<ThingA> pub2 =
|
||||
topic.PublishEx(wpi::util::json::object());
|
||||
wpi::nt::StructSubscriber<ThingA> sub = topic.Subscribe({});
|
||||
wpi::nt::StructEntry<ThingA> entry = topic.GetEntry({});
|
||||
pub.SetDefault({});
|
||||
@@ -360,7 +361,8 @@ TEST_F(StructTest, StructArrayA) {
|
||||
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::StructArrayPublisher<ThingA> pub2 =
|
||||
topic.PublishEx(wpi::util::json::object());
|
||||
wpi::nt::StructArraySubscriber<ThingA> sub = topic.Subscribe({});
|
||||
wpi::nt::StructArrayEntry<ThingA> entry = topic.GetEntry({});
|
||||
pub.SetDefault({{ThingA{}, ThingA{}}});
|
||||
@@ -378,7 +380,8 @@ TEST_F(StructTest, StructFixedArrayA) {
|
||||
wpi::nt::StructTopic<std::array<ThingA, 2>> topic =
|
||||
inst.GetStructTopic<std::array<ThingA, 2>>("a");
|
||||
wpi::nt::StructPublisher<std::array<ThingA, 2>> pub = topic.Publish();
|
||||
wpi::nt::StructPublisher<std::array<ThingA, 2>> pub2 = topic.PublishEx({{}});
|
||||
wpi::nt::StructPublisher<std::array<ThingA, 2>> pub2 =
|
||||
topic.PublishEx(wpi::util::json::object());
|
||||
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;
|
||||
@@ -398,7 +401,8 @@ TEST_F(StructTest, StructB) {
|
||||
wpi::nt::StructTopic<ThingB, Info1> topic =
|
||||
inst.GetStructTopic<ThingB, Info1>("b", info);
|
||||
wpi::nt::StructPublisher<ThingB, Info1> pub = topic.Publish();
|
||||
wpi::nt::StructPublisher<ThingB, Info1> pub2 = topic.PublishEx({{}});
|
||||
wpi::nt::StructPublisher<ThingB, Info1> pub2 =
|
||||
topic.PublishEx(wpi::util::json::object());
|
||||
wpi::nt::StructSubscriber<ThingB, Info1> sub = topic.Subscribe({});
|
||||
wpi::nt::StructEntry<ThingB, Info1> entry = topic.GetEntry({});
|
||||
pub.SetDefault({});
|
||||
@@ -417,7 +421,8 @@ TEST_F(StructTest, StructArrayB) {
|
||||
wpi::nt::StructArrayTopic<ThingB, Info1> topic =
|
||||
inst.GetStructArrayTopic<ThingB, Info1>("b", info);
|
||||
wpi::nt::StructArrayPublisher<ThingB, Info1> pub = topic.Publish();
|
||||
wpi::nt::StructArrayPublisher<ThingB, Info1> pub2 = topic.PublishEx({{}});
|
||||
wpi::nt::StructArrayPublisher<ThingB, Info1> pub2 =
|
||||
topic.PublishEx(wpi::util::json::object());
|
||||
wpi::nt::StructArraySubscriber<ThingB, Info1> sub = topic.Subscribe({});
|
||||
wpi::nt::StructArrayEntry<ThingB, Info1> entry = topic.GetEntry({});
|
||||
pub.SetDefault({{ThingB{}, ThingB{}}});
|
||||
@@ -437,7 +442,7 @@ TEST_F(StructTest, StructFixedArrayB) {
|
||||
inst.GetStructTopic<std::array<ThingB, 2>, Info1>("b", info);
|
||||
wpi::nt::StructPublisher<std::array<ThingB, 2>, Info1> pub = topic.Publish();
|
||||
wpi::nt::StructPublisher<std::array<ThingB, 2>, Info1> pub2 =
|
||||
topic.PublishEx({{}});
|
||||
topic.PublishEx(wpi::util::json::object());
|
||||
wpi::nt::StructSubscriber<std::array<ThingB, 2>, Info1> sub =
|
||||
topic.Subscribe({});
|
||||
wpi::nt::StructEntry<std::array<ThingB, 2>, Info1> entry = topic.GetEntry({});
|
||||
|
||||
@@ -43,33 +43,20 @@ TEST_F(WireDecodeTextClientTest, EmptyArray) {
|
||||
}
|
||||
|
||||
TEST_F(WireDecodeTextClientTest, ErrorEmpty) {
|
||||
EXPECT_CALL(
|
||||
logger,
|
||||
Call(_, _, _,
|
||||
"could not decode JSON message: [json.exception.parse_error.101] "
|
||||
"parse error at line 1, column 1: attempting to parse an empty "
|
||||
"input; check that your input string or stream contains the "
|
||||
"expected JSON"sv));
|
||||
EXPECT_CALL(logger,
|
||||
Call(_, _, _, "could not decode JSON message: absent_value"sv));
|
||||
net::WireDecodeText("", handler, logger);
|
||||
}
|
||||
|
||||
TEST_F(WireDecodeTextClientTest, ErrorBadJson1) {
|
||||
EXPECT_CALL(
|
||||
logger,
|
||||
Call(_, _, _,
|
||||
"could not decode JSON message: [json.exception.parse_error.101] "
|
||||
"parse error at line 1, column 2: syntax error while parsing value "
|
||||
"- unexpected end of input; expected '[', '{', or a literal"sv));
|
||||
EXPECT_CALL(logger,
|
||||
Call(_, _, _, "could not decode JSON message: unexpected_eof"sv));
|
||||
net::WireDecodeText("[", handler, logger);
|
||||
}
|
||||
|
||||
TEST_F(WireDecodeTextClientTest, ErrorBadJson2) {
|
||||
EXPECT_CALL(
|
||||
logger,
|
||||
Call(_, _, _,
|
||||
"could not decode JSON message: [json.exception.parse_error.101] "
|
||||
"parse error at line 1, column 3: syntax error while parsing object "
|
||||
"key - unexpected end of input; expected string literal"sv));
|
||||
EXPECT_CALL(logger,
|
||||
Call(_, _, _, "could not decode JSON message: unexpected_eof"sv));
|
||||
net::WireDecodeText("[{", handler, logger);
|
||||
}
|
||||
|
||||
@@ -129,7 +116,7 @@ TEST_F(WireDecodeTextClientTest, PublishPropsEmpty) {
|
||||
}
|
||||
|
||||
TEST_F(WireDecodeTextClientTest, PublishProps) {
|
||||
wpi::util::json props = {{"k", 6}};
|
||||
auto props = wpi::util::json::object("k", 6);
|
||||
EXPECT_CALL(handler, ClientPublish(5, std::string_view{"test"},
|
||||
std::string_view{"double"}, props,
|
||||
PubSubOptionsEq({})));
|
||||
|
||||
@@ -29,7 +29,9 @@ class WireEncoderTextTest : public ::testing::Test {
|
||||
protected:
|
||||
std::string out;
|
||||
wpi::util::raw_string_ostream os{out};
|
||||
wpi::util::json GetJson() { return wpi::util::json::parse(os.str()); }
|
||||
wpi::util::json GetJson() {
|
||||
return wpi::util::json::parse(os.str()).value_or(wpi::util::json::object());
|
||||
}
|
||||
};
|
||||
|
||||
class WireEncoderBinaryTest : public ::testing::Test {
|
||||
@@ -47,7 +49,8 @@ TEST_F(WireEncoderTextTest, PublishPropsEmpty) {
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderTextTest, PublishProps) {
|
||||
net::WireEncodePublish(os, 5, "test", "double", {{"k", 6}});
|
||||
net::WireEncodePublish(os, 5, "test", "double",
|
||||
wpi::util::json::object("k", 6));
|
||||
ASSERT_EQ(os.str(),
|
||||
"{\"method\":\"publish\",\"params\":{"
|
||||
"\"name\":\"test\",\"properties\":{\"k\":6},"
|
||||
@@ -60,7 +63,7 @@ TEST_F(WireEncoderTextTest, Unpublish) {
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderTextTest, SetProperties) {
|
||||
net::WireEncodeSetProperties(os, "test", {{"k", 6}});
|
||||
net::WireEncodeSetProperties(os, "test", wpi::util::json::object("k", 6));
|
||||
ASSERT_EQ(os.str(),
|
||||
"{\"method\":\"setproperties\",\"params\":{"
|
||||
"\"name\":\"test\",\"update\":{\"k\":6}}}");
|
||||
@@ -122,7 +125,8 @@ TEST_F(WireEncoderTextTest, Announce) {
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderTextTest, AnnounceProperties) {
|
||||
net::WireEncodeAnnounce(os, "test", 5, "double", {{"k", 6}}, std::nullopt);
|
||||
net::WireEncodeAnnounce(os, "test", 5, "double",
|
||||
wpi::util::json::object("k", 6), std::nullopt);
|
||||
ASSERT_EQ(os.str(),
|
||||
"{\"method\":\"announce\",\"params\":{\"id\":5,\"name\":\"test\","
|
||||
"\"properties\":{\"k\":6},\"type\":\"double\"}}");
|
||||
@@ -144,7 +148,8 @@ TEST_F(WireEncoderTextTest, Unannounce) {
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderTextTest, MessagePublish) {
|
||||
net::ClientMessage msg{net::PublishMsg{5, "test", "double", {{"k", 6}}, {}}};
|
||||
net::ClientMessage msg{net::PublishMsg{
|
||||
5, "test", "double", wpi::util::json::object("k", 6), {}}};
|
||||
ASSERT_TRUE(net::WireEncodeText(os, msg));
|
||||
ASSERT_EQ(os.str(),
|
||||
"{\"method\":\"publish\",\"params\":{"
|
||||
@@ -159,7 +164,8 @@ TEST_F(WireEncoderTextTest, MessageUnpublish) {
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderTextTest, MessageSetProperties) {
|
||||
net::ClientMessage msg{net::SetPropertiesMsg{"test", {{"k", 6}}}};
|
||||
net::ClientMessage msg{
|
||||
net::SetPropertiesMsg{"test", wpi::util::json::object("k", 6)}};
|
||||
ASSERT_TRUE(net::WireEncodeText(os, msg));
|
||||
ASSERT_EQ(os.str(),
|
||||
"{\"method\":\"setproperties\",\"params\":{"
|
||||
@@ -190,8 +196,8 @@ TEST_F(WireEncoderTextTest, MessageAnnounce) {
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderTextTest, MessageAnnounceProperties) {
|
||||
net::ServerMessage msg{
|
||||
net::AnnounceMsg{"test", 5, "double", std::nullopt, {{"k", 6}}}};
|
||||
net::ServerMessage msg{net::AnnounceMsg{"test", 5, "double", std::nullopt,
|
||||
wpi::util::json::object("k", 6)}};
|
||||
ASSERT_TRUE(net::WireEncodeText(os, msg));
|
||||
ASSERT_EQ(os.str(),
|
||||
"{\"method\":\"announce\",\"params\":{\"id\":5,\"name\":\"test\","
|
||||
|
||||
Reference in New Issue
Block a user