mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
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:
@@ -35,8 +35,9 @@ void ConnectionListenerTest::Connect() {
|
||||
nt::StartClient(client_inst, "127.0.0.1", 10000);
|
||||
|
||||
// wait for client to report it's started, then wait another 0.1 sec
|
||||
while ((nt::GetNetworkMode(client_inst) & NT_NET_MODE_STARTING) != 0)
|
||||
while ((nt::GetNetworkMode(client_inst) & NT_NET_MODE_STARTING) != 0) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,9 @@ TEST_F(EntryListenerTest, EntryNewLocal) {
|
||||
|
||||
TEST_F(EntryListenerTest, DISABLED_EntryNewRemote) {
|
||||
Connect();
|
||||
if (HasFatalFailure()) return;
|
||||
if (HasFatalFailure()) {
|
||||
return;
|
||||
}
|
||||
std::vector<nt::EntryNotification> events;
|
||||
auto handle = nt::AddEntryListener(
|
||||
nt::GetEntry(server_inst, "/foo"),
|
||||
@@ -134,7 +136,9 @@ TEST_F(EntryListenerTest, PrefixNewLocal) {
|
||||
|
||||
TEST_F(EntryListenerTest, DISABLED_PrefixNewRemote) {
|
||||
Connect();
|
||||
if (HasFatalFailure()) return;
|
||||
if (HasFatalFailure()) {
|
||||
return;
|
||||
}
|
||||
std::vector<nt::EntryNotification> events;
|
||||
auto handle = nt::AddEntryListener(
|
||||
server_inst, "/foo",
|
||||
|
||||
@@ -10,7 +10,9 @@ bool MessageMatcher::MatchAndExplain(
|
||||
std::shared_ptr<Message> msg,
|
||||
::testing::MatchResultListener* listener) const {
|
||||
bool match = true;
|
||||
if (!msg) return false;
|
||||
if (!msg) {
|
||||
return false;
|
||||
}
|
||||
if (msg->str() != goodmsg->str()) {
|
||||
*listener << "str mismatch ";
|
||||
match = false;
|
||||
|
||||
@@ -378,10 +378,11 @@ TEST_P(StorageTestPopulated, SetDefaultEntryEmptyName) {
|
||||
EXPECT_FALSE(ret_val);
|
||||
// assert that no entries get added
|
||||
EXPECT_EQ(4u, entries().size());
|
||||
if (GetParam())
|
||||
if (GetParam()) {
|
||||
EXPECT_EQ(4u, idmap().size());
|
||||
else
|
||||
} else {
|
||||
EXPECT_EQ(0u, idmap().size());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(StorageTestPopulated, SetDefaultEntryEmptyValue) {
|
||||
@@ -390,10 +391,11 @@ TEST_P(StorageTestPopulated, SetDefaultEntryEmptyValue) {
|
||||
EXPECT_FALSE(ret_val);
|
||||
// assert that no entries get added
|
||||
EXPECT_EQ(4u, entries().size());
|
||||
if (GetParam())
|
||||
if (GetParam()) {
|
||||
EXPECT_EQ(4u, idmap().size());
|
||||
else
|
||||
} else {
|
||||
EXPECT_EQ(0u, idmap().size());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(StorageTestEmpty, SetEntryFlagsNew) {
|
||||
@@ -446,7 +448,9 @@ TEST_P(StorageTestPopulateOne, GetEntryFlagsExist) {
|
||||
EXPECT_EQ(1u, storage.GetEntryFlags("foo"));
|
||||
}
|
||||
|
||||
TEST_P(StorageTestEmpty, DeleteEntryNotExist) { storage.DeleteEntry("foo"); }
|
||||
TEST_P(StorageTestEmpty, DeleteEntryNotExist) {
|
||||
storage.DeleteEntry("foo");
|
||||
}
|
||||
|
||||
TEST_P(StorageTestPopulated, DeleteEntryExist) {
|
||||
// client shouldn't send an update as id not assigned yet
|
||||
@@ -551,7 +555,9 @@ TEST_P(StorageTestPersistent, SavePersistentEmpty) {
|
||||
}
|
||||
|
||||
TEST_P(StorageTestPersistent, SavePersistent) {
|
||||
for (auto& i : entries()) i.getValue()->flags = NT_PERSISTENT;
|
||||
for (auto& i : entries()) {
|
||||
i.getValue()->flags = NT_PERSISTENT;
|
||||
}
|
||||
wpi::SmallString<256> buf;
|
||||
wpi::raw_svector_ostream oss(buf);
|
||||
storage.SavePersistent(oss, false);
|
||||
|
||||
@@ -34,7 +34,9 @@ void PrintTo(const Message& msg, std::ostream* os);
|
||||
|
||||
inline void PrintTo(std::shared_ptr<Message> msg, std::ostream* os) {
|
||||
*os << "shared_ptr{";
|
||||
if (msg) PrintTo(*msg, os);
|
||||
if (msg) {
|
||||
PrintTo(*msg, os);
|
||||
}
|
||||
*os << '}';
|
||||
}
|
||||
|
||||
@@ -42,7 +44,9 @@ void PrintTo(const Value& value, std::ostream* os);
|
||||
|
||||
inline void PrintTo(std::shared_ptr<Value> value, std::ostream* os) {
|
||||
*os << "shared_ptr{";
|
||||
if (value) PrintTo(*value, os);
|
||||
if (value) {
|
||||
PrintTo(*value, os);
|
||||
}
|
||||
*os << '}';
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,9 @@ class WireDecoderTest : public ::testing::Test {
|
||||
v_string_array = Value::MakeStringArray(std::move(sa));
|
||||
|
||||
sa.clear();
|
||||
for (int i = 0; i < 255; ++i) sa.push_back("h");
|
||||
for (int i = 0; i < 255; ++i) {
|
||||
sa.push_back("h");
|
||||
}
|
||||
v_string_array_big = Value::MakeStringArray(std::move(sa));
|
||||
|
||||
s_normal = std::string("hello");
|
||||
@@ -364,7 +366,9 @@ TEST_F(WireDecoderTest, ReadStringArrayValue2) {
|
||||
TEST_F(WireDecoderTest, ReadStringArrayBigValue2) {
|
||||
std::string s;
|
||||
s.push_back('\xff');
|
||||
for (int i = 0; i < 255; ++i) s.append("\x00\x01h", 3);
|
||||
for (int i = 0; i < 255; ++i) {
|
||||
s.append("\x00\x01h", 3);
|
||||
}
|
||||
wpi::raw_mem_istream is(s.data(), s.size());
|
||||
wpi::Logger logger;
|
||||
WireDecoder d(is, 0x0200u, logger);
|
||||
@@ -561,7 +565,9 @@ TEST_F(WireDecoderTest, ReadStringArrayValue3) {
|
||||
TEST_F(WireDecoderTest, ReadStringArrayBigValue3) {
|
||||
std::string s;
|
||||
s.push_back('\xff');
|
||||
for (int i = 0; i < 255; ++i) s.append("\x01h", 2);
|
||||
for (int i = 0; i < 255; ++i) {
|
||||
s.append("\x01h", 2);
|
||||
}
|
||||
wpi::raw_mem_istream is(s.data(), s.size());
|
||||
wpi::Logger logger;
|
||||
WireDecoder d(is, 0x0300u, logger);
|
||||
|
||||
@@ -35,7 +35,9 @@ class WireEncoderTest : public ::testing::Test {
|
||||
v_string_array = Value::MakeStringArray(std::move(sa));
|
||||
|
||||
sa.clear();
|
||||
for (int i = 0; i < 256; ++i) sa.push_back("h");
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
sa.push_back("h");
|
||||
}
|
||||
v_string_array_big = Value::MakeStringArray(std::move(sa));
|
||||
|
||||
s_normal = "hello";
|
||||
@@ -74,7 +76,9 @@ TEST_F(WireEncoderTest, SetProtoRev) {
|
||||
TEST_F(WireEncoderTest, Write8) {
|
||||
size_t off = BUFSIZE - 1;
|
||||
WireEncoder e(0x0300u);
|
||||
for (size_t i = 0; i < off; ++i) e.Write8(0u); // test across Reserve()
|
||||
for (size_t i = 0; i < off; ++i) {
|
||||
e.Write8(0u); // test across Reserve()
|
||||
}
|
||||
e.Write8(5u);
|
||||
e.Write8(0x101u); // should be truncated
|
||||
e.Write8(0u);
|
||||
@@ -86,7 +90,9 @@ TEST_F(WireEncoderTest, Write8) {
|
||||
TEST_F(WireEncoderTest, Write16) {
|
||||
size_t off = BUFSIZE - 2;
|
||||
WireEncoder e(0x0300u);
|
||||
for (size_t i = 0; i < off; ++i) e.Write8(0u); // test across Reserve()
|
||||
for (size_t i = 0; i < off; ++i) {
|
||||
e.Write8(0u); // test across Reserve()
|
||||
}
|
||||
e.Write16(5u);
|
||||
e.Write16(0x10001u); // should be truncated
|
||||
e.Write16(0x4567u);
|
||||
@@ -99,7 +105,9 @@ TEST_F(WireEncoderTest, Write16) {
|
||||
TEST_F(WireEncoderTest, Write32) {
|
||||
size_t off = BUFSIZE - 4;
|
||||
WireEncoder e(0x0300u);
|
||||
for (size_t i = 0; i < off; ++i) e.Write8(0u); // test across Reserve()
|
||||
for (size_t i = 0; i < off; ++i) {
|
||||
e.Write8(0u); // test across Reserve()
|
||||
}
|
||||
e.Write32(5ul);
|
||||
e.Write32(1ul);
|
||||
e.Write32(0xabcdul);
|
||||
@@ -115,7 +123,9 @@ TEST_F(WireEncoderTest, Write32) {
|
||||
TEST_F(WireEncoderTest, WriteDouble) {
|
||||
size_t off = BUFSIZE - 8;
|
||||
WireEncoder e(0x0300u);
|
||||
for (size_t i = 0; i < off; ++i) e.Write8(0u); // test across Reserve()
|
||||
for (size_t i = 0; i < off; ++i) {
|
||||
e.Write8(0u); // test across Reserve()
|
||||
}
|
||||
e.WriteDouble(0.0);
|
||||
e.WriteDouble(2.3e5);
|
||||
e.WriteDouble(std::numeric_limits<double>::infinity());
|
||||
@@ -136,7 +146,9 @@ TEST_F(WireEncoderTest, WriteDouble) {
|
||||
TEST_F(WireEncoderTest, WriteUleb128) {
|
||||
size_t off = BUFSIZE - 2;
|
||||
WireEncoder e(0x0300u);
|
||||
for (size_t i = 0; i < off; ++i) e.Write8(0u); // test across Reserve()
|
||||
for (size_t i = 0; i < off; ++i) {
|
||||
e.Write8(0u); // test across Reserve()
|
||||
}
|
||||
e.WriteUleb128(0ul);
|
||||
e.WriteUleb128(0x7ful);
|
||||
e.WriteUleb128(0x80ul);
|
||||
@@ -148,7 +160,9 @@ TEST_F(WireEncoderTest, WriteUleb128) {
|
||||
TEST_F(WireEncoderTest, WriteType) {
|
||||
size_t off = BUFSIZE - 1;
|
||||
WireEncoder e(0x0300u);
|
||||
for (size_t i = 0; i < off; ++i) e.Write8(0u); // test across Reserve()
|
||||
for (size_t i = 0; i < off; ++i) {
|
||||
e.Write8(0u); // test across Reserve()
|
||||
}
|
||||
e.WriteType(NT_BOOLEAN);
|
||||
e.WriteType(NT_DOUBLE);
|
||||
e.WriteType(NT_STRING);
|
||||
|
||||
Reference in New Issue
Block a user