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:
@@ -23,11 +23,11 @@ std::ostream& operator<<(std::ostream& os, const Base64TestParam& param) {
|
||||
|
||||
class Base64Test : public ::testing::TestWithParam<Base64TestParam> {
|
||||
protected:
|
||||
StringRef GetPlain() {
|
||||
std::string_view GetPlain() {
|
||||
if (GetParam().plain_len < 0) {
|
||||
return StringRef(GetParam().plain);
|
||||
return GetParam().plain;
|
||||
} else {
|
||||
return StringRef(GetParam().plain, GetParam().plain_len);
|
||||
return std::string_view(GetParam().plain, GetParam().plain_len);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -51,7 +51,7 @@ TEST_P(Base64Test, EncodeSmallString) {
|
||||
|
||||
TEST_P(Base64Test, DecodeStdString) {
|
||||
std::string s;
|
||||
StringRef encoded = GetParam().encoded;
|
||||
std::string_view encoded = GetParam().encoded;
|
||||
EXPECT_EQ(encoded.size(), Base64Decode(encoded, &s));
|
||||
ASSERT_EQ(GetPlain(), s);
|
||||
|
||||
@@ -62,9 +62,9 @@ TEST_P(Base64Test, DecodeStdString) {
|
||||
|
||||
TEST_P(Base64Test, DecodeSmallString) {
|
||||
SmallString<128> buf;
|
||||
StringRef encoded = GetParam().encoded;
|
||||
std::string_view encoded = GetParam().encoded;
|
||||
size_t len;
|
||||
StringRef plain = Base64Decode(encoded, &len, buf);
|
||||
std::string_view plain = Base64Decode(encoded, &len, buf);
|
||||
EXPECT_EQ(encoded.size(), len);
|
||||
ASSERT_EQ(GetPlain(), plain);
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace wpi {
|
||||
TEST(HttpParserTest, UrlMethodHeadersComplete) {
|
||||
HttpParser p{HttpParser::kRequest};
|
||||
int callbacks = 0;
|
||||
p.url.connect([&](StringRef path) {
|
||||
p.url.connect([&](std::string_view path) {
|
||||
ASSERT_EQ(path, "/foo/bar");
|
||||
ASSERT_EQ(p.GetUrl(), "/foo/bar");
|
||||
++callbacks;
|
||||
@@ -29,7 +29,7 @@ TEST(HttpParserTest, UrlMethodHeadersComplete) {
|
||||
TEST(HttpParserTest, UrlMethodHeader) {
|
||||
HttpParser p{HttpParser::kRequest};
|
||||
int callbacks = 0;
|
||||
p.url.connect([&](StringRef path) {
|
||||
p.url.connect([&](std::string_view path) {
|
||||
ASSERT_EQ(path, "/foo/bar");
|
||||
ASSERT_EQ(p.GetUrl(), "/foo/bar");
|
||||
++callbacks;
|
||||
@@ -49,7 +49,7 @@ TEST(HttpParserTest, UrlMethodHeader) {
|
||||
TEST(HttpParserTest, StatusHeadersComplete) {
|
||||
HttpParser p{HttpParser::kResponse};
|
||||
int callbacks = 0;
|
||||
p.status.connect([&](StringRef status) {
|
||||
p.status.connect([&](std::string_view status) {
|
||||
ASSERT_EQ(status, "OK");
|
||||
ASSERT_EQ(p.GetStatusCode(), 200u);
|
||||
++callbacks;
|
||||
@@ -66,7 +66,7 @@ TEST(HttpParserTest, StatusHeadersComplete) {
|
||||
TEST(HttpParserTest, StatusHeader) {
|
||||
HttpParser p{HttpParser::kResponse};
|
||||
int callbacks = 0;
|
||||
p.status.connect([&](StringRef status) {
|
||||
p.status.connect([&](std::string_view status) {
|
||||
ASSERT_EQ(status, "OK");
|
||||
ASSERT_EQ(p.GetStatusCode(), 200u);
|
||||
++callbacks;
|
||||
@@ -83,7 +83,7 @@ TEST(HttpParserTest, StatusHeader) {
|
||||
TEST(HttpParserTest, HeaderFieldComplete) {
|
||||
HttpParser p{HttpParser::kRequest};
|
||||
int callbacks = 0;
|
||||
p.header.connect([&](StringRef name, StringRef value) {
|
||||
p.header.connect([&](std::string_view name, std::string_view value) {
|
||||
ASSERT_EQ(name, "Foo");
|
||||
ASSERT_EQ(value, "Bar");
|
||||
++callbacks;
|
||||
@@ -106,7 +106,7 @@ TEST(HttpParserTest, HeaderFieldComplete) {
|
||||
TEST(HttpParserTest, HeaderFieldNext) {
|
||||
HttpParser p{HttpParser::kRequest};
|
||||
int callbacks = 0;
|
||||
p.header.connect([&](StringRef name, StringRef value) {
|
||||
p.header.connect([&](std::string_view name, std::string_view value) {
|
||||
ASSERT_EQ(name, "Foo");
|
||||
ASSERT_EQ(value, "Bar");
|
||||
++callbacks;
|
||||
|
||||
@@ -12,7 +12,7 @@ class HttpWebSocketServerConnectionTest
|
||||
: public HttpWebSocketServerConnection<HttpWebSocketServerConnectionTest> {
|
||||
public:
|
||||
HttpWebSocketServerConnectionTest(std::shared_ptr<uv::Stream> stream,
|
||||
ArrayRef<StringRef> protocols)
|
||||
ArrayRef<std::string_view> protocols)
|
||||
: HttpWebSocketServerConnection{stream, protocols} {}
|
||||
|
||||
void ProcessRequest() override { ++gotRequest; }
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ TEST_F(WebSocketIntegrationTest, Open) {
|
||||
serverPipe->Listen([&]() {
|
||||
auto conn = serverPipe->Accept();
|
||||
auto server = WebSocketServer::Create(*conn);
|
||||
server->connected.connect([&](StringRef url, WebSocket&) {
|
||||
server->connected.connect([&](std::string_view url, WebSocket&) {
|
||||
++gotServerOpen;
|
||||
ASSERT_EQ(url, "/test");
|
||||
});
|
||||
@@ -27,13 +27,13 @@ TEST_F(WebSocketIntegrationTest, 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([&, s = ws.get()](StringRef) {
|
||||
ws->open.connect([&, s = ws.get()](std::string_view) {
|
||||
++gotClientOpen;
|
||||
s->Close();
|
||||
});
|
||||
@@ -52,7 +52,7 @@ TEST_F(WebSocketIntegrationTest, Protocol) {
|
||||
serverPipe->Listen([&]() {
|
||||
auto conn = serverPipe->Accept();
|
||||
auto server = WebSocketServer::Create(*conn, {"proto1", "proto2"});
|
||||
server->connected.connect([&](StringRef, WebSocket& ws) {
|
||||
server->connected.connect([&](std::string_view, WebSocket& ws) {
|
||||
++gotServerOpen;
|
||||
ASSERT_EQ(ws.GetProtocol(), "proto1");
|
||||
});
|
||||
@@ -61,13 +61,13 @@ TEST_F(WebSocketIntegrationTest, Protocol) {
|
||||
clientPipe->Connect(pipeName, [&] {
|
||||
auto ws =
|
||||
WebSocket::CreateClient(*clientPipe, "/test", pipeName, {"proto1"});
|
||||
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([&, s = ws.get()](StringRef protocol) {
|
||||
ws->open.connect([&, s = ws.get()](std::string_view protocol) {
|
||||
++gotClientOpen;
|
||||
s->Close();
|
||||
ASSERT_EQ(protocol, "proto1");
|
||||
@@ -86,7 +86,7 @@ TEST_F(WebSocketIntegrationTest, ServerSendBinary) {
|
||||
serverPipe->Listen([&]() {
|
||||
auto conn = serverPipe->Accept();
|
||||
auto server = WebSocketServer::Create(*conn);
|
||||
server->connected.connect([&](StringRef, WebSocket& ws) {
|
||||
server->connected.connect([&](std::string_view, WebSocket& ws) {
|
||||
ws.SendBinary(uv::Buffer{"\x03\x04", 2}, [&](auto, uv::Error) {});
|
||||
ws.Close();
|
||||
});
|
||||
@@ -94,7 +94,7 @@ TEST_F(WebSocketIntegrationTest, ServerSendBinary) {
|
||||
|
||||
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;
|
||||
@@ -119,8 +119,8 @@ TEST_F(WebSocketIntegrationTest, ClientSendText) {
|
||||
serverPipe->Listen([&]() {
|
||||
auto conn = serverPipe->Accept();
|
||||
auto server = WebSocketServer::Create(*conn);
|
||||
server->connected.connect([&](StringRef, WebSocket& ws) {
|
||||
ws.text.connect([&](StringRef data, bool) {
|
||||
server->connected.connect([&](std::string_view, WebSocket& ws) {
|
||||
ws.text.connect([&](std::string_view data, bool) {
|
||||
++gotData;
|
||||
ASSERT_EQ(data, "hello");
|
||||
});
|
||||
@@ -129,13 +129,13 @@ TEST_F(WebSocketIntegrationTest, ClientSendText) {
|
||||
|
||||
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([&, s = ws.get()](StringRef) {
|
||||
ws->open.connect([&, s = ws.get()](std::string_view) {
|
||||
s->SendText(uv::Buffer{"hello"}, [&](auto, uv::Error) {});
|
||||
s->Close();
|
||||
});
|
||||
|
||||
@@ -28,7 +28,7 @@ class WebSocketServerTest : public WebSocketTest {
|
||||
clientPipe->Connect(pipeName, [this]() {
|
||||
clientPipe->StartRead();
|
||||
clientPipe->data.connect([this](uv::Buffer& buf, size_t size) {
|
||||
StringRef data{buf.base, size};
|
||||
std::string_view data{buf.base, size};
|
||||
if (!headersDone) {
|
||||
data = resp.Execute(data);
|
||||
if (resp.HasError()) {
|
||||
@@ -40,7 +40,7 @@ class WebSocketServerTest : public WebSocketTest {
|
||||
return;
|
||||
}
|
||||
}
|
||||
wireData.insert(wireData.end(), data.bytes_begin(), data.bytes_end());
|
||||
wireData.insert(wireData.end(), data.begin(), data.end());
|
||||
if (handleData) {
|
||||
handleData(data);
|
||||
}
|
||||
@@ -50,7 +50,7 @@ class WebSocketServerTest : public WebSocketTest {
|
||||
}
|
||||
|
||||
std::function<void()> setupWebSocket;
|
||||
std::function<void(StringRef)> handleData;
|
||||
std::function<void(std::string_view)> handleData;
|
||||
std::vector<uint8_t> wireData;
|
||||
std::shared_ptr<WebSocket> ws;
|
||||
HttpParser resp{HttpParser::kResponse};
|
||||
@@ -64,8 +64,8 @@ class WebSocketServerTest : public WebSocketTest {
|
||||
TEST_F(WebSocketServerTest, Terminate) {
|
||||
int gotClosed = 0;
|
||||
setupWebSocket = [&] {
|
||||
ws->open.connect([&](StringRef) { ws->Terminate(); });
|
||||
ws->closed.connect([&](uint16_t code, StringRef reason) {
|
||||
ws->open.connect([&](std::string_view) { ws->Terminate(); });
|
||||
ws->closed.connect([&](uint16_t code, std::string_view reason) {
|
||||
++gotClosed;
|
||||
ASSERT_EQ(code, 1006) << "reason: " << reason;
|
||||
});
|
||||
@@ -80,8 +80,8 @@ TEST_F(WebSocketServerTest, Terminate) {
|
||||
TEST_F(WebSocketServerTest, TerminateCode) {
|
||||
int gotClosed = 0;
|
||||
setupWebSocket = [&] {
|
||||
ws->open.connect([&](StringRef) { ws->Terminate(1000); });
|
||||
ws->closed.connect([&](uint16_t code, StringRef reason) {
|
||||
ws->open.connect([&](std::string_view) { ws->Terminate(1000); });
|
||||
ws->closed.connect([&](uint16_t code, std::string_view reason) {
|
||||
++gotClosed;
|
||||
ASSERT_EQ(code, 1000) << "reason: " << reason;
|
||||
});
|
||||
@@ -96,8 +96,8 @@ TEST_F(WebSocketServerTest, TerminateCode) {
|
||||
TEST_F(WebSocketServerTest, TerminateReason) {
|
||||
int gotClosed = 0;
|
||||
setupWebSocket = [&] {
|
||||
ws->open.connect([&](StringRef) { ws->Terminate(1000, "reason"); });
|
||||
ws->closed.connect([&](uint16_t code, StringRef reason) {
|
||||
ws->open.connect([&](std::string_view) { ws->Terminate(1000, "reason"); });
|
||||
ws->closed.connect([&](uint16_t code, std::string_view reason) {
|
||||
++gotClosed;
|
||||
ASSERT_EQ(code, 1000);
|
||||
ASSERT_EQ(reason, "reason");
|
||||
@@ -117,15 +117,15 @@ TEST_F(WebSocketServerTest, TerminateReason) {
|
||||
TEST_F(WebSocketServerTest, CloseBasic) {
|
||||
int gotClosed = 0;
|
||||
setupWebSocket = [&] {
|
||||
ws->open.connect([&](StringRef) { ws->Close(); });
|
||||
ws->closed.connect([&](uint16_t code, StringRef reason) {
|
||||
ws->open.connect([&](std::string_view) { ws->Close(); });
|
||||
ws->closed.connect([&](uint16_t code, std::string_view reason) {
|
||||
++gotClosed;
|
||||
ASSERT_EQ(code, 1005) << "reason: " << reason;
|
||||
});
|
||||
};
|
||||
// need to respond with close for server to finish shutdown
|
||||
auto message = BuildMessage(0x08, true, true, {});
|
||||
handleData = [&](StringRef) {
|
||||
handleData = [&](std::string_view) {
|
||||
clientPipe->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
|
||||
};
|
||||
|
||||
@@ -139,8 +139,8 @@ TEST_F(WebSocketServerTest, CloseBasic) {
|
||||
TEST_F(WebSocketServerTest, CloseCode) {
|
||||
int gotClosed = 0;
|
||||
setupWebSocket = [&] {
|
||||
ws->open.connect([&](StringRef) { ws->Close(1000); });
|
||||
ws->closed.connect([&](uint16_t code, StringRef reason) {
|
||||
ws->open.connect([&](std::string_view) { ws->Close(1000); });
|
||||
ws->closed.connect([&](uint16_t code, std::string_view reason) {
|
||||
++gotClosed;
|
||||
ASSERT_EQ(code, 1000) << "reason: " << reason;
|
||||
});
|
||||
@@ -148,7 +148,7 @@ TEST_F(WebSocketServerTest, CloseCode) {
|
||||
// need to respond with close for server to finish shutdown
|
||||
const uint8_t contents[] = {0x03u, 0xe8u};
|
||||
auto message = BuildMessage(0x08, true, true, contents);
|
||||
handleData = [&](StringRef) {
|
||||
handleData = [&](std::string_view) {
|
||||
clientPipe->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
|
||||
};
|
||||
|
||||
@@ -162,8 +162,8 @@ TEST_F(WebSocketServerTest, CloseCode) {
|
||||
TEST_F(WebSocketServerTest, CloseReason) {
|
||||
int gotClosed = 0;
|
||||
setupWebSocket = [&] {
|
||||
ws->open.connect([&](StringRef) { ws->Close(1000, "hangup"); });
|
||||
ws->closed.connect([&](uint16_t code, StringRef reason) {
|
||||
ws->open.connect([&](std::string_view) { ws->Close(1000, "hangup"); });
|
||||
ws->closed.connect([&](uint16_t code, std::string_view reason) {
|
||||
++gotClosed;
|
||||
ASSERT_EQ(code, 1000);
|
||||
ASSERT_EQ(reason, "hangup");
|
||||
@@ -172,7 +172,7 @@ TEST_F(WebSocketServerTest, CloseReason) {
|
||||
// need to respond with close for server to finish shutdown
|
||||
const uint8_t contents[] = {0x03u, 0xe8u, 'h', 'a', 'n', 'g', 'u', 'p'};
|
||||
auto message = BuildMessage(0x08, true, true, contents);
|
||||
handleData = [&](StringRef) {
|
||||
handleData = [&](std::string_view) {
|
||||
clientPipe->Write(uv::Buffer(message), [&](auto bufs, uv::Error) {});
|
||||
};
|
||||
|
||||
@@ -190,7 +190,7 @@ TEST_F(WebSocketServerTest, CloseReason) {
|
||||
TEST_F(WebSocketServerTest, ReceiveCloseBasic) {
|
||||
int gotClosed = 0;
|
||||
setupWebSocket = [&] {
|
||||
ws->closed.connect([&](uint16_t code, StringRef reason) {
|
||||
ws->closed.connect([&](uint16_t code, std::string_view reason) {
|
||||
++gotClosed;
|
||||
ASSERT_EQ(code, 1005) << "reason: " << reason;
|
||||
});
|
||||
@@ -211,7 +211,7 @@ TEST_F(WebSocketServerTest, ReceiveCloseBasic) {
|
||||
TEST_F(WebSocketServerTest, ReceiveCloseCode) {
|
||||
int gotClosed = 0;
|
||||
setupWebSocket = [&] {
|
||||
ws->closed.connect([&](uint16_t code, StringRef reason) {
|
||||
ws->closed.connect([&](uint16_t code, std::string_view reason) {
|
||||
++gotClosed;
|
||||
ASSERT_EQ(code, 1000) << "reason: " << reason;
|
||||
});
|
||||
@@ -233,7 +233,7 @@ TEST_F(WebSocketServerTest, ReceiveCloseCode) {
|
||||
TEST_F(WebSocketServerTest, ReceiveCloseReason) {
|
||||
int gotClosed = 0;
|
||||
setupWebSocket = [&] {
|
||||
ws->closed.connect([&](uint16_t code, StringRef reason) {
|
||||
ws->closed.connect([&](uint16_t code, std::string_view reason) {
|
||||
++gotClosed;
|
||||
ASSERT_EQ(code, 1000);
|
||||
ASSERT_EQ(reason, "hangup");
|
||||
@@ -271,7 +271,7 @@ TEST_P(WebSocketServerBadOpcodeTest, Receive) {
|
||||
int gotCallback = 0;
|
||||
std::vector<uint8_t> data(4, 0x03);
|
||||
setupWebSocket = [&] {
|
||||
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;
|
||||
});
|
||||
@@ -302,7 +302,7 @@ TEST_P(WebSocketServerControlFrameTest, ReceiveFragment) {
|
||||
int gotCallback = 0;
|
||||
std::vector<uint8_t> data(4, 0x03);
|
||||
setupWebSocket = [&] {
|
||||
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;
|
||||
});
|
||||
@@ -329,7 +329,7 @@ TEST_F(WebSocketServerTest, ReceiveFragmentInvalidNoPrevFrame) {
|
||||
int gotCallback = 0;
|
||||
std::vector<uint8_t> data(4, 0x03);
|
||||
setupWebSocket = [&] {
|
||||
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;
|
||||
});
|
||||
@@ -349,7 +349,7 @@ TEST_F(WebSocketServerTest, ReceiveFragmentInvalidNoPrevFragment) {
|
||||
int gotCallback = 0;
|
||||
std::vector<uint8_t> data(4, 0x03);
|
||||
setupWebSocket = [&] {
|
||||
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;
|
||||
});
|
||||
@@ -370,7 +370,7 @@ TEST_F(WebSocketServerTest, ReceiveFragmentInvalidNoPrevFragment) {
|
||||
TEST_F(WebSocketServerTest, ReceiveFragmentInvalidIncomplete) {
|
||||
int gotCallback = 0;
|
||||
setupWebSocket = [&] {
|
||||
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;
|
||||
});
|
||||
@@ -488,7 +488,7 @@ TEST_F(WebSocketServerTest, ReceiveTooLarge) {
|
||||
ws->Terminate();
|
||||
FAIL() << "Should not have gotten unmasked message";
|
||||
});
|
||||
ws->closed.connect([&](uint16_t code, StringRef reason) {
|
||||
ws->closed.connect([&](uint16_t code, std::string_view reason) {
|
||||
++gotCallback;
|
||||
ASSERT_EQ(code, 1009) << "reason: " << reason;
|
||||
});
|
||||
@@ -513,7 +513,7 @@ TEST_F(WebSocketServerTest, ReceiveTooLargeFragmented) {
|
||||
ws->Terminate();
|
||||
FAIL() << "Should not have gotten unmasked message";
|
||||
});
|
||||
ws->closed.connect([&](uint16_t code, StringRef reason) {
|
||||
ws->closed.connect([&](uint16_t code, std::string_view reason) {
|
||||
++gotCallback;
|
||||
ASSERT_EQ(code, 1009) << "reason: " << reason;
|
||||
});
|
||||
@@ -544,7 +544,7 @@ TEST_P(WebSocketServerDataTest, SendText) {
|
||||
int gotCallback = 0;
|
||||
std::vector<uint8_t> data(GetParam(), ' ');
|
||||
setupWebSocket = [&] {
|
||||
ws->open.connect([&](StringRef) {
|
||||
ws->open.connect([&](std::string_view) {
|
||||
ws->SendText(uv::Buffer(data), [&](auto bufs, uv::Error) {
|
||||
++gotCallback;
|
||||
ws->Terminate();
|
||||
@@ -565,7 +565,7 @@ TEST_P(WebSocketServerDataTest, 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();
|
||||
@@ -586,7 +586,7 @@ TEST_P(WebSocketServerDataTest, SendPing) {
|
||||
int gotCallback = 0;
|
||||
std::vector<uint8_t> data(GetParam(), 0x03u);
|
||||
setupWebSocket = [&] {
|
||||
ws->open.connect([&](StringRef) {
|
||||
ws->open.connect([&](std::string_view) {
|
||||
ws->SendPing(uv::Buffer(data), [&](auto bufs, uv::Error) {
|
||||
++gotCallback;
|
||||
ws->Terminate();
|
||||
@@ -607,7 +607,7 @@ TEST_P(WebSocketServerDataTest, SendPong) {
|
||||
int gotCallback = 0;
|
||||
std::vector<uint8_t> data(GetParam(), 0x03u);
|
||||
setupWebSocket = [&] {
|
||||
ws->open.connect([&](StringRef) {
|
||||
ws->open.connect([&](std::string_view) {
|
||||
ws->SendPong(uv::Buffer(data), [&](auto bufs, uv::Error) {
|
||||
++gotCallback;
|
||||
ws->Terminate();
|
||||
@@ -628,12 +628,12 @@ TEST_P(WebSocketServerDataTest, ReceiveText) {
|
||||
int gotCallback = 0;
|
||||
std::vector<uint8_t> data(GetParam(), ' ');
|
||||
setupWebSocket = [&] {
|
||||
ws->text.connect([&](StringRef inData, bool fin) {
|
||||
ws->text.connect([&](std::string_view inData, bool fin) {
|
||||
++gotCallback;
|
||||
ws->Terminate();
|
||||
ASSERT_TRUE(fin);
|
||||
std::vector<uint8_t> recvData;
|
||||
recvData.insert(recvData.end(), inData.bytes_begin(), inData.bytes_end());
|
||||
recvData.insert(recvData.end(), inData.begin(), inData.end());
|
||||
ASSERT_EQ(data, recvData);
|
||||
});
|
||||
};
|
||||
@@ -719,11 +719,11 @@ TEST_P(WebSocketServerDataTest, ReceiveUnmasked) {
|
||||
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 unmasked 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;
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "WebSocketTest.h"
|
||||
|
||||
#include "wpi/HttpParser.h"
|
||||
#include "wpi/StringExtras.h"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
@@ -106,24 +107,24 @@ TEST_F(WebSocketTest, CreateClientBasic) {
|
||||
int gotVersion = 0;
|
||||
|
||||
HttpParser req{HttpParser::kRequest};
|
||||
req.url.connect([](StringRef url) { ASSERT_EQ(url, "/test"); });
|
||||
req.header.connect([&](StringRef name, StringRef value) {
|
||||
if (name.equals_lower("host")) {
|
||||
req.url.connect([](std::string_view url) { ASSERT_EQ(url, "/test"); });
|
||||
req.header.connect([&](std::string_view name, std::string_view value) {
|
||||
if (equals_lower(name, "host")) {
|
||||
ASSERT_EQ(value, pipeName);
|
||||
++gotHost;
|
||||
} else if (name.equals_lower("upgrade")) {
|
||||
} else if (equals_lower(name, "upgrade")) {
|
||||
ASSERT_EQ(value, "websocket");
|
||||
++gotUpgrade;
|
||||
} else if (name.equals_lower("connection")) {
|
||||
} else if (equals_lower(name, "connection")) {
|
||||
ASSERT_EQ(value, "Upgrade");
|
||||
++gotConnection;
|
||||
} else if (name.equals_lower("sec-websocket-key")) {
|
||||
} else if (equals_lower(name, "sec-websocket-key")) {
|
||||
++gotKey;
|
||||
} else if (name.equals_lower("sec-websocket-version")) {
|
||||
} else if (equals_lower(name, "sec-websocket-version")) {
|
||||
ASSERT_EQ(value, "13");
|
||||
++gotVersion;
|
||||
} else {
|
||||
FAIL() << "unexpected header " << name.str();
|
||||
FAIL() << "unexpected header " << name;
|
||||
}
|
||||
});
|
||||
req.headersComplete.connect([&](bool) { Finish(); });
|
||||
@@ -132,7 +133,7 @@ TEST_F(WebSocketTest, CreateClientBasic) {
|
||||
auto conn = serverPipe->Accept();
|
||||
conn->StartRead();
|
||||
conn->data.connect([&](uv::Buffer& buf, size_t size) {
|
||||
req.Execute(StringRef{buf.base, size});
|
||||
req.Execute(std::string_view{buf.base, size});
|
||||
if (req.HasError()) {
|
||||
Finish();
|
||||
}
|
||||
@@ -159,11 +160,11 @@ TEST_F(WebSocketTest, CreateClientExtraHeaders) {
|
||||
int gotExtra1 = 0;
|
||||
int gotExtra2 = 0;
|
||||
HttpParser req{HttpParser::kRequest};
|
||||
req.header.connect([&](StringRef name, StringRef value) {
|
||||
if (name.equals("Extra1")) {
|
||||
req.header.connect([&](std::string_view name, std::string_view value) {
|
||||
if (equals(name, "Extra1")) {
|
||||
ASSERT_EQ(value, "Data1");
|
||||
++gotExtra1;
|
||||
} else if (name.equals("Extra2")) {
|
||||
} else if (equals(name, "Extra2")) {
|
||||
ASSERT_EQ(value, "Data2");
|
||||
++gotExtra2;
|
||||
}
|
||||
@@ -174,7 +175,7 @@ TEST_F(WebSocketTest, CreateClientExtraHeaders) {
|
||||
auto conn = serverPipe->Accept();
|
||||
conn->StartRead();
|
||||
conn->data.connect([&](uv::Buffer& buf, size_t size) {
|
||||
req.Execute(StringRef{buf.base, size});
|
||||
req.Execute(std::string_view{buf.base, size});
|
||||
if (req.HasError()) {
|
||||
Finish();
|
||||
}
|
||||
@@ -183,12 +184,12 @@ TEST_F(WebSocketTest, CreateClientExtraHeaders) {
|
||||
});
|
||||
clientPipe->Connect(pipeName, [&]() {
|
||||
WebSocket::ClientOptions options;
|
||||
SmallVector<std::pair<StringRef, StringRef>, 4> extraHeaders;
|
||||
SmallVector<std::pair<std::string_view, std::string_view>, 4> extraHeaders;
|
||||
extraHeaders.emplace_back("Extra1", "Data1");
|
||||
extraHeaders.emplace_back("Extra2", "Data2");
|
||||
options.extraHeaders = extraHeaders;
|
||||
auto ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName,
|
||||
ArrayRef<StringRef>{}, options);
|
||||
auto ws =
|
||||
WebSocket::CreateClient(*clientPipe, "/test", pipeName, {}, options);
|
||||
});
|
||||
|
||||
loop->Run();
|
||||
@@ -206,9 +207,9 @@ TEST_F(WebSocketTest, CreateClientTimeout) {
|
||||
clientPipe->Connect(pipeName, [&]() {
|
||||
WebSocket::ClientOptions options;
|
||||
options.handshakeTimeout = uv::Timer::Time{100};
|
||||
auto ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName,
|
||||
ArrayRef<StringRef>{}, options);
|
||||
ws->closed.connect([&](uint16_t code, StringRef) {
|
||||
auto ws =
|
||||
WebSocket::CreateClient(*clientPipe, "/test", pipeName, {}, options);
|
||||
ws->closed.connect([&](uint16_t code, std::string_view) {
|
||||
Finish();
|
||||
++gotClosed;
|
||||
ASSERT_EQ(code, 1006);
|
||||
@@ -231,22 +232,22 @@ TEST_F(WebSocketTest, CreateServerBasic) {
|
||||
int gotOpen = 0;
|
||||
|
||||
HttpParser resp{HttpParser::kResponse};
|
||||
resp.status.connect([&](StringRef status) {
|
||||
resp.status.connect([&](std::string_view status) {
|
||||
++gotStatus;
|
||||
ASSERT_EQ(resp.GetStatusCode(), 101u) << "status: " << status;
|
||||
});
|
||||
resp.header.connect([&](StringRef name, StringRef value) {
|
||||
if (name.equals_lower("upgrade")) {
|
||||
resp.header.connect([&](std::string_view name, std::string_view value) {
|
||||
if (equals_lower(name, "upgrade")) {
|
||||
ASSERT_EQ(value, "websocket");
|
||||
++gotUpgrade;
|
||||
} else if (name.equals_lower("connection")) {
|
||||
} else if (equals_lower(name, "connection")) {
|
||||
ASSERT_EQ(value, "Upgrade");
|
||||
++gotConnection;
|
||||
} else if (name.equals_lower("sec-websocket-accept")) {
|
||||
} else if (equals_lower(name, "sec-websocket-accept")) {
|
||||
ASSERT_EQ(value, "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=");
|
||||
++gotAccept;
|
||||
} else {
|
||||
FAIL() << "unexpected header " << name.str();
|
||||
FAIL() << "unexpected header " << name;
|
||||
}
|
||||
});
|
||||
resp.headersComplete.connect([&](bool) { Finish(); });
|
||||
@@ -254,7 +255,7 @@ TEST_F(WebSocketTest, CreateServerBasic) {
|
||||
serverPipe->Listen([&]() {
|
||||
auto conn = serverPipe->Accept();
|
||||
auto ws = WebSocket::CreateServer(*conn, "dGhlIHNhbXBsZSBub25jZQ==", "13");
|
||||
ws->open.connect([&](StringRef protocol) {
|
||||
ws->open.connect([&](std::string_view protocol) {
|
||||
++gotOpen;
|
||||
ASSERT_TRUE(protocol.empty());
|
||||
});
|
||||
@@ -262,7 +263,7 @@ TEST_F(WebSocketTest, CreateServerBasic) {
|
||||
clientPipe->Connect(pipeName, [&] {
|
||||
clientPipe->StartRead();
|
||||
clientPipe->data.connect([&](uv::Buffer& buf, size_t size) {
|
||||
resp.Execute(StringRef{buf.base, size});
|
||||
resp.Execute(std::string_view{buf.base, size});
|
||||
if (resp.HasError()) {
|
||||
Finish();
|
||||
}
|
||||
@@ -287,8 +288,8 @@ TEST_F(WebSocketTest, CreateServerProtocol) {
|
||||
int gotOpen = 0;
|
||||
|
||||
HttpParser resp{HttpParser::kResponse};
|
||||
resp.header.connect([&](StringRef name, StringRef value) {
|
||||
if (name.equals_lower("sec-websocket-protocol")) {
|
||||
resp.header.connect([&](std::string_view name, std::string_view value) {
|
||||
if (equals_lower(name, "sec-websocket-protocol")) {
|
||||
++gotProtocol;
|
||||
ASSERT_EQ(value, "myProtocol");
|
||||
}
|
||||
@@ -298,7 +299,7 @@ TEST_F(WebSocketTest, CreateServerProtocol) {
|
||||
serverPipe->Listen([&]() {
|
||||
auto conn = serverPipe->Accept();
|
||||
auto ws = WebSocket::CreateServer(*conn, "foo", "13", "myProtocol");
|
||||
ws->open.connect([&](StringRef protocol) {
|
||||
ws->open.connect([&](std::string_view protocol) {
|
||||
++gotOpen;
|
||||
ASSERT_EQ(protocol, "myProtocol");
|
||||
});
|
||||
@@ -306,7 +307,7 @@ TEST_F(WebSocketTest, CreateServerProtocol) {
|
||||
clientPipe->Connect(pipeName, [&] {
|
||||
clientPipe->StartRead();
|
||||
clientPipe->data.connect([&](uv::Buffer& buf, size_t size) {
|
||||
resp.Execute(StringRef{buf.base, size});
|
||||
resp.Execute(std::string_view{buf.base, size});
|
||||
if (resp.HasError()) {
|
||||
Finish();
|
||||
}
|
||||
@@ -329,19 +330,19 @@ TEST_F(WebSocketTest, CreateServerBadVersion) {
|
||||
int gotUpgrade = 0;
|
||||
|
||||
HttpParser resp{HttpParser::kResponse};
|
||||
resp.status.connect([&](StringRef status) {
|
||||
resp.status.connect([&](std::string_view status) {
|
||||
++gotStatus;
|
||||
ASSERT_EQ(resp.GetStatusCode(), 426u) << "status: " << status;
|
||||
});
|
||||
resp.header.connect([&](StringRef name, StringRef value) {
|
||||
if (name.equals_lower("sec-websocket-version")) {
|
||||
resp.header.connect([&](std::string_view name, std::string_view value) {
|
||||
if (equals_lower(name, "sec-websocket-version")) {
|
||||
++gotVersion;
|
||||
ASSERT_EQ(value, "13");
|
||||
} else if (name.equals_lower("upgrade")) {
|
||||
} else if (equals_lower(name, "upgrade")) {
|
||||
++gotUpgrade;
|
||||
ASSERT_EQ(value, "WebSocket");
|
||||
} else {
|
||||
FAIL() << "unexpected header " << name.str();
|
||||
FAIL() << "unexpected header " << name;
|
||||
}
|
||||
});
|
||||
resp.headersComplete.connect([&](bool) { Finish(); });
|
||||
@@ -349,7 +350,7 @@ TEST_F(WebSocketTest, CreateServerBadVersion) {
|
||||
serverPipe->Listen([&] {
|
||||
auto conn = serverPipe->Accept();
|
||||
auto ws = WebSocket::CreateServer(*conn, "foo", "14");
|
||||
ws->open.connect([&](StringRef) {
|
||||
ws->open.connect([&](std::string_view) {
|
||||
Finish();
|
||||
FAIL();
|
||||
});
|
||||
@@ -357,7 +358,7 @@ TEST_F(WebSocketTest, CreateServerBadVersion) {
|
||||
clientPipe->Connect(pipeName, [&] {
|
||||
clientPipe->StartRead();
|
||||
clientPipe->data.connect([&](uv::Buffer& buf, size_t size) {
|
||||
resp.Execute(StringRef{buf.base, size});
|
||||
resp.Execute(std::string_view{buf.base, size});
|
||||
if (resp.HasError()) {
|
||||
Finish();
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ SOFTWARE.
|
||||
#include "unit-json.h"
|
||||
using wpi::json;
|
||||
|
||||
#include "wpi/Format.h"
|
||||
#include "fmt/format.h"
|
||||
#include "wpi/StringExtras.h"
|
||||
#include "wpi/raw_ostream.h"
|
||||
|
||||
@@ -919,11 +919,7 @@ static std::string codepoint_to_unicode(std::size_t cp)
|
||||
// reverse solidus, followed by the lowercase letter u, followed
|
||||
// by four hexadecimal digits that encode the character's code
|
||||
// point
|
||||
std::string s;
|
||||
wpi::raw_string_ostream ss(s);
|
||||
ss << "\\u" << wpi::format_hex_no_prefix(cp, 4);
|
||||
ss.flush();
|
||||
return s;
|
||||
return fmt::format("\\u{:04x}", cp);
|
||||
}
|
||||
|
||||
// correct sequences
|
||||
|
||||
@@ -14,23 +14,23 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "wpi/SmallString.h"
|
||||
#include "wpi/StringRef.h"
|
||||
#include "wpi/leb128.h"
|
||||
#include "wpi/raw_istream.h"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
TEST(LEB128Test, WriteUleb128) {
|
||||
#define EXPECT_ULEB128_EQ(EXPECTED, VALUE, PAD) \
|
||||
do { \
|
||||
StringRef expected(EXPECTED, sizeof(EXPECTED) - 1); \
|
||||
SmallString<32> buf; \
|
||||
size_t size = WriteUleb128(buf, VALUE); \
|
||||
EXPECT_EQ(size, buf.size()); \
|
||||
EXPECT_EQ(expected, buf.str()); \
|
||||
#define EXPECT_ULEB128_EQ(EXPECTED, VALUE, PAD) \
|
||||
do { \
|
||||
std::string_view expected(EXPECTED, sizeof(EXPECTED) - 1); \
|
||||
SmallString<32> buf; \
|
||||
size_t size = WriteUleb128(buf, VALUE); \
|
||||
EXPECT_EQ(size, buf.size()); \
|
||||
EXPECT_EQ(expected, buf.str()); \
|
||||
} while (0)
|
||||
|
||||
// Write ULEB128
|
||||
|
||||
@@ -43,7 +43,7 @@ TEST(UvGetAddrInfo, BothNull) {
|
||||
});
|
||||
|
||||
GetAddrInfo(
|
||||
loop, [](const addrinfo&) { FAIL(); }, Twine::createNull());
|
||||
loop, [](const addrinfo&) { FAIL(); }, "");
|
||||
loop->Run();
|
||||
ASSERT_EQ(fail_cb_called, 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user