Skip to content

Commit

Permalink
New test cases for SvgQRCodes with logos
Browse files Browse the repository at this point in the history
  • Loading branch information
codebude committed May 3, 2021
1 parent 9fe1f2b commit 1d25386
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions QRCoderTests/QRCoderTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<ProjectReference Include="..\QRCoder\QRCoder.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="assets\noun_Scientist_2909361.svg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="assets\noun_software engineer_2909346.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
42 changes: 42 additions & 0 deletions QRCoderTests/SvgQRCodeRendererTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,48 @@ public void can_render_svg_qrcode_without_quietzones()

result.ShouldBe("24392f47d4c1c2c5097bd6b3f8eefccc");
}

[Fact]
[Category("QRRenderer/SvgQRCode")]
public void can_render_svg_qrcode_with_png_logo()
{
//Create QR code
var gen = new QRCodeGenerator();
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.H);

//Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346
var logoBitmap = (Bitmap)Bitmap.FromFile(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Replace("file:\\", "") + "\\assets\\noun_software engineer_2909346.png");
var logoObj = new SvgQRCode.SvgLogo(logoBitmap, 15);

var svg = new SvgQRCode(data).GetGraphic(10, Color.DarkGray, Color.White, logo: logoObj);

var md5 = new MD5CryptoServiceProvider();
var hash = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(svg));
var result = BitConverter.ToString(hash).Replace("-", "").ToLower();

result.ShouldBe("4ff45872787f321524cc4d071239c25e");
}

[Fact]
[Category("QRRenderer/SvgQRCode")]
public void can_render_svg_qrcode_with_svg_logo()
{
//Create QR code
var gen = new QRCodeGenerator();
var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.H);

//Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909361
var logoSvg = File.ReadAllText(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).Replace("file:\\", "") + "\\assets\\noun_Scientist_2909361.svg");
var logoObj = new SvgQRCode.SvgLogo(logoSvg, 30);

var svg = new SvgQRCode(data).GetGraphic(10, Color.DarkGray, Color.White, logo: logoObj);

var md5 = new MD5CryptoServiceProvider();
var hash = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(svg));
var result = BitConverter.ToString(hash).Replace("-", "").ToLower();

result.ShouldBe("b4ded3964e2e640b6b6c74d1c89d71fa");
}
#endif
}
}
Expand Down
1 change: 1 addition & 0 deletions QRCoderTests/assets/noun_Scientist_2909361.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1d25386

Please sign in to comment.