mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-12 21:30:45 +01:00

This CL was generated by running git ls-files | grep -P "(\.h|\.cc)$" | grep -v 'sdk/' | grep -v 'rtc_base/ssl_' | \ grep -v 'fake_rtc_certificate_generator.h' | grep -v 'modules/audio_device/win/' | \ grep -v 'system_wrappers/source/clock.cc' | grep -v 'rtc_base/trace_event.h' | \ grep -v 'modules/audio_coding/codecs/ilbc/' | grep -v 'screen_capturer_mac.h' | \ grep -v 'spl_inl_mips.h' | grep -v 'data_size_unittest.cc' | grep -v 'timestamp_unittest.cc' \ | xargs clang-format -i ; git cl format Most of these changes are clang-format grouping and reordering includes differently. Bug: webrtc:9340 Change-Id: Ic83ddbc169bfacd21883e381b5181c3dd4fe8a63 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/144051 Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#28505}
83 lines
2.3 KiB
C++
83 lines
2.3 KiB
C++
/*
|
|
* Copyright 2012 The WebRTC Project Authors. All rights reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "rtc_base/byte_order.h"
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "test/gtest.h"
|
|
|
|
namespace rtc {
|
|
|
|
// Test memory set functions put values into memory in expected order.
|
|
TEST(ByteOrderTest, TestSet) {
|
|
uint8_t buf[8] = {0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u};
|
|
Set8(buf, 0, 0xfb);
|
|
Set8(buf, 1, 0x12);
|
|
EXPECT_EQ(0xfb, buf[0]);
|
|
EXPECT_EQ(0x12, buf[1]);
|
|
SetBE16(buf, 0x1234);
|
|
EXPECT_EQ(0x12, buf[0]);
|
|
EXPECT_EQ(0x34, buf[1]);
|
|
SetLE16(buf, 0x1234);
|
|
EXPECT_EQ(0x34, buf[0]);
|
|
EXPECT_EQ(0x12, buf[1]);
|
|
SetBE32(buf, 0x12345678);
|
|
EXPECT_EQ(0x12, buf[0]);
|
|
EXPECT_EQ(0x34, buf[1]);
|
|
EXPECT_EQ(0x56, buf[2]);
|
|
EXPECT_EQ(0x78, buf[3]);
|
|
SetLE32(buf, 0x12345678);
|
|
EXPECT_EQ(0x78, buf[0]);
|
|
EXPECT_EQ(0x56, buf[1]);
|
|
EXPECT_EQ(0x34, buf[2]);
|
|
EXPECT_EQ(0x12, buf[3]);
|
|
SetBE64(buf, UINT64_C(0x0123456789abcdef));
|
|
EXPECT_EQ(0x01, buf[0]);
|
|
EXPECT_EQ(0x23, buf[1]);
|
|
EXPECT_EQ(0x45, buf[2]);
|
|
EXPECT_EQ(0x67, buf[3]);
|
|
EXPECT_EQ(0x89, buf[4]);
|
|
EXPECT_EQ(0xab, buf[5]);
|
|
EXPECT_EQ(0xcd, buf[6]);
|
|
EXPECT_EQ(0xef, buf[7]);
|
|
SetLE64(buf, UINT64_C(0x0123456789abcdef));
|
|
EXPECT_EQ(0xef, buf[0]);
|
|
EXPECT_EQ(0xcd, buf[1]);
|
|
EXPECT_EQ(0xab, buf[2]);
|
|
EXPECT_EQ(0x89, buf[3]);
|
|
EXPECT_EQ(0x67, buf[4]);
|
|
EXPECT_EQ(0x45, buf[5]);
|
|
EXPECT_EQ(0x23, buf[6]);
|
|
EXPECT_EQ(0x01, buf[7]);
|
|
}
|
|
|
|
// Test memory get functions get values from memory in expected order.
|
|
TEST(ByteOrderTest, TestGet) {
|
|
uint8_t buf[8];
|
|
buf[0] = 0x01u;
|
|
buf[1] = 0x23u;
|
|
buf[2] = 0x45u;
|
|
buf[3] = 0x67u;
|
|
buf[4] = 0x89u;
|
|
buf[5] = 0xabu;
|
|
buf[6] = 0xcdu;
|
|
buf[7] = 0xefu;
|
|
EXPECT_EQ(0x01u, Get8(buf, 0));
|
|
EXPECT_EQ(0x23u, Get8(buf, 1));
|
|
EXPECT_EQ(0x0123u, GetBE16(buf));
|
|
EXPECT_EQ(0x2301u, GetLE16(buf));
|
|
EXPECT_EQ(0x01234567u, GetBE32(buf));
|
|
EXPECT_EQ(0x67452301u, GetLE32(buf));
|
|
EXPECT_EQ(UINT64_C(0x0123456789abcdef), GetBE64(buf));
|
|
EXPECT_EQ(UINT64_C(0xefcdab8967452301), GetLE64(buf));
|
|
}
|
|
|
|
} // namespace rtc
|