Run clang-format and enable CI check for it (#755)
* pre-commit: Update and enable clang-format check There is newer version from clang-format so use that. We do not yet want 18 as that is little bit too new. * Format some thing by hand which clang-format "breaks" Clang-format will format some things little bit off in some cases. Format some things by hand so we get cleaner end result. * Run clang-format with ``` pre-commit run --all-files clang-format ``` We have already in previously checked places where clang-format does not make good format and ignored those (hopefully most of the things). --------- Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
This commit is contained in:
@@ -86,7 +86,8 @@ DEFINE_FAKE_VALUE_FUNC(int, bacnet_signed_application_decode, uint8_t *, uint16_
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_enumerated_decode, uint8_t *, uint16_t, uint32_t, uint32_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, bacnet_enumerated_context_decode, uint8_t *, uint16_t, uint8_t, uint32_t *);
|
||||
#endif
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_enumerated, const uint8_t *, uint32_t, uint32_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(
|
||||
int, decode_enumerated, const uint8_t *, uint32_t, uint32_t *);
|
||||
#if 0
|
||||
DEFINE_FAKE_VALUE_FUNC(int, decode_context_enumerated, uint8_t *, uint8_t, uint32_t *);
|
||||
DEFINE_FAKE_VALUE_FUNC(int, encode_bacnet_enumerated, uint8_t *, uint32_t);
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
CONTEXTTYPE *const contexts = CONTAINER_OF( \
|
||||
FUNCNAME##_fake.return_val_seq, CONTEXTTYPE, RESULTFIELD); \
|
||||
size_t const seq_idx = (FUNCNAME##_fake.return_val_seq_idx < \
|
||||
FUNCNAME##_fake.return_val_seq_len) \
|
||||
FUNCNAME##_fake.return_val_seq_len) \
|
||||
? FUNCNAME##_fake.return_val_seq_idx++ \
|
||||
: FUNCNAME##_fake.return_val_seq_idx - 1; \
|
||||
CONTEXTTYPE *const CONTEXTPTRNAME = &contexts[seq_idx]; \
|
||||
@@ -54,15 +54,16 @@ struct encode_application_enumerated_custom_fake_context {
|
||||
|
||||
/* Written to client by custom fake */
|
||||
const uint8_t *const encoded_enumerated;
|
||||
int const encoded_enumerated_len;
|
||||
const int encoded_enumerated_len;
|
||||
|
||||
int result;
|
||||
};
|
||||
|
||||
static int encode_application_enumerated_custom_fake(
|
||||
uint8_t *apdu, uint32_t enumerated)
|
||||
static int
|
||||
encode_application_enumerated_custom_fake(uint8_t *apdu, uint32_t enumerated)
|
||||
{
|
||||
RETURN_HANDLED_CONTEXT(encode_application_enumerated,
|
||||
RETURN_HANDLED_CONTEXT(
|
||||
encode_application_enumerated,
|
||||
struct encode_application_enumerated_custom_fake_context,
|
||||
result, /* return field name in _fake_context struct */
|
||||
context, /* Name of context ptr variable used below */
|
||||
@@ -70,7 +71,8 @@ static int encode_application_enumerated_custom_fake(
|
||||
if (context != NULL) {
|
||||
if (context->result == 0) {
|
||||
if (apdu != NULL) {
|
||||
memcpy(apdu, context->encoded_enumerated,
|
||||
memcpy(
|
||||
apdu, context->encoded_enumerated,
|
||||
context->encoded_enumerated_len);
|
||||
}
|
||||
}
|
||||
@@ -86,8 +88,8 @@ struct decode_tag_number_and_value_custom_fake_context {
|
||||
uint8_t *const apdu_expected;
|
||||
|
||||
/* Written to client by custom fake */
|
||||
uint8_t const tag_number;
|
||||
uint32_t const value;
|
||||
const uint8_t tag_number;
|
||||
const uint32_t value;
|
||||
|
||||
int result;
|
||||
};
|
||||
@@ -95,17 +97,20 @@ struct decode_tag_number_and_value_custom_fake_context {
|
||||
static int decode_tag_number_and_value_custom_fake(
|
||||
const uint8_t *apdu, uint8_t *tag_number, uint32_t *value)
|
||||
{
|
||||
RETURN_HANDLED_CONTEXT(decode_tag_number_and_value,
|
||||
RETURN_HANDLED_CONTEXT(
|
||||
decode_tag_number_and_value,
|
||||
struct decode_tag_number_and_value_custom_fake_context,
|
||||
result, /* return field name in _fake_context struct */
|
||||
context, /* Name of context ptr variable used below */
|
||||
{
|
||||
if (context != NULL) {
|
||||
if (context->result > 0) {
|
||||
if (tag_number != NULL)
|
||||
if (tag_number != NULL) {
|
||||
*tag_number = context->tag_number;
|
||||
if (value != NULL)
|
||||
}
|
||||
if (value != NULL) {
|
||||
*value = context->value;
|
||||
}
|
||||
}
|
||||
|
||||
return context->result;
|
||||
@@ -119,7 +124,7 @@ struct decode_enumerated_custom_fake_context {
|
||||
uint8_t *const apdu_expected;
|
||||
|
||||
/* Written to client by custom fake */
|
||||
uint32_t const value;
|
||||
const uint32_t value;
|
||||
|
||||
int result;
|
||||
};
|
||||
@@ -127,15 +132,16 @@ struct decode_enumerated_custom_fake_context {
|
||||
static int decode_enumerated_custom_fake(
|
||||
const uint8_t *apdu, uint32_t len_value, uint32_t *value)
|
||||
{
|
||||
RETURN_HANDLED_CONTEXT(decode_enumerated,
|
||||
struct decode_enumerated_custom_fake_context,
|
||||
RETURN_HANDLED_CONTEXT(
|
||||
decode_enumerated, struct decode_enumerated_custom_fake_context,
|
||||
result, /* return field name in _fake_context struct */
|
||||
context, /* Name of context ptr variable used below */
|
||||
{
|
||||
if (context != NULL) {
|
||||
if (context->result > 0) {
|
||||
if (value != NULL)
|
||||
if (value != NULL) {
|
||||
*value = context->value;
|
||||
}
|
||||
}
|
||||
|
||||
return context->result;
|
||||
@@ -276,7 +282,8 @@ static void test_bacerror_encode_apdu(void)
|
||||
for (int i = 0; i < ARRAY_SIZE(test_cases); ++i) {
|
||||
const struct test_case *const tc = &test_cases[i];
|
||||
|
||||
printk("Checking test_cases[%i]: %s\n", i,
|
||||
printk(
|
||||
"Checking test_cases[%i]: %s\n", i,
|
||||
(tc->description_oneliner != NULL) ? tc->description_oneliner : "");
|
||||
|
||||
/*
|
||||
@@ -296,7 +303,8 @@ static void test_bacerror_encode_apdu(void)
|
||||
*/
|
||||
encode_application_enumerated_fake.return_val =
|
||||
-E2BIG; /* for excessive calls */
|
||||
SET_RETURN_SEQ(encode_application_enumerated,
|
||||
SET_RETURN_SEQ(
|
||||
encode_application_enumerated,
|
||||
&tc->encode_application_enumerated_custom_fake_contexts[0].result,
|
||||
tc->encode_application_enumerated_custom_fake_contexts_len);
|
||||
encode_application_enumerated_fake.custom_fake =
|
||||
@@ -307,8 +315,9 @@ static void test_bacerror_encode_apdu(void)
|
||||
/*
|
||||
* Call code_under_test
|
||||
*/
|
||||
int result = bacerror_encode_apdu(tc->apdu, tc->invoke_id, tc->service,
|
||||
tc->error_class, tc->error_code);
|
||||
int result = bacerror_encode_apdu(
|
||||
tc->apdu, tc->invoke_id, tc->service, tc->error_class,
|
||||
tc->error_code);
|
||||
|
||||
/*
|
||||
* Verify expected behavior of code_under_test:
|
||||
@@ -332,15 +341,18 @@ static void test_bacerror_encode_apdu(void)
|
||||
? 0
|
||||
: tc->encode_application_enumerated_custom_fake_contexts_len - 1;
|
||||
|
||||
zassert_equal(encode_application_enumerated_fake.call_count,
|
||||
zassert_equal(
|
||||
encode_application_enumerated_fake.call_count,
|
||||
encode_application_enumerated_fake_call_count_expected, NULL);
|
||||
for (int j = 0;
|
||||
j < encode_application_enumerated_fake_call_count_expected; ++j) {
|
||||
zassert_equal(encode_application_enumerated_fake.arg0_history[j],
|
||||
zassert_equal(
|
||||
encode_application_enumerated_fake.arg0_history[j],
|
||||
tc->encode_application_enumerated_custom_fake_contexts[j]
|
||||
.apdu_expected,
|
||||
NULL);
|
||||
zassert_equal(encode_application_enumerated_fake.arg1_history[j],
|
||||
zassert_equal(
|
||||
encode_application_enumerated_fake.arg1_history[j],
|
||||
tc->encode_application_enumerated_custom_fake_contexts[j]
|
||||
.value_expected,
|
||||
NULL);
|
||||
@@ -469,7 +481,8 @@ static void test_bacerror_decode_error_class_and_code(void)
|
||||
|
||||
.expected_call_history =
|
||||
(void *[]) {
|
||||
bacnet_enumerated_application_decode, NULL, /* mark end of array */
|
||||
bacnet_enumerated_application_decode,
|
||||
NULL, /* mark end of array */
|
||||
},
|
||||
|
||||
.decode_tag_number_and_value_custom_fake_contexts_len = 2,
|
||||
@@ -983,7 +996,8 @@ static void test_bacerror_decode_error_class_and_code(void)
|
||||
for (int i = 0; i < ARRAY_SIZE(test_cases); ++i) {
|
||||
const struct test_case *const tc = &test_cases[i];
|
||||
|
||||
printk("Checking test_cases[%i]: %s\n", i,
|
||||
printk(
|
||||
"Checking test_cases[%i]: %s\n", i,
|
||||
(tc->description_oneliner != NULL) ? tc->description_oneliner : "");
|
||||
|
||||
/*
|
||||
@@ -1003,14 +1017,16 @@ static void test_bacerror_decode_error_class_and_code(void)
|
||||
*/
|
||||
decode_tag_number_and_value_fake.return_val =
|
||||
-E2BIG; /* for excessive calls */
|
||||
SET_RETURN_SEQ(decode_tag_number_and_value,
|
||||
SET_RETURN_SEQ(
|
||||
decode_tag_number_and_value,
|
||||
&tc->decode_tag_number_and_value_custom_fake_contexts[0].result,
|
||||
tc->decode_tag_number_and_value_custom_fake_contexts_len);
|
||||
decode_tag_number_and_value_fake.custom_fake =
|
||||
decode_tag_number_and_value_custom_fake;
|
||||
|
||||
decode_enumerated_fake.return_val = -E2BIG; /* for excessive calls */
|
||||
SET_RETURN_SEQ(decode_enumerated,
|
||||
SET_RETURN_SEQ(
|
||||
decode_enumerated,
|
||||
&tc->decode_enumerated_custom_fake_contexts[0].result,
|
||||
tc->decode_enumerated_custom_fake_contexts_len);
|
||||
decode_enumerated_fake.custom_fake = decode_enumerated_custom_fake;
|
||||
@@ -1064,11 +1080,13 @@ static void test_bacerror_decode_error_class_and_code(void)
|
||||
? 0
|
||||
: tc->decode_tag_number_and_value_custom_fake_contexts_len - 1;
|
||||
|
||||
zassert_equal(decode_tag_number_and_value_fake.call_count,
|
||||
zassert_equal(
|
||||
decode_tag_number_and_value_fake.call_count,
|
||||
decode_tag_number_and_value_fake_call_count_expected, NULL);
|
||||
for (int j = 0;
|
||||
j < decode_tag_number_and_value_fake_call_count_expected; ++j) {
|
||||
zassert_equal(decode_tag_number_and_value_fake.arg0_history[j],
|
||||
zassert_equal(
|
||||
decode_tag_number_and_value_fake.arg0_history[j],
|
||||
tc->decode_tag_number_and_value_custom_fake_contexts[j]
|
||||
.apdu_expected,
|
||||
NULL);
|
||||
@@ -1083,13 +1101,16 @@ static void test_bacerror_decode_error_class_and_code(void)
|
||||
? 0
|
||||
: tc->decode_enumerated_custom_fake_contexts_len - 1;
|
||||
|
||||
zassert_equal(decode_enumerated_fake.call_count,
|
||||
zassert_equal(
|
||||
decode_enumerated_fake.call_count,
|
||||
decode_enumerated_fake_call_count_expected, NULL);
|
||||
for (int j = 0; j < decode_enumerated_fake_call_count_expected; ++j) {
|
||||
zassert_equal(decode_enumerated_fake.arg0_history[j],
|
||||
zassert_equal(
|
||||
decode_enumerated_fake.arg0_history[j],
|
||||
tc->decode_enumerated_custom_fake_contexts[j].apdu_expected,
|
||||
NULL);
|
||||
zassert_equal(decode_enumerated_fake.arg1_history[j],
|
||||
zassert_equal(
|
||||
decode_enumerated_fake.arg1_history[j],
|
||||
tc->decode_tag_number_and_value_custom_fake_contexts[j].value,
|
||||
NULL);
|
||||
zassert_not_null(decode_enumerated_fake.arg2_history[j], NULL);
|
||||
@@ -1131,8 +1152,8 @@ ZTEST_SUITE(bacnet_error, NULL, NULL, NULL, NULL, NULL);
|
||||
#else
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(bacnet_bacerror,
|
||||
ztest_unit_test(test_bacerror_encode_apdu),
|
||||
ztest_test_suite(
|
||||
bacnet_bacerror, ztest_unit_test(test_bacerror_encode_apdu),
|
||||
ztest_unit_test(test_bacerror_decode_error_class_and_code));
|
||||
ztest_run_test_suite(bacnet_bacerror);
|
||||
}
|
||||
|
||||
+206
-214
@@ -48,8 +48,8 @@ static void test_unsigned16(void)
|
||||
/* Verify aligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[3] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(2, encode_unsigned16(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(2, decode_unsigned16(&apdu[2], &value), NULL);
|
||||
@@ -57,8 +57,8 @@ static void test_unsigned16(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[3] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(2, encode_unsigned16(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(2, decode_unsigned16(&apdu[2], &value), NULL);
|
||||
@@ -67,8 +67,8 @@ static void test_unsigned16(void)
|
||||
/* Verify unaligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[4] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(2, encode_unsigned16(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(2, decode_unsigned16(&apdu[3], &value), NULL);
|
||||
@@ -76,8 +76,8 @@ static void test_unsigned16(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[4] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(2, encode_unsigned16(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(2, decode_unsigned16(&apdu[3], &value), NULL);
|
||||
@@ -122,9 +122,9 @@ static void test_unsigned24(void)
|
||||
/* Verify aligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >>16);
|
||||
test_apdu[3] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[4] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(3, encode_unsigned24(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(3, decode_unsigned24(&apdu[2], &value), NULL);
|
||||
@@ -132,9 +132,9 @@ static void test_unsigned24(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >>16);
|
||||
test_apdu[3] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[4] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(3, encode_unsigned24(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(3, decode_unsigned24(&apdu[2], &value), NULL);
|
||||
@@ -143,9 +143,9 @@ static void test_unsigned24(void)
|
||||
/* Verify unaligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >>16);
|
||||
test_apdu[4] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[5] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(3, encode_unsigned24(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(3, decode_unsigned24(&apdu[3], &value), NULL);
|
||||
@@ -153,9 +153,9 @@ static void test_unsigned24(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >>16);
|
||||
test_apdu[4] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[5] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(3, encode_unsigned24(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(3, decode_unsigned24(&apdu[3], &value), NULL);
|
||||
@@ -200,10 +200,10 @@ static void test_unsigned32(void)
|
||||
/* Verify aligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >>24);
|
||||
test_apdu[3] = (uint8_t) (test_value >>16);
|
||||
test_apdu[4] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[5] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(4, encode_unsigned32(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(4, decode_unsigned32(&apdu[2], &value), NULL);
|
||||
@@ -211,10 +211,10 @@ static void test_unsigned32(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >>24);
|
||||
test_apdu[3] = (uint8_t) (test_value >>16);
|
||||
test_apdu[4] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[5] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(4, encode_unsigned32(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(4, decode_unsigned32(&apdu[2], &value), NULL);
|
||||
@@ -223,10 +223,10 @@ static void test_unsigned32(void)
|
||||
/* Verify unaligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >>24);
|
||||
test_apdu[4] = (uint8_t) (test_value >>16);
|
||||
test_apdu[5] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[6] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(4, encode_unsigned32(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(4, decode_unsigned32(&apdu[3], &value), NULL);
|
||||
@@ -234,10 +234,10 @@ static void test_unsigned32(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >>24);
|
||||
test_apdu[4] = (uint8_t) (test_value >>16);
|
||||
test_apdu[5] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[6] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(4, encode_unsigned32(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(4, decode_unsigned32(&apdu[3], &value), NULL);
|
||||
@@ -283,11 +283,11 @@ static void test_unsigned40(void)
|
||||
/* Verify aligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >>32);
|
||||
test_apdu[3] = (uint8_t) (test_value >>24);
|
||||
test_apdu[4] = (uint8_t) (test_value >>16);
|
||||
test_apdu[5] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[6] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 32);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(5, encode_unsigned40(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(5, decode_unsigned40(&apdu[2], &value), NULL);
|
||||
@@ -295,11 +295,11 @@ static void test_unsigned40(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >>32);
|
||||
test_apdu[3] = (uint8_t) (test_value >>24);
|
||||
test_apdu[4] = (uint8_t) (test_value >>16);
|
||||
test_apdu[5] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[6] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 32);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(5, encode_unsigned40(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(5, decode_unsigned40(&apdu[2], &value), NULL);
|
||||
@@ -308,11 +308,11 @@ static void test_unsigned40(void)
|
||||
/* Verify unaligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >>32);
|
||||
test_apdu[4] = (uint8_t) (test_value >>24);
|
||||
test_apdu[5] = (uint8_t) (test_value >>16);
|
||||
test_apdu[6] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[7] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 32);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[7] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(5, encode_unsigned40(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(5, decode_unsigned40(&apdu[3], &value), NULL);
|
||||
@@ -320,11 +320,11 @@ static void test_unsigned40(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >>32);
|
||||
test_apdu[4] = (uint8_t) (test_value >>24);
|
||||
test_apdu[5] = (uint8_t) (test_value >>16);
|
||||
test_apdu[6] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[7] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 32);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[7] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(5, encode_unsigned40(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(5, decode_unsigned40(&apdu[3], &value), NULL);
|
||||
@@ -377,12 +377,12 @@ static void test_unsigned48(void)
|
||||
/* Verify aligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >>40);
|
||||
test_apdu[3] = (uint8_t) (test_value >>32);
|
||||
test_apdu[4] = (uint8_t) (test_value >>24);
|
||||
test_apdu[5] = (uint8_t) (test_value >>16);
|
||||
test_apdu[6] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[7] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 40);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 32);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[7] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(6, encode_unsigned48(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(6, decode_unsigned48(&apdu[2], &value), NULL);
|
||||
@@ -390,12 +390,12 @@ static void test_unsigned48(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >>40);
|
||||
test_apdu[3] = (uint8_t) (test_value >>32);
|
||||
test_apdu[4] = (uint8_t) (test_value >>24);
|
||||
test_apdu[5] = (uint8_t) (test_value >>16);
|
||||
test_apdu[6] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[7] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 40);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 32);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[7] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(6, encode_unsigned48(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(6, decode_unsigned48(&apdu[2], &value), NULL);
|
||||
@@ -404,12 +404,12 @@ static void test_unsigned48(void)
|
||||
/* Verify unaligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >>40);
|
||||
test_apdu[4] = (uint8_t) (test_value >>32);
|
||||
test_apdu[5] = (uint8_t) (test_value >>24);
|
||||
test_apdu[6] = (uint8_t) (test_value >>16);
|
||||
test_apdu[7] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[8] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 40);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 32);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[7] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[8] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(6, encode_unsigned48(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(6, decode_unsigned48(&apdu[3], &value), NULL);
|
||||
@@ -417,12 +417,12 @@ static void test_unsigned48(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >>40);
|
||||
test_apdu[4] = (uint8_t) (test_value >>32);
|
||||
test_apdu[5] = (uint8_t) (test_value >>24);
|
||||
test_apdu[6] = (uint8_t) (test_value >>16);
|
||||
test_apdu[7] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[8] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 40);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 32);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[7] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[8] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(6, encode_unsigned48(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(6, decode_unsigned48(&apdu[3], &value), NULL);
|
||||
@@ -475,13 +475,13 @@ static void test_unsigned56(void)
|
||||
/* Verify aligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >>48);
|
||||
test_apdu[3] = (uint8_t) (test_value >>40);
|
||||
test_apdu[4] = (uint8_t) (test_value >>32);
|
||||
test_apdu[5] = (uint8_t) (test_value >>24);
|
||||
test_apdu[6] = (uint8_t) (test_value >>16);
|
||||
test_apdu[7] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[8] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 48);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 40);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 32);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[7] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[8] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(7, encode_unsigned56(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(7, decode_unsigned56(&apdu[2], &value), NULL);
|
||||
@@ -489,13 +489,13 @@ static void test_unsigned56(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >>48);
|
||||
test_apdu[3] = (uint8_t) (test_value >>40);
|
||||
test_apdu[4] = (uint8_t) (test_value >>32);
|
||||
test_apdu[5] = (uint8_t) (test_value >>24);
|
||||
test_apdu[6] = (uint8_t) (test_value >>16);
|
||||
test_apdu[7] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[8] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 48);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 40);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 32);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[7] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[8] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(7, encode_unsigned56(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(7, decode_unsigned56(&apdu[2], &value), NULL);
|
||||
@@ -504,13 +504,13 @@ static void test_unsigned56(void)
|
||||
/* Verify unaligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >>48);
|
||||
test_apdu[4] = (uint8_t) (test_value >>40);
|
||||
test_apdu[5] = (uint8_t) (test_value >>32);
|
||||
test_apdu[6] = (uint8_t) (test_value >>24);
|
||||
test_apdu[7] = (uint8_t) (test_value >>16);
|
||||
test_apdu[8] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[9] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 48);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 40);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 32);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[7] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[8] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[9] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(7, encode_unsigned56(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(7, decode_unsigned56(&apdu[3], &value), NULL);
|
||||
@@ -518,13 +518,13 @@ static void test_unsigned56(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >>48);
|
||||
test_apdu[4] = (uint8_t) (test_value >>40);
|
||||
test_apdu[5] = (uint8_t) (test_value >>32);
|
||||
test_apdu[6] = (uint8_t) (test_value >>24);
|
||||
test_apdu[7] = (uint8_t) (test_value >>16);
|
||||
test_apdu[8] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[9] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 48);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 40);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 32);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[7] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[8] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[9] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(7, encode_unsigned56(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(7, decode_unsigned56(&apdu[3], &value), NULL);
|
||||
@@ -577,14 +577,14 @@ static void test_unsigned64(void)
|
||||
/* Verify aligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >>56);
|
||||
test_apdu[3] = (uint8_t) (test_value >>48);
|
||||
test_apdu[4] = (uint8_t) (test_value >>40);
|
||||
test_apdu[5] = (uint8_t) (test_value >>32);
|
||||
test_apdu[6] = (uint8_t) (test_value >>24);
|
||||
test_apdu[7] = (uint8_t) (test_value >>16);
|
||||
test_apdu[8] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[9] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 56);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 48);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 40);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 32);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[7] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[8] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[9] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(8, encode_unsigned64(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(8, decode_unsigned64(&apdu[2], &value), NULL);
|
||||
@@ -592,14 +592,14 @@ static void test_unsigned64(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >>56);
|
||||
test_apdu[3] = (uint8_t) (test_value >>48);
|
||||
test_apdu[4] = (uint8_t) (test_value >>40);
|
||||
test_apdu[5] = (uint8_t) (test_value >>32);
|
||||
test_apdu[6] = (uint8_t) (test_value >>24);
|
||||
test_apdu[7] = (uint8_t) (test_value >>16);
|
||||
test_apdu[8] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[9] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 56);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 48);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 40);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 32);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[7] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[8] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[9] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(8, encode_unsigned64(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(8, decode_unsigned64(&apdu[2], &value), NULL);
|
||||
@@ -608,14 +608,14 @@ static void test_unsigned64(void)
|
||||
/* Verify unaligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >>56);
|
||||
test_apdu[4] = (uint8_t) (test_value >>48);
|
||||
test_apdu[5] = (uint8_t) (test_value >>40);
|
||||
test_apdu[6] = (uint8_t) (test_value >>32);
|
||||
test_apdu[7] = (uint8_t) (test_value >>24);
|
||||
test_apdu[8] = (uint8_t) (test_value >>16);
|
||||
test_apdu[9] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[10] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 56);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 48);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 40);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 32);
|
||||
test_apdu[7] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[8] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[9] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[10] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(8, encode_unsigned64(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(8, decode_unsigned64(&apdu[3], &value), NULL);
|
||||
@@ -623,14 +623,14 @@ static void test_unsigned64(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >>56);
|
||||
test_apdu[4] = (uint8_t) (test_value >>48);
|
||||
test_apdu[5] = (uint8_t) (test_value >>40);
|
||||
test_apdu[6] = (uint8_t) (test_value >>32);
|
||||
test_apdu[7] = (uint8_t) (test_value >>24);
|
||||
test_apdu[8] = (uint8_t) (test_value >>16);
|
||||
test_apdu[9] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[10] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 56);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 48);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 40);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 32);
|
||||
test_apdu[7] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[8] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[9] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[10] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(8, encode_unsigned64(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(8, decode_unsigned64(&apdu[3], &value), NULL);
|
||||
@@ -659,35 +659,35 @@ static void test_unsigned_length(void)
|
||||
zassert_equal(2, bacnet_unsigned_length(0xFFUL << 8), NULL);
|
||||
zassert_equal(2, bacnet_unsigned_length(0xFFFFUL), NULL);
|
||||
|
||||
zassert_equal(3, bacnet_unsigned_length(1UL <<16), NULL);
|
||||
zassert_equal(3, bacnet_unsigned_length(0x7DUL <<16), NULL);
|
||||
zassert_equal(3, bacnet_unsigned_length(0xFFUL <<16), NULL);
|
||||
zassert_equal(3, bacnet_unsigned_length(1UL << 16), NULL);
|
||||
zassert_equal(3, bacnet_unsigned_length(0x7DUL << 16), NULL);
|
||||
zassert_equal(3, bacnet_unsigned_length(0xFFUL << 16), NULL);
|
||||
zassert_equal(3, bacnet_unsigned_length(0xFFFFFFUL), NULL);
|
||||
|
||||
zassert_equal(4, bacnet_unsigned_length(1UL <<24), NULL);
|
||||
zassert_equal(4, bacnet_unsigned_length(0x7DUL <<24), NULL);
|
||||
zassert_equal(4, bacnet_unsigned_length(0xFFUL <<24), NULL);
|
||||
zassert_equal(4, bacnet_unsigned_length(1UL << 24), NULL);
|
||||
zassert_equal(4, bacnet_unsigned_length(0x7DUL << 24), NULL);
|
||||
zassert_equal(4, bacnet_unsigned_length(0xFFUL << 24), NULL);
|
||||
zassert_equal(4, bacnet_unsigned_length(0xFFFFFFFFUL), NULL);
|
||||
|
||||
#ifdef UINT64_MAX
|
||||
zassert_equal(5, bacnet_unsigned_length(1ULL <<32), NULL);
|
||||
zassert_equal(5, bacnet_unsigned_length(0x7DULL <<32), NULL);
|
||||
zassert_equal(5, bacnet_unsigned_length(0xFFULL <<32), NULL);
|
||||
zassert_equal(5, bacnet_unsigned_length(1ULL << 32), NULL);
|
||||
zassert_equal(5, bacnet_unsigned_length(0x7DULL << 32), NULL);
|
||||
zassert_equal(5, bacnet_unsigned_length(0xFFULL << 32), NULL);
|
||||
zassert_equal(5, bacnet_unsigned_length(0xFFFFFFFFFFULL), NULL);
|
||||
|
||||
zassert_equal(6, bacnet_unsigned_length(1ULL <<40), NULL);
|
||||
zassert_equal(6, bacnet_unsigned_length(0x7DULL <<40), NULL);
|
||||
zassert_equal(6, bacnet_unsigned_length(0xFFULL <<40), NULL);
|
||||
zassert_equal(6, bacnet_unsigned_length(1ULL << 40), NULL);
|
||||
zassert_equal(6, bacnet_unsigned_length(0x7DULL << 40), NULL);
|
||||
zassert_equal(6, bacnet_unsigned_length(0xFFULL << 40), NULL);
|
||||
zassert_equal(6, bacnet_unsigned_length(0xFFFFFFFFFFFFULL), NULL);
|
||||
|
||||
zassert_equal(7, bacnet_unsigned_length(1ULL <<48), NULL);
|
||||
zassert_equal(7, bacnet_unsigned_length(0x7DULL <<48), NULL);
|
||||
zassert_equal(7, bacnet_unsigned_length(0xFFULL <<48), NULL);
|
||||
zassert_equal(7, bacnet_unsigned_length(1ULL << 48), NULL);
|
||||
zassert_equal(7, bacnet_unsigned_length(0x7DULL << 48), NULL);
|
||||
zassert_equal(7, bacnet_unsigned_length(0xFFULL << 48), NULL);
|
||||
zassert_equal(7, bacnet_unsigned_length(0xFFFFFFFFFFFFFFULL), NULL);
|
||||
|
||||
zassert_equal(8, bacnet_unsigned_length(1ULL <<56), NULL);
|
||||
zassert_equal(8, bacnet_unsigned_length(0x7DULL <<56), NULL);
|
||||
zassert_equal(8, bacnet_unsigned_length(0xFFULL <<56), NULL);
|
||||
zassert_equal(8, bacnet_unsigned_length(1ULL << 56), NULL);
|
||||
zassert_equal(8, bacnet_unsigned_length(0x7DULL << 56), NULL);
|
||||
zassert_equal(8, bacnet_unsigned_length(0xFFULL << 56), NULL);
|
||||
zassert_equal(8, bacnet_unsigned_length(0xFFFFFFFFFFFFFFFFULL), NULL);
|
||||
#endif
|
||||
}
|
||||
@@ -731,7 +731,7 @@ static void test_signed8(void)
|
||||
/* Verify aligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(1, encode_signed8(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(1, decode_signed8(&apdu[2], &value), NULL);
|
||||
@@ -739,7 +739,7 @@ static void test_signed8(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(1, encode_signed8(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(1, decode_signed8(&apdu[2], &value), NULL);
|
||||
@@ -748,7 +748,7 @@ static void test_signed8(void)
|
||||
/* Verify unaligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(1, encode_signed8(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(1, decode_signed8(&apdu[3], &value), NULL);
|
||||
@@ -756,7 +756,7 @@ static void test_signed8(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(1, encode_signed8(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(1, decode_signed8(&apdu[3], &value), NULL);
|
||||
@@ -809,8 +809,8 @@ static void test_signed16(void)
|
||||
/* Verify aligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[3] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(2, encode_signed16(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(2, decode_signed16(&apdu[2], &value), NULL);
|
||||
@@ -818,8 +818,8 @@ static void test_signed16(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[3] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(2, encode_signed16(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(2, decode_signed16(&apdu[2], &value), NULL);
|
||||
@@ -828,8 +828,8 @@ static void test_signed16(void)
|
||||
/* Verify unaligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[4] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(2, encode_signed16(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(2, decode_signed16(&apdu[3], &value), NULL);
|
||||
@@ -837,8 +837,8 @@ static void test_signed16(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[4] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(2, encode_signed16(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(2, decode_signed16(&apdu[3], &value), NULL);
|
||||
@@ -887,9 +887,9 @@ static void test_signed24(void)
|
||||
/* Verify aligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >>16);
|
||||
test_apdu[3] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[4] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(3, encode_signed24(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(3, decode_signed24(&apdu[2], &value), NULL);
|
||||
@@ -897,9 +897,9 @@ static void test_signed24(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >>16);
|
||||
test_apdu[3] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[4] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(3, encode_signed24(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(3, decode_signed24(&apdu[2], &value), NULL);
|
||||
@@ -908,9 +908,9 @@ static void test_signed24(void)
|
||||
/* Verify unaligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >>16);
|
||||
test_apdu[4] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[5] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(3, encode_signed24(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(3, decode_signed24(&apdu[3], &value), NULL);
|
||||
@@ -918,9 +918,9 @@ static void test_signed24(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >>16);
|
||||
test_apdu[4] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[5] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(3, encode_signed24(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(3, decode_signed24(&apdu[3], &value), NULL);
|
||||
@@ -969,10 +969,10 @@ static void test_signed32(void)
|
||||
/* Verify aligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >>24);
|
||||
test_apdu[3] = (uint8_t) (test_value >>16);
|
||||
test_apdu[4] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[5] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(4, encode_signed32(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(4, decode_signed32(&apdu[2], &value), NULL);
|
||||
@@ -980,10 +980,10 @@ static void test_signed32(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[2] = (uint8_t) (test_value >>24);
|
||||
test_apdu[3] = (uint8_t) (test_value >>16);
|
||||
test_apdu[4] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[5] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[2] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(4, encode_signed32(&apdu[2], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(4, decode_signed32(&apdu[2], &value), NULL);
|
||||
@@ -992,10 +992,10 @@ static void test_signed32(void)
|
||||
/* Verify unaligned access with no extra bytes written */
|
||||
memset(test_apdu, ~0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >>24);
|
||||
test_apdu[4] = (uint8_t) (test_value >>16);
|
||||
test_apdu[5] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[6] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(4, encode_signed32(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(4, decode_signed32(&apdu[3], &value), NULL);
|
||||
@@ -1003,10 +1003,10 @@ static void test_signed32(void)
|
||||
|
||||
memset(test_apdu, 0U, sizeof(test_apdu));
|
||||
memcpy(apdu, test_apdu, sizeof(test_apdu));
|
||||
test_apdu[3] = (uint8_t) (test_value >>24);
|
||||
test_apdu[4] = (uint8_t) (test_value >>16);
|
||||
test_apdu[5] = (uint8_t) (test_value >> 8);
|
||||
test_apdu[6] = (uint8_t) (test_value >> 0);
|
||||
test_apdu[3] = (uint8_t)(test_value >> 24);
|
||||
test_apdu[4] = (uint8_t)(test_value >> 16);
|
||||
test_apdu[5] = (uint8_t)(test_value >> 8);
|
||||
test_apdu[6] = (uint8_t)(test_value >> 0);
|
||||
zassert_equal(4, encode_signed32(&apdu[3], test_value), NULL);
|
||||
zassert_mem_equal(test_apdu, apdu, sizeof(test_apdu), NULL);
|
||||
zassert_equal(4, decode_signed32(&apdu[3], &value), NULL);
|
||||
@@ -1051,27 +1051,19 @@ static void test_signed_length(void)
|
||||
#endif /* BACNET_USE_SIGNED */
|
||||
}
|
||||
|
||||
|
||||
#ifdef CONFIG_ZTEST_NEW_API
|
||||
ZTEST_SUITE(bacnet_bacint, NULL, NULL, NULL, NULL, NULL);
|
||||
#else
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(bacnet_bacint,
|
||||
ztest_unit_test(test_unsigned16),
|
||||
ztest_unit_test(test_unsigned24),
|
||||
ztest_unit_test(test_unsigned32),
|
||||
ztest_unit_test(test_unsigned40),
|
||||
ztest_unit_test(test_unsigned48),
|
||||
ztest_unit_test(test_unsigned56),
|
||||
ztest_unit_test(test_unsigned64),
|
||||
ztest_unit_test(test_unsigned_length),
|
||||
ztest_unit_test(test_signed8),
|
||||
ztest_unit_test(test_signed16),
|
||||
ztest_unit_test(test_signed24),
|
||||
ztest_unit_test(test_signed32),
|
||||
ztest_unit_test(test_signed_length)
|
||||
);
|
||||
ztest_test_suite(
|
||||
bacnet_bacint, ztest_unit_test(test_unsigned16),
|
||||
ztest_unit_test(test_unsigned24), ztest_unit_test(test_unsigned32),
|
||||
ztest_unit_test(test_unsigned40), ztest_unit_test(test_unsigned48),
|
||||
ztest_unit_test(test_unsigned56), ztest_unit_test(test_unsigned64),
|
||||
ztest_unit_test(test_unsigned_length), ztest_unit_test(test_signed8),
|
||||
ztest_unit_test(test_signed16), ztest_unit_test(test_signed24),
|
||||
ztest_unit_test(test_signed32), ztest_unit_test(test_signed_length));
|
||||
ztest_run_test_suite(bacnet_bacint);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
|
||||
#include <zephyr/ztest.h>
|
||||
|
||||
#undef BIT
|
||||
@@ -20,7 +19,6 @@
|
||||
|
||||
#include "bacnet/basic/sys/bits.h"
|
||||
|
||||
|
||||
/* NOTE: These tests must be compatible with C90, so they do not
|
||||
* verify support for ULL.
|
||||
*/
|
||||
@@ -34,7 +32,7 @@ static void test_BIT(void)
|
||||
unsigned int bitpos = sizeof(unsigned int) * 8;
|
||||
|
||||
do {
|
||||
bitpos -= 1;
|
||||
bitpos -= 1;
|
||||
zassert_true(BIT(bitpos) == (1U << bitpos), NULL);
|
||||
} while (bitpos > 0);
|
||||
}
|
||||
@@ -48,7 +46,7 @@ static void test__BV(void)
|
||||
unsigned int bitpos = sizeof(unsigned int) * 8;
|
||||
|
||||
do {
|
||||
bitpos -= 1;
|
||||
bitpos -= 1;
|
||||
zassert_true(BIT(bitpos) == (1U << bitpos), NULL);
|
||||
} while (bitpos > 0);
|
||||
}
|
||||
@@ -63,8 +61,8 @@ static void test_BIT_SET(void)
|
||||
|
||||
do {
|
||||
unsigned int a = 0U;
|
||||
bitpos -= 1;
|
||||
BIT_SET(a, bitpos);
|
||||
bitpos -= 1;
|
||||
BIT_SET(a, bitpos);
|
||||
zassert_true(a == (1U << bitpos), NULL);
|
||||
} while (bitpos > 0);
|
||||
}
|
||||
@@ -79,8 +77,8 @@ static void test_BIT_CLEAR(void)
|
||||
|
||||
do {
|
||||
unsigned int a = ~0U;
|
||||
bitpos -= 1;
|
||||
BIT_CLEAR(a, bitpos);
|
||||
bitpos -= 1;
|
||||
BIT_CLEAR(a, bitpos);
|
||||
zassert_true(~(a) == (1U << bitpos), NULL);
|
||||
} while (bitpos > 0);
|
||||
}
|
||||
@@ -95,16 +93,16 @@ static void test_BIT_FLIP(void)
|
||||
|
||||
do {
|
||||
unsigned int a = ~0U;
|
||||
bitpos -= 1;
|
||||
BIT_FLIP(a, bitpos);
|
||||
bitpos -= 1;
|
||||
BIT_FLIP(a, bitpos);
|
||||
zassert_true(a == ~(1U << bitpos), NULL);
|
||||
BIT_FLIP(a, bitpos);
|
||||
BIT_FLIP(a, bitpos);
|
||||
zassert_true(a == ~0U, NULL);
|
||||
|
||||
a = 0U;
|
||||
BIT_FLIP(a, bitpos);
|
||||
a = 0U;
|
||||
BIT_FLIP(a, bitpos);
|
||||
zassert_true(a == (1U << bitpos), NULL);
|
||||
BIT_FLIP(a, bitpos);
|
||||
BIT_FLIP(a, bitpos);
|
||||
zassert_true(a == 0U, NULL);
|
||||
|
||||
} while (bitpos > 0);
|
||||
@@ -120,11 +118,11 @@ static void test_BIT_CHECK(void)
|
||||
|
||||
do {
|
||||
unsigned int a = ~0U;
|
||||
bitpos -= 1;
|
||||
zassert_true(BIT_CHECK(a, bitpos), NULL);
|
||||
bitpos -= 1;
|
||||
zassert_true(BIT_CHECK(a, bitpos), NULL);
|
||||
|
||||
a = 0U;
|
||||
zassert_false(BIT_CHECK(a, bitpos), NULL);
|
||||
a = 0U;
|
||||
zassert_false(BIT_CHECK(a, bitpos), NULL);
|
||||
|
||||
} while (bitpos > 0);
|
||||
}
|
||||
@@ -139,8 +137,8 @@ static void test_BITMASK_SET(void)
|
||||
|
||||
do {
|
||||
unsigned int a = 0U;
|
||||
bitpos -= 1;
|
||||
BITMASK_SET(a, (1U << bitpos));
|
||||
bitpos -= 1;
|
||||
BITMASK_SET(a, (1U << bitpos));
|
||||
zassert_true(a == (1U << bitpos), NULL);
|
||||
} while (bitpos > 0);
|
||||
}
|
||||
@@ -155,8 +153,8 @@ static void test_BITMASK_CLEAR(void)
|
||||
|
||||
do {
|
||||
unsigned int a = ~0U;
|
||||
bitpos -= 1;
|
||||
BITMASK_CLEAR(a, (1U << bitpos));
|
||||
bitpos -= 1;
|
||||
BITMASK_CLEAR(a, (1U << bitpos));
|
||||
zassert_true(~(a) == (1U << bitpos), NULL);
|
||||
} while (bitpos > 0);
|
||||
}
|
||||
@@ -171,16 +169,16 @@ static void test_BITMASK_FLIP(void)
|
||||
|
||||
do {
|
||||
unsigned int a = ~0U;
|
||||
bitpos -= 1;
|
||||
BITMASK_FLIP(a, (1U << bitpos));
|
||||
bitpos -= 1;
|
||||
BITMASK_FLIP(a, (1U << bitpos));
|
||||
zassert_true(a == ~(1U << bitpos), NULL);
|
||||
BITMASK_FLIP(a, (1U << bitpos));
|
||||
BITMASK_FLIP(a, (1U << bitpos));
|
||||
zassert_true(a == ~0U, NULL);
|
||||
|
||||
a = 0U;
|
||||
BITMASK_FLIP(a, (1U << bitpos));
|
||||
a = 0U;
|
||||
BITMASK_FLIP(a, (1U << bitpos));
|
||||
zassert_true(a == (1U << bitpos), NULL);
|
||||
BITMASK_FLIP(a, (1U << bitpos));
|
||||
BITMASK_FLIP(a, (1U << bitpos));
|
||||
zassert_true(a == 0U, NULL);
|
||||
|
||||
} while (bitpos > 0);
|
||||
@@ -196,11 +194,11 @@ static void test_BITMASK_CHECK(void)
|
||||
|
||||
do {
|
||||
unsigned int a = ~0U;
|
||||
bitpos -= 1;
|
||||
zassert_true(BITMASK_CHECK(a, (1U << bitpos)), NULL);
|
||||
bitpos -= 1;
|
||||
zassert_true(BITMASK_CHECK(a, (1U << bitpos)), NULL);
|
||||
|
||||
a = 0U;
|
||||
zassert_false(BITMASK_CHECK(a, (1U << bitpos)), NULL);
|
||||
a = 0U;
|
||||
zassert_false(BITMASK_CHECK(a, (1U << bitpos)), NULL);
|
||||
|
||||
} while (bitpos > 0);
|
||||
}
|
||||
@@ -210,18 +208,13 @@ ZTEST_SUITE(bacnet_bits, NULL, NULL, NULL, NULL, NULL);
|
||||
#else
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(bacnet_bits,
|
||||
ztest_unit_test(test_BIT),
|
||||
ztest_unit_test(test__BV),
|
||||
ztest_unit_test(test_BIT_SET),
|
||||
ztest_unit_test(test_BIT_CLEAR),
|
||||
ztest_unit_test(test_BIT_FLIP),
|
||||
ztest_unit_test(test_BIT_CHECK),
|
||||
ztest_unit_test(test_BITMASK_SET),
|
||||
ztest_unit_test(test_BITMASK_CLEAR),
|
||||
ztest_unit_test(test_BITMASK_FLIP),
|
||||
ztest_unit_test(test_BITMASK_CHECK)
|
||||
);
|
||||
ztest_test_suite(
|
||||
bacnet_bits, ztest_unit_test(test_BIT), ztest_unit_test(test__BV),
|
||||
ztest_unit_test(test_BIT_SET), ztest_unit_test(test_BIT_CLEAR),
|
||||
ztest_unit_test(test_BIT_FLIP), ztest_unit_test(test_BIT_CHECK),
|
||||
ztest_unit_test(test_BITMASK_SET), ztest_unit_test(test_BITMASK_CLEAR),
|
||||
ztest_unit_test(test_BITMASK_FLIP),
|
||||
ztest_unit_test(test_BITMASK_CHECK));
|
||||
ztest_run_test_suite(bacnet_bits);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user