From f3e8a1937f31a6fa8dbf6830e5354814ce75a4a5 Mon Sep 17 00:00:00 2001 From: mbanth Date: Tue, 25 May 2021 12:07:11 +0100 Subject: [PATCH] Add header tag and type tests --- tests/xua_unit_tests/src/test_hid.c | 62 +++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/xua_unit_tests/src/test_hid.c b/tests/xua_unit_tests/src/test_hid.c index 73fa95d3..beeef5a9 100644 --- a/tests/xua_unit_tests/src/test_hid.c +++ b/tests/xua_unit_tests/src/test_hid.c @@ -145,3 +145,65 @@ void test_unsupported_size_hidSetReportItem( void ) unsigned retVal = hidSetReportItem( byte, bit, header, NULL ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); } + +// Header tag and type tests +void test_bad_tag_hidSetReportItem( void ) +{ + const unsigned bit = 0; + const unsigned byte = 0; + const unsigned char good_header = construct_usage_header( 0x00 ); + + for( unsigned tag = 0x01; tag <= 0x0F; ++tag ) { + unsigned char bad_header = good_header | (( 0x0F << HID_REPORT_ITEM_HDR_TAG_SHIFT ) & HID_REPORT_ITEM_HDR_TAG_MASK ); + unsigned retVal = hidSetReportItem( byte, bit, bad_header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); + } +} + +void test_local_type_hidSetReportItem( void ) +{ + const unsigned bit = 0; + const unsigned byte = 0; + const unsigned char header = ( construct_usage_header( 0x00 ) & + ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | + (( 0x02 << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); + + unsigned retVal = hidSetReportItem( byte, bit, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); +} + +void test_global_type_hidSetReportItem( void ) +{ + const unsigned bit = 0; + const unsigned byte = 0; + const unsigned char header = ( construct_usage_header( 0x00 ) & + ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | + (( 0x01 << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); + + unsigned retVal = hidSetReportItem( byte, bit, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); +} + +void test_main_type_hidSetReportItem( void ) +{ + const unsigned bit = 0; + const unsigned byte = 0; + const unsigned char header = ( construct_usage_header( 0x00 ) & + ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | + (( 0x00 << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); + + unsigned retVal = hidSetReportItem( byte, bit, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); +} + +void test_reserved_type_hidSetReportItem( void ) +{ + const unsigned bit = 0; + const unsigned byte = 0; + const unsigned char header = ( construct_usage_header( 0x00 ) & + ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | + (( 0x03 << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); + + unsigned retVal = hidSetReportItem( byte, bit, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); +}