-
Notifications
You must be signed in to change notification settings - Fork 308
/
BarcodeDataMatrixTest.cs
264 lines (239 loc) · 12.6 KB
/
BarcodeDataMatrixTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 iText Group NV
Authors: iText Software.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA, or download the license from the following URL:
http://itextpdf.com/terms-of-use/
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using iText.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the iText software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping iText with a closed
source product.
For more information, please contact iText Software Corp. at this
address: sales@itextpdf.com
*/
using System;
using iText.Kernel.Colors;
using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas;
using iText.Kernel.Utils;
using iText.Test;
namespace iText.Barcodes {
[NUnit.Framework.Category("IntegrationTest")]
public class BarcodeDataMatrixTest : ExtendedITextTest {
public static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
+ "/test/itext/barcodes/BarcodeDataMatrix/";
public static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/barcodes/";
[NUnit.Framework.OneTimeSetUp]
public static void BeforeClass() {
CreateOrClearDestinationFolder(destinationFolder);
}
[NUnit.Framework.Test]
public virtual void Barcode01Test() {
String filename = "barcodeDataMatrix.pdf";
PdfWriter writer = new PdfWriter(destinationFolder + filename);
PdfDocument document = new PdfDocument(writer);
PdfPage page = document.AddNewPage();
PdfCanvas canvas = new PdfCanvas(page);
BarcodeDataMatrix barcode = new BarcodeDataMatrix();
barcode.SetCode("AAAAAAAAAA;BBBBAAAA3;00028;BBBAA05;AAAA;AAAAAA;1234567;AQWXSZ;JEAN;;;;7894561;AQWXSZ;GEO;;;;1;1;1;1;0;0;1;0;1;0;0;0;1;0;1;0;0;0;0;0;0;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1"
);
barcode.PlaceBarcode(canvas, ColorConstants.GREEN, 5);
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder
+ "cmp_" + filename, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void Barcode02Test() {
String filename = "barcodeDataMatrix2.pdf";
PdfWriter writer = new PdfWriter(destinationFolder + filename);
PdfDocument document = new PdfDocument(writer);
PdfPage page1 = document.AddNewPage();
PdfCanvas canvas = new PdfCanvas(page1);
BarcodeDataMatrix barcode2 = new BarcodeDataMatrix("дима", "UTF-8");
barcode2.PlaceBarcode(canvas, ColorConstants.GREEN, 10);
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder
+ "cmp_" + filename, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void Barcode03Test() {
String filename = "barcodeDataMatrix3.pdf";
PdfWriter writer = new PdfWriter(destinationFolder + filename);
PdfDocument document = new PdfDocument(writer);
PdfPage page1 = document.AddNewPage();
PdfCanvas canvas = new PdfCanvas(page1);
BarcodeDataMatrix barcode3 = new BarcodeDataMatrix();
barcode3.SetWidth(36);
barcode3.SetHeight(12);
barcode3.SetCode("AbcdFFghijklmnopqrstuWXSQ");
barcode3.PlaceBarcode(canvas, ColorConstants.BLACK, 10);
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder
+ "cmp_" + filename, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void Barcode04Test() {
String filename = "barcodeDataMatrix4.pdf";
PdfWriter writer = new PdfWriter(destinationFolder + filename);
PdfDocument document = new PdfDocument(writer);
PdfPage page1 = document.AddNewPage();
PdfCanvas canvas = new PdfCanvas(page1);
BarcodeDataMatrix barcode3 = new BarcodeDataMatrix();
barcode3.SetWidth(36);
barcode3.SetHeight(12);
barcode3.SetCode("01AbcdefgAbcdefg123451231231234");
barcode3.PlaceBarcode(canvas, ColorConstants.BLACK, 10);
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder
+ "cmp_" + filename, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void Barcode05Test() {
String filename = "barcodeDataMatrix5.pdf";
PdfWriter writer = new PdfWriter(destinationFolder + filename);
PdfDocument document = new PdfDocument(writer);
PdfPage page1 = document.AddNewPage();
PdfCanvas canvas = new PdfCanvas(page1);
BarcodeDataMatrix barcode3 = new BarcodeDataMatrix();
barcode3.SetWidth(40);
barcode3.SetHeight(40);
barcode3.SetCode("aaabbbcccdddAAABBBAAABBaaabbbcccdddaaa");
barcode3.PlaceBarcode(canvas, ColorConstants.BLACK, 10);
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder
+ "cmp_" + filename, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void Barcode06Test() {
String filename = "barcodeDataMatrix6.pdf";
PdfWriter writer = new PdfWriter(destinationFolder + filename);
PdfDocument document = new PdfDocument(writer);
PdfPage page1 = document.AddNewPage();
PdfCanvas canvas = new PdfCanvas(page1);
BarcodeDataMatrix barcode3 = new BarcodeDataMatrix();
barcode3.SetWidth(36);
barcode3.SetHeight(12);
barcode3.SetCode(">>>\r>>>THIS VERY TEXT>>\r>");
barcode3.PlaceBarcode(canvas, ColorConstants.BLACK, 10);
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder
+ "cmp_" + filename, destinationFolder, "diff_"));
}
[NUnit.Framework.Test]
public virtual void Barcode07Test() {
BarcodeDataMatrix bc = new BarcodeDataMatrix();
bc.SetOptions(BarcodeDataMatrix.DM_AUTO);
bc.SetWidth(10);
bc.SetHeight(10);
String aCode = "aBCdeFG12";
int result = bc.SetCode(aCode);
NUnit.Framework.Assert.AreEqual(result, BarcodeDataMatrix.DM_ERROR_TEXT_TOO_BIG);
}
[NUnit.Framework.Test]
public virtual void Barcode08Test() {
BarcodeDataMatrix barcodeDataMatrix = new BarcodeDataMatrix();
barcodeDataMatrix.SetWidth(18);
barcodeDataMatrix.SetHeight(18);
int result = barcodeDataMatrix.SetCode("AbcdFFghijklmnopqrstuWXSQ");
NUnit.Framework.Assert.AreEqual(BarcodeDataMatrix.DM_ERROR_TEXT_TOO_BIG, result);
}
[NUnit.Framework.Test]
public virtual void Barcode09Test() {
BarcodeDataMatrix barcodeDataMatrix = new BarcodeDataMatrix();
barcodeDataMatrix.SetWidth(17);
barcodeDataMatrix.SetHeight(17);
int result = barcodeDataMatrix.SetCode("AbcdFFghijklmnopqrstuWXSQ");
NUnit.Framework.Assert.AreEqual(BarcodeDataMatrix.DM_ERROR_INVALID_SQUARE, result);
}
[NUnit.Framework.Test]
public virtual void Barcode10Test() {
BarcodeDataMatrix barcodeDataMatrix = new BarcodeDataMatrix();
barcodeDataMatrix.SetWidth(26);
barcodeDataMatrix.SetHeight(12);
int result = barcodeDataMatrix.SetCode("AbcdFFghijklmnopqrstuWXSQ");
NUnit.Framework.Assert.AreEqual(BarcodeDataMatrix.DM_ERROR_TEXT_TOO_BIG, result);
}
[NUnit.Framework.Test]
public virtual void Barcode11Test() {
BarcodeDataMatrix barcodeDataMatrix = new BarcodeDataMatrix();
barcodeDataMatrix.SetWidth(18);
barcodeDataMatrix.SetHeight(18);
byte[] str = "AbcdFFghijklmnop".GetBytes();
int result = barcodeDataMatrix.SetCode(str, 0, str.Length);
NUnit.Framework.Assert.AreEqual(BarcodeDataMatrix.DM_NO_ERROR, result);
}
[NUnit.Framework.Test]
public virtual void Barcode12Test() {
BarcodeDataMatrix barcodeDataMatrix = new BarcodeDataMatrix();
barcodeDataMatrix.SetWidth(18);
barcodeDataMatrix.SetHeight(18);
byte[] str = "AbcdFFghijklmnop".GetBytes();
Exception e = NUnit.Framework.Assert.Catch(typeof(IndexOutOfRangeException), () => barcodeDataMatrix.SetCode
(str, -1, str.Length));
}
[NUnit.Framework.Test]
public virtual void Barcode13Test() {
BarcodeDataMatrix barcodeDataMatrix = new BarcodeDataMatrix();
barcodeDataMatrix.SetWidth(18);
barcodeDataMatrix.SetHeight(18);
byte[] str = "AbcdFFghijklmnop".GetBytes();
NUnit.Framework.Assert.Catch(typeof(IndexOutOfRangeException), () => barcodeDataMatrix.SetCode(str, 0, str
.Length + 1));
}
[NUnit.Framework.Test]
public virtual void Barcode14Test() {
BarcodeDataMatrix barcodeDataMatrix = new BarcodeDataMatrix();
barcodeDataMatrix.SetWidth(18);
barcodeDataMatrix.SetHeight(18);
byte[] str = "AbcdFFghijklmnop".GetBytes();
NUnit.Framework.Assert.Catch(typeof(IndexOutOfRangeException), () => barcodeDataMatrix.SetCode(str, 0, -1)
);
}
[NUnit.Framework.Test]
public virtual void Barcode15Test() {
BarcodeDataMatrix barcodeDataMatrix = new BarcodeDataMatrix();
barcodeDataMatrix.SetWidth(18);
barcodeDataMatrix.SetHeight(18);
byte[] str = "AbcdFFghijklmnop".GetBytes();
int result = barcodeDataMatrix.SetCode(str, str.Length, 0);
NUnit.Framework.Assert.AreEqual(BarcodeDataMatrix.DM_NO_ERROR, result);
}
[NUnit.Framework.Test]
public virtual void Barcode16Test() {
String filename = "barcode16Test.pdf";
PdfDocument document = new PdfDocument(new PdfWriter(destinationFolder + filename));
PdfCanvas canvas = new PdfCanvas(document.AddNewPage());
BarcodeDataMatrix barcode = new BarcodeDataMatrix();
barcode.SetCode("999999DILLERT XANG LIMITON 18 000");
canvas.ConcatMatrix(1, 0, 0, 1, 100, 600);
barcode.PlaceBarcode(canvas, ColorConstants.BLACK, 3);
document.Close();
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(destinationFolder + filename, sourceFolder
+ "cmp_" + filename, destinationFolder));
}
}
}