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
span_util_unittest.cpp
Go to the documentation of this file.
1// Copyright 2021 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/span_util.h"
6
7#include <vector>
8
9#include "testing/gtest/include/gtest/gtest.h"
10
12 std::vector<char> dst(4, 'B');
13 fxcrt::spanset(pdfium::make_span(dst).first(2), 'A');
14 EXPECT_EQ(dst[0], 'A');
15 EXPECT_EQ(dst[1], 'A');
16 EXPECT_EQ(dst[2], 'B');
17 EXPECT_EQ(dst[3], 'B');
18}
19
21 std::vector<char> dst(4, 'B');
22 fxcrt::spanset(pdfium::make_span(dst).subspan(4), 'A');
23 EXPECT_EQ(dst[0], 'B');
24 EXPECT_EQ(dst[1], 'B');
25 EXPECT_EQ(dst[2], 'B');
26 EXPECT_EQ(dst[3], 'B');
27}
28
30 std::vector<char> src(4, 'A');
31 std::vector<char> dst(4, 'B');
32 fxcrt::spancpy(pdfium::make_span(dst), pdfium::make_span(src));
33 EXPECT_EQ(dst[0], 'A');
34 EXPECT_EQ(dst[1], 'A');
35 EXPECT_EQ(dst[2], 'A');
36 EXPECT_EQ(dst[3], 'A');
37}
38
40 std::vector<char> src(2, 'A');
41 std::vector<char> dst(4, 'B');
42 // Also show that a const src argument is acceptable.
43 fxcrt::spancpy(pdfium::make_span(dst).subspan(1),
44 pdfium::span<const char>(src));
45 EXPECT_EQ(dst[0], 'B');
46 EXPECT_EQ(dst[1], 'A');
47 EXPECT_EQ(dst[2], 'A');
48 EXPECT_EQ(dst[3], 'B');
49}
50
52 std::vector<char> src(2, 'A');
53 std::vector<char> dst(4, 'B');
54 fxcrt::spancpy(pdfium::make_span(dst).subspan(1),
55 pdfium::make_span(src).subspan(2));
56 EXPECT_EQ(dst[0], 'B');
57 EXPECT_EQ(dst[1], 'B');
58 EXPECT_EQ(dst[2], 'B');
59 EXPECT_EQ(dst[3], 'B');
60}
61
63 std::vector<char> src(2, 'A');
64 std::vector<char> dst(4, 'B');
65 fxcrt::spancpy(pdfium::make_span(dst).subspan(4),
66 pdfium::make_span(src).subspan(2));
67 EXPECT_EQ(dst[0], 'B');
68 EXPECT_EQ(dst[1], 'B');
69 EXPECT_EQ(dst[2], 'B');
70 EXPECT_EQ(dst[3], 'B');
71}
72
74 std::vector<char> src(2, 'A');
75 std::vector<char> dst(4, 'B');
76 // Also show that a const src argument is acceptable.
77 fxcrt::spanmove(pdfium::make_span(dst).subspan(1),
78 pdfium::span<const char>(src));
79 EXPECT_EQ(dst[0], 'B');
80 EXPECT_EQ(dst[1], 'A');
81 EXPECT_EQ(dst[2], 'A');
82 EXPECT_EQ(dst[3], 'B');
83}
84
86 std::vector<char> src(2, 'A');
87 pdfium::span<char> span = pdfium::make_span(src);
88 span = span.subspan(2);
89 span = pdfium::make_span(src);
90 EXPECT_EQ(span.size(), 2u);
91}
92
94 pdfium::span<uint8_t> empty;
95 pdfium::span<uint32_t> converted = fxcrt::reinterpret_span<uint32_t>(empty);
96 EXPECT_EQ(converted.data(), nullptr);
97 EXPECT_EQ(converted.size(), 0u);
98}
99
101 uint8_t aaaabbbb[8] = {0x61, 0x61, 0x61, 0x61, 0x62, 0x62, 0x62, 0x62};
102 pdfium::span<uint8_t> original = pdfium::make_span(aaaabbbb);
103 pdfium::span<uint32_t> converted =
104 fxcrt::reinterpret_span<uint32_t>(original);
105 ASSERT_NE(converted.data(), nullptr);
106 ASSERT_EQ(converted.size(), 2u);
107 EXPECT_EQ(converted[0], 0x61616161u);
108 EXPECT_EQ(converted[1], 0x62626262u);
109}
110
112 uint8_t ab[2] = {0x61, 0x62};
113 EXPECT_DEATH(fxcrt::reinterpret_span<uint32_t>(pdfium::make_span(ab)), "");
114}
115
117 uint8_t abcabc[6] = {0x61, 0x62, 0x63, 0x61, 0x62, 0x63};
118 EXPECT_DEATH(fxcrt::reinterpret_span<uint32_t>(
119 pdfium::make_span(abcabc).subspan(1, 4)),
120 "");
121}
TEST(FXCRYPT, MD5GenerateEmtpyData)