OSDN Git Service

TwitterCredentialOAuth1に渡す引数の誤りを修正
[opentween/open-tween.git] / OpenTween.Tests / OTBaseFormTest.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.Linq;
26 using System.Text;
27 using System.Threading.Tasks;
28 using System.Windows.Forms;
29 using Xunit;
30
31 namespace OpenTween
32 {
33     public class OTBaseFormTest
34     {
35         private class TestForm : OTBaseForm
36         {
37         }
38
39         public OTBaseFormTest()
40             => this.SetupSynchronizationContext();
41
42         protected void SetupSynchronizationContext()
43             => WindowsFormsSynchronizationContext.AutoInstall = false;
44
45         [Fact]
46         public async Task InvokeAsync_Test()
47         {
48             using var form = new TestForm();
49             await Task.Run(async () =>
50             {
51                 await form.InvokeAsync(() => form.Text = "hoge");
52             });
53
54             Assert.Equal("hoge", form.Text);
55         }
56
57         [Fact]
58         public async Task InvokeAsync_ReturnValueTest()
59         {
60             using var form = new TestForm();
61             form.Text = "hoge";
62
63             await Task.Run(async () =>
64             {
65                 var ret = await form.InvokeAsync(() => form.Text);
66                 Assert.Equal("hoge", ret);
67             });
68         }
69
70         [Fact]
71         public async Task InvokeAsync_TaskTest()
72         {
73             using var form = new TestForm();
74             await Task.Run(async () =>
75             {
76                 await form.InvokeAsync(async () =>
77                 {
78                     await Task.Delay(1);
79                     form.Text = "hoge";
80                 });
81             });
82
83             Assert.Equal("hoge", form.Text);
84         }
85
86         [Fact]
87         public async Task InvokeAsync_TaskWithValueTest()
88         {
89             using var form = new TestForm();
90             form.Text = "hoge";
91
92             await Task.Run(async () =>
93             {
94                 var ret = await form.InvokeAsync(async () =>
95                 {
96                     await Task.Delay(1);
97                     return form.Text;
98                 });
99
100                 Assert.Equal("hoge", ret);
101             });
102         }
103
104         [Fact]
105         public void ScaleChildControl_ListViewTest()
106         {
107             using var listview = new ListView { Width = 200, Height = 200 };
108             listview.Columns.AddRange(new[]
109             {
110                 new ColumnHeader { Width = 60 },
111                 new ColumnHeader { Width = 140 },
112             });
113
114             OTBaseForm.ScaleChildControl(listview, new SizeF(1.25f, 1.25f));
115
116             Assert.Equal(75, listview.Columns[0].Width);
117             Assert.Equal(175, listview.Columns[1].Width);
118         }
119
120         [Fact]
121         public void ScaleChildControl_VScrollBarTest()
122         {
123             using var scrollBar = new VScrollBar { Width = 20, Height = 200 };
124             OTBaseForm.ScaleChildControl(scrollBar, new SizeF(2.0f, 2.0f));
125
126             Assert.Equal(40, scrollBar.Width);
127         }
128
129         [WinFormsFact]
130         public void ScaleChildControl_ImageListTest()
131         {
132             using var imageList = new ImageList() { ImageSize = new(16, 16) };
133             OTBaseForm.ScaleChildControl(imageList, new SizeF(2.0f, 2.0f));
134
135             Assert.Equal(new(32, 32), imageList.ImageSize);
136         }
137
138         [Fact]
139         public void ScaleBy_SizeTest()
140         {
141             var factor = new SizeF(2.0f, 2.0f);
142             Assert.Equal(new(32, 32), OTBaseForm.ScaleBy(factor, new(16, 16)));
143         }
144
145         [Fact]
146         public void ScaleBy_IntegerTest()
147         {
148             var factor = 2.0f;
149             Assert.Equal(32, OTBaseForm.ScaleBy(factor, 16));
150         }
151     }
152 }