Skip to content

Commit

Permalink
Merge branch 'release/v0.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Cory Todd committed Jun 14, 2018
2 parents 0d07464 + cbb551c commit 8698b0c
Show file tree
Hide file tree
Showing 84 changed files with 3,494 additions and 129 deletions.
3 changes: 2 additions & 1 deletion PTIReliance.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=REL/@EntryIndexedValue">REL</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=RTC/@EntryIndexedValue">RTC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=USB/@EntryIndexedValue">USB</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=USBSN/@EntryIndexedValue">USBSN</s:String></wpf:ResourceDictionary>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=USBSN/@EntryIndexedValue">USBSN</s:String>
<s:String x:Key="/Default/FilterSettingsManager/CoverageFilterXml/@EntryValue">&lt;data&gt;&lt;IncludeFilters /&gt;&lt;ExcludeFilters&gt;&lt;Filter ModuleMask="PTIRelianceLib" ModuleVersionMask="*" ClassMask="PTIRelianceLib.Logging.LogProviders.*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="PTIRelianceLib" ModuleVersionMask="*" ClassMask="PTIRelianceLib.Logging.*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="RelianceCLI" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="True" /&gt;&lt;Filter ModuleMask="PTIRelianceLib.Tests" ModuleVersionMask="*" ClassMask="*" FunctionMask="*" IsEnabled="True" /&gt;&lt;/ExcludeFilters&gt;&lt;/data&gt;</s:String></wpf:ResourceDictionary>
17 changes: 17 additions & 0 deletions PTIRelianceLib.Tests/Flash/RELStreamerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using PTIRelianceLib.Flash;
using Xunit;

namespace PTIRelianceLib.Tests.Flash
{
public class RELStreamerTests
{

[Fact]
public void TestNullStreamer()
{
var streamer = new RELStreamer(null, null);
var status = streamer.StreamFlashData(null);
Assert.Equal(ReturnCodes.InvalidRequestPayload, status);
}
}
}
37 changes: 37 additions & 0 deletions PTIRelianceLib.Tests/Imaging/BasePrintLogoTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using PTIRelianceLib.Imaging;
using Xunit;

namespace PTIRelianceLib.Tests.Imaging
{
using System.ComponentModel;

public class BasePrintLogoTests
{
[Fact()]
[Category("BMP")]
public void ApplyColorInversionTest()
{
// Input are expected are provided as resources, dithered is what
// we are testing

var input = BinaryFile.From(Properties.Resources.white_bitmap);

var logo = new BasePrintLogo(input);

Assert.False(logo.IsInverted);

logo.ApplyColorInversion();

var inverted = logo.ImageData;
var expected = new BasePrintLogo(BinaryFile.From(Properties.Resources.black_bitmap)).ImageData;

// White should ivnert to black
Assert.True(ImageTestHelpers.CompareCrc32(expected, inverted));
Assert.True(logo.IsInverted);

// Flip back to white, test that the inversion flag is cleared
logo.ApplyColorInversion();
Assert.False(logo.IsInverted);
}
}
}
129 changes: 129 additions & 0 deletions PTIRelianceLib.Tests/Imaging/DitherFactoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#region Header
// DitherFactoryTests.cs
// PTIRelianceLib.Tests
// Cory Todd
// 13-06-2018
// 2:17 PM
#endregion

