forked from PAWPAW-Mirror/lib_xua
Clean-up
This commit is contained in:
@@ -6,6 +6,19 @@
|
||||
#include "xua_unit_tests.h"
|
||||
#include "xua_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 MAX_VALID_BIT ( 7 )
|
||||
#define MAX_VALID_BYTE ( 2 )
|
||||
|
||||
#define MIN_VALID_BIT ( 0 )
|
||||
#define MIN_VALID_BYTE ( 0 )
|
||||
|
||||
#define SPACEBAR_KEY_CODE ( 0x2C )
|
||||
|
||||
static unsigned construct_usage_header( unsigned size )
|
||||
{
|
||||
unsigned header = 0x00;
|
||||
@@ -35,9 +48,9 @@ void test_prepared_hidGetReportDescriptor( void )
|
||||
// Configurable and non-configurable item tests
|
||||
void test_configurable_item_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned bit = 0;
|
||||
const unsigned byte = 0;
|
||||
const unsigned char data[ 1 ] = { 0x2C }; // Spacebar keycode
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char data[ 1 ] = { SPACEBAR_KEY_CODE };
|
||||
const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char ));
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, header, data );
|
||||
@@ -46,9 +59,9 @@ void test_configurable_item_hidSetReportItem( void )
|
||||
|
||||
void test_nonconfigurable_item_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned bit = 7; // Reserved bit
|
||||
const unsigned byte = 0;
|
||||
const unsigned char data[ 1 ] = { 0x2C }; // Spacebar keycode
|
||||
const unsigned bit = 7; // This bit and byte combination should not appear in the
|
||||
const unsigned byte = 0; // hidConfigurableItems list in hid_report_descriptors.c.
|
||||
const unsigned char data[ 1 ] = { SPACEBAR_KEY_CODE };
|
||||
const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char ));
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, header, data );
|
||||
@@ -58,8 +71,8 @@ void test_nonconfigurable_item_hidSetReportItem( void )
|
||||
// Bit range tests
|
||||
void test_max_bit_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned bit = 7;
|
||||
const unsigned byte = 1; // Only byte 1 has bit 7 not reserved
|
||||
const unsigned bit = MAX_VALID_BIT; // Only byte 1 has bit 7 not reserved, See the
|
||||
const unsigned byte = 1; // hidConfigurableItems list in hid_report_descriptors.c.
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, header, NULL );
|
||||
@@ -68,8 +81,8 @@ void test_max_bit_hidSetReportItem( void )
|
||||
|
||||
void test_min_bit_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned bit = 0;
|
||||
const unsigned byte = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, header, NULL );
|
||||
@@ -78,8 +91,8 @@ void test_min_bit_hidSetReportItem( void )
|
||||
|
||||
void test_overflow_bit_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned bit = 8;
|
||||
const unsigned byte = 0;
|
||||
const unsigned bit = MAX_VALID_BIT + 1;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, header, NULL );
|
||||
@@ -88,8 +101,8 @@ void test_overflow_bit_hidSetReportItem( void )
|
||||
|
||||
void test_underflow_bit_hidSetReportItem( void )
|
||||
{
|
||||
const int bit = -1;
|
||||
const unsigned byte = 0;
|
||||
const int bit = MIN_VALID_BIT - 1;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, ( unsigned ) bit, header, NULL );
|
||||
@@ -99,8 +112,8 @@ void test_underflow_bit_hidSetReportItem( void )
|
||||
// Byte range tests
|
||||
void test_max_byte_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned bit = 0;
|
||||
const unsigned byte = 2;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MAX_VALID_BYTE;
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, header, NULL );
|
||||
@@ -109,8 +122,8 @@ void test_max_byte_hidSetReportItem( void )
|
||||
|
||||
void test_min_byte_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned bit = 0;
|
||||
const unsigned byte = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, header, NULL );
|
||||
@@ -119,8 +132,8 @@ void test_min_byte_hidSetReportItem( void )
|
||||
|
||||
void test_overflow_byte_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned bit = 0;
|
||||
const unsigned byte = 4;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MAX_VALID_BYTE + 1;
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, header, NULL );
|
||||
@@ -129,8 +142,8 @@ void test_overflow_byte_hidSetReportItem( void )
|
||||
|
||||
void test_underflow_byte_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned bit = 0;
|
||||
const int byte = -1;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const int byte = MIN_VALID_BYTE - 1;
|
||||
const unsigned char header = construct_usage_header( 0 );
|
||||
|
||||
unsigned retVal = hidSetReportItem( ( unsigned ) byte, bit, header, NULL );
|
||||
@@ -140,8 +153,8 @@ void test_underflow_byte_hidSetReportItem( void )
|
||||
// Size range tests
|
||||
void test_max_size_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned bit = 0;
|
||||
const unsigned byte = 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 );
|
||||
|
||||
@@ -151,8 +164,8 @@ void test_max_size_hidSetReportItem( void )
|
||||
|
||||
void test_min_size_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned bit = 0;
|
||||
const unsigned byte = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char header = construct_usage_header( 0x00 );
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, header, NULL );
|
||||
@@ -161,8 +174,8 @@ void test_min_size_hidSetReportItem( void )
|
||||
|
||||
void test_unsupported_size_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned bit = 0;
|
||||
const unsigned byte = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char header = construct_usage_header( 0x03 );
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, header, NULL );
|
||||
@@ -172,8 +185,8 @@ void test_unsupported_size_hidSetReportItem( void )
|
||||
// Header tag and type tests
|
||||
void test_bad_tag_hidSetReportItem( void )
|
||||
{
|
||||
const unsigned bit = 0;
|
||||
const unsigned byte = 0;
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char good_header = construct_usage_header( 0x00 );
|
||||
|
||||
for( unsigned tag = 0x01; tag <= 0x0F; ++tag ) {
|
||||
@@ -183,37 +196,34 @@ void test_bad_tag_hidSetReportItem( void )
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
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 );
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal );
|
||||
}
|
||||
|
||||
void test_local_type_hidSetReportItem( void )
|
||||
{
|
||||
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 );
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, 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 );
|
||||
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 );
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal );
|
||||
@@ -221,11 +231,10 @@ void test_main_type_hidSetReportItem( void )
|
||||
|
||||
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 );
|
||||
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 );
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, header, NULL );
|
||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal );
|
||||
@@ -234,9 +243,9 @@ void test_reserved_type_hidSetReportItem( void )
|
||||
// Combined function tests
|
||||
void test_initial_modification_without_subsequent_preparation( void )
|
||||
{
|
||||
const unsigned bit = 0;
|
||||
const unsigned byte = 0;
|
||||
const unsigned char data[ 1 ] = { 0x2C }; // Spacebar keycode
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char data[ 1 ] = { SPACEBAR_KEY_CODE };
|
||||
const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char ));
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, header, data );
|
||||
@@ -248,9 +257,9 @@ void test_initial_modification_without_subsequent_preparation( void )
|
||||
|
||||
void test_initial_modification_with_subsequent_preparation( void )
|
||||
{
|
||||
const unsigned bit = 0;
|
||||
const unsigned byte = 0;
|
||||
const unsigned char data[ 1 ] = { 0x2C }; // Spacebar keycode
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char data[ 1 ] = { SPACEBAR_KEY_CODE };
|
||||
const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char ));
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, header, data );
|
||||
@@ -267,9 +276,9 @@ void test_modification_without_subsequent_preparation( void )
|
||||
unsigned char* reportDescPtr = hidGetReportDescriptor();
|
||||
TEST_ASSERT_NOT_NULL( reportDescPtr );
|
||||
|
||||
const unsigned bit = 0;
|
||||
const unsigned byte = 0;
|
||||
const unsigned char data[ 1 ] = { 0x2C }; // Spacebar keycode
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char data[ 1 ] = { SPACEBAR_KEY_CODE };
|
||||
const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char ));
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, header, data );
|
||||
@@ -285,9 +294,9 @@ void test_modification_with_subsequent_preparation( void )
|
||||
unsigned char* reportDescPtr = hidGetReportDescriptor();
|
||||
TEST_ASSERT_NOT_NULL( reportDescPtr );
|
||||
|
||||
const unsigned bit = 0;
|
||||
const unsigned byte = 0;
|
||||
const unsigned char data[ 1 ] = { 0x2C }; // Spacebar keycode
|
||||
const unsigned bit = MIN_VALID_BIT;
|
||||
const unsigned byte = MIN_VALID_BYTE;
|
||||
const unsigned char data[ 1 ] = { SPACEBAR_KEY_CODE };
|
||||
const unsigned char header = construct_usage_header( sizeof data / sizeof( unsigned char ));
|
||||
|
||||
unsigned retVal = hidSetReportItem( byte, bit, header, data );
|
||||
|
||||
Reference in New Issue
Block a user