/* * Copyright (c) 2020 Legrand North America, LLC. * * SPDX-License-Identifier: MIT */ /* @file * @brief test BACnet integer encode/decode APIs */ #include #include #include /** * @addtogroup bacnet_tests * @{ */ /** * @brief Test */ #if defined(CONFIG_ZTEST_NEW_API) ZTEST(ms_input_tests, testMultistateInput) #else static void testMultistateInput(void) #endif { uint8_t apdu[MAX_APDU] = { 0 }; int len = 0, test_len = 0; BACNET_READ_PROPERTY_DATA rpdata = { 0 }; BACNET_APPLICATION_DATA_VALUE value = {0}; const int *pRequired = NULL; const int *pOptional = NULL; const int *pProprietary = NULL; unsigned count = 0; bool status = false; Multistate_Input_Init(); count = Multistate_Input_Count(); zassert_true(count > 0, NULL); rpdata.application_data = &apdu[0]; rpdata.application_data_len = sizeof(apdu); rpdata.object_type = OBJECT_MULTI_STATE_INPUT; rpdata.object_instance = Multistate_Input_Index_To_Instance(0); rpdata.array_index = BACNET_ARRAY_ALL; status = Multistate_Input_Valid_Instance(rpdata.object_instance); zassert_true(status, NULL); Multistate_Input_Property_Lists(&pRequired, &pOptional, &pProprietary); while ((*pRequired) >= 0) { rpdata.object_property = *pRequired; len = Multistate_Input_Read_Property(&rpdata); zassert_true(len >= 0, NULL); if (len >= 0) { test_len = bacapp_decode_known_property(rpdata.application_data, len, &value, rpdata.object_type, rpdata.object_property); if (len != test_len) { printf("property '%s': failed to decode!\n", bactext_property_name(rpdata.object_property)); } if (rpdata.object_property == PROP_PRIORITY_ARRAY) { /* FIXME: known fail to decode */ len = test_len; } zassert_equal(len, test_len, NULL); } else { printf("property '%s': failed to read!\n", bactext_property_name(rpdata.object_property)); } pRequired++; } while ((*pOptional) != -1) { rpdata.object_property = *pOptional; rpdata.array_index = BACNET_ARRAY_ALL; len = Multistate_Input_Read_Property(&rpdata); zassert_not_equal(len, BACNET_STATUS_ERROR, NULL); if (len > 0) { test_len = bacapp_decode_application_data(rpdata.application_data, (uint8_t)rpdata.application_data_len, &value); if (len != test_len) { printf("property '%s': failed to decode!\n", bactext_property_name(rpdata.object_property)); } zassert_true(test_len >= 0, NULL); } else { printf("property '%s': failed to read!\n", bactext_property_name(rpdata.object_property)); } pOptional++; } } /** * @} */ #if defined(CONFIG_ZTEST_NEW_API) ZTEST_SUITE(ms_input_tests, NULL, NULL, NULL, NULL, NULL); #else void test_main(void) { ztest_test_suite(ms_input_tests, ztest_unit_test(testMultistateInput) ); ztest_run_test_suite(ms_input_tests); } #endif