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

Side by Side Diff: chrome/browser/extensions/api/serial/serial_apitest.cc

Issue 10827123: Add serial bulk reads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/browser/extensions/api/api_resource_event_notifier.h" 9 #include "chrome/browser/extensions/api/api_resource_event_notifier.h"
10 #include "chrome/browser/extensions/api/serial/serial_api.h" 10 #include "chrome/browser/extensions/api/serial/serial_api.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 virtual void Close() { 71 virtual void Close() {
72 DCHECK(opened_); 72 DCHECK(opened_);
73 } 73 }
74 74
75 virtual void Flush() { 75 virtual void Flush() {
76 DCHECK(opened_); 76 DCHECK(opened_);
77 read_index_ = write_index_ = 0; 77 read_index_ = write_index_ = 0;
78 } 78 }
79 79
80 virtual int Read(uint8* byte) { 80 virtual int Read(scoped_refptr<net::IOBufferWithSize> io_buffer) {
81 DCHECK(byte); 81 DCHECK(io_buffer->data());
82 DCHECK(io_buffer->size() <= BUFFER_SIZE);
82 83
83 if (read_index_ >= write_index_) { 84 if (read_index_ >= write_index_) {
Peng 2012/08/01 22:14:00 As it is a ring bufer, I think just testing read_i
84 return 0; 85 return 0;
85 } 86 }
86 *byte = ring_buffer_[read_index_++]; 87 char *data = io_buffer->data();
87 if (read_index_ == BUFFER_SIZE) 88 int bytes_to_copy = io_buffer->size();
88 read_index_ = 0; 89 while (bytes_to_copy--) {
89 return 1; 90 *data++ = ring_buffer_[read_index_++];
91 if (read_index_ == BUFFER_SIZE)
92 read_index_ = 0;
93 }
94 return io_buffer->size();
90 } 95 }
91 96
92 virtual int Write(scoped_refptr<net::IOBuffer> io_buffer, int byte_count) { 97 virtual int Write(scoped_refptr<net::IOBuffer> io_buffer, int byte_count) {
93 DCHECK(io_buffer.get()); 98 DCHECK(io_buffer.get());
94 DCHECK(byte_count >= 0); 99 DCHECK(byte_count >= 0);
95 100
96 char *data = io_buffer->data(); 101 char *data = io_buffer->data();
97 int count = byte_count; 102 int count = byte_count;
98 while (count--) { 103 while (count--) {
99 ring_buffer_[write_index_++] = *data++; 104 ring_buffer_[write_index_++] = *data++;
Peng 2012/08/01 22:14:00 I think here may overwrite unread data.
100 if (write_index_ == BUFFER_SIZE) 105 if (write_index_ == BUFFER_SIZE)
101 write_index_ = 0; 106 write_index_ = 0;
102 } 107 }
103 return byte_count; 108 return byte_count;
104 } 109 }
105 110
106 MOCK_METHOD1(GetControlSignals, bool(ControlSignals &)); 111 MOCK_METHOD1(GetControlSignals, bool(ControlSignals &));
107 MOCK_METHOD1(SetControlSignals, bool(const ControlSignals &)); 112 MOCK_METHOD1(SetControlSignals, bool(const ControlSignals &));
108 113
109 private: 114 private:
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 188
184 ASSERT_TRUE(RunExtensionTest("serial/api")) << message_; 189 ASSERT_TRUE(RunExtensionTest("serial/api")) << message_;
185 } 190 }
186 191
187 IN_PROC_BROWSER_TEST_F(SerialApiTest, SerialRealHardware) { 192 IN_PROC_BROWSER_TEST_F(SerialApiTest, SerialRealHardware) {
188 ResultCatcher catcher; 193 ResultCatcher catcher;
189 catcher.RestrictToProfile(browser()->profile()); 194 catcher.RestrictToProfile(browser()->profile());
190 195
191 ASSERT_TRUE(RunExtensionTest("serial/real_hardware")) << message_; 196 ASSERT_TRUE(RunExtensionTest("serial/real_hardware")) << message_;
192 } 197 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/serial/serial_api.cc ('k') | chrome/browser/extensions/api/serial/serial_connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698