namespace PTIRelianceLib.Tests.Imaging
{
using System;
using System.ComponentModel;
using PTIRelianceLib.Imaging;
using Xunit;

public class DitherFactoryTests
{
/// <summary>
/// Generates various perfect-gray input dithers and compares to known
/// good dither generators, e.g. photoshop
/// </summary>
[Fact()]
public void GetDithererAtkinsonFact()
{

// Input are expected are provided as resources, dithered is what
// we are testing
var input = new BasePrintLogo(BinaryFile.From(Properties.Resources.gray_bitmap)).ImageData;
var expected = new BasePrintLogo(BinaryFile.From(Properties.Resources.gray_atkinson)).ImageData;
var dithered = DitherFactory.GetDitherer(DitherAlgorithms.Atkinson).GenerateDithered(input);

Assert.True(ImageTestHelpers.CompareCrc32(expected, dithered));
}

[Fact()]
public void GetDithererBurkesFact()
{
var input = new BasePrintLogo(BinaryFile.From(Properties.Resources.gray_bitmap)).ImageData;
var expected = new BasePrintLogo(BinaryFile.From(Properties.Resources.gray_burkes)).ImageData;
var dithered = DitherFactory.GetDitherer(DitherAlgorithms.Burkes).GenerateDithered(input);

Assert.True(ImageTestHelpers.CompareCrc32(expected, dithered));
}

[Fact()]
public void GetDithererFloydSteinbergFact()
{
var input = new BasePrintLogo(BinaryFile.From(Properties.Resources.gray_bitmap)).ImageData;
var expected = new BasePrintLogo(BinaryFile.From(Properties.Resources.gray_floydsteinbergs)).ImageData;
var dithered = DitherFactory.GetDitherer(DitherAlgorithms.FloydSteinberg).GenerateDithered(input);

Assert.True(ImageTestHelpers.CompareCrc32(expected, dithered));
}

// TODO test false floyd steinberg

[Fact()]
public void GetDithererJarvisJudiceNinkeFact()
{
var input = new BasePrintLogo(BinaryFile.From(Properties.Resources.gray_bitmap)).ImageData;
var expected = new BasePrintLogo(BinaryFile.From(Properties.Resources.gray_jjn)).ImageData;
var dithered = DitherFactory.GetDitherer(DitherAlgorithms.JarvisJudiceNinke).GenerateDithered(input);

Assert.True(ImageTestHelpers.CompareCrc32(expected, dithered));
}

[Fact()]
[Category("BMP")]
public void GetDithererNoneFact()
{
var input = new BasePrintLogo(BinaryFile.From(Properties.Resources.gray_bitmap)).ImageData;
var expected = new BasePrintLogo(BinaryFile.From(Properties.Resources.white_bitmap)).ImageData;
var dithered = DitherFactory.GetDitherer(DitherAlgorithms.None).GenerateDithered(input);

Assert.True(ImageTestHelpers.CompareCrc32(expected, dithered));
}

[Fact()]
public void GetDithererSierraFact()
{
var input = new BasePrintLogo(BinaryFile.From(Properties.Resources.gray_bitmap)).ImageData;
var expected = new BasePrintLogo(BinaryFile.From(Properties.Resources.gray_sierra)).ImageData;
var dithered = DitherFactory.GetDitherer(DitherAlgorithms.Sierra).GenerateDithered(input);

Assert.True(ImageTestHelpers.CompareCrc32(expected, dithered));
}

[Fact()]
public void GetDithererSierra2Fact()
{
var input = new BasePrintLogo(BinaryFile.From(Properties.Resources.gray_bitmap)).ImageData;
var expected = new BasePrintLogo(BinaryFile.From(Properties.Resources.gray_sierra2)).ImageData;
var dithered = DitherFactory.GetDitherer(DitherAlgorithms.Sierra2).GenerateDithered(input);

Assert.True(ImageTestHelpers.CompareCrc32(expected, dithered));
}

[Fact()]
public void GetDithererSierraLiteFact()
{
var input = new BasePrintLogo(BinaryFile.From(Properties.Resources.gray_bitmap)).ImageData;
var expected = new BasePrintLogo(BinaryFile.From(Properties.Resources.gray_sierralite)).ImageData;
var dithered = DitherFactory.GetDitherer(DitherAlgorithms.SierraLite).GenerateDithered(input);

Assert.True(ImageTestHelpers.CompareCrc32(expected, dithered));
}

[Fact()]
public void GetDithererStuckiFact()
{
var input = new BasePrintLogo(BinaryFile.From(Properties.Resources.gray_bitmap)).ImageData;
var expected = new BasePrintLogo(BinaryFile.From(Properties.Resources.gray_stucki)).ImageData;
var dithered = DitherFactory.GetDitherer(DitherAlgorithms.Stucki).GenerateDithered(input);

Assert.True(ImageTestHelpers.CompareCrc32(expected, dithered));
}


[Fact()]
public void BadDitherCtorFact()
{
// Cannot have a null algorith matrix
Assert.Throws<ArgumentNullException>(() => new Dither(null, 1, 1));

// Cannot allow a zero divisor
Assert.Throws<ArgumentException>(() => new Dither(new byte[,] { }, 0, 0));
}
}
}
179 changes: 179 additions & 0 deletions PTIRelianceLib.Tests/Imaging/ImageExtTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#region Header

// ImageExtTests.cs
// PTIRelianceLib.Tests
// Cory Todd
// 13-06-2018
// 2:08 PM

