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
rle_unittest.cpp
Go to the documentation of this file.
1// Copyright 2016 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 <stdint.h>
6
7#include <array>
8#include <limits>
9#include <memory>
10
11#include "core/fpdfapi/parser/fpdf_parser_decode.h"
12#include "core/fxcodec/basic/basicmodule.h"
13#include "core/fxcodec/data_and_bytes_consumed.h"
14#include "core/fxcrt/data_vector.h"
15#include "testing/gmock/include/gmock/gmock.h"
16#include "testing/gtest/include/gtest/gtest.h"
17
18using ::testing::ElementsAreArray;
19
20TEST(fxcodec, RLEEmptyInput) {
21 EXPECT_TRUE(BasicModule::RunLengthEncode({}).empty());
22}
23
24// Check length 1 input works. Check terminating character is applied.
25TEST(fxcodec, RLEShortInput) {
26 const uint8_t src_buf[] = {1};
27 DataVector<uint8_t> dest_buf = BasicModule::RunLengthEncode(src_buf);
28 ASSERT_EQ(3u, dest_buf.size());
29 EXPECT_EQ(0, dest_buf[0]);
30 EXPECT_EQ(1, dest_buf[1]);
31 EXPECT_EQ(128, dest_buf[2]);
32}
33
34// Check a few basic cases (2 matching runs in a row, matching run followed
35// by a non-matching run, and non-matching run followed by a matching run).
36TEST(fxcodec, RLENormalInputs) {
37 {
38 // Case 1: Match, match
39 const uint8_t src_buf_1[] = {2, 2, 2, 2, 4, 4, 4, 4, 4, 4};
40 DataVector<uint8_t> dest_buf = BasicModule::RunLengthEncode(src_buf_1);
41 DataAndBytesConsumed result = RunLengthDecode(dest_buf);
42 EXPECT_THAT(result.data, ElementsAreArray(src_buf_1));
43 }
44 {
45 // Case 2: Match, non-match
46 const uint8_t src_buf_2[] = {2, 2, 2, 2, 1, 2, 3, 4, 5, 6};
47 DataVector<uint8_t> dest_buf = BasicModule::RunLengthEncode(src_buf_2);
48 DataAndBytesConsumed result = RunLengthDecode(dest_buf);
49 EXPECT_THAT(result.data, ElementsAreArray(src_buf_2));
50 }
51 {
52 // Case 3: Non-match, match
53 const uint8_t src_buf_3[] = {1, 2, 3, 4, 5, 3, 3, 3, 3, 3};
54 DataVector<uint8_t> dest_buf = BasicModule::RunLengthEncode(src_buf_3);
55 DataAndBytesConsumed result = RunLengthDecode(dest_buf);
56 EXPECT_THAT(result.data, ElementsAreArray(src_buf_3));
57 }
58}
59
60// Check that runs longer than 128 are broken up properly, both matched and
61// non-matched.
62TEST(fxcodec, RLEFullLengthInputs) {
63 {
64 // Case 1: Match, match
65 std::array<uint8_t, 260> src_buf_1 = {{1}};
66 DataVector<uint8_t> dest_buf = BasicModule::RunLengthEncode(src_buf_1);
67 DataAndBytesConsumed result = RunLengthDecode(dest_buf);
68 EXPECT_THAT(result.data, ElementsAreArray(src_buf_1));
69 }
70 {
71 // Case 2: Match, non-match
72 std::array<uint8_t, 260> src_buf_2 = {{2}};
73 for (uint16_t i = 128; i < 260; i++)
74 src_buf_2[i] = static_cast<uint8_t>(i - 125);
75 DataVector<uint8_t> dest_buf = BasicModule::RunLengthEncode(src_buf_2);
76 DataAndBytesConsumed result = RunLengthDecode(dest_buf);
77 EXPECT_THAT(result.data, ElementsAreArray(src_buf_2));
78 }
79 {
80 // Case 3: Non-match, match
81 std::array<uint8_t, 260> src_buf_3 = {};
82 for (uint8_t i = 0; i < 128; i++)
83 src_buf_3[i] = i;
84 DataVector<uint8_t> dest_buf = BasicModule::RunLengthEncode(src_buf_3);
85 DataAndBytesConsumed result = RunLengthDecode(dest_buf);
86 EXPECT_THAT(result.data, ElementsAreArray(src_buf_3));
87 }
88 {
89 // Case 4: Non-match, non-match
90 std::array<uint8_t, 260> src_buf_4;
91 for (uint16_t i = 0; i < 260; i++)
92 src_buf_4[i] = static_cast<uint8_t>(i);
93 DataVector<uint8_t> dest_buf = BasicModule::RunLengthEncode(src_buf_4);
94 DataAndBytesConsumed result = RunLengthDecode(dest_buf);
95 EXPECT_THAT(result.data, ElementsAreArray(src_buf_4));
96 }
97}
TEST(FXCRYPT, CryptToBase16)