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_OnedUPCAWriter_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_OnedUPCAWriter.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(OnedUPCAWriterTest, Encode) {
16 CBC_OnedUPCAWriter writer;
17 writer.InitEANWriter();
18
19 // UPCA barcodes encode 12-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("12345678901").empty());
24 EXPECT_TRUE(writer.Encode("1234567890123").empty());
25
26 static const char kExpected1[] =
27 "# #" // Start
28 " ## #" // 1 L
29 " # ##" // 2 L
30 " #### #" // 3 L
31 " # ##" // 4 L
32 " ## #" // 5 L
33 " # ####" // 6 L
34 " # # " // Middle
35 "# # " // 7 R
36 "# # " // 8 R
37 "### # " // 9 R
38 "### # " // 0 R
39 "## ## " // 1 R
40 "## ## " // 2 R
41 "# #"; // End
42 DataVector<uint8_t> encoded = writer.Encode("123456789012");
43 ASSERT_EQ(strlen(kExpected1), encoded.size());
44 for (size_t i = 0; i < strlen(kExpected1); i++) {
45 UNSAFE_TODO(EXPECT_EQ(kExpected1[i] != ' ', !!encoded[i])) << i;
46 }
47
48 encoded = writer.Encode("777666555440");
49 static const char kExpected2[] =
50 "# #" // Start
51 " ### ##" // 7 L
52 " ### ##" // 7 L
53 " ### ##" // 7 L
54 " # ####" // 6 L
55 " # ####" // 6 L
56 " # ####" // 6 L
57 " # # " // Middle
58 "# ### " // 5 R
59 "# ### " // 5 R
60 "# ### " // 5 R
61 "# ### " // 4 R
62 "# ### " // 4 R
63 "### # " // 0 R
64 "# #"; // End
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(OnedUPCAWriterTest, Checksum) {
72 CBC_OnedUPCAWriter writer;
73 writer.InitEANWriter();
74 EXPECT_EQ(0, writer.CalcChecksum(""));
75 EXPECT_EQ(6, writer.CalcChecksum("123"));
76 EXPECT_EQ(2, writer.CalcChecksum("12345678901"));
77 EXPECT_EQ(0, writer.CalcChecksum("77766655544"));
78}
79
80} // namespace
void InitEANWriter() override
int32_t CalcChecksum(const ByteString &contents) override
#define UNSAFE_TODO(...)