OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "remoting/proto/event.pb.h" | 10 #include "remoting/proto/event.pb.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 *size = encoded_data.length(); | 43 *size = encoded_data.length(); |
44 *buffer = new uint8[*size]; | 44 *buffer = new uint8[*size]; |
45 memcpy(*buffer, encoded_data.c_str(), *size); | 45 memcpy(*buffer, encoded_data.c_str(), *size); |
46 } | 46 } |
47 | 47 |
48 void SimulateReadSequence(const int read_sequence[], int sequence_size) { | 48 void SimulateReadSequence(const int read_sequence[], int sequence_size) { |
49 // Prepare encoded data for testing. | 49 // Prepare encoded data for testing. |
50 int size; | 50 int size; |
51 uint8* test_data; | 51 uint8* test_data; |
52 PrepareData(&test_data, &size); | 52 PrepareData(&test_data, &size); |
53 scoped_array<uint8> memory_deleter(test_data); | 53 scoped_ptr<uint8[]> memory_deleter(test_data); |
54 | 54 |
55 // Then simulate using MessageDecoder to decode variable | 55 // Then simulate using MessageDecoder to decode variable |
56 // size of encoded data. | 56 // size of encoded data. |
57 // The first thing to do is to generate a variable size of data. This is done | 57 // The first thing to do is to generate a variable size of data. This is done |
58 // by iterating the following array for read sizes. | 58 // by iterating the following array for read sizes. |
59 MessageDecoder decoder; | 59 MessageDecoder decoder; |
60 | 60 |
61 // Then feed the protocol decoder using the above generated data and the | 61 // Then feed the protocol decoder using the above generated data and the |
62 // read pattern. | 62 // read pattern. |
63 std::list<EventMessage*> message_list; | 63 std::list<EventMessage*> message_list; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 SimulateReadSequence(kReads, arraysize(kReads)); | 116 SimulateReadSequence(kReads, arraysize(kReads)); |
117 } | 117 } |
118 | 118 |
119 TEST(MessageDecoderTest, EmptyReads) { | 119 TEST(MessageDecoderTest, EmptyReads) { |
120 const int kReads[] = {4, 0, 50, 0}; | 120 const int kReads[] = {4, 0, 50, 0}; |
121 SimulateReadSequence(kReads, arraysize(kReads)); | 121 SimulateReadSequence(kReads, arraysize(kReads)); |
122 } | 122 } |
123 | 123 |
124 } // namespace protocol | 124 } // namespace protocol |
125 } // namespace remoting | 125 } // namespace remoting |
OLD | NEW |