[ntcore] NetworkTables 4 (#3217)

This commit is contained in:
Peter Johnson
2022-10-08 10:01:31 -07:00
committed by GitHub
parent 90cfa00115
commit 77301b126c
380 changed files with 34573 additions and 22095 deletions

View File

@@ -0,0 +1,86 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <string>
#include <wpi/json.h>
#include "PubSubOptions.h"
#include "gmock/gmock.h"
#include "net/NetworkInterface.h"
namespace nt::net {
class MockLocalInterface : public LocalInterface {
public:
MOCK_METHOD(NT_Topic, NetworkAnnounce,
(std::string_view name, std::string_view typeStr,
const wpi::json& properties, NT_Publisher pubHandle),
(override));
MOCK_METHOD(void, NetworkUnannounce, (std::string_view name), (override));
MOCK_METHOD(void, NetworkPropertiesUpdate,
(std::string_view name, const wpi::json& update, bool ack),
(override));
MOCK_METHOD(void, NetworkSetValue, (NT_Topic topicHandle, const Value& value),
(override));
};
class MockNetworkStartupInterface : public NetworkStartupInterface {
public:
MOCK_METHOD(void, Publish,
(NT_Publisher pubHandle, NT_Topic topicHandle,
std::string_view name, std::string_view typeStr,
const wpi::json& properties, const PubSubOptions& options),
(override));
MOCK_METHOD(void, Subscribe,
(NT_Subscriber subHandle, wpi::span<const std::string> prefixes,
const PubSubOptions& options),
(override));
MOCK_METHOD(void, SetValue, (NT_Publisher pubHandle, const Value& value),
(override));
};
class MockNetworkInterface : public NetworkInterface {
public:
MOCK_METHOD(void, Publish,
(NT_Publisher pubHandle, NT_Topic topicHandle,
std::string_view name, std::string_view typeStr,
const wpi::json& properties, const PubSubOptions& options),
(override));
MOCK_METHOD(void, Unpublish, (NT_Publisher pubHandle, NT_Topic topicHandle),
(override));
MOCK_METHOD(void, SetProperties,
(NT_Topic topicHandle, std::string_view name,
const wpi::json& update),
(override));
MOCK_METHOD(void, Subscribe,
(NT_Subscriber subHandle, wpi::span<const std::string> prefixes,
const PubSubOptions& options),
(override));
MOCK_METHOD(void, Unsubscribe, (NT_Subscriber subHandle), (override));
MOCK_METHOD(void, SetValue, (NT_Publisher pubHandle, const Value& value),
(override));
};
class MockLocalStorage : public ILocalStorage {
public:
MOCK_METHOD(NT_Topic, NetworkAnnounce,
(std::string_view name, std::string_view typeStr,
const wpi::json& properties, NT_Publisher pubHandle),
(override));
MOCK_METHOD(void, NetworkUnannounce, (std::string_view name), (override));
MOCK_METHOD(void, NetworkPropertiesUpdate,
(std::string_view name, const wpi::json& update, bool ack),
(override));
MOCK_METHOD(void, NetworkSetValue, (NT_Topic topicHandle, const Value& value),
(override));
MOCK_METHOD(void, StartNetwork, (NetworkStartupInterface & startup),
(override));
MOCK_METHOD(void, SetNetwork, (NetworkInterface * network), (override));
MOCK_METHOD(void, ClearNetwork, (), (override));
};
} // namespace nt::net

View File

@@ -0,0 +1,26 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "MockWireConnection.h"
using namespace nt::net;
void MockWireConnection::StartSendText() {
if (m_in_text) {
m_text_os << ',';
} else {
m_text_os << '[';
m_in_text = true;
}
}
void MockWireConnection::FinishSendText() {
if (m_in_text) {
m_text_os << ']';
m_in_text = false;
}
m_text_os.flush();
Text(m_text);
m_text.clear();
}

View File

@@ -0,0 +1,54 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#pragma once
#include <stdint.h>
#include <string>
#include <string_view>
#include <vector>
#include <wpi/raw_ostream.h>
#include <wpi/span.h>
#include "gmock/gmock.h"
#include "net/WireConnection.h"
namespace nt::net {
class MockWireConnection : public WireConnection {
public:
MockWireConnection() : m_text_os{m_text}, m_binary_os{m_binary} {}
MOCK_METHOD(bool, Ready, (), (const, override));
TextWriter SendText() override { return {m_text_os, *this}; }
BinaryWriter SendBinary() override { return {m_binary_os, *this}; }
MOCK_METHOD(void, Text, (std::string_view contents));
MOCK_METHOD(void, Binary, (wpi::span<const uint8_t> contents));
MOCK_METHOD(void, Flush, (), (override));
MOCK_METHOD(void, Disconnect, (std::string_view reason), (override));
protected:
void StartSendText() override;
void FinishSendText() override;
void StartSendBinary() override {}
void FinishSendBinary() override {
Binary(m_binary);
m_binary.resize(0);
}
private:
std::string m_text;
wpi::raw_string_ostream m_text_os;
std::vector<uint8_t> m_binary;
wpi::raw_uvector_ostream m_binary_os;
bool m_in_text{false};
};
} // namespace nt::net

View File

@@ -0,0 +1,214 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <wpi/SmallString.h>
#include <wpi/raw_ostream.h>
#include "../MockLogger.h"
#include "../TestPrinters.h"
#include "Handle.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "net/Message.h"
#include "net/WireDecoder.h"
#include "networktables/NetworkTableValue.h"
using namespace std::string_view_literals;
using testing::_;
using testing::MockFunction;
using testing::StrictMock;
namespace nt {
class MockClientMessageHandler : public net::ClientMessageHandler {
public:
MOCK_METHOD4(ClientPublish,
void(int64_t pubuid, std::string_view name,
std::string_view typeStr, const wpi::json& properties));
MOCK_METHOD1(ClientUnpublish, void(int64_t pubuid));
MOCK_METHOD2(ClientSetProperties,
void(std::string_view name, const wpi::json& update));
MOCK_METHOD3(ClientSubscribe,
void(int64_t subuid, wpi::span<const std::string> prefixes,
const PubSubOptions& options));
MOCK_METHOD1(ClientUnsubscribe, void(int64_t subuid));
};
class MockServerMessageHandler : public net::ServerMessageHandler {
public:
MOCK_METHOD5(ServerAnnounce,
void(std::string_view name, int64_t id, std::string_view typeStr,
const wpi::json& properties,
std::optional<int64_t> pubuid));
MOCK_METHOD2(ServerUnannounce, void(std::string_view name, int64_t id));
MOCK_METHOD3(ServerPropertiesUpdate,
void(std::string_view name, const wpi::json& update, bool ack));
};
class WireDecodeTextClientTest : public ::testing::Test {
public:
StrictMock<MockClientMessageHandler> handler;
StrictMock<wpi::MockLogger> logger;
};
class WireDecodeTextServerTest : public ::testing::Test {
public:
StrictMock<MockServerMessageHandler> handler;
StrictMock<wpi::MockLogger> logger;
};
TEST_F(WireDecodeTextClientTest, EmptyArray) {
net::WireDecodeText("[]", handler, logger);
}
TEST_F(WireDecodeTextClientTest, ErrorEmpty) {
EXPECT_CALL(
logger,
Call(_, _, _,
"could not decode JSON message: [json.exception.parse_error.101] "
"parse error at 1: syntax error - "
"unexpected end of input; expected '[', '{', or a literal"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 2: syntax error - "
"unexpected end of input; expected '[', '{', or a literal"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 3: syntax error - "
"unexpected end of input; expected string literal"sv));
net::WireDecodeText("[{", handler, logger);
}
TEST_F(WireDecodeTextClientTest, ErrorNotArray) {
EXPECT_CALL(logger, Call(_, _, _, "expected JSON array at top level"sv));
net::WireDecodeText("{}", handler, logger);
}
TEST_F(WireDecodeTextClientTest, ErrorMessageNotObject) {
EXPECT_CALL(logger, Call(_, _, _, "0: expected message to be an object"sv));
net::WireDecodeText("[5]", handler, logger);
}
TEST_F(WireDecodeTextClientTest, ErrorNoMethodKey) {
EXPECT_CALL(logger, Call(_, _, _, "0: no method key"sv));
net::WireDecodeText("[{}]", handler, logger);
}
TEST_F(WireDecodeTextClientTest, ErrorMethodNotString) {
EXPECT_CALL(logger, Call(_, _, _, "0: method must be a string"sv));
net::WireDecodeText("[{\"method\":5}]", handler, logger);
}
TEST_F(WireDecodeTextClientTest, ErrorNoParamsKey) {
EXPECT_CALL(logger, Call(_, _, _, "0: no params key"sv));
net::WireDecodeText("[{\"method\":\"a\"}]", handler, logger);
}
TEST_F(WireDecodeTextClientTest, ErrorParamsNotObject) {
EXPECT_CALL(logger, Call(_, _, _, "0: params must be an object"sv));
net::WireDecodeText("[{\"method\":\"a\",\"params\":5}]", handler, logger);
}
TEST_F(WireDecodeTextClientTest, ErrorUnknownMethod) {
EXPECT_CALL(logger, Call(_, _, _, "0: unrecognized method 'a'"sv));
net::WireDecodeText("[{\"method\":\"a\",\"params\":{}}]", handler, logger);
}
TEST_F(WireDecodeTextClientTest, PublishPropsEmpty) {
EXPECT_CALL(handler,
ClientPublish(5, std::string_view{"test"},
std::string_view{"double"}, wpi::json::object()));
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::json::object()));
net::WireDecodeText(
"[{\"method\":\"publish\",\"params\":{"
"\"name\":\"test\",\"pubuid\":5,\"type\":\"double\"}}]",
handler, logger);
}
TEST_F(WireDecodeTextClientTest, PublishProps) {
wpi::json props = {{"k", 6}};
EXPECT_CALL(handler, ClientPublish(5, std::string_view{"test"},
std::string_view{"double"}, props));
net::WireDecodeText(
"[{\"method\":\"publish\",\"params\":{"
"\"name\":\"test\",\"properties\":{\"k\":6},"
"\"pubuid\":5,\"type\":\"double\"}}]",
handler, logger);
}
TEST_F(WireDecodeTextClientTest, PublishPropsError) {
EXPECT_CALL(logger, Call(_, _, _, "0: properties must be an object"sv));
net::WireDecodeText(
"[{\"method\":\"publish\",\"params\":{"
"\"name\":\"test\",\"properties\":[\"k\"],"
"\"pubuid\":5,\"type\":\"double\"}}]",
handler, logger);
}
TEST_F(WireDecodeTextClientTest, PublishError) {
EXPECT_CALL(logger, Call(_, _, _, "0: no name key"sv));
net::WireDecodeText(
"[{\"method\":\"publish\",\"params\":{"
"\"pubuid\":5,\"type\":\"double\"}}]",
handler, logger);
EXPECT_CALL(logger, Call(_, _, _, "0: no type key"sv));
net::WireDecodeText(
"[{\"method\":\"publish\",\"params\":{"
"\"name\":\"test\",\"pubuid\":5}}]",
handler, logger);
EXPECT_CALL(logger, Call(_, _, _, "0: no pubuid key"sv));
net::WireDecodeText(
"[{\"method\":\"publish\",\"params\":{"
"\"name\":\"test\",\"type\":\"double\"}}]",
handler, logger);
}
TEST_F(WireDecodeTextClientTest, Unpublish) {
EXPECT_CALL(handler, ClientUnpublish(5));
net::WireDecodeText("[{\"method\":\"unpublish\",\"params\":{\"pubuid\":5}}]",
handler, logger);
}
TEST_F(WireDecodeTextClientTest, UnpublishMultiple) {
EXPECT_CALL(handler, ClientUnpublish(5));
EXPECT_CALL(handler, ClientUnpublish(6));
net::WireDecodeText(
"[{\"method\":\"unpublish\",\"params\":{\"pubuid\":5}},{\"method\":"
"\"unpublish\",\"params\":{\"pubuid\":6}}]",
handler, logger);
}
TEST_F(WireDecodeTextClientTest, UnpublishError) {
EXPECT_CALL(logger, Call(_, _, _, "0: no pubuid key"sv));
net::WireDecodeText("[{\"method\":\"unpublish\",\"params\":{}}]", handler,
logger);
EXPECT_CALL(logger, Call(_, _, _, "0: pubuid must be a number"sv));
net::WireDecodeText(
"[{\"method\":\"unpublish\",\"params\":{\"pubuid\":\"5\"}}]", handler,
logger);
}
} // namespace nt

