1
0
Fork 0

Require semi-colon at end of function-like macros (#4719)

This commit is contained in:
peterbell10 2020-05-05 21:39:59 +01:00 committed by GitHub
parent f4b5c4c341
commit 8e2dfce84b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 100 additions and 79 deletions

View File

@ -38,21 +38,21 @@
#define HANDLE_CLIENT_PACKET_READ(Proc, Type, Var) \ #define HANDLE_CLIENT_PACKET_READ(Proc, Type, Var) \
Type Var; \ Type Var; \
{ \ do { \
if (!m_ClientBuffer.Proc(Var)) \ if (!m_ClientBuffer.Proc(Var)) \
{ \ { \
return false; \ return false; \
} \ } \
} } while(false)
#define HANDLE_SERVER_PACKET_READ(Proc, Type, Var) \ #define HANDLE_SERVER_PACKET_READ(Proc, Type, Var) \
Type Var; \ Type Var; \
{ \ do { \
if (!m_ServerBuffer.Proc(Var)) \ if (!m_ServerBuffer.Proc(Var)) \
{ \ { \
return false; \ return false; \
} \ } \
} } while(false)
#define CLIENTSEND(...) SendData(m_ClientSocket, __VA_ARGS__, "Client") #define CLIENTSEND(...) SendData(m_ClientSocket, __VA_ARGS__, "Client")
#define SERVERSEND(...) SendData(m_ServerSocket, __VA_ARGS__, "Server") #define SERVERSEND(...) SendData(m_ServerSocket, __VA_ARGS__, "Server")
@ -60,7 +60,7 @@
#define SERVERENCRYPTSEND(...) SendEncryptedData(m_ServerSocket, m_ServerEncryptor, __VA_ARGS__, "Server") #define SERVERENCRYPTSEND(...) SendEncryptedData(m_ServerSocket, m_ServerEncryptor, __VA_ARGS__, "Server")
#define COPY_TO_SERVER() \ #define COPY_TO_SERVER() \
{ \ do { \
AString ToServer; \ AString ToServer; \
m_ClientBuffer.ReadAgain(ToServer); \ m_ClientBuffer.ReadAgain(ToServer); \
switch (m_ServerState) \ switch (m_ServerState) \
@ -84,10 +84,10 @@
} \ } \
} \ } \
DebugSleep(50); \ DebugSleep(50); \
} } while (false)
#define COPY_TO_CLIENT() \ #define COPY_TO_CLIENT() \
{ \ do { \
AString ToClient; \ AString ToClient; \
m_ServerBuffer.ReadAgain(ToClient); \ m_ServerBuffer.ReadAgain(ToClient); \
switch (m_ClientState) \ switch (m_ClientState) \
@ -110,10 +110,10 @@
\ \
} \ } \
DebugSleep(50); \ DebugSleep(50); \
} } while (false)
#define HANDLE_CLIENT_READ(Proc) \ #define HANDLE_CLIENT_READ(Proc) \
{ \ do { \
if (!Proc) \ if (!Proc) \
{ \ { \
AString Leftover; \ AString Leftover; \
@ -122,16 +122,16 @@
m_ClientBuffer.ResetRead(); \ m_ClientBuffer.ResetRead(); \
return true; \ return true; \
} \ } \
} } while (false)
#define HANDLE_SERVER_READ(Proc) \ #define HANDLE_SERVER_READ(Proc) \
{ \ do { \
if (!Proc) \ if (!Proc) \
{ \ { \
m_ServerBuffer.ResetRead(); \ m_ServerBuffer.ResetRead(); \
return true; \ return true; \
} \ } \
} } while (false)
@ -1777,7 +1777,7 @@ bool cConnection::HandleServerKeepAlive(void)
HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, PingID); HANDLE_SERVER_PACKET_READ(ReadBEUInt32, UInt32, PingID);
Log("Received a PACKET_KEEP_ALIVE from the server:"); Log("Received a PACKET_KEEP_ALIVE from the server:");
Log(" ID = %u", PingID); Log(" ID = %u", PingID);
COPY_TO_CLIENT() COPY_TO_CLIENT();
return true; return true;
} }
@ -1875,7 +1875,7 @@ bool cConnection::HandleServerMapChunk(void)
// TODO: Save the compressed data into a file for later analysis // TODO: Save the compressed data into a file for later analysis
COPY_TO_CLIENT() COPY_TO_CLIENT();
return true; return true;
} }
@ -2238,9 +2238,9 @@ bool cConnection::HandleServerSpawnNamedEntity(void)
sSpawnDatas Data; sSpawnDatas Data;
for (UInt32 i = 0; i < DataCount; i++) for (UInt32 i = 0; i < DataCount; i++)
{ {
HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, Name) HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, Name);
HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, Value) HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, Value);
HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, Signature) HANDLE_SERVER_PACKET_READ(ReadVarUTF8String, AString, Signature);
Data.push_back(sSpawnData(Name, Value, Signature)); Data.push_back(sSpawnData(Name, Value, Signature));
} }
HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosX); HANDLE_SERVER_PACKET_READ(ReadBEInt32, Int32, PosX);

