mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Fix modernize-loop-convert in tests
This commit is contained in:
parent
ad0ca6090a
commit
99d1fb726c
|
@ -5,27 +5,24 @@
|
|||
#include <base/system.h>
|
||||
|
||||
static const int INT_DATA[] = {0, 1, -1, 32, 64, 256, -512, 12345, -123456, 1234567, 12345678, 123456789, 2147483647, (-2147483647 - 1)};
|
||||
static const int INT_NUM = std::size(INT_DATA);
|
||||
|
||||
static const unsigned UINT_DATA[] = {0u, 1u, 2u, 32u, 64u, 256u, 512u, 12345u, 123456u, 1234567u, 12345678u, 123456789u, 2147483647u, 2147483648u, 4294967295u};
|
||||
static const int UINT_NUM = std::size(INT_DATA);
|
||||
|
||||
TEST(BytePacking, RoundtripInt)
|
||||
{
|
||||
for(int i = 0; i < INT_NUM; i++)
|
||||
for(auto i : INT_DATA)
|
||||
{
|
||||
unsigned char aPacked[4];
|
||||
int_to_bytes_be(aPacked, INT_DATA[i]);
|
||||
EXPECT_EQ(bytes_be_to_int(aPacked), INT_DATA[i]);
|
||||
int_to_bytes_be(aPacked, i);
|
||||
EXPECT_EQ(bytes_be_to_int(aPacked), i);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(BytePacking, RoundtripUnsigned)
|
||||
{
|
||||
for(int i = 0; i < UINT_NUM; i++)
|
||||
for(auto u : UINT_DATA)
|
||||
{
|
||||
unsigned char aPacked[4];
|
||||
uint_to_bytes_be(aPacked, UINT_DATA[i]);
|
||||
EXPECT_EQ(bytes_be_to_uint(aPacked), UINT_DATA[i]);
|
||||
uint_to_bytes_be(aPacked, u);
|
||||
EXPECT_EQ(bytes_be_to_uint(aPacked), u);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@ TEST(CVariableInt, RoundtripPackUnpack)
|
|||
TEST(CVariableInt, UnpackInvalid)
|
||||
{
|
||||
unsigned char aPacked[CVariableInt::MAX_BYTES_PACKED];
|
||||
for(unsigned i = 0; i < sizeof(aPacked); i++)
|
||||
aPacked[i] = 0xFF;
|
||||
for(auto &Byte : aPacked)
|
||||
Byte = 0xFF;
|
||||
|
||||
int Result;
|
||||
EXPECT_EQ(int(CVariableInt::Unpack(aPacked, &Result, sizeof(aPacked)) - aPacked), int(CVariableInt::MAX_BYTES_PACKED));
|
||||
|
@ -43,8 +43,8 @@ TEST(CVariableInt, PackBufferTooSmall)
|
|||
TEST(CVariableInt, UnpackBufferTooSmall)
|
||||
{
|
||||
unsigned char aPacked[CVariableInt::MAX_BYTES_PACKED / 2];
|
||||
for(unsigned i = 0; i < sizeof(aPacked); i++)
|
||||
aPacked[i] = 0xFF; // extended bits are set, but buffer ends too early
|
||||
for(auto &Byte : aPacked)
|
||||
Byte = 0xFF; // extended bits are set, but buffer ends too early
|
||||
|
||||
int UnusedResult;
|
||||
EXPECT_EQ(CVariableInt::Unpack(aPacked, &UnusedResult, sizeof(aPacked)), (const unsigned char *)0x0);
|
||||
|
@ -55,8 +55,8 @@ TEST(CVariableInt, RoundtripCompressDecompress)
|
|||
unsigned char aCompressed[NUM * CVariableInt::MAX_BYTES_PACKED];
|
||||
int aDecompressed[NUM];
|
||||
long ExpectedCompressedSize = 0;
|
||||
for(int i = 0; i < NUM; i++)
|
||||
ExpectedCompressedSize += SIZES[i];
|
||||
for(auto Size : SIZES)
|
||||
ExpectedCompressedSize += Size;
|
||||
|
||||
long CompressedSize = CVariableInt::Compress(DATA, sizeof(DATA), aCompressed, sizeof(aCompressed));
|
||||
ASSERT_EQ(CompressedSize, ExpectedCompressedSize);
|
||||
|
|
|
@ -56,9 +56,9 @@ TEST(Prng, EqualsPcg32GlobalDemo)
|
|||
|
||||
CPrng Prng;
|
||||
Prng.Seed(aSeed);
|
||||
for(unsigned i = 0; i < std::size(PCG32_GLOBAL_DEMO); i++)
|
||||
for(auto Expected : PCG32_GLOBAL_DEMO)
|
||||
{
|
||||
EXPECT_EQ(Prng.RandomBits(), PCG32_GLOBAL_DEMO[i]);
|
||||
EXPECT_EQ(Prng.RandomBits(), Expected);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -183,9 +183,9 @@ TEST_P(SingleScore, LoadPlayerData)
|
|||
|
||||
EXPECT_EQ(m_pPlayerResult->m_MessageKind, CScorePlayerResult::PLAYER_INFO);
|
||||
ASSERT_EQ(m_pPlayerResult->m_Data.m_Info.m_Time, 0.0);
|
||||
for(int i = 0; i < NUM_CHECKPOINTS; i++)
|
||||
for(auto &Time : m_pPlayerResult->m_Data.m_Info.m_aTimeCp)
|
||||
{
|
||||
ASSERT_EQ(m_pPlayerResult->m_Data.m_Info.m_aTimeCp[i], 0);
|
||||
ASSERT_EQ(Time, 0);
|
||||
}
|
||||
|
||||
str_copy(m_PlayerRequest.m_aRequestingPlayer, "nameless tee", sizeof(m_PlayerRequest.m_aRequestingPlayer));
|
||||
|
|
|
@ -22,9 +22,8 @@ TEST(SecureRandom, Below1)
|
|||
TEST(SecureRandom, Below)
|
||||
{
|
||||
int BOUNDS[] = {2, 3, 4, 5, 10, 100, 127, 128, 129};
|
||||
for(unsigned i = 0; i < std::size(BOUNDS); i++)
|
||||
for(auto Below : BOUNDS)
|
||||
{
|
||||
int Below = BOUNDS[i];
|
||||
for(int j = 0; j < 10; j++)
|
||||
{
|
||||
int Random = secure_rand_below(Below);
|
||||
|
|
Loading…
Reference in a new issue