Skip to content

Commit

Permalink
CSHARP-389 - More specific test showing an example of a Bitmap that c…
Browse files Browse the repository at this point in the history
…an be roundtripped in Mono.
  • Loading branch information
Sridhar Nanjundeswaran committed Mar 25, 2013
1 parent fad9b8b commit 5f1e099
Showing 1 changed file with 38 additions and 6 deletions.
44 changes: 38 additions & 6 deletions MongoDB.DriverUnitTests/Jira/CSharp355Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public void TestFixtureSetup()
}

[Test]
public void TestBitmap()
public void TestDefaultBitmap()
{
if (TestEnvironment.IsMono)
{
// this test does not work in Mono. Skipping for the time being
// CSHARP-389
// This test does not work in Mono. Bits 57 and 61 are 255 when
// the Bitmap is recreated upon retrieval from the database
return;
}
var bitmap = new Bitmap(1, 2);
Expand All @@ -63,8 +63,23 @@ public void TestBitmap()
var r = _collection.FindOne();
Assert.IsInstanceOf<C>(r);
Assert.IsInstanceOf<Bitmap>(r.I);
Assert.AreEqual(1, r.B.Width);
Assert.AreEqual(2, r.B.Height);
Assert.AreEqual(bitmap.Width, r.B.Width);
Assert.AreEqual(bitmap.Height, r.B.Height);
Assert.IsTrue(GetBytes(bitmap).SequenceEqual(GetBytes(r.B)));
}

[Test]
public void TestBitmap()
{
var bitmap = GetTestBitmap();
var c = new C { I = bitmap, B = bitmap };
_collection.RemoveAll();
_collection.Insert(c);
var r = _collection.FindOne();
Assert.IsInstanceOf<C>(r);
Assert.IsInstanceOf<Bitmap>(r.I);
Assert.AreEqual(bitmap.Width, r.B.Width);
Assert.AreEqual(bitmap.Height, r.B.Height);
Assert.IsTrue(GetBytes(bitmap).SequenceEqual(GetBytes(r.B)));
}

Expand All @@ -88,5 +103,22 @@ private byte[] GetBytes(Bitmap bitmap)
return stream.ToArray();
}
}
}

private Bitmap GetTestBitmap ()
{
var bitmap = new Bitmap (2, 2, PixelFormat.Format32bppRgb);
for (int x = 0; x < bitmap.Height; ++x)
{
for (int y = 0; y < bitmap.Width; ++y)
{
bitmap.SetPixel (x, y, Color.White);
}
}
for (int x = 0; x < bitmap.Height; ++x)
{
bitmap.SetPixel (x, x, Color.Red);
}
return bitmap;
}
}
}

0 comments on commit 5f1e099

Please sign in to comment.