1
0
mirror of synced 2025-01-19 01:24:15 +01:00

tests: Added endian changer tests

This commit is contained in:
WerWolv 2021-10-20 11:17:55 +02:00
parent d6f9ec3f8f
commit 442f164159
4 changed files with 33 additions and 5 deletions

View File

@ -5,12 +5,22 @@ project(algorithms_test)
# Add new tests here #
set(AVAILABLE_TESTS
TestSucceeding
TestFailing
# Common
TestSucceeding
TestFailing
# Endian
32BitIntegerEndianSwap
64BitFloatEndianSwap
)
add_executable(algorithms_test source/hash.cpp source/main.cpp include/tests.hpp)
add_executable(algorithms_test
source/main.cpp
source/common.cpp
source/endian.cpp
)
target_include_directories(algorithms_test PRIVATE include)
target_link_libraries(algorithms_test libimhex)

View File

@ -9,9 +9,10 @@
#include <functional>
#define TEST_SEQUENCE(...) static auto ANONYMOUS_VARIABLE(TEST_SEQUENCE) = ::hex::test::TestSequenceExecutor(__VA_ARGS__) + []() -> int
#define TEST_FAIL() return EXIT_FAILURE;
#define TEST_SUCCESS() return EXIT_SUCCESS;
#define TEST_FAIL() return EXIT_FAILURE
#define TEST_SUCCESS() return EXIT_SUCCESS
#define FAILING true
#define TEST_ASSERT(x) return (x) ? EXIT_SUCCESS : EXIT_FAILURE
namespace hex::test {

View File

@ -0,0 +1,17 @@
#include <hex/helpers/utils.hpp>
#include "test_provider.hpp"
#include "tests.hpp"
TEST_SEQUENCE("32BitIntegerEndianSwap") {
TEST_ASSERT(hex::changeEndianess<u32>(0xAABBCCDD, std::endian::big) == 0xDDCCBBAA);
};
TEST_SEQUENCE("64BitFloatEndianSwap", FAILING) {
double floatValue = 1234.5;
u64 integerValue = reinterpret_cast<u64&>(floatValue);
double swappedFloatValue = hex::changeEndianess(floatValue, std::endian::big);
u64 swappedIntegerValue = hex::changeEndianess(integerValue, std::endian::big);
TEST_ASSERT(std::memcmp(&floatValue, &integerValue, 8) && std::memcmp(&swappedFloatValue, &swappedIntegerValue, 8));
};