Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
byteorder_unittest.cpp
Go to the documentation of this file.
1// Copyright 2019 The PDFium Authors
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 "core/fxcrt/byteorder.h"
6
7#include "core/fxcrt/fx_system.h"
8#include "testing/gtest/include/gtest/gtest.h"
9
10namespace {
11
12constexpr uint32_t kTestValues32[] = {
13 0x0, 0x1, 0x2, 0x3, 0x4, 0xfe,
14 0xff, 0x100, 0x101, 0xffff, 0x10000, 0x123456,
15 0x345167, 0x2f3e4a5b, 0xff000000, 0xfffffffe, 0xffffffff};
16
17} // namespace
18
19namespace fxcrt {
20
22 // Since there are so few values, test them all.
23 for (uint32_t v = 0; v < 0x10000; ++v) {
24 const uint16_t v16 = v;
26 FXSYS_UINT16_GET_LSBFIRST(reinterpret_cast<const uint8_t*>(&v16));
28
29 // Check safety against unexpectedly signed bytes.
30 expected = FXSYS_UINT16_GET_LSBFIRST(reinterpret_cast<const int8_t*>(&v16));
32 }
33}
34
36 for (uint32_t v : kTestValues32) {
38 FXSYS_UINT32_GET_LSBFIRST(reinterpret_cast<const uint8_t*>(&v));
40
41 // Check safety against unexpectedly signed bytes.
42 expected = FXSYS_UINT32_GET_LSBFIRST(reinterpret_cast<const int8_t*>(&v));
44 }
45}
46
48 // Since there are so few values, test them all.
49 for (uint32_t v = 0; v < 0x10000; ++v) {
50 const uint16_t v16 = v;
52 FXSYS_UINT16_GET_MSBFIRST(reinterpret_cast<const uint8_t*>(&v16));
54
55 // Check safety against unexpectedly signed bytes.
56 expected = FXSYS_UINT16_GET_MSBFIRST(reinterpret_cast<const int8_t*>(&v16));
58 }
59}
60
62 for (uint32_t v : kTestValues32) {
64 FXSYS_UINT32_GET_MSBFIRST(reinterpret_cast<const uint8_t*>(&v));
66
67 // Check safety against unexpectedly signed bytes.
68 expected = FXSYS_UINT32_GET_MSBFIRST(reinterpret_cast<const int8_t*>(&v));
70 }
71}
72
73} // namespace fxcrt
TEST(ByteOrder, ByteSwapToLE16)