Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Image.cs « Test « DrawingTest « Test « System.Drawing « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2f48076afeace3cc90c6a245549612d8f60e650f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
using System;
using NUnit.Framework;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using DrawingTestHelper;
using System.IO;

namespace Test.Sys.Drawing {
	[TestFixture]
	public class ImageFixture {
		DrawingTest t;
		[SetUp]
		public void SetUp () {
			t = DrawingTest.Create (256, 256);
			Image im=new Bitmap (@"..\..\Bitmap1.png"); 
			t.Graphics.DrawImageUnscaled (im, 0, 0);
		}
		[Test]
		public void Clone () {
			Image im1 = (Image) t.Bitmap.Clone ();
			Assert.IsFalse (Object.ReferenceEquals (im1, t.Bitmap));
			Assert.AreEqual (DrawingTest.CalculateNorm ((Bitmap)im1),
				DrawingTest.CalculateNorm (t.Bitmap));
			t.Graphics.FillRectangle (Brushes.Beige, 0, 0, 100, 100);
			Assert.IsFalse (DrawingTest.CalculateNorm ((Bitmap)im1) ==
				DrawingTest.CalculateNorm (t.Bitmap));
		}
		[Test]
		public void Clone2 () {
			Image im1 = (Image) t.Bitmap.Clone (new Rectangle(0, 0, t.Bitmap.Width, t.Bitmap.Height), t.Bitmap.PixelFormat);
			t.Graphics.FillRectangle (Brushes.Beige, 0, 0, 100, 100);
			Assert.IsFalse (DrawingTest.CalculateNorm ((Bitmap)im1) ==
				DrawingTest.CalculateNorm (t.Bitmap));
		}
		[Test]
		public void GetHashCodeTest () {
			Assert.IsFalse (t.Bitmap.GetHashCode () == 0);
			Bitmap im1 = new Bitmap (10, 20);
			Assert.IsFalse (t.Bitmap.GetHashCode () == im1.GetHashCode ());
		}
		[Test]
		public void GetBounds () {
			GraphicsUnit unit = new GraphicsUnit();
			Assert.AreEqual (new RectangleF (0, 0, 256, 256),
				t.Bitmap.GetBounds (ref unit));
			Assert.AreEqual (GraphicsUnit.Pixel, unit);
		}
		[Test]
#if TARGET_JVM
		[Category ("NotWorking")]
#endif
		public void GetEncoderParameterList () {
			Assert.Fail ("Test not implemented - undocumented parameter");
		}
		[Test]
		public void GetFrameCount () {
			Assert.AreEqual (1, t.Bitmap.GetFrameCount (FrameDimension.Page));
		}
		[Test]
		public void GetFrameCount2 () {
			try {
				t.Bitmap.GetFrameCount (FrameDimension.Time);
			}
			catch (ArgumentException) {
				Assert.IsTrue( true );
			}
		}
		[Test]
		public void GetFrameCount3 () {
			try {
				t.Bitmap.GetFrameCount (new FrameDimension (Guid.NewGuid ()));
			}
			catch (ArgumentException) {
				Assert.IsTrue( true );
			}
		}
		[Test]
#if TARGET_JVM
		[Category ("NotWorking")]
#endif
		public void GetPropertyItem () {
			Assert.Fail ("Test not implemented - undocumented parameter");
		}
		[Test]
#if TARGET_JVM
		[Category ("NotWorking")]
#endif
		public void RemovePropertyItem () {
			Assert.Fail ("Test not implemented - undocumented parameter");
		}
		static bool ThumbnailCallback() {
			return false;
		}
		[Test]
#if TARGET_JVM
		[Category ("NotWorking")] // FIXME: IntPtr
#endif
		public void GetThumbnailImage() {
			t.Show ();
			Image.GetThumbnailImageAbort myCallback =
				new Image.GetThumbnailImageAbort(ThumbnailCallback);
			Image myThumbnail = t.Bitmap.GetThumbnailImage(
				10, 10, myCallback, IntPtr.Zero);
			t.Graphics.DrawImageUnscaled (myThumbnail, 100, 75);
			t.Show ();
		}
		[Test]
#if TARGET_JVM
		[Category ("NotWorking")] // FIXME: Image.RotateFlip is not implemented for now.
#endif
		public void RotateFlip () {
			t.Show ();
			t.Bitmap.RotateFlip (RotateFlipType.Rotate90FlipY);
			t.Show ();
			Assert.IsTrue (t.Compare (10));
		}
		[Test]
		public void Save_string () {
			t.Bitmap.Save ("test.png");
			using (FileStream r = new FileStream ("test.png", FileMode.Open)) {
				Bitmap b1 = new Bitmap (r);
				Assert.AreEqual (DrawingTest.CalculateNorm (t.Bitmap),
					DrawingTest.CalculateNorm (b1));
			}
			File.Delete ("test.png");
		}
		[Test]
		public void Save_Stream_ImageFormat () {
			using (FileStream w = new FileStream ("test.png", FileMode.OpenOrCreate)) {
				t.Bitmap.Save (w, ImageFormat.Png);
			}
			using (FileStream r = new FileStream ("test.png", FileMode.Open)) {
				Bitmap b1 = new Bitmap (r);
				Assert.AreEqual (DrawingTest.CalculateNorm (t.Bitmap),
					DrawingTest.CalculateNorm (b1));
			}
			File.Delete ("test.png");
		}
		[Test]
		public void Save_string_ImageFormat () {
			t.Bitmap.Save ("test.png", ImageFormat.Png);
			using (FileStream r = new FileStream ("test.png", FileMode.Open)) {
				Bitmap b1 = new Bitmap (r);
				Assert.AreEqual (DrawingTest.CalculateNorm (t.Bitmap),
					DrawingTest.CalculateNorm (b1));
			}
			File.Delete ("test.png");
		}
		[Test]
#if TARGET_JVM
		[Category("NotWorking")]
#endif
		public void Save_Stream_ImageCodecInfo_EncoderParameters () {
			using (FileStream w = new FileStream ("test.png", FileMode.OpenOrCreate)) {
				foreach (ImageCodecInfo i in ImageCodecInfo.GetImageEncoders()) {
					if (i.FilenameExtension.IndexOf ("png") != -1) {
						t.Bitmap.Save (w, i, new EncoderParameters ());
						break;
					}
				}
			}
			using (FileStream r = new FileStream ("test.png", FileMode.Open)) {
				Bitmap b1 = new Bitmap (r);
				Assert.AreEqual (DrawingTest.CalculateNorm (t.Bitmap),
					DrawingTest.CalculateNorm (b1));
			}
			File.Delete ("test.png");
		}
		[Test]
#if TARGET_JVM
		[Category("NotWorking")]
#endif
		public void Save_string_ImageCodecInfo_EncoderParameters () {
			foreach (ImageCodecInfo i in ImageCodecInfo.GetImageEncoders()) {
				if (i.FilenameExtension.IndexOf ("png") != -1) {
					t.Bitmap.Save ("test.png", i, new EncoderParameters ());
					break;
				}
			}
			using (FileStream r = new FileStream ("test.png", FileMode.Open)) {
				Bitmap b1 = new Bitmap (r);
				Assert.AreEqual (DrawingTest.CalculateNorm (t.Bitmap),
					DrawingTest.CalculateNorm (b1));
			}
			File.Delete ("test.png");
		}
		[Test]
#if TARGET_JVM
		[Category ("NotWorking")]
#endif
		public void SaveAdd () {
			Assert.Fail ("Test not implemented");
		}
		[Test]
#if TARGET_JVM
		[Category ("NotWorking")]
#endif
		public void SelectActiveFrame () {
			Assert.Fail ("Test not implemented");
		}
		[Test]
		[Category ("NotWorking")]
		public void SetPropertyItem () {
			Assert.Fail ("Test not implemented - undocumented parameter");
		}
		[Test]
		public new void ToString () {
			Assert.IsTrue (t.Bitmap.ToString().ToLower().StartsWith("system.drawing.bitmap"));
		}
		[Test]
		public void Height () {
			Assert.AreEqual (256, t.Bitmap.Height);
		}
		[Test]
		public void Width () {
			Assert.AreEqual (256, t.Bitmap.Width);
		}
		[Test]
#if TARGET_JVM
		[Category ("NotWorking")] // FIXME: Image.HorizontalResolution is not implemented for now.
#endif
		public void HorizontalResolution () {
			Assert.AreEqual (96, t.Bitmap.HorizontalResolution);
		}
		[Test]
#if TARGET_JVM
		[Category ("NotWorking")] // FIXME: Image.VerticalResolution is not implemented for now.
#endif
		public void VerticalResolution () {
			Assert.AreEqual (96, t.Bitmap.VerticalResolution);
		}
		[Test]
		public void PixelFormatTest () {
			Assert.AreEqual (PixelFormat.Format32bppArgb, t.Bitmap.PixelFormat);
		}
		[Test]
#if TARGET_JVM
		[Category ("NotWorking")] // FIXME: Image.PropertyIdList is not implemented for now.
#endif
		public void PropertyIdList () {
			Assert.AreEqual (new int [0], t.Bitmap.PropertyIdList);
		}
		[Test]
#if TARGET_JVM
		[Category ("NotWorking")] // FIXME: Image.PropertyItems is not implemented for now.
#endif
		public void PropertyItems () {
			Assert.AreEqual (new PropertyItem [0], t.Bitmap.PropertyItems);
		}
		[Test]
		public void FrameDimensionsList () {
			Assert.AreEqual (new Guid [] {FrameDimension.Page.Guid},
				t.Bitmap.FrameDimensionsList);
		}
		[Test]
		[Category ("Create")]
		public void PNG_Interop()
		{

			string file_name = @"..\..\bitmap_gh.png";
			using (FileStream r = new FileStream (file_name, FileMode.Open)) 
			{
				Image im = new Bitmap (r);
				t.Graphics.DrawImageUnscaled (im, 0, 0);
				Assert.IsTrue(t.Compare(2));
			}

			file_name = @"..\..\bitmap_net.png";
			using (FileStream r = new FileStream (file_name, FileMode.Open)) 
			{
				Image im = new Bitmap (r);
				t.Graphics.DrawImageUnscaled (im, 0, 0);
				Assert.IsTrue(t.Compare(2));
			}
		}
		[Test]
		public void DefaultSaveFormat()
		{
			Bitmap b = new Bitmap(64, 64);
			b.Save("saveFormat.xxx");

			StreamReader sr = new StreamReader("saveFormat.xxx");
			char [] buffer = new char[4];
			sr.Read(buffer, 0, 4);
			sr.Close();

			Assert.AreEqual('P', buffer[0]);
			Assert.AreEqual('N', buffer[1]);
			Assert.AreEqual('G', buffer[2]);
		}
	}
}