-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
84 changed files
with
3,494 additions
and
129 deletions.
There are no files selected for viewing
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
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,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); | ||
} | ||
} | ||
} |
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,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); | ||
} | ||
} | ||
} |
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,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)); | ||
} | ||
} | ||
} |
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,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; | ||
} | ||
} | ||
} |
Oops, something went wrong.