OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/events/keycodes/dom4/keycode_converter.h" | 5 #include "ui/events/keycodes/dom4/keycode_converter.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 19 matching lines...) Expand all Loading... | |
30 const uint32_t kUsbNonUsHash = 0x070032; | 30 const uint32_t kUsbNonUsHash = 0x070032; |
31 | 31 |
32 TEST(UsbKeycodeMap, Basic) { | 32 TEST(UsbKeycodeMap, Basic) { |
33 // Verify that the first element in the table is the "invalid" code. | 33 // Verify that the first element in the table is the "invalid" code. |
34 const ui::KeycodeMapEntry* keycode_map = | 34 const ui::KeycodeMapEntry* keycode_map = |
35 ui::KeycodeConverter::GetKeycodeMapForTest(); | 35 ui::KeycodeConverter::GetKeycodeMapForTest(); |
36 EXPECT_EQ(ui::KeycodeConverter::InvalidUsbKeycode(), | 36 EXPECT_EQ(ui::KeycodeConverter::InvalidUsbKeycode(), |
37 keycode_map[0].usb_keycode); | 37 keycode_map[0].usb_keycode); |
38 EXPECT_EQ(ui::KeycodeConverter::InvalidNativeKeycode(), | 38 EXPECT_EQ(ui::KeycodeConverter::InvalidNativeKeycode(), |
39 keycode_map[0].native_keycode); | 39 keycode_map[0].native_keycode); |
40 EXPECT_EQ(ui::KeycodeConverter::InvalidNativeKeycode(), | 40 EXPECT_EQ( |
41 ui::KeycodeConverter::CodeToNativeKeycode("Unidentified")); | 41 ui::KeycodeConverter::InvalidNativeKeycode(), |
42 ui::KeycodeConverter::DomCodeToNativeKeycode(ui::DomCode::NONE)); | |
42 | 43 |
43 // Verify that there are no duplicate entries in the mapping. | 44 // Verify that there are no duplicate entries in the mapping. |
44 std::map<uint32_t, uint16_t> usb_to_native; | 45 std::map<uint32_t, uint16_t> usb_to_native; |
45 std::map<uint16_t, uint32_t> native_to_usb; | 46 std::map<uint16_t, uint32_t> native_to_usb; |
46 size_t numEntries = ui::KeycodeConverter::NumKeycodeMapEntriesForTest(); | 47 size_t numEntries = ui::KeycodeConverter::NumKeycodeMapEntriesForTest(); |
47 for (size_t i = 0; i < numEntries; ++i) { | 48 for (size_t i = 0; i < numEntries; ++i) { |
48 const ui::KeycodeMapEntry* entry = &keycode_map[i]; | 49 const ui::KeycodeMapEntry* entry = &keycode_map[i]; |
49 // Don't test keys with no native keycode mapping on this platform. | 50 // Don't test keys with no native keycode mapping on this platform. |
50 if (entry->native_keycode == ui::KeycodeConverter::InvalidNativeKeycode()) | 51 if (entry->native_keycode == ui::KeycodeConverter::InvalidNativeKeycode()) |
51 continue; | 52 continue; |
52 | 53 |
53 // Verify UsbKeycodeToNativeKeycode works for this key. | 54 // Verify UsbKeycodeToNativeKeycode works for this key. |
54 EXPECT_EQ( | 55 EXPECT_EQ( |
55 entry->native_keycode, | 56 entry->native_keycode, |
56 ui::KeycodeConverter::UsbKeycodeToNativeKeycode(entry->usb_keycode)); | 57 ui::KeycodeConverter::UsbKeycodeToNativeKeycode(entry->usb_keycode)); |
57 | 58 |
58 // Verify CodeToNativeKeycode and NativeKeycodeToCode work correctly. | 59 // Verify DomCodeToNativeKeycode and NativeKeycodeToCode work correctly. |
60 ui::DomCode dom_code = | |
61 ui::KeycodeConverter::CodeStringToDomCode(entry->code); | |
Wez
2015/05/05 20:11:48
You only need this because you're testing DomCode-
kpschoedel
2015/05/05 20:48:50
Done. (DomCode<->DomCodeString is tested in Keycod
| |
59 if (entry->code) { | 62 if (entry->code) { |
60 EXPECT_EQ(entry->native_keycode, | 63 EXPECT_EQ(entry->native_keycode, |
61 ui::KeycodeConverter::CodeToNativeKeycode(entry->code)); | 64 ui::KeycodeConverter::DomCodeToNativeKeycode(dom_code)); |
62 EXPECT_STREQ( | 65 EXPECT_STREQ(entry->code, ui::KeycodeConverter::NativeKeycodeToCode( |
63 entry->code, | 66 entry->native_keycode)); |
Wez
2015/05/05 20:11:48
nit: More readable to wrap after "code," and keep
kpschoedel
2015/05/05 20:48:50
Agreed — I liked the old clang-format rule better
| |
64 ui::KeycodeConverter::NativeKeycodeToCode(entry->native_keycode)); | 67 } else { |
65 } | 68 EXPECT_EQ(ui::DomCode::NONE, dom_code); |
66 else { | |
67 EXPECT_EQ(ui::KeycodeConverter::InvalidNativeKeycode(), | |
68 ui::KeycodeConverter::CodeToNativeKeycode(entry->code)); | |
69 } | 69 } |
70 | 70 |
71 // Verify that the USB or native codes aren't duplicated. | 71 // Verify that the USB or native codes aren't duplicated. |
72 EXPECT_EQ(0U, usb_to_native.count(entry->usb_keycode)) | 72 EXPECT_EQ(0U, usb_to_native.count(entry->usb_keycode)) |
73 << " duplicate of USB code 0x" << std::hex << std::setfill('0') | 73 << " duplicate of USB code 0x" << std::hex << std::setfill('0') |
74 << std::setw(6) << entry->usb_keycode | 74 << std::setw(6) << entry->usb_keycode |
75 << " to native 0x" | 75 << " to native 0x" |
76 << std::setw(4) << entry->native_keycode | 76 << std::setw(4) << entry->native_keycode |
77 << " (previous was 0x" | 77 << " (previous was 0x" |
78 << std::setw(4) << usb_to_native[entry->usb_keycode] | 78 << std::setw(4) << usb_to_native[entry->usb_keycode] |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 ui::DomKey key = ui::KeycodeConverter::KeyStringToDomKey(s); | 146 ui::DomKey key = ui::KeycodeConverter::KeyStringToDomKey(s); |
147 if (s) { | 147 if (s) { |
148 EXPECT_STREQ(s, ui::KeycodeConverter::DomKeyToKeyString(key)); | 148 EXPECT_STREQ(s, ui::KeycodeConverter::DomKeyToKeyString(key)); |
149 } else { | 149 } else { |
150 EXPECT_EQ(ui::DomKey::NONE, key); | 150 EXPECT_EQ(ui::DomKey::NONE, key); |
151 } | 151 } |
152 } | 152 } |
153 } | 153 } |
154 | 154 |
155 } // namespace | 155 } // namespace |
OLD | NEW |