View File

@@ -0,0 +1,292 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <string>
#include <string_view>
#include <vector>
#include <wpi/json.h>
#include <wpi/raw_ostream.h>
#include "../SpanMatcher.h"
#include "../TestPrinters.h"
#include "Handle.h"
#include "PubSubOptions.h"
#include "gmock/gmock-matchers.h"
#include "gtest/gtest.h"
#include "net/Message.h"
#include "net/WireEncoder.h"
#include "networktables/NetworkTableValue.h"
using namespace std::string_view_literals;
namespace 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()); }
};
class WireEncoderBinaryTest : public ::testing::Test {
protected:
std::vector<uint8_t> out;
wpi::raw_uvector_ostream os{out};
};
TEST_F(WireEncoderTextTest, PublishPropsEmpty) {
net::WireEncodePublish(os, 5, "test", "double", wpi::json::object());
ASSERT_EQ(
os.str(),
"{\"method\":\"publish\",\"params\":{"
"\"name\":\"test\",\"properties\":{},\"pubuid\":5,\"type\":\"double\"}}");
}
TEST_F(WireEncoderTextTest, PublishProps) {
net::WireEncodePublish(os, 5, "test", "double", {{"k", 6}});
ASSERT_EQ(os.str(),
"{\"method\":\"publish\",\"params\":{"
"\"name\":\"test\",\"properties\":{\"k\":6},"
"\"pubuid\":5,\"type\":\"double\"}}");
}
TEST_F(WireEncoderTextTest, Unpublish) {
net::WireEncodeUnpublish(os, 5);
ASSERT_EQ(os.str(), "{\"method\":\"unpublish\",\"params\":{\"pubuid\":5}}");
}
TEST_F(WireEncoderTextTest, SetProperties) {
net::WireEncodeSetProperties(os, "test", {{"k", 6}});
ASSERT_EQ(os.str(),
"{\"method\":\"setproperties\",\"params\":{"
"\"name\":\"test\",\"update\":{\"k\":6}}}");
}
TEST_F(WireEncoderTextTest, Subscribe) {
net::WireEncodeSubscribe(os, 5, std::vector<std::string_view>{{"a", "b"}},
PubSubOptions{});
ASSERT_EQ(os.str(),
"{\"method\":\"subscribe\",\"params\":{"
"\"options\":{},\"topics\":[\"a\",\"b\"],\"subuid\":5}}");
}
TEST_F(WireEncoderTextTest, SubscribeSendAll) {
PubSubOptions options;
options.sendAll = true;
net::WireEncodeSubscribe(os, 5, std::vector<std::string_view>{{"a", "b"}},
options);
ASSERT_EQ(os.str(),
"{\"method\":\"subscribe\",\"params\":{"
"\"options\":{\"all\":true},\"topics\":[\"a\",\"b\"],"
"\"subuid\":5}}");
}
TEST_F(WireEncoderTextTest, SubscribePeriodic) {
PubSubOptions options;
options.periodic = 0.5;
net::WireEncodeSubscribe(os, 5, std::vector<std::string_view>{{"a", "b"}},
options);
ASSERT_EQ(os.str(),
"{\"method\":\"subscribe\",\"params\":{"
"\"options\":{\"periodic\":0.5},\"topics\":[\"a\",\"b\"],"
"\"subuid\":5}}");
}
TEST_F(WireEncoderTextTest, SubscribeAllOptions) {
PubSubOptions options;
options.sendAll = true;
options.periodic = 0.5;
net::WireEncodeSubscribe(os, 5, std::vector<std::string_view>{{"a", "b"}},
options);
ASSERT_EQ(os.str(),
"{\"method\":\"subscribe\",\"params\":{"
"\"options\":{\"all\":true,\"periodic\":0.5},"
"\"topics\":[\"a\",\"b\"],\"subuid\":5}}");
}
TEST_F(WireEncoderTextTest, Unsubscribe) {
net::WireEncodeUnsubscribe(os, 5);
ASSERT_EQ(os.str(), "{\"method\":\"unsubscribe\",\"params\":{\"subuid\":5}}");
}
TEST_F(WireEncoderTextTest, Announce) {
net::WireEncodeAnnounce(os, "test", 5, "double", wpi::json::object(),
std::nullopt);
ASSERT_EQ(os.str(),
"{\"method\":\"announce\",\"params\":{\"id\":5,\"name\":\"test\","
"\"properties\":{},\"type\":\"double\"}}");
}
TEST_F(WireEncoderTextTest, AnnounceProperties) {
net::WireEncodeAnnounce(os, "test", 5, "double", {{"k", 6}}, std::nullopt);
ASSERT_EQ(os.str(),
"{\"method\":\"announce\",\"params\":{\"id\":5,\"name\":\"test\","
"\"properties\":{\"k\":6},\"type\":\"double\"}}");
}
TEST_F(WireEncoderTextTest, AnnouncePubuid) {
net::WireEncodeAnnounce(os, "test", 5, "double", wpi::json::object(), 6);
ASSERT_EQ(os.str(),
"{\"method\":\"announce\",\"params\":{\"id\":5,\"name\":\"test\","
"\"properties\":{},\"pubuid\":6,\"type\":\"double\"}}");
}
TEST_F(WireEncoderTextTest, Unannounce) {
net::WireEncodeUnannounce(os, "test", 5);
ASSERT_EQ(
os.str(),
"{\"method\":\"unannounce\",\"params\":{\"id\":5,\"name\":\"test\"}}");
}
TEST_F(WireEncoderTextTest, MessagePublish) {
net::ClientMessage msg{net::PublishMsg{
Handle{0, 5, Handle::kPublisher}, 0, "test", "double", {{"k", 6}}, {}}};
ASSERT_TRUE(net::WireEncodeText(os, msg));
ASSERT_EQ(os.str(),
"{\"method\":\"publish\",\"params\":{"
"\"name\":\"test\",\"properties\":{\"k\":6},"
"\"pubuid\":5,\"type\":\"double\"}}");
}
TEST_F(WireEncoderTextTest, MessageUnpublish) {
net::ClientMessage msg{
net::UnpublishMsg{Handle{0, 5, Handle::kPublisher}, 0}};
ASSERT_TRUE(net::WireEncodeText(os, msg));
ASSERT_EQ(os.str(), "{\"method\":\"unpublish\",\"params\":{\"pubuid\":5}}");
}
TEST_F(WireEncoderTextTest, MessageSetProperties) {
net::ClientMessage msg{net::SetPropertiesMsg{0, "test", {{"k", 6}}}};
ASSERT_TRUE(net::WireEncodeText(os, msg));
ASSERT_EQ(os.str(),
"{\"method\":\"setproperties\",\"params\":{"
"\"name\":\"test\",\"update\":{\"k\":6}}}");
}
TEST_F(WireEncoderTextTest, MessageSubscribe) {
net::ClientMessage msg{
net::SubscribeMsg{Handle{0, 5, Handle::kSubscriber}, {"a", "b"}, {}}};
ASSERT_TRUE(net::WireEncodeText(os, msg));
ASSERT_EQ(os.str(),
"{\"method\":\"subscribe\",\"params\":{"
"\"options\":{},\"topics\":[\"a\",\"b\"],\"subuid\":5}}");
}
TEST_F(WireEncoderTextTest, MessageUnsubscribe) {
net::ClientMessage msg{
net::UnsubscribeMsg{Handle{0, 5, Handle::kSubscriber}}};
ASSERT_TRUE(net::WireEncodeText(os, msg));
ASSERT_EQ(os.str(), "{\"method\":\"unsubscribe\",\"params\":{\"subuid\":5}}");
}
TEST_F(WireEncoderTextTest, MessageAnnounce) {
net::ServerMessage msg{
net::AnnounceMsg{"test", 5, "double", std::nullopt, wpi::json::object()}};
ASSERT_TRUE(net::WireEncodeText(os, msg));
ASSERT_EQ(os.str(),
"{\"method\":\"announce\",\"params\":{\"id\":5,\"name\":\"test\","
"\"properties\":{},\"type\":\"double\"}}");
}
TEST_F(WireEncoderTextTest, MessageAnnounceProperties) {
net::ServerMessage msg{
net::AnnounceMsg{"test", 5, "double", std::nullopt, {{"k", 6}}}};
ASSERT_TRUE(net::WireEncodeText(os, msg));
ASSERT_EQ(os.str(),
"{\"method\":\"announce\",\"params\":{\"id\":5,\"name\":\"test\","
"\"properties\":{\"k\":6},\"type\":\"double\"}}");
}
TEST_F(WireEncoderTextTest, MessageAnnouncePubuid) {
net::ServerMessage msg{
net::AnnounceMsg{"test", 5, "double", 6, wpi::json::object()}};
ASSERT_TRUE(net::WireEncodeText(os, msg));
ASSERT_EQ(os.str(),
"{\"method\":\"announce\",\"params\":{\"id\":5,\"name\":\"test\","
"\"properties\":{},\"pubuid\":6,\"type\":\"double\"}}");
}
TEST_F(WireEncoderTextTest, MessageUnannounce) {
net::ServerMessage msg{net::UnannounceMsg{"test", 5}};
ASSERT_TRUE(net::WireEncodeText(os, msg));
ASSERT_EQ(
os.str(),
"{\"method\":\"unannounce\",\"params\":{\"id\":5,\"name\":\"test\"}}");
}
TEST_F(WireEncoderTextTest, ServerMessageEmpty) {
ASSERT_FALSE(net::WireEncodeText(os, net::ServerMessage{}));
}
TEST_F(WireEncoderTextTest, ServerMessageValue) {
net::ServerMessage msg{net::ServerValueMsg{}};
ASSERT_FALSE(net::WireEncodeText(os, msg));
}
TEST_F(WireEncoderBinaryTest, Boolean) {
net::WireEncodeBinary(os, 5, 6, Value::MakeBoolean(true));
ASSERT_THAT(out, wpi::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));
}
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));
}
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));
}
TEST_F(WireEncoderBinaryTest, String) {
net::WireEncodeBinary(os, 5, 6, Value::MakeString("hello"));
ASSERT_THAT(out, wpi::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));
}
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));
}
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));
}
TEST_F(WireEncoderBinaryTest, FloatArray) {
net::WireEncodeBinary(os, 5, 6, Value::MakeFloatArray({1, 2, 3}));
ASSERT_THAT(out, wpi::SpanEq("\x94\x05\x06\x13\x93"
"\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::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::SpanEq("\x94\x05\x06\x14\x92\xa5hello\xa3"
"bye"_us));
}
} // namespace nt