forked from PAWPAW-Mirror/lib_xua
Add size range tests. Fix misspelled function name.
This commit is contained in:
@@ -239,7 +239,6 @@ static unsigned hidGetItemByteLocation( const unsigned char location )
|
|||||||
static unsigned hidGetItemSize( const unsigned char header )
|
static unsigned hidGetItemSize( const unsigned char header )
|
||||||
{
|
{
|
||||||
unsigned bSize = ( header & HID_REPORT_ITEM_HDR_SIZE_MASK ) >> HID_REPORT_ITEM_HDR_SIZE_SHIFT;
|
unsigned bSize = ( header & HID_REPORT_ITEM_HDR_SIZE_MASK ) >> HID_REPORT_ITEM_HDR_SIZE_SHIFT;
|
||||||
assert( bSize <= HID_REPORT_ITEM_MAX_SIZE );
|
|
||||||
return bSize;
|
return bSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,7 +265,7 @@ unsigned char* hidGetReportDescriptor( void )
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hidPrerpareReportDescriptor( void )
|
void hidPrepareReportDescriptor( void )
|
||||||
{
|
{
|
||||||
unsigned char* ptr = hidReportDescriptor;
|
unsigned char* ptr = hidReportDescriptor;
|
||||||
for( unsigned idx = 0; idx < sizeof hidReportDescriptorItems / sizeof( USB_HID_Short_Item_t ); ++idx ) {
|
for( unsigned idx = 0; idx < sizeof hidReportDescriptorItems / sizeof( USB_HID_Short_Item_t ); ++idx ) {
|
||||||
@@ -283,9 +282,9 @@ unsigned hidSetReportItem( const unsigned byte, const unsigned bit, const unsign
|
|||||||
unsigned bTag = hidGetItemTag ( header );
|
unsigned bTag = hidGetItemTag ( header );
|
||||||
unsigned bType = hidGetItemType( header );
|
unsigned bType = hidGetItemType( header );
|
||||||
|
|
||||||
if(( HID_REPORT_ITEM_MAX_SIZE < bSize ) &&
|
if(( HID_REPORT_ITEM_MAX_SIZE < bSize ) ||
|
||||||
( HID_REPORT_ITEM_USAGE_TAG == bTag ) &&
|
( HID_REPORT_ITEM_USAGE_TAG != bTag ) ||
|
||||||
( HID_REPORT_ITEM_USAGE_TAG == bType )) {
|
( HID_REPORT_ITEM_USAGE_TYPE != bType )) {
|
||||||
retVal = HID_STATUS_BAD_HEADER;
|
retVal = HID_STATUS_BAD_HEADER;
|
||||||
} else {
|
} else {
|
||||||
for( unsigned itemIdx = 0; itemIdx < sizeof hidConfigurableItems / sizeof( USB_HID_Short_Item_t ); ++itemIdx ) {
|
for( unsigned itemIdx = 0; itemIdx < sizeof hidConfigurableItems / sizeof( USB_HID_Short_Item_t ); ++itemIdx ) {
|
||||||
|
|||||||
@@ -75,6 +75,10 @@ void hidPrepareReportDescriptor( void );
|
|||||||
/**
|
/**
|
||||||
* @brief Modify a HID Report descriptor item
|
* @brief Modify a HID Report descriptor item
|
||||||
*
|
*
|
||||||
|
* @warning This function does not check that the length of the \a data array matches the value of
|
||||||
|
* the bSize field in the \a header. For safe operation use a \a data array of at least
|
||||||
|
* \c HID_REPORT_ITEM_MAX_SIZE bytes in length.
|
||||||
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
*
|
*
|
||||||
* @param[in] byte The byte position of the control within the HID Report
|
* @param[in] byte The byte position of the control within the HID Report
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// Copyright 2021 XMOS LIMITED.
|
// Copyright 2021 XMOS LIMITED.
|
||||||
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "xua_unit_tests.h"
|
#include "xua_unit_tests.h"
|
||||||
#include "xua_hid_report_descriptor.h"
|
#include "xua_hid_report_descriptor.h"
|
||||||
@@ -18,15 +19,15 @@ static unsigned construct_usage_header( unsigned size )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Basic report descriptor tests
|
// Basic report descriptor tests
|
||||||
void test_uninitialised_hidGetReportDescriptor( void )
|
void test_unprepared_hidGetReportDescriptor( void )
|
||||||
{
|
{
|
||||||
unsigned char* reportDescPtr = hidGetReportDescriptor();
|
unsigned char* reportDescPtr = hidGetReportDescriptor();
|
||||||
TEST_ASSERT_NULL( reportDescPtr );
|
TEST_ASSERT_NULL( reportDescPtr );
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_initialised_hidGetReportDescriptor( void )
|
void test_prepared_hidGetReportDescriptor( void )
|
||||||
{
|
{
|
||||||
hidInitReportDescriptor();
|
hidPrepareReportDescriptor();
|
||||||
unsigned char* reportDescPtr = hidGetReportDescriptor();
|
unsigned char* reportDescPtr = hidGetReportDescriptor();
|
||||||
TEST_ASSERT_NOT_NULL( reportDescPtr );
|
TEST_ASSERT_NOT_NULL( reportDescPtr );
|
||||||
}
|
}
|
||||||
@@ -112,3 +113,35 @@ void test_underflow_byte_hidSetReportItem( void )
|
|||||||
unsigned retVal = hidSetReportItem( ( unsigned ) byte, bit, header, NULL );
|
unsigned retVal = hidSetReportItem( ( unsigned ) byte, bit, header, NULL );
|
||||||
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_LOCATION, retVal );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Size range tests
|
||||||
|
void test_max_size_hidSetReportItem( void )
|
||||||
|
{
|
||||||
|
const unsigned bit = 0;
|
||||||
|
const unsigned byte = 0;
|
||||||
|
const unsigned char data[ HID_REPORT_ITEM_MAX_SIZE ] = { 0x00 };
|
||||||
|
const unsigned char header = construct_usage_header( HID_REPORT_ITEM_MAX_SIZE );
|
||||||
|
|
||||||
|
unsigned retVal = hidSetReportItem( byte, bit, header, data );
|
||||||
|
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_min_size_hidSetReportItem( void )
|
||||||
|
{
|
||||||
|
const unsigned bit = 0;
|
||||||
|
const unsigned byte = 0;
|
||||||
|
const unsigned char header = construct_usage_header( 0x00 );
|
||||||
|
|
||||||
|
unsigned retVal = hidSetReportItem( byte, bit, header, NULL );
|
||||||
|
TEST_ASSERT_EQUAL_UINT( HID_STATUS_GOOD, retVal );
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_unsupported_size_hidSetReportItem( void )
|
||||||
|
{
|
||||||
|
const unsigned bit = 0;
|
||||||
|
const unsigned byte = 0;
|
||||||
|
const unsigned char header = construct_usage_header( 0x03 );
|
||||||
|
|
||||||
|
unsigned retVal = hidSetReportItem( byte, bit, header, NULL );
|
||||||
|
TEST_ASSERT_EQUAL_UINT( HID_STATUS_BAD_HEADER, retVal );
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user