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 "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "remoting/base/multiple_array_input_stream.h" | 10 #include "remoting/base/multiple_array_input_stream.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 MessageDecoder decoder; | 76 MessageDecoder decoder; |
77 | 77 |
78 // Then feed the protocol decoder using the above generated data and the | 78 // Then feed the protocol decoder using the above generated data and the |
79 // read pattern. | 79 // read pattern. |
80 std::list<ChromotingHostMessage*> message_list; | 80 std::list<ChromotingHostMessage*> message_list; |
81 for (int i = 0; i < size;) { | 81 for (int i = 0; i < size;) { |
82 // First generate the amount to feed the decoder. | 82 // First generate the amount to feed the decoder. |
83 int read = std::min(size - i, read_sequence[i % sequence_size]); | 83 int read = std::min(size - i, read_sequence[i % sequence_size]); |
84 | 84 |
85 // And then prepare an IOBuffer for feeding it. | 85 // And then prepare an IOBuffer for feeding it. |
86 scoped_refptr<net::IOBuffer> buffer = new net::IOBuffer(read); | 86 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(read)); |
87 memcpy(buffer->data(), test_data + i, read); | 87 memcpy(buffer->data(), test_data + i, read); |
88 decoder.ParseMessages(buffer, read, &message_list); | 88 decoder.ParseMessages(buffer, read, &message_list); |
89 i += read; | 89 i += read; |
90 } | 90 } |
91 | 91 |
92 // Then verify the decoded messages. | 92 // Then verify the decoded messages. |
93 EXPECT_EQ(31u, message_list.size()); | 93 EXPECT_EQ(31u, message_list.size()); |
94 EXPECT_TRUE(message_list.front()->has_init_client()); | 94 EXPECT_TRUE(message_list.front()->has_init_client()); |
95 delete message_list.front(); | 95 delete message_list.front(); |
96 message_list.pop_front(); | 96 message_list.pop_front(); |
(...skipping 30 matching lines...) Expand all Loading... |
127 const int kReads[] = {50, 50, 5}; | 127 const int kReads[] = {50, 50, 5}; |
128 SimulateReadSequence(kReads, arraysize(kReads)); | 128 SimulateReadSequence(kReads, arraysize(kReads)); |
129 } | 129 } |
130 | 130 |
131 TEST(MessageDecoderTest, EmptyReads) { | 131 TEST(MessageDecoderTest, EmptyReads) { |
132 const int kReads[] = {4, 0, 50, 0}; | 132 const int kReads[] = {4, 0, 50, 0}; |
133 SimulateReadSequence(kReads, arraysize(kReads)); | 133 SimulateReadSequence(kReads, arraysize(kReads)); |
134 } | 134 } |
135 | 135 |
136 } // namespace remoting | 136 } // namespace remoting |
OLD | NEW |