OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 | 154 |
155 // Write and read uint64_t. | 155 // Write and read uint64_t. |
156 uint32_t another32 = (8 << 24) + (7 << 16) + (6 << 8) + 5; | 156 uint32_t another32 = (8 << 24) + (7 << 16) + (6 << 8) + 5; |
157 uint64_t wu64 = (static_cast<uint64_t>(another32) << 32) + wu32; | 157 uint64_t wu64 = (static_cast<uint64_t>(another32) << 32) + wu32; |
158 buffer.WriteUInt64(wu64); | 158 buffer.WriteUInt64(wu64); |
159 uint64_t ru64; | 159 uint64_t ru64; |
160 EXPECT_TRUE(buffer.ReadUInt64(&ru64)); | 160 EXPECT_TRUE(buffer.ReadUInt64(&ru64)); |
161 EXPECT_EQ(wu64, ru64); | 161 EXPECT_EQ(wu64, ru64); |
162 EXPECT_EQ(0U, buffer.Length()); | 162 EXPECT_EQ(0U, buffer.Length()); |
163 | 163 |
164 // Write and read varint. | |
pthatcher1
2016/03/30 20:34:50
What does this mean?
mikescarlett
2016/04/05 19:58:52
This doesn't belong here, removed
| |
165 | |
164 // Write and read string. | 166 // Write and read string. |
165 std::string write_string("hello"); | 167 std::string write_string("hello"); |
166 buffer.WriteString(write_string); | 168 buffer.WriteString(write_string); |
167 std::string read_string; | 169 std::string read_string; |
168 EXPECT_TRUE(buffer.ReadString(&read_string, write_string.size())); | 170 EXPECT_TRUE(buffer.ReadString(&read_string, write_string.size())); |
169 EXPECT_EQ(write_string, read_string); | 171 EXPECT_EQ(write_string, read_string); |
170 EXPECT_EQ(0U, buffer.Length()); | 172 EXPECT_EQ(0U, buffer.Length()); |
171 | 173 |
172 // Write and read bytes | 174 // Write and read bytes |
173 char write_bytes[] = "foo"; | 175 char write_bytes[] = "foo"; |
(...skipping 28 matching lines...) Expand all Loading... | |
202 EXPECT_TRUE(buffer.ReadUInt24(&ru24)); | 204 EXPECT_TRUE(buffer.ReadUInt24(&ru24)); |
203 EXPECT_EQ(wu24, ru24); | 205 EXPECT_EQ(wu24, ru24); |
204 EXPECT_TRUE(buffer.ReadUInt32(&ru32)); | 206 EXPECT_TRUE(buffer.ReadUInt32(&ru32)); |
205 EXPECT_EQ(wu32, ru32); | 207 EXPECT_EQ(wu32, ru32); |
206 EXPECT_TRUE(buffer.ReadUInt64(&ru64)); | 208 EXPECT_TRUE(buffer.ReadUInt64(&ru64)); |
207 EXPECT_EQ(wu64, ru64); | 209 EXPECT_EQ(wu64, ru64); |
208 EXPECT_EQ(0U, buffer.Length()); | 210 EXPECT_EQ(0U, buffer.Length()); |
209 } | 211 } |
210 } | 212 } |
211 | 213 |
214 TEST(ByteBufferTest, TestReadWriteVarint) { | |
pthatcher1
2016/03/30 20:34:50
Uvarint
mikescarlett
2016/04/05 19:58:52
Done.
| |
215 ByteBuffer write_buffer(nullptr, 0, rtc::ByteBuffer::ByteOrder::ORDER_HOST); | |
216 size_t size = 0; | |
217 EXPECT_EQ(size, write_buffer.Length()); | |
218 | |
219 write_buffer.WriteVarint(1u); | |
220 ++size; | |
221 EXPECT_EQ(size, write_buffer.Length()); | |
222 | |
223 write_buffer.WriteVarint(2u); | |
224 ++size; | |
225 EXPECT_EQ(size, write_buffer.Length()); | |
226 | |
227 write_buffer.WriteVarint(27u); | |
228 ++size; | |
229 EXPECT_EQ(size, write_buffer.Length()); | |
230 | |
231 write_buffer.WriteVarint(149u); | |
232 size += 2; | |
233 EXPECT_EQ(size, write_buffer.Length()); | |
234 | |
235 write_buffer.WriteVarint(68719476736u); | |
236 size += 6; | |
237 EXPECT_EQ(size, write_buffer.Length()); | |
238 | |
239 ByteBuffer read_buffer(write_buffer.Data(), write_buffer.Length(), | |
240 rtc::ByteBuffer::ByteOrder::ORDER_HOST); | |
pthatcher1
2016/03/30 20:34:50
Test with ORDER_NETWORK also.
mikescarlett
2016/04/05 19:58:52
Done.
| |
241 EXPECT_EQ(size, read_buffer.Length()); | |
242 uint64_t val1, val2, val3, val4, val5; | |
243 | |
244 ASSERT_TRUE(read_buffer.ReadVarint(&val1)); | |
245 EXPECT_EQ(1u, val1); | |
246 --size; | |
247 EXPECT_EQ(size, read_buffer.Length()); | |
248 | |
249 ASSERT_TRUE(read_buffer.ReadVarint(&val2)); | |
250 EXPECT_EQ(2u, val2); | |
251 --size; | |
252 EXPECT_EQ(size, read_buffer.Length()); | |
253 | |
254 ASSERT_TRUE(read_buffer.ReadVarint(&val3)); | |
255 EXPECT_EQ(27u, val3); | |
256 --size; | |
257 EXPECT_EQ(size, read_buffer.Length()); | |
258 | |
259 ASSERT_TRUE(read_buffer.ReadVarint(&val4)); | |
260 EXPECT_EQ(149u, val4); | |
261 size -= 2; | |
262 EXPECT_EQ(size, read_buffer.Length()); | |
263 | |
264 ASSERT_TRUE(read_buffer.ReadVarint(&val5)); | |
265 EXPECT_EQ(68719476736u, val5); | |
266 size -= 6; | |
267 EXPECT_EQ(size, read_buffer.Length()); | |
268 } | |
269 | |
212 } // namespace rtc | 270 } // namespace rtc |
OLD | NEW |