Skip to content

Commit 5f1e099

Browse files
author
Sridhar Nanjundeswaran
committed
CSHARP-389 - More specific test showing an example of a Bitmap that can be roundtripped in Mono.
1 parent fad9b8b commit 5f1e099

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

MongoDB.DriverUnitTests/Jira/CSharp355Tests.cs

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ public void TestFixtureSetup()
4848
}
4949

5050
[Test]
51-
public void TestBitmap()
51+
public void TestDefaultBitmap()
5252
{
5353
if (TestEnvironment.IsMono)
5454
{
55-
// this test does not work in Mono. Skipping for the time being
56-
// CSHARP-389
55+
// This test does not work in Mono. Bits 57 and 61 are 255 when
56+
// the Bitmap is recreated upon retrieval from the database
5757
return;
5858
}
5959
var bitmap = new Bitmap(1, 2);
@@ -63,8 +63,23 @@ public void TestBitmap()
6363
var r = _collection.FindOne();
6464
Assert.IsInstanceOf<C>(r);
6565
Assert.IsInstanceOf<Bitmap>(r.I);
66-
Assert.AreEqual(1, r.B.Width);
67-
Assert.AreEqual(2, r.B.Height);
66+
Assert.AreEqual(bitmap.Width, r.B.Width);
67+
Assert.AreEqual(bitmap.Height, r.B.Height);
68+
Assert.IsTrue(GetBytes(bitmap).SequenceEqual(GetBytes(r.B)));
69+
}
70+
71+
[Test]
72+
public void TestBitmap()
73+
{
74+
var bitmap = GetTestBitmap();
75+
var c = new C { I = bitmap, B = bitmap };
76+
_collection.RemoveAll();
77+
_collection.Insert(c);
78+
var r = _collection.FindOne();
79+
Assert.IsInstanceOf<C>(r);
80+
Assert.IsInstanceOf<Bitmap>(r.I);
81+
Assert.AreEqual(bitmap.Width, r.B.Width);
82+
Assert.AreEqual(bitmap.Height, r.B.Height);
6883
Assert.IsTrue(GetBytes(bitmap).SequenceEqual(GetBytes(r.B)));
6984
}
7085

@@ -88,5 +103,22 @@ private byte[] GetBytes(Bitmap bitmap)
88103
return stream.ToArray();
89104
}
90105
}
91-
}
106+
107+
private Bitmap GetTestBitmap ()
108+
{
109+
var bitmap = new Bitmap (2, 2, PixelFormat.Format32bppRgb);
110+
for (int x = 0; x < bitmap.Height; ++x)
111+
{
112+
for (int y = 0; y < bitmap.Width; ++y)
113+
{
114+
bitmap.SetPixel (x, y, Color.White);
115+
}
116+
}
117+
for (int x = 0; x < bitmap.Height; ++x)
118+
{
119+
bitmap.SetPixel (x, x, Color.Red);
120+
}
121+
return bitmap;
122+
}
123+
}
92124
}

0 commit comments

Comments
 (0)