// // Created by erki on 10/12/22. // #include #include "utility_bytes.hpp" TEST_CASE("zeroInitialized creates an appropriate struct.") { struct TestStruct { int a; char b; int c; }; SECTION("Return by value variant returns a struct where all members are 0.") { const TestStruct test = Utility::zeroInitialized(); REQUIRE(test.a == 0); REQUIRE(test.b == 0); REQUIRE(test.c == 0); } SECTION("Pass by reference variant initializes the struct to all 0's.") { TestStruct test; Utility::zeroInitialized(test); REQUIRE(test.a == 0); REQUIRE(test.b == 0); REQUIRE(test.c == 0); } SECTION("Pass by pointer variant initializes the struct to all 0's.") { TestStruct test; Utility::zeroInitialized(&test); REQUIRE(test.a == 0); REQUIRE(test.b == 0); REQUIRE(test.c == 0); } } TEST_CASE("arrayToType constructs a type appropriately.") { const std::uint32_t initial_value = 0x12345678; SECTION("Using C-arrays the operation works appropriately.") { std::uint8_t raw_data[4] = {0}; std::memcpy(raw_data, &initial_value, 4); const std::uint32_t output = Utility::arrayToType(raw_data); REQUIRE(output == initial_value); } SECTION("Using C-arrays the operation works appropriately.") { std::array raw_data = {0, 0, 0, 0}; std::memcpy(raw_data.data(), &initial_value, 4); const std::uint32_t output = Utility::arrayToType(raw_data); REQUIRE(output == initial_value); } }