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

Side by Side Diff: remoting/protocol/message_decoder_unittest.cc

Issue 10894050: Remove support for Windows-style keycodes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Linux EventExecutor typo. Created 8 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 | Annotate | Revision Log
« no previous file with comments | « remoting/protocol/input_event_tracker_unittest.cc ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <string> 5 #include <string>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "remoting/proto/event.pb.h" 10 #include "remoting/proto/event.pb.h"
11 #include "remoting/proto/internal.pb.h" 11 #include "remoting/proto/internal.pb.h"
12 #include "remoting/protocol/message_decoder.h" 12 #include "remoting/protocol/message_decoder.h"
13 #include "remoting/protocol/util.h" 13 #include "remoting/protocol/util.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace remoting { 16 namespace remoting {
17 namespace protocol { 17 namespace protocol {
18 18
19 static const int kTestKey = 142; 19 static const unsigned int kTestKey = 142;
20 20
21 static void AppendMessage(const EventMessage& msg, 21 static void AppendMessage(const EventMessage& msg,
22 std::string* buffer) { 22 std::string* buffer) {
23 // Contains one encoded message. 23 // Contains one encoded message.
24 scoped_refptr<net::IOBufferWithSize> encoded_msg; 24 scoped_refptr<net::IOBufferWithSize> encoded_msg;
25 encoded_msg = SerializeAndFrameMessage(msg); 25 encoded_msg = SerializeAndFrameMessage(msg);
26 buffer->append(encoded_msg->data(), encoded_msg->size()); 26 buffer->append(encoded_msg->data(), encoded_msg->size());
27 } 27 }
28 28
29 // Construct and prepare data in the |output_stream|. 29 // Construct and prepare data in the |output_stream|.
30 static void PrepareData(uint8** buffer, int* size) { 30 static void PrepareData(uint8** buffer, int* size) {
31 // Contains all encoded messages. 31 // Contains all encoded messages.
32 std::string encoded_data; 32 std::string encoded_data;
33 33
34 // Then append 10 update sequences to the data. 34 // Then append 10 update sequences to the data.
35 for (int i = 0; i < 10; ++i) { 35 for (int i = 0; i < 10; ++i) {
36 EventMessage msg; 36 EventMessage msg;
37 msg.set_sequence_number(i); 37 msg.set_sequence_number(i);
38 msg.mutable_key_event()->set_keycode(kTestKey + i); 38 msg.mutable_key_event()->set_usb_keycode(kTestKey + i);
39 msg.mutable_key_event()->set_pressed((i % 2) != 0); 39 msg.mutable_key_event()->set_pressed((i % 2) != 0);
40 AppendMessage(msg, &encoded_data); 40 AppendMessage(msg, &encoded_data);
41 } 41 }
42 42
43 *size = encoded_data.length(); 43 *size = encoded_data.length();
44 *buffer = new uint8[*size]; 44 *buffer = new uint8[*size];
45 memcpy(*buffer, encoded_data.c_str(), *size); 45 memcpy(*buffer, encoded_data.c_str(), *size);
46 } 46 }
47 47
48 void SimulateReadSequence(const int read_sequence[], int sequence_size) { 48 void SimulateReadSequence(const int read_sequence[], int sequence_size) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 CompoundBufferInputStream stream(message.get()); 80 CompoundBufferInputStream stream(message.get());
81 ASSERT_TRUE(event->ParseFromZeroCopyStream(&stream)); 81 ASSERT_TRUE(event->ParseFromZeroCopyStream(&stream));
82 message_list.push_back(event); 82 message_list.push_back(event);
83 } 83 }
84 pos += read; 84 pos += read;
85 } 85 }
86 86
87 // Then verify the decoded messages. 87 // Then verify the decoded messages.
88 EXPECT_EQ(10u, message_list.size()); 88 EXPECT_EQ(10u, message_list.size());
89 89
90 int index = 0; 90 unsigned int index = 0;
91 for (std::list<EventMessage*>::iterator it = 91 for (std::list<EventMessage*>::iterator it =
92 message_list.begin(); 92 message_list.begin();
93 it != message_list.end(); ++it) { 93 it != message_list.end(); ++it) {
94 SCOPED_TRACE("Message " + base::IntToString(index)); 94 SCOPED_TRACE("Message " + base::IntToString(index));
95 95
96 EventMessage* message = *it; 96 EventMessage* message = *it;
97 // Partial update stream. 97 // Partial update stream.
98 EXPECT_TRUE(message->has_key_event()); 98 EXPECT_TRUE(message->has_key_event());
99 99
100 // TODO(sergeyu): Don't use index here. Instead store the expected values 100 // TODO(sergeyu): Don't use index here. Instead store the expected values
101 // in an array. 101 // in an array.
102 EXPECT_EQ(kTestKey + index, message->key_event().keycode()); 102 EXPECT_EQ(kTestKey + index, message->key_event().usb_keycode());
103 EXPECT_EQ((index % 2) != 0, message->key_event().pressed()); 103 EXPECT_EQ((index % 2) != 0, message->key_event().pressed());
104 ++index; 104 ++index;
105 } 105 }
106 STLDeleteElements(&message_list); 106 STLDeleteElements(&message_list);
107 } 107 }
108 108
109 TEST(MessageDecoderTest, SmallReads) { 109 TEST(MessageDecoderTest, SmallReads) {
110 const int kReads[] = {1, 2, 3, 1}; 110 const int kReads[] = {1, 2, 3, 1};
111 SimulateReadSequence(kReads, arraysize(kReads)); 111 SimulateReadSequence(kReads, arraysize(kReads));
112 } 112 }
113 113
114 TEST(MessageDecoderTest, LargeReads) { 114 TEST(MessageDecoderTest, LargeReads) {
115 const int kReads[] = {50, 50, 5}; 115 const int kReads[] = {50, 50, 5};
116 SimulateReadSequence(kReads, arraysize(kReads)); 116 SimulateReadSequence(kReads, arraysize(kReads));
117 } 117 }
118 118
119 TEST(MessageDecoderTest, EmptyReads) { 119 TEST(MessageDecoderTest, EmptyReads) {
120 const int kReads[] = {4, 0, 50, 0}; 120 const int kReads[] = {4, 0, 50, 0};
121 SimulateReadSequence(kReads, arraysize(kReads)); 121 SimulateReadSequence(kReads, arraysize(kReads));
122 } 122 }
123 123
124 } // namespace protocol 124 } // namespace protocol
125 } // namespace remoting 125 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/input_event_tracker_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698