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

Side by Side Diff: webrtc/base/bytebuffer_unittest.cc

Issue 1844333006: Add WriteUVarint to ByteBufferWriter and ReadUVarint to ByteBufferReader (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix typo 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 | « webrtc/base/bytebuffer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 EXPECT_EQ(wu24, ru24); 189 EXPECT_EQ(wu24, ru24);
190 EXPECT_TRUE(read_buf9.ReadUInt32(&ru32)); 190 EXPECT_TRUE(read_buf9.ReadUInt32(&ru32));
191 EXPECT_EQ(wu32, ru32); 191 EXPECT_EQ(wu32, ru32);
192 EXPECT_TRUE(read_buf9.ReadUInt64(&ru64)); 192 EXPECT_TRUE(read_buf9.ReadUInt64(&ru64));
193 EXPECT_EQ(wu64, ru64); 193 EXPECT_EQ(wu64, ru64);
194 EXPECT_EQ(0U, read_buf9.Length()); 194 EXPECT_EQ(0U, read_buf9.Length());
195 buffer.Clear(); 195 buffer.Clear();
196 } 196 }
197 } 197 }
198 198
199 TEST(ByteBufferTest, TestReadWriteUVarint) {
200 ByteBufferWriter::ByteOrder orders[2] = {ByteBufferWriter::ORDER_HOST,
201 ByteBufferWriter::ORDER_NETWORK};
202 for (ByteBufferWriter::ByteOrder& order : orders) {
203 ByteBufferWriter write_buffer(order);
204 size_t size = 0;
205 EXPECT_EQ(size, write_buffer.Length());
206
207 write_buffer.WriteUVarint(1u);
208 ++size;
209 EXPECT_EQ(size, write_buffer.Length());
210
211 write_buffer.WriteUVarint(2u);
212 ++size;
213 EXPECT_EQ(size, write_buffer.Length());
214
215 write_buffer.WriteUVarint(27u);
216 ++size;
217 EXPECT_EQ(size, write_buffer.Length());
218
219 write_buffer.WriteUVarint(149u);
220 size += 2;
221 EXPECT_EQ(size, write_buffer.Length());
222
223 write_buffer.WriteUVarint(68719476736u);
224 size += 6;
225 EXPECT_EQ(size, write_buffer.Length());
226
227 ByteBufferReader read_buffer(write_buffer.Data(), write_buffer.Length(),
228 order);
229 EXPECT_EQ(size, read_buffer.Length());
230 uint64_t val1, val2, val3, val4, val5;
231
232 ASSERT_TRUE(read_buffer.ReadUVarint(&val1));
233 EXPECT_EQ(1u, val1);
234 --size;
235 EXPECT_EQ(size, read_buffer.Length());
236
237 ASSERT_TRUE(read_buffer.ReadUVarint(&val2));
238 EXPECT_EQ(2u, val2);
239 --size;
240 EXPECT_EQ(size, read_buffer.Length());
241
242 ASSERT_TRUE(read_buffer.ReadUVarint(&val3));
243 EXPECT_EQ(27u, val3);
244 --size;
245 EXPECT_EQ(size, read_buffer.Length());
246
247 ASSERT_TRUE(read_buffer.ReadUVarint(&val4));
248 EXPECT_EQ(149u, val4);
249 size -= 2;
250 EXPECT_EQ(size, read_buffer.Length());
251
252 ASSERT_TRUE(read_buffer.ReadUVarint(&val5));
253 EXPECT_EQ(68719476736u, val5);
254 size -= 6;
255 EXPECT_EQ(size, read_buffer.Length());
256 }
257 }
258
199 } // namespace rtc 259 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/bytebuffer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698