From 459ce6bd63c3fd2fb4c8b9af12afb9560ba0d4af Mon Sep 17 00:00:00 2001 From: Ciaran Woodward Date: Wed, 8 Dec 2021 17:55:33 +0000 Subject: [PATCH] Begin building up a set of multi-report unit tests This work is starting by expanding the tests written for single report purposes. I have also added a couple of extra simple tests that made sense (under/overflow of report IDs) as I went along. --- .../test_multi_report/hid_report_descriptor.h | 251 ++++++ .../test_multi_report/test_hid_multi_report.c | 728 ++++++++++++++++++ 2 files changed, 979 insertions(+) create mode 100644 tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h create mode 100644 tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c diff --git a/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h b/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h new file mode 100644 index 00000000..f524fcad --- /dev/null +++ b/tests/xua_unit_tests/src/test_multi_report/hid_report_descriptor.h @@ -0,0 +1,251 @@ +// Copyright 2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. + +#ifndef __hid_report_descriptor_h__ +#define __hid_report_descriptor_h__ + +#include "xua_hid_report_descriptor.h" + +#define REPORT1_MAX_VALID_BIT ( 3 ) +#define REPORT1_MAX_VALID_BYTE ( 0 ) +#define REPORT1_MIN_VALID_BIT ( 0 ) +#define REPORT1_MIN_VALID_BYTE ( 0 ) + +#define REPORT2_MAX_VALID_BIT ( 7 ) +#define REPORT2_MAX_VALID_BYTE ( 1 ) +#define REPORT2_MIN_VALID_BIT ( 0 ) +#define REPORT2_MIN_VALID_BYTE ( 0 ) + +#define REPORT3_MAX_VALID_BIT ( 1 ) +#define REPORT3_MAX_VALID_BYTE ( 0 ) +#define REPORT3_MIN_VALID_BIT ( 0 ) +#define REPORT3_MIN_VALID_BYTE ( 0 ) + +#define USB_HID_REPORT_ID_CONSUMER ( 0x02 ) +#define USB_HID_REPORT_ID_KEYBOARD ( 0x01 ) +#define USB_HID_REPORT_ID_TELEPHONY ( 0x03 ) + +#define USB_HID_USAGE_PAGE_ID_CONSUMER ( 0x0C ) +#define USB_HID_USAGE_PAGE_ID_KEYBOARD ( 0x07 ) +#define USB_HID_USAGE_PAGE_ID_TELEPHONY ( 0x0B ) + +/* + * Define non-configurable items in the HID Report descriptor. + * (These are short items as the location field isn't relevant for them) + */ +static const USB_HID_Short_Item_t hidCollectionApplication = { .header = 0xA1, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidCollectionEnd = { .header = 0xC0, .data = { 0x00, 0x00 }}; +static const USB_HID_Short_Item_t hidCollectionLogical = { .header = 0xA1, .data = { 0x02, 0x00 }}; + +static const USB_HID_Short_Item_t hidInputConstArray = { .header = 0x81, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidInputDataVar = { .header = 0x81, .data = { 0x02, 0x00 }}; + +static const USB_HID_Short_Item_t hidLogicalMaximum0 = { .header = 0x25, .data = { 0x00, 0x00 }}; +static const USB_HID_Short_Item_t hidLogicalMaximum1 = { .header = 0x25, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidLogicalMinimum0 = { .header = 0x15, .data = { 0x00, 0x00 }}; + +static const USB_HID_Short_Item_t hidReportCount1 = { .header = 0x95, .data = { 0x01, 0x00 }}; +static const USB_HID_Short_Item_t hidReportCount4 = { .header = 0x95, .data = { 0x04, 0x00 }}; +static const USB_HID_Short_Item_t hidReportCount6 = { .header = 0x95, .data = { 0x06, 0x00 }}; +static const USB_HID_Short_Item_t hidReportSize1 = { .header = 0x75, .data = { 0x01, 0x00 }}; + +static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09, .data = { 0x01, 0x00 }}; + +/* + * Define the HID Report Descriptor Item, Usage Page, Report ID and length for each HID Report + * For internal purposes, a report element with ID of 0 must be included if report IDs are not being used. + */ +static const USB_HID_Short_Item_t hidReportId1 = { .header = 0x85, .data = { USB_HID_USAGE_PAGE_ID_KEYBOARD, 0x00 }}; +static const USB_HID_Short_Item_t hidReportId2 = { .header = 0x85, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }}; +static const USB_HID_Short_Item_t hidReportId3 = { .header = 0x85, .data = { USB_HID_USAGE_PAGE_ID_TELEPHONY, 0x00 }}; + +static const USB_HID_Report_Element_t hidReportKeyboard = { + .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_KEYBOARD, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_KEYBOARD, 1, 0, 0 ) +}; + +static const USB_HID_Report_Element_t hidReportConsumer = { + .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 2, 0, 0 ) +}; + +static const USB_HID_Report_Element_t hidReportTelephony = { + .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_TELEPHONY, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_TELEPHONY, 1, 0, 0 ) +}; + +static USB_HID_Report_Element_t hidUsageReport1Byte0Bit0 = { + .item = { .header = 0x09, .data = { 0x17, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_KEYBOARD, 0, 0, 0 ) +}; // 't' + +static USB_HID_Report_Element_t hidUsageReport1Byte0Bit2 = { + .item = { .header = 0x09, .data = { 0x72, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_KEYBOARD, 0, 0, 2 ) +}; // F23 + +static USB_HID_Report_Element_t hidUsageReport1Byte0Bit3 = { + .item = { .header = 0x09, .data = { 0x73, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_KEYBOARD, 0, 0, 3 ) +}; // F24 + +static USB_HID_Report_Element_t hidUsageReport2Byte0Bit0 = { + .item = { .header = 0x0A, .data = { 0x26, 0x02 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 0 ) +}; // AC Stop + +static USB_HID_Report_Element_t hidUsageReport2Byte0Bit1 = { + .item = { .header = 0x0A, .data = { 0x21, 0x02 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 1 ) +}; // AC Search + +static USB_HID_Report_Element_t hidUsageReport2Byte0Bit2 = { + .item = { .header = 0x09, .data = { 0xE2, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 2 ) +}; // Mute + +static USB_HID_Report_Element_t hidUsageReport2Byte0Bit4 = { + .item = { .header = 0x09, .data = { 0xCF, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 4 ) +}; // Voice Command + +static USB_HID_Report_Element_t hidUsageReport2Byte0Bit6 = { + .item = { .header = 0x09, .data = { 0xE9, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 6 ) +}; // Vol+ + +static USB_HID_Report_Element_t hidUsageReport2Byte0Bit7 = { + .item = { .header = 0x09, .data = { 0xEA, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 0, 7 ) +}; // Vol- + +static USB_HID_Report_Element_t hidUsageReport2Byte1Bit7 = { + .item = { .header = 0x09, .data = { 0xE5, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_CONSUMER, 0, 1, 7 ) +}; // Bass boost + +static USB_HID_Report_Element_t hidUsageReport3Byte0Bit0 = { + .item = { .header = 0x09, .data = { 0x20, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_TELEPHONY, 0, 0, 0 ) +}; // Hook Switch + +static USB_HID_Report_Element_t hidUsageReport3Byte0Bit1 = { + .item = { .header = 0x09, .data = { 0x2F, 0x00 }}, + .location = HID_REPORT_SET_LOC( USB_HID_REPORT_ID_TELEPHONY, 0, 0, 1 ) +}; // Phone Mute + +/* + * List the configurable elements in the HID Report. + */ +static USB_HID_Report_Element_t* const hidConfigurableElements[] = { + &hidUsageReport1Byte0Bit0, + &hidUsageReport1Byte0Bit2, + &hidUsageReport1Byte0Bit3, + + &hidUsageReport2Byte0Bit0, + &hidUsageReport2Byte0Bit1, + &hidUsageReport2Byte0Bit2, + &hidUsageReport2Byte0Bit4, + &hidUsageReport2Byte0Bit6, + &hidUsageReport2Byte0Bit7, + &hidUsageReport2Byte1Bit7, + + &hidUsageReport3Byte0Bit0, + &hidUsageReport3Byte0Bit1 +}; + +/* + * List HID Reports, one per Report ID. This should be a usage page item with the relevant + * If not using report IDs - still have one with report ID 0 + */ +static const USB_HID_Report_Element_t* const hidReports[] = { + &hidReportKeyboard, + &hidReportConsumer, + &hidReportTelephony +}; + +/* + * List all items in the HID Report descriptor. + */ +static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = { + &(hidReportConsumer.item), + &hidUsageConsumerControl, + &hidCollectionApplication, + &hidReportSize1, + &hidLogicalMinimum0, + &hidCollectionLogical, // Report 1 + &hidReportId1, + &(hidReportKeyboard.item), + &hidLogicalMaximum1, + &hidReportCount1, + &(hidUsageReport1Byte0Bit0.item), + &hidInputDataVar, + &hidLogicalMaximum0, + &hidInputConstArray, + &hidLogicalMaximum1, + &(hidUsageReport1Byte0Bit2.item), + &hidInputDataVar, + &(hidUsageReport1Byte0Bit3.item), + &hidInputDataVar, + &hidLogicalMaximum0, + &hidReportCount4, + &hidInputConstArray, + &hidCollectionEnd, + &hidCollectionLogical, // Report 2 + &hidReportId2, + &(hidReportConsumer.item), + &hidLogicalMaximum1, + &hidReportCount1, + &(hidUsageReport2Byte0Bit0.item), + &hidInputDataVar, + &(hidUsageReport2Byte0Bit1.item), + &hidInputDataVar, + &(hidUsageReport2Byte0Bit2.item), + &hidInputDataVar, + &hidLogicalMaximum0, + &hidInputConstArray, + &hidLogicalMaximum1, + &(hidUsageReport2Byte0Bit4.item), + &hidInputDataVar, + &hidLogicalMaximum0, + &hidInputConstArray, + &hidLogicalMaximum1, + &(hidUsageReport2Byte0Bit6.item), + &hidInputDataVar, + &(hidUsageReport2Byte0Bit7.item), + &hidInputDataVar, + &hidLogicalMaximum0, + &hidReportCount6, + &hidInputConstArray, + &hidLogicalMaximum1, + &(hidUsageReport2Byte1Bit7.item), + &hidInputDataVar, + &hidCollectionEnd, + &hidCollectionLogical, // Report 3 + &hidReportId3, + &(hidReportTelephony.item), + &(hidUsageReport3Byte0Bit0.item), + &hidInputDataVar, + &(hidUsageReport3Byte0Bit1.item), + &hidInputDataVar, + &hidLogicalMaximum0, + &hidReportCount6, + &hidInputConstArray, + &hidCollectionEnd, + &hidCollectionEnd +}; + +/* + * Define the length of the HID Report. + * This value must match the number of Report bytes defined by hidReportDescriptorItems. + */ +#define HID_REPORT_LENGTH ( 3 ) + +/* + * Define the number of HID Reports + * Due to XC not supporting designated initializers, this constant has a hard-coded value. + * It must equal ( sizeof hidReports / sizeof ( USB_HID_Report_Element_t* )) + */ +#define HID_REPORT_COUNT ( 3 ) + +#endif // __hid_report_descriptor_h__ diff --git a/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c new file mode 100644 index 00000000..f225a212 --- /dev/null +++ b/tests/xua_unit_tests/src/test_multi_report/test_hid_multi_report.c @@ -0,0 +1,728 @@ +// Copyright 2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. +#include +#include + +#include "xua_unit_tests.h" +#include "xua_hid_report_descriptor.h" +#include "hid_report_descriptor.h" + +#define HID_REPORT_ITEM_TYPE_GLOBAL ( 0x01 ) +#define HID_REPORT_ITEM_TYPE_LOCAL ( 0x02 ) +#define HID_REPORT_ITEM_TYPE_MAIN ( 0x00 ) +#define HID_REPORT_ITEM_TYPE_RESERVED ( 0x03 ) + +#define KEYBOARD_PAGE ( 0x07 ) +#define CONSUMER_PAGE ( 0x0C ) +#define TELEPHONY_DEVICE_PAGE ( 0x0B ) +#define LOUDNESS_CONTROL ( 0xE7 ) +#define AL_CONTROL_PANEL ( 0x019F ) + +static unsigned construct_usage_header( unsigned size ) +{ + unsigned header = 0x00; + + header |= ( HID_REPORT_ITEM_USAGE_TAG << HID_REPORT_ITEM_HDR_TAG_SHIFT ) & HID_REPORT_ITEM_HDR_TAG_MASK; + header |= ( HID_REPORT_ITEM_USAGE_TYPE << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK; + + header |= ( size << HID_REPORT_ITEM_HDR_SIZE_SHIFT ) & HID_REPORT_ITEM_HDR_SIZE_MASK; + + return header; +} + +void setUp( void ) +{ + hidResetReportDescriptor(); +} + +// Basic report descriptor tests +void test_unprepared_hidGetReportDescriptor( void ) +{ + unsigned char* reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NULL( reportDescPtr ); + + for (unsigned reportId = 1; reportId <= HID_REPORT_COUNT; reportId++) + { + unsigned reportLength = hidGetReportLength( reportId ); + TEST_ASSERT_EQUAL_UINT( 0, reportLength ); + } +} + +void test_prepared_hidGetReportDescriptor( void ) +{ + hidPrepareReportDescriptor(); + unsigned char* reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NOT_NULL( reportDescPtr ); + + unsigned reportId = 1; + unsigned reportLength = hidGetReportLength( reportId ); + TEST_ASSERT_EQUAL_UINT( 1, reportLength ); + + reportId = 2; + reportLength = hidGetReportLength( reportId ); + TEST_ASSERT_EQUAL_UINT( 2, reportLength ); + + reportId = 3; + reportLength = hidGetReportLength( reportId ); + TEST_ASSERT_EQUAL_UINT( 1, reportLength ); +} + +void test_reset_unprepared_hidGetReportDescriptor( void ) +{ + hidPrepareReportDescriptor(); + hidResetReportDescriptor(); + unsigned char* reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NULL( reportDescPtr ); +} + +void test_reset_prepared_hidGetReportDescriptor( void ) +{ + hidPrepareReportDescriptor(); + hidResetReportDescriptor(); + hidPrepareReportDescriptor(); + unsigned char* reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NOT_NULL( reportDescPtr ); +} + +// Basic item tests +void test_max_loc_hidGetReportItem( void ) +{ + unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ]; + unsigned char header; + unsigned char page; + + unsigned reportId = 1; + unsigned bit = REPORT1_MAX_VALID_BIT; + unsigned byte = REPORT1_MAX_VALID_BYTE; + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + TEST_ASSERT_EQUAL_UINT( KEYBOARD_PAGE, page ); + TEST_ASSERT_EQUAL_UINT( 0x09, header ); + TEST_ASSERT_EQUAL_UINT( 0x73, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]); + + reportId = 2; + bit = REPORT2_MAX_VALID_BIT; + byte = REPORT2_MAX_VALID_BYTE; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + TEST_ASSERT_EQUAL_UINT( CONSUMER_PAGE, page ); + TEST_ASSERT_EQUAL_UINT( 0x09, header ); + TEST_ASSERT_EQUAL_UINT( 0xE5, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]); + + reportId = 3; + bit = REPORT3_MAX_VALID_BIT; + byte = REPORT3_MAX_VALID_BYTE; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + TEST_ASSERT_EQUAL_UINT( TELEPHONY_DEVICE_PAGE, page ); + TEST_ASSERT_EQUAL_UINT( 0x09, header ); + TEST_ASSERT_EQUAL_UINT( 0x2F, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]); +} + + +void test_min_loc_hidGetReportItem( void ) +{ + unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ]; + unsigned char header; + unsigned char page; + + unsigned reportId = 1; + unsigned bit = REPORT1_MIN_VALID_BIT; + unsigned byte = REPORT1_MIN_VALID_BYTE; + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + TEST_ASSERT_EQUAL_UINT( KEYBOARD_PAGE, page ); + TEST_ASSERT_EQUAL_UINT( 0x09, header ); + TEST_ASSERT_EQUAL_UINT( 0x17, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]); + + reportId = 2; + bit = REPORT2_MIN_VALID_BIT; + byte = REPORT2_MIN_VALID_BYTE; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + TEST_ASSERT_EQUAL_UINT( CONSUMER_PAGE, page ); + TEST_ASSERT_EQUAL_UINT( 0x0A, header ); + TEST_ASSERT_EQUAL_UINT( 0x26, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0x02, data[ 1 ]); + + reportId = 3; + bit = REPORT3_MIN_VALID_BIT; + byte = REPORT3_MIN_VALID_BYTE; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + TEST_ASSERT_EQUAL_UINT( TELEPHONY_DEVICE_PAGE, page ); + TEST_ASSERT_EQUAL_UINT( 0x09, header ); + TEST_ASSERT_EQUAL_UINT( 0x20, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0x00, data[ 1 ]); +} + +void test_invalid_report_id( void ) +{ + unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD2 }; + unsigned char header = 0x33; + unsigned char page = 0x44; + + unsigned reportId = 0; + unsigned bit = REPORT1_MIN_VALID_BIT; + unsigned byte = REPORT1_MIN_VALID_BYTE; + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_ID, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0x33, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD2, data[ 1 ]); +} + +void test_unused_report_id( void ) +{ + unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD2 }; + unsigned char header = 0x33; + unsigned char page = 0x44; + + unsigned reportId = 8; + unsigned bit = REPORT1_MIN_VALID_BIT; + unsigned byte = REPORT1_MIN_VALID_BYTE; + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_ID, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0x33, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD2, data[ 1 ]); +} + +void test_overflow_bit_hidGetReportItem( void ) +{ + unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 }; + unsigned char header = 0xAA; + unsigned char page = 0x44; + + unsigned reportId = 1; + unsigned bit = REPORT1_MAX_VALID_BIT + 1; + unsigned byte = REPORT1_MAX_VALID_BYTE; + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); + + reportId = 2; + bit = REPORT2_MAX_VALID_BIT + 1; + byte = REPORT2_MAX_VALID_BYTE; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); + + reportId = 3; + bit = REPORT3_MAX_VALID_BIT + 1; + byte = REPORT3_MAX_VALID_BYTE; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); +} + +void test_overflow_byte_hidGetReportItem( void ) +{ + unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 }; + unsigned char header = 0xAA; + unsigned char page = 0x44; + + unsigned reportId = 1; + unsigned bit = REPORT1_MAX_VALID_BIT; + unsigned byte = REPORT1_MAX_VALID_BYTE + 1; + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); + + reportId = 2; + bit = REPORT2_MAX_VALID_BIT; + byte = REPORT2_MAX_VALID_BYTE + 1; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); + + reportId = 3; + bit = REPORT3_MAX_VALID_BIT; + byte = REPORT3_MAX_VALID_BYTE + 1; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); +} + +void test_underflow_bit_hidGetReportItem( void ) +{ + unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 }; + unsigned char header = 0xAA; + unsigned char page = 0x44; + + unsigned reportId = 1; + unsigned bit = REPORT1_MIN_VALID_BIT - 1; + unsigned byte = REPORT1_MIN_VALID_BYTE; + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); + + reportId = 2; + bit = REPORT2_MIN_VALID_BIT - 1; + byte = REPORT2_MIN_VALID_BYTE; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); + + reportId = 3; + bit = REPORT3_MIN_VALID_BIT - 1; + byte = REPORT3_MIN_VALID_BYTE; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); +} + +void test_underflow_byte_hidGetReportItem( void ) +{ + unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 }; + unsigned char header = 0xAA; + unsigned char page = 0x44; + + unsigned reportId = 1; + unsigned bit = REPORT1_MIN_VALID_BIT; + unsigned byte = REPORT1_MIN_VALID_BYTE - 1; + unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); + + reportId = 2; + bit = REPORT2_MIN_VALID_BIT; + byte = REPORT2_MIN_VALID_BYTE - 1; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); + + reportId = 3; + bit = REPORT3_MIN_VALID_BIT; + byte = REPORT3_MIN_VALID_BYTE - 1; + retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); + TEST_ASSERT_EQUAL_UINT( 0x44, page ); + TEST_ASSERT_EQUAL_UINT( 0xAA, header ); + TEST_ASSERT_EQUAL_UINT( 0xBA, data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0xD1, data[ 1 ]); +} + +#if 0 +//here + +// Configurable and non-configurable item tests +void xtest_configurable_item_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; + const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); +} + +void xtest_nonconfigurable_item_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MAX_VALID_BIT; // This bit and byte combination should not appear in the + const unsigned byte = MIN_VALID_BYTE; // hidConfigurableElements list in hid_report_descriptors.c. + const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; + const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); +} + +// Bit range tests +void xtest_max_bit_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MAX_VALID_BIT; // Only byte 1 has bit 7 not reserved, See the + const unsigned byte = MAX_VALID_BYTE; // hidConfigurableElements list in hid_report_descriptors.c. + const unsigned char header = construct_usage_header( 0 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); +} + +void xtest_min_bit_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = construct_usage_header( 0 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); +} + +void xtest_overflow_bit_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MAX_VALID_BIT + 1; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = construct_usage_header( 0 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); +} + +void xtest_underflow_bit_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const int bit = MIN_VALID_BIT - 1; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = construct_usage_header( 0 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, ( unsigned ) bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); +} + +// Byte range tests +void xtest_max_byte_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MAX_VALID_BYTE; + const unsigned char header = construct_usage_header( 0 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); +} + +void xtest_min_byte_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = construct_usage_header( 0 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); +} + +void xtest_overflow_byte_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MAX_VALID_BYTE + 1; + const unsigned char header = construct_usage_header( 0 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); +} + +void xtest_underflow_byte_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const int byte = MIN_VALID_BYTE - 1; + const unsigned char header = construct_usage_header( 0 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, ( unsigned ) byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); +} + +// Size range tests +void xtest_max_size_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0x00 }; + const unsigned char header = construct_usage_header( HID_REPORT_ITEM_MAX_SIZE ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); +} + +void xtest_min_size_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = construct_usage_header( 0x00 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); +} + +void xtest_unsupported_size_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = construct_usage_header( 0x03 ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); +} + +// Header tag and type tests +void xtest_bad_tag_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char good_header = construct_usage_header( 0x00 ); + const unsigned char page = CONSUMER_PAGE; + + 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( reportId, byte, bit, page, bad_header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); + } +} + +void xtest_global_type_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | + (( HID_REPORT_ITEM_TYPE_GLOBAL << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); +} + +void xtest_local_type_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | + (( HID_REPORT_ITEM_TYPE_LOCAL << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); +} + +void xtest_main_type_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | + (( HID_REPORT_ITEM_TYPE_MAIN << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); +} + +void xtest_reserved_type_hidSetReportItem( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | + (( HID_REPORT_ITEM_TYPE_RESERVED << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK ); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); +} + +// Combined function tests +void xtest_initial_modification_without_subsequent_preparation( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; + const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + + unsigned char* reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NULL( reportDescPtr ); +} + +void xtest_initial_modification_with_subsequent_preparation( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; + const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); + const unsigned char page = CONSUMER_PAGE; + + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + + hidPrepareReportDescriptor(); + unsigned char* reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NOT_NULL( reportDescPtr ); +} + +void xtest_initial_modification_with_subsequent_verification_1( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + + unsigned char get_data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xFF, 0xFF }; + unsigned char get_header = 0xFF; + unsigned char get_page = 0xFF; + + const unsigned char set_data[ 1 ] = { LOUDNESS_CONTROL }; + const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char )); + const unsigned char set_page = CONSUMER_PAGE; + + unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal ); + + unsigned getRetVal = hidGetReportItem( reportId, byte, bit, &get_page, &get_header, get_data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal ); + TEST_ASSERT_EQUAL_UINT( set_page, get_page ); + TEST_ASSERT_EQUAL_UINT( set_header, get_header ); + TEST_ASSERT_EQUAL_UINT( set_data[ 0 ], get_data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0, get_data[ 1 ]); // Should be MSB of data from hidUsageByte0Bit0 in hid_report_descriptor.h +} + +void xtest_initial_modification_with_subsequent_verification_2( void ) +{ + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + + { + unsigned char get_data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xFF, 0xFF }; + unsigned char get_header = 0xFF; + unsigned char get_page = 0xFF; + + const unsigned char set_data[ 2 ] = {( AL_CONTROL_PANEL & 0x00FF ), (( AL_CONTROL_PANEL & 0xFF00 ) >> 8 )}; + const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char )); + const unsigned char set_page = CONSUMER_PAGE; + + unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal ); + + unsigned getRetVal = hidGetReportItem( reportId, byte, bit, &get_page, &get_header, get_data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal ); + TEST_ASSERT_EQUAL_UINT( set_page, get_page ); + TEST_ASSERT_EQUAL_UINT( set_header, get_header ); + TEST_ASSERT_EQUAL_UINT( set_data[ 0 ], get_data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( set_data[ 1 ], get_data[ 1 ]); + } + + { + unsigned char get_data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xFF, 0xFF }; + unsigned char get_header = 0xFF; + unsigned char get_page = 0xFF; + + const unsigned char set_data[ 1 ] = { LOUDNESS_CONTROL }; + const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char )); + const unsigned char set_page = CONSUMER_PAGE; + + unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal ); + + unsigned getRetVal = hidGetReportItem( reportId, byte, bit, &get_page, &get_header, get_data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal ); + TEST_ASSERT_EQUAL_UINT( set_page, get_page ); + TEST_ASSERT_EQUAL_UINT( set_header, get_header ); + TEST_ASSERT_EQUAL_UINT( set_data[ 0 ], get_data[ 0 ]); + TEST_ASSERT_EQUAL_UINT( 0, get_data[ 1 ]); // The call to hidSetReportItem with size 1 in the header should return the MSB to zero + } +} + +void xtest_modification_without_subsequent_preparation( void ) +{ + hidPrepareReportDescriptor(); + unsigned char* reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NOT_NULL( reportDescPtr ); + + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; + const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); + const unsigned char page = CONSUMER_PAGE; + + hidResetReportDescriptor(); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + + reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NULL( reportDescPtr ); +} + +void xtest_modification_with_subsequent_preparation( void ) +{ + hidPrepareReportDescriptor(); + unsigned char* reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NOT_NULL( reportDescPtr ); + + const unsigned reportId = 0; + const unsigned bit = MIN_VALID_BIT; + const unsigned byte = MIN_VALID_BYTE; + const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; + const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); + const unsigned char page = CONSUMER_PAGE; + + hidResetReportDescriptor(); + unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data ); + TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); + + hidPrepareReportDescriptor(); + reportDescPtr = hidGetReportDescriptor(); + TEST_ASSERT_NOT_NULL( reportDescPtr ); +} + +#endif \ No newline at end of file