1 // OpenTween - Client of Twitter
2 // Copyright (c) 2012 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;
25 using System.Reflection;
27 using System.Windows.Forms;
29 using Xunit.Extensions;
33 public class TabsDialogTest
35 private TabInformations tabinfo;
37 public TabsDialogTest()
39 this.tabinfo = Activator.CreateInstance(typeof(TabInformations), true) as TabInformations;
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);
48 // 一応 TabInformation.GetInstance() でも取得できるようにする
49 var field = typeof(TabInformations).GetField("_instance",
50 BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.SetField);
51 field.SetValue(null, this.tabinfo);
55 public void OKButtonEnabledTest()
57 using (var dialog = new TabsDialog(this.tabinfo))
59 Assert.False(dialog.OK_Button.Enabled);
61 dialog.TabList.SelectedIndex = 0;
63 Assert.True(dialog.OK_Button.Enabled);
65 dialog.TabList.SelectedIndex = -1;
67 Assert.False(dialog.OK_Button.Enabled);
72 public void MultiSelectTest()
74 using (var dialog = new TabsDialog(this.tabinfo))
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);
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);
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);
94 public void DoubleClickTest()
96 using (var dialog = new TabsDialog(this.tabinfo))
98 dialog.TabList.SelectedIndex = -1;
99 TestUtils.FireEvent(dialog.TabList, "DoubleClick");
101 Assert.Equal(DialogResult.None, dialog.DialogResult);
102 Assert.False(dialog.IsDisposed);
104 dialog.TabList.SelectedIndex = 1;
105 TestUtils.FireEvent(dialog.TabList, "DoubleClick");
107 Assert.Equal(DialogResult.OK, dialog.DialogResult);
108 Assert.True(dialog.IsDisposed);
113 public void SelectableTabTest()
115 using (var dialog = new TabsDialog(this.tabinfo))
117 dialog.MultiSelect = false;
119 var item = dialog.TabList.Items[0] as TabsDialog.TabListItem;
120 Assert.Null(item.Tab);
122 item = dialog.TabList.Items[1] as TabsDialog.TabListItem;
123 Assert.Equal(this.tabinfo.Tabs["Reply"], item.Tab);
125 item = dialog.TabList.Items[2] as TabsDialog.TabListItem;
126 Assert.Equal(this.tabinfo.Tabs["MyTab1"], item.Tab);
131 public void SelectedTabTest()
133 using (var dialog = new TabsDialog(this.tabinfo))
135 dialog.MultiSelect = false;
137 dialog.TabList.SelectedIndex = 0;
138 Assert.Null(dialog.SelectedTab);
140 dialog.TabList.SelectedIndex = 1;
141 Assert.Equal(this.tabinfo.Tabs["Reply"], dialog.SelectedTab);
146 public void SelectedTabsTest()
148 using (var dialog = new TabsDialog(this.tabinfo))
150 dialog.MultiSelect = true;
152 dialog.TabList.SelectedIndices.Clear();
153 var selectedTabs = dialog.SelectedTabs;
154 Assert.Empty(selectedTabs);
156 dialog.TabList.SelectedIndices.Add(0);
157 selectedTabs = dialog.SelectedTabs;
158 Assert.Equal(new[] { this.tabinfo.Tabs["Reply"] }, selectedTabs);
160 dialog.TabList.SelectedIndices.Add(1);
161 selectedTabs = dialog.SelectedTabs;
162 Assert.Equal(new[] { this.tabinfo.Tabs["Reply"], this.tabinfo.Tabs["MyTab1"] }, selectedTabs);