| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #undef USB_KEYMAP | 26 #undef USB_KEYMAP |
| 27 | 27 |
| 28 const uint32_t kUsbNonExistentKeycode = 0xffffff; | 28 const uint32_t kUsbNonExistentKeycode = 0xffffff; |
| 29 const uint32_t kUsbUsBackslash = 0x070031; | 29 const uint32_t kUsbUsBackslash = 0x070031; |
| 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 EXPECT_EQ(InvalidUsbKeycode(), usb_keycode_map[0].usb_keycode); | 34 EXPECT_EQ(InvalidUsbKeycode(), usb_keycode_map[0].usb_keycode); |
| 35 EXPECT_EQ(InvalidNativeKeycode(), usb_keycode_map[0].native_keycode); | 35 EXPECT_EQ(InvalidNativeKeycode(), usb_keycode_map[0].native_keycode); |
| 36 EXPECT_EQ(InvalidKeyboardEventCode(), "Unidentified"); | |
| 37 EXPECT_EQ(InvalidNativeKeycode(), CodeToNativeKeycode("Unidentified")); | |
| 38 | 36 |
| 39 // Verify that there are no duplicate entries in the mapping. | 37 // Verify that there are no duplicate entries in the mapping. |
| 40 std::map<uint32_t, uint16_t> usb_to_native; | 38 std::map<uint32_t, uint16_t> usb_to_native; |
| 41 std::map<uint16_t, uint32_t> native_to_usb; | 39 std::map<uint16_t, uint32_t> native_to_usb; |
| 42 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { | 40 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { |
| 43 // Don't test keys with no native keycode mapping on this platform. | 41 // Don't test keys with no native keycode mapping on this platform. |
| 44 if (usb_keycode_map[i].native_keycode == InvalidNativeKeycode()) | 42 if (usb_keycode_map[i].native_keycode == InvalidNativeKeycode()) |
| 45 continue; | 43 continue; |
| 46 | 44 |
| 47 // Verify UsbKeycodeToNativeKeycode works for this key. | 45 // Verify UsbKeycodeToNativeKeycode works for this key. |
| 48 EXPECT_EQ(usb_keycode_map[i].native_keycode, | 46 EXPECT_EQ(usb_keycode_map[i].native_keycode, |
| 49 UsbKeycodeToNativeKeycode(usb_keycode_map[i].usb_keycode)); | 47 UsbKeycodeToNativeKeycode(usb_keycode_map[i].usb_keycode)); |
| 50 | 48 |
| 51 // Verify CodeToNativeKeycode and NativeKeycodeToCode work correctly. | |
| 52 if (usb_keycode_map[i].code) { | |
| 53 EXPECT_EQ(usb_keycode_map[i].native_keycode, | |
| 54 CodeToNativeKeycode(usb_keycode_map[i].code)); | |
| 55 EXPECT_EQ(usb_keycode_map[i].code, | |
| 56 NativeKeycodeToCode(usb_keycode_map[i].native_keycode)); | |
| 57 } | |
| 58 else { | |
| 59 EXPECT_EQ(InvalidNativeKeycode(), | |
| 60 CodeToNativeKeycode(usb_keycode_map[i].code)); | |
| 61 } | |
| 62 | |
| 63 // Verify that the USB or native codes aren't duplicated. | 49 // Verify that the USB or native codes aren't duplicated. |
| 64 EXPECT_EQ(0U, usb_to_native.count(usb_keycode_map[i].usb_keycode)) | 50 EXPECT_EQ(0U, usb_to_native.count(usb_keycode_map[i].usb_keycode)) |
| 65 << " duplicate of USB code 0x" << std::hex << std::setfill('0') | 51 << " duplicate of USB code 0x" << std::hex << std::setfill('0') |
| 66 << std::setw(6) << usb_keycode_map[i].usb_keycode | 52 << std::setw(6) << usb_keycode_map[i].usb_keycode |
| 67 << " to native 0x" | 53 << " to native 0x" |
| 68 << std::setw(4) << usb_keycode_map[i].native_keycode | 54 << std::setw(4) << usb_keycode_map[i].native_keycode |
| 69 << " (previous was 0x" | 55 << " (previous was 0x" |
| 70 << std::setw(4) << usb_to_native[usb_keycode_map[i].usb_keycode] | 56 << std::setw(4) << usb_to_native[usb_keycode_map[i].usb_keycode] |
| 71 << ")"; | 57 << ")"; |
| 72 usb_to_native[usb_keycode_map[i].usb_keycode] = | 58 usb_to_native[usb_keycode_map[i].usb_keycode] = |
| (...skipping 24 matching lines...) Expand all Loading... |
| 97 | 83 |
| 98 TEST(UsbKeycodeMap, UsBackslashIsNonUsHash) { | 84 TEST(UsbKeycodeMap, UsBackslashIsNonUsHash) { |
| 99 // Verify that UsbKeycodeToNativeKeycode treats the non-US "hash" key | 85 // Verify that UsbKeycodeToNativeKeycode treats the non-US "hash" key |
| 100 // as equivalent to the US "backslash" key. | 86 // as equivalent to the US "backslash" key. |
| 101 EXPECT_EQ(UsbKeycodeToNativeKeycode(kUsbUsBackslash), | 87 EXPECT_EQ(UsbKeycodeToNativeKeycode(kUsbUsBackslash), |
| 102 UsbKeycodeToNativeKeycode(kUsbNonUsHash)); | 88 UsbKeycodeToNativeKeycode(kUsbNonUsHash)); |
| 103 | 89 |
| 104 } | 90 } |
| 105 | 91 |
| 106 } // namespace | 92 } // namespace |
| OLD | NEW |