diff options
author | Jordan Maples [MSFT] <49793787+JordanMaples@users.noreply.github.com> | 2019-12-04 01:32:25 +0300 |
---|---|---|
committer | Jordan Maples [MSFT] <49793787+JordanMaples@users.noreply.github.com> | 2019-12-04 01:32:25 +0300 |
commit | 2b10729386062479641951e822e4257066655863 (patch) | |
tree | 8a6888152a800ecee4d5be08ebaf08c6e31f8eff /tests/byte_tests.cpp | |
parent | 7e99e76c9761d0d0b0848b91f8648830670ee872 (diff) |
gtest migration
Diffstat (limited to 'tests/byte_tests.cpp')
-rw-r--r-- | tests/byte_tests.cpp | 83 |
1 files changed, 41 insertions, 42 deletions
diff --git a/tests/byte_tests.cpp b/tests/byte_tests.cpp index d6634bb..0a8a1f6 100644 --- a/tests/byte_tests.cpp +++ b/tests/byte_tests.cpp @@ -20,7 +20,7 @@ #pragma warning(disable : 26440 26426) // from catch #endif -#include <catch/catch.hpp> // for AssertionHandler, StringRef, CHECK, TEST_... +#include <gtest/gtest.h> #include <gsl/gsl_byte> // for to_byte, to_integer, byte, operator&, ope... @@ -29,104 +29,103 @@ using namespace gsl; namespace { -TEST_CASE("construction") +int modify_both(gsl::byte& b, int& i) +{ + i = 10; + b = to_byte<5>(); + return i; +} + +TEST(byte_tests, construction) { { const byte b = static_cast<byte>(4); - CHECK(static_cast<unsigned char>(b) == 4); + EXPECT_TRUE(static_cast<unsigned char>(b) == 4); } GSL_SUPPRESS(es.49) { const byte b = byte(12); - CHECK(static_cast<unsigned char>(b) == 12); + EXPECT_TRUE(static_cast<unsigned char>(b) == 12); } { const byte b = to_byte<12>(); - CHECK(static_cast<unsigned char>(b) == 12); + EXPECT_TRUE(static_cast<unsigned char>(b) == 12); } { const unsigned char uc = 12; const byte b = to_byte(uc); - CHECK(static_cast<unsigned char>(b) == 12); + EXPECT_TRUE(static_cast<unsigned char>(b) == 12); } #if defined(__cplusplus) && (__cplusplus >= 201703L) { const byte b { 14 }; - CHECK(static_cast<unsigned char>(b) == 14); + EXPECT_TRUE(static_cast<unsigned char>(b) == 14); } #endif } -TEST_CASE("bitwise_operations") +TEST(byte_tests, bitwise_operations) { const byte b = to_byte<0xFF>(); byte a = to_byte<0x00>(); - CHECK((b | a) == to_byte<0xFF>()); - CHECK(a == to_byte<0x00>()); + EXPECT_TRUE((b | a) == to_byte<0xFF>()); + EXPECT_TRUE(a == to_byte<0x00>()); a |= b; - CHECK(a == to_byte<0xFF>()); + EXPECT_TRUE(a == to_byte<0xFF>()); a = to_byte<0x01>(); - CHECK((b & a) == to_byte<0x01>()); + EXPECT_TRUE((b & a) == to_byte<0x01>()); a &= b; - CHECK(a == to_byte<0x01>()); + EXPECT_TRUE(a == to_byte<0x01>()); - CHECK((b ^ a) == to_byte<0xFE>()); + EXPECT_TRUE((b ^ a) == to_byte<0xFE>()); - CHECK(a == to_byte<0x01>()); + EXPECT_TRUE(a == to_byte<0x01>()); a ^= b; - CHECK(a == to_byte<0xFE>()); + EXPECT_TRUE(a == to_byte<0xFE>()); a = to_byte<0x01>(); - CHECK(~a == to_byte<0xFE>()); + EXPECT_TRUE(~a == to_byte<0xFE>()); a = to_byte<0xFF>(); - CHECK((a << 4) == to_byte<0xF0>()); - CHECK((a >> 4) == to_byte<0x0F>()); + EXPECT_TRUE((a << 4) == to_byte<0xF0>()); + EXPECT_TRUE((a >> 4) == to_byte<0x0F>()); a <<= 4; - CHECK(a == to_byte<0xF0>()); + EXPECT_TRUE(a == to_byte<0xF0>()); a >>= 4; - CHECK(a == to_byte<0x0F>()); + EXPECT_TRUE(a == to_byte<0x0F>()); } -TEST_CASE("to_integer") +TEST(byte_tests, to_integer) { const byte b = to_byte<0x12>(); - CHECK(0x12 == gsl::to_integer<char>(b)); - CHECK(0x12 == gsl::to_integer<short>(b)); - CHECK(0x12 == gsl::to_integer<long>(b)); - CHECK(0x12 == gsl::to_integer<long long>(b)); + EXPECT_TRUE(0x12 == gsl::to_integer<char>(b)); + EXPECT_TRUE(0x12 == gsl::to_integer<short>(b)); + EXPECT_TRUE(0x12 == gsl::to_integer<long>(b)); + EXPECT_TRUE(0x12 == gsl::to_integer<long long>(b)); - CHECK(0x12 == gsl::to_integer<unsigned char>(b)); - CHECK(0x12 == gsl::to_integer<unsigned short>(b)); - CHECK(0x12 == gsl::to_integer<unsigned long>(b)); - CHECK(0x12 == gsl::to_integer<unsigned long long>(b)); + EXPECT_TRUE(0x12 == gsl::to_integer<unsigned char>(b)); + EXPECT_TRUE(0x12 == gsl::to_integer<unsigned short>(b)); + EXPECT_TRUE(0x12 == gsl::to_integer<unsigned long>(b)); + EXPECT_TRUE(0x12 == gsl::to_integer<unsigned long long>(b)); - // CHECK(0x12 == gsl::to_integer<float>(b)); // expect compile-time error - // CHECK(0x12 == gsl::to_integer<double>(b)); // expect compile-time error -} - -int modify_both(gsl::byte & b, int& i) -{ - i = 10; - b = to_byte<5>(); - return i; + // EXPECT_TRUE(0x12 == gsl::to_integer<float>(b)); // expect compile-time error + // EXPECT_TRUE(0x12 == gsl::to_integer<double>(b)); // expect compile-time error } -GSL_SUPPRESS(type.1) -TEST_CASE("aliasing") +TEST(byte_tests, aliasing) { int i{0}; const int res = modify_both(reinterpret_cast<byte&>(i), i); - CHECK(res == i); + EXPECT_TRUE(res == i); } } |