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_OnedEAN13Writer_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_OnedEAN13Writer.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
13namespace {
14
15TEST(OnedEAN13WriterTest, Encode) {
16 CBC_OnedEAN13Writer writer;
17 writer.InitEANWriter();
18
19 // EAN-13 barcodes encode 13-digit numbers into 95 modules in a unidimensional
20 // disposition.
21 EXPECT_TRUE(writer.Encode("").empty());
22 EXPECT_TRUE(writer.Encode("123").empty());
23 EXPECT_TRUE(writer.Encode("123456789012").empty());
24 EXPECT_TRUE(writer.Encode("12345678901234").empty());
25
26 static const char kExpected1[] =
27 "# #" // Start
28 // 1 implicit by LLGLGG in next 6 digits
29 " # ##" // 2 L
30 " #### #" // 3 L
31 " ### #" // 4 G
32 " ## #" // 5 L
33 " # #" // 6 G
34 " # #" // 7 G
35 " # # " // Middle
36 "# # " // 8 R
37 "### # " // 9 R
38 "### # " // 0 R
39 "## ## " // 1 R
40 "## ## " // 2 R
41 "# # " // 8 R
42 "# #"; // End
43 DataVector<uint8_t> encoded = writer.Encode("1234567890128");
44 for (size_t i = 0; i < strlen(kExpected1); i++) {
45 UNSAFE_TODO(EXPECT_EQ(kExpected1[i] != ' ', !!encoded[i])) << i;
46 }
47 static const char kExpected2[] =
48 "# #" // Start
49 // 7 implicit by LGLGLG in next 6 digits
50 " ### ##" // 7 L
51 " # #" // 7 G
52 " # ####" // 6 L
53 " # #" // 6 G
54 " # ####" // 6 L
55 " ### #" // 5 G
56 " # # " // Middle
57 "# ### " // 5 R
58 "# ### " // 5 R
59 "# ### " // 4 R
60 "# ### " // 4 R
61 "# ### " // 4 R
62 "### # " // 0 R
63 "# #"; // End
64 encoded = writer.Encode("7776665554440");
65 ASSERT_EQ(strlen(kExpected2), encoded.size());
66 for (size_t i = 0; i < strlen(kExpected2); i++) {
67 UNSAFE_TODO(EXPECT_EQ(kExpected2[i] != ' ', !!encoded[i])) << i;
68 }
69}
70
71TEST(OnedEAN13WriterTest, Checksum) {
72 CBC_OnedEAN13Writer writer;
73 writer.InitEANWriter();
74 EXPECT_EQ(0, writer.CalcChecksum(""));
75 EXPECT_EQ(6, writer.CalcChecksum("123"));
76 EXPECT_EQ(8, writer.CalcChecksum("123456789012"));
77 EXPECT_EQ(0, writer.CalcChecksum("777666555444"));
78}
79
80} // namespace
virtual void InitEANWriter()
int32_t CalcChecksum(const ByteString &contents) override
#define UNSAFE_TODO(...)