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
BC_DataMatrixWriter_unittest.cpp
Go to the documentation of this file.
1// Copyright 2018 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 "fxbarcode/datamatrix/BC_DataMatrixWriter.h"
6
7#include <stdint.h>
8
9#include "core/fxcrt/data_vector.h"
10#include "testing/gtest/include/gtest/gtest.h"
11
13 public:
16
17 // testing::Test:
20};
21
23 CBC_DataMatrixWriter writer;
24 int32_t width = -1;
25 int32_t height = -1;
26
27 {
28 static constexpr int kExpectedDimension = 10;
29 // clang-format off
30 static constexpr uint8_t kExpectedData[] = {
31 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
32 1, 1, 0, 1, 1, 0, 1, 0, 0, 1,
33 1, 1, 0, 1, 0, 0, 0, 0, 1, 0,
34 1, 1, 1, 1, 0, 0, 0, 1, 0, 1,
35 1, 0, 1, 0, 0, 0, 1, 0, 0, 0,
36 1, 1, 1, 0, 1, 0, 0, 0, 0, 1,
37 1, 0, 0, 1, 0, 1, 1, 0, 1, 0,
38 1, 0, 1, 0, 1, 1, 1, 1, 0, 1,
39 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
40 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
41 };
42 // clang-format on
43 DataVector<uint8_t> data = writer.Encode(L"", &width, &height);
44 ASSERT_EQ(std::size(kExpectedData), data.size());
45 ASSERT_EQ(kExpectedDimension, width);
46 ASSERT_EQ(kExpectedDimension, height);
47 for (size_t i = 0; i < std::size(kExpectedData); ++i)
48 EXPECT_EQ(kExpectedData[i], data[i]) << i;
49 }
50 {
51 static constexpr int kExpectedDimension = 14;
52 // clang-format off
53 static constexpr uint8_t kExpectedData[] = {
54 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
55 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1,
56 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0,
57 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1,
58 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0,
59 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1,
60 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0,
61 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1,
62 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0,
63 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1,
64 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0,
65 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1,
66 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0,
67 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
68 };
69 // clang-format on
70 DataVector<uint8_t> data = writer.Encode(L"helloworld", &width, &height);
71 ASSERT_EQ(std::size(kExpectedData), data.size());
72 ASSERT_EQ(kExpectedDimension, width);
73 ASSERT_EQ(kExpectedDimension, height);
74 for (size_t i = 0; i < std::size(kExpectedData); ++i)
75 EXPECT_EQ(kExpectedData[i], data[i]) << i;
76 }
77 {
78 static constexpr int kExpectedDimension = 10;
79 // clang-format off
80 static constexpr uint8_t kExpectedData[] = {
81 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
82 1, 1, 0, 1, 1, 0, 0, 1, 1, 1,
83 1, 1, 0, 0, 0, 1, 0, 1, 1, 0,
84 1, 1, 0, 0, 1, 1, 0, 1, 0, 1,
85 1, 1, 0, 0, 1, 1, 1, 0, 0, 0,
86 1, 0, 0, 0, 0, 1, 1, 1, 1, 1,
87 1, 1, 0, 1, 0, 1, 1, 1, 1, 0,
88 1, 1, 1, 0, 0, 0, 0, 1, 1, 1,
89 1, 1, 0, 1, 1, 0, 0, 1, 0, 0,
90 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
91 };
92 // clang-format on
93 DataVector<uint8_t> data = writer.Encode(L"12345", &width, &height);
94 ASSERT_EQ(std::size(kExpectedData), data.size());
95 ASSERT_EQ(kExpectedDimension, width);
96 ASSERT_EQ(kExpectedDimension, height);
97 for (size_t i = 0; i < std::size(kExpectedData); ++i)
98 EXPECT_EQ(kExpectedData[i], data[i]) << i;
99 }
100 {
101 static constexpr int kExpectedDimension = 18;
102 // clang-format off
103 static constexpr uint8_t kExpectedData[] = {
104 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
105 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1,
106 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0,
107 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1,
108 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0,
109 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1,
110 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0,
111 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1,
112 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0,
113 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1,
114 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0,
115 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1,
116 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0,
117 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1,
118 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0,
119 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1,
120 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0,
121 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
122 };
123 // clang-format on
124 DataVector<uint8_t> data =
125 writer.Encode(L"abcdefghijklmnopqrst", &width, &height);
126 ASSERT_EQ(std::size(kExpectedData), data.size());
127 ASSERT_EQ(kExpectedDimension, width);
128 ASSERT_EQ(kExpectedDimension, height);
129 for (size_t i = 0; i < std::size(kExpectedData); ++i)
130 EXPECT_EQ(kExpectedData[i], data[i]) << i;
131 }
132 {
133 DataVector<uint8_t> data = writer.Encode(L"hello world", &width, &height);
134 ASSERT_TRUE(data.empty());
135 }
136}
137
139 CBC_DataMatrixWriter writer;
140 int32_t width = -1;
141 int32_t height = -1;
142
143 static constexpr int kMaxInputLength = 2335; // Per spec.
144 WideString input;
145 for (size_t i = 0; i < kMaxInputLength; ++i)
146 input.InsertAtBack(L'a');
147
148 {
149 static constexpr int kExpectedDimension = 144;
150 DataVector<uint8_t> data = writer.Encode(input.c_str(), &width, &height);
151 EXPECT_EQ(20736u, data.size());
152 EXPECT_EQ(kExpectedDimension, width);
153 EXPECT_EQ(kExpectedDimension, height);
154 }
155
156 // Go over the limit.
157 input.InsertAtBack(L'a');
158 {
159 width = -1;
160 height = -1;
161 DataVector<uint8_t> data = writer.Encode(input.c_str(), &width, &height);
162 EXPECT_EQ(0u, data.size());
163 EXPECT_EQ(-1, width);
164 EXPECT_EQ(-1, height);
165 }
166}
167
169 CBC_DataMatrixWriter writer;
170 int32_t width = -1;
171 int32_t height = -1;
172
173 static constexpr int kMaxInputLength = 3116; // Per spec.
174 WideString input;
175 for (size_t i = 0; i < kMaxInputLength; ++i)
176 input.InsertAtBack(L'1');
177
178 {
179 static constexpr int kExpectedDimension = 144;
180 DataVector<uint8_t> data = writer.Encode(input.c_str(), &width, &height);
181 EXPECT_EQ(20736u, data.size());
182 EXPECT_EQ(kExpectedDimension, width);
183 EXPECT_EQ(kExpectedDimension, height);
184 }
185
186 // Go over the limit.
187 input.InsertAtBack(L'1');
188 {
189 width = -1;
190 height = -1;
191 DataVector<uint8_t> data = writer.Encode(input.c_str(), &width, &height);
192 EXPECT_EQ(0u, data.size());
193 EXPECT_EQ(-1, width);
194 EXPECT_EQ(-1, height);
195 }
196}
TEST_F(CBC_DataMatrixWriterTest, Encode)
void BC_Library_Init()
void BC_Library_Destroy()
~CBC_DataMatrixWriterTest() override=default
CBC_DataMatrixWriterTest()=default