Skip to content

Commit

Permalink
Add unit tests for LabelTop and LabelShift
Browse files Browse the repository at this point in the history
  • Loading branch information
sungaila committed Aug 9, 2024
1 parent c288a3a commit c708405
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Tests/LabelShiftTests.ExpectedResults.cs

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions Tests/LabelShiftTests.cs
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));
}
}
}
34 changes: 34 additions & 0 deletions Tests/LabelTopTests.ExpectedResults.cs

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions Tests/LabelTopTests.cs
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));
}
}
}
6 changes: 6 additions & 0 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
<Compile Update="AntiAliasingTests.ExpectedResults.cs">
<DependentUpon>AntiAliasingTests.cs</DependentUpon>
</Compile>
<Compile Update="LabelTopTests.ExpectedResults.cs">
<DependentUpon>LabelTopTests.cs</DependentUpon>
</Compile>
<Compile Update="LabelShiftTests.ExpectedResults.cs">
<DependentUpon>LabelShiftTests.cs</DependentUpon>
</Compile>
<Compile Update="PrintQuantityTests.ExpectedResults.cs">
<DependentUpon>PrintQuantityTests.cs</DependentUpon>
</Compile>
Expand Down

0 comments on commit c708405

Please sign in to comment.