Add braces to C++ single-line loops and conditionals (NFC) (#2973)

This makes code easier to read and more consistent between C++ and Java.
Also update clang-format settings to always add a line break (even if no braces are used).
This commit is contained in:
Peter Johnson
2020-12-28 12:58:06 -08:00
committed by GitHub
parent 0291a3ff56
commit 2aed432b4b
634 changed files with 10716 additions and 3938 deletions

View File

@@ -19,7 +19,9 @@ class WebSocketClientTest : public WebSocketTest {
// Bare bones server
req.header.connect([this](StringRef name, StringRef value) {
// save key (required for valid response)
if (name.equals_lower("sec-websocket-key")) clientKey = value;
if (name.equals_lower("sec-websocket-key")) {
clientKey = value;
}
});
req.headersComplete.connect([this](bool) {
// send response
@@ -33,23 +35,30 @@ class WebSocketClientTest : public WebSocketTest {
SHA1 hash;
hash.Update(clientKey);
hash.Update("258EAFA5-E914-47DA-95CA-C5AB0DC85B11");
if (mockBadAccept) hash.Update("1");
if (mockBadAccept) {
hash.Update("1");
}
SmallString<64> hashBuf;
SmallString<64> acceptBuf;
os << "Sec-WebSocket-Accept: "
<< Base64Encode(hash.RawFinal(hashBuf), acceptBuf) << "\r\n";
if (!mockProtocol.empty())
if (!mockProtocol.empty()) {
os << "Sec-WebSocket-Protocol: " << mockProtocol << "\r\n";
}
os << "\r\n";
conn->Write(bufs, [](auto bufs, uv::Error) {
for (auto& buf : bufs) buf.Deallocate();
for (auto& buf : bufs) {
buf.Deallocate();
}
});
serverHeadersDone = true;
if (connected) connected();
if (connected) {
connected();
}
});
serverPipe->Listen([this] {
@@ -59,9 +68,13 @@ class WebSocketClientTest : public WebSocketTest {
StringRef data{buf.base, size};
if (!serverHeadersDone) {
data = req.Execute(data);
if (req.HasError()) Finish();
if (req.HasError()) {
Finish();
}
ASSERT_EQ(req.GetError(), HPE_OK) << http_errno_name(req.GetError());
if (data.empty()) return;
if (data.empty()) {
return;
}
}
wireData.insert(wireData.end(), data.bytes_begin(), data.bytes_end());
});
@@ -86,8 +99,9 @@ TEST_F(WebSocketClientTest, Open) {
auto ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName);
ws->closed.connect([&](uint16_t code, StringRef reason) {
Finish();
if (code != 1005 && code != 1006)
if (code != 1005 && code != 1006) {
FAIL() << "Code: " << code << " Reason: " << reason;
}
});
ws->open.connect([&](StringRef protocol) {
++gotOpen;
@@ -98,7 +112,9 @@ TEST_F(WebSocketClientTest, Open) {
loop->Run();
if (HasFatalFailure()) return;
if (HasFatalFailure()) {
return;
}
ASSERT_EQ(gotOpen, 1);
}
@@ -122,7 +138,9 @@ TEST_F(WebSocketClientTest, BadAccept) {
loop->Run();
if (HasFatalFailure()) return;
if (HasFatalFailure()) {
return;
}
ASSERT_EQ(gotClosed, 1);
}
@@ -136,8 +154,9 @@ TEST_F(WebSocketClientTest, ProtocolGood) {
{"myProtocol", "myProtocol2"});
ws->closed.connect([&](uint16_t code, StringRef msg) {
Finish();
if (code != 1005 && code != 1006)
if (code != 1005 && code != 1006) {
FAIL() << "Code: " << code << "Message: " << msg;
}
});
ws->open.connect([&](StringRef protocol) {
++gotOpen;
@@ -148,7 +167,9 @@ TEST_F(WebSocketClientTest, ProtocolGood) {
loop->Run();
if (HasFatalFailure()) return;
if (HasFatalFailure()) {
return;
}
ASSERT_EQ(gotOpen, 1);
}
@@ -172,7 +193,9 @@ TEST_F(WebSocketClientTest, ProtocolRespNotReq) {
loop->Run();
if (HasFatalFailure()) return;
if (HasFatalFailure()) {
return;
}
ASSERT_EQ(gotClosed, 1);
}
@@ -195,7 +218,9 @@ TEST_F(WebSocketClientTest, ProtocolReqNotResp) {
loop->Run();
if (HasFatalFailure()) return;
if (HasFatalFailure()) {
return;
}
ASSERT_EQ(gotClosed, 1);
}
@@ -210,7 +235,9 @@ class WebSocketClientDataTest : public WebSocketClientTest,
WebSocketClientDataTest() {
clientPipe->Connect(pipeName, [&] {
ws = WebSocket::CreateClient(*clientPipe, "/test", pipeName);
if (setupWebSocket) setupWebSocket();
if (setupWebSocket) {
setupWebSocket();
}
});
}