Flutter Engine
The Flutter Engine
endianness_unittests.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/fml/endianness.h"
6
7#include "flutter/testing/testing.h"
8
9namespace fml {
10namespace testing {
11
12TEST(EndiannessTest, ByteSwap) {
13 ASSERT_EQ(ByteSwap<int16_t>(0x1122), 0x2211);
14 ASSERT_EQ(ByteSwap<int32_t>(0x11223344), 0x44332211);
15 ASSERT_EQ(ByteSwap<uint64_t>(0x1122334455667788), 0x8877665544332211);
16}
17
18TEST(EndiannessTest, BigEndianToArch) {
19#if FML_ARCH_CPU_LITTLE_ENDIAN
20 uint32_t expected = 0x44332211;
21#else
22 uint32_t expected = 0x11223344;
23#endif
24 ASSERT_EQ(BigEndianToArch(0x11223344u), expected);
25}
26
27TEST(EndiannessTest, LittleEndianToArch) {
28#if FML_ARCH_CPU_LITTLE_ENDIAN
29 uint32_t expected = 0x11223344;
30#else
31 uint32_t expected = 0x44332211;
32#endif
33 ASSERT_EQ(LittleEndianToArch(0x11223344u), expected);
34}
35
36} // namespace testing
37} // namespace fml
TEST(BacktraceTest, CanGatherBacktrace)
Definition: ascii_trie.cc:9
constexpr T BigEndianToArch(T n)
Convert a known big endian value to match the endianness of the current architecture....
Definition: endianness.h:59
constexpr T ByteSwap(T n)
Flips the endianness of the given value. The given value must be an integral type of size 1,...
Definition: endianness.h:40
constexpr T LittleEndianToArch(T n)
Convert a known little endian value to match the endianness of the current architecture....
Definition: endianness.h:71