From e046e6b2abf50f5a62fb108f5f023536dca1ad95 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Fri, 3 Aug 2018 15:56:01 +0200 Subject: [PATCH] Fix -Wsign-compare warnings in unittests --- .../unittests/EnumClassBitmasksTests.cpp | 14 +++--- src/tests/unittests/MathTests.cpp | 44 +++++++++---------- src/tests/unittests/SerialQueueTests.cpp | 6 +-- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/tests/unittests/EnumClassBitmasksTests.cpp b/src/tests/unittests/EnumClassBitmasksTests.cpp index ce3317a0a2..ad7f708a04 100644 --- a/src/tests/unittests/EnumClassBitmasksTests.cpp +++ b/src/tests/unittests/EnumClassBitmasksTests.cpp @@ -32,13 +32,13 @@ namespace dawn { TEST(BitmaskTests, BasicOperations) { Color test1 = Color::R | Color::G; - ASSERT_EQ(1 | 2, static_cast(test1)); + ASSERT_EQ(1u | 2u, static_cast(test1)); Color test2 = test1 ^ (Color::R | Color::A); - ASSERT_EQ(2 | 8, static_cast(test2)); + ASSERT_EQ(2u | 8u, static_cast(test2)); Color test3 = test2 & Color::A; - ASSERT_EQ(8, static_cast(test3)); + ASSERT_EQ(8u, static_cast(test3)); Color test4 = ~test3; ASSERT_EQ(~uint32_t(8), static_cast(test4)); @@ -47,15 +47,15 @@ namespace dawn { TEST(BitmaskTests, AssignOperations) { Color test1 = Color::R; test1 |= Color::G; - ASSERT_EQ(1 | 2, static_cast(test1)); + ASSERT_EQ(1u | 2u, static_cast(test1)); Color test2 = test1; test2 ^= (Color::R | Color::A); - ASSERT_EQ(2 | 8, static_cast(test2)); + ASSERT_EQ(2u | 8u, static_cast(test2)); Color test3 = test2; test3 &= Color::A; - ASSERT_EQ(8, static_cast(test3)); + ASSERT_EQ(8u, static_cast(test3)); } TEST(BitmaskTests, BoolConversion) { @@ -75,7 +75,7 @@ namespace dawn { TEST(BitmaskTests, ThreeOrs) { Color c = Color::R | Color::G | Color::B; - ASSERT_EQ(7, static_cast(c)); + ASSERT_EQ(7u, static_cast(c)); } TEST(BitmaskTests, ZeroOrOneBits) { diff --git a/src/tests/unittests/MathTests.cpp b/src/tests/unittests/MathTests.cpp index 929452dccd..4caf9e7d0a 100644 --- a/src/tests/unittests/MathTests.cpp +++ b/src/tests/unittests/MathTests.cpp @@ -19,27 +19,27 @@ // Tests for ScanForward TEST(Math, ScanForward) { // Test extrema - ASSERT_EQ(ScanForward(1), 0); - ASSERT_EQ(ScanForward(0x80000000), 31); + ASSERT_EQ(ScanForward(1), 0u); + ASSERT_EQ(ScanForward(0x80000000), 31u); // Test with more than one bit set. - ASSERT_EQ(ScanForward(256), 8); - ASSERT_EQ(ScanForward(256 + 32), 5); - ASSERT_EQ(ScanForward(1024 + 256 + 32), 5); + ASSERT_EQ(ScanForward(256), 8u); + ASSERT_EQ(ScanForward(256 + 32), 5u); + ASSERT_EQ(ScanForward(1024 + 256 + 32), 5u); } // Tests for Log2 TEST(Math, Log2) { // Test extrema - ASSERT_EQ(Log2(1), 0); - ASSERT_EQ(Log2(0xFFFFFFFF), 31); + ASSERT_EQ(Log2(1), 0u); + ASSERT_EQ(Log2(0xFFFFFFFF), 31u); // Test boundary between two logs - ASSERT_EQ(Log2(0x80000000), 31); - ASSERT_EQ(Log2(0x7FFFFFFF), 30); + ASSERT_EQ(Log2(0x80000000), 31u); + ASSERT_EQ(Log2(0x7FFFFFFF), 30u); - ASSERT_EQ(Log2(16), 4); - ASSERT_EQ(Log2(15), 3); + ASSERT_EQ(Log2(16), 4u); + ASSERT_EQ(Log2(15), 3u); } // Tests for IsPowerOfTwo @@ -64,24 +64,24 @@ TEST(Math, AlignPtr) { ASSERT_GE(aligned - unaligned, 0); ASSERT_LT(static_cast(aligned - unaligned), kTestAlignment); - ASSERT_EQ(reinterpret_cast(aligned) & (kTestAlignment -1), 0); + ASSERT_EQ(reinterpret_cast(aligned) & (kTestAlignment -1), 0u); } } // Tests for Align TEST(Math, Align) { // 0 aligns to 0 - ASSERT_EQ(Align(0, 4), 0); - ASSERT_EQ(Align(0, 256), 0); - ASSERT_EQ(Align(0, 512), 0); + ASSERT_EQ(Align(0, 4), 0u); + ASSERT_EQ(Align(0, 256), 0u); + ASSERT_EQ(Align(0, 512), 0u); // Multiples align to self - ASSERT_EQ(Align(8, 8), 8); - ASSERT_EQ(Align(16, 8), 16); - ASSERT_EQ(Align(24, 8), 24); - ASSERT_EQ(Align(256, 256), 256); - ASSERT_EQ(Align(512, 256), 512); - ASSERT_EQ(Align(768, 256), 768); + ASSERT_EQ(Align(8, 8), 8u); + ASSERT_EQ(Align(16, 8), 16u); + ASSERT_EQ(Align(24, 8), 24u); + ASSERT_EQ(Align(256, 256), 256u); + ASSERT_EQ(Align(512, 256), 512u); + ASSERT_EQ(Align(768, 256), 768u); // Alignment with 1 is self 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 for (uint32_t i = 1; i <= 64; ++i) { - ASSERT_EQ(Align(64 + i, 64), 128); + ASSERT_EQ(Align(64 + i, 64), 128u); } } diff --git a/src/tests/unittests/SerialQueueTests.cpp b/src/tests/unittests/SerialQueueTests.cpp index 2c45c2f65a..712c093aed 100644 --- a/src/tests/unittests/SerialQueueTests.cpp +++ b/src/tests/unittests/SerialQueueTests.cpp @@ -132,12 +132,12 @@ TEST(SerialQueue, FirstSerial) { queue.Enqueue(std::move(vector2), 1); queue.Enqueue(vector3, 2); - EXPECT_EQ(queue.FirstSerial(), 0); + EXPECT_EQ(queue.FirstSerial(), 0u); queue.ClearUpTo(1); - EXPECT_EQ(queue.FirstSerial(), 2); + EXPECT_EQ(queue.FirstSerial(), 2u); queue.Clear(); queue.Enqueue(vector1, 6); - EXPECT_EQ(queue.FirstSerial(), 6); + EXPECT_EQ(queue.FirstSerial(), 6u); }