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

Side by Side Diff: remoting/protocol/message_decoder_unittest.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU Created 4 years, 8 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 | « remoting/protocol/message_channel_factory.h ('k') | remoting/protocol/message_pipe.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "remoting/protocol/message_decoder.h"
6
5 #include <stdint.h> 7 #include <stdint.h>
6 8
9 #include <memory>
7 #include <string> 10 #include <string>
8 11
9 #include "base/macros.h" 12 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/stl_util.h" 13 #include "base/stl_util.h"
12 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
13 #include "remoting/proto/event.pb.h" 15 #include "remoting/proto/event.pb.h"
14 #include "remoting/proto/internal.pb.h" 16 #include "remoting/proto/internal.pb.h"
15 #include "remoting/protocol/message_decoder.h"
16 #include "remoting/protocol/message_serialization.h" 17 #include "remoting/protocol/message_serialization.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 namespace remoting { 20 namespace remoting {
20 namespace protocol { 21 namespace protocol {
21 22
22 static const unsigned int kTestKey = 142; 23 static const unsigned int kTestKey = 142;
23 24
24 static void AppendMessage(const EventMessage& msg, 25 static void AppendMessage(const EventMessage& msg,
25 std::string* buffer) { 26 std::string* buffer) {
(...skipping 20 matching lines...) Expand all
46 *size = encoded_data.length(); 47 *size = encoded_data.length();
47 *buffer = new uint8_t[*size]; 48 *buffer = new uint8_t[*size];
48 memcpy(*buffer, encoded_data.c_str(), *size); 49 memcpy(*buffer, encoded_data.c_str(), *size);
49 } 50 }
50 51
51 void SimulateReadSequence(const int read_sequence[], int sequence_size) { 52 void SimulateReadSequence(const int read_sequence[], int sequence_size) {
52 // Prepare encoded data for testing. 53 // Prepare encoded data for testing.
53 int size; 54 int size;
54 uint8_t* test_data; 55 uint8_t* test_data;
55 PrepareData(&test_data, &size); 56 PrepareData(&test_data, &size);
56 scoped_ptr<uint8_t[]> memory_deleter(test_data); 57 std::unique_ptr<uint8_t[]> memory_deleter(test_data);
57 58
58 // Then simulate using MessageDecoder to decode variable 59 // Then simulate using MessageDecoder to decode variable
59 // size of encoded data. 60 // size of encoded data.
60 // The first thing to do is to generate a variable size of data. This is done 61 // The first thing to do is to generate a variable size of data. This is done
61 // by iterating the following array for read sizes. 62 // by iterating the following array for read sizes.
62 MessageDecoder decoder; 63 MessageDecoder decoder;
63 64
64 // Then feed the protocol decoder using the above generated data and the 65 // Then feed the protocol decoder using the above generated data and the
65 // read pattern. 66 // read pattern.
66 std::list<EventMessage*> message_list; 67 std::list<EventMessage*> message_list;
67 for (int pos = 0; pos < size;) { 68 for (int pos = 0; pos < size;) {
68 SCOPED_TRACE("Input position: " + base::IntToString(pos)); 69 SCOPED_TRACE("Input position: " + base::IntToString(pos));
69 70
70 // First generate the amount to feed the decoder. 71 // First generate the amount to feed the decoder.
71 int read = std::min(size - pos, read_sequence[pos % sequence_size]); 72 int read = std::min(size - pos, read_sequence[pos % sequence_size]);
72 73
73 // And then prepare an IOBuffer for feeding it. 74 // And then prepare an IOBuffer for feeding it.
74 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(read)); 75 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(read));
75 memcpy(buffer->data(), test_data + pos, read); 76 memcpy(buffer->data(), test_data + pos, read);
76 decoder.AddData(buffer, read); 77 decoder.AddData(buffer, read);
77 while (true) { 78 while (true) {
78 scoped_ptr<CompoundBuffer> message(decoder.GetNextMessage()); 79 std::unique_ptr<CompoundBuffer> message(decoder.GetNextMessage());
79 if (!message.get()) 80 if (!message.get())
80 break; 81 break;
81 82
82 EventMessage* event = new EventMessage(); 83 EventMessage* event = new EventMessage();
83 CompoundBufferInputStream stream(message.get()); 84 CompoundBufferInputStream stream(message.get());
84 ASSERT_TRUE(event->ParseFromZeroCopyStream(&stream)); 85 ASSERT_TRUE(event->ParseFromZeroCopyStream(&stream));
85 message_list.push_back(event); 86 message_list.push_back(event);
86 } 87 }
87 pos += read; 88 pos += read;
88 } 89 }
(...skipping 30 matching lines...) Expand all
119 SimulateReadSequence(kReads, arraysize(kReads)); 120 SimulateReadSequence(kReads, arraysize(kReads));
120 } 121 }
121 122
122 TEST(MessageDecoderTest, EmptyReads) { 123 TEST(MessageDecoderTest, EmptyReads) {
123 const int kReads[] = {4, 0, 50, 0}; 124 const int kReads[] = {4, 0, 50, 0};
124 SimulateReadSequence(kReads, arraysize(kReads)); 125 SimulateReadSequence(kReads, arraysize(kReads));
125 } 126 }
126 127
127 } // namespace protocol 128 } // namespace protocol
128 } // namespace remoting 129 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/message_channel_factory.h ('k') | remoting/protocol/message_pipe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698