forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathendianness_unittests.cc
37 lines (30 loc) · 956 Bytes
/
endianness_unittests.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/fml/endianness.h"
#include "flutter/testing/testing.h"
namespace fml {
namespace testing {
TEST(EndiannessTest, ByteSwap) {
ASSERT_EQ(ByteSwap<int16_t>(0x1122), 0x2211);
ASSERT_EQ(ByteSwap<int32_t>(0x11223344), 0x44332211);
ASSERT_EQ(ByteSwap<uint64_t>(0x1122334455667788), 0x8877665544332211);
}
TEST(EndiannessTest, BigEndianToArch) {
#if FML_ARCH_CPU_LITTLE_ENDIAN
uint32_t expected = 0x44332211;
#else
uint32_t expected = 0x11223344;
#endif
ASSERT_EQ(BigEndianToArch(0x11223344u), expected);
}
TEST(EndiannessTest, LittleEndianToArch) {
#if FML_ARCH_CPU_LITTLE_ENDIAN
uint32_t expected = 0x11223344;
#else
uint32_t expected = 0x44332211;
#endif
ASSERT_EQ(LittleEndianToArch(0x11223344u), expected);
}
} // namespace testing
} // namespace fml