1 // OpenTween - Client of Twitter
2 // Copyright (c) 2014 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.Threading;
24 using System.Threading.Tasks;
25 using System.Windows.Forms;
30 public class OTPictureBoxTest
33 public void SizeMode_SetterGetterTest()
35 using (var picbox = new OTPictureBox())
37 picbox.SizeMode = PictureBoxSizeMode.Zoom;
39 Assert.Equal(PictureBoxSizeMode.Zoom, picbox.SizeMode);
40 Assert.Equal(PictureBoxSizeMode.Zoom, ((PictureBox)picbox).SizeMode);
45 public void SizeMode_ErrorImageTest()
47 using (var picbox = new OTPictureBox())
49 picbox.SizeMode = PictureBoxSizeMode.Zoom;
51 picbox.ShowErrorImage();
53 Assert.Equal(PictureBoxSizeMode.Zoom, picbox.SizeMode);
54 Assert.Equal(PictureBoxSizeMode.CenterImage, ((PictureBox)picbox).SizeMode);
59 public void SizeMode_ErrorImageTest2()
61 using (var picbox = new OTPictureBox())
63 picbox.ShowErrorImage();
65 picbox.SizeMode = PictureBoxSizeMode.Zoom;
67 Assert.Equal(PictureBoxSizeMode.Zoom, picbox.SizeMode);
68 Assert.Equal(PictureBoxSizeMode.CenterImage, ((PictureBox)picbox).SizeMode);
73 public void SizeMode_RestoreTest()
75 using (var picbox = new OTPictureBox())
77 picbox.SizeMode = PictureBoxSizeMode.Zoom;
79 picbox.ShowErrorImage();
81 picbox.Image = TestUtils.CreateDummyImage();
83 Assert.Equal(PictureBoxSizeMode.Zoom, picbox.SizeMode);
84 Assert.Equal(PictureBoxSizeMode.Zoom, ((PictureBox)picbox).SizeMode);
89 public async Task SetImageFromAsync_Test()
91 using (var picbox = new OTPictureBox())
93 // Mono でのテスト実行時にデッドロックする問題の対策
94 SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
96 var tcs = new TaskCompletionSource<MemoryImage>();
98 var setImageTask = picbox.SetImageFromTask(() => tcs.Task);
100 Assert.Equal(picbox.InitialImage, ((PictureBox)picbox).Image);
102 var image = TestUtils.CreateDummyImage();
103 tcs.SetResult(image);
106 Assert.Equal(image, picbox.Image);
111 public async Task SetImageFromAsync_ErrorTest()
113 using (var picbox = new OTPictureBox())
115 // Mono でのテスト実行時にデッドロックする問題の対策
116 SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
118 var tcs = new TaskCompletionSource<MemoryImage>();
120 var setImageTask = picbox.SetImageFromTask(() => tcs.Task);
122 Assert.Equal(picbox.InitialImage, ((PictureBox)picbox).Image);
124 tcs.SetException(new InvalidImageException());
127 Assert.Equal(picbox.ErrorImage, ((PictureBox)picbox).Image);