mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[ntcore] NetworkTables 4 (#3217)
This commit is contained in:
45
ntcore/src/test/native/cpp/net3/MessageMatcher3.cpp
Normal file
45
ntcore/src/test/native/cpp/net3/MessageMatcher3.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
// 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 "MessageMatcher3.h"
|
||||
|
||||
namespace nt::net3 {
|
||||
|
||||
bool MessageMatcher::MatchAndExplain(
|
||||
Message3 msg, ::testing::MatchResultListener* listener) const {
|
||||
bool match = true;
|
||||
if (msg.str() != goodmsg.str()) {
|
||||
*listener << "str mismatch ";
|
||||
match = false;
|
||||
}
|
||||
if ((!msg.value() && goodmsg.value()) || (msg.value() && !goodmsg.value()) ||
|
||||
(msg.value() && goodmsg.value() && msg.value() != goodmsg.value())) {
|
||||
*listener << "value mismatch ";
|
||||
match = false;
|
||||
}
|
||||
if (msg.id() != goodmsg.id()) {
|
||||
*listener << "id mismatch ";
|
||||
match = false;
|
||||
}
|
||||
if (msg.flags() != goodmsg.flags()) {
|
||||
*listener << "flags mismatch";
|
||||
match = false;
|
||||
}
|
||||
if (msg.seq_num_uid() != goodmsg.seq_num_uid()) {
|
||||
*listener << "seq_num_uid mismatch";
|
||||
match = false;
|
||||
}
|
||||
return match;
|
||||
}
|
||||
|
||||
void MessageMatcher::DescribeTo(::std::ostream* os) const {
|
||||
PrintTo(goodmsg, os);
|
||||
}
|
||||
|
||||
void MessageMatcher::DescribeNegationTo(::std::ostream* os) const {
|
||||
*os << "is not equal to ";
|
||||
PrintTo(goodmsg, os);
|
||||
}
|
||||
|
||||
} // namespace nt::net3
|
||||
34
ntcore/src/test/native/cpp/net3/MessageMatcher3.h
Normal file
34
ntcore/src/test/native/cpp/net3/MessageMatcher3.h
Normal file
@@ -0,0 +1,34 @@
|
||||
// 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 <memory>
|
||||
#include <ostream>
|
||||
#include <utility>
|
||||
|
||||
#include "../TestPrinters.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "net3/Message3.h"
|
||||
|
||||
namespace nt::net3 {
|
||||
|
||||
class MessageMatcher : public ::testing::MatcherInterface<Message3> {
|
||||
public:
|
||||
explicit MessageMatcher(Message3 goodmsg_) : goodmsg(std::move(goodmsg_)) {}
|
||||
|
||||
bool MatchAndExplain(Message3 msg,
|
||||
::testing::MatchResultListener* listener) const override;
|
||||
void DescribeTo(::std::ostream* os) const override;
|
||||
void DescribeNegationTo(::std::ostream* os) const override;
|
||||
|
||||
private:
|
||||
Message3 goodmsg;
|
||||
};
|
||||
|
||||
inline ::testing::Matcher<Message3> MessageEq(Message3 goodmsg) {
|
||||
return ::testing::MakeMatcher(new MessageMatcher(std::move(goodmsg)));
|
||||
}
|
||||
|
||||
} // namespace nt::net3
|
||||
44
ntcore/src/test/native/cpp/net3/MockWireConnection3.h
Normal file
44
ntcore/src/test/native/cpp/net3/MockWireConnection3.h
Normal file
@@ -0,0 +1,44 @@
|
||||
// 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 <vector>
|
||||
|
||||
#include <wpi/raw_ostream.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "net3/WireConnection3.h"
|
||||
|
||||
namespace nt::net3 {
|
||||
|
||||
class MockWireConnection3 : public WireConnection3 {
|
||||
public:
|
||||
MockWireConnection3() : m_os{m_data} {}
|
||||
|
||||
MOCK_METHOD(bool, Ready, (), (const, override));
|
||||
|
||||
Writer Send() override { return {m_os, *this}; }
|
||||
|
||||
MOCK_METHOD(void, Data, (wpi::span<const uint8_t> data));
|
||||
|
||||
MOCK_METHOD(void, Flush, (), (override));
|
||||
|
||||
MOCK_METHOD(void, Disconnect, (std::string_view reason), (override));
|
||||
|
||||
protected:
|
||||
void FinishSend() override {
|
||||
Data(m_data);
|
||||
m_data.resize(0);
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> m_data;
|
||||
wpi::raw_uvector_ostream m_os;
|
||||
};
|
||||
|
||||
} // namespace nt::net3
|
||||
276
ntcore/src/test/native/cpp/net3/WireDecoder3Test.cpp
Normal file
276
ntcore/src/test/native/cpp/net3/WireDecoder3Test.cpp
Normal file
@@ -0,0 +1,276 @@
|
||||
// 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 <stdint.h>
|
||||
|
||||
#include <cfloat>
|
||||
#include <climits>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "../SpanMatcher.h"
|
||||
#include "../TestPrinters.h"
|
||||
#include "../ValueMatcher.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "net3/WireDecoder3.h"
|
||||
#include "networktables/NetworkTableValue.h"
|
||||
|
||||
using namespace std::string_view_literals;
|
||||
using testing::_;
|
||||
using testing::MockFunction;
|
||||
using testing::StrictMock;
|
||||
|
||||
namespace nt {
|
||||
|
||||
class MockMessageHandler3 : public net3::MessageHandler3 {
|
||||
public:
|
||||
MOCK_METHOD0(KeepAlive, void());
|
||||
MOCK_METHOD0(ServerHelloDone, void());
|
||||
MOCK_METHOD0(ClientHelloDone, void());
|
||||
MOCK_METHOD0(ClearEntries, void());
|
||||
MOCK_METHOD1(ProtoUnsup, void(unsigned int proto_rev));
|
||||
MOCK_METHOD2(ClientHello,
|
||||
void(std::string_view self_id, unsigned int proto_rev));
|
||||
MOCK_METHOD2(ServerHello, void(unsigned int flags, std::string_view self_id));
|
||||
MOCK_METHOD5(EntryAssign, void(std::string_view name, unsigned int id,
|
||||
unsigned int seq_num, const Value& value,
|
||||
unsigned int flags));
|
||||
MOCK_METHOD3(EntryUpdate,
|
||||
void(unsigned int id, unsigned int seq_num, const Value& value));
|
||||
MOCK_METHOD2(FlagsUpdate, void(unsigned int id, unsigned int flags));
|
||||
MOCK_METHOD1(EntryDelete, void(unsigned int id));
|
||||
MOCK_METHOD3(ExecuteRpc, void(unsigned int id, unsigned int uid,
|
||||
wpi::span<const uint8_t> params));
|
||||
MOCK_METHOD3(RpcResponse, void(unsigned int id, unsigned int uid,
|
||||
wpi::span<const uint8_t> result));
|
||||
};
|
||||
|
||||
class WireDecoder3Test : public ::testing::Test {
|
||||
protected:
|
||||
StrictMock<MockMessageHandler3> handler;
|
||||
net3::WireDecoder3 decoder{handler};
|
||||
|
||||
void DecodeComplete(wpi::span<const uint8_t> in) {
|
||||
decoder.Execute(&in);
|
||||
EXPECT_TRUE(in.empty());
|
||||
ASSERT_EQ(decoder.GetError(), "");
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(WireDecoder3Test, KeepAlive) {
|
||||
EXPECT_CALL(handler, KeepAlive());
|
||||
DecodeComplete("\x00"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, ClientHello) {
|
||||
EXPECT_CALL(handler, ClientHello(std::string_view{"hello"}, 0x0300u));
|
||||
DecodeComplete("\x01\x03\x00\x05hello"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, ProtoUnsup) {
|
||||
EXPECT_CALL(handler, ProtoUnsup(0x0300u));
|
||||
EXPECT_CALL(handler, ProtoUnsup(0x0200u));
|
||||
DecodeComplete("\x02\x03\x00\x02\x02\x00"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, ServerHelloDone) {
|
||||
EXPECT_CALL(handler, ServerHelloDone());
|
||||
DecodeComplete("\x03"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, ServerHello) {
|
||||
EXPECT_CALL(handler, ServerHello(0x03, std::string_view{"hello"}));
|
||||
DecodeComplete("\x04\x03\x05hello"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, ClientHelloDone) {
|
||||
EXPECT_CALL(handler, ClientHelloDone());
|
||||
DecodeComplete("\x05"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, FlagsUpdate) {
|
||||
EXPECT_CALL(handler, FlagsUpdate(0x5678, 0x03));
|
||||
DecodeComplete("\x12\x56\x78\x03"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, EntryDelete) {
|
||||
EXPECT_CALL(handler, EntryDelete(0x5678));
|
||||
DecodeComplete("\x13\x56\x78"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, ClearEntries) {
|
||||
EXPECT_CALL(handler, ClearEntries());
|
||||
DecodeComplete("\x14\xd0\x6c\xb2\x7a"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, ClearEntriesInvalid) {
|
||||
auto in = "\x14\xd0\x6c\xb2\x7b"_us;
|
||||
decoder.Execute(&in);
|
||||
EXPECT_EQ(decoder.GetError(), "received incorrect CLEAR_ENTRIES magic value");
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, ExecuteRpc) {
|
||||
EXPECT_CALL(handler, ExecuteRpc(0x5678, 0x1234, wpi::SpanEq("hello"_us)));
|
||||
DecodeComplete("\x20\x56\x78\x12\x34\x05hello"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, RpcResponse) {
|
||||
EXPECT_CALL(handler, RpcResponse(0x5678, 0x1234, wpi::SpanEq("hello"_us)));
|
||||
DecodeComplete("\x21\x56\x78\x12\x34\x05hello"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, UnknownMessage) {
|
||||
auto in = "\x23"_us;
|
||||
decoder.Execute(&in);
|
||||
EXPECT_EQ(decoder.GetError(), "unrecognized message type: 35");
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, EntryAssignBoolean) {
|
||||
EXPECT_CALL(handler, EntryAssign("test"sv, 0x5678, 0x1234,
|
||||
Value::MakeBoolean(true), 0x9a));
|
||||
DecodeComplete("\x10\x04test\x00\x56\x78\x12\x34\x9a\x01"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, EntryAssignDouble) {
|
||||
EXPECT_CALL(handler, EntryAssign("test"sv, 0x5678, 0x1234,
|
||||
Value::MakeDouble(2.3e5), 0x9a));
|
||||
DecodeComplete(
|
||||
"\x10\x04test\x01\x56\x78\x12\x34"
|
||||
"\x9a\x41\x0c\x13\x80\x00\x00\x00\x00"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, EntryUpdateBoolean) {
|
||||
EXPECT_CALL(handler, EntryUpdate(0x5678, 0x1234, Value::MakeBoolean(true)));
|
||||
DecodeComplete("\x11\x56\x78\x12\x34\x00\x01"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, EntryUpdateDouble) {
|
||||
// values except min and max from
|
||||
// http://www.binaryconvert.com/result_double.html
|
||||
EXPECT_CALL(handler, EntryUpdate(0x5678, 0x1234, Value::MakeDouble(0.0)));
|
||||
DecodeComplete("\x11\x56\x78\x12\x34\x01\x00\x00\x00\x00\x00\x00\x00\x00"_us);
|
||||
EXPECT_CALL(handler, EntryUpdate(0x5678, 0x1234, Value::MakeDouble(2.3e5)));
|
||||
DecodeComplete("\x11\x56\x78\x12\x34\x01\x41\x0c\x13\x80\x00\x00\x00\x00"_us);
|
||||
EXPECT_CALL(
|
||||
handler,
|
||||
EntryUpdate(0x5678, 0x1234,
|
||||
Value::MakeDouble(std::numeric_limits<double>::infinity())));
|
||||
DecodeComplete("\x11\x56\x78\x12\x34\x01\x7f\xf0\x00\x00\x00\x00\x00\x00"_us);
|
||||
EXPECT_CALL(handler, EntryUpdate(0x5678, 0x1234, Value::MakeDouble(DBL_MIN)));
|
||||
DecodeComplete("\x11\x56\x78\x12\x34\x01\x00\x10\x00\x00\x00\x00\x00\x00"_us);
|
||||
EXPECT_CALL(handler, EntryUpdate(0x5678, 0x1234, Value::MakeDouble(DBL_MAX)));
|
||||
DecodeComplete("\x11\x56\x78\x12\x34\x01\x7f\xef\xff\xff\xff\xff\xff\xff"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, EntryUpdateString) {
|
||||
EXPECT_CALL(handler,
|
||||
EntryUpdate(0x5678, 0x1234, Value::MakeString("hello"sv)));
|
||||
DecodeComplete("\x11\x56\x78\x12\x34\x02\x05hello"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, EntryUpdateString2) {
|
||||
std::vector<uint8_t> in{0x11, 0x56, 0x78, 0x12, 0x34, 0x02, 0x7f};
|
||||
in.insert(in.end(), 127, '*');
|
||||
std::string out(127, '*');
|
||||
EXPECT_CALL(handler,
|
||||
EntryUpdate(0x5678, 0x1234, Value::MakeString(std::move(out))));
|
||||
DecodeComplete(in);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, EntryUpdateStringLarge) {
|
||||
std::vector<uint8_t> in{0x11, 0x56, 0x78, 0x12, 0x34, 0x02, 0x80, 0x01};
|
||||
in.insert(in.end(), 127, '*');
|
||||
in.push_back('x');
|
||||
|
||||
std::string out(127, '*');
|
||||
out.push_back('x');
|
||||
|
||||
EXPECT_CALL(handler,
|
||||
EntryUpdate(0x5678, 0x1234, Value::MakeString(std::move(out))));
|
||||
DecodeComplete(in);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, EntryUpdateStringHuge) {
|
||||
std::vector<uint8_t> in{0x11, 0x56, 0x78, 0x12, 0x34, 0x02, 0x81, 0x80, 0x04};
|
||||
in.insert(in.end(), 65534, '*');
|
||||
in.insert(in.end(), 3, 'x');
|
||||
|
||||
std::string out(65534, '*');
|
||||
out.append(3, 'x');
|
||||
|
||||
EXPECT_CALL(handler,
|
||||
EntryUpdate(0x5678, 0x1234, Value::MakeString(std::move(out))));
|
||||
DecodeComplete(in);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, EntryUpdateRaw) {
|
||||
EXPECT_CALL(handler, EntryUpdate(0x5678, 0x1234, Value::MakeRaw("hello"_us)));
|
||||
DecodeComplete("\x11\x56\x78\x12\x34\x03\x05hello"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, EntryUpdateBooleanArray) {
|
||||
EXPECT_CALL(handler,
|
||||
EntryUpdate(0x5678, 0x1234,
|
||||
Value::MakeBooleanArray({false, true, false})));
|
||||
DecodeComplete("\x11\x56\x78\x12\x34\x10\x03\x00\x01\x00"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, EntryUpdateBooleanArrayLarge) {
|
||||
std::vector<uint8_t> in{0x11, 0x56, 0x78, 0x12, 0x34, 0x10, 0xff};
|
||||
in.insert(in.end(), 255, 0);
|
||||
std::vector<int> out(255, 0);
|
||||
EXPECT_CALL(handler, EntryUpdate(0x5678, 0x1234,
|
||||
Value::MakeBooleanArray(std::move(out))));
|
||||
DecodeComplete(in);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, EntryUpdateDoubleArray) {
|
||||
EXPECT_CALL(handler,
|
||||
EntryUpdate(0x5678, 0x1234, Value::MakeDoubleArray({0.5, 0.25})));
|
||||
DecodeComplete(
|
||||
"\x11\x56\x78\x12\x34\x11\x02"
|
||||
"\x3f\xe0\x00\x00\x00\x00\x00\x00"
|
||||
"\x3f\xd0\x00\x00\x00\x00\x00\x00"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, EntryUpdateDoubleArrayLarge) {
|
||||
std::vector<uint8_t> in{0x11, 0x56, 0x78, 0x12, 0x34, 0x11, 0xff};
|
||||
in.insert(in.end(), 255 * 8, 0);
|
||||
std::vector<double> out(255, 0.0);
|
||||
EXPECT_CALL(handler, EntryUpdate(0x5678, 0x1234,
|
||||
Value::MakeDoubleArray(std::move(out))));
|
||||
DecodeComplete(in);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, EntryUpdateStringArray) {
|
||||
EXPECT_CALL(handler, EntryUpdate(0x5678, 0x1234,
|
||||
Value::MakeStringArray({"hello", "bye"})));
|
||||
DecodeComplete(
|
||||
"\x11\x56\x78\x12\x34\x12\x02\x05hello\x03"
|
||||
"bye"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, EntryUpdateStringArrayLarge) {
|
||||
std::vector<uint8_t> in{0x11, 0x56, 0x78, 0x12, 0x34, 0x12, 0xff};
|
||||
in.insert(in.end(), 255, 0);
|
||||
std::vector<std::string> out(255, "");
|
||||
EXPECT_CALL(handler, EntryUpdate(0x5678, 0x1234,
|
||||
Value::MakeStringArray(std::move(out))));
|
||||
DecodeComplete(in);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, EntryUpdateRpc) {
|
||||
// RPC values are decoded as raw
|
||||
EXPECT_CALL(handler, EntryUpdate(0x5678, 0x1234, Value::MakeRaw("hello"_us)));
|
||||
DecodeComplete("\x11\x56\x78\x12\x34\x20\x05hello"_us);
|
||||
}
|
||||
|
||||
TEST_F(WireDecoder3Test, EntryUpdateTypeError) {
|
||||
auto in = "\x11\x56\x78\x12\x34\x30\x11"_us;
|
||||
decoder.Execute(&in);
|
||||
ASSERT_EQ(decoder.GetError(), "unrecognized value type");
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
283
ntcore/src/test/native/cpp/net3/WireEncoder3Test.cpp
Normal file
283
ntcore/src/test/native/cpp/net3/WireEncoder3Test.cpp
Normal file
@@ -0,0 +1,283 @@
|
||||
// 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 <cfloat>
|
||||
#include <climits>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/raw_ostream.h>
|
||||
|
||||
#include "../SpanMatcher.h"
|
||||
#include "../TestPrinters.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "net3/Message3.h"
|
||||
#include "net3/WireEncoder3.h"
|
||||
#include "networktables/NetworkTableValue.h"
|
||||
|
||||
using namespace std::string_view_literals;
|
||||
|
||||
namespace nt {
|
||||
|
||||
class WireEncoder3Test : public ::testing::Test {
|
||||
protected:
|
||||
std::vector<uint8_t> out;
|
||||
wpi::raw_uvector_ostream os{out};
|
||||
};
|
||||
|
||||
TEST_F(WireEncoder3Test, Unknown) {
|
||||
net3::WireEncode(os, net3::Message3{});
|
||||
ASSERT_TRUE(out.empty());
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, KeepAlive) {
|
||||
net3::WireEncode(os, net3::Message3::KeepAlive());
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x00"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, ClientHello) {
|
||||
net3::WireEncode(os, net3::Message3::ClientHello("hello"));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x01\x03\x00\x05hello"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, ProtoUnsup) {
|
||||
net3::WireEncode(os, net3::Message3::ProtoUnsup());
|
||||
net3::WireEncode(os, net3::Message3::ProtoUnsup(0x0200u));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x02\x03\x00\x02\x02\x00"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, ServerHelloDone) {
|
||||
net3::WireEncode(os, net3::Message3::ServerHelloDone());
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x03"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, ServerHello) {
|
||||
net3::WireEncode(os, net3::Message3::ServerHello(0x03, "hello"));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x04\x03\x05hello"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, ClientHelloDone) {
|
||||
net3::WireEncode(os, net3::Message3::ClientHelloDone());
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x05"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, FlagsUpdate) {
|
||||
net3::WireEncode(os, net3::Message3::FlagsUpdate(0x5678, 0x03));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x12\x56\x78\x03"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, EntryDelete) {
|
||||
net3::WireEncode(os, net3::Message3::EntryDelete(0x5678));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x13\x56\x78"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, ClearEntries) {
|
||||
net3::WireEncode(os, net3::Message3::ClearEntries());
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x14\xd0\x6c\xb2\x7a"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, ExecuteRpc) {
|
||||
net3::WireEncode(os, net3::Message3::ExecuteRpc(0x5678, 0x1234, "hello"_us));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x20\x56\x78\x12\x34\x05hello"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, RpcResponse) {
|
||||
net3::WireEncode(os, net3::Message3::RpcResponse(0x5678, 0x1234, "hello"_us));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x21\x56\x78\x12\x34\x05hello"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, EntryAssignBoolean) {
|
||||
net3::WireEncode(os,
|
||||
net3::Message3::EntryAssign("test"sv, 0x5678, 0x1234,
|
||||
Value::MakeBoolean(true), 0x9a));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x10\x04test\x00\x56\x78\x12\x34\x9a\x01"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, EntryAssignDouble) {
|
||||
net3::WireEncode(os,
|
||||
net3::Message3::EntryAssign("test"sv, 0x5678, 0x1234,
|
||||
Value::MakeDouble(2.3e5), 0x9a));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x10\x04test\x01\x56\x78\x12\x34"
|
||||
"\x9a\x41\x0c\x13\x80\x00\x00\x00\x00"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, EntryUpdateBoolean) {
|
||||
net3::WireEncode(os, net3::Message3::EntryUpdate(0x5678, 0x1234,
|
||||
Value::MakeBoolean(true)));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x11\x56\x78\x12\x34\x00\x01"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, EntryUpdateDouble) {
|
||||
// values except min and max from
|
||||
// http://www.binaryconvert.com/result_double.html
|
||||
net3::WireEncode(
|
||||
os, net3::Message3::EntryUpdate(0x5678, 0x1234, Value::MakeDouble(0.0)));
|
||||
ASSERT_THAT(
|
||||
out, wpi::SpanEq(
|
||||
"\x11\x56\x78\x12\x34\x01\x00\x00\x00\x00\x00\x00\x00\x00"_us));
|
||||
|
||||
out.clear();
|
||||
net3::WireEncode(os, net3::Message3::EntryUpdate(0x5678, 0x1234,
|
||||
Value::MakeDouble(2.3e5)));
|
||||
ASSERT_THAT(
|
||||
out, wpi::SpanEq(
|
||||
"\x11\x56\x78\x12\x34\x01\x41\x0c\x13\x80\x00\x00\x00\x00"_us));
|
||||
|
||||
out.clear();
|
||||
net3::WireEncode(
|
||||
os, net3::Message3::EntryUpdate(
|
||||
0x5678, 0x1234,
|
||||
Value::MakeDouble(std::numeric_limits<double>::infinity())));
|
||||
ASSERT_THAT(
|
||||
out, wpi::SpanEq(
|
||||
"\x11\x56\x78\x12\x34\x01\x7f\xf0\x00\x00\x00\x00\x00\x00"_us));
|
||||
|
||||
out.clear();
|
||||
net3::WireEncode(os, net3::Message3::EntryUpdate(0x5678, 0x1234,
|
||||
Value::MakeDouble(DBL_MIN)));
|
||||
ASSERT_THAT(
|
||||
out, wpi::SpanEq(
|
||||
"\x11\x56\x78\x12\x34\x01\x00\x10\x00\x00\x00\x00\x00\x00"_us));
|
||||
|
||||
out.clear();
|
||||
net3::WireEncode(os, net3::Message3::EntryUpdate(0x5678, 0x1234,
|
||||
Value::MakeDouble(DBL_MAX)));
|
||||
ASSERT_THAT(
|
||||
out, wpi::SpanEq(
|
||||
"\x11\x56\x78\x12\x34\x01\x7f\xef\xff\xff\xff\xff\xff\xff"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, EntryUpdateString) {
|
||||
net3::WireEncode(os, net3::Message3::EntryUpdate(
|
||||
0x5678, 0x1234, Value::MakeString("hello"sv)));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x11\x56\x78\x12\x34\x02\x05hello"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, EntryUpdateString2) {
|
||||
std::vector<uint8_t> ex{0x11, 0x56, 0x78, 0x12, 0x34, 0x02, 0x7f};
|
||||
ex.insert(ex.end(), 127, '*');
|
||||
std::string in(127, '*');
|
||||
net3::WireEncode(os, net3::Message3::EntryUpdate(
|
||||
0x5678, 0x1234, Value::MakeString(std::move(in))));
|
||||
ASSERT_THAT(out, ex);
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, EntryUpdateStringLarge) {
|
||||
std::vector<uint8_t> ex{0x11, 0x56, 0x78, 0x12, 0x34, 0x02, 0x80, 0x01};
|
||||
ex.insert(ex.end(), 127, '*');
|
||||
ex.push_back('x');
|
||||
|
||||
std::string in(127, '*');
|
||||
in.push_back('x');
|
||||
|
||||
net3::WireEncode(os, net3::Message3::EntryUpdate(
|
||||
0x5678, 0x1234, Value::MakeString(std::move(in))));
|
||||
ASSERT_THAT(out, ex);
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, EntryUpdateStringHuge) {
|
||||
std::vector<uint8_t> ex{0x11, 0x56, 0x78, 0x12, 0x34, 0x02, 0x81, 0x80, 0x04};
|
||||
ex.insert(ex.end(), 65534, '*');
|
||||
ex.insert(ex.end(), 3, 'x');
|
||||
|
||||
std::string in(65534, '*');
|
||||
in.append(3, 'x');
|
||||
|
||||
net3::WireEncode(os, net3::Message3::EntryUpdate(
|
||||
0x5678, 0x1234, Value::MakeString(std::move(in))));
|
||||
ASSERT_THAT(out, ex);
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, EntryUpdateRaw) {
|
||||
net3::WireEncode(os, net3::Message3::EntryUpdate(0x5678, 0x1234,
|
||||
Value::MakeRaw("hello"_us)));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x11\x56\x78\x12\x34\x03\x05hello"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, EntryUpdateBooleanArray) {
|
||||
net3::WireEncode(
|
||||
os, net3::Message3::EntryUpdate(
|
||||
0x5678, 0x1234, Value::MakeBooleanArray({false, true, false})));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x11\x56\x78\x12\x34\x10\x03\x00\x01\x00"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, EntryUpdateBooleanArrayLarge) {
|
||||
std::vector<uint8_t> ex{0x11, 0x56, 0x78, 0x12, 0x34, 0x10, 0xff};
|
||||
ex.insert(ex.end(), 255, 0);
|
||||
std::vector<int> in(255, 0);
|
||||
net3::WireEncode(
|
||||
os, net3::Message3::EntryUpdate(0x5678, 0x1234,
|
||||
Value::MakeBooleanArray(std::move(in))));
|
||||
ASSERT_THAT(out, ex);
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, EntryUpdateBooleanArrayTrunc) {
|
||||
std::vector<uint8_t> ex{0x11, 0x56, 0x78, 0x12, 0x34, 0x10, 0xff};
|
||||
ex.insert(ex.end(), 255, 0);
|
||||
std::vector<int> in(256, 0);
|
||||
net3::WireEncode(
|
||||
os, net3::Message3::EntryUpdate(0x5678, 0x1234,
|
||||
Value::MakeBooleanArray(std::move(in))));
|
||||
ASSERT_THAT(out, ex);
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, EntryUpdateDoubleArray) {
|
||||
net3::WireEncode(
|
||||
os, net3::Message3::EntryUpdate(0x5678, 0x1234,
|
||||
Value::MakeDoubleArray({0.5, 0.25})));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x11\x56\x78\x12\x34\x11\x02"
|
||||
"\x3f\xe0\x00\x00\x00\x00\x00\x00"
|
||||
"\x3f\xd0\x00\x00\x00\x00\x00\x00"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, EntryUpdateDoubleArrayLarge) {
|
||||
std::vector<uint8_t> ex{0x11, 0x56, 0x78, 0x12, 0x34, 0x11, 0xff};
|
||||
ex.insert(ex.end(), 255 * 8, 0);
|
||||
std::vector<double> in(255, 0.0);
|
||||
net3::WireEncode(
|
||||
os, net3::Message3::EntryUpdate(0x5678, 0x1234,
|
||||
Value::MakeDoubleArray(std::move(in))));
|
||||
ASSERT_THAT(out, ex);
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, EntryUpdateDoubleArrayTrunc) {
|
||||
std::vector<uint8_t> ex{0x11, 0x56, 0x78, 0x12, 0x34, 0x11, 0xff};
|
||||
ex.insert(ex.end(), 255 * 8, 0);
|
||||
std::vector<double> in(256, 0.0);
|
||||
net3::WireEncode(
|
||||
os, net3::Message3::EntryUpdate(0x5678, 0x1234,
|
||||
Value::MakeDoubleArray(std::move(in))));
|
||||
ASSERT_THAT(out, ex);
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, EntryUpdateStringArray) {
|
||||
net3::WireEncode(
|
||||
os, net3::Message3::EntryUpdate(
|
||||
0x5678, 0x1234, Value::MakeStringArray({"hello", "bye"})));
|
||||
ASSERT_THAT(out, wpi::SpanEq("\x11\x56\x78\x12\x34\x12\x02\x05hello\x03"
|
||||
"bye"_us));
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, EntryUpdateStringArrayLarge) {
|
||||
std::vector<uint8_t> ex{0x11, 0x56, 0x78, 0x12, 0x34, 0x12, 0xff};
|
||||
ex.insert(ex.end(), 255, 0);
|
||||
std::vector<std::string> in(255, "");
|
||||
net3::WireEncode(
|
||||
os, net3::Message3::EntryUpdate(0x5678, 0x1234,
|
||||
Value::MakeStringArray(std::move(in))));
|
||||
ASSERT_THAT(out, ex);
|
||||
}
|
||||
|
||||
TEST_F(WireEncoder3Test, EntryUpdateStringArrayTrunc) {
|
||||
std::vector<uint8_t> ex{0x11, 0x56, 0x78, 0x12, 0x34, 0x12, 0xff};
|
||||
ex.insert(ex.end(), 255, 0);
|
||||
std::vector<std::string> in(256, "");
|
||||
net3::WireEncode(
|
||||
os, net3::Message3::EntryUpdate(0x5678, 0x1234,
|
||||
Value::MakeStringArray(std::move(in))));
|
||||
ASSERT_THAT(out, ex);
|
||||
}
|
||||
|
||||
} // namespace nt
|
||||
Reference in New Issue
Block a user