7
7
8
8
#include "../hid.c"
9
9
10
- static ssize_t parse_max_input_report_size (const char * filename )
10
+ struct max_report_sizes {
11
+ size_t input ;
12
+ size_t output ;
13
+ size_t feature ;
14
+ };
15
+
16
+ static int parse_max_input_report_size (const char * filename , struct max_report_sizes * sizes )
11
17
{
12
18
FILE * file = fopen (filename , "r" );
13
19
if (file == NULL ) {
@@ -20,16 +26,20 @@ static ssize_t parse_max_input_report_size(const char * filename)
20
26
while (fgets (line , sizeof (line ), file ) != NULL ) {
21
27
unsigned short temp_ushort ;
22
28
if (sscanf (line , "pp_data->caps_info[0]->ReportByteLength = %hu\n" , & temp_ushort ) == 1 ) {
23
- fclose (file );
24
- return (ssize_t )temp_ushort ;
29
+ sizes -> input = (size_t )temp_ushort ;
30
+ }
31
+ if (sscanf (line , "pp_data->caps_info[1]->ReportByteLength = %hu\n" , & temp_ushort ) == 1 ) {
32
+ sizes -> output = (size_t )temp_ushort ;
33
+ }
34
+ if (sscanf (line , "pp_data->caps_info[2]->ReportByteLength = %hu\n" , & temp_ushort ) == 1 ) {
35
+ sizes -> feature = (size_t )temp_ushort ;
25
36
}
26
37
}
27
38
}
28
39
29
- fprintf (stderr , "Unable to find pp_data->caps_info[0]->ReportByteLength in %s\n" , filename );
30
40
fclose (file );
31
41
32
- return -1 ;
42
+ return 0 ;
33
43
}
34
44
35
45
static bool read_hex_data_from_text_file (const char * filename , unsigned char * data_out , size_t data_size , size_t * actual_read )
@@ -97,19 +107,36 @@ int main(int argc, char* argv[])
97
107
return EXIT_FAILURE ;
98
108
}
99
109
100
- ssize_t expected = parse_max_input_report_size ( argv [ 1 ]) ;
101
- if (expected < 0 ) {
102
- fprintf (stderr , "Unable to expected max input report size from %s\n" , argv [1 ]);
110
+ struct max_report_sizes expected ;
111
+ if (parse_max_input_report_size ( argv [ 1 ], & expected ) < 0 ) {
112
+ fprintf (stderr , "Unable to get expected max report sizes from %s\n" , argv [1 ]);
103
113
return EXIT_FAILURE ;
104
114
}
105
115
106
- ssize_t res = (ssize_t )get_max_input_report_size (report_descriptor , report_descriptor_size );
116
+ struct max_report_sizes computed = {
117
+ .input = (size_t )get_max_report_size (report_descriptor , report_descriptor_size , REPORT_DESCR_INPUT ),
118
+ .output = (size_t )get_max_report_size (report_descriptor , report_descriptor_size , REPORT_DESCR_OUTPUT ),
119
+ .feature = (size_t )get_max_report_size (report_descriptor , report_descriptor_size , REPORT_DESCR_FEATURE )
120
+ };
107
121
108
- if (res != expected ) {
109
- fprintf (stderr , "Failed to properly compute size. Got %zd, expected %zd\n" , res , expected );
110
- return EXIT_FAILURE ;
111
- } else {
112
- printf ("Properly computed size: %zd\n" , res );
113
- return EXIT_SUCCESS ;
122
+ int ret = EXIT_SUCCESS ;
123
+
124
+ if (expected .input != computed .input ) {
125
+ fprintf (stderr , "Failed to properly compute input size. Got %zu, expected %zu\n" , computed .input , expected .input );
126
+ ret = EXIT_FAILURE ;
114
127
}
128
+ if (expected .output != computed .output ) {
129
+ fprintf (stderr , "Failed to properly compute output size. Got %zu, expected %zu\n" , computed .output , expected .output );
130
+ ret = EXIT_FAILURE ;
131
+ }
132
+ if (expected .feature != computed .feature ) {
133
+ fprintf (stderr , "Failed to properly compute feature size. Got %zu, expected %zu\n" , computed .feature , expected .feature );
134
+ ret = EXIT_FAILURE ;
135
+ }
136
+
137
+ if (ret == EXIT_SUCCESS ) {
138
+ printf ("Properly computed sizes: %zu, %zu, %zu\n" , computed .input , computed .output , computed .feature );
139
+ }
140
+
141
+ return ret ;
115
142
}
0 commit comments