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;
27 using System.Threading.Tasks;
28 using System.Windows.Forms;
33 public class OTBaseFormTest
35 private class TestForm : OTBaseForm { }
37 public OTBaseFormTest()
39 this.SetupSynchronizationContext();
42 protected void SetupSynchronizationContext()
44 WindowsFormsSynchronizationContext.AutoInstall = false;
48 public async Task InvokeAsync_Test()
50 using (var form = new TestForm())
52 await Task.Run(async () =>
54 await form.InvokeAsync(() => { form.Text = "hoge"; });
57 Assert.Equal("hoge", form.Text);
62 public async Task InvokeAsync_ReturnValueTest()
64 using (var form = new TestForm())
68 await Task.Run(async () =>
70 var ret = await form.InvokeAsync(() => form.Text);
71 Assert.Equal("hoge", ret);
77 public async Task InvokeAsync_TaskTest()
79 using (var form = new TestForm())
81 await Task.Run(async () =>
83 await form.InvokeAsync(async () =>
90 Assert.Equal("hoge", form.Text);
95 public async Task InvokeAsync_TaskWithValueTest()
97 using (var form = new TestForm())
101 await Task.Run(async () =>
103 var ret = await form.InvokeAsync(async () =>
109 Assert.Equal("hoge", ret);
115 public void ScaleChildControl_ListViewTest()
117 using (var listview = new ListView { Width = 200, Height = 200 })
119 listview.Columns.AddRange(new[]
121 new ColumnHeader { Width = 60 },
122 new ColumnHeader { Width = 140 },
125 OTBaseForm.ScaleChildControl(listview, new SizeF(1.25f, 1.25f));
127 Assert.Equal(75, listview.Columns[0].Width);
128 Assert.Equal(175, listview.Columns[1].Width);
133 public void ScaleChildControl_VScrollBarTest()
135 using (var scrollBar = new VScrollBar { Width = 20, Height = 200 })
137 OTBaseForm.ScaleChildControl(scrollBar, new SizeF(2.0f, 2.0f));
139 Assert.Equal(40, scrollBar.Width);