1 // OpenTween - Client of Twitter
2 // Copyright (c) 2023 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.
24 using OpenTween.OpenTweenCustomControl;
29 public class DetailsListViewTest
32 public void Initialize_Test()
34 using var listView = new DetailsListView();
38 public void SelectionMark_Test()
40 using var listView = new DetailsListView();
42 listView.RetrieveVirtualItem += (s, e) => e.Item = new();
43 listView.VirtualMode = true;
44 listView.VirtualListSize = 10;
45 listView.CreateControl();
47 listView.SelectionMark = 3;
48 Assert.Equal(3, listView.SelectionMark);
52 public void SelectItems_EmptyTest()
54 using var listView = new DetailsListView();
56 listView.RetrieveVirtualItem += (s, e) => e.Item = new();
57 listView.VirtualMode = true;
58 listView.VirtualListSize = 10;
59 listView.CreateControl();
61 listView.SelectedIndices.Add(1);
62 Assert.Single(listView.SelectedIndices);
64 listView.SelectItems(Array.Empty<int>());
65 Assert.Empty(listView.SelectedIndices);
69 public void SelectItems_SingleTest()
71 using var listView = new DetailsListView();
73 listView.RetrieveVirtualItem += (s, e) => e.Item = new();
74 listView.VirtualMode = true;
75 listView.VirtualListSize = 10;
76 listView.CreateControl();
78 listView.SelectedIndices.Add(1);
79 Assert.Single(listView.SelectedIndices);
81 listView.SelectItems(new[] { 2 });
82 Assert.Equal(new[] { 2 }, listView.SelectedIndices.Cast<int>());
86 public void SelectItems_Multiple_ClearAndSelectTest()
88 using var listView = new DetailsListView();
90 listView.RetrieveVirtualItem += (s, e) => e.Item = new();
91 listView.VirtualMode = true;
92 listView.VirtualListSize = 10;
93 listView.CreateControl();
95 listView.SelectedIndices.Add(2);
96 listView.SelectedIndices.Add(3);
97 Assert.Equal(2, listView.SelectedIndices.Count);
99 // Clear して選択し直した方が早いパターン
100 listView.SelectItems(new[] { 5, 6 });
101 Assert.Equal(new[] { 5, 6 }, listView.SelectedIndices.Cast<int>());
105 public void SelectItems_Multiple_DeselectAndSelectTest()
107 using var listView = new DetailsListView();
109 listView.RetrieveVirtualItem += (s, e) => e.Item = new();
110 listView.VirtualMode = true;
111 listView.VirtualListSize = 10;
112 listView.CreateControl();
114 listView.SelectedIndices.Add(1);
115 listView.SelectedIndices.Add(2);
116 listView.SelectedIndices.Add(3);
117 Assert.Equal(3, listView.SelectedIndices.Count);
119 // 選択範囲の差分だけ更新した方が早いパターン
120 listView.SelectItems(new[] { 2, 3, 4 });
121 Assert.Equal(new[] { 2, 3, 4 }, listView.SelectedIndices.Cast<int>());
125 public void SelectItems_OutOfRangeTest()
127 using var listView = new DetailsListView();
129 listView.RetrieveVirtualItem += (s, e) => e.Item = new();
130 listView.VirtualMode = true;
131 listView.VirtualListSize = 10;
132 listView.CreateControl();
134 Assert.Throws<ArgumentOutOfRangeException>(
135 () => listView.SelectItems(new[] { -1 })
137 Assert.Throws<ArgumentOutOfRangeException>(
138 () => listView.SelectItems(new[] { 10 })