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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/byte_io_unittest.cc

Issue 1615653011: Fix a bug in webrtc::ByteReader (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 11 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/modules/rtp_rtcp/source/byte_io.h ('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 (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 sizeof(int32_t)>(false); 199 sizeof(int32_t)>(false);
200 } 200 }
201 201
202 TEST_F(ByteIoTest, Test64SBitLittleEndian) { 202 TEST_F(ByteIoTest, Test64SBitLittleEndian) {
203 TestRead<int64_t, ByteReader<int64_t>::ReadLittleEndian, 203 TestRead<int64_t, ByteReader<int64_t>::ReadLittleEndian,
204 sizeof(int64_t)>(false); 204 sizeof(int64_t)>(false);
205 TestWrite<int64_t, ByteWriter<int64_t>::WriteLittleEndian, 205 TestWrite<int64_t, ByteWriter<int64_t>::WriteLittleEndian,
206 sizeof(int64_t)>(false); 206 sizeof(int64_t)>(false);
207 } 207 }
208 208
209 // Sets up a fixed byte array and converts N bytes from the array into a
210 // uint64_t. Verifies the value with hard-coded reference.
211 TEST(ByteIo, SanityCheckFixedByteArrayUnsignedReadBigEndian) {
212 uint8_t data[8] = {0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88};
213 uint64_t value = ByteReader<uint64_t, 2>::ReadBigEndian(data);
214 EXPECT_EQ(static_cast<uint64_t>(0xFFEE), value);
215 value = ByteReader<uint64_t, 3>::ReadBigEndian(data);
216 EXPECT_EQ(static_cast<uint64_t>(0xFFEEDD), value);
217 value = ByteReader<uint64_t, 4>::ReadBigEndian(data);
218 EXPECT_EQ(static_cast<uint64_t>(0xFFEEDDCC), value);
219 value = ByteReader<uint64_t, 5>::ReadBigEndian(data);
220 EXPECT_EQ(static_cast<uint64_t>(0xFFEEDDCCBB), value);
221 value = ByteReader<uint64_t, 6>::ReadBigEndian(data);
222 EXPECT_EQ(static_cast<uint64_t>(0xFFEEDDCCBBAA), value);
223 value = ByteReader<uint64_t, 7>::ReadBigEndian(data);
224 EXPECT_EQ(static_cast<uint64_t>(0xFFEEDDCCBBAA99), value);
225 value = ByteReader<uint64_t, 8>::ReadBigEndian(data);
226 EXPECT_EQ(static_cast<uint64_t>(0xFFEEDDCCBBAA9988), value);
227 }
228
229 // Same as above, but for little-endian reading.
230 TEST(ByteIo, SanityCheckFixedByteArrayUnsignedReadLittleEndian) {
231 uint8_t data[8] = {0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88};
232 uint64_t value = ByteReader<uint64_t, 2>::ReadLittleEndian(data);
233 EXPECT_EQ(static_cast<uint64_t>(0xEEFF), value);
234 value = ByteReader<uint64_t, 3>::ReadLittleEndian(data);
235 EXPECT_EQ(static_cast<uint64_t>(0xDDEEFF), value);
236 value = ByteReader<uint64_t, 4>::ReadLittleEndian(data);
237 EXPECT_EQ(static_cast<uint64_t>(0xCCDDEEFF), value);
238 value = ByteReader<uint64_t, 5>::ReadLittleEndian(data);
239 EXPECT_EQ(static_cast<uint64_t>(0xBBCCDDEEFF), value);
240 value = ByteReader<uint64_t, 6>::ReadLittleEndian(data);
241 EXPECT_EQ(static_cast<uint64_t>(0xAABBCCDDEEFF), value);
242 value = ByteReader<uint64_t, 7>::ReadLittleEndian(data);
243 EXPECT_EQ(static_cast<uint64_t>(0x99AABBCCDDEEFF), value);
244 value = ByteReader<uint64_t, 8>::ReadLittleEndian(data);
245 EXPECT_EQ(static_cast<uint64_t>(0x8899AABBCCDDEEFF), value);
246 }
209 } // namespace 247 } // namespace
210 } // namespace webrtc 248 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/byte_io.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698