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_OnedCodaBarWriter_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_OnedCodaBarWriter.h"
6
7#include <string.h>
8
9#include "core/fxcrt/data_vector.h"
10#include "testing/gtest/include/gtest/gtest.h"
11
12namespace {
13
14TEST(OnedCodaBarWriterTest, Encode) {
15 CBC_OnedCodaBarWriter writer;
16
17 static const char kExpected1[] =
18 "# ## # # " // A Start
19 "# # # ##"; // B End
20 DataVector<uint8_t> encoded = writer.Encode("");
21 ASSERT_EQ(strlen(kExpected1), encoded.size());
22 for (size_t i = 0; i < strlen(kExpected1); i++)
23 EXPECT_EQ(kExpected1[i] != ' ', !!encoded[i]) << i;
24
25 static const char kExpected2[] =
26 "# ## # # " // A Start
27 "# # ## # " // 1
28 "# # # ## " // 2
29 "## # # # " // 3
30 "# # # ##"; // B End
31 encoded = writer.Encode("123");
32 ASSERT_EQ(strlen(kExpected2), encoded.size());
33 for (size_t i = 0; i < strlen(kExpected2); i++)
34 EXPECT_EQ(kExpected2[i] != ' ', !!encoded[i]) << i;
35
36 static const char kExpected3[] =
37 "# ## # # " // A Start
38 "# # ## # " // -
39 "# ## # # " // $
40 "## ## ## # " // .
41 "## ## # ## " // /
42 "## # ## ## " // :
43 "# ## ## ## " // +
44 "# # # ##"; // B End
45 encoded = writer.Encode("-$./:+");
46 ASSERT_EQ(strlen(kExpected3), encoded.size());
47 for (size_t i = 0; i < strlen(kExpected3); i++)
48 EXPECT_EQ(kExpected3[i] != ' ', !!encoded[i]) << i;
49
50 static const char kExpected4[] =
51 "# ## # # " // A Start
52 "# ## # # " // 4
53 "## # # # " // 5
54 "# # # ## " // 6
55 "## ## ## # " // .
56 "## # # # " // 9
57 "# ## # # " // 8
58 "# # ## # " // 7
59 "## # # # " // 9
60 "# ## # # " // 8
61 "# # ## # " // 7
62 "## # # # " // 9
63 "# ## # # " // 8
64 "# # ## # " // 7
65 "## ## # ## " // /
66 "# # # ## " // 0
67 "# # # ## " // 0
68 "# # ## # " // 1
69 "# # # ##"; // B End
70 encoded = writer.Encode("456.987987987/001");
71 ASSERT_EQ(strlen(kExpected4), encoded.size());
72 for (size_t i = 0; i < strlen(kExpected4); i++)
73 EXPECT_EQ(kExpected4[i] != ' ', !!encoded[i]) << i;
74}
75
76TEST(OnedCodaBarWriterTest, SetDelimiters) {
77 CBC_OnedCodaBarWriter writer;
78
79 EXPECT_TRUE(writer.SetStartChar('A'));
80 EXPECT_TRUE(writer.SetStartChar('B'));
81 EXPECT_TRUE(writer.SetStartChar('C'));
82 EXPECT_TRUE(writer.SetStartChar('D'));
83 EXPECT_TRUE(writer.SetStartChar('E'));
84 EXPECT_TRUE(writer.SetStartChar('N'));
85 EXPECT_TRUE(writer.SetStartChar('T'));
86 EXPECT_TRUE(writer.SetStartChar('*'));
87 EXPECT_FALSE(writer.SetStartChar('V'));
88 EXPECT_FALSE(writer.SetStartChar('0'));
89 EXPECT_FALSE(writer.SetStartChar('\0'));
90 EXPECT_FALSE(writer.SetStartChar('@'));
91
92 EXPECT_TRUE(writer.SetEndChar('A'));
93 EXPECT_TRUE(writer.SetEndChar('B'));
94 EXPECT_TRUE(writer.SetEndChar('C'));
95 EXPECT_TRUE(writer.SetEndChar('D'));
96 EXPECT_TRUE(writer.SetEndChar('E'));
97 EXPECT_TRUE(writer.SetEndChar('N'));
98 EXPECT_TRUE(writer.SetEndChar('T'));
99 EXPECT_TRUE(writer.SetEndChar('*'));
100 EXPECT_FALSE(writer.SetEndChar('V'));
101 EXPECT_FALSE(writer.SetEndChar('0'));
102 EXPECT_FALSE(writer.SetEndChar('\0'));
103 EXPECT_FALSE(writer.SetEndChar('@'));
104
105 writer.SetStartChar('N');
106 writer.SetEndChar('*');
107
108 static const char kExpected[] =
109 "# # # ## " // N (same as B) Start
110 "## # # # " // 9
111 "# ## # # " // 8
112 "# # ## # " // 7
113 "# # # ##"; // * (same as C) End
114 DataVector<uint8_t> encoded = writer.Encode("987");
115 ASSERT_EQ(strlen(kExpected), encoded.size());
116 for (size_t i = 0; i < strlen(kExpected); i++)
117 EXPECT_EQ(kExpected[i] != ' ', !!encoded[i]) << i;
118}
119
120} // namespace
bool SetEndChar(char end) override
bool SetStartChar(char start) override