Consolidates app id comparison
[chromium-blink-merge.git] / device / usb / usb_descriptors_unittest.cc
blob2db06cb1a83da7ba9d5a3fa8add25dc8af0de021
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/strings/utf_string_conversions.h"
6 #include "device/usb/usb_descriptors.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace device {
11 namespace {
13 class UsbDescriptorsTest : public ::testing::Test {};
15 TEST_F(UsbDescriptorsTest, StringDescriptor) {
16 static const uint8_t kBuffer[] = {0x1a, 0x03, 'H', 0, 'e', 0, 'l', 0, 'l', 0,
17 'o', 0, ' ', 0, 'w', 0, 'o', 0, 'r', 0,
18 'l', 0, 'd', 0, '!', 0};
19 base::string16 string;
20 ASSERT_TRUE(ParseUsbStringDescriptor(
21 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer)), &string));
22 EXPECT_EQ(base::ASCIIToUTF16("Hello world!"), string);
25 TEST_F(UsbDescriptorsTest, ShortStringDescriptorHeader) {
26 // The buffer is just too darn short.
27 static const uint8_t kBuffer[] = {0x01};
28 base::string16 string;
29 ASSERT_FALSE(ParseUsbStringDescriptor(
30 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer)), &string));
33 TEST_F(UsbDescriptorsTest, ShortStringDescriptor) {
34 // The buffer is just too darn short.
35 static const uint8_t kBuffer[] = {0x01, 0x03};
36 base::string16 string;
37 ASSERT_FALSE(ParseUsbStringDescriptor(
38 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer)), &string));
41 TEST_F(UsbDescriptorsTest, OddLengthStringDescriptor) {
42 // There's an extra byte at the end of the string.
43 static const uint8_t kBuffer[] = {0x0d, 0x03, 'H', 0, 'e', 0, 'l',
44 0, 'l', 0, 'o', 0, '!'};
45 base::string16 string;
46 ASSERT_TRUE(ParseUsbStringDescriptor(
47 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer)), &string));
48 EXPECT_EQ(base::ASCIIToUTF16("Hello"), string);
51 TEST_F(UsbDescriptorsTest, EmptyStringDescriptor) {
52 // The string is empty.
53 static const uint8_t kBuffer[] = {0x02, 0x03};
54 base::string16 string;
55 ASSERT_TRUE(ParseUsbStringDescriptor(
56 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer)), &string));
57 EXPECT_EQ(base::string16(), string);
60 TEST_F(UsbDescriptorsTest, OneByteStringDescriptor) {
61 // The string is only one byte.
62 static const uint8_t kBuffer[] = {0x03, 0x03, '?'};
63 base::string16 string;
64 ASSERT_TRUE(ParseUsbStringDescriptor(
65 std::vector<uint8_t>(kBuffer, kBuffer + sizeof(kBuffer)), &string));
66 EXPECT_EQ(base::string16(), string);
69 } // namespace
71 } // namespace device