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:
Kari Argillander
2024-08-30 19:20:58 +03:00
committed by GitHub
parent 622a9e609e
commit f806c5829b
547 changed files with 18286 additions and 16575 deletions
+7 -4
View File
@@ -28,16 +28,19 @@ static int abort_decode_apdu(
{
int len = 0;
if (!apdu)
if (!apdu) {
return -1;
}
/* optional checking - most likely was already done prior to this call */
if (apdu_len > 0) {
if ((apdu[0] & 0xF0) != PDU_TYPE_ABORT)
if ((apdu[0] & 0xF0) != PDU_TYPE_ABORT) {
return -1;
if (apdu[0] & 1)
}
if (apdu[0] & 1) {
*server = true;
else
} else {
*server = false;
}
if (apdu_len > 1) {
len = abort_decode_service_request(
&apdu[1], apdu_len - 1, invoke_id, abort_reason);
+18 -9
View File
@@ -45,8 +45,10 @@ static void testAlarmAck(void)
data.eventStateAcked = EVENT_STATE_OFFNORMAL;
memset(&test_data, 0, sizeof(test_data));
apdu_len = bacnet_acknowledge_alarm_info_request_encode(apdu, sizeof(apdu), &data);
null_len = bacnet_acknowledge_alarm_info_request_encode(NULL, apdu_len, &data);
apdu_len =
bacnet_acknowledge_alarm_info_request_encode(apdu, sizeof(apdu), &data);
null_len =
bacnet_acknowledge_alarm_info_request_encode(NULL, apdu_len, &data);
zassert_equal(null_len, apdu_len, NULL);
test_len = alarm_ack_decode_service_request(apdu, apdu_len, &test_data);
@@ -93,8 +95,10 @@ static void testAlarmAck(void)
status = bacapp_timestamp_init_ascii(&data.eventTimeStamp, "2021/12/31");
zassert_true(status, NULL);
zassert_equal(data.eventTimeStamp.tag, TIME_STAMP_DATETIME, NULL);
apdu_len = bacnet_acknowledge_alarm_info_request_encode(apdu, sizeof(apdu), &data);
null_len = bacnet_acknowledge_alarm_info_request_encode(NULL, apdu_len, &data);
apdu_len =
bacnet_acknowledge_alarm_info_request_encode(apdu, sizeof(apdu), &data);
null_len =
bacnet_acknowledge_alarm_info_request_encode(NULL, apdu_len, &data);
zassert_equal(null_len, apdu_len, NULL);
test_len = alarm_ack_decode_service_request(apdu, apdu_len, &test_data);
zassert_equal(
@@ -103,20 +107,25 @@ static void testAlarmAck(void)
status = bacapp_timestamp_init_ascii(&data.eventTimeStamp, "1234");
zassert_true(status, NULL);
zassert_equal(data.eventTimeStamp.tag, TIME_STAMP_SEQUENCE, NULL);
apdu_len = bacnet_acknowledge_alarm_info_request_encode(apdu, sizeof(apdu), &data);
null_len = bacnet_acknowledge_alarm_info_request_encode(NULL, apdu_len, &data);
apdu_len =
bacnet_acknowledge_alarm_info_request_encode(apdu, sizeof(apdu), &data);
null_len =
bacnet_acknowledge_alarm_info_request_encode(NULL, apdu_len, &data);
zassert_equal(null_len, apdu_len, NULL);
test_len = alarm_ack_decode_service_request(apdu, apdu_len, &test_data);
zassert_equal(
apdu_len, test_len, "apdu_len=%d test_len=%d", apdu_len, test_len);
while (--apdu_len) {
test_len = bacnet_acknowledge_alarm_info_request_encode(apdu, apdu_len, &data);
zassert_equal(test_len, 0, "apdu_len=%d test_len=%d", apdu_len, test_len);
test_len =
bacnet_acknowledge_alarm_info_request_encode(apdu, apdu_len, &data);
zassert_equal(
test_len, 0, "apdu_len=%d test_len=%d", apdu_len, test_len);
}
apdu_len = null_len;
while (--apdu_len) {
test_len = alarm_ack_decode_service_request(apdu, apdu_len, &data);
zassert_true(test_len < 0, "apdu_len=%d test_len=%d", apdu_len, test_len);
zassert_true(
test_len < 0, "apdu_len=%d test_len=%d", apdu_len, test_len);
}
}
+2 -2
View File
@@ -100,8 +100,8 @@ static void testAtomicWriteFile(void)
return;
}
static void testAtomicWriteFileAckAccess(
const BACNET_ATOMIC_WRITE_FILE_DATA *data)
static void
testAtomicWriteFileAckAccess(const BACNET_ATOMIC_WRITE_FILE_DATA *data)
{
BACNET_ATOMIC_WRITE_FILE_DATA test_data = { 0 };
uint8_t apdu[480] = { 0 };
+3 -6
View File
@@ -1249,10 +1249,8 @@ static void test_bacapp_data(void)
/* 1. test encoding matches for NULL and APDU buffer */
BACNET_APPLICATION_TAG tag = tag_list[i];
value.tag = tag;
null_len =
bacapp_encode_application_data(NULL, &value);
apdu_len =
bacapp_encode_application_data(apdu, &value);
null_len = bacapp_encode_application_data(NULL, &value);
apdu_len = bacapp_encode_application_data(apdu, &value);
if (apdu_len != null_len) {
printf(
"bacapp: NULL len=%d != APDU len=%d for tag=%s", null_len,
@@ -1264,8 +1262,7 @@ static void test_bacapp_data(void)
test_len = 0;
len = encode_opening_tag(apdu, 3);
apdu_len += len;
len = bacapp_encode_application_data(
&apdu[apdu_len], &value);
len = bacapp_encode_application_data(&apdu[apdu_len], &value);
test_len += len;
apdu_len += len;
len = encode_closing_tag(&apdu[apdu_len], 3);
+10 -17
View File
@@ -1230,10 +1230,8 @@ static void testBACDCodeBitString(void)
null_len = encode_application_bitstring(NULL, &value);
zassert_equal(len, null_len, NULL);
/* decode */
len = bacnet_bitstring_application_decode(
apdu, null_len, &test_value);
zassert_equal(
bitstring_bits_used(&test_value), (bit + 1), NULL);
len = bacnet_bitstring_application_decode(apdu, null_len, &test_value);
zassert_equal(bitstring_bits_used(&test_value), (bit + 1), NULL);
zassert_true(bitstring_bit(&test_value, bit), NULL);
len = bacnet_tag_decode(apdu, len, &tag);
zassert_true(len > 0, NULL);
@@ -1247,26 +1245,22 @@ static void testBACDCodeBitString(void)
zassert_false(bitstring_bit(&value, bit), NULL);
/* encode */
len = bacnet_bitstring_application_encode(apdu, sizeof(apdu), &value);
null_len = bacnet_bitstring_application_encode(NULL, sizeof(apdu), &value);
null_len =
bacnet_bitstring_application_encode(NULL, sizeof(apdu), &value);
zassert_equal(len, null_len, NULL);
/* decode */
len = bacnet_bitstring_application_decode(
apdu, null_len, &test_value);
len = bacnet_bitstring_application_decode(apdu, null_len, &test_value);
len = bacnet_tag_decode(apdu, len, &tag);
zassert_true(len > 0, NULL);
zassert_equal(tag.number, BACNET_APPLICATION_TAG_BIT_STRING, NULL);
zassert_equal(
bitstring_bits_used(&test_value), (bit + 1), NULL);
zassert_equal(bitstring_bits_used(&test_value), (bit + 1), NULL);
zassert_false(bitstring_bit(&test_value, bit), NULL);
}
/* test APDU size limits */
apdu_len =
bacnet_bitstring_application_encode(apdu, sizeof(apdu), &value);
null_len =
bacnet_bitstring_application_encode(NULL, sizeof(apdu), &value);
apdu_len = bacnet_bitstring_application_encode(apdu, sizeof(apdu), &value);
null_len = bacnet_bitstring_application_encode(NULL, sizeof(apdu), &value);
zassert_equal(apdu_len, null_len, NULL);
test_len =
bacnet_bitstring_application_decode(apdu, apdu_len, &test_value);
test_len = bacnet_bitstring_application_decode(apdu, apdu_len, &test_value);
zassert_equal(
apdu_len, test_len, "test_len=%d apdu_len=%d", test_len, apdu_len);
zassert_true(bitstring_same(&value, &test_value), NULL);
@@ -1275,8 +1269,7 @@ static void testBACDCodeBitString(void)
zassert_equal(len, BACNET_STATUS_ERROR, NULL);
}
while (--apdu_len) {
len =
bacnet_bitstring_application_encode(apdu, apdu_len, &value);
len = bacnet_bitstring_application_encode(apdu, apdu_len, &value);
zassert_equal(len, 0, NULL);
}
}
+6 -5
View File
@@ -83,8 +83,8 @@ static void testBACnetDestination(void)
zassert_equal(apdu_len, null_len, NULL);
test_len = bacnet_destination_decode(apdu, apdu_len, &test_destination);
zassert_equal(apdu_len, test_len, NULL);
testBACnetRecipientData(&destination.Recipient,
&test_destination.Recipient);
testBACnetRecipientData(
&destination.Recipient, &test_destination.Recipient);
destination.Recipient.tag = BACNET_RECIPIENT_TAG_ADDRESS;
destination.Recipient.type.address.net = 1234;
@@ -151,11 +151,12 @@ static void test_BACnetDestination_ASCII(void)
if (null_len > 0) {
test_ascii = calloc(null_len, 1);
if (test_ascii) {
test_len =
bacnet_destination_to_ascii(&test_destination, test_ascii, null_len);
test_len = bacnet_destination_to_ascii(
&test_destination, test_ascii, null_len);
zassert_equal(null_len, test_len, NULL);
while (--test_len) {
len = bacnet_destination_to_ascii(&test_destination, test_ascii, test_len);
len = bacnet_destination_to_ascii(
&test_destination, test_ascii, test_len);
zassert_equal(len, null_len, NULL);
}
free(test_ascii);
+4 -2
View File
@@ -339,8 +339,9 @@ static void testBACnetSigned8(void)
test_value = ~0U;
len = decode_signed8(&apdu[0], &test_value);
zassert_equal(value, test_value, NULL);
if (value == 127)
if (value == 127) {
break;
}
}
}
@@ -376,8 +377,9 @@ static void testBACnetSigned16(void)
test_value = ~0U;
len = decode_signed16(&apdu[0], &test_value);
zassert_equal(value, test_value, NULL);
if (value == 32767)
if (value == 32767) {
break;
}
}
}
+6 -5
View File
@@ -53,7 +53,7 @@ static void test_BACnetTimeValue(BACNET_TIME_VALUE *value)
}
len = bacnet_time_value_context_encode(apdu, tag_number, value);
null_len = bacnet_time_value_context_encode(NULL,tag_number, value);
null_len = bacnet_time_value_context_encode(NULL, tag_number, value);
zassert_equal(len, null_len, NULL);
apdu_len =
bacnet_time_value_context_decode(apdu, len, tag_number, &test_value);
@@ -67,7 +67,8 @@ static void test_BACnetTimeValue(BACNET_TIME_VALUE *value)
zassert_true(status, NULL);
/* apdu too short testing */
while (--apdu_len) {
len = bacnet_time_value_context_decode(apdu, apdu_len, tag_number, &test_value);
len = bacnet_time_value_context_decode(
apdu, apdu_len, tag_number, &test_value);
zassert_true(len < 0, NULL);
}
/* negative testing */
@@ -162,11 +163,11 @@ static void test_BACnetTimeValues(void)
BACNET_APPLICATION_TAG_OBJECT_ID, "8:4194303", &value);
zassert_true(status, NULL);
rc = bacnet_application_to_primitive_data_value(&time_value.Value, &value);
zassert_equal(rc, BACNET_STATUS_ERROR ,"rc=%d", rc);
zassert_equal(rc, BACNET_STATUS_ERROR, "rc=%d", rc);
rc = bacnet_application_to_primitive_data_value(NULL, &value);
zassert_equal(rc, BACNET_STATUS_ERROR ,"rc=%d", rc);
zassert_equal(rc, BACNET_STATUS_ERROR, "rc=%d", rc);
rc = bacnet_application_to_primitive_data_value(&time_value.Value, NULL);
zassert_equal(rc, BACNET_STATUS_ERROR ,"rc=%d", rc);
zassert_equal(rc, BACNET_STATUS_ERROR, "rc=%d", rc);
rc = bacnet_primitive_to_application_data_value(NULL, &time_value.Value);
zassert_equal(rc, BACNET_STATUS_ERROR, NULL);
rc = bacnet_primitive_to_application_data_value(&value, NULL);
+1 -3
View File
@@ -41,9 +41,7 @@ static void testAnalogInput(void)
Analog_Input_Read_Property, Analog_Input_Write_Property,
skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Analog_Input_Name_Set,
Analog_Input_Name_ASCII);
object_instance, Analog_Input_Name_Set, Analog_Input_Name_ASCII);
status = Analog_Input_Delete(object_instance);
zassert_true(status, NULL);
}
+1 -3
View File
@@ -41,9 +41,7 @@ static void testAnalogOutput(void)
Analog_Output_Read_Property, Analog_Output_Write_Property,
skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Analog_Output_Name_Set,
Analog_Output_Name_ASCII);
object_instance, Analog_Output_Name_Set, Analog_Output_Name_ASCII);
status = Analog_Output_Delete(object_instance);
zassert_true(status, NULL);
}
+1 -3
View File
@@ -41,9 +41,7 @@ static void testAnalog_Value(void)
Analog_Value_Read_Property, Analog_Value_Write_Property,
skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Analog_Value_Name_Set,
Analog_Value_Name_ASCII);
object_instance, Analog_Value_Name_Set, Analog_Value_Name_ASCII);
status = Analog_Value_Delete(object_instance);
zassert_true(status, NULL);
}
+1 -3
View File
@@ -42,9 +42,7 @@ static void testBinaryInput(void)
Binary_Input_Read_Property, Binary_Input_Write_Property,
skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Binary_Input_Name_Set,
Binary_Input_Name_ASCII);
object_instance, Binary_Input_Name_Set, Binary_Input_Name_ASCII);
status = Binary_Input_Delete(object_instance);
zassert_true(status, NULL);
}
@@ -40,7 +40,7 @@ static void test_BitString_Value_Object(void)
zassert_true(status, NULL);
status = BitString_Value_Valid_Instance(instance);
zassert_true(status, NULL);
status = BitString_Value_Valid_Instance(instance+1);
status = BitString_Value_Valid_Instance(instance + 1);
zassert_false(status, NULL);
test_count = BitString_Value_Count();
zassert_equal(test_count, 1, NULL);
@@ -53,9 +53,7 @@ static void test_BitString_Value_Object(void)
BitString_Value_Read_Property, BitString_Value_Write_Property,
skip_fail_property_list);
bacnet_object_name_ascii_test(
instance,
BitString_Value_Name_Set,
BitString_Value_Name_ASCII);
instance, BitString_Value_Name_Set, BitString_Value_Name_ASCII);
/* test specific WriteProperty values */
BitString_Value_Write_Disable(instance);
status = BitString_Value_Write_Enabled(instance);
@@ -73,24 +71,24 @@ static void test_BitString_Value_Object(void)
wpdata.object_property = PROP_PRESENT_VALUE;
value.tag = BACNET_APPLICATION_TAG_BIT_STRING;
bitstring_init(&value.type.Bit_String);
wpdata.application_data_len = bacapp_encode_application_data(
wpdata.application_data, &value);
wpdata.application_data_len =
bacapp_encode_application_data(wpdata.application_data, &value);
status = BitString_Value_Write_Property(&wpdata);
zassert_true(status, NULL);
/* WP to out-of-service */
wpdata.object_property = PROP_OUT_OF_SERVICE;
value.tag = BACNET_APPLICATION_TAG_BOOLEAN;
value.type.Boolean = false;
wpdata.application_data_len = bacapp_encode_application_data(
wpdata.application_data, &value);
wpdata.application_data_len =
bacapp_encode_application_data(wpdata.application_data, &value);
status = BitString_Value_Write_Property(&wpdata);
zassert_true(status, NULL);
/* WP to status-flags - read-only */
wpdata.object_property = PROP_STATUS_FLAGS;
value.tag = BACNET_APPLICATION_TAG_BIT_STRING;
bitstring_init(&value.type.Bit_String);
wpdata.application_data_len = bacapp_encode_application_data(
wpdata.application_data, &value);
wpdata.application_data_len =
bacapp_encode_application_data(wpdata.application_data, &value);
status = BitString_Value_Write_Property(&wpdata);
zassert_false(status, NULL);
zassert_equal(wpdata.error_class, ERROR_CLASS_PROPERTY, NULL);
@@ -99,8 +97,8 @@ static void test_BitString_Value_Object(void)
wpdata.object_property = PROP_PRESENT_VALUE;
value.tag = BACNET_APPLICATION_TAG_BIT_STRING;
wpdata.array_index = 0;
wpdata.application_data_len = bacapp_encode_application_data(
wpdata.application_data, &value);
wpdata.application_data_len =
bacapp_encode_application_data(wpdata.application_data, &value);
status = BitString_Value_Write_Property(&wpdata);
zassert_false(status, NULL);
zassert_equal(wpdata.error_class, ERROR_CLASS_PROPERTY, NULL);
@@ -114,21 +112,21 @@ static void test_BitString_Value_Object(void)
zassert_false(status, NULL);
/* set same value */
BitString_Value_Change_Of_Value_Clear(instance);
status = BitString_Value_Present_Value_Set(instance,
&value.type.Bit_String);
status =
BitString_Value_Present_Value_Set(instance, &value.type.Bit_String);
zassert_true(status, NULL);
status = BitString_Value_Change_Of_Value(instance);
zassert_false(status, NULL);
/* set different value */
bitstring_set_bit(&value.type.Bit_String, 1, true);
status = BitString_Value_Present_Value_Set(instance,
&value.type.Bit_String);
status =
BitString_Value_Present_Value_Set(instance, &value.type.Bit_String);
zassert_true(status, NULL);
status = BitString_Value_Change_Of_Value(instance);
zassert_true(status, NULL);
/* COV */
cov_property_value_list_link(value_list,
sizeof(value_list)/sizeof(value_list[0]));
cov_property_value_list_link(
value_list, sizeof(value_list) / sizeof(value_list[0]));
status = BitString_Value_Encode_Value_List(instance, value_list);
zassert_true(status, NULL);
/* delete */
@@ -149,9 +147,9 @@ ZTEST_SUITE(bitstring_value_object_tests, NULL, NULL, NULL, NULL, NULL);
#else
void test_main(void)
{
ztest_test_suite(bitstring_value_object_tests,
ztest_unit_test(test_BitString_Value_Object)
);
ztest_test_suite(
bitstring_value_object_tests,
ztest_unit_test(test_BitString_Value_Object));
ztest_run_test_suite(bitstring_value_object_tests);
}
+1 -3
View File
@@ -41,9 +41,7 @@ static void testBinaryOutput(void)
Binary_Output_Read_Property, Binary_Output_Write_Property,
skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Binary_Output_Name_Set,
Binary_Output_Name_ASCII);
object_instance, Binary_Output_Name_Set, Binary_Output_Name_ASCII);
status = Binary_Output_Delete(object_instance);
zassert_true(status, NULL);
}
+1 -3
View File
@@ -43,9 +43,7 @@ static void testBinary_Value(void)
Binary_Value_Read_Property, Binary_Value_Write_Property,
skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Binary_Value_Name_Set,
Binary_Value_Name_ASCII);
object_instance, Binary_Value_Name_Set, Binary_Value_Name_ASCII);
status = Binary_Value_Delete(object_instance);
zassert_true(status, NULL);
}
+4 -2
View File
@@ -230,16 +230,18 @@ static void testPresentValue(void)
value->type.WeekNDay.weekofmonth = (date.day - 1) % 7 + 1;
zassert_true(Calendar_Present_Value(instance), NULL);
value->type.WeekNDay.weekofmonth++;
if (value->type.WeekNDay.weekofmonth > 5)
if (value->type.WeekNDay.weekofmonth > 5) {
value->type.WeekNDay.weekofmonth = 1;
}
zassert_false(Calendar_Present_Value(instance), NULL);
value->type.WeekNDay.weekofmonth = 0xff;
value->type.WeekNDay.dayofweek = date.wday;
zassert_true(Calendar_Present_Value(instance), NULL);
value->type.WeekNDay.dayofweek++;
if (value->type.WeekNDay.dayofweek > 7)
if (value->type.WeekNDay.dayofweek > 7) {
value->type.WeekNDay.dayofweek = 1;
}
zassert_false(Calendar_Present_Value(instance), NULL);
Calendar_Date_List_Delete_All(instance);
+4 -7
View File
@@ -255,8 +255,7 @@ static bool Test_Present_Value_Priority_Set(float value, unsigned priority)
* @param priority - priority-array index value 1..16
* @return true if values are within range and present-value is relinquished.
*/
static bool Test_Present_Value_Priority_Relinquish(
unsigned priority)
static bool Test_Present_Value_Priority_Relinquish(unsigned priority)
{
bool status = false;
@@ -615,8 +614,8 @@ static void testLoadControlStateMachine(void)
Load_Control_Present_Value(object_instance), BACNET_SHED_COMPLIANT,
NULL);
level = Test_Present_Value();
zassert_true(islessgreater(100.0f, level),
"Present Value = %f", (double)level);
zassert_true(
islessgreater(100.0f, level), "Present Value = %f", (double)level);
priority = Test_Present_Value_Priority();
zassert_equal(
Load_Control_Priority_For_Writing(object_instance), priority, NULL);
@@ -658,9 +657,7 @@ static void test_Load_Control_Read_Write_Property(void)
Load_Control_Read_Property, Load_Control_Write_Property,
skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Load_Control_Name_Set,
Load_Control_Name_ASCII);
object_instance, Load_Control_Name_Set, Load_Control_Name_ASCII);
test_teardown(object_instance);
}
-1
View File
@@ -55,7 +55,6 @@ static void testLifeSafetyZone(void)
zassert_equal(test_name, NULL, NULL);
/* cleanup */
status = Life_Safety_Zone_Delete(object_instance);
}
/**
* @}
+1 -2
View File
@@ -42,8 +42,7 @@ static void testMultistateInput(void)
Multistate_Input_Property_Lists, Multistate_Input_Read_Property,
Multistate_Input_Write_Property, skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Multistate_Input_Name_Set,
object_instance, Multistate_Input_Name_Set,
Multistate_Input_Name_ASCII);
status = Multistate_Input_Delete(object_instance);
zassert_true(status, NULL);
+1 -2
View File
@@ -41,8 +41,7 @@ static void testMultistateOutput(void)
Multistate_Output_Property_Lists, Multistate_Output_Read_Property,
Multistate_Output_Write_Property, skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Multistate_Output_Name_Set,
object_instance, Multistate_Output_Name_Set,
Multistate_Output_Name_ASCII);
status = Multistate_Output_Delete(object_instance);
zassert_true(status, NULL);
+1 -2
View File
@@ -42,8 +42,7 @@ static void testMultistateValue(void)
Multistate_Value_Property_Lists, Multistate_Value_Read_Property,
Multistate_Value_Write_Property, skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Multistate_Value_Name_Set,
object_instance, Multistate_Value_Name_Set,
Multistate_Value_Name_ASCII);
status = Multistate_Value_Delete(object_instance);
zassert_true(status, NULL);
+1 -2
View File
@@ -58,8 +58,7 @@ static void test_network_port(void)
Network_Port_Read_Property, Network_Port_Write_Property,
known_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Network_Port_Name_Set,
object_instance, Network_Port_Name_Set,
Network_Port_Object_Name_ASCII);
port++;
}
+1 -3
View File
@@ -27,9 +27,7 @@ static void testSchedule(void)
{
unsigned count = 0;
uint32_t object_instance = 0;
const int skip_fail_property_list[] = {
-1
};
const int skip_fail_property_list[] = { -1 };
Schedule_Init();
count = Schedule_Count();
@@ -41,9 +41,7 @@ static void test_object_structured_view(void)
OBJECT_STRUCTURED_VIEW, instance, Structured_View_Property_Lists,
Structured_View_Read_Property, NULL, skip_fail_property_list);
bacnet_object_name_ascii_test(
instance,
Structured_View_Name_Set,
Structured_View_Name_ASCII);
instance, Structured_View_Name_Set, Structured_View_Name_ASCII);
}
/**
* @}
@@ -31,8 +31,7 @@ bool datetime_local(
return true;
}
void datetime_timesync(
BACNET_DATE *bdate, BACNET_TIME *btime, bool utc)
void datetime_timesync(BACNET_DATE *bdate, BACNET_TIME *btime, bool utc)
{
if (bdate) {
datetime_copy_date(&BACnet_Date, bdate);
@@ -14,10 +14,9 @@
#include <bacnet/wp.h>
/* function API pattern for testing ASCII name get/set */
typedef bool (*object_name_ascii_set_function) (uint32_t object_instance,
const char *new_name);
typedef const char * (*object_name_ascii_function) (
uint32_t object_instance);
typedef bool (*object_name_ascii_set_function)(
uint32_t object_instance, const char *new_name);
typedef const char *(*object_name_ascii_function)(uint32_t object_instance);
void bacnet_object_name_ascii_test(
uint32_t object_instance,
@@ -41,9 +41,7 @@ static void testTimeValue(void)
Time_Value_Read_Property, Time_Value_Write_Property,
skip_fail_property_list);
bacnet_object_name_ascii_test(
object_instance,
Time_Value_Name_Set,
Time_Value_Name_ASCII);
object_instance, Time_Value_Name_Set, Time_Value_Name_ASCII);
/* check the delete function */
status = Time_Value_Delete(object_instance);
zassert_true(status, NULL);
+2 -1
View File
@@ -291,8 +291,9 @@ static void testKeyListLarge(void)
const unsigned num_keys = 1024 * 16;
list = Keylist_Create();
if (!list)
if (!list) {
return;
}
for (key = 0; key < num_keys; key++) {
data_list[key] = 42 + key;
+25 -15
View File
@@ -33,12 +33,14 @@ int ccov_notify_decode_apdu(
return -1;
}
/* optional checking - most likely was already done prior to this call */
if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST)
if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) {
return -2;
}
/* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */
*invoke_id = apdu[2]; /* invoke id - filled in by net layer */
if (apdu[3] != SERVICE_CONFIRMED_COV_NOTIFICATION)
if (apdu[3] != SERVICE_CONFIRMED_COV_NOTIFICATION) {
return -3;
}
offset = 4;
/* optional limits - must be used as a pair */
@@ -56,13 +58,16 @@ int ucov_notify_decode_apdu(
int len = 0;
unsigned offset = 0;
if (!apdu)
if (!apdu) {
return -1;
}
/* optional checking - most likely was already done prior to this call */
if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST)
if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST) {
return -2;
if (apdu[1] != SERVICE_UNCONFIRMED_COV_NOTIFICATION)
}
if (apdu[1] != SERVICE_UNCONFIRMED_COV_NOTIFICATION) {
return -3;
}
/* optional limits - must be used as a pair */
offset = 2;
if (apdu_len > offset) {
@@ -82,15 +87,18 @@ static int cov_subscribe_decode_apdu(
int len = 0;
unsigned offset = 0;
if (!apdu)
if (!apdu) {
return -1;
}
/* optional checking - most likely was already done prior to this call */
if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST)
if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) {
return -2;
}
/* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */
*invoke_id = apdu[2]; /* invoke id - filled in by net layer */
if (apdu[3] != SERVICE_CONFIRMED_SUBSCRIBE_COV)
if (apdu[3] != SERVICE_CONFIRMED_SUBSCRIBE_COV) {
return -3;
}
offset = 4;
/* optional limits - must be used as a pair */
@@ -111,15 +119,18 @@ static int cov_subscribe_property_decode_apdu(
int len = 0;
unsigned offset = 0;
if (!apdu)
if (!apdu) {
return -1;
}
/* optional checking - most likely was already done prior to this call */
if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST)
if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) {
return -2;
}
/* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */
*invoke_id = apdu[2]; /* invoke id - filled in by net layer */
if (apdu[3] != SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY)
if (apdu[3] != SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY) {
return -3;
}
offset = 4;
/* optional limits - must be used as a pair */
@@ -132,8 +143,8 @@ static int cov_subscribe_property_decode_apdu(
}
/* dummy function stubs */
static void testCOVNotifyData(
const BACNET_COV_DATA *data, BACNET_COV_DATA *test_data)
static void
testCOVNotifyData(const BACNET_COV_DATA *data, BACNET_COV_DATA *test_data)
{
const BACNET_PROPERTY_VALUE *value = NULL;
BACNET_PROPERTY_VALUE *test_value = NULL;
@@ -295,8 +306,7 @@ static void testCOVSubscribePropertyData(
}
}
static void
testCOVSubscribeEncoding(
static void testCOVSubscribeEncoding(
uint8_t invoke_id, const BACNET_SUBSCRIBE_COV_DATA *data)
{
uint8_t apdu[480] = { 0 };
+2 -2
View File
@@ -365,8 +365,8 @@ static void test_BVLC_Delete_Foreign_Device(void)
test_BVLC_Delete_Foreign_Device_Message(&fdt_entry);
}
static void test_BVLC_Secure_BVLL_Message(
const uint8_t *sbuf, uint16_t sbuf_len)
static void
test_BVLC_Secure_BVLL_Message(const uint8_t *sbuf, uint16_t sbuf_len)
{
uint8_t test_sbuf[50] = { 0 };
uint8_t pdu[60] = { 0 };
+2 -1
View File
@@ -96,7 +96,8 @@ bool bip6_set_broadcast_addr(const BACNET_IP6_ADDRESS *addr)
return ztest_get_return_value();
}
int bip6_send_mpdu(const BACNET_IP6_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len)
int bip6_send_mpdu(
const BACNET_IP6_ADDRESS *dest, const uint8_t *mtu, uint16_t mtu_len)
{
ztest_check_expected_value(dest);
ztest_check_expected_data(mtu, mtu_len);
+12 -8
View File
@@ -1103,23 +1103,27 @@ static void testZeroConfigNodeFSM(void)
station = 0;
test_station = Nmin_poll_station;
next_station = MSTP_Zero_Config_Station_Increment(station);
zassert_equal(next_station, test_station, "station=%u next_station=%u",
station, next_station);
zassert_equal(
next_station, test_station, "station=%u next_station=%u", station,
next_station);
station = Nmin_poll_station;
test_station = Nmin_poll_station + 1;
next_station = MSTP_Zero_Config_Station_Increment(station);
zassert_equal(next_station, test_station, "station=%u next_station=%u",
station, next_station);
zassert_equal(
next_station, test_station, "station=%u next_station=%u", station,
next_station);
station = Nmax_poll_station - 1;
test_station = Nmax_poll_station;
next_station = MSTP_Zero_Config_Station_Increment(station);
zassert_equal(next_station, test_station,"station=%u next_station=%u",
station, next_station);
zassert_equal(
next_station, test_station, "station=%u next_station=%u", station,
next_station);
station = Nmax_poll_station;
test_station = Nmin_poll_station;
next_station = MSTP_Zero_Config_Station_Increment(station);
zassert_equal(next_station, test_station, "station=%u next_station=%u",
station, next_station);
zassert_equal(
next_station, test_station, "station=%u next_station=%u", station,
next_station);
}
/**
+6 -3
View File
@@ -67,14 +67,17 @@ static int getevent_ack_decode_apdu(
int len = 0;
int offset = 0;
if (!apdu)
if (!apdu) {
return -1;
}
/* optional checking - most likely was already done prior to this call */
if (apdu[0] != PDU_TYPE_COMPLEX_ACK)
if (apdu[0] != PDU_TYPE_COMPLEX_ACK) {
return -1;
}
*invoke_id = apdu[1];
if (apdu[2] != SERVICE_CONFIRMED_GET_EVENT_INFORMATION)
if (apdu[2] != SERVICE_CONFIRMED_GET_EVENT_INFORMATION) {
return -1;
}
offset = 3;
if (apdu_len > offset) {
len = getevent_ack_decode_service_request(
+6 -3
View File
@@ -29,13 +29,16 @@ static int iam_decode_apdu(
int apdu_len = 0; /* total length of the apdu, return value */
/* valid data? */
if (!apdu)
if (!apdu) {
return -1;
}
/* optional checking - most likely was already done prior to this call */
if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST)
if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST) {
return -1;
if (apdu[1] != SERVICE_UNCONFIRMED_I_AM)
}
if (apdu[1] != SERVICE_UNCONFIRMED_I_AM) {
return -1;
}
apdu_len = iam_decode_service_request(
&apdu[2], pDevice_id, pMax_apdu, pSegmentation, pVendor_id);
+12 -12
View File
@@ -1,21 +1,21 @@
/**************************************************************************
*
* Copyright (c) 2022 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
*
* Copyright (c) 2022 Legrand North America, LLC.
*
* SPDX-License-Identifier: MIT
*
*********************************************************************/
/* ztest mock file */
#ifndef BACPORT_H
#define BACPORT_H
#define BACNET_OBJECT_TABLE(table_name, _type, _init, _count, \
_index_to_instance, _valid_instance, _object_name, \
_read_property, _write_property, _RPM_list, \
_RR_info, _iterator, _value_list, _COV, \
_COV_clear, _intrinsic_reporting) \
while{}(0)
#define BACNET_OBJECT_TABLE( \
table_name, _type, _init, _count, _index_to_instance, _valid_instance, \
_object_name, _read_property, _write_property, _RPM_list, _RR_info, \
_iterator, _value_list, _COV, _COV_clear, _intrinsic_reporting) \
while { } \
(0)
#endif
+18 -9
View File
@@ -30,16 +30,19 @@ static int ptransfer_decode_apdu(
int len = 0;
unsigned offset = 0;
if (!apdu)
if (!apdu) {
return -1;
}
/* optional checking - most likely was already done prior to this call */
if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST)
if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) {
return -1;
}
/* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */
/* invoke id - filled in by net layer */
*invoke_id = apdu[2];
if (apdu[3] != SERVICE_CONFIRMED_PRIVATE_TRANSFER)
if (apdu[3] != SERVICE_CONFIRMED_PRIVATE_TRANSFER) {
return -1;
}
offset = 4;
if (apdu_len > offset) {
@@ -86,14 +89,17 @@ static int ptransfer_ack_decode_apdu(
int len = 0;
int offset = 0;
if (!apdu)
if (!apdu) {
return -1;
}
/* optional checking - most likely was already done prior to this call */
if (apdu[0] != PDU_TYPE_COMPLEX_ACK)
if (apdu[0] != PDU_TYPE_COMPLEX_ACK) {
return -1;
}
*invoke_id = apdu[1];
if (apdu[2] != SERVICE_CONFIRMED_PRIVATE_TRANSFER)
if (apdu[2] != SERVICE_CONFIRMED_PRIVATE_TRANSFER) {
return -1;
}
offset = 3;
if (apdu_len > offset) {
len = ptransfer_decode_service_request(
@@ -114,14 +120,17 @@ static int ptransfer_error_decode_apdu(
int len = 0;
int offset = 0;
if (!apdu)
if (!apdu) {
return -1;
}
/* optional checking - most likely was already done prior to this call */
if (apdu[0] != PDU_TYPE_ERROR)
if (apdu[0] != PDU_TYPE_ERROR) {
return -1;
}
*invoke_id = apdu[1];
if (apdu[2] != SERVICE_CONFIRMED_PRIVATE_TRANSFER)
if (apdu[2] != SERVICE_CONFIRMED_PRIVATE_TRANSFER) {
return -1;
}
offset = 3;
if (apdu_len > offset) {
len = ptransfer_error_decode_service_request(
+4 -2
View File
@@ -28,12 +28,14 @@ static int reject_decode_apdu(
{
int len = 0;
if (!apdu)
if (!apdu) {
return -1;
}
/* optional checking - most likely was already done prior to this call */
if (apdu_len) {
if (apdu[0] != PDU_TYPE_REJECT)
if (apdu[0] != PDU_TYPE_REJECT) {
return -1;
}
if (apdu_len > 1) {
len = reject_decode_service_request(
&apdu[1], apdu_len - 1, invoke_id, reject_reason);
+20 -10
View File
@@ -28,20 +28,25 @@ static int rpm_ack_decode_apdu(
{
int offset = 0;
if (!apdu)
if (!apdu) {
return -1;
}
/* optional checking - most likely was already done prior to this call */
if (apdu[0] != PDU_TYPE_COMPLEX_ACK)
if (apdu[0] != PDU_TYPE_COMPLEX_ACK) {
return -1;
}
*invoke_id = apdu[1];
if (apdu[2] != SERVICE_CONFIRMED_READ_PROP_MULTIPLE)
if (apdu[2] != SERVICE_CONFIRMED_READ_PROP_MULTIPLE) {
return -1;
}
offset = 3;
if (apdu_len > offset) {
if (service_request)
if (service_request) {
*service_request = &apdu[offset];
if (service_request_len)
}
if (service_request_len) {
*service_request_len = apdu_len - offset;
}
}
return offset;
@@ -56,22 +61,27 @@ static int rpm_decode_apdu(
{
unsigned offset = 0;
if (!apdu)
if (!apdu) {
return -1;
}
/* optional checking - most likely was already done prior to this call */
if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST)
if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) {
return -1;
}
/* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */
*invoke_id = apdu[2]; /* invoke id - filled in by net layer */
if (apdu[3] != SERVICE_CONFIRMED_READ_PROP_MULTIPLE)
if (apdu[3] != SERVICE_CONFIRMED_READ_PROP_MULTIPLE) {
return -1;
}
offset = 4;
if (apdu_len > offset) {
if (service_request)
if (service_request) {
*service_request = &apdu[offset];
if (service_request_len)
}
if (service_request_len) {
*service_request_len = apdu_len - offset;
}
}
return offset;
+8 -5
View File
@@ -133,13 +133,16 @@ static int timesync_decode_apdu_service(
{
int len = 0;
if (!apdu)
if (!apdu) {
return -1;
}
/* optional checking - most likely was already done prior to this call */
if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST)
if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST) {
return -1;
if (apdu[1] != service)
}
if (apdu[1] != service) {
return -1;
}
/* optional limits - must be used as a pair */
if (apdu_len > 2) {
len = timesync_decode_service_request(
@@ -171,8 +174,8 @@ int timesync_decode_apdu(
my_time);
}
static void testTimeSyncData(
const BACNET_DATE *my_date, const BACNET_TIME *my_time)
static void
testTimeSyncData(const BACNET_DATE *my_date, const BACNET_TIME *my_time)
{
uint8_t apdu[480] = { 0 };
int len = 0;
+8 -5
View File
@@ -22,13 +22,16 @@ int whohas_decode_apdu(
{
int len = 0;
if (!apdu)
if (!apdu) {
return -1;
}
/* optional checking - most likely was already done prior to this call */
if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST)
if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST) {
return -1;
if (apdu[1] != SERVICE_UNCONFIRMED_WHO_HAS)
}
if (apdu[1] != SERVICE_UNCONFIRMED_WHO_HAS) {
return -1;
}
/* optional limits - must be used as a pair */
if (apdu_size > 2) {
len = whohas_decode_service_request(&apdu[2], apdu_size - 2, data);
@@ -82,7 +85,7 @@ static void testWhoHasData(BACNET_WHO_HAS_DATA *data)
/* test short APDU buffer */
while (--apdu_len) {
test_len = bacnet_who_has_service_request_encode(apdu, apdu_len, data);
zassert_equal(test_len, 0 , NULL);
zassert_equal(test_len, 0, NULL);
}
/* decoder bounds checking */
apdu_len = bacnet_who_has_request_encode(apdu, data);
@@ -93,7 +96,7 @@ static void testWhoHasData(BACNET_WHO_HAS_DATA *data)
/* test short APDU buffer */
while (--apdu_len) {
test_len = whohas_decode_service_request(apdu, apdu_len, data);
zassert_equal(test_len, BACNET_STATUS_ERROR , NULL);
zassert_equal(test_len, BACNET_STATUS_ERROR, NULL);
}
}
+2 -2
View File
@@ -17,8 +17,8 @@
/**
* @brief Decode service header for WritePropertyMultiple
*/
static int wpm_decode_apdu(
const uint8_t *apdu, unsigned apdu_len, uint8_t *invoke_id)
static int
wpm_decode_apdu(const uint8_t *apdu, unsigned apdu_len, uint8_t *invoke_id)
{
int len = 0;