Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
BC_OnedEAN8Writer_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/oned/BC_OnedEAN8Writer.h"
6
7
#
include
<
string
.
h
>
8
9
#
include
"core/fxcrt/compiler_specific.h"
10
#
include
"core/fxcrt/data_vector.h"
11
#
include
"testing/gtest/include/gtest/gtest.h"
12
13
namespace
{
14
15
TEST(OnedEAN8WriterTest, Encode) {
16
CBC_OnedEAN8Writer writer;
17
writer
.
InitEANWriter
();
18
19
// EAN-8 barcodes encode 8-digit numbers into 67 modules in a unidimensional
20
// disposition.
21
EXPECT_TRUE(writer.Encode(
""
).empty());
22
EXPECT_TRUE(writer.Encode(
"123"
).empty());
23
EXPECT_TRUE(writer.Encode(
"1234567"
).empty());
24
EXPECT_TRUE(writer.Encode(
"123456789"
).empty());
25
26
static
const
char
kExpected1[] =
27
"# #"
// Start
28
" ## #"
// 1 L
29
" # ##"
// 2 L
30
" #### #"
// 3 L
31
" # ##"
// 4 L
32
" # # "
// Middle
33
"# ### "
// 5 R
34
"# # "
// 6 R
35
"# # "
// 7 R
36
"### # "
// 0 R
37
"# #"
;
// End
38
DataVector<uint8_t> encoded = writer.Encode(
"12345670"
);
39
ASSERT_EQ(strlen(kExpected1), encoded.size());
40
for
(size_t i = 0; i < strlen(kExpected1); i++) {
41
UNSAFE_TODO
(EXPECT_EQ(kExpected1[i] !=
' '
, !!encoded[i])) << i;
42
}
43
static
const
char
kExpected2[] =
44
"# #"
// Start
45
" # ##"
// 9 L
46
" # ##"
// 9 L
47
" # ##"
// 4 L
48
" # ##"
// 4 L
49
" # # "
// Middle
50
"## ## "
// 1 R
51
"## ## "
// 1 R
52
"### # "
// 0 R
53
"# ### "
// 4 R
54
"# #"
;
// End
55
encoded = writer.Encode(
"99441104"
);
56
ASSERT_EQ(strlen(kExpected2), encoded.size());
57
for
(size_t i = 0; i < strlen(kExpected2); i++)
58
UNSAFE_TODO
(EXPECT_EQ(kExpected2[i] !=
' '
, !!encoded[i])) << i;
59
}
60
61
TEST(OnedEAN8WriterTest, Checksum) {
62
CBC_OnedEAN8Writer writer;
63
writer
.
InitEANWriter
();
64
EXPECT_EQ(0, writer
.
CalcChecksum
(
""
)
);
65
EXPECT_EQ(6, writer
.
CalcChecksum
(
"123"
)
);
66
EXPECT_EQ(0, writer
.
CalcChecksum
(
"1234567"
)
);
67
EXPECT_EQ(4, writer
.
CalcChecksum
(
"9944110"
)
);
68
}
69
70
}
// namespace
CBC_OneDimEANWriter::InitEANWriter
virtual void InitEANWriter()
Definition
BC_OnedEANWriter.cpp:11
CBC_OnedEAN8Writer::CalcChecksum
int32_t CalcChecksum(const ByteString &contents) override
Definition
BC_OnedEAN8Writer.cpp:96
UNSAFE_TODO
#define UNSAFE_TODO(...)
Definition
compiler_specific.h:102
qtwebengine
src
3rdparty
chromium
third_party
pdfium
fxbarcode
oned
BC_OnedEAN8Writer_unittest.cpp
Generated on
for Qt by
1.18.0