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/gmock/include/gmock/gmock.h"
9
#
include
"testing/gtest/include/gtest/gtest.h"
10
11
namespace
{
12
13
constexpr
uint32_t kTestValues32[] = {
14
0x0, 0x1, 0x2, 0x3, 0x4, 0xfe,
15
0xff, 0x100, 0x101, 0xffff, 0x10000, 0x123456,
16
0x345167, 0x2f3e4a5b, 0xff000000, 0xfffffffe, 0xffffffff};
17
18
}
// namespace
19
20
namespace
fxcrt
{
21
22
TEST
(
ByteOrder
,
FromLE16
) {
23
// Since there are so few values, test them all.
24
for
(
uint32_t
v
= 0;
v
< 0x10000; ++
v
) {
25
const
uint16_t
v16
=
v
;
26
uint16_t
expected
=
GetUInt16LSBFirst
(
pdfium
::
byte_span_from_ref
(
v16
));
27
EXPECT_EQ
(
expected
,
FromLE16
(
v16
)) <<
v
;
28
}
29
}
30
31
TEST
(
ByteOrder
,
FromLE32
) {
32
for
(
uint32_t
v
:
kTestValues32
) {
33
uint32_t
expected
=
GetUInt32LSBFirst
(
pdfium
::
byte_span_from_ref
(
v
));
34
EXPECT_EQ
(
expected
,
FromLE32
(
v
)) <<
v
;
35
}
36
}
37
38
TEST
(
ByteOrder
,
FromBE16
) {
39
// Since there are so few values, test them all.
40
for
(
uint32_t
v
= 0;
v
< 0x10000; ++
v
) {
41
const
uint16_t
v16
=
v
;
42
uint16_t
expected
=
GetUInt16MSBFirst
(
pdfium
::
byte_span_from_ref
(
v16
));
43
EXPECT_EQ
(
expected
,
FromBE16
(
v16
)) <<
v
;
44
}
45
}
46
47
TEST
(
ByteOrder
,
FromBE32
) {
48
for
(
uint32_t
v
:
kTestValues32
) {
49
uint32_t
expected
=
GetUInt32MSBFirst
(
pdfium
::
byte_span_from_ref
(
v
));
50
EXPECT_EQ
(
expected
,
FromBE32
(
v
)) <<
v
;
51
}
52
}
53
54
TEST
(
ByteOrder
,
GetUInt16LSBFirst
) {
55
const
uint8_t
kBuf
[2] = {0xff, 0xfe};
56
EXPECT_EQ
(0xfeff,
GetUInt16LSBFirst
(
kBuf
));
57
}
58
59
TEST
(
ByteOrder
,
GetUInt16MSBFirst
) {
60
const
uint8_t
kBuf
[2] = {0xff, 0xfe};
61
EXPECT_EQ
(0xfffe,
GetUInt16MSBFirst
(
kBuf
));
62
}
63
64
TEST
(
ByteOrder
,
GetUInt32LSBFirst
) {
65
const
uint8_t
kBuf
[4] = {0xff, 0xfe, 0xfd, 0xfc};
66
EXPECT_EQ
(0xfcfdfeff,
GetUInt32LSBFirst
(
kBuf
));
67
}
68
69
TEST
(
ByteOrder
,
GetUInt32MSBFirst
) {
70
const
uint8_t
kBuf
[4] = {0xff, 0xfe, 0xfd, 0xfc};
71
EXPECT_EQ
(0xfffefdfc,
GetUInt32MSBFirst
(
kBuf
));
72
}
73
74
TEST
(
ByteOrder
,
PutUInt16LSBFirst
) {
75
uint8_t
buf
[2];
76
PutUInt16LSBFirst
(0xfffe,
buf
);
77
EXPECT_THAT
(
buf
,
testing
::
ElementsAre
(0xfe, 0xff));
78
}
79
80
TEST
(
ByteOrder
,
PutUInt16MSBFirst
) {
81
uint8_t
buf
[2];
82
PutUInt16MSBFirst
(0xfffe,
buf
);
83
EXPECT_THAT
(
buf
,
testing
::
ElementsAre
(0xff, 0xfe));
84
}
85
86
TEST
(
ByteOrder
,
PutUInt32LSBFirst
) {
87
uint8_t
buf
[4];
88
PutUInt32LSBFirst
(0xfffefdfc,
buf
);
89
EXPECT_THAT
(
buf
,
testing
::
ElementsAre
(0xfc, 0xfd, 0xfe, 0xff));
90
}
91
92
TEST
(
ByteOrder
,
PutUInt32MSBFirst
) {
93
uint8_t
buf
[4];
94
PutUInt32MSBFirst
(0xfffefdfc,
buf
);
95
EXPECT_THAT
(
buf
,
testing
::
ElementsAre
(0xff, 0xfe, 0xfd, 0xfc));
96
}
97
98
}
// namespace fxcrt
fxcrt
Definition
stl_util.h:17
fxcrt::TEST
TEST(ByteOrder, FromLE16)
Definition
byteorder_unittest.cpp:22
qtwebengine
src
3rdparty
chromium
third_party
pdfium
core
fxcrt
byteorder_unittest.cpp
Generated on
for Qt by
1.14.0