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
cfx_barcode_unittest.cpp
Go to the documentation of this file.
1// Copyright 2017 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/cfx_barcode.h"
6
7#include <memory>
8#include <string>
9#include <utility>
10
11#include "core/fxcrt/fx_coordinates.h"
12#include "core/fxcrt/fx_string.h"
13#include "core/fxge/cfx_defaultrenderdevice.h"
14#include "core/fxge/cfx_renderdevice.h"
15#include "core/fxge/dib/cfx_dibitmap.h"
16#include "testing/gtest/include/gtest/gtest.h"
17#include "testing/utils/bitmap_saver.h"
18#include "testing/utils/hash.h"
19
20class BarcodeTest : public testing::Test {
21 public:
22 void SetUp() override {
24
25 auto device = std::make_unique<CFX_DefaultRenderDevice>();
26 auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
27 if (bitmap->Create(640, 480, FXDIB_Format::kRgb32))
28 bitmap_ = bitmap;
29 ASSERT_TRUE(bitmap_);
30 ASSERT_TRUE(device->Attach(bitmap_));
31 device_ = std::move(device);
32 }
33
35 bitmap_.Reset();
36 device_.reset();
37 barcode_.reset();
39 }
40
41 CFX_Barcode* barcode() const { return barcode_.get(); }
42
43 void Create(BC_TYPE type) {
44 barcode_ = CFX_Barcode::Create(type);
45 barcode_->SetHeight(298);
46 barcode_->SetWidth(418);
47 }
48
49 bool RenderDevice() { return barcode_->RenderDevice(device_.get(), matrix_); }
50
51 std::string BitmapChecksum() {
52 return GenerateMD5Base16(bitmap_->GetBuffer());
53 }
54
55 // Manually insert calls to this as needed for debugging.
56 void SaveBitmap(const std::string& filename) {
57 BitmapSaver::WriteBitmapToPng(bitmap_.Get(), filename);
58 }
59
60 protected:
64 RetainPtr<CFX_DIBitmap> bitmap_;
65};
66
67// https://crbug.com/pdfium/738
68#if defined(PDF_USE_SKIA)
69#define MAYBE_Code39 DISABLED_Code39
70#else
71#define MAYBE_Code39 Code39
72#endif
74 Create(BC_TYPE::kCode39);
75 EXPECT_TRUE(barcode()->Encode(L"CLAMS"));
76 RenderDevice();
77 EXPECT_EQ("cd4cd3f36da38ff58d9f621827018903", BitmapChecksum());
78}
79
80// https://crbug.com/pdfium/738
81#if defined(PDF_USE_SKIA)
82#define MAYBE_CodaBar DISABLED_CodaBar
83#else
84#define MAYBE_CodaBar CodaBar
85#endif
87 Create(BC_TYPE::kCodabar);
88 EXPECT_TRUE(barcode()->Encode(L"$123-456"));
89 RenderDevice();
90 EXPECT_EQ("5fad4fc19f099001a0fe83c89430c977", BitmapChecksum());
91}
92
94 Create(BC_TYPE::kCodabar);
95 EXPECT_FALSE(barcode()->Encode(L"clams"));
96}
97
98// https://crbug.com/pdfium/738
99#if defined(PDF_USE_SKIA)
100#define MAYBE_Code128 DISABLED_Code128
101#else
102#define MAYBE_Code128 Code128
103#endif
105 Create(BC_TYPE::kCode128);
106 EXPECT_TRUE(barcode()->Encode(L"Clams"));
107 RenderDevice();
108 EXPECT_EQ("6351f0f6e997050e4658bbb4777aef74", BitmapChecksum());
109}
110
111// https://crbug.com/pdfium/738
112#if defined(PDF_USE_SKIA)
113#define MAYBE_Code128B DISABLED_Code128B
114#else
115#define MAYBE_Code128B Code128B
116#endif
118 Create(BC_TYPE::kCode128B);
119 EXPECT_TRUE(barcode()->Encode(L"Clams"));
120 RenderDevice();
121 EXPECT_EQ("6351f0f6e997050e4658bbb4777aef74", BitmapChecksum());
122}
123
124// https://crbug.com/pdfium/738
125#if defined(PDF_USE_SKIA)
126#define MAYBE_Code128C DISABLED_Code128C
127#else
128#define MAYBE_Code128C Code128C
129#endif
131 Create(BC_TYPE::kCode128C);
132 EXPECT_TRUE(barcode()->Encode(L"123456"));
133 RenderDevice();
134 EXPECT_EQ("fba730a807ba6363f9bd2bc7f8c56d1f", BitmapChecksum());
135}
136
137// https://crbug.com/pdfium/738
138#if defined(PDF_USE_SKIA)
139#define MAYBE_Code128CLetters DISABLED_Code128CLetters
140#else
141#define MAYBE_Code128CLetters Code128CLetters
142#endif
144 Create(BC_TYPE::kCode128C);
145 EXPECT_TRUE(barcode()->Encode(L"clams"));
146 RenderDevice();
147 EXPECT_EQ("6284ec8503d5a948c9518108da33cdd3", BitmapChecksum());
148}
149
150// https://crbug.com/pdfium/738
151#if defined(PDF_USE_SKIA)
152#define MAYBE_Ean8 DISABLED_Ean8
153#else
154#define MAYBE_Ean8 Ean8
155#endif
157 Create(BC_TYPE::kEAN8);
158 EXPECT_TRUE(barcode()->Encode(L"123456"));
159 RenderDevice();
160 EXPECT_EQ("aff88491ac46ca6217d780d185300cde", BitmapChecksum());
161}
162
164 Create(BC_TYPE::kEAN8);
165 EXPECT_FALSE(barcode()->Encode(L"clams"));
166}
167
168// https://crbug.com/pdfium/738
169#if defined(PDF_USE_SKIA)
170#define MAYBE_UPCA DISABLED_UPCA
171#else
172#define MAYBE_UPCA UPCA
173#endif
175 Create(BC_TYPE::kUPCA);
176 EXPECT_TRUE(barcode()->Encode(L"123456"));
177 RenderDevice();
178 EXPECT_EQ("fe26a5714cff7ffe3f9b02183efc435b", BitmapChecksum());
179}
180
182 Create(BC_TYPE::kUPCA);
183 EXPECT_FALSE(barcode()->Encode(L"clams"));
184}
185
186// https://crbug.com/pdfium/738
187#if defined(PDF_USE_SKIA)
188#define MAYBE_Ean13 DISABLED_Ean13
189#else
190#define MAYBE_Ean13 Ean13
191#endif
193 Create(BC_TYPE::kEAN13);
194 EXPECT_TRUE(barcode()->Encode(L"123456"));
195 RenderDevice();
196 EXPECT_EQ("72d2190b98d635c32834bf67552e561e", BitmapChecksum());
197}
198
200 Create(BC_TYPE::kEAN13);
201 EXPECT_FALSE(barcode()->Encode(L"clams"));
202}
203
204// https://crbug.com/pdfium/738
205#if defined(PDF_USE_SKIA)
206#define MAYBE_Pdf417 DISABLED_Pdf417
207#else
208#define MAYBE_Pdf417 Pdf417
209#endif
211 Create(BC_TYPE::kPDF417);
212 EXPECT_TRUE(barcode()->Encode(L"clams"));
213 RenderDevice();
214 EXPECT_EQ("191e35d11613901b7d5d51033689aa89", BitmapChecksum());
215}
216
217// https://crbug.com/pdfium/738
218#if defined(PDF_USE_SKIA)
219#define MAYBE_DataMatrix DISABLED_DataMatrix
220#else
221#define MAYBE_DataMatrix DataMatrix
222#endif
224 Create(BC_TYPE::kDataMatrix);
225 EXPECT_TRUE(barcode()->Encode(L"clams"));
226 RenderDevice();
227 EXPECT_EQ("5e5cd9a680b86fcd4ffd53ed36e3c980", BitmapChecksum());
228}
229
230// https://crbug.com/pdfium/738
231#if defined(PDF_USE_SKIA)
232#define MAYBE_QrCode DISABLED_QrCode
233#else
234#define MAYBE_QrCode QrCode
235#endif
237 Create(BC_TYPE::kQRCode);
238 EXPECT_TRUE(barcode()->Encode(L"clams"));
239 RenderDevice();
240 EXPECT_EQ("4751c6e0f67749fabe24f787128decee", BitmapChecksum());
241}
BC_TYPE
Definition BC_Library.h:25
void BC_Library_Init()
void BC_Library_Destroy()
#define MAYBE_Pdf417
#define MAYBE_Code128B
#define MAYBE_Code128C
#define MAYBE_UPCA
#define MAYBE_Code128
#define MAYBE_CodaBar
#define MAYBE_Code128CLetters
#define MAYBE_QrCode
TEST_F(BarcodeTest, MAYBE_Code39)
#define MAYBE_DataMatrix
#define MAYBE_Ean13
#define MAYBE_Ean8
#define MAYBE_Code39
void TearDown() override
std::string BitmapChecksum()
void SetUp() override
std::unique_ptr< CFX_Barcode > barcode_
CFX_Barcode * barcode() const
void SaveBitmap(const std::string &filename)
void Create(BC_TYPE type)
std::unique_ptr< CFX_RenderDevice > device_
RetainPtr< CFX_DIBitmap > bitmap_