Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: ui/base/keycodes/usb_keycode_map_unittest.cc

Issue 23542008: Add a CodeToNativeKeycode helper that converts UIEvent code to native code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing unittests Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/keycodes/usb_keycode_map.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_STREQ(InvalidKeyboardEventCode(), "Unidentified");
37 EXPECT_EQ(InvalidNativeKeycode(), CodeToNativeKeycode("Unidentified"));
36 38
37 // Verify that there are no duplicate entries in the mapping. 39 // Verify that there are no duplicate entries in the mapping.
38 std::map<uint32_t, uint16_t> usb_to_native; 40 std::map<uint32_t, uint16_t> usb_to_native;
39 std::map<uint16_t, uint32_t> native_to_usb; 41 std::map<uint16_t, uint32_t> native_to_usb;
40 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) { 42 for (size_t i = 0; i < arraysize(usb_keycode_map); ++i) {
41 // Don't test keys with no native keycode mapping on this platform. 43 // Don't test keys with no native keycode mapping on this platform.
42 if (usb_keycode_map[i].native_keycode == InvalidNativeKeycode()) 44 if (usb_keycode_map[i].native_keycode == InvalidNativeKeycode())
43 continue; 45 continue;
44 46
45 // Verify UsbKeycodeToNativeKeycode works for this key. 47 // Verify UsbKeycodeToNativeKeycode works for this key.
46 EXPECT_EQ(usb_keycode_map[i].native_keycode, 48 EXPECT_EQ(usb_keycode_map[i].native_keycode,
47 UsbKeycodeToNativeKeycode(usb_keycode_map[i].usb_keycode)); 49 UsbKeycodeToNativeKeycode(usb_keycode_map[i].usb_keycode));
48 50
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_STREQ(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
49 // Verify that the USB or native codes aren't duplicated. 63 // Verify that the USB or native codes aren't duplicated.
50 EXPECT_EQ(0U, usb_to_native.count(usb_keycode_map[i].usb_keycode)) 64 EXPECT_EQ(0U, usb_to_native.count(usb_keycode_map[i].usb_keycode))
51 << " duplicate of USB code 0x" << std::hex << std::setfill('0') 65 << " duplicate of USB code 0x" << std::hex << std::setfill('0')
52 << std::setw(6) << usb_keycode_map[i].usb_keycode 66 << std::setw(6) << usb_keycode_map[i].usb_keycode
53 << " to native 0x" 67 << " to native 0x"
54 << std::setw(4) << usb_keycode_map[i].native_keycode 68 << std::setw(4) << usb_keycode_map[i].native_keycode
55 << " (previous was 0x" 69 << " (previous was 0x"
56 << std::setw(4) << usb_to_native[usb_keycode_map[i].usb_keycode] 70 << std::setw(4) << usb_to_native[usb_keycode_map[i].usb_keycode]
57 << ")"; 71 << ")";
58 usb_to_native[usb_keycode_map[i].usb_keycode] = 72 usb_to_native[usb_keycode_map[i].usb_keycode] =
(...skipping 24 matching lines...) Expand all
83 97
84 TEST(UsbKeycodeMap, UsBackslashIsNonUsHash) { 98 TEST(UsbKeycodeMap, UsBackslashIsNonUsHash) {
85 // Verify that UsbKeycodeToNativeKeycode treats the non-US "hash" key 99 // Verify that UsbKeycodeToNativeKeycode treats the non-US "hash" key
86 // as equivalent to the US "backslash" key. 100 // as equivalent to the US "backslash" key.
87 EXPECT_EQ(UsbKeycodeToNativeKeycode(kUsbUsBackslash), 101 EXPECT_EQ(UsbKeycodeToNativeKeycode(kUsbUsBackslash),
88 UsbKeycodeToNativeKeycode(kUsbNonUsHash)); 102 UsbKeycodeToNativeKeycode(kUsbNonUsHash));
89 103
90 } 104 }
91 105
92 } // namespace 106 } // namespace
OLDNEW
« no previous file with comments | « ui/base/keycodes/usb_keycode_map.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698