aboutsummaryrefslogtreecommitdiffstats
path: root/tests/byte_tests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/byte_tests.cpp')
-rw-r--r--tests/byte_tests.cpp158
1 files changed, 77 insertions, 81 deletions
diff --git a/tests/byte_tests.cpp b/tests/byte_tests.cpp
index 8cb0da8..2c6259d 100644
--- a/tests/byte_tests.cpp
+++ b/tests/byte_tests.cpp
@@ -14,7 +14,8 @@
//
///////////////////////////////////////////////////////////////////////////////
-#include <UnitTest++/UnitTest++.h>
+#include <catch/catch.hpp>
+
#include <gsl/gsl_byte>
#include <iostream>
@@ -30,106 +31,101 @@ using namespace gsl;
namespace
{
-SUITE(byte_tests)
+TEST_CASE("construction")
{
- TEST(construction)
{
- {
- byte b = static_cast<byte>(4);
- CHECK(static_cast<unsigned char>(b) == 4);
- }
-
- {
- byte b = byte(12);
- CHECK(static_cast<unsigned char>(b) == 12);
- }
-
- {
- byte b = to_byte<12>();
- CHECK(static_cast<unsigned char>(b) == 12);
- }
- {
- unsigned char uc = 12;
- byte b = to_byte(uc);
- CHECK(static_cast<unsigned char>(b) == 12);
- }
-
- // waiting for C++17 enum class direct initializer support
- //{
- // byte b { 14 };
- // CHECK(static_cast<unsigned char>(b) == 14);
- //}
+ const byte b = static_cast<byte>(4);
+ CHECK(static_cast<unsigned char>(b) == 4);
}
- TEST(bitwise_operations)
{
- byte b = to_byte<0xFF>();
+ const byte b = byte(12);
+ CHECK(static_cast<unsigned char>(b) == 12);
+ }
- byte a = to_byte<0x00>();
- CHECK((b | a) == to_byte<0xFF>());
- CHECK(a == to_byte<0x00>());
+ {
+ const byte b = to_byte<12>();
+ CHECK(static_cast<unsigned char>(b) == 12);
+ }
+ {
+ const unsigned char uc = 12;
+ const byte b = to_byte(uc);
+ CHECK(static_cast<unsigned char>(b) == 12);
+ }
- a |= b;
- CHECK(a == to_byte<0xFF>());
+ // waiting for C++17 enum class direct initializer support
+ //{
+ // byte b { 14 };
+ // CHECK(static_cast<unsigned char>(b) == 14);
+ //}
+}
- a = to_byte<0x01>();
- CHECK((b & a) == to_byte<0x01>());
+TEST_CASE("bitwise_operations")
+{
+ const byte b = to_byte<0xFF>();
- a &= b;
- CHECK(a == to_byte<0x01>());
+ byte a = to_byte<0x00>();
+ CHECK((b | a) == to_byte<0xFF>());
+ CHECK(a == to_byte<0x00>());
- CHECK((b ^ a) == to_byte<0xFE>());
-
- CHECK(a == to_byte<0x01>());
- a ^= b;
- CHECK(a == to_byte<0xFE>());
+ a |= b;
+ CHECK(a == to_byte<0xFF>());
- a = to_byte<0x01>();
- CHECK(~a == to_byte<0xFE>());
+ a = to_byte<0x01>();
+ CHECK((b & a) == to_byte<0x01>());
- a = to_byte<0xFF>();
- CHECK((a << 4) == to_byte<0xF0>());
- CHECK((a >> 4) == to_byte<0x0F>());
+ a &= b;
+ CHECK(a == to_byte<0x01>());
- a <<= 4;
- CHECK(a == to_byte<0xF0>());
- a >>= 4;
- CHECK(a == to_byte<0x0F>());
- }
+ CHECK((b ^ a) == to_byte<0xFE>());
- TEST(to_integer)
- {
- byte b = to_byte<0x12>();
+ CHECK(a == to_byte<0x01>());
+ a ^= b;
+ CHECK(a == to_byte<0xFE>());
- 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));
+ a = to_byte<0x01>();
+ CHECK(~a == to_byte<0xFE>());
- 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));
+ a = to_byte<0xFF>();
+ CHECK((a << 4) == to_byte<0xF0>());
+ CHECK((a >> 4) == to_byte<0x0F>());
-// CHECK(0x12 == gsl::to_integer<float>(b)); // expect compile-time error
-// CHECK(0x12 == gsl::to_integer<double>(b)); // expect compile-time error
- }
+ a <<= 4;
+ CHECK(a == to_byte<0xF0>());
+ a >>= 4;
+ CHECK(a == to_byte<0x0F>());
+}
- int modify_both(gsl::byte& b, int& i)
- {
- i = 10;
- b = to_byte<5>();
- return i;
- }
+TEST_CASE("to_integer")
+{
+ const byte b = to_byte<0x12>();
- TEST(aliasing)
- {
- int i{ 0 };
- int res = modify_both(reinterpret_cast<byte&>(i), i);
- CHECK(res == i);
- }
+ 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));
+
+ 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));
+
+ // 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;
}
+TEST_CASE("aliasing")
+{
+ int i{0};
+ const int res = modify_both(reinterpret_cast<byte&>(i), i);
+ CHECK(res == i);
}
-int main(int, const char* []) { return UnitTest::RunAllTests(); }
+}