-
-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathEngineTest.cs
More file actions
172 lines (140 loc) · 7.1 KB
/
EngineTest.cs
File metadata and controls
172 lines (140 loc) · 7.1 KB
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
using BinaryKits.Zpl.Label.Elements;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Diagnostics;
namespace BinaryKits.Zpl.Label.UnitTest
{
[TestClass]
public class EngineTest
{
[TestMethod]
public void SingelElement()
{
var output = new ZplGraphicBox(100, 100, 100, 100).ToZplString();
Debug.WriteLine(output);
Assert.IsNotNull(output);
Assert.AreEqual("^FO100,100\n^GB100,100,1,B,0^FS", output);
}
[TestMethod]
public void MultipleElements()
{
var sampleText = "[_~^][LineBreak\n][The quick fox jumps over the lazy dog.]";
var font = new ZplFont(fontWidth: 50, fontHeight: 50);
var elements = new List<ZplElementBase>();
elements.Add(new ZplTextField(sampleText, 50, 100, font));
elements.Add(new ZplGraphicBox(400, 700, 100, 100, 5));
elements.Add(new ZplGraphicBox(450, 750, 100, 100, 50, LineColor.White));
elements.Add(new ZplGraphicCircle(400, 700, 100, 5));
elements.Add(new ZplGraphicDiagonalLine(400, 700, 100, 50, 5));
elements.Add(new ZplGraphicDiagonalLine(400, 700, 50, 100, 5));
elements.Add(new ZplGraphicSymbol(GraphicSymbolCharacter.Copyright, 600, 600, 50, 50));
elements.Add(new ZplQrCode("MM,AAC-42", 200, 800));
//Add raw Zpl code
elements.Add(new ZplRaw("^FO200, 200^GB300, 200, 10 ^FS"));
var renderEngine = new ZplEngine(elements);
var output = renderEngine.ToZplString(new ZplRenderOptions { AddEmptyLineBeforeElementStart = true });
Debug.WriteLine(output);
}
[TestMethod]
public void ChangeDPI()
{
var elements = new List<ZplElementBase>();
elements.Add(new ZplGraphicBox(400, 700, 100, 100, 5));
var options = new ZplRenderOptions { SourcePrintDpi = 203, TargetPrintDpi = 300 };
var output = new ZplEngine(elements).ToZplString(options);
Debug.WriteLine(output);
Assert.IsNotNull(output);
Assert.AreEqual("^XA\n^LH0,0\n^FO591,1034\n^GB147,147,7,B,0^FS\n^XZ", output);
}
[TestMethod]
public void LayoutWithOriginOffset()
{
var elements = new List<ZplElementBase>();
var origin = new ZplFieldOrigin(100, 100);
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
elements.Add(new ZplGraphicBox(origin.PositionX, origin.PositionY, 50, 50));
origin = origin.Offset(0, 100);
}
origin = origin.Offset(100, -300);
}
var options = new ZplRenderOptions();
var output = new ZplEngine(elements).ToZplString(options);
Debug.WriteLine(output);
}
[TestMethod]
public void RenderComments()
{
var elements = new List<ZplElementBase>();
var textField = new ZplTextField("AAA", 50, 100, ZplConstants.Font.Default);
textField.Comments.Add("A important field");
elements.Add(textField);
var renderEngine = new ZplEngine(elements);
var output = renderEngine.ToZplString(new ZplRenderOptions { DisplayComments = true });
Debug.WriteLine(output);
}
[TestMethod]
public void TextFieldVariations()
{
var sampleText = "[_~^][LineBreak\n][The quick fox jumps over the lazy dog.]";
var font = new ZplFont(fontWidth: 50, fontHeight: 50);
var elements = new List<ZplElementBase>();
//Specail character is repalced with space
elements.Add(new ZplTextField(sampleText, 10, 10, font, hexadecimalIndicator: null));
//Specail character is using Hex value ^FH
elements.Add(new ZplTextField(sampleText, 10, 50, font, hexadecimalIndicator: '_'));
//Only the first line is displayed
elements.Add(new ZplSingleLineFieldBlock(sampleText, 10, 150, 500, font));
//Max 2 lines, text exceeding the maximum number of lines overwrites the last line.
elements.Add(new ZplFieldBlock(sampleText, 10, 300, 400, font, 2));
// Multi - line text within a box region
elements.Add(new ZplTextBlock(sampleText, 10, 600, 400, 100, font));
var renderEngine = new ZplEngine(elements);
var output = renderEngine.ToZplString(new ZplRenderOptions { AddEmptyLineBeforeElementStart = true });
Debug.WriteLine(output);
}
[TestMethod]
public void WithoutAutoElements()
{
var elements = new List<ZplElementBase>();
var textField = new ZplTextField("Pure element zpl only", 50, 100, ZplConstants.Font.Default);
textField.Comments.Add("A important field");
elements.Add(textField);
var renderEngine = new ZplEngine(elements);
var output = renderEngine.ToZplString(new ZplRenderOptions { DisplayComments = true, AddDefaultLabelHome = false, AddStartEndFormat = false });
Debug.WriteLine(output);
Assert.IsNotNull(output);
Assert.AreEqual("^FX\n//A important field\n^A0N,30,30\n^FO50,100\n^FDPure element zpl only^FS", output);
}
[TestMethod]
public void ChangeInternationalFont()
{
var elements = new List<ZplElementBase>() {
new ZplChangeInternationalFont(InternationalFont.ZCP1252),
new ZplTextField("Straße", 10, 10, ZplConstants.Font.Default, hexadecimalIndicator: '_'),
};
var renderEngine = new ZplEngine(elements);
var output = renderEngine.ToZplString(new ZplRenderOptions());
Debug.WriteLine(output);
Assert.IsNotNull(output);
//TODO: escape non-ascii characters according to current charset if hexIndicator is given
Assert.AreEqual("^XA\n^LH0,0\n^CI27\n^A0N,30,30\n^FO10,10\n^FH^FDStraße^FS\n^XZ", output);
}
[TestMethod]
public void FieldTypesetDefaultPosition()
{
var elements = new List<ZplElementBase>() {
new ZplTextField("ACME ", 10, 200, new ZplFont(30, 20, "0"), bottomToTop: true),
new ZplTextField("Summer ", 0, 0, new ZplFont(30, 20, "0"), bottomToTop: true, useDefaultPosition: true),
new ZplTextField("Clearance ", 0, 0, new ZplFont(60, 50, "0"), bottomToTop: true, useDefaultPosition: true),
new ZplTextField("Sale ", 0, 0, new ZplFont(120, 100, "0"), bottomToTop: true, useDefaultPosition: true)
};
var renderEngine = new ZplEngine(elements);
var output = renderEngine.ToZplString(new ZplRenderOptions());
Debug.WriteLine(output);
Assert.AreEqual("^XA\n^LH0,0\n^A0N,20,30\n^FT10,200\n^FDACME ^FS\n^A0N,20,30\n^FT\n^FDSummer ^FS\n^A0N,50,60\n^FT\n^FDClearance ^FS\n^A0N,100,120\n^FT\n^FDSale ^FS\n^XZ", output);
}
}
}