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
utf16_unittest.cpp
Go to the documentation of this file.
1// Copyright 2023 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/utf16.h"
6
7#include "testing/gtest/include/gtest/gtest.h"
8
9namespace pdfium {
10
11static_assert(kSurrogateMask == 0x3ff);
12static_assert(kMaximumSupplementaryCodePoint == 0x10ffff);
13static_assert(kMaximumHighSurrogateCodeUnit == 0xdbff);
14static_assert(kMinimumLowSurrogateCodeUnit == 0xdc00);
15static_assert(kMaximumLowSurrogateCodeUnit == 0xdfff);
16
17static_assert(!IsSupplementary(0xffff));
18static_assert(IsSupplementary(0x10000));
19static_assert(IsSupplementary(0x10ffff));
20static_assert(!IsSupplementary(0x110000));
21
22static_assert(!IsHighSurrogate(0xd7ff));
23static_assert(IsHighSurrogate(0xd800));
24static_assert(IsHighSurrogate(0xdbff));
25static_assert(!IsHighSurrogate(0xdc00));
26
27static_assert(!IsLowSurrogate(0xdbff));
28static_assert(IsLowSurrogate(0xdc00));
29static_assert(IsLowSurrogate(0xdfff));
30static_assert(!IsLowSurrogate(0xe000));
31
32static_assert(SurrogatePair(0xd800, 0xdc00).high() == 0xd800);
33static_assert(SurrogatePair(0xd800, 0xdc00).low() == 0xdc00);
34static_assert(SurrogatePair(0xd800, 0xdc00).ToCodePoint() == 0x10000);
35
36static_assert(SurrogatePair(0xdbff, 0xdfff).high() == 0xdbff);
37static_assert(SurrogatePair(0xdbff, 0xdfff).low() == 0xdfff);
38static_assert(SurrogatePair(0xdbff, 0xdfff).ToCodePoint() == 0x10ffff);
39
40static_assert(SurrogatePair(0x10000).high() == 0xd800);
41static_assert(SurrogatePair(0x10000).low() == 0xdc00);
42static_assert(SurrogatePair(0x10000).ToCodePoint() == 0x10000);
43
44static_assert(SurrogatePair(0x10ffff).high() == 0xdbff);
45static_assert(SurrogatePair(0x10ffff).low() == 0xdfff);
46static_assert(SurrogatePair(0x10ffff).ToCodePoint() == 0x10ffff);
47
49 for (char32_t code_point = kMinimumSupplementaryCodePoint;
50 code_point <= kMaximumSupplementaryCodePoint; ++code_point) {
51 SurrogatePair from_code_point(code_point);
52 EXPECT_EQ(code_point, from_code_point.ToCodePoint());
53
54 SurrogatePair from_pair(from_code_point.high(), from_code_point.low());
55 EXPECT_EQ(from_code_point.high(), from_pair.high());
56 EXPECT_EQ(from_code_point.low(), from_pair.low());
57 EXPECT_EQ(code_point, from_pair.ToCodePoint());
58 }
59}
60
61} // namespace pdfium
constexpr SurrogatePair(char32_t code_point)
Definition utf16.h:71
constexpr char16_t high() const
Definition utf16.h:78
constexpr char32_t ToCodePoint() const
Definition utf16.h:82
constexpr SurrogatePair(char16_t high, char16_t low)
Definition utf16.h:64
constexpr char16_t low() const
Definition utf16.h:79
constexpr bool IsSupplementary(char32_t code_point)
Definition utf16.h:43
constexpr char32_t kMaximumSupplementaryCodePoint
Definition utf16.h:22
constexpr char32_t kMinimumSupplementaryCodePoint
Definition utf16.h:19
TEST(SurrogatePairTest, RoundTrip)
constexpr bool IsHighSurrogate(char32_t code_point)
Definition utf16.h:49
constexpr char16_t kMaximumHighSurrogateCodeUnit
Definition utf16.h:30
constexpr char16_t kMaximumLowSurrogateCodeUnit
Definition utf16.h:38
constexpr char16_t kSurrogateMask
Definition utf16.h:16
constexpr bool IsLowSurrogate(char32_t code_point)
Definition utf16.h:55
constexpr char16_t kMinimumLowSurrogateCodeUnit
Definition utf16.h:34