summaryrefslogtreecommitdiff
path: root/tests/test
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-03-26 11:41:41 +0700
committerhathach <[email protected]>2013-03-26 11:41:41 +0700
commit54acee1fc80ce6f3ba86c91db4409e1ebfbda638 (patch)
treed68364c2f763f0516cfa0b7b663863b1c39779c6 /tests/test
parenta7e8a2ba9aa5e8a6ba074f397b1fd789a8f25205 (diff)
start merge hidh_keyboard back to hidh
Diffstat (limited to 'tests/test')
-rw-r--r--tests/test/host/hid/test_hid_host.c33
-rw-r--r--tests/test/host/hid/test_hidh_keyboard.c39
2 files changed, 30 insertions, 42 deletions
diff --git a/tests/test/host/hid/test_hid_host.c b/tests/test/host/hid/test_hid_host.c
index 3114eaf1e..caa73eb06 100644
--- a/tests/test/host/hid/test_hid_host.c
+++ b/tests/test/host/hid/test_hid_host.c
@@ -45,7 +45,6 @@
#include "mock_osal.h"
#include "mock_hcd.h"
#include "mock_usbh.h"
-#include "mock_hid_host_keyboard.h"
#include "hid_host.h"
@@ -64,39 +63,31 @@ void tearDown(void)
{
}
-void test_hidh_init_ok(void)
-{
-// hidh_keyboard_init_Expect();
- // TODO mouse, generic expect
-
- //------------- Code Under TEST -------------//
-// hidh_init();
-}
-
void test_hidh_open_ok(void)
{
uint16_t length=0;
-//
-// hidh_keyboard_open_subtask_ExpectAndReturn(dev_addr, p_kbd_interface_desc, &length, TUSB_ERROR_NONE);
-//
+ pipe_handle_t pipe_hdl = {.dev_addr = dev_addr, .xfer_type = TUSB_XFER_INTERRUPT, .index = 2};
+
+ // TODO expect get HID report descriptor
+ hcd_pipe_open_IgnoreAndReturn( pipe_hdl );
+
//------------- Code Under TEST -------------//
-// hidh_open_subtask(dev_addr, (uint8_t*) p_kbd_interface_desc, &length);
+ TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, hidh_open_subtask(dev_addr, (uint8_t*) p_kbd_interface_desc, &length) );
-// TEST_ASSERT_EQUAL(sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t),
-// length);
+ TEST_ASSERT_EQUAL(sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t),
+ length);
}
void test_hidh_close(void)
{
- hidh_keyboard_close_Expect(dev_addr);
-
+ TEST_IGNORE();
//------------- Code Under TEST -------------//
hidh_close(dev_addr);
}
void test_hihd_isr(void)
{
- if (!hidh_isr)
- TEST_IGNORE();
-
+ TEST_IGNORE();
+ //------------- Code Under TEST -------------//
+// hidh_isr()
}
diff --git a/tests/test/host/hid/test_hidh_keyboard.c b/tests/test/host/hid/test_hidh_keyboard.c
index 528f146e2..d907bc6c2 100644
--- a/tests/test/host/hid/test_hidh_keyboard.c
+++ b/tests/test/host/hid/test_hidh_keyboard.c
@@ -37,9 +37,9 @@
#include "stdlib.h"
#include "unity.h"
+#include "type_helper.h"
#include "errors.h"
#include "hid_host.h"
-#include "hid_host_keyboard.h"
#include "mock_osal.h"
#include "mock_usbh.h"
#include "mock_hcd.h"
@@ -71,7 +71,7 @@ void setUp(void)
memclr_(&report, sizeof(tusb_keyboard_report_t));
dev_addr = RANDOM(TUSB_CFG_HOST_DEVICE_MAX)+1;
- hidh_keyboard_init();
+ hidh_init();
p_hidh_kbd = &keyboard_data[dev_addr-1];
@@ -88,28 +88,25 @@ void tearDown(void)
{
}
-//--------------------------------------------------------------------+
-// keyboard_install, keyboard_no_instances, keybaord_init
-//--------------------------------------------------------------------+
-void TEST_ASSERT_PIPE_HANDLE(pipe_handle_t x, pipe_handle_t y)
+void test_keyboard_init(void)
{
- TEST_ASSERT_EQUAL(x.dev_addr , y.dev_addr);
- TEST_ASSERT_EQUAL(x.xfer_type , y.xfer_type);
- TEST_ASSERT_EQUAL(x.index , y.index);
+ hidh_init();
+
+ TEST_ASSERT_MEM_ZERO(keyboard_data, sizeof(hidh_keyboard_info_t)*TUSB_CFG_HOST_DEVICE_MAX);
}
-void test_keyboard_is_supported_fail(void)
+void test_keyboard_is_supported_fail_unplug(void)
{
+ hidh_init();
tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_UNPLUG);
TEST_ASSERT_FALSE( tusbh_hid_keyboard_is_supported(dev_addr) );
}
-void test_keyboard_init(void)
+void test_keyboard_is_supported_fail_not_opened(void)
{
- hidh_keyboard_init();
-
- for(uint32_t i=0; i < sizeof(hidh_keyboard_info_t)*TUSB_CFG_HOST_DEVICE_MAX; i++)
- TEST_ASSERT_EQUAL(0, ((uint8_t*)keyboard_data) [i]);
+ hidh_init();
+ tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
+ TEST_ASSERT_FALSE( tusbh_hid_keyboard_is_supported(dev_addr) );
}
void test_keyboard_open_ok(void)
@@ -121,7 +118,7 @@ void test_keyboard_open_ok(void)
hcd_pipe_open_ExpectAndReturn(dev_addr, p_kdb_endpoint_desc, TUSB_CLASS_HID, pipe_hdl);
//------------- Code Under TEST -------------//
- TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, hidh_keyboard_open_subtask(dev_addr, (uint8_t*) p_kbd_interface_desc, &length));
+ TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, hidh_open_subtask(dev_addr, (uint8_t*) p_kbd_interface_desc, &length));
TEST_ASSERT_PIPE_HANDLE(pipe_hdl, p_hidh_kbd->pipe_hdl);
TEST_ASSERT_EQUAL(8, p_hidh_kbd->report_size);
@@ -143,19 +140,19 @@ void test_keyboard_close(void)
void test_keyboard_get_invalid_address(void)
{
tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
- TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get(0, 0, NULL)); // invalid address
+ TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get_report(0, 0, NULL)); // invalid address
}
void test_keyboard_get_invalid_buffer(void)
{
tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
- TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get(dev_addr, 0, NULL)); // invalid buffer
+ TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get_report(dev_addr, 0, NULL)); // invalid buffer
}
void test_keyboard_get_device_not_ready(void)
{
tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_UNPLUG);
- TEST_ASSERT_EQUAL(TUSB_ERROR_DEVICE_NOT_READY, tusbh_hid_keyboard_get(dev_addr, 0, &report)); // device not mounted
+ TEST_ASSERT_EQUAL(TUSB_ERROR_DEVICE_NOT_READY, tusbh_hid_keyboard_get_report(dev_addr, 0, &report)); // device not mounted
}
void test_keyboard_get_report_xfer_failed()
@@ -164,7 +161,7 @@ void test_keyboard_get_report_xfer_failed()
hcd_pipe_xfer_ExpectAndReturn(p_hidh_kbd->pipe_hdl, (uint8_t*) &report, p_hidh_kbd->report_size, true, TUSB_ERROR_INVALID_PARA);
//------------- Code Under TEST -------------//
- TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get(dev_addr, 0, &report));
+ TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get_report(dev_addr, 0, &report));
}
void test_keyboard_get_ok()
@@ -173,6 +170,6 @@ void test_keyboard_get_ok()
hcd_pipe_xfer_ExpectAndReturn(p_hidh_kbd->pipe_hdl, (uint8_t*) &report, p_hidh_kbd->report_size, true, TUSB_ERROR_NONE);
//------------- Code Under TEST -------------//
- TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_hid_keyboard_get(dev_addr, 0, &report));
+ TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_hid_keyboard_get_report(dev_addr, 0, &report));
}