1 // OpenTween - Client of Twitter
2 // Copyright (c) 2015 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
5 // This file is part of OpenTween.
7 // This program is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by the Free
9 // Software Foundation; either version 3 of the License, or (at your option)
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 // You should have received a copy of the GNU General Public License along
18 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 // Boston, MA 02110-1301, USA.
23 using System.Collections.Generic;
25 using System.Drawing.Imaging;
29 using System.Threading.Tasks;
34 public class MemoryImageTest
37 public async Task ImageFormat_GifTest()
39 using (var imgStream = File.OpenRead("Resources/re.gif"))
40 using (var image = await MemoryImage.CopyFromStreamAsync(imgStream).ConfigureAwait(false))
42 Assert.Equal(ImageFormat.Gif, image.ImageFormat);
43 Assert.Equal(".gif", image.ImageFormatExt);
48 public void ImageFormat_CopyFromImageTest()
50 using (var bitmap = new Bitmap(width: 200, height: 200))
51 using (var image = MemoryImage.CopyFromImage(bitmap))
53 // CopyFromImage から作成した MemoryImage は PNG 画像として扱われる
54 Assert.Equal(ImageFormat.Png, image.ImageFormat);
55 Assert.Equal(".png", image.ImageFormatExt);
60 public void CopyFromImage_Test()
62 using (var bitmap = new Bitmap(width: 200, height: 200))
64 // MemoryImage をエラー無く作成できることをテストする
65 using (var image = MemoryImage.CopyFromImage(bitmap)) { }
70 public void Dispose_Test()
72 using (var image = TestUtils.CreateDummyImage())
74 Assert.False(image.IsDisposed);
78 Assert.True(image.IsDisposed);
79 Assert.Throws<ObjectDisposedException>(() => image.Image);
80 Assert.Throws<ObjectDisposedException>(() => image.ImageFormat);
85 public async Task Equals_Test()
87 using (var imgStream1 = File.OpenRead("Resources/re.gif"))
88 using (var image1 = await MemoryImage.CopyFromStreamAsync(imgStream1).ConfigureAwait(false))
90 using (var imgStream2 = File.OpenRead("Resources/re.gif"))
91 using (var image2 = await MemoryImage.CopyFromStreamAsync(imgStream2).ConfigureAwait(false))
93 Assert.True(image1.Equals(image2));
94 Assert.True(image2.Equals(image1));
97 using (var image3 = TestUtils.CreateDummyImage())
99 Assert.False(image1.Equals(image3));
100 Assert.False(image3.Equals(image1));