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

Side by Side Diff: tools/battor_agent/battor_connection_impl_unittest.cc

Issue 2000743002: [battor agent] Add 'read more bytes' logic in the BattOr connection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 | « tools/battor_agent/battor_connection_impl.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "tools/battor_agent/battor_connection_impl.h" 5 #include "tools/battor_agent/battor_connection_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 const char data[] = { 223 const char data[] = {
224 BATTOR_CONTROL_BYTE_START, 224 BATTOR_CONTROL_BYTE_START,
225 BATTOR_MESSAGE_TYPE_CONTROL, 225 BATTOR_MESSAGE_TYPE_CONTROL,
226 BATTOR_CONTROL_BYTE_ESCAPE, 226 BATTOR_CONTROL_BYTE_ESCAPE,
227 BATTOR_CONTROL_MESSAGE_TYPE_RESET, 227 BATTOR_CONTROL_MESSAGE_TYPE_RESET,
228 0x04, 228 0x04,
229 }; 229 };
230 SendBytesRaw(data, 5); 230 SendBytesRaw(data, 5);
231 ReadMessage(BATTOR_MESSAGE_TYPE_CONTROL); 231 ReadMessage(BATTOR_MESSAGE_TYPE_CONTROL);
232 232
233 ASSERT_TRUE(IsReadComplete()); 233 // The first read should recognize that a second read is necessary, but the
234 ASSERT_FALSE(GetReadSuccess()); 234 // second read will hang because no bytes ever come in.
235 ASSERT_FALSE(IsReadComplete());
235 } 236 }
236 237
237 TEST_F(BattOrConnectionImplTest, ReadMessageMissingEndByte) { 238 TEST_F(BattOrConnectionImplTest, ReadMessageMissingEndByte) {
238 OpenConnection(); 239 OpenConnection();
239 ASSERT_TRUE(GetOpenSuccess()); 240 ASSERT_TRUE(GetOpenSuccess());
240 241
241 const char data[] = { 242 const char data[] = {
242 BATTOR_CONTROL_BYTE_START, 243 BATTOR_CONTROL_BYTE_START,
243 BATTOR_MESSAGE_TYPE_CONTROL, 244 BATTOR_MESSAGE_TYPE_CONTROL,
244 BATTOR_CONTROL_BYTE_ESCAPE, 245 BATTOR_CONTROL_BYTE_ESCAPE,
245 BATTOR_CONTROL_MESSAGE_TYPE_RESET, 246 BATTOR_CONTROL_MESSAGE_TYPE_RESET,
246 0x04, 247 0x04,
247 0x04, 248 0x04,
248 0x04, 249 0x04,
249 0x04, 250 0x04,
250 }; 251 };
251 SendBytesRaw(data, 6); 252 SendBytesRaw(data, 6);
252 ReadMessage(BATTOR_MESSAGE_TYPE_CONTROL); 253 ReadMessage(BATTOR_MESSAGE_TYPE_CONTROL);
253 254
254 ASSERT_TRUE(IsReadComplete()); 255 // The first read should recognize that a second read is necessary, but the
255 ASSERT_FALSE(GetReadSuccess()); 256 // second read will hang because no bytes ever come in.
257 ASSERT_FALSE(IsReadComplete());
256 } 258 }
257 259
258 TEST_F(BattOrConnectionImplTest, ReadMessageWithEscapeCharacters) { 260 TEST_F(BattOrConnectionImplTest, ReadMessageWithEscapeCharacters) {
259 OpenConnection(); 261 OpenConnection();
260 ASSERT_TRUE(GetOpenSuccess()); 262 ASSERT_TRUE(GetOpenSuccess());
261 263
262 const char data[] = { 264 const char data[] = {
263 BATTOR_CONTROL_BYTE_START, 265 BATTOR_CONTROL_BYTE_START,
264 BATTOR_MESSAGE_TYPE_CONTROL, 266 BATTOR_MESSAGE_TYPE_CONTROL,
265 BATTOR_CONTROL_BYTE_ESCAPE, 267 BATTOR_CONTROL_BYTE_ESCAPE,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 BATTOR_CONTROL_BYTE_END, 391 BATTOR_CONTROL_BYTE_END,
390 }; 392 };
391 SendBytesRaw(data, 3); 393 SendBytesRaw(data, 3);
392 ReadMessage(BATTOR_MESSAGE_TYPE_PRINT); 394 ReadMessage(BATTOR_MESSAGE_TYPE_PRINT);
393 395
394 ASSERT_TRUE(IsReadComplete()); 396 ASSERT_TRUE(IsReadComplete());
395 ASSERT_FALSE(GetReadSuccess()); 397 ASSERT_FALSE(GetReadSuccess());
396 } 398 }
397 399
398 } // namespace battor 400 } // namespace battor
OLDNEW
« no previous file with comments | « tools/battor_agent/battor_connection_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698