Update existing unit tests to work with the new API

This commit is contained in:
Ciaran Woodward
2021-12-08 12:34:14 +00:00
parent be90779db5
commit 79e256f829
2 changed files with 71 additions and 39 deletions

View File

@@ -42,7 +42,7 @@ static const USB_HID_Short_Item_t hidUsageConsumerControl = { .header = 0x09,
*/ */
static const USB_HID_Report_Element_t hidReportPageConsumer = { static const USB_HID_Report_Element_t hidReportPageConsumer = {
.item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }}, .item = { .header = 0x05, .data = { USB_HID_USAGE_PAGE_ID_CONSUMER, 0x00 }},
.location = HID_REPORT_SET_LOC( 0, 1, 0, 0 ) .location = HID_REPORT_SET_LOC( 0, 2, 0, 0 )
}; };
/* /*
@@ -123,6 +123,6 @@ static const USB_HID_Short_Item_t* const hidReportDescriptorItems[] = {
* Due to XC not supporting designated initializers, this constant has a hard-coded value. * 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* )) * It must equal ( sizeof hidReports / sizeof ( USB_HID_Report_Element_t* ))
*/ */
#define HID_REPORT_COUNT ( 3 ) #define HID_REPORT_COUNT ( 1 )
#endif // __hid_report_descriptor_h__ #endif // __hid_report_descriptor_h__

View File

