| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // Then feed the protocol decoder using the above generated data and the | 62 // Then feed the protocol decoder using the above generated data and the |
| 63 // read pattern. | 63 // read pattern. |
| 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.ParseMessages(buffer, read, &message_list); | 72 decoder.AddData(buffer, read); |
| 73 while (true) { |
| 74 CompoundBuffer message; |
| 75 if (!decoder.GetNextMessage(&message)) |
| 76 break; |
| 77 |
| 78 EventMessage* event = new EventMessage(); |
| 79 CompoundBufferInputStream stream(&message); |
| 80 ASSERT_TRUE(event->ParseFromZeroCopyStream(&stream)); |
| 81 message_list.push_back(event); |
| 82 } |
| 73 i += read; | 83 i += read; |
| 74 } | 84 } |
| 75 | 85 |
| 76 // Then verify the decoded messages. | 86 // Then verify the decoded messages. |
| 77 EXPECT_EQ(10u, message_list.size()); | 87 EXPECT_EQ(10u, message_list.size()); |
| 78 | 88 |
| 79 int index = 0; | 89 int index = 0; |
| 80 for (std::list<EventMessage*>::iterator it = | 90 for (std::list<EventMessage*>::iterator it = |
| 81 message_list.begin(); | 91 message_list.begin(); |
| 82 it != message_list.end(); ++it) { | 92 it != message_list.end(); ++it) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 104 SimulateReadSequence(kReads, arraysize(kReads)); | 114 SimulateReadSequence(kReads, arraysize(kReads)); |
| 105 } | 115 } |
| 106 | 116 |
| 107 TEST(MessageDecoderTest, EmptyReads) { | 117 TEST(MessageDecoderTest, EmptyReads) { |
| 108 const int kReads[] = {4, 0, 50, 0}; | 118 const int kReads[] = {4, 0, 50, 0}; |
| 109 SimulateReadSequence(kReads, arraysize(kReads)); | 119 SimulateReadSequence(kReads, arraysize(kReads)); |
| 110 } | 120 } |
| 111 | 121 |
| 112 } // namespace protocol | 122 } // namespace protocol |
| 113 } // namespace remoting | 123 } // namespace remoting |
| OLD | NEW |