-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Change invertdraw to skia xor blending - Also added tests - Refactored viewer tests * Begin structuring viewer testing project - readme for goals - custom test for feature development - zpl/png data folder copied to output - factor out more to common * Try to fix cannot copy data to output for linux build * Copy data again * Capitalization mistake
- Loading branch information
1 parent
a41fc18
commit 2150dac
Showing
12 changed files
with
194 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.IO; | ||
using BinaryKits.Zpl.Viewer.ElementDrawers; | ||
|
||
namespace BinaryKits.Zpl.Viewer.UnitTest | ||
{ | ||
internal class Common | ||
{ | ||
/// <summary> | ||
/// Load zpl strings from files in the Data/Zpl directory | ||
/// </summary> | ||
/// <param name="name">name of of the file, .zpl2 extension optional</param> | ||
/// <returns></returns> | ||
public static string LoadZPL(string name) { | ||
if (!name.Contains(".zpl2")) | ||
{ | ||
name += ".zpl2"; ; | ||
} | ||
var path = Path.Combine("Data", "Zpl", name); | ||
return System.IO.File.ReadAllText(path); | ||
} | ||
|
||
/// <summary> | ||
/// Generic printer to test zpl -> png output | ||
/// </summary> | ||
/// <param name="zpl"></param> | ||
/// <param name="outputFilename">PNG filename ex: "file.png"</param> | ||
/// <param name="width"></param> | ||
/// <param name="height"></param> | ||
/// <param name="ppmm"></param> | ||
/// <param name="options"></param> | ||
public static void DefaultPrint( | ||
string zpl, | ||
string outputFilename, | ||
double width = 101.6, | ||
double height = 152.4, | ||
int ppmm = 8, | ||
DrawerOptions options = null | ||
) | ||
{ | ||
IPrinterStorage printerStorage = new PrinterStorage(); | ||
var drawer = new ZplElementDrawer(printerStorage, options); | ||
|
||
var analyzer = new ZplAnalyzer(printerStorage); | ||
var analyzeInfo = analyzer.Analyze(zpl); | ||
|
||
foreach (var labelInfo in analyzeInfo.LabelInfos) | ||
{ | ||
var imageData = drawer.Draw(labelInfo.ZplElements, width, height, ppmm); | ||
File.WriteAllBytes(outputFilename, imageData); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace BinaryKits.Zpl.Viewer.UnitTest | ||
{ | ||
[TestClass] | ||
public class CustomTest | ||
{ | ||
[TestMethod] | ||
public void Custom() | ||
{ | ||
string zplString = Common.LoadZPL("custom"); | ||
Common.DefaultPrint(zplString, "custom.png"); | ||
} | ||
} | ||
} |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
^XA | ||
^FO20, 20 | ||
^A1N,40, 30 ^FD西瓜^FS | ||
^FO20, 50 | ||
^A0N,40, 30 ^FDABCDEFG^FS | ||
^XZ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
^XA | ||
^FO10,100 | ||
^GB70,70,70,,3^FS | ||
^FO110,100 | ||
^GB70,70,70,,3^FS | ||
^FO210,100 | ||
^GB70,70,70,,3^FS | ||
^FO310,100 | ||
^GB70,70,70,,3^FS | ||
^FO17,110 | ||
^CF0,70,93 | ||
^FR | ||
^FDREVERSE^FS | ||
^XZ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
^XA | ||
^FR | ||
^FO50,50 | ||
^GB100,100,10,W,5^FS | ||
^FR | ||
^FO200,50 | ||
^GB100,100,10,W,5^FS | ||
^FO100,120 | ||
^GB30,25,10,B,2^FS | ||
^FO250,120 | ||
^GB30,25,10,B,2^FS | ||
^FO130,180 | ||
^GB90,90,45,B,8^FS | ||
^FR | ||
^FO75,300 | ||
^GB30,20,10,W,0^FS | ||
^FR | ||
^FO265,300 | ||
^GB30,20,10,W,0^FS | ||
^FR | ||
^FO105,320 | ||
^GB160,20,10,W,0^FS | ||
^FR | ||
^FO120,310 | ||
^GB10,20,5,B,0^FS | ||
^FR | ||
^FO140,310 | ||
^GB10,20,5,B,0^FS | ||
^FR | ||
^FO160,310 | ||
^GB10,20,5,B,0^FS | ||
^FR | ||
^FO180,310 | ||
^GB10,20,5,B,0^FS | ||
^FR | ||
^FO200,310 | ||
^GB10,20,5,B,0^FS | ||
^FR | ||
^FO220,310 | ||
^GB10,20,5,B,0^FS | ||
^FR | ||
^FO240,310 | ||
^GB10,20,5,B,0^FS | ||
^FO150,330 | ||
^GB70,90,45,B,0^FS | ||
^XZ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
^XA | ||
^DFETIQUE-1^FS | ||
^PRC | ||
^LH0,0^FS | ||
^LL408 | ||
^MD0 | ||
^MNY | ||
^LH0,0^FS | ||
^FO120,141^A0N,27,23^CI13^FR^FN999^FS | ||
^BY2,3.0^FO213,7^BCN,80,N,Y,N^FR^FN997^FS | ||
^FO313,95^A0N,35,23^CI13^FR^FB105,2,0,L^FN997^FS | ||
^FO40,141^A0N,27,33^CI13^FR^FDP/N :^FS | ||
^XZ | ||
|
||
^XA | ||
^XFETIQUE-1.ZPL | ||
^FN999^FDC19755BA01:F9111^FS | ||
^FN997^FD3758292^FS | ||
^PQ1,0,1,N | ||
^XZ | ||
^FX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Viewer Unit Test | ||
|
||
This project (should) supports the Viewer project in multiple ways. | ||
|
||
## Standard unit testing | ||
Mostly testing the features of the virtual printer(s) and analyzers. | ||
|
||
## Detect changes and regressions in png outputs | ||
Given a set of known good png output files, we should be able to detect when new output changes. | ||
This would be done by loading 2 pngs into skia bitmaps and xor-ing them. We can then count the amount of black pixels and output a new png showing the difference. | ||
|
||
## Feature development | ||
The `CustomTest.cs` exists for quick development. Load your zpl data in `Data/Zpl/custom.zpl2` and test. Changes to these files are not tracked under source control. Use `git update-index --no-skip-worktree custom.zpl2` and `git update-index --skip-worktree custom.zpl2` (see https://stackoverflow.com/a/39776107) to enable tracking changes to the files. | ||
|
||
## Benchmarks | ||
Performance isn't stellar yet. We can use features in Visual Studio, but other tools might be more suitable like [BenchmarkDotNet](https://github.com/dotnet/BenchmarkDotNet). | ||
|
||
Note that a lot of time is spent inside 3rd party libraries like Skia, BarcodeLib and Zxing.net and Drawing. | ||
|
||
## Todo | ||
- [ ] Linux compatibility | ||
- [ ] Benchmarking | ||
- [ ] Xor diffing pngs |