Skip to content

Commit

Permalink
Make Save test encoding independent
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-cooper committed Oct 29, 2018
1 parent c48a098 commit 0828ba8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions StenographyTests/StenographyTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<HintPath>..\packages\NUnit.3.11.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
Expand Down
26 changes: 25 additions & 1 deletion StenographyTests/Storage/LsbStorageProviderTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Drawing;
using System.IO;
using NUnit.Framework;
using Stenography.Noise;
Expand Down Expand Up @@ -34,12 +35,35 @@ public void SaveTest()
Console.WriteLine(System.Text.Encoding.UTF8.GetString(File.ReadAllBytes(outputFile)));
Console.WriteLine(System.Text.Encoding.UTF8.GetString(File.ReadAllBytes(expectedFile)));

// Load images
Bitmap expected = new Bitmap(expectedFile);
Bitmap actual = new Bitmap(outputFile);

try
{
FileAssert.AreEqual(expectedFile, outputFile);
bool fail = (expected.Width != actual.Width) || (expected.Height != actual.Height);

if (!fail)
{
// Compare pixel by pixel (due to encoding differences on Mono)
for (int i = 0; i < expected.Width; i++)
{
for (int j = 0; j < expected.Height; j++)
{
if (expected.GetPixel(i, j) != actual.GetPixel(i, j))
{
fail = true;
}
}
}
}

Assert.AreEqual(false, fail);
}
finally
{
expected.Dispose();
actual.Dispose();
File.Delete(outputFile);
}
}
Expand Down

0 comments on commit 0828ba8

Please sign in to comment.