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 "remoting/base/compound_buffer.h" |
| 6 |
5 #include <stddef.h> | 7 #include <stddef.h> |
6 #include <stdint.h> | 8 #include <stdint.h> |
7 | 9 |
| 10 #include <memory> |
8 #include <string> | 11 #include <string> |
9 | 12 |
10 #include "base/bind.h" | 13 #include "base/bind.h" |
11 #include "base/callback.h" | 14 #include "base/callback.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
14 #include "remoting/base/compound_buffer.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 using net::IOBuffer; | 18 using net::IOBuffer; |
18 | 19 |
19 namespace remoting { | 20 namespace remoting { |
20 | 21 |
21 namespace { | 22 namespace { |
22 const int kDataSize = 1024; | 23 const int kDataSize = 1024; |
23 | 24 |
24 // Chunk sizes used to append and prepend data to the buffer. | 25 // Chunk sizes used to append and prepend data to the buffer. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 134 |
134 memcpy(out, in, in_size); | 135 memcpy(out, in, in_size); |
135 out += in_size; | 136 out += in_size; |
136 out_size -= in_size; | 137 out_size -= in_size; |
137 } | 138 } |
138 } | 139 } |
139 | 140 |
140 static void ReadString(CompoundBufferInputStream* input, | 141 static void ReadString(CompoundBufferInputStream* input, |
141 const std::string& str) { | 142 const std::string& str) { |
142 SCOPED_TRACE(str); | 143 SCOPED_TRACE(str); |
143 scoped_ptr<char[]> buffer(new char[str.size() + 1]); | 144 std::unique_ptr<char[]> buffer(new char[str.size() + 1]); |
144 buffer[str.size()] = '\0'; | 145 buffer[str.size()] = '\0'; |
145 EXPECT_EQ(ReadFromInput(input, buffer.get(), str.size()), str.size()); | 146 EXPECT_EQ(ReadFromInput(input, buffer.get(), str.size()), str.size()); |
146 EXPECT_STREQ(str.data(), buffer.get()); | 147 EXPECT_STREQ(str.data(), buffer.get()); |
147 } | 148 } |
148 | 149 |
149 // Construct and prepare data in the |buffer|. | 150 // Construct and prepare data in the |buffer|. |
150 static void PrepareData(scoped_ptr<CompoundBuffer>* buffer) { | 151 static void PrepareData(std::unique_ptr<CompoundBuffer>* buffer) { |
151 static const std::string kTestData = | 152 static const std::string kTestData = |
152 "Hello world!" | 153 "Hello world!" |
153 "This is testing" | 154 "This is testing" |
154 "MultipleArrayInputStream" | 155 "MultipleArrayInputStream" |
155 "for Chromoting"; | 156 "for Chromoting"; |
156 | 157 |
157 // Determine how many segments to split kTestData. We split the data in | 158 // Determine how many segments to split kTestData. We split the data in |
158 // 1 character, 2 characters, 1 character, 2 characters ... | 159 // 1 character, 2 characters, 1 character, 2 characters ... |
159 int segments = (kTestData.length() / 3) * 2; | 160 int segments = (kTestData.length() / 3) * 2; |
160 int remaining_chars = kTestData.length() % 3; | 161 int remaining_chars = kTestData.length() % 3; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 &CompoundBufferTest::TestCopyFrom, base::Unretained(this))); | 255 &CompoundBufferTest::TestCopyFrom, base::Unretained(this))); |
255 } | 256 } |
256 { | 257 { |
257 SCOPED_TRACE("CopyFrom.kCopySizes1"); | 258 SCOPED_TRACE("CopyFrom.kCopySizes1"); |
258 IterateOverPieces(kCopySizes1, base::Bind( | 259 IterateOverPieces(kCopySizes1, base::Bind( |
259 &CompoundBufferTest::TestCopyFrom, base::Unretained(this))); | 260 &CompoundBufferTest::TestCopyFrom, base::Unretained(this))); |
260 } | 261 } |
261 } | 262 } |
262 | 263 |
263 TEST_F(CompoundBufferTest, InputStream) { | 264 TEST_F(CompoundBufferTest, InputStream) { |
264 scoped_ptr<CompoundBuffer> buffer; | 265 std::unique_ptr<CompoundBuffer> buffer; |
265 PrepareData(&buffer); | 266 PrepareData(&buffer); |
266 CompoundBufferInputStream stream(buffer.get()); | 267 CompoundBufferInputStream stream(buffer.get()); |
267 | 268 |
268 ReadString(&stream, "Hello world!"); | 269 ReadString(&stream, "Hello world!"); |
269 ReadString(&stream, "This "); | 270 ReadString(&stream, "This "); |
270 ReadString(&stream, "is test"); | 271 ReadString(&stream, "is test"); |
271 EXPECT_TRUE(stream.Skip(3)); | 272 EXPECT_TRUE(stream.Skip(3)); |
272 ReadString(&stream, "MultipleArrayInput"); | 273 ReadString(&stream, "MultipleArrayInput"); |
273 EXPECT_TRUE(stream.Skip(6)); | 274 EXPECT_TRUE(stream.Skip(6)); |
274 ReadString(&stream, "f"); | 275 ReadString(&stream, "f"); |
275 ReadString(&stream, "o"); | 276 ReadString(&stream, "o"); |
276 ReadString(&stream, "r"); | 277 ReadString(&stream, "r"); |
277 ReadString(&stream, " "); | 278 ReadString(&stream, " "); |
278 ReadString(&stream, "Chromoting"); | 279 ReadString(&stream, "Chromoting"); |
279 } | 280 } |
280 | 281 |
281 } // namespace remoting | 282 } // namespace remoting |
OLD | NEW |