Home | History | Annotate | Line # | Download | only in libusbhid
t_usbhid.c revision 1.7
      1 /*	$NetBSD: t_usbhid.c,v 1.7 2016/01/03 15:16:10 jakllsch Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2016 Jonathan A. Kollasch
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
     20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     23  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     25  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     26  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __RCSID("$NetBSD: t_usbhid.c,v 1.7 2016/01/03 15:16:10 jakllsch Exp $");
     31 
     32 #include <atf-c.h>
     33 
     34 #include <inttypes.h>
     35 #include <usbhid.h>
     36 #include <string.h>
     37 
     38 #include <stdio.h>
     39 #include <stdlib.h>
     40 
     41 #include <limits.h>
     42 
     43 ATF_TC(check_hid_logical_range);
     44 ATF_TC(check_hid_physical_range);
     45 ATF_TC(check_hid_usage);
     46 ATF_TC(check_hid_get_data);
     47 ATF_TC(check_hid_set_data);
     48 
     49 #define MYd_ATF_CHECK_EQ(d, v) \
     50 	ATF_CHECK_EQ_MSG(d, v, "== %d", (d))
     51 
     52 #define MYu_ATF_CHECK_EQ(d, v) \
     53 	ATF_CHECK_EQ_MSG(d, v, "== %u", (d))
     54 
     55 #define MYx_ATF_CHECK_EQ(d, v) \
     56 	ATF_CHECK_EQ_MSG(d, v, "== 0x%x", (d))
     57 
     58 static const uint8_t range_test_report_descriptor[] = {
     59 	0x0b, 0x03, 0x00, 0x00, 0xff,	// Usage
     60 	0x75, 0x20,			// Report Size
     61 	0x95, 0x01,			// Report Count
     62 	0x17, 0x00, 0x00, 0x00, 0x80,	// Logical Minimum
     63 	0x27, 0xff, 0xff, 0xff, 0x7f,	// Logical Maximum
     64 	0x37, 0x00, 0x00, 0x00, 0x80,	// Physical Minimum
     65 	0x47, 0xff, 0xff, 0xff, 0x7f,	// Physical Maximum
     66 	0x81, 0x00,			// Input
     67 
     68 	0x0b, 0x02, 0x00, 0x00, 0xff,	// Usage
     69 	0x75, 0x10,			// Report Size
     70 	0x95, 0x01,			// Report Count
     71 	0x16, 0x00, 0x80,		// Logical Minimum
     72 	0x26, 0xff, 0x7f,		// Logical Maximum
     73 	0x36, 0x00, 0x80,		// Physical Minimum
     74 	0x46, 0xff, 0x7f,		// Physical Maximum
     75 	0x81, 0x00,			// Input
     76 
     77 	0x0b, 0x01, 0x00, 0x00, 0xff,	// Usage
     78 	0x75, 0x08,			// Report Size
     79 	0x95, 0x01,			// Report Count
     80 	0x15, 0x80,			// Logical Minimum
     81 	0x25, 0x7f,			// Logical Maximum
     82 	0x35, 0x80,			// Physical Minimum
     83 	0x45, 0x7f,			// Physical Maximum
     84 	0x81, 0x00,			// Input
     85 };
     86 
     87 static const uint8_t unsigned_range_test_report_descriptor[] = {
     88 	0x0b, 0x13, 0x00, 0x00, 0xff,	// Usage
     89 	0x75, 0x20,			// Report Size
     90 	0x95, 0x01,			// Report Count
     91 	0x17, 0x00, 0x00, 0x00, 0x00,	// Logical Minimum
     92 	0x27, 0xff, 0xff, 0xff, 0xff,	// Logical Maximum
     93 	0x37, 0x00, 0x00, 0x00, 0x00,	// Physical Minimum
     94 	0x47, 0xff, 0xff, 0xff, 0xff,	// Physical Maximum
     95 	0x81, 0x00,			// Input
     96 
     97 	0x0b, 0x12, 0x00, 0x00, 0xff,	// Usage
     98 	0x75, 0x10,			// Report Size
     99 	0x95, 0x01,			// Report Count
    100 	0x16, 0x00, 0x00,		// Logical Minimum
    101 	0x26, 0xff, 0xff,		// Logical Maximum
    102 	0x36, 0x00, 0x00,		// Physical Minimum
    103 	0x46, 0xff, 0xff,		// Physical Maximum
    104 	0x81, 0x00,			// Input
    105 
    106 	0x0b, 0x11, 0x00, 0x00, 0xff,	// Usage
    107 	0x75, 0x08,			// Report Size
    108 	0x95, 0x01,			// Report Count
    109 	0x15, 0x00,			// Logical Minimum
    110 	0x25, 0xff,			// Logical Maximum
    111 	0x35, 0x00,			// Physical Minimum
    112 	0x45, 0xff,			// Physical Maximum
    113 	0x81, 0x00,			// Input
    114 };
    115 
    116 static const uint8_t range_test_minimum_report[7] = {
    117 	0x00, 0x00, 0x00, 0x80,
    118 	0x00, 0x80,
    119 	0x80,
    120 };
    121 
    122 static const uint8_t unsigned_range_test_minimum_report[7] = {
    123 	0x00, 0x00, 0x00, 0x00,
    124 	0x00, 0x00,
    125 	0x00,
    126 };
    127 
    128 static const uint8_t range_test_maximum_report[7] = {
    129 	0xff, 0xff, 0xff, 0x7f,
    130 	0xff, 0x7f,
    131 	0x7f,
    132 };
    133 
    134 static const uint8_t unsigned_range_test_maximum_report[7] = {
    135 	0xff, 0xff, 0xff, 0xff,
    136 	0xff, 0xff,
    137 	0xff,
    138 };
    139 
    140 static const uint8_t range_test_positive_one_report[7] = {
    141 	0x01, 0x00, 0x00, 0x00,
    142 	0x01, 0x00,
    143 	0x01,
    144 };
    145 
    146 static const uint8_t unsigned_range_test_positive_one_report[7] = {
    147 	0x01, 0x00, 0x00, 0x00,
    148 	0x01, 0x00,
    149 	0x01,
    150 };
    151 
    152 static const uint8_t range_test_negative_one_report[7] = {
    153 	0xff, 0xff, 0xff, 0xff,
    154 	0xff, 0xff,
    155 	0xff,
    156 };
    157 
    158 static const uint8_t unsigned_range_test_negative_one_report[7] = {
    159 	0xfe, 0xff, 0xff, 0xff,
    160 	0xfe, 0xff,
    161 	0xfe,
    162 };
    163 
    164 ATF_TC_HEAD(check_hid_usage, tc)
    165 {
    166 
    167 	atf_tc_set_md_var(tc, "descr", "Test libusbhid usage.c");
    168 }
    169 
    170 ATF_TC_BODY(check_hid_usage, tc)
    171 {
    172 	char usages_path[PATH_MAX];
    173 
    174 	(void)strlcpy(usages_path, atf_tc_get_config_var(tc, "srcdir"),
    175 	    sizeof(usages_path));
    176 	(void)strlcat(usages_path, "/test_usb_hid_usages",
    177 	    sizeof(usages_path));
    178 
    179 	hid_init(usages_path);
    180 
    181 	ATF_CHECK_STREQ("t_usbhid_page", hid_usage_page(0xff1b));
    182 	ATF_CHECK_EQ((uint32_t)hid_parse_usage_page("t_usbhid_page"), 0xff1b);
    183 
    184 	ATF_CHECK_STREQ("t_usbhid_usage", hid_usage_in_page(0xff1bff2a));
    185 	ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
    186 	    "t_usbhid_page:t_usbhid_usage"), 0xff1bff2a);
    187 
    188 	ATF_CHECK_STREQ("Quick_zephyrs_blow_vexing_daft_Jim_",
    189 	    hid_usage_page(0xff2a));
    190 	ATF_CHECK_EQ((uint32_t)hid_parse_usage_page(
    191 	    "Quick_zephyrs_blow_vexing_daft_Jim_"), 0xff2a);
    192 
    193 	ATF_CHECK_STREQ("Usage_ID_Zero_%", hid_usage_in_page(0xff2a0000));
    194 	ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
    195 	    "Quick_zephyrs_blow_vexing_daft_Jim_:Usage_ID_Zero_%"),
    196 	    0xff2a0000);
    197 
    198 	//ATF_CHECK_STREQ("Usage_ID_0_%", hid_usage_in_page(0xff2a0000));
    199 	ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
    200 	    "Quick_zephyrs_blow_vexing_daft_Jim_:Usage_ID_0_%"), 0xff2a0000);
    201 
    202 	ATF_CHECK_STREQ("Usage_ID_65535_%", hid_usage_in_page(0xff2affff));
    203 	ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
    204 	    "Quick_zephyrs_blow_vexing_daft_Jim_:Usage_ID_65535_%"),
    205 	    0xff2affff);
    206 
    207 	MYx_ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page("0xff2a:0xff1b"),
    208 	    0xff2aff1b);
    209 }
    210 
    211 ATF_TC_HEAD(check_hid_logical_range, tc)
    212 {
    213 
    214 	atf_tc_set_md_var(tc, "descr", "Test hid_get_item "
    215 	    "Logical Minimum/Maximum results");
    216 }
    217 
    218 ATF_TC_BODY(check_hid_logical_range, tc)
    219 {
    220 	report_desc_t hrd;
    221 	hid_item_t hi;
    222 	uint32_t minimum, maximum;
    223 
    224 	atf_tc_expect_fail("only the 32-bit opcode works, "
    225 	    "8 and 16-bit is broken");
    226 
    227 	ATF_REQUIRE((hrd = hid_use_report_desc(range_test_report_descriptor,
    228 	    __arraycount(range_test_report_descriptor))) != NULL);
    229 	ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
    230 	    NO_REPORT_ID) > 0);
    231 	MYd_ATF_CHECK_EQ(hi.logical_minimum, -128);
    232 	MYd_ATF_CHECK_EQ(hi.logical_maximum, 127);
    233 	ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
    234 	    NO_REPORT_ID) > 0);
    235 	MYd_ATF_CHECK_EQ(hi.logical_minimum, -32768);
    236 	MYd_ATF_CHECK_EQ(hi.logical_maximum, 32767);
    237 	ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
    238 	    NO_REPORT_ID) > 0);
    239 	MYd_ATF_CHECK_EQ(hi.logical_minimum, -2147483648);
    240 	MYd_ATF_CHECK_EQ(hi.logical_maximum, 2147483647);
    241 
    242 	hid_dispose_report_desc(hrd);
    243 	hrd = NULL;
    244 
    245 	ATF_REQUIRE((hrd = hid_use_report_desc(
    246 	    unsigned_range_test_report_descriptor,
    247 	    __arraycount(unsigned_range_test_report_descriptor))) != NULL);
    248 	ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
    249 	    NO_REPORT_ID) > 0);
    250 	ATF_CHECK(hi.logical_minimum > hi.logical_maximum);
    251 	minimum = (uint32_t)hi.logical_minimum & ((1ULL<<hi.report_size)-1);
    252 	MYu_ATF_CHECK_EQ(minimum, 0);
    253 	maximum = (uint32_t)hi.logical_maximum & ((1ULL<<hi.report_size)-1);
    254 	MYu_ATF_CHECK_EQ(maximum, 255);
    255 	ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
    256 	    NO_REPORT_ID) > 0);
    257 	ATF_CHECK(hi.logical_minimum > hi.logical_maximum);
    258 	minimum = hi.logical_minimum & ((1ULL<<hi.report_size)-1);
    259 	MYu_ATF_CHECK_EQ(minimum, 0);
    260 	maximum = hi.logical_maximum & ((1ULL<<hi.report_size)-1);
    261 	MYu_ATF_CHECK_EQ(maximum, 65535);
    262 	ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
    263 	    NO_REPORT_ID) > 0);
    264 	ATF_CHECK(hi.logical_minimum > hi.logical_maximum);
    265 	minimum = hi.logical_minimum & ((1ULL<<hi.report_size)-1);
    266 	MYu_ATF_CHECK_EQ(minimum, 0);
    267 	maximum = hi.logical_maximum & ((1ULL<<hi.report_size)-1);
    268 	MYu_ATF_CHECK_EQ(maximum, 4294967295);
    269 
    270 	hid_dispose_report_desc(hrd);
    271 	hrd = NULL;
    272 }
    273 
    274 ATF_TC_HEAD(check_hid_physical_range, tc)
    275 {
    276 
    277 	atf_tc_set_md_var(tc, "descr", "Test hid_get_item "
    278 	    "Physical Minimum/Maximum results");
    279 }
    280 
    281 ATF_TC_BODY(check_hid_physical_range, tc)
    282 {
    283 	report_desc_t hrd;
    284 	hid_item_t hi;
    285 	uint32_t minimum, maximum;
    286 
    287 	atf_tc_expect_fail("only the 32-bit opcode works, "
    288 	    "8 and 16-bit is broken");
    289 
    290 	ATF_REQUIRE((hrd = hid_use_report_desc(range_test_report_descriptor,
    291 	    __arraycount(range_test_report_descriptor))) != NULL);
    292 	ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
    293 	    NO_REPORT_ID) > 0);
    294 	MYd_ATF_CHECK_EQ(hi.physical_minimum, -128);
    295 	MYd_ATF_CHECK_EQ(hi.physical_maximum, 127);
    296 	ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
    297 	    NO_REPORT_ID) > 0);
    298 	MYd_ATF_CHECK_EQ(hi.physical_minimum, -32768);
    299 	MYd_ATF_CHECK_EQ(hi.physical_maximum, 32767);
    300 	ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
    301 	    NO_REPORT_ID) > 0);
    302 	MYd_ATF_CHECK_EQ(hi.physical_minimum, -2147483648);
    303 	MYd_ATF_CHECK_EQ(hi.physical_maximum, 2147483647);
    304 
    305 	hid_dispose_report_desc(hrd);
    306 	hrd = NULL;
    307 
    308 	ATF_REQUIRE((hrd = hid_use_report_desc(
    309 	    unsigned_range_test_report_descriptor,
    310 	    __arraycount(unsigned_range_test_report_descriptor))) != NULL);
    311 	ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
    312 	    NO_REPORT_ID) > 0);
    313 	ATF_CHECK(hi.physical_minimum > hi.physical_maximum);
    314 	minimum = (uint32_t)hi.physical_minimum & ((1ULL<<hi.report_size)-1);
    315 	MYu_ATF_CHECK_EQ(minimum, 0);
    316 	maximum = (uint32_t)hi.physical_maximum & ((1ULL<<hi.report_size)-1);
    317 	MYu_ATF_CHECK_EQ(maximum, 255);
    318 	ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
    319 	    NO_REPORT_ID) > 0);
    320 	ATF_CHECK(hi.physical_minimum > hi.physical_maximum);
    321 	minimum = hi.physical_minimum & ((1ULL<<hi.report_size)-1);
    322 	MYu_ATF_CHECK_EQ(minimum, 0);
    323 	maximum = hi.physical_maximum & ((1ULL<<hi.report_size)-1);
    324 	MYu_ATF_CHECK_EQ(maximum, 65535);
    325 	ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
    326 	    NO_REPORT_ID) > 0);
    327 	ATF_CHECK(hi.physical_minimum > hi.physical_maximum);
    328 	minimum = hi.physical_minimum & ((1ULL<<hi.report_size)-1);
    329 	MYu_ATF_CHECK_EQ(minimum, 0);
    330 	maximum = hi.physical_maximum & ((1ULL<<hi.report_size)-1);
    331 	MYu_ATF_CHECK_EQ(maximum, 4294967295);
    332 
    333 	hid_dispose_report_desc(hrd);
    334 	hrd = NULL;
    335 }
    336 
    337 ATF_TC_HEAD(check_hid_get_data, tc)
    338 {
    339 
    340 	atf_tc_set_md_var(tc, "descr", "Test hid_get_data results");
    341 }
    342 
    343 ATF_TC_BODY(check_hid_get_data, tc)
    344 {
    345 	report_desc_t hrd;
    346 	hid_item_t hi;
    347 	int32_t data;
    348 	uint32_t udat;
    349 
    350 	ATF_REQUIRE((hrd = hid_use_report_desc(
    351 	    range_test_report_descriptor,
    352 	    __arraycount(range_test_report_descriptor))) != NULL);
    353 
    354 	ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
    355 	    NO_REPORT_ID) > 0);
    356 	data = hid_get_data(range_test_minimum_report, &hi);
    357 	MYd_ATF_CHECK_EQ(data, -128);
    358 	data = hid_get_data(range_test_negative_one_report, &hi);
    359 	MYd_ATF_CHECK_EQ(data, -1);
    360 	data = hid_get_data(range_test_positive_one_report, &hi);
    361 	MYd_ATF_CHECK_EQ(data, 1);
    362 	data = hid_get_data(range_test_maximum_report, &hi);
    363 	MYd_ATF_CHECK_EQ(data, 127);
    364 
    365 	ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
    366 	    NO_REPORT_ID) > 0);
    367 	data = hid_get_data(range_test_minimum_report, &hi);
    368 	MYd_ATF_CHECK_EQ(data, -32768);
    369 	data = hid_get_data(range_test_negative_one_report, &hi);
    370 	MYd_ATF_CHECK_EQ(data, -1);
    371 	data = hid_get_data(range_test_positive_one_report, &hi);
    372 	MYd_ATF_CHECK_EQ(data, 1);
    373 	data = hid_get_data(range_test_maximum_report, &hi);
    374 	MYd_ATF_CHECK_EQ(data, 32767);
    375 
    376 	ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
    377 	    NO_REPORT_ID) > 0);
    378 	data = hid_get_data(range_test_minimum_report, &hi);
    379 	MYd_ATF_CHECK_EQ(data, -2147483648);
    380 	data = hid_get_data(range_test_negative_one_report, &hi);
    381 	MYd_ATF_CHECK_EQ(data, -1);
    382 	data = hid_get_data(range_test_positive_one_report, &hi);
    383 	MYd_ATF_CHECK_EQ(data, 1);
    384 	data = hid_get_data(range_test_maximum_report, &hi);
    385 	MYd_ATF_CHECK_EQ(data, 2147483647);
    386 
    387 	hid_dispose_report_desc(hrd);
    388 	hrd = NULL;
    389 
    390 	ATF_REQUIRE((hrd = hid_use_report_desc(
    391 	    unsigned_range_test_report_descriptor,
    392 	    __arraycount(unsigned_range_test_report_descriptor))) != NULL);
    393 	ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
    394 	    NO_REPORT_ID) > 0);
    395 	udat = hid_get_data(unsigned_range_test_minimum_report, &hi);
    396 	MYu_ATF_CHECK_EQ(udat, 0);
    397 	udat = hid_get_data(unsigned_range_test_positive_one_report, &hi);
    398 	MYu_ATF_CHECK_EQ(udat, 1);
    399 	udat = hid_get_data(unsigned_range_test_negative_one_report, &hi);
    400 	MYu_ATF_CHECK_EQ(udat, 254);
    401 	udat = hid_get_data(unsigned_range_test_maximum_report, &hi);
    402 	MYu_ATF_CHECK_EQ(udat, 255);
    403 
    404 	ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
    405 	    NO_REPORT_ID) > 0);
    406 	udat = hid_get_data(unsigned_range_test_minimum_report, &hi);
    407 	MYu_ATF_CHECK_EQ(udat, 0);
    408 	udat = hid_get_data(unsigned_range_test_positive_one_report, &hi);
    409 	MYu_ATF_CHECK_EQ(udat, 1);
    410 	udat = hid_get_data(unsigned_range_test_negative_one_report, &hi);
    411 	MYu_ATF_CHECK_EQ(udat, 65534);
    412 	udat = hid_get_data(unsigned_range_test_maximum_report, &hi);
    413 	MYu_ATF_CHECK_EQ(udat, 65535);
    414 
    415 	ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
    416 	    NO_REPORT_ID) > 0);
    417 	udat = hid_get_data(unsigned_range_test_minimum_report, &hi);
    418 	MYu_ATF_CHECK_EQ(udat, 0);
    419 	udat = hid_get_data(unsigned_range_test_positive_one_report, &hi);
    420 	MYu_ATF_CHECK_EQ(udat, 1);
    421 	udat = hid_get_data(unsigned_range_test_negative_one_report, &hi);
    422 	MYu_ATF_CHECK_EQ(udat, 4294967294);
    423 	udat = hid_get_data(unsigned_range_test_maximum_report, &hi);
    424 	MYu_ATF_CHECK_EQ(udat, 4294967295);
    425 
    426 	hid_dispose_report_desc(hrd);
    427 	hrd = NULL;
    428 }
    429 
    430 ATF_TC_HEAD(check_hid_set_data, tc)
    431 {
    432 
    433 	atf_tc_set_md_var(tc, "descr", "Test hid_set_data results");
    434 }
    435 
    436 ATF_TC_BODY(check_hid_set_data, tc)
    437 {
    438 	report_desc_t hrd;
    439 	hid_item_t hi;
    440 	uint8_t test_data_minimum[7];
    441 	uint8_t test_data_negative_one[7];
    442 	uint8_t test_data_positive_one[7];
    443 	uint8_t test_data_maximum[7];
    444 
    445 	ATF_REQUIRE((hrd = hid_use_report_desc(
    446 	    range_test_report_descriptor,
    447 	    __arraycount(range_test_report_descriptor))) != NULL);
    448 	ATF_REQUIRE(hid_locate(hrd, 0xff000001U, hid_input, &hi,
    449 	    NO_REPORT_ID) > 0);
    450 	hid_set_data(test_data_minimum, &hi, -128);
    451 	hid_set_data(test_data_negative_one, &hi, -1);
    452 	hid_set_data(test_data_positive_one, &hi, 1);
    453 	hid_set_data(test_data_maximum, &hi, 127);
    454 	ATF_REQUIRE(hid_locate(hrd, 0xff000002U, hid_input, &hi,
    455 	    NO_REPORT_ID) > 0);
    456 	hid_set_data(test_data_minimum, &hi, -32768);
    457 	hid_set_data(test_data_negative_one, &hi, -1);
    458 	hid_set_data(test_data_positive_one, &hi, 1);
    459 	hid_set_data(test_data_maximum, &hi, 32767);
    460 	ATF_REQUIRE(hid_locate(hrd, 0xff000003U, hid_input, &hi,
    461 	    NO_REPORT_ID) > 0);
    462 	hid_set_data(test_data_minimum, &hi, -2147483648);
    463 	hid_set_data(test_data_negative_one, &hi, -1);
    464 	hid_set_data(test_data_positive_one, &hi, 1);
    465 	hid_set_data(test_data_maximum, &hi, 2147483647);
    466 	ATF_CHECK(memcmp(test_data_minimum, range_test_minimum_report,
    467 	    sizeof test_data_minimum) == 0);
    468 	ATF_CHECK(memcmp(test_data_negative_one,
    469 	    range_test_negative_one_report,
    470 	    sizeof test_data_negative_one) == 0);
    471 	ATF_CHECK(memcmp(test_data_positive_one,
    472 	    range_test_positive_one_report,
    473 	    sizeof test_data_positive_one) == 0);
    474 	ATF_CHECK(memcmp(test_data_maximum, range_test_maximum_report,
    475 	    sizeof test_data_maximum) == 0);
    476 
    477 	hid_dispose_report_desc(hrd);
    478 	hrd = NULL;
    479 
    480 	ATF_REQUIRE((hrd = hid_use_report_desc(
    481 	    unsigned_range_test_report_descriptor,
    482 	    __arraycount(range_test_report_descriptor))) != NULL);
    483 	ATF_REQUIRE(hid_locate(hrd, 0xff000011U, hid_input, &hi,
    484 	    NO_REPORT_ID) > 0);
    485 	hid_set_data(test_data_minimum, &hi, 0);
    486 	hid_set_data(test_data_positive_one, &hi, 1);
    487 	hid_set_data(test_data_negative_one, &hi, 0xfffffffe);
    488 	hid_set_data(test_data_maximum, &hi, 0xffffffff);
    489 	ATF_REQUIRE(hid_locate(hrd, 0xff000012U, hid_input, &hi,
    490 	    NO_REPORT_ID) > 0);
    491 	hid_set_data(test_data_minimum, &hi, 0);
    492 	hid_set_data(test_data_positive_one, &hi, 1);
    493 	hid_set_data(test_data_negative_one, &hi, 0xfffe);
    494 	hid_set_data(test_data_maximum, &hi, 0xffff);
    495 	ATF_REQUIRE(hid_locate(hrd, 0xff000013U, hid_input, &hi,
    496 	    NO_REPORT_ID) > 0);
    497 	hid_set_data(test_data_minimum, &hi, 0);
    498 	hid_set_data(test_data_positive_one, &hi, 1);
    499 	hid_set_data(test_data_negative_one, &hi, 0xfffffffe);
    500 	hid_set_data(test_data_maximum, &hi, 0xffffffff);
    501 	ATF_CHECK(memcmp(test_data_minimum,
    502 	    unsigned_range_test_minimum_report,
    503 	    sizeof test_data_minimum) == 0);
    504 	ATF_CHECK(memcmp(test_data_negative_one,
    505 	    unsigned_range_test_negative_one_report,
    506 	    sizeof test_data_negative_one) == 0);
    507 	ATF_CHECK(memcmp(test_data_positive_one,
    508 	    unsigned_range_test_positive_one_report,
    509 	    sizeof test_data_positive_one) == 0);
    510 	ATF_CHECK(memcmp(test_data_maximum,
    511 	    unsigned_range_test_maximum_report,
    512 	    sizeof test_data_maximum) == 0);
    513 
    514 	hid_dispose_report_desc(hrd);
    515 	hrd = NULL;
    516 }
    517 
    518 ATF_TP_ADD_TCS(tp)
    519 {
    520 
    521 	ATF_TP_ADD_TC(tp, check_hid_logical_range);
    522 	ATF_TP_ADD_TC(tp, check_hid_physical_range);
    523 	ATF_TP_ADD_TC(tp, check_hid_usage);
    524 	ATF_TP_ADD_TC(tp, check_hid_get_data);
    525 	ATF_TP_ADD_TC(tp, check_hid_set_data);
    526 
    527 	return atf_no_error();
    528 }
    529