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 28 matching lines...) Expand all Loading... | |
39 std::map<uint16_t, uint32_t> native_to_usb; | 39 std::map<uint16_t, uint32_t> native_to_usb; |
40 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { | 40 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { |
41 // 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. |
42 if (usb_keycode_map[i].native_keycode == InvalidNativeKeycode()) | 42 if (usb_keycode_map[i].native_keycode == InvalidNativeKeycode()) |
43 continue; | 43 continue; |
44 | 44 |
45 // Verify UsbKeycodeToNativeKeycode works for this key. | 45 // Verify UsbKeycodeToNativeKeycode works for this key. |
46 EXPECT_EQ(usb_keycode_map[i].native_keycode, | 46 EXPECT_EQ(usb_keycode_map[i].native_keycode, |
47 UsbKeycodeToNativeKeycode(usb_keycode_map[i].usb_keycode)); | 47 UsbKeycodeToNativeKeycode(usb_keycode_map[i].usb_keycode)); |
48 | 48 |
49 // Verify CodeToNativeKeycode works for this key. | |
50 if (usb_keycode_map[i].code) { | |
51 EXPECT_EQ(usb_keycode_map[i].native_keycode, | |
52 CodeToNativeKeycode(usb_keycode_map[i].code)); | |
garykac
2013/09/04 23:04:03
Can you check both directions here?
EXPECT_EQ(usb
weitao
2013/09/04 23:41:27
Done.
| |
53 } | |
54 else { | |
55 EXPECT_EQ(InvalidNativeKeycode(), | |
56 CodeToNativeKeycode(usb_keycode_map[i].code)); | |
57 } | |
58 | |
49 // Verify that the USB or native codes aren't duplicated. | 59 // Verify that the USB or native codes aren't duplicated. |
50 EXPECT_EQ(0U, usb_to_native.count(usb_keycode_map[i].usb_keycode)) | 60 EXPECT_EQ(0U, usb_to_native.count(usb_keycode_map[i].usb_keycode)) |
51 << " duplicate of USB code 0x" << std::hex << std::setfill('0') | 61 << " duplicate of USB code 0x" << std::hex << std::setfill('0') |
52 << std::setw(6) << usb_keycode_map[i].usb_keycode | 62 << std::setw(6) << usb_keycode_map[i].usb_keycode |
53 << " to native 0x" | 63 << " to native 0x" |
54 << std::setw(4) << usb_keycode_map[i].native_keycode | 64 << std::setw(4) << usb_keycode_map[i].native_keycode |
55 << " (previous was 0x" | 65 << " (previous was 0x" |
56 << std::setw(4) << usb_to_native[usb_keycode_map[i].usb_keycode] | 66 << std::setw(4) << usb_to_native[usb_keycode_map[i].usb_keycode] |
57 << ")"; | 67 << ")"; |
58 usb_to_native[usb_keycode_map[i].usb_keycode] = | 68 usb_to_native[usb_keycode_map[i].usb_keycode] = |
(...skipping 24 matching lines...) Expand all Loading... | |
83 | 93 |
84 TEST(UsbKeycodeMap, UsBackslashIsNonUsHash) { | 94 TEST(UsbKeycodeMap, UsBackslashIsNonUsHash) { |
85 // Verify that UsbKeycodeToNativeKeycode treats the non-US "hash" key | 95 // Verify that UsbKeycodeToNativeKeycode treats the non-US "hash" key |
86 // as equivalent to the US "backslash" key. | 96 // as equivalent to the US "backslash" key. |
87 EXPECT_EQ(UsbKeycodeToNativeKeycode(kUsbUsBackslash), | 97 EXPECT_EQ(UsbKeycodeToNativeKeycode(kUsbUsBackslash), |
88 UsbKeycodeToNativeKeycode(kUsbNonUsHash)); | 98 UsbKeycodeToNativeKeycode(kUsbNonUsHash)); |
89 | 99 |
90 } | 100 } |
91 | 101 |
92 } // namespace | 102 } // namespace |
OLD | NEW |