diff options
author | Lennart Poettering <lennart@poettering.net> | 2016-06-02 18:12:16 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2016-06-06 19:59:09 +0200 |
commit | c917a32122ac18c9b6112d67fbb815d84a053e4a (patch) | |
tree | 9dd8675e7792f75541c8c47e560063f34d087b77 /src/test | |
parent | c9d81ae858cdf0482fa4c9c37e5f5e26d615e8c4 (diff) |
util-lib: add accessors for unaligned native endian words
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-unaligned.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/test/test-unaligned.c b/src/test/test-unaligned.c index b18b3fca0e..4f64398943 100644 --- a/src/test/test-unaligned.c +++ b/src/test/test-unaligned.c @@ -159,7 +159,31 @@ static void test_le(void) { assert_se(memcmp(&scratch[7], &data[7], sizeof(uint64_t)) == 0); } +static void test_ne(void) { + uint16_t x = 4711; + uint32_t y = 123456; + uint64_t z = 9876543210; + + /* Note that we don't bother actually testing alignment issues in this function, after all the _ne() functions + * are just aliases for the _le() or _be() implementations, which we test extensively above. Hence, in this + * function, just ensure that they map to the right version on the local architecture. */ + + assert_se(unaligned_read_ne16(&x) == 4711); + assert_se(unaligned_read_ne32(&y) == 123456); + assert_se(unaligned_read_ne64(&z) == 9876543210); + + unaligned_write_ne16(&x, 1); + unaligned_write_ne32(&y, 2); + unaligned_write_ne64(&z, 3); + + assert_se(x == 1); + assert_se(y == 2); + assert_se(z == 3); +} + int main(int argc, const char *argv[]) { test_be(); test_le(); + test_ne(); + return 0; } |