Skip to content

Commit

Permalink
Increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbl committed May 30, 2024
1 parent cc2662a commit 76f75e8
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Core/QRBill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ public static void Draw(Bill bill, ICanvas canvas)
{
throw;
}
catch (QRBillGenerationException)
{
throw;
}
catch (Exception e)
{
throw new QRBillGenerationException("Failed to generate QR bill", e);
Expand Down
11 changes: 10 additions & 1 deletion CoreTest/PdfCanvasTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,22 @@ public Task LocaleIndependence()
}

[Fact]
public void CharactersOutsideWinANSI_RaisesException()
public void DrawWithCharactersOutsideWinANSI_RaisesException()
{
var bill = SampleData.CreateExample8();
bill.CharacterSet = SpsCharacterSet.ExtendedLatin;
using var canvas = new PDFCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight);
Assert.Throws<QRBillGenerationException>(() => QRBill.Draw(bill, canvas));
}

[Fact]
public void GenerateWithCharactersOutsideWinANSI_RaisesException()
{
var bill = SampleData.CreateExample8();
bill.CharacterSet = SpsCharacterSet.ExtendedLatin;
bill.Format.GraphicsFormat = GraphicsFormat.PDF;

Assert.Throws<QRBillGenerationException>(() => QRBill.Generate(bill));
}
}
}
15 changes: 15 additions & 0 deletions CoreTest/StringsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

using Codecrete.SwissQRBill.Generator;
using System.Text;
using Xunit;

namespace Codecrete.SwissQRBill.CoreTest
Expand Down Expand Up @@ -48,5 +49,19 @@ public void ManySpaces_Cleaned()
{
Assert.Equal("a b c", " a b c ".SpacesCleaned());
}

[Theory]
[InlineData(0x00DC, "Ü")]
[InlineData(0x0409, "Љ")]
[InlineData(0x1F609, "😉")]
[InlineData(0x1F680, "🚀")]
public void AppendCodePoint_ExpectedResult(int codePoint, string expectedResult)
{
var sb = new StringBuilder();
sb.Append("xx");
StringExtensions.AppendCodePoint(sb, codePoint);
sb.Append("yy");
Assert.Equal($"xx{expectedResult}yy", sb.ToString());
}
}
}
1 change: 0 additions & 1 deletion PixelCanvasTest/PNGCanvasTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,5 @@ public void PngSaveAs()
QRBill.Draw(bill, canvas);
canvas.SaveAs("qrbill.png");
}

}
}
56 changes: 56 additions & 0 deletions PixelCanvasTest/PngProcessorTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// Swiss QR Bill Generator for .NET
// Copyright (c) 2018 Manuel Bleichenbacher
// Licensed under MIT License
// https://opensource.org/licenses/MIT
//

using Codecrete.SwissQRBill.PixelCanvas;
using System;
using Xunit;

namespace Codecrete.SwissQRBill.PixelCanvasTest
{
public class PngProcessorTest
{
[Fact]
public void HeaderIncomplete_Fails()
{
var data = new byte[] { 0, 0, 0, 0, 0 };
Assert.Throws<ArgumentException>(() =>
{
PngProcessor.InsertDpi(new System.IO.MemoryStream(data), new System.IO.MemoryStream(), 96);
});
}

[Fact]
public void NoPhysChunk_Fails()
{
var data = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 };
Assert.Throws<ArgumentException>(() =>
{
PngProcessor.InsertDpi(new System.IO.MemoryStream(data), new System.IO.MemoryStream(), 96);
});
}

[Fact]
public void FirstChunkIncomplete_Fails()
{
var data = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Assert.Throws<ArgumentException>(() =>
{
PngProcessor.InsertDpi(new System.IO.MemoryStream(data), new System.IO.MemoryStream(), 96);
});
}

[Fact]
public void Incomplete_Fails()
{
var data = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
Assert.Throws<ArgumentException>(() =>
{
PngProcessor.InsertDpi(new System.IO.MemoryStream(data), new System.IO.MemoryStream(), 96);
});
}
}
}

0 comments on commit 76f75e8

Please sign in to comment.