Fix -Wsign-compare warnings in unittests

This commit is contained in:
Corentin Wallez 2018-08-03 15:56:01 +02:00 committed by Corentin Wallez
parent 5aea8d15be
commit e046e6b2ab
3 changed files with 32 additions and 32 deletions

View File

@ -32,13 +32,13 @@ namespace dawn {
TEST(BitmaskTests, BasicOperations) { TEST(BitmaskTests, BasicOperations) {
Color test1 = Color::R | Color::G; Color test1 = Color::R | Color::G;
ASSERT_EQ(1 | 2, static_cast<uint32_t>(test1)); ASSERT_EQ(1u | 2u, static_cast<uint32_t>(test1));
Color test2 = test1 ^ (Color::R | Color::A); Color test2 = test1 ^ (Color::R | Color::A);
ASSERT_EQ(2 | 8, static_cast<uint32_t>(test2)); ASSERT_EQ(2u | 8u, static_cast<uint32_t>(test2));
Color test3 = test2 & Color::A; Color test3 = test2 & Color::A;
ASSERT_EQ(8, static_cast<uint32_t>(test3)); ASSERT_EQ(8u, static_cast<uint32_t>(test3));
Color test4 = ~test3; Color test4 = ~test3;
ASSERT_EQ(~uint32_t(8), static_cast<uint32_t>(test4)); ASSERT_EQ(~uint32_t(8), static_cast<uint32_t>(test4));
@ -47,15 +47,15 @@ namespace dawn {
TEST(BitmaskTests, AssignOperations) { TEST(BitmaskTests, AssignOperations) {
Color test1 = Color::R; Color test1 = Color::R;
test1 |= Color::G; test1 |= Color::G;
ASSERT_EQ(1 | 2, static_cast<uint32_t>(test1)); ASSERT_EQ(1u | 2u, static_cast<uint32_t>(test1));
Color test2 = test1; Color test2 = test1;
test2 ^= (Color::R | Color::A); test2 ^= (Color::R | Color::A);
ASSERT_EQ(2 | 8, static_cast<uint32_t>(test2)); ASSERT_EQ(2u | 8u, static_cast<uint32_t>(test2));
Color test3 = test2; Color test3 = test2;
test3 &= Color::A; test3 &= Color::A;
ASSERT_EQ(8, static_cast<uint32_t>(test3)); ASSERT_EQ(8u, static_cast<uint32_t>(test3));
} }
TEST(BitmaskTests, BoolConversion) { TEST(BitmaskTests, BoolConversion) {
@ -75,7 +75,7 @@ namespace dawn {
TEST(BitmaskTests, ThreeOrs) { TEST(BitmaskTests, ThreeOrs) {
Color c = Color::R | Color::G | Color::B; Color c = Color::R | Color::G | Color::B;
ASSERT_EQ(7, static_cast<uint32_t>(c)); ASSERT_EQ(7u, static_cast<uint32_t>(c));
} }
TEST(BitmaskTests, ZeroOrOneBits) { TEST(BitmaskTests, ZeroOrOneBits) {

View File

@ -19,27 +19,27 @@
// Tests for ScanForward // Tests for ScanForward
TEST(Math, ScanForward) { TEST(Math, ScanForward) {
// Test extrema // Test extrema
ASSERT_EQ(ScanForward(1), 0); ASSERT_EQ(ScanForward(1), 0u);
ASSERT_EQ(ScanForward(0x80000000), 31); ASSERT_EQ(ScanForward(0x80000000), 31u);
// Test with more than one bit set. // Test with more than one bit set.
ASSERT_EQ(ScanForward(256), 8); ASSERT_EQ(ScanForward(256), 8u);
ASSERT_EQ(ScanForward(256 + 32), 5); ASSERT_EQ(ScanForward(256 + 32), 5u);
ASSERT_EQ(ScanForward(1024 + 256 + 32), 5); ASSERT_EQ(ScanForward(1024 + 256 + 32), 5u);
} }
// Tests for Log2 // Tests for Log2
TEST(Math, Log2) { TEST(Math, Log2) {
// Test extrema // Test extrema
ASSERT_EQ(Log2(1), 0); ASSERT_EQ(Log2(1), 0u);
ASSERT_EQ(Log2(0xFFFFFFFF), 31); ASSERT_EQ(Log2(0xFFFFFFFF), 31u);
// Test boundary between two logs // Test boundary between two logs
ASSERT_EQ(Log2(0x80000000), 31); ASSERT_EQ(Log2(0x80000000), 31u);
ASSERT_EQ(Log2(0x7FFFFFFF), 30); ASSERT_EQ(Log2(0x7FFFFFFF), 30u);
ASSERT_EQ(Log2(16), 4); ASSERT_EQ(Log2(16), 4u);
ASSERT_EQ(Log2(15), 3); ASSERT_EQ(Log2(15), 3u);
} }
// Tests for IsPowerOfTwo // Tests for IsPowerOfTwo
@ -64,24 +64,24 @@ TEST(Math, AlignPtr) {
ASSERT_GE(aligned - unaligned, 0); ASSERT_GE(aligned - unaligned, 0);
ASSERT_LT(static_cast<size_t>(aligned - unaligned), kTestAlignment); ASSERT_LT(static_cast<size_t>(aligned - unaligned), kTestAlignment);
ASSERT_EQ(reinterpret_cast<uintptr_t>(aligned) & (kTestAlignment -1), 0); ASSERT_EQ(reinterpret_cast<uintptr_t>(aligned) & (kTestAlignment -1), 0u);
} }
} }
// Tests for Align // Tests for Align
TEST(Math, Align) { TEST(Math, Align) {
// 0 aligns to 0 // 0 aligns to 0
ASSERT_EQ(Align(0, 4), 0); ASSERT_EQ(Align(0, 4), 0u);
ASSERT_EQ(Align(0, 256), 0); ASSERT_EQ(Align(0, 256), 0u);
ASSERT_EQ(Align(0, 512), 0); ASSERT_EQ(Align(0, 512), 0u);
// Multiples align to self // Multiples align to self
ASSERT_EQ(Align(8, 8), 8); ASSERT_EQ(Align(8, 8), 8u);
ASSERT_EQ(Align(16, 8), 16); ASSERT_EQ(Align(16, 8), 16u);
ASSERT_EQ(Align(24, 8), 24); ASSERT_EQ(Align(24, 8), 24u);
ASSERT_EQ(Align(256, 256), 256); ASSERT_EQ(Align(256, 256), 256u);
ASSERT_EQ(Align(512, 256), 512); ASSERT_EQ(Align(512, 256), 512u);
ASSERT_EQ(Align(768, 256), 768); ASSERT_EQ(Align(768, 256), 768u);
// Alignment with 1 is self // Alignment with 1 is self
for (uint32_t i = 0; i < 128; ++i) { for (uint32_t i = 0; i < 128; ++i) {
@ -90,7 +90,7 @@ TEST(Math, Align) {
// Everything in the range (align, 2*align] aligns to 2*align // Everything in the range (align, 2*align] aligns to 2*align
for (uint32_t i = 1; i <= 64; ++i) { for (uint32_t i = 1; i <= 64; ++i) {
ASSERT_EQ(Align(64 + i, 64), 128); ASSERT_EQ(Align(64 + i, 64), 128u);
} }
} }

View File

@ -132,12 +132,12 @@ TEST(SerialQueue, FirstSerial) {
queue.Enqueue(std::move(vector2), 1); queue.Enqueue(std::move(vector2), 1);
queue.Enqueue(vector3, 2); queue.Enqueue(vector3, 2);
EXPECT_EQ(queue.FirstSerial(), 0); EXPECT_EQ(queue.FirstSerial(), 0u);
queue.ClearUpTo(1); queue.ClearUpTo(1);
EXPECT_EQ(queue.FirstSerial(), 2); EXPECT_EQ(queue.FirstSerial(), 2u);
queue.Clear(); queue.Clear();
queue.Enqueue(vector1, 6); queue.Enqueue(vector1, 6);
EXPECT_EQ(queue.FirstSerial(), 6); EXPECT_EQ(queue.FirstSerial(), 6u);
} }