GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / device / hid / hid_report_descriptor_unittest.cc
blob308780cdba441d0ed06b5cca7481aa16ef93586f
1 // Copyright (c) 2014 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 <sstream>
7 #include "device/hid/hid_report_descriptor.h"
8 #include "device/hid/test_report_descriptors.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 using namespace testing;
14 namespace device {
16 class HidReportDescriptorTest : public testing::Test {
18 protected:
19 void SetUp() override { descriptor_ = NULL; }
21 void TearDown() override {
22 if (descriptor_) {
23 delete descriptor_;
27 public:
28 void ValidateDetails(
29 const std::vector<HidCollectionInfo>& expected_collections,
30 const bool expected_has_report_id,
31 const size_t expected_max_input_report_size,
32 const size_t expected_max_output_report_size,
33 const size_t expected_max_feature_report_size,
34 const uint8_t* bytes,
35 size_t size) {
36 descriptor_ =
37 new HidReportDescriptor(std::vector<uint8>(bytes, bytes + size));
39 std::vector<HidCollectionInfo> actual_collections;
40 bool actual_has_report_id;
41 size_t actual_max_input_report_size;
42 size_t actual_max_output_report_size;
43 size_t actual_max_feature_report_size;
44 descriptor_->GetDetails(&actual_collections,
45 &actual_has_report_id,
46 &actual_max_input_report_size,
47 &actual_max_output_report_size,
48 &actual_max_feature_report_size);
50 ASSERT_EQ(expected_collections.size(), actual_collections.size());
52 std::vector<HidCollectionInfo>::const_iterator actual_collections_iter =
53 actual_collections.begin();
54 std::vector<HidCollectionInfo>::const_iterator expected_collections_iter =
55 expected_collections.begin();
57 while (expected_collections_iter != expected_collections.end() &&
58 actual_collections_iter != actual_collections.end()) {
59 HidCollectionInfo expected_collection = *expected_collections_iter;
60 HidCollectionInfo actual_collection = *actual_collections_iter;
62 ASSERT_EQ(expected_collection.usage.usage_page,
63 actual_collection.usage.usage_page);
64 ASSERT_EQ(expected_collection.usage.usage, actual_collection.usage.usage);
65 ASSERT_THAT(actual_collection.report_ids,
66 ContainerEq(expected_collection.report_ids));
68 expected_collections_iter++;
69 actual_collections_iter++;
72 ASSERT_EQ(expected_has_report_id, actual_has_report_id);
73 ASSERT_EQ(expected_max_input_report_size, actual_max_input_report_size);
74 ASSERT_EQ(expected_max_output_report_size, actual_max_output_report_size);
75 ASSERT_EQ(expected_max_feature_report_size, actual_max_feature_report_size);
78 private:
79 HidReportDescriptor* descriptor_;
82 TEST_F(HidReportDescriptorTest, ValidateDetails_Digitizer) {
83 HidCollectionInfo digitizer;
84 digitizer.usage = HidUsageAndPage(0x01, HidUsageAndPage::kPageDigitizer);
85 digitizer.report_ids.insert(1);
86 digitizer.report_ids.insert(2);
87 digitizer.report_ids.insert(3);
88 HidCollectionInfo expected[] = {digitizer};
89 ValidateDetails(
90 std::vector<HidCollectionInfo>(expected, expected + arraysize(expected)),
91 true, 6, 0, 0, kDigitizer, kDigitizerSize);
94 TEST_F(HidReportDescriptorTest, ValidateDetails_Keyboard) {
95 HidCollectionInfo keyboard;
96 keyboard.usage = HidUsageAndPage(0x06, HidUsageAndPage::kPageGenericDesktop);
97 HidCollectionInfo expected[] = {keyboard};
98 ValidateDetails(
99 std::vector<HidCollectionInfo>(expected, expected + arraysize(expected)),
100 false, 8, 1, 0, kKeyboard, kKeyboardSize);
103 TEST_F(HidReportDescriptorTest, ValidateDetails_Monitor) {
104 HidCollectionInfo monitor;
105 monitor.usage = HidUsageAndPage(0x01, HidUsageAndPage::kPageMonitor0);
106 monitor.report_ids.insert(1);
107 monitor.report_ids.insert(2);
108 monitor.report_ids.insert(3);
109 monitor.report_ids.insert(4);
110 monitor.report_ids.insert(5);
111 HidCollectionInfo expected[] = {monitor};
112 ValidateDetails(
113 std::vector<HidCollectionInfo>(expected, expected + arraysize(expected)),
114 true, 0, 0, 243, kMonitor, kMonitorSize);
117 TEST_F(HidReportDescriptorTest, ValidateDetails_Mouse) {
118 HidCollectionInfo mouse;
119 mouse.usage = HidUsageAndPage(0x02, HidUsageAndPage::kPageGenericDesktop);
120 HidCollectionInfo expected[] = {mouse};
121 ValidateDetails(
122 std::vector<HidCollectionInfo>(expected, expected + arraysize(expected)),
123 false, 3, 0, 0, kMouse, kMouseSize);
126 TEST_F(HidReportDescriptorTest, ValidateDetails_LogitechUnifyingReceiver) {
127 HidCollectionInfo hidpp_short;
128 hidpp_short.usage = HidUsageAndPage(0x01, HidUsageAndPage::kPageVendor);
129 hidpp_short.report_ids.insert(0x10);
130 HidCollectionInfo hidpp_long;
131 hidpp_long.usage = HidUsageAndPage(0x02, HidUsageAndPage::kPageVendor);
132 hidpp_long.report_ids.insert(0x11);
133 HidCollectionInfo hidpp_dj;
134 hidpp_dj.usage = HidUsageAndPage(0x04, HidUsageAndPage::kPageVendor);
135 hidpp_dj.report_ids.insert(0x20);
136 hidpp_dj.report_ids.insert(0x21);
138 HidCollectionInfo expected[] = {hidpp_short, hidpp_long, hidpp_dj};
139 ValidateDetails(
140 std::vector<HidCollectionInfo>(expected, expected + arraysize(expected)),
141 true, 31, 31, 0, kLogitechUnifyingReceiver,
142 kLogitechUnifyingReceiverSize);
145 } // namespace device