View File

@ -186,7 +186,7 @@ static void testGenerateNether(cChunkGenerator & aDefaultNetherGen)
} }
TEST_EQUAL_MSG(y, prevHeight, Printf("Failed: Same height across the entire chunk, at {%d, %d}: exp %d, got %d; top block: %d", TEST_EQUAL_MSG(y, prevHeight, Printf("Failed: Same height across the entire chunk, at {%d, %d}: exp %d, got %d; top block: %d",
x, z, prevHeight, y, chd.GetBlockType(x, y, z) x, z, prevHeight, y, chd.GetBlockType(x, y, z)
)) ));
auto blockType = chd.GetBlockType(x, y, z); auto blockType = chd.GetBlockType(x, y, z);
TEST_EQUAL_MSG(blockType, E_BLOCK_BEDROCK, TEST_EQUAL_MSG(blockType, E_BLOCK_BEDROCK,
Printf("Bedrock ceiling at {%d, %d, %d}: %d", x, y, z, blockType) Printf("Bedrock ceiling at {%d, %d, %d}: %d", x, y, z, blockType)

View File

@ -53,11 +53,14 @@ public:
#define EXPECT(X) if (!(X)) \ #define EXPECT(X) \
{ \ do { \
ASSERT(X); \ if (!(X)) \
throw cTestFailure(#X, __FILE__, __LINE__); \ { \
} ASSERT(X); \
throw cTestFailure(#X, __FILE__, __LINE__); \
} \
} while (false)

View File

@ -45,12 +45,14 @@ public:
/** Checks that the two values are equal; if not, throws a TestException. */ /** Checks that the two values are equal; if not, throws a TestException. */
#define TEST_EQUAL(VAL1, VAL2) \ #define TEST_EQUAL(VAL1, VAL2) \
if (VAL1 != VAL2) \ do { \
{ \ if (VAL1 != VAL2) \
throw TestException(__FILE__, __LINE__, __FUNCTION__, Printf("Equality test failed: %s != %s", \ { \
#VAL1, #VAL2 \ throw TestException( \
)); \ __FILE__, __LINE__, __FUNCTION__, \
} Printf("Equality test failed: %s != %s", #VAL1, #VAL2)); \
} \
} while (false)
@ -58,12 +60,14 @@ public:
/** Checks that the two values are equal; if not, throws a TestException, includes the specified message. */ /** Checks that the two values are equal; if not, throws a TestException, includes the specified message. */
#define TEST_EQUAL_MSG(VAL1, VAL2, MSG) \ #define TEST_EQUAL_MSG(VAL1, VAL2, MSG) \
if (VAL1 != VAL2) \ do { \
{ \ if (VAL1 != VAL2) \
throw TestException(__FILE__, __LINE__, __FUNCTION__, Printf("Equality test failed: %s != %s (%s)", \ { \
#VAL1, #VAL2, MSG \ throw TestException( \
)); \ __FILE__, __LINE__, __FUNCTION__, \
} Printf("Equality test failed: %s != %s (%s)", #VAL1, #VAL2, MSG)); \
} \
} while (false)
@ -71,12 +75,15 @@ public:
/** Checks that the two values are not equal; if they are, throws a TestException. */ /** Checks that the two values are not equal; if they are, throws a TestException. */
#define TEST_NOTEQUAL(VAL1, VAL2) \ #define TEST_NOTEQUAL(VAL1, VAL2) \
if (VAL1 == VAL2) \ do { \
{ \ if (VAL1 == VAL2) \
throw TestException(__FILE__, __LINE__, __FUNCTION__, Printf("Inequality test failed: %s == %s", \ { \
#VAL1, #VAL2 \ throw TestException( \
)); \ __FILE__, __LINE__, __FUNCTION__, \
} Printf("Inequality test failed: %s == %s", #VAL1, #VAL2) \
); \
} \
} while(false)
@ -124,29 +131,36 @@ public:
/** Checks that the statement throws an exception of the specified class. */ /** Checks that the statement throws an exception of the specified class. */
#define TEST_THROWS(Stmt, ExcClass) \ #define TEST_THROWS(Stmt, ExcClass) \
try \ do { \
{ \ try \
Stmt; \ { \
throw TestException(__FILE__, __LINE__, __FUNCTION__, Printf("Failed to throw an exception of type %s", \ Stmt; \
#ExcClass \ throw TestException( \
)); \ __FILE__, __LINE__, __FUNCTION__, \
} \ Printf("Failed to throw an exception of type %s", #ExcClass) \
catch (const ExcClass &) \ ); \
{ \ } \
/* This is the expected case. */ \ catch (const ExcClass &) \
} \ { \
catch (const std::exception & exc) \ /* This is the expected case. */ \
{ \ } \
throw TestException(__FILE__, __LINE__, __FUNCTION__, Printf("An unexpected std::exception descendant was thrown, was expecting type %s. Message is: %s", \ catch (const std::exception & exc) \
#ExcClass, exc.what() \ { \
)); \ throw TestException( \
} \ __FILE__, __LINE__, __FUNCTION__, \
catch (...) \ Printf("An unexpected std::exception descendant was thrown, was expecting type %s. Message is: %s", \
{ \ #ExcClass, exc.what() \
throw TestException(__FILE__, __LINE__, __FUNCTION__, Printf("An unexpected unknown exception object was thrown, was expecting type %s", \ )); \
#ExcClass \ } \
)); \ catch (...)\
} { \
throw TestException( \
__FILE__, __LINE__, __FUNCTION__, \
Printf("An unexpected unknown exception object was thrown, was expecting type %s", \
#ExcClass \
)); \
} \
} while (false)
@ -154,19 +168,23 @@ public:
/** Checks that the statement throws an exception of any type. */ /** Checks that the statement throws an exception of any type. */
#define TEST_THROWS_ANY(Stmt) \ #define TEST_THROWS_ANY(Stmt) \
try \ do { \
{ \ try \
Stmt; \ { \
throw TestException(__FILE__, __LINE__, __FUNCTION__, "Failed to throw an exception of any type"); \ Stmt; \
} \ throw TestException( \
catch (const TestException & exc) \ __FILE__, __LINE__, __FUNCTION__, \
{ \ "Failed to throw an exception of any type"); \
throw exc; \ } \
} \ catch (const TestException & exc) \
catch (...) \ { \
{ \ throw exc; \
/* This is the expected case */ \ } \
} catch (...)\
{ \
/* This is the expected case */ \
} \
} while (false)
@ -174,7 +192,7 @@ public:
/** Fails the test unconditionally, with the specified message. */ /** Fails the test unconditionally, with the specified message. */
#define TEST_FAIL(MSG) \ #define TEST_FAIL(MSG) \
throw TestException(__FILE__, __LINE__, __FUNCTION__, MSG); throw TestException(__FILE__, __LINE__, __FUNCTION__, MSG)
@ -184,7 +202,7 @@ public:
#ifdef _DEBUG #ifdef _DEBUG
#define TEST_ASSERTS(Stmt) TEST_THROWS(Stmt, cAssertFailure) #define TEST_ASSERTS(Stmt) TEST_THROWS(Stmt, cAssertFailure)
#else #else
#define TEST_ASSERTS(Stmt) LOG("Skipped, cannot test in Release mode: TEST_ASSERT(%s); (%s:%d)", #Stmt, __FILE__, __LINE__); #define TEST_ASSERTS(Stmt) LOG("Skipped, cannot test in Release mode: TEST_ASSERT(%s); (%s:%d)", #Stmt, __FILE__, __LINE__)
#endif // else _DEBUG #endif // else _DEBUG