#endregion

namespace PTIRelianceLib.Tests.Imaging
{
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using Properties;
using PTIRelianceLib.Imaging;
using Xunit;

public class ImageExtTests
{
/// <summary>
/// Given a known bitmap, esnure that it generates the correct colorspace buffer with full opacity
/// </summary>
[Fact()]
public void BitmapToBufferFact()
{
var inbmp = new BasePrintLogo(BinaryFile.From(Resources.gray_bitmap)).ImageData;
var expectedBuff =
ImageTestHelpers.BgraGenerator(new byte[] { 128, 128, 128, 255}, inbmp.Height * inbmp.Width);
Assert.Equal(ImageConvertResults.Success, ImageTestHelpers.TestBitmapConversion(inbmp, expectedBuff));

inbmp = new BasePrintLogo(BinaryFile.From(Resources.white_bitmap)).ImageData;
expectedBuff = ImageTestHelpers.BgraGenerator(new byte[] {255, 255, 255, 255}, inbmp.Height * inbmp.Width);
Assert.Equal(ImageConvertResults.Success, ImageTestHelpers.TestBitmapConversion(inbmp, expectedBuff));

inbmp = new BasePrintLogo(BinaryFile.From(Resources.black_bitmap)).ImageData;
expectedBuff = ImageTestHelpers.BgraGenerator(new byte[] {0, 0, 0, 255}, inbmp.Height * inbmp.Width);
Assert.Equal(ImageConvertResults.Success, ImageTestHelpers.TestBitmapConversion(inbmp, expectedBuff));

inbmp = new BasePrintLogo(BinaryFile.From(Resources.red_bitmap)).ImageData;
expectedBuff = ImageTestHelpers.BgraGenerator(new byte[] {0, 0, 255, 255}, inbmp.Height * inbmp.Width);
Assert.Equal(ImageConvertResults.Success, ImageTestHelpers.TestBitmapConversion(inbmp, expectedBuff));

inbmp = new BasePrintLogo(BinaryFile.From(Resources.green_bitmap)).ImageData;
expectedBuff = ImageTestHelpers.BgraGenerator(new byte[] {0, 255, 0, 255}, inbmp.Height * inbmp.Width);
Assert.Equal(ImageConvertResults.Success, ImageTestHelpers.TestBitmapConversion(inbmp, expectedBuff));

inbmp = new BasePrintLogo(BinaryFile.From(Resources.blue_bitmap)).ImageData;
expectedBuff = ImageTestHelpers.BgraGenerator(new byte[] {255, 0, 0, 255}, inbmp.Height * inbmp.Width);
Assert.Equal(ImageConvertResults.Success, ImageTestHelpers.TestBitmapConversion(inbmp, expectedBuff));
}

[Fact()]
[Category("BMP")]
public void BitmapImageToBitmapFact()
{
var bmps = new List<Bitmap>
{
new BasePrintLogo(BinaryFile.From(Resources.gray_bitmap)).ImageData,
new BasePrintLogo(BinaryFile.From(Resources.white_bitmap)).ImageData,
new BasePrintLogo(BinaryFile.From(Resources.black_bitmap)).ImageData,
new BasePrintLogo(BinaryFile.From(Resources.red_bitmap)).ImageData,
new BasePrintLogo(BinaryFile.From(Resources.green_bitmap)).ImageData,
new BasePrintLogo(BinaryFile.From(Resources.blue_bitmap)).ImageData
};

foreach (var inbmp in bmps)
{
using (var memory = new MemoryStream())
{
inbmp.Save(memory, ImageFormat.Png);
memory.Position = 0;

var id = new Bitmap(memory);
Assert.True(ImageTestHelpers.CompareCrc32(inbmp, id));
}
}
}


/// <summary>
/// Given a known bitmap, esnure that it generates the correct colorspace buffer with full opacity
/// </summary>
[Fact()]
[Category("BMP")]
public void BitmapInvertColorChannelsFact()
{
var inbmp = new BasePrintLogo(BinaryFile.From(Resources.gray_bitmap)).ImageData;
var expectedBuff =
ImageTestHelpers.BgraGenerator(new byte[] {127, 127, 127, 255}, inbmp.Height * inbmp.Width);
inbmp.InvertColorChannels();
var actualBuff = inbmp.ToBuffer();
Assert.Equal(expectedBuff, actualBuff);

inbmp = new BasePrintLogo(BinaryFile.From(Resources.white_bitmap)).ImageData;
expectedBuff = ImageTestHelpers.BgraGenerator(new byte[] {0, 0, 0, 255}, inbmp.Height * inbmp.Width);
inbmp.InvertColorChannels();
actualBuff = inbmp.ToBuffer();
Assert.Equal(expectedBuff, actualBuff);

inbmp = new BasePrintLogo(BinaryFile.From(Resources.black_bitmap)).ImageData;
expectedBuff = ImageTestHelpers.BgraGenerator(new byte[] {255, 255, 255, 255}, inbmp.Height * inbmp.Width);
inbmp.InvertColorChannels();
actualBuff = inbmp.ToBuffer();
Assert.Equal(expectedBuff, actualBuff);

inbmp = new BasePrintLogo(BinaryFile.From(Resources.red_bitmap)).ImageData;
expectedBuff = ImageTestHelpers.BgraGenerator(new byte[] {255, 255, 0, 255}, inbmp.Height * inbmp.Width);
inbmp.InvertColorChannels();
actualBuff = inbmp.ToBuffer();
Assert.Equal(expectedBuff, actualBuff);

inbmp = new BasePrintLogo(BinaryFile.From(Resources.green_bitmap)).ImageData;
expectedBuff = ImageTestHelpers.BgraGenerator(new byte[] {255, 0, 255, 255}, inbmp.Height * inbmp.Width);
inbmp.InvertColorChannels();
actualBuff = inbmp.ToBuffer();
Assert.Equal(expectedBuff, actualBuff);

inbmp = new BasePrintLogo(BinaryFile.From(Resources.blue_bitmap)).ImageData;
expectedBuff = ImageTestHelpers.BgraGenerator(new byte[] {0, 255, 255, 255}, inbmp.Height * inbmp.Width);
inbmp.InvertColorChannels();
actualBuff = inbmp.ToBuffer();
Assert.Equal(expectedBuff, actualBuff);
}


[Fact()]
public void BitmapToLogoBufferSimpleFact()
{
var inbmp = new BasePrintLogo(BinaryFile.From(Resources.gray_bitmap)).ImageData;
var expectedBuff = Repeated<byte>(255, (inbmp.Height * inbmp.Width) >> 3).ToArray();
var actualBuff = inbmp.ToLogoBuffer();
Assert.Equal(expectedBuff, actualBuff);

inbmp = new BasePrintLogo(BinaryFile.From(Resources.white_bitmap)).ImageData;
expectedBuff = Repeated<byte>(0, (inbmp.Height * inbmp.Width) >> 3).ToArray();
actualBuff = inbmp.ToLogoBuffer();
Assert.Equal(expectedBuff, actualBuff);

inbmp = new BasePrintLogo(BinaryFile.From(Resources.black_bitmap)).ImageData;
expectedBuff = Repeated<byte>(255, (inbmp.Height * inbmp.Width) >> 3).ToArray();
actualBuff = inbmp.ToLogoBuffer();
Assert.Equal(expectedBuff, actualBuff);

inbmp = new BasePrintLogo(BinaryFile.From(Resources.red_bitmap)).ImageData;
expectedBuff = Repeated<byte>(255, (inbmp.Height * inbmp.Width) >> 3).ToArray();
actualBuff = inbmp.ToLogoBuffer();
Assert.Equal(expectedBuff, actualBuff);

inbmp = new BasePrintLogo(BinaryFile.From(Resources.green_bitmap)).ImageData;
expectedBuff = Repeated<byte>(255, (inbmp.Height * inbmp.Width) >> 3).ToArray();
actualBuff = inbmp.ToLogoBuffer();
Assert.Equal(expectedBuff, actualBuff);

inbmp = new BasePrintLogo(BinaryFile.From(Resources.blue_bitmap)).ImageData;
expectedBuff = Repeated<byte>(255, (inbmp.Height * inbmp.Width) >> 3).ToArray();
actualBuff = inbmp.ToLogoBuffer();
Assert.Equal(expectedBuff, actualBuff);
}

/// <summary>
/// Returns a list of type T with value repeat count times
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="value"></param>
/// <param name="count"></param>
/// <returns></returns>
private static List<T> Repeated<T>(T value, int count)
{
var ret = new List<T>(count);
ret.AddRange(Enumerable.Repeat(value, count));
return ret;
}
}
}
Loading

0 comments on commit 8698b0c

Please sign in to comment.