@@ -36,20 +36,22 @@ void setUp( void )
// Basic report descriptor tests // Basic report descriptor tests
void test_unprepared_hidGetReportDescriptor( void ) void test_unprepared_hidGetReportDescriptor( void )
{ {
const unsigned reportId = 0;
unsigned char* reportDescPtr = hidGetReportDescriptor(); unsigned char* reportDescPtr = hidGetReportDescriptor();
TEST_ASSERT_NULL( reportDescPtr ); TEST_ASSERT_NULL( reportDescPtr );
unsigned reportLength = hidGetReportLength(); unsigned reportLength = hidGetReportLength( reportId );
TEST_ASSERT_EQUAL_UINT( 0, reportLength ); TEST_ASSERT_EQUAL_UINT( 0, reportLength );
} }
void test_prepared_hidGetReportDescriptor( void ) void test_prepared_hidGetReportDescriptor( void )
{ {
const unsigned reportId = 0;
hidPrepareReportDescriptor(); hidPrepareReportDescriptor();
unsigned char* reportDescPtr = hidGetReportDescriptor(); unsigned char* reportDescPtr = hidGetReportDescriptor();
TEST_ASSERT_NOT_NULL( reportDescPtr ); TEST_ASSERT_NOT_NULL( reportDescPtr );
unsigned reportLength = hidGetReportLength(); unsigned reportLength = hidGetReportLength( reportId );
TEST_ASSERT_EQUAL_UINT( HID_REPORT_LENGTH, reportLength ); TEST_ASSERT_EQUAL_UINT( HID_REPORT_LENGTH, reportLength );
} }
@@ -73,13 +75,14 @@ void test_reset_prepared_hidGetReportDescriptor( void )
// Basic item tests // Basic item tests
void test_max_loc_hidGetReportItem( void ) void test_max_loc_hidGetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MAX_VALID_BIT; const unsigned bit = MAX_VALID_BIT;
const unsigned byte = MAX_VALID_BYTE; const unsigned byte = MAX_VALID_BYTE;
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ]; unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ];
unsigned char header; unsigned char header;
unsigned char page; unsigned char page;
unsigned retVal = hidGetReportItem( byte, bit, &page, &header, data ); unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
TEST_ASSERT_EQUAL_UINT( CONSUMER_CONTROL_PAGE, page ); TEST_ASSERT_EQUAL_UINT( CONSUMER_CONTROL_PAGE, page );
TEST_ASSERT_EQUAL_UINT( 0x09, header ); TEST_ASSERT_EQUAL_UINT( 0x09, header );
@@ -89,13 +92,14 @@ void test_max_loc_hidGetReportItem( void )
void test_min_loc_hidGetReportItem( void ) void test_min_loc_hidGetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ]; unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ];
unsigned char header; unsigned char header;
unsigned char page; unsigned char page;
unsigned retVal = hidGetReportItem( byte, bit, &page, &header, data ); unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
TEST_ASSERT_EQUAL_UINT( CONSUMER_CONTROL_PAGE, page ); TEST_ASSERT_EQUAL_UINT( CONSUMER_CONTROL_PAGE, page );
TEST_ASSERT_EQUAL_UINT( 0x09, header ); TEST_ASSERT_EQUAL_UINT( 0x09, header );
@@ -105,13 +109,14 @@ void test_min_loc_hidGetReportItem( void )
void test_overflow_bit_hidGetReportItem( void ) void test_overflow_bit_hidGetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MAX_VALID_BIT + 1; const unsigned bit = MAX_VALID_BIT + 1;
const unsigned byte = MAX_VALID_BYTE; const unsigned byte = MAX_VALID_BYTE;
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 }; unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 };
unsigned char header = 0xAA; unsigned char header = 0xAA;
unsigned char page = 0x44; unsigned char page = 0x44;
unsigned retVal = hidGetReportItem( byte, bit, &page, &header, data ); unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
TEST_ASSERT_EQUAL_UINT( 0x44, page ); TEST_ASSERT_EQUAL_UINT( 0x44, page );
TEST_ASSERT_EQUAL_UINT( 0xAA, header ); TEST_ASSERT_EQUAL_UINT( 0xAA, header );
@@ -121,13 +126,14 @@ void test_overflow_bit_hidGetReportItem( void )
void test_overflow_byte_hidGetReportItem( void ) void test_overflow_byte_hidGetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MAX_VALID_BIT; const unsigned bit = MAX_VALID_BIT;
const unsigned byte = MAX_VALID_BYTE + 1; const unsigned byte = MAX_VALID_BYTE + 1;
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 }; unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 };
unsigned char header = 0xAA; unsigned char header = 0xAA;
unsigned char page = 0x44; unsigned char page = 0x44;
unsigned retVal = hidGetReportItem( byte, bit, &page, &header, data ); unsigned retVal = hidGetReportItem( reportId, byte, bit, &page, &header, data );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
TEST_ASSERT_EQUAL_UINT( 0x44, page ); TEST_ASSERT_EQUAL_UINT( 0x44, page );
TEST_ASSERT_EQUAL_UINT( 0xAA, header ); TEST_ASSERT_EQUAL_UINT( 0xAA, header );
@@ -137,13 +143,14 @@ void test_overflow_byte_hidGetReportItem( void )
void test_underflow_bit_hidGetReportItem( void ) void test_underflow_bit_hidGetReportItem( void )
{ {
const int bit = MIN_VALID_BIT - 1; const unsigned reportId = 0;
const int bit = MIN_VALID_BIT - 1;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 }; unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 };
unsigned char header = 0xAA; unsigned char header = 0xAA;
unsigned char page = 0x44; unsigned char page = 0x44;
unsigned retVal = hidGetReportItem( byte, ( unsigned ) bit, &page, &header, data ); unsigned retVal = hidGetReportItem( reportId, byte, ( unsigned ) bit, &page, &header, data );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
TEST_ASSERT_EQUAL_UINT( 0x44, page ); TEST_ASSERT_EQUAL_UINT( 0x44, page );
TEST_ASSERT_EQUAL_UINT( 0xAA, header ); TEST_ASSERT_EQUAL_UINT( 0xAA, header );
@@ -153,13 +160,14 @@ void test_underflow_bit_hidGetReportItem( void )
void test_underflow_byte_hidGetReportItem( void ) void test_underflow_byte_hidGetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const int byte = MIN_VALID_BYTE - 1; const int byte = MIN_VALID_BYTE - 1;
unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 }; unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0xBA, 0xD1 };
unsigned char header = 0xAA; unsigned char header = 0xAA;
unsigned char page = 0x44; unsigned char page = 0x44;
unsigned retVal = hidGetReportItem(( unsigned ) byte, bit, &page, &header, data ); unsigned retVal = hidGetReportItem( reportId, ( unsigned ) byte, bit, &page, &header, data );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
TEST_ASSERT_EQUAL_UINT( 0x44, page ); TEST_ASSERT_EQUAL_UINT( 0x44, page );
TEST_ASSERT_EQUAL_UINT( 0xAA, header ); TEST_ASSERT_EQUAL_UINT( 0xAA, header );
@@ -170,156 +178,170 @@ void test_underflow_byte_hidGetReportItem( void )
// Configurable and non-configurable item tests // Configurable and non-configurable item tests
void test_configurable_item_hidSetReportItem( void ) void test_configurable_item_hidSetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; const unsigned char data[ 1 ] = { LOUDNESS_CONTROL };
const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char ));
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
} }
void test_nonconfigurable_item_hidSetReportItem( void ) void test_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 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 byte = MIN_VALID_BYTE; // hidConfigurableElements list in hid_report_descriptors.c.
const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; const unsigned char data[ 1 ] = { LOUDNESS_CONTROL };
const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char ));
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
} }
// Bit range tests // Bit range tests
void test_max_bit_hidSetReportItem( void ) void test_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 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 byte = MAX_VALID_BYTE; // hidConfigurableElements list in hid_report_descriptors.c.
const unsigned char header = construct_usage_header( 0 ); const unsigned char header = construct_usage_header( 0 );
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
} }
void test_min_bit_hidSetReportItem( void ) void test_min_bit_hidSetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
const unsigned char header = construct_usage_header( 0 ); const unsigned char header = construct_usage_header( 0 );
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
} }
void test_overflow_bit_hidSetReportItem( void ) void test_overflow_bit_hidSetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MAX_VALID_BIT + 1; const unsigned bit = MAX_VALID_BIT + 1;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
const unsigned char header = construct_usage_header( 0 ); const unsigned char header = construct_usage_header( 0 );
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
} }
void test_underflow_bit_hidSetReportItem( void ) void test_underflow_bit_hidSetReportItem( void )
{ {
const unsigned reportId = 0;
const int bit = MIN_VALID_BIT - 1; const int bit = MIN_VALID_BIT - 1;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
const unsigned char header = construct_usage_header( 0 ); const unsigned char header = construct_usage_header( 0 );
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
unsigned retVal = hidSetReportItem( byte, ( unsigned ) bit, page, header, NULL ); unsigned retVal = hidSetReportItem( reportId, byte, ( unsigned ) bit, page, header, NULL );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
} }
// Byte range tests // Byte range tests
void test_max_byte_hidSetReportItem( void ) void test_max_byte_hidSetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MAX_VALID_BYTE; const unsigned byte = MAX_VALID_BYTE;
const unsigned char header = construct_usage_header( 0 ); const unsigned char header = construct_usage_header( 0 );
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
} }
void test_min_byte_hidSetReportItem( void ) void test_min_byte_hidSetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
const unsigned char header = construct_usage_header( 0 ); const unsigned char header = construct_usage_header( 0 );
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
} }
void test_overflow_byte_hidSetReportItem( void ) void test_overflow_byte_hidSetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MAX_VALID_BYTE + 1; const unsigned byte = MAX_VALID_BYTE + 1;
const unsigned char header = construct_usage_header( 0 ); const unsigned char header = construct_usage_header( 0 );
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
} }
void test_underflow_byte_hidSetReportItem( void ) void test_underflow_byte_hidSetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const int byte = MIN_VALID_BYTE - 1; const int byte = MIN_VALID_BYTE - 1;
const unsigned char header = construct_usage_header( 0 ); const unsigned char header = construct_usage_header( 0 );
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
unsigned retVal = hidSetReportItem( ( unsigned ) byte, bit, page, header, NULL ); unsigned retVal = hidSetReportItem( reportId, ( unsigned ) byte, bit, page, header, NULL );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
} }
// Size range tests // Size range tests
void test_max_size_hidSetReportItem( void ) void test_max_size_hidSetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
const unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0x00 }; 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 header = construct_usage_header( HID_REPORT_ITEM_MAX_SIZE );
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
} }
void test_min_size_hidSetReportItem( void ) void test_min_size_hidSetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
const unsigned char header = construct_usage_header( 0x00 ); const unsigned char header = construct_usage_header( 0x00 );
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
} }
void test_unsupported_size_hidSetReportItem( void ) void test_unsupported_size_hidSetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
const unsigned char header = construct_usage_header( 0x03 ); const unsigned char header = construct_usage_header( 0x03 );
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal );
} }
// Header tag and type tests // Header tag and type tests
void test_bad_tag_hidSetReportItem( void ) void test_bad_tag_hidSetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
const unsigned char good_header = construct_usage_header( 0x00 ); const unsigned char good_header = construct_usage_header( 0x00 );
@@ -327,69 +349,74 @@ void test_bad_tag_hidSetReportItem( void )
for( unsigned tag = 0x01; tag <= 0x0F; ++tag ) { 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 char bad_header = good_header | (( 0x0F << HID_REPORT_ITEM_HDR_TAG_SHIFT ) & HID_REPORT_ITEM_HDR_TAG_MASK );
unsigned retVal = hidSetReportItem( byte, bit, page, bad_header, NULL ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, bad_header, NULL );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal );
} }
} }
void test_global_type_hidSetReportItem( void ) void test_global_type_hidSetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | 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 ); (( HID_REPORT_ITEM_TYPE_GLOBAL << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK );
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal );
} }
void test_local_type_hidSetReportItem( void ) void test_local_type_hidSetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | 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 ); (( HID_REPORT_ITEM_TYPE_LOCAL << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK );
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
} }
void test_main_type_hidSetReportItem( void ) void test_main_type_hidSetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | 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 ); (( HID_REPORT_ITEM_TYPE_MAIN << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK );
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal );
} }
void test_reserved_type_hidSetReportItem( void ) void test_reserved_type_hidSetReportItem( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
const unsigned char header = ( construct_usage_header( 0x00 ) & ~HID_REPORT_ITEM_HDR_TYPE_MASK ) | 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 ); (( HID_REPORT_ITEM_TYPE_RESERVED << HID_REPORT_ITEM_HDR_TYPE_SHIFT ) & HID_REPORT_ITEM_HDR_TYPE_MASK );
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
unsigned retVal = hidSetReportItem( byte, bit, page, header, NULL ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, NULL );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal );
} }
// Combined function tests // Combined function tests
void test_initial_modification_without_subsequent_preparation( void ) void test_initial_modification_without_subsequent_preparation( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; const unsigned char data[ 1 ] = { LOUDNESS_CONTROL };
const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char ));
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
unsigned char* reportDescPtr = hidGetReportDescriptor(); unsigned char* reportDescPtr = hidGetReportDescriptor();
@@ -398,13 +425,14 @@ void test_initial_modification_without_subsequent_preparation( void )
void test_initial_modification_with_subsequent_preparation( void ) void test_initial_modification_with_subsequent_preparation( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; const unsigned char data[ 1 ] = { LOUDNESS_CONTROL };
const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char )); const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char ));
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
hidPrepareReportDescriptor(); hidPrepareReportDescriptor();
@@ -414,6 +442,7 @@ void test_initial_modification_with_subsequent_preparation( void )
void test_initial_modification_with_subsequent_verification_1( void ) void test_initial_modification_with_subsequent_verification_1( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
@@ -425,10 +454,10 @@ void test_initial_modification_with_subsequent_verification_1( void )
const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char )); const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char ));
const unsigned char set_page = CONSUMER_CONTROL_PAGE; const unsigned char set_page = CONSUMER_CONTROL_PAGE;
unsigned setRetVal = hidSetReportItem( byte, bit, set_page, set_header, set_data ); unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal );
unsigned getRetVal = hidGetReportItem( byte, bit, &get_page, &get_header, get_data ); unsigned getRetVal = hidGetReportItem( reportId, byte, bit, &get_page, &get_header, get_data );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal );
TEST_ASSERT_EQUAL_UINT( set_page, get_page ); TEST_ASSERT_EQUAL_UINT( set_page, get_page );
TEST_ASSERT_EQUAL_UINT( set_header, get_header ); TEST_ASSERT_EQUAL_UINT( set_header, get_header );
@@ -438,6 +467,7 @@ void test_initial_modification_with_subsequent_verification_1( void )
void test_initial_modification_with_subsequent_verification_2( void ) void test_initial_modification_with_subsequent_verification_2( void )
{ {
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
@@ -450,10 +480,10 @@ void test_initial_modification_with_subsequent_verification_2( void )
const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char )); const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char ));
const unsigned char set_page = CONSUMER_CONTROL_PAGE; const unsigned char set_page = CONSUMER_CONTROL_PAGE;
unsigned setRetVal = hidSetReportItem( byte, bit, set_page, set_header, set_data ); unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal );
unsigned getRetVal = hidGetReportItem( byte, bit, &get_page, &get_header, get_data ); unsigned getRetVal = hidGetReportItem( reportId, byte, bit, &get_page, &get_header, get_data );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal );
TEST_ASSERT_EQUAL_UINT( set_page, get_page ); TEST_ASSERT_EQUAL_UINT( set_page, get_page );
TEST_ASSERT_EQUAL_UINT( set_header, get_header ); TEST_ASSERT_EQUAL_UINT( set_header, get_header );
@@ -470,10 +500,10 @@ void test_initial_modification_with_subsequent_verification_2( void )
const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char )); const unsigned char set_header = construct_usage_header( sizeof set_data / sizeof( unsigned char ));
const unsigned char set_page = CONSUMER_CONTROL_PAGE; const unsigned char set_page = CONSUMER_CONTROL_PAGE;
unsigned setRetVal = hidSetReportItem( byte, bit, set_page, set_header, set_data ); unsigned setRetVal = hidSetReportItem( reportId, byte, bit, set_page, set_header, set_data );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, setRetVal );
unsigned getRetVal = hidGetReportItem( byte, bit, &get_page, &get_header, get_data ); unsigned getRetVal = hidGetReportItem( reportId, byte, bit, &get_page, &get_header, get_data );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, getRetVal );
TEST_ASSERT_EQUAL_UINT( set_page, get_page ); TEST_ASSERT_EQUAL_UINT( set_page, get_page );
TEST_ASSERT_EQUAL_UINT( set_header, get_header ); TEST_ASSERT_EQUAL_UINT( set_header, get_header );
@@ -488,6 +518,7 @@ void test_modification_without_subsequent_preparation( void )
unsigned char* reportDescPtr = hidGetReportDescriptor(); unsigned char* reportDescPtr = hidGetReportDescriptor();
TEST_ASSERT_NOT_NULL( reportDescPtr ); TEST_ASSERT_NOT_NULL( reportDescPtr );
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; const unsigned char data[ 1 ] = { LOUDNESS_CONTROL };
@@ -495,7 +526,7 @@ void test_modification_without_subsequent_preparation( void )
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
hidResetReportDescriptor(); hidResetReportDescriptor();
unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
reportDescPtr = hidGetReportDescriptor(); reportDescPtr = hidGetReportDescriptor();
@@ -508,6 +539,7 @@ void test_modification_with_subsequent_preparation( void )
unsigned char* reportDescPtr = hidGetReportDescriptor(); unsigned char* reportDescPtr = hidGetReportDescriptor();
TEST_ASSERT_NOT_NULL( reportDescPtr ); TEST_ASSERT_NOT_NULL( reportDescPtr );
const unsigned reportId = 0;
const unsigned bit = MIN_VALID_BIT; const unsigned bit = MIN_VALID_BIT;
const unsigned byte = MIN_VALID_BYTE; const unsigned byte = MIN_VALID_BYTE;
const unsigned char data[ 1 ] = { LOUDNESS_CONTROL }; const unsigned char data[ 1 ] = { LOUDNESS_CONTROL };
@@ -515,7 +547,7 @@ void test_modification_with_subsequent_preparation( void )
const unsigned char page = CONSUMER_CONTROL_PAGE; const unsigned char page = CONSUMER_CONTROL_PAGE;
hidResetReportDescriptor(); hidResetReportDescriptor();
unsigned retVal = hidSetReportItem( byte, bit, page, header, data ); unsigned retVal = hidSetReportItem( reportId, byte, bit, page, header, data );
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal ); TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
hidPrepareReportDescriptor(); hidPrepareReportDescriptor();