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_device_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_device_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_device_printer APIs Test.................................. ");
56 #if !defined(UX_DEVICE_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_DEVICE_CLASS_PRINTER                 dummy_printer_inst;
97 UX_DEVICE_CLASS_PRINTER                 *dummy_printer = &dummy_printer_inst;
98 UCHAR                                   dummy_buffer[32];
99 ULONG                                   dummy_actual_length;
100 UX_SLAVE_CLASS_COMMAND                  dummy_command;
101 UX_DEVICE_CLASS_PRINTER_PARAMETER       dummy_printer_parameter;
102 
103 #if !defined(UX_DEVICE_STANDALONE)
104 /* Device printer device ID.  */
105 UCHAR printer_device_id[] =
106  {
107     "  "                                // Will be replaced by length (big endian)
108     "MFG:Generic;"                      //   manufacturer (case sensitive)
109     "MDL:Generic_/_Text_Only;"          //   model (case sensitive)
110     "CMD:1284.4;"                       //   PDL command set
111     "CLS:PRINTER;"                      //   class
112     "DES:Generic text only printer;"    //   description
113  };
114 
115     dummy_printer_parameter.ux_device_class_printer_device_id = printer_device_id;
116     dummy_command.ux_slave_class_command_parameter = &dummy_printer_parameter;
117 
118     /* ux_device_class_printer_entry()  */
119     dummy_command.ux_slave_class_command_request = UX_SLAVE_CLASS_COMMAND_INITIALIZE;
120 
121     printer_device_id[0] = 2;
122     printer_device_id[1] = 1;
123     status = ux_device_class_printer_entry(&dummy_command);
124     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
125 
126     /* ux_device_class_printer_write()  */
127     status = ux_device_class_printer_write(UX_NULL, dummy_buffer, 32, &dummy_actual_length);
128     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
129 
130     status = ux_device_class_printer_write(dummy_printer, UX_NULL, 32, &dummy_actual_length);
131     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
132 
133     status = ux_device_class_printer_write(dummy_printer, dummy_buffer, 32, UX_NULL);
134     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
135 
136     /* ux_device_class_printer_read()  */
137     status = ux_device_class_printer_read(UX_NULL, dummy_buffer, 32, &dummy_actual_length);
138     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
139 
140     status = ux_device_class_printer_read(dummy_printer, UX_NULL, 32, &dummy_actual_length);
141     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
142 
143     status = ux_device_class_printer_read(dummy_printer, dummy_buffer, 32, UX_NULL);
144     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
145 
146     /* ux_device_class_printer_ioctl()  */
147     status = ux_device_class_printer_ioctl(UX_NULL, UX_DEVICE_CLASS_PRINTER_IOCTL_PORT_STATUS_SET, 0);
148     UX_TEST_CHECK_CODE(UX_INVALID_PARAMETER, status);
149 #else
150 
151    /* ux_device_class_printer_read_run()  */
152     status = ux_device_class_printer_read_run(UX_NULL, dummy_buffer, 32, &dummy_actual_length);
153     UX_TEST_CHECK_CODE(UX_STATE_ERROR, status);
154 
155     status = ux_device_class_printer_read_run(&dummy_printer_inst, UX_NULL, 32, &dummy_actual_length);
156     UX_TEST_CHECK_CODE(UX_STATE_ERROR, status);
157 
158     status = ux_device_class_printer_read_run(&dummy_printer_inst, dummy_buffer, 32, UX_NULL);
159     UX_TEST_CHECK_CODE(UX_STATE_ERROR, status);
160 
161     /* ux_device_class_cdc_acm_write_run()  */
162     status = ux_device_class_printer_write_run(UX_NULL, dummy_buffer, 32, &dummy_actual_length);
163     UX_TEST_CHECK_CODE(UX_STATE_ERROR, status);
164 
165     status = ux_device_class_printer_write_run(&dummy_printer_inst, UX_NULL, 32, &dummy_actual_length);
166     UX_TEST_CHECK_CODE(UX_STATE_ERROR, status);
167 
168     status = ux_device_class_printer_write_run(&dummy_printer_inst, dummy_buffer, 32, UX_NULL);
169     UX_TEST_CHECK_CODE(UX_STATE_ERROR, status);
170 
171 #endif
172 
173     /* Sleep for a tick to make sure everything is complete.  */
174     tx_thread_sleep(1);
175 
176     /* Check for errors from other threads.  */
177     if (error_counter)
178     {
179 
180         /* Test error.  */
181         printf("ERROR #%d: total %ld errors\n", __LINE__, error_counter);
182         test_control_return(1);
183     }
184     else
185     {
186 
187         /* Successful test.  */
188         printf("SUCCESS!\n");
189         test_control_return(0);
190     }
191 }
192