-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for LabelTop and LabelShift
- Loading branch information
Showing
5 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,56 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using PDFtoZPL; | ||
using System; | ||
using System.IO; | ||
using static PDFtoZPL.Conversion; | ||
|
||
namespace Tests | ||
{ | ||
[TestClass] | ||
public partial class LabelShiftTests | ||
{ | ||
[TestInitialize] | ||
public void Initialize() | ||
{ | ||
#if NET6_0_OR_GREATER | ||
if (!OperatingSystem.IsWindows() && !OperatingSystem.IsLinux() && !OperatingSystem.IsMacOS()) | ||
Assert.Inconclusive("This test must run on Windows, Linux or macOS."); | ||
#endif | ||
} | ||
|
||
#pragma warning disable CA1416 | ||
|
||
[TestMethod] | ||
[DataRow("SocialPreview.pdf", null)] | ||
[DataRow("SocialPreview.pdf", 0)] | ||
[DataRow("SocialPreview.pdf", 9999)] | ||
[DataRow("SocialPreview.pdf", -9999)] | ||
[DataRow("SocialPreview.pdf", (int)short.MaxValue)] | ||
[DataRow("SocialPreview.pdf", (int)short.MinValue)] | ||
[DataRow("SocialPreview.png", null)] | ||
[DataRow("SocialPreview.png", 0)] | ||
[DataRow("SocialPreview.png", 9999)] | ||
[DataRow("SocialPreview.png", -9999)] | ||
[DataRow("SocialPreview.png", (int)short.MaxValue)] | ||
[DataRow("SocialPreview.png", (int)short.MinValue)] | ||
[DataRow("Wikimedia_Commons_web.pdf", null)] | ||
[DataRow("Wikimedia_Commons_web.pdf", 0)] | ||
[DataRow("Wikimedia_Commons_web.pdf", 9999)] | ||
[DataRow("Wikimedia_Commons_web.pdf", -9999)] | ||
[DataRow("Wikimedia_Commons_web.pdf", (int)short.MaxValue)] | ||
[DataRow("Wikimedia_Commons_web.pdf", (int)short.MinValue)] | ||
public void ConvertWithEncodings(string fileName, int? labelShiftInput) | ||
{ | ||
short? labelShift = (short?)labelShiftInput; | ||
var expectedResult = _expectedResults[fileName][labelShift ?? 0]; | ||
|
||
using var fileStream = new FileStream(Path.Combine("Assets", fileName), FileMode.Open, FileAccess.Read); | ||
|
||
var zplResult = fileName.EndsWith(".pdf") | ||
? (labelShift != null ? ConvertPdfPage(fileStream, pdfOptions: new(Dpi: 203), zplOptions: new(EncodingKind: BitmapEncodingKind.Base64Compressed, LabelShift: labelShift.Value)) : ConvertPdfPage(fileStream, pdfOptions: new(Dpi: 203), zplOptions: new(EncodingKind: BitmapEncodingKind.Base64Compressed))) | ||
: (labelShift != null ? ConvertBitmap(fileStream, zplOptions: new(EncodingKind: BitmapEncodingKind.Base64Compressed, LabelShift: labelShift.Value)) : ConvertBitmap(fileStream, zplOptions: new(EncodingKind: BitmapEncodingKind.Base64Compressed))); | ||
|
||
Assert.AreEqual(expectedResult, zplResult.Replace("\n", string.Empty)); | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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,56 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using PDFtoZPL; | ||
using System; | ||
using System.IO; | ||
using static PDFtoZPL.Conversion; | ||
|
||
namespace Tests | ||
{ | ||
[TestClass] | ||
public partial class LabelTopTests | ||
{ | ||
[TestInitialize] | ||
public void Initialize() | ||
{ | ||
#if NET6_0_OR_GREATER | ||
if (!OperatingSystem.IsWindows() && !OperatingSystem.IsLinux() && !OperatingSystem.IsMacOS()) | ||
Assert.Inconclusive("This test must run on Windows, Linux or macOS."); | ||
#endif | ||
} | ||
|
||
#pragma warning disable CA1416 | ||
|
||
[TestMethod] | ||
[DataRow("SocialPreview.pdf", null)] | ||
[DataRow("SocialPreview.pdf", 0)] | ||
[DataRow("SocialPreview.pdf", 120)] | ||
[DataRow("SocialPreview.pdf", -120)] | ||
[DataRow("SocialPreview.pdf", (int)sbyte.MaxValue)] | ||
[DataRow("SocialPreview.pdf", (int)sbyte.MinValue)] | ||
[DataRow("SocialPreview.png", null)] | ||
[DataRow("SocialPreview.png", 0)] | ||
[DataRow("SocialPreview.png", 120)] | ||
[DataRow("SocialPreview.png", -120)] | ||
[DataRow("SocialPreview.png", (int)sbyte.MaxValue)] | ||
[DataRow("SocialPreview.png", (int)sbyte.MinValue)] | ||
[DataRow("Wikimedia_Commons_web.pdf", null)] | ||
[DataRow("Wikimedia_Commons_web.pdf", 0)] | ||
[DataRow("Wikimedia_Commons_web.pdf", 120)] | ||
[DataRow("Wikimedia_Commons_web.pdf", -120)] | ||
[DataRow("Wikimedia_Commons_web.pdf", (int)sbyte.MaxValue)] | ||
[DataRow("Wikimedia_Commons_web.pdf", (int)sbyte.MinValue)] | ||
public void ConvertWithEncodings(string fileName, int? labelTopInput) | ||
{ | ||
sbyte? labelTop = (sbyte?)labelTopInput; | ||
var expectedResult = _expectedResults[fileName][labelTop ?? 0]; | ||
|
||
using var fileStream = new FileStream(Path.Combine("Assets", fileName), FileMode.Open, FileAccess.Read); | ||
|
||
var zplResult = fileName.EndsWith(".pdf") | ||
? (labelTop != null ? ConvertPdfPage(fileStream, pdfOptions: new(Dpi: 203), zplOptions: new(EncodingKind: BitmapEncodingKind.Base64Compressed, LabelTop: labelTop.Value)) : ConvertPdfPage(fileStream, pdfOptions: new(Dpi: 203), zplOptions: new(EncodingKind: BitmapEncodingKind.Base64Compressed))) | ||
: (labelTop != null ? ConvertBitmap(fileStream, zplOptions: new(EncodingKind: BitmapEncodingKind.Base64Compressed, LabelTop: labelTop.Value)) : ConvertBitmap(fileStream, zplOptions: new(EncodingKind: BitmapEncodingKind.Base64Compressed))); | ||
|
||
Assert.AreEqual(expectedResult, zplResult.Replace("\n", string.Empty)); | ||
} | ||
} | ||
} |
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