OSDN Git Service

TabClassにもStatusIdとIndexの相互変換機能を持たせた
[opentween/open-tween.git] / OpenTween.Tests / TabsDialogTest.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2012 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.Linq;
25 using System.Reflection;
26 using System.Text;
27 using System.Windows.Forms;
28 using Xunit;
29 using Xunit.Extensions;
30
31 namespace OpenTween
32 {
33     public class TabsDialogTest
34     {
35         private TabInformations tabinfo;
36
37         public TabsDialogTest()
38         {
39             this.tabinfo = Activator.CreateInstance(typeof(TabInformations), true) as TabInformations;
40
41             // タブを追加
42             this.tabinfo.AddTab("Recent", MyCommon.TabUsageType.Home, null);
43             this.tabinfo.AddTab("Reply", MyCommon.TabUsageType.Mentions, null);
44             this.tabinfo.AddTab("DM", MyCommon.TabUsageType.DirectMessage, null);
45             this.tabinfo.AddTab("Favorites", MyCommon.TabUsageType.Favorites, null);
46             this.tabinfo.AddTab("MyTab1", MyCommon.TabUsageType.UserDefined, null);
47
48             // 一応 TabInformation.GetInstance() でも取得できるようにする
49             var field = typeof(TabInformations).GetField("_instance",
50                 BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.SetField);
51             field.SetValue(null, this.tabinfo);
52         }
53
54         [Fact]
55         public void OKButtonEnabledTest()
56         {
57             using (var dialog = new TabsDialog(this.tabinfo))
58             {
59                 Assert.False(dialog.OK_Button.Enabled);
60
61                 dialog.TabList.SelectedIndex = 0;
62
63                 Assert.True(dialog.OK_Button.Enabled);
64
65                 dialog.TabList.SelectedIndex = -1;
66
67                 Assert.False(dialog.OK_Button.Enabled);
68             }
69         }
70
71         [Fact]
72         public void MultiSelectTest()
73         {
74             using (var dialog = new TabsDialog(this.tabinfo))
75             {
76                 // MultiSelect = false (default)
77                 var firstItem = dialog.TabList.Items[0] as TabsDialog.TabListItem;
78                 Assert.Null(firstItem.Tab); // 「(新規タブ)」
79                 Assert.Equal(SelectionMode.One, dialog.TabList.SelectionMode);
80
81                 dialog.MultiSelect = true;
82                 firstItem = dialog.TabList.Items[0] as TabsDialog.TabListItem;
83                 Assert.NotNull(firstItem.Tab);
84                 Assert.Equal(SelectionMode.MultiExtended, dialog.TabList.SelectionMode);
85
86                 dialog.MultiSelect = false;
87                 firstItem = dialog.TabList.Items[0] as TabsDialog.TabListItem;
88                 Assert.Null(firstItem.Tab);
89                 Assert.Equal(SelectionMode.One, dialog.TabList.SelectionMode);
90             }
91         }
92
93         [Fact]
94         public void DoubleClickTest()
95         {
96             using (var dialog = new TabsDialog(this.tabinfo))
97             {
98                 dialog.TabList.SelectedIndex = -1;
99                 TestUtils.FireEvent(dialog.TabList, "DoubleClick");
100
101                 Assert.Equal(DialogResult.None, dialog.DialogResult);
102                 Assert.False(dialog.IsDisposed);
103
104                 dialog.TabList.SelectedIndex = 1;
105                 TestUtils.FireEvent(dialog.TabList, "DoubleClick");
106
107                 Assert.Equal(DialogResult.OK, dialog.DialogResult);
108                 Assert.True(dialog.IsDisposed);
109             }
110         }
111
112         [Fact]
113         public void SelectableTabTest()
114         {
115             using (var dialog = new TabsDialog(this.tabinfo))
116             {
117                 dialog.MultiSelect = false;
118
119                 var item = dialog.TabList.Items[0] as TabsDialog.TabListItem;
120                 Assert.Null(item.Tab);
121
122                 item = dialog.TabList.Items[1] as TabsDialog.TabListItem;
123                 Assert.Equal(this.tabinfo.Tabs["Reply"], item.Tab);
124
125                 item = dialog.TabList.Items[2] as TabsDialog.TabListItem;
126                 Assert.Equal(this.tabinfo.Tabs["MyTab1"], item.Tab);
127             }
128         }
129
130         [Fact]
131         public void SelectedTabTest()
132         {
133             using (var dialog = new TabsDialog(this.tabinfo))
134             {
135                 dialog.MultiSelect = false;
136
137                 dialog.TabList.SelectedIndex = 0;
138                 Assert.Null(dialog.SelectedTab);
139
140                 dialog.TabList.SelectedIndex = 1;
141                 Assert.Equal(this.tabinfo.Tabs["Reply"], dialog.SelectedTab);
142             }
143         }
144
145         [Fact]
146         public void SelectedTabsTest()
147         {
148             using (var dialog = new TabsDialog(this.tabinfo))
149             {
150                 dialog.MultiSelect = true;
151
152                 dialog.TabList.SelectedIndices.Clear();
153                 var selectedTabs = dialog.SelectedTabs;
154                 Assert.Empty(selectedTabs);
155
156                 dialog.TabList.SelectedIndices.Add(0);
157                 selectedTabs = dialog.SelectedTabs;
158                 Assert.Equal(new[] { this.tabinfo.Tabs["Reply"] }, selectedTabs);
159
160                 dialog.TabList.SelectedIndices.Add(1);
161                 selectedTabs = dialog.SelectedTabs;
162                 Assert.Equal(new[] { this.tabinfo.Tabs["Reply"], this.tabinfo.Tabs["MyTab1"] }, selectedTabs);
163             }
164         }
165     }
166 }