1 /* This test is designed to test the ux_utility_descriptor_pack.  */
2 
3 #include <stdio.h>
4 #include "tx_api.h"
5 #include "ux_api.h"
6 #include "ux_system.h"
7 #include "ux_utility.h"
8 
9 #include "ux_host_stack.h"
10 #include "ux_device_stack.h"
11 
12 #include "ux_host_class_printer.h"
13 
14 #include "ux_test.h"
15 
16 /* Define USBX test constants.  */
17 
18 #define UX_TEST_STACK_SIZE      4096
19 #define UX_TEST_BUFFER_SIZE     2048
20 #define UX_TEST_MEMORY_SIZE     (64*1024)
21 
22 
23 /* Define the counters used in the test application...  */
24 
25 static ULONG                           error_counter = 0;
26 
27 /* Define USBX test global variables.  */
28 
29 
30 /* Define prototypes for external Host Controller's (HCDs), classes and clients.  */
31 
32 static TX_THREAD           ux_test_thread_simulation_0;
33 static void                ux_test_thread_simulation_0_entry(ULONG);
34 
35 
36 /* Prototype for test control return.  */
37 
38 void  test_control_return(UINT status);
39 
40 
41 /* Define what the initial system looks like.  */
42 
43 #ifdef CTEST
test_application_define(void * first_unused_memory)44 void test_application_define(void *first_unused_memory)
45 #else
46 void usbx_uxe_host_printer_test_application_define(void *first_unused_memory)
47 #endif
48 {
49 
50 UINT status;
51 CHAR                            *stack_pointer;
52 CHAR                            *memory_pointer;
53 
54     /* Inform user.  */
55     printf("Running uxe_host_printer APIs Test.................................... ");
56 #if !defined(UX_HOST_CLASS_PRINTER_ENABLE_ERROR_CHECKING)
57 #warning Tests skipped due to compile option!
58     printf("SKIP SUCCESS!\n");
59     test_control_return(0);
60     return;
61 #endif
62 
63     /* Initialize the free memory pointer.  */
64     stack_pointer = (CHAR *) first_unused_memory;
65     memory_pointer = stack_pointer + (UX_TEST_STACK_SIZE * 2);
66 
67     /* Initialize USBX Memory.  */
68     status =  ux_system_initialize(memory_pointer, UX_TEST_MEMORY_SIZE, UX_NULL, 0);
69 
70     /* Check for error.  */
71     if (status != UX_SUCCESS)
72     {
73 
74         printf("ERROR #%d\n", __LINE__);
75         test_control_return(1);
76     }
77 
78     /* Create the simulation thread.  */
79     status =  tx_thread_create(&ux_test_thread_simulation_0, "test simulation", ux_test_thread_simulation_0_entry, 0,
80             stack_pointer, UX_TEST_STACK_SIZE,
81             20, 20, 1, TX_AUTO_START);
82 
83     /* Check for error.  */
84     if (status != TX_SUCCESS)
85     {
86 
87         printf("ERROR #%d\n", __LINE__);
88         test_control_return(1);
89     }
90 }
91 
92 
ux_test_thread_simulation_0_entry(ULONG arg)93 static void  ux_test_thread_simulation_0_entry(ULONG arg)
94 {
95 UINT                                            status;
96 UX_HOST_CLASS_PRINTER                           dummy_printer_inst;
97 UX_HOST_CLASS_PRINTER                           *dummy_printer = &dummy_printer_inst;
98 UCHAR                                           dummy_buffer[64];
99 ULONG                                           actual_length;
100 ULONG                                           printer_status;
101 
102     /* ux_host_class_printer_name_get()  */
103     status = ux_host_class_printer_name_get(UX_NULL);
104     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
105 
106     /* ux_host_class_printer_device_id_get() */
107     status = ux_host_class_printer_device_id_get(UX_NULL, dummy_buffer, 64);
108     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
109 
110     status = ux_host_class_printer_device_id_get(dummy_printer, UX_NULL, 64);
111     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
112 
113     status = ux_host_class_printer_device_id_get(dummy_printer, dummy_buffer, 0);
114     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
115 
116     /* ux_host_class_printer_read() */
117     status = ux_host_class_printer_read(UX_NULL, dummy_buffer, 64, &actual_length);
118     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
119 
120     status = ux_host_class_printer_read(dummy_printer, UX_NULL, 64, &actual_length);
121     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
122 
123     status = ux_host_class_printer_read(dummy_printer, dummy_buffer, 64, UX_NULL);
124     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
125 
126     /* ux_host_class_printer_soft_reset() */
127     status = ux_host_class_printer_soft_reset(UX_NULL);
128     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
129 
130     /* ux_host_class_printer_status_get() */
131     status = ux_host_class_printer_status_get(UX_NULL, &printer_status);
132     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
133 
134     status = ux_host_class_printer_status_get(dummy_printer, UX_NULL);
135     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
136 
137     /* ux_host_class_printer_write() */
138     status = ux_host_class_printer_write(UX_NULL, dummy_buffer, 64, &actual_length);
139     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
140 
141     status = ux_host_class_printer_write(dummy_printer, UX_NULL, 64, &actual_length);
142     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
143 
144     status = ux_host_class_printer_write(dummy_printer, dummy_buffer, 64, UX_NULL);
145     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
146 
147     /* Sleep for a tick to make sure everything is complete.  */
148     tx_thread_sleep(1);
149 
150     /* Check for errors from other threads.  */
151     if (error_counter)
152     {
153 
154         /* Test error.  */
155         printf("ERROR #%d: total %ld errors\n", __LINE__, error_counter);
156         test_control_return(1);
157     }
158     else
159     {
160 
161         /* Successful test.  */
162         printf("SUCCESS!\n");
163         test_control_return(0);
164     }
165 }
166