mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-17 06:15:47 +01:00
replace endianness tests with more robust and architecture-agnostic tests for swapping byte order
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../src/util/conf.h"
|
||||
#include "../src/util/vec/float3.h"
|
||||
@@ -10,7 +9,12 @@
|
||||
testdat tests[] = {
|
||||
{"", test_float3_norm, &(float3){2.0F, 0.67F, 5.0F} },
|
||||
{"", test_float3_norm, &(float3){0.2F, 0.4F, 0.1F} },
|
||||
{"", test_compat_endianess, (uint32_t[]){0x15F59267} },
|
||||
{"", test_bswap16, (uint16_t[]){0x11EE, 0xEE11} },
|
||||
{"", test_bswap32, (uint32_t[]){0x1142ADEE, 0xEEAD4211} },
|
||||
{"", test_bswap64, (uint64_t[]){0x114266897799ADEE, 0xEEAD997789664211} },
|
||||
{"", test_bswap16_impl, (uint16_t[]){0x11EE, 0xEE11} },
|
||||
{"", test_bswap32_impl, (uint32_t[]){0x1142ADEE, 0xEEAD4211} },
|
||||
{"", test_bswap64_impl, (uint64_t[]){0x114266897799ADEE, 0xEEAD997789664211} },
|
||||
{"k=v", test_procbuf, &(struct test_procbuf){"key=val", "key", "val", 0} },
|
||||
{"sometxt", test_procbuf, &(struct test_procbuf){"sometxt", "sometxt", "", CONF_ESYNTAX}},
|
||||
{"comment", test_procbuf, &(struct test_procbuf){"# comment", "", "", CONF_ENODAT} },
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../src/util/colour32.h"
|
||||
#include "../src/util/compat/endian.h"
|
||||
#include "../src/util/compat/bswap.h"
|
||||
#include "../src/util/vec/float3.h"
|
||||
#include "test.h"
|
||||
|
||||
@@ -23,24 +23,32 @@ int test_colour32_endianess(void* d) {
|
||||
return assert_true(c.ch.r == 0xFF);
|
||||
}
|
||||
|
||||
int test_compat_endianess(void* d) {
|
||||
uint32_t x = *((uint32_t*)d + 0);
|
||||
int res = 0;
|
||||
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
res |= assert_false(be32ton(x) == x);
|
||||
res |= assert_false(ntobe32(x) == x);
|
||||
res |= assert_true(be32ton(ntobe32(x)) == x);
|
||||
res |= assert_true(le32ton(x) == x);
|
||||
res |= assert_true(ntole32(x) == x);
|
||||
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
res |= assert_false(le32ton(x) == x);
|
||||
res |= assert_false(ntole32(x) == x);
|
||||
res |= assert_true(le32ton(ntole32(x)) == x);
|
||||
res |= assert_true(be32ton(x) == x);
|
||||
res |= assert_true(ntobe32(x) == x);
|
||||
#else
|
||||
res |= assert_false("platform unsupported!!");
|
||||
#endif
|
||||
return res;
|
||||
int test_bswap16(void* d) {
|
||||
uint16_t* arg = d;
|
||||
return assert_true(bswap16(arg[0]) == arg[1]);
|
||||
}
|
||||
|
||||
int test_bswap32(void* d) {
|
||||
uint32_t* arg = d;
|
||||
return assert_true(bswap32(arg[0]) == arg[1]);
|
||||
}
|
||||
|
||||
int test_bswap64(void* d) {
|
||||
uint64_t* arg = d;
|
||||
return assert_true(bswap64(arg[0]) == arg[1]);
|
||||
}
|
||||
|
||||
int test_bswap16_impl(void* d) {
|
||||
uint16_t* arg = d;
|
||||
return assert_true(bswap16_impl(arg[0]) == arg[1]);
|
||||
}
|
||||
|
||||
int test_bswap32_impl(void* d) {
|
||||
uint32_t* arg = d;
|
||||
return assert_true(bswap32_impl(arg[0]) == arg[1]);
|
||||
}
|
||||
|
||||
int test_bswap64_impl(void* d) {
|
||||
uint64_t* arg = d;
|
||||
return assert_true(bswap64_impl(arg[0]) == arg[1]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user