| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 9 #include "remoting/proto/event.pb.h" | 9 #include "remoting/proto/event.pb.h" |
| 10 #include "remoting/protocol/message_decoder.h" | 10 #include "remoting/protocol/message_decoder.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 std::list<EventMessage*> message_list; | 64 std::list<EventMessage*> message_list; |
| 65 for (int i = 0; i < size;) { | 65 for (int i = 0; i < size;) { |
| 66 // First generate the amount to feed the decoder. | 66 // First generate the amount to feed the decoder. |
| 67 int read = std::min(size - i, read_sequence[i % sequence_size]); | 67 int read = std::min(size - i, read_sequence[i % sequence_size]); |
| 68 | 68 |
| 69 // And then prepare an IOBuffer for feeding it. | 69 // And then prepare an IOBuffer for feeding it. |
| 70 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(read)); | 70 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(read)); |
| 71 memcpy(buffer->data(), test_data + i, read); | 71 memcpy(buffer->data(), test_data + i, read); |
| 72 decoder.AddData(buffer, read); | 72 decoder.AddData(buffer, read); |
| 73 while (true) { | 73 while (true) { |
| 74 CompoundBuffer message; | 74 scoped_ptr<CompoundBuffer> message(decoder.GetNextMessage()); |
| 75 if (!decoder.GetNextMessage(&message)) | 75 if (!message.get()) |
| 76 break; | 76 break; |
| 77 | 77 |
| 78 EventMessage* event = new EventMessage(); | 78 EventMessage* event = new EventMessage(); |
| 79 CompoundBufferInputStream stream(&message); | 79 CompoundBufferInputStream stream(message.get()); |
| 80 ASSERT_TRUE(event->ParseFromZeroCopyStream(&stream)); | 80 ASSERT_TRUE(event->ParseFromZeroCopyStream(&stream)); |
| 81 message_list.push_back(event); | 81 message_list.push_back(event); |
| 82 } | 82 } |
| 83 i += read; | 83 i += read; |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Then verify the decoded messages. | 86 // Then verify the decoded messages. |
| 87 EXPECT_EQ(10u, message_list.size()); | 87 EXPECT_EQ(10u, message_list.size()); |
| 88 | 88 |
| 89 int index = 0; | 89 int index = 0; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 114 SimulateReadSequence(kReads, arraysize(kReads)); | 114 SimulateReadSequence(kReads, arraysize(kReads)); |
| 115 } | 115 } |
| 116 | 116 |
| 117 TEST(MessageDecoderTest, EmptyReads) { | 117 TEST(MessageDecoderTest, EmptyReads) { |
| 118 const int kReads[] = {4, 0, 50, 0}; | 118 const int kReads[] = {4, 0, 50, 0}; |
| 119 SimulateReadSequence(kReads, arraysize(kReads)); | 119 SimulateReadSequence(kReads, arraysize(kReads)); |
| 120 } | 120 } |
| 121 | 121 |
| 122 } // namespace protocol | 122 } // namespace protocol |
| 123 } // namespace remoting | 123 } // namespace remoting |
| OLD | NEW |