mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Use std::string_view and fmtlib across all libraries (#3402)
- Twine, StringRef, Format, and NativeFormatting have been removed - Logging now uses fmtlib style formatting - Nearly all uses of wpi::outs/errs have been replaced with fmt::print() or std::puts()/std::fputs() (for unformatted strings). - A wpi/fmt/raw_ostream.h header has been added to enable fmt::print() with wpi::raw_ostream
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "wpi/Base64.h"
|
||||
#include "wpi/HttpParser.h"
|
||||
#include "wpi/SmallString.h"
|
||||
#include "wpi/StringExtras.h"
|
||||
#include "wpi/raw_uv_ostream.h"
|
||||
#include "wpi/sha1.h"
|
||||
|
||||
@@ -17,9 +18,9 @@ class WebSocketClientTest : public WebSocketTest {
|
||||
public:
|
||||
WebSocketClientTest() {
|
||||
// Bare bones server
|
||||
req.header.connect([this](StringRef name, StringRef value) {
|
||||
req.header.connect([this](std::string_view name, std::string_view value) {
|
||||
// save key (required for valid response)
|
||||
if (name.equals_lower("sec-websocket-key")) {
|
||||
if (equals_lower(name, "sec-websocket-key")) {
|
||||
clientKey = value;
|
||||
}
|
||||
});
|
||||
@@ -65,7 +66,7 @@ class WebSocketClientTest : public WebSocketTest {
|
||||
conn = serverPipe->Accept();
|
||||
conn->StartRead();
|
||||
conn->data.connect([this](uv::Buffer& buf, size_t size) {
|
||||
StringRef data{buf.base, size};
|
||||
std::string_view data{buf.base, size};
|
||||
if (!serverHeadersDone) {
|
||||
data = req.Execute(data);
|
||||
if (req.HasError()) {
|
||||
@@ -76,7 +77,7 @@ class WebSocketClientTest : public WebSocketTest {
|
||||
return;
|
||||
}
|
||||
}
|
||||
wireData.insert(wireData.end(), data.bytes_begin(), data.bytes_end());
|
||||
wireData.insert(wireData.end(), data.begin(), data.end());
|
||||
});
|
||||
conn->end.connect([this] { Finish(); });
|
||||
});
|
||||
@@ -97,13 +98,13 @@ TEST_F(WebSocketClientTest, Open) {
|
||||
|
||||
clientPipe->Connect(pipeName, [&] {
|
||||
auto ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName);
|
||||
ws->closed.connect([&](uint16_t code, StringRef reason) {
|
||||
ws->closed.connect([&](uint16_t code, std::string_view reason) {
|
||||
Finish();
|
||||
if (code != 1005 && code != 1006) {
|
||||
FAIL() << "Code: " << code << " Reason: " << reason;
|
||||
}
|
||||
});
|
||||
ws->open.connect([&](StringRef protocol) {
|
||||
ws->open.connect([&](std::string_view protocol) {
|
||||
++gotOpen;
|
||||
Finish();
|
||||
ASSERT_TRUE(protocol.empty());
|
||||
@@ -125,12 +126,12 @@ TEST_F(WebSocketClientTest, BadAccept) {
|
||||
|
||||
clientPipe->Connect(pipeName, [&] {
|
||||
auto ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName);
|
||||
ws->closed.connect([&](uint16_t code, StringRef msg) {
|
||||
ws->closed.connect([&](uint16_t code, std::string_view msg) {
|
||||
Finish();
|
||||
++gotClosed;
|
||||
ASSERT_EQ(code, 1002) << "Message: " << msg;
|
||||
});
|
||||
ws->open.connect([&](StringRef protocol) {
|
||||
ws->open.connect([&](std::string_view protocol) {
|
||||
Finish();
|
||||
FAIL() << "Got open";
|
||||
});
|
||||
@@ -152,13 +153,13 @@ TEST_F(WebSocketClientTest, ProtocolGood) {
|
||||
clientPipe->Connect(pipeName, [&] {
|
||||
auto ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName,
|
||||
{"myProtocol", "myProtocol2"});
|
||||
ws->closed.connect([&](uint16_t code, StringRef msg) {
|
||||
ws->closed.connect([&](uint16_t code, std::string_view msg) {
|
||||
Finish();
|
||||
if (code != 1005 && code != 1006) {
|
||||
FAIL() << "Code: " << code << "Message: " << msg;
|
||||
}
|
||||
});
|
||||
ws->open.connect([&](StringRef protocol) {
|
||||
ws->open.connect([&](std::string_view protocol) {
|
||||
++gotOpen;
|
||||
Finish();
|
||||
ASSERT_EQ(protocol, "myProtocol");
|
||||
@@ -180,12 +181,12 @@ TEST_F(WebSocketClientTest, ProtocolRespNotReq) {
|
||||
|
||||
clientPipe->Connect(pipeName, [&] {
|
||||
auto ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName);
|
||||
ws->closed.connect([&](uint16_t code, StringRef msg) {
|
||||
ws->closed.connect([&](uint16_t code, std::string_view msg) {
|
||||
Finish();
|
||||
++gotClosed;
|
||||
ASSERT_EQ(code, 1003) << "Message: " << msg;
|
||||
});
|
||||
ws->open.connect([&](StringRef protocol) {
|
||||
ws->open.connect([&](std::string_view protocol) {
|
||||
Finish();
|
||||
FAIL() << "Got open";
|
||||
});
|
||||
@@ -204,13 +205,13 @@ TEST_F(WebSocketClientTest, ProtocolReqNotResp) {
|
||||
|
||||
clientPipe->Connect(pipeName, [&] {
|
||||
auto ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName,
|
||||
StringRef{"myProtocol"});
|
||||
ws->closed.connect([&](uint16_t code, StringRef msg) {
|
||||
std::string_view{"myProtocol"});
|
||||
ws->closed.connect([&](uint16_t code, std::string_view msg) {
|
||||
Finish();
|
||||
++gotClosed;
|
||||
ASSERT_EQ(code, 1002) << "Message: " << msg;
|
||||
});
|
||||
ws->open.connect([&](StringRef protocol) {
|
||||
ws->open.connect([&](std::string_view protocol) {
|
||||
Finish();
|
||||
FAIL() << "Got open";
|
||||
});
|
||||
@@ -252,7 +253,7 @@ TEST_P(WebSocketClientDataTest, SendBinary) {
|
||||
int gotCallback = 0;
|
||||
std::vector<uint8_t> data(GetParam(), 0x03u);
|
||||
setupWebSocket = [&] {
|
||||
ws->open.connect([&](StringRef) {
|
||||
ws->open.connect([&](std::string_view) {
|
||||
ws->SendBinary(uv::Buffer(data), [&](auto bufs, uv::Error) {
|
||||
++gotCallback;
|
||||
ws->Terminate();
|
||||
@@ -300,11 +301,11 @@ TEST_P(WebSocketClientDataTest, ReceiveMasked) {
|
||||
int gotCallback = 0;
|
||||
std::vector<uint8_t> data(GetParam(), ' ');
|
||||
setupWebSocket = [&] {
|
||||
ws->text.connect([&](StringRef, bool) {
|
||||
ws->text.connect([&](std::string_view, bool) {
|
||||
ws->Terminate();
|
||||
FAIL() << "Should not have gotten masked message";
|
||||
});
|
||||
ws->closed.connect([&](uint16_t code, StringRef reason) {
|
||||
ws->closed.connect([&](uint16_t code, std::string_view reason) {
|
||||
++gotCallback;
|
||||
ASSERT_EQ(code, 1002) << "reason: " << reason;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user