OSDN Git Service

Assert.Equalの引数順の誤りを修正 (xUnit2000)
[opentween/open-tween.git] / OpenTween.Tests / MemoryImageTest.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2015 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
4 //
5 // This file is part of OpenTween.
6 //
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)
10 // any later version.
11 //
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
15 // for more details.
16 //
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.
21
22 using System;
23 using System.Collections.Generic;
24 using System.Drawing;
25 using System.Drawing.Imaging;
26 using System.IO;
27 using System.Linq;
28 using System.Text;
29 using System.Threading.Tasks;
30 using Xunit;
31
32 namespace OpenTween
33 {
34     public class MemoryImageTest
35     {
36         [Fact]
37         public async Task ImageFormat_GifTest()
38         {
39             using (var imgStream = File.OpenRead("Resources/re.gif"))
40             using (var image = await MemoryImage.CopyFromStreamAsync(imgStream).ConfigureAwait(false))
41             {
42                 Assert.Equal(ImageFormat.Gif, image.ImageFormat);
43                 Assert.Equal(".gif", image.ImageFormatExt);
44             }
45         }
46
47         [Fact]
48         public void ImageFormat_CopyFromImageTest()
49         {
50             using (var bitmap = new Bitmap(width: 200, height: 200))
51             using (var image = MemoryImage.CopyFromImage(bitmap))
52             {
53                 // CopyFromImage から作成した MemoryImage は PNG 画像として扱われる
54                 Assert.Equal(ImageFormat.Png, image.ImageFormat);
55                 Assert.Equal(".png", image.ImageFormatExt);
56             }
57         }
58
59         [Fact]
60         public void CopyFromImage_Test()
61         {
62             using (var bitmap = new Bitmap(width: 200, height: 200))
63             {
64                 // MemoryImage をエラー無く作成できることをテストする
65                 using (var image = MemoryImage.CopyFromImage(bitmap)) { }
66             }
67         }
68
69         [Fact]
70         public void Dispose_Test()
71         {
72             using (var image = TestUtils.CreateDummyImage())
73             {
74                 Assert.False(image.IsDisposed);
75
76                 image.Dispose();
77
78                 Assert.True(image.IsDisposed);
79                 Assert.Throws<ObjectDisposedException>(() => image.Image);
80                 Assert.Throws<ObjectDisposedException>(() => image.ImageFormat);
81             }
82         }
83
84         [Fact]
85         public async Task Equals_Test()
86         {
87             using (var imgStream1 = File.OpenRead("Resources/re.gif"))
88             using (var image1 = await MemoryImage.CopyFromStreamAsync(imgStream1).ConfigureAwait(false))
89             {
90                 using (var imgStream2 = File.OpenRead("Resources/re.gif"))
91                 using (var image2 = await MemoryImage.CopyFromStreamAsync(imgStream2).ConfigureAwait(false))
92                 {
93                     Assert.True(image1.Equals(image2));
94                     Assert.True(image2.Equals(image1));
95                 }
96
97                 using (var image3 = TestUtils.CreateDummyImage())
98                 {
99                     Assert.False(image1.Equals(image3));
100                     Assert.False(image3.Equals(image1));
101                 }
102             }
103         }
104     }
105 }