From a943cce99110eabeaea98a390a41842a15de715f Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 29 Jun 2013 21:00:33 +0700 Subject: [PATCH] test refractor --- demos/device/keyboard/tusb_descriptors.h | 19 --- tests/lpc175x_6x/test/test_usbd.c | 48 +++++++ tests/lpc18xx_43xx/project.yml | 7 +- .../lpc18xx_43xx/test/device/usbd/test_usbd.c | 136 ------------------ .../ehci/test_ehci_usbh_hcd_integration.c | 1 + tests/lpc18xx_43xx/test/host/usbh/test_usbh.c | 2 +- tinyusb/class/cdc.h | 6 +- tinyusb/core/tusb_types.h | 23 +-- tinyusb/osal/osal.h | 10 +- tinyusb/tusb_option.h | 7 +- 10 files changed, 80 insertions(+), 179 deletions(-) delete mode 100644 tests/lpc18xx_43xx/test/device/usbd/test_usbd.c diff --git a/demos/device/keyboard/tusb_descriptors.h b/demos/device/keyboard/tusb_descriptors.h index 2cdee40cf..81c629fd7 100644 --- a/demos/device/keyboard/tusb_descriptors.h +++ b/demos/device/keyboard/tusb_descriptors.h @@ -76,25 +76,6 @@ typedef ATTR_PACKED_STRUCT(struct) { tusb_descriptor_configuration_t configuration; -#if IAD_DESC_REQUIRED - tusb_descriptor_interface_association_t CDC_IAD; -#endif - -#if TUSB_CFG_DEVICE_CDC - //CDC - Serial - //CDC Control Interface - tusb_descriptor_interface_t CDC_CCI_Interface; - CDC_HEADER_DESCRIPTOR CDC_Header; - CDC_ABSTRACT_CONTROL_MANAGEMENT_DESCRIPTOR CDC_ACM; - CDC_UNION_1SLAVE_DESCRIPTOR CDC_Union; - tusb_descriptor_endpoint_t CDC_NotificationEndpoint; - - //CDC Data Interface - tusb_descriptor_interface_t CDC_DCI_Interface; - tusb_descriptor_endpoint_t CDC_DataOutEndpoint; - tusb_descriptor_endpoint_t CDC_DataInEndpoint; -#endif - //------------- HID Keyboard -------------// #if TUSB_CFG_DEVICE_HID_KEYBOARD tusb_descriptor_interface_t keyboard_interface; diff --git a/tests/lpc175x_6x/test/test_usbd.c b/tests/lpc175x_6x/test/test_usbd.c index 0e724ef6e..0fe37083a 100644 --- a/tests/lpc175x_6x/test/test_usbd.c +++ b/tests/lpc175x_6x/test/test_usbd.c @@ -103,3 +103,51 @@ void test_usbd_init(void) //------------- Code Under Test -------------// TEST_ASSERT_STATUS( usbd_init() ); } + + +void test_usbd_init_ok(void) +{ + TEST_IGNORE_MESSAGE("pause device stack"); + dcd_init_ExpectAndReturn(TUSB_ERROR_NONE); + + hidd_init_StubWithCallback(stub_hidd_init); + + dcd_controller_connect_Expect(0); + + //------------- Code Under Test -------------// + TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, usbd_init() ); + +} + +void test_usbd_string_descriptor(void) +{ + dcd_init_IgnoreAndReturn(TUSB_ERROR_FAILED); + + //------------- Code Under Test -------------// + TEST_ASSERT_EQUAL( TUSB_ERROR_FAILED, usbd_init() ); + + + //------------- manufacturer string descriptor -------------// + uint32_t const manufacturer_len = sizeof(TUSB_CFG_DEVICE_STRING_MANUFACTURER) - 1; + TEST_ASSERT_EQUAL(manufacturer_len*2 + 2, app_tusb_desc_strings.manufacturer.bLength); + for(uint32_t i=0; i -#include "unity.h" -#include "errors.h" -#include "type_helper.h" - -#include "tusb_descriptors.h" - -#include "usbd.h" -#include "mock_dcd.h" -#include "mock_hid_device.h" - -void setUp(void) -{ - -} - -void tearDown(void) -{ -} - -void test_dcd_init_failed(void) -{ - dcd_init_ExpectAndReturn(TUSB_ERROR_FAILED); - - //------------- Code Under Test -------------// - TEST_ASSERT_EQUAL( TUSB_ERROR_FAILED, usbd_init() ); -} - -tusb_error_t stub_hidd_init(tusb_descriptor_interface_t const* p_interface_desc, uint16_t* p_length, int num_call) -{ - printf("hidd_init num_call = %d\n", num_call); - switch(num_call) - { - case 0: - TEST_ASSERT_EQUAL_HEX32(&app_tusb_desc_configuration.keyboard_interface, p_interface_desc); - break; - - case 1: - TEST_ASSERT_EQUAL_HEX32(&app_tusb_desc_configuration.mouse_interface, p_interface_desc); - break; - - case 2: - break; - - default: - return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE; - } - - return TUSB_ERROR_NONE; -} - -void test_usbd_init_ok(void) -{ - TEST_IGNORE_MESSAGE("pause device stack"); - dcd_init_ExpectAndReturn(TUSB_ERROR_NONE); - - hidd_init_StubWithCallback(stub_hidd_init); - - dcd_controller_connect_Expect(0); - - //------------- Code Under Test -------------// - TEST_ASSERT_EQUAL( TUSB_ERROR_NONE, usbd_init() ); - -} - -void test_usbd_string_descriptor(void) -{ - dcd_init_IgnoreAndReturn(TUSB_ERROR_FAILED); - - //------------- Code Under Test -------------// - TEST_ASSERT_EQUAL( TUSB_ERROR_FAILED, usbd_init() ); - - - //------------- manufacturer string descriptor -------------// - uint32_t const manufacturer_len = sizeof(TUSB_CFG_DEVICE_STRING_MANUFACTURER) - 1; - TEST_ASSERT_EQUAL(manufacturer_len*2 + 2, app_tusb_desc_strings.manufacturer.bLength); - for(uint32_t i=0; i