1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#include <aws/common/byte_order.h>
#include <aws/testing/aws_test_harness.h>
#ifdef _MSC_VER
# pragma warning(disable : 4324) /* structure was padded due to alignment specifier */
#endif
static int s_byte_swap_test_fn(struct aws_allocator *allocator, void *ctx) {
(void)allocator;
(void)ctx;
uint64_t ans_x = 0x1122334455667788ULL;
uint32_t ans_y = 0xaabbccdd;
uint16_t ans_w = 0xeeff;
uint8_t x[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88};
uint8_t y[] = {0xaa, 0xbb, 0xcc, 0xdd};
uint8_t w[] = {0xee, 0xff};
uint64_t x64;
uint32_t y32;
uint16_t w16;
memcpy(&x64, x, sizeof(x));
memcpy(&y32, y, sizeof(y));
memcpy(&w16, w, sizeof(w));
ASSERT_UINT_EQUALS(aws_ntoh64(x64), ans_x);
ASSERT_UINT_EQUALS(aws_hton64(x64), ans_x);
ASSERT_UINT_EQUALS(aws_ntoh32(y32), ans_y);
ASSERT_UINT_EQUALS(aws_hton32(y32), ans_y);
ASSERT_UINT_EQUALS(aws_ntoh16(w16), ans_w);
ASSERT_UINT_EQUALS(aws_hton16(w16), ans_w);
return 0;
}
AWS_TEST_CASE(byte_swap_test, s_byte_swap_test_fn);
AWS_ALIGNED_TYPEDEF(uint8_t, aligned32_storage[64], 32);
struct padding32_disaster {
uint8_t dumb;
aligned32_storage b;
};
static int s_alignment32_test_fn(struct aws_allocator *allocator, void *ctx) {
(void)allocator;
(void)ctx;
size_t spacing = offsetof(struct padding32_disaster, b) - offsetof(struct padding32_disaster, dumb);
ASSERT_UINT_EQUALS(0, spacing % 32);
return 0;
}
AWS_TEST_CASE(alignment32_test, s_alignment32_test_fn)
AWS_ALIGNED_TYPEDEF(uint8_t, aligned16_storage[64], 16);
struct padding16_disaster {
uint8_t dumb;
aligned16_storage b;
};
static int s_alignment16_test_fn(struct aws_allocator *allocator, void *ctx) {
(void)allocator;
(void)ctx;
size_t spacing = offsetof(struct padding32_disaster, b) - offsetof(struct padding32_disaster, dumb);
ASSERT_UINT_EQUALS(0, spacing % 16);
return 0;
}
AWS_TEST_CASE(alignment16_test, s_alignment16_test_fn)
|