-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathusb_endpoint_descriptor_test.cc
81 lines (66 loc) · 2.62 KB
/
usb_endpoint_descriptor_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mist/usb_endpoint_descriptor.h"
#include <libusb.h>
#include <gtest/gtest.h>
namespace mist {
TEST(UsbEndpointDescriptorTest, TrivialGetters) {
libusb_endpoint_descriptor descriptor;
descriptor.bLength = 7;
descriptor.bDescriptorType = LIBUSB_DT_ENDPOINT;
descriptor.bEndpointAddress = 0x81;
descriptor.bmAttributes = 0x3;
descriptor.wMaxPacketSize = 64;
descriptor.bInterval = 32;
UsbEndpointDescriptor endpoint_descriptor(&descriptor);
EXPECT_EQ(7, endpoint_descriptor.GetLength());
EXPECT_EQ(LIBUSB_DT_ENDPOINT, endpoint_descriptor.GetDescriptorType());
EXPECT_EQ(0x81, endpoint_descriptor.GetEndpointAddress());
EXPECT_EQ(1, endpoint_descriptor.GetEndpointNumber());
EXPECT_EQ(0x3, endpoint_descriptor.GetAttributes());
EXPECT_EQ(64, endpoint_descriptor.GetMaxPacketSize());
EXPECT_EQ(32, endpoint_descriptor.GetInterval());
}
TEST(UsbEndpointDescriptorTest, GetDirection) {
{
libusb_endpoint_descriptor descriptor;
descriptor.bEndpointAddress = LIBUSB_ENDPOINT_IN | 0x1;
UsbEndpointDescriptor endpoint_descriptor(&descriptor);
EXPECT_EQ(kUsbDirectionIn, endpoint_descriptor.GetDirection());
}
{
libusb_endpoint_descriptor descriptor;
descriptor.bEndpointAddress = LIBUSB_ENDPOINT_OUT | 0x1;
UsbEndpointDescriptor endpoint_descriptor(&descriptor);
EXPECT_EQ(kUsbDirectionOut, endpoint_descriptor.GetDirection());
}
}
TEST(UsbEndpointDescriptorTest, GetTransferType) {
{
libusb_endpoint_descriptor descriptor;
descriptor.bmAttributes = LIBUSB_TRANSFER_TYPE_CONTROL;
UsbEndpointDescriptor endpoint_descriptor(&descriptor);
EXPECT_EQ(kUsbTransferTypeControl, endpoint_descriptor.GetTransferType());
}
{
libusb_endpoint_descriptor descriptor;
descriptor.bmAttributes = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS;
UsbEndpointDescriptor endpoint_descriptor(&descriptor);
EXPECT_EQ(kUsbTransferTypeIsochronous,
endpoint_descriptor.GetTransferType());
}
{
libusb_endpoint_descriptor descriptor;
descriptor.bmAttributes = LIBUSB_TRANSFER_TYPE_BULK;
UsbEndpointDescriptor endpoint_descriptor(&descriptor);
EXPECT_EQ(kUsbTransferTypeBulk, endpoint_descriptor.GetTransferType());
}
{
libusb_endpoint_descriptor descriptor;
descriptor.bmAttributes = LIBUSB_TRANSFER_TYPE_INTERRUPT;
UsbEndpointDescriptor endpoint_descriptor(&descriptor);
EXPECT_EQ(kUsbTransferTypeInterrupt, endpoint_descriptor.GetTransferType());
}
}
} // namespace mist