Skip to content

Commit

Permalink
Merge pull request #296 from opentween/add-tweenmain-testcase
Browse files Browse the repository at this point in the history
TweenMain.RefreshTimelineメソッドに対するテストコードを追加
  • Loading branch information
upsilon authored Jan 13, 2024
2 parents d359f51 + f5c2a59 commit a632e4f
Show file tree
Hide file tree
Showing 7 changed files with 613 additions and 16 deletions.
108 changes: 105 additions & 3 deletions OpenTween.Tests/DetailsListViewTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
// Boston, MA 02110-1301, USA.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTween.OpenTweenCustomControl;
using Xunit;

Expand All @@ -36,5 +33,110 @@ public void Initialize_Test()
{
using var listView = new DetailsListView();
}

[WinFormsFact]
public void SelectionMark_Test()
{
using var listView = new DetailsListView();

listView.RetrieveVirtualItem += (s, e) => e.Item = new();
listView.VirtualMode = true;
listView.VirtualListSize = 10;
listView.CreateControl();

listView.SelectionMark = 3;
Assert.Equal(3, listView.SelectionMark);
}

[WinFormsFact]
public void SelectItems_EmptyTest()
{
using var listView = new DetailsListView();

listView.RetrieveVirtualItem += (s, e) => e.Item = new();
listView.VirtualMode = true;
listView.VirtualListSize = 10;
listView.CreateControl();

listView.SelectedIndices.Add(1);
Assert.Single(listView.SelectedIndices);

listView.SelectItems(Array.Empty<int>());
Assert.Empty(listView.SelectedIndices);
}

[WinFormsFact]
public void SelectItems_SingleTest()
{
using var listView = new DetailsListView();

listView.RetrieveVirtualItem += (s, e) => e.Item = new();
listView.VirtualMode = true;
listView.VirtualListSize = 10;
listView.CreateControl();

listView.SelectedIndices.Add(1);
Assert.Single(listView.SelectedIndices);

listView.SelectItems(new[] { 2 });
Assert.Equal(new[] { 2 }, listView.SelectedIndices.Cast<int>());
}

[WinFormsFact]
public void SelectItems_Multiple_ClearAndSelectTest()
{
using var listView = new DetailsListView();

listView.RetrieveVirtualItem += (s, e) => e.Item = new();
listView.VirtualMode = true;
listView.VirtualListSize = 10;
listView.CreateControl();

listView.SelectedIndices.Add(2);
listView.SelectedIndices.Add(3);
Assert.Equal(2, listView.SelectedIndices.Count);

// Clear して選択し直した方が早いパターン
listView.SelectItems(new[] { 5, 6 });
Assert.Equal(new[] { 5, 6 }, listView.SelectedIndices.Cast<int>());
}

[WinFormsFact]
public void SelectItems_Multiple_DeselectAndSelectTest()
{
using var listView = new DetailsListView();

listView.RetrieveVirtualItem += (s, e) => e.Item = new();
listView.VirtualMode = true;
listView.VirtualListSize = 10;
listView.CreateControl();

listView.SelectedIndices.Add(1);
listView.SelectedIndices.Add(2);
listView.SelectedIndices.Add(3);
Assert.Equal(3, listView.SelectedIndices.Count);

// 選択範囲の差分だけ更新した方が早いパターン
listView.SelectItems(new[] { 2, 3, 4 });
Assert.Equal(new[] { 2, 3, 4 }, listView.SelectedIndices.Cast<int>());
}

[WinFormsFact]
public void SelectItems_OutOfRangeTest()
{
using var listView = new DetailsListView();

listView.RetrieveVirtualItem += (s, e) => e.Item = new();
listView.VirtualMode = true;
listView.VirtualListSize = 10;
listView.CreateControl();

Assert.Throws<ArgumentOutOfRangeException>(
() => listView.SelectItems(new[] { -1 })
);
Assert.Throws<ArgumentOutOfRangeException>(
() => listView.SelectItems(new[] { 10 })
);
}
}
}
82 changes: 82 additions & 0 deletions OpenTween.Tests/Models/TabModelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,88 @@ public void OnFilterModified_DetachedTest()
Assert.False(tab.FilterModified);
}

[Fact]
public void IndexOf_SingleFoundTest()
{
var tab = new PublicSearchTabModel("search");

tab.AddPostQueue(new()
{
StatusId = new TwitterStatusId("100"),
CreatedAtForSorting = new(2023, 1, 1, 0, 0, 0),
TextFromApi = "aaa",
});
tab.SetSortMode(ComparerMode.Id, SortOrder.Ascending);
tab.AddSubmit();

Assert.Equal(0, tab.IndexOf(new TwitterStatusId("100")));
}

[Fact]
public void IndexOf_SingleNotFoundTest()
{
var tab = new PublicSearchTabModel("search");

tab.AddPostQueue(new()
{
StatusId = new TwitterStatusId("100"),
CreatedAtForSorting = new(2023, 1, 1, 0, 0, 0),
TextFromApi = "aaa",
});
tab.SetSortMode(ComparerMode.Id, SortOrder.Ascending);
tab.AddSubmit();

Assert.Equal(-1, tab.IndexOf(new TwitterStatusId("200")));
}

[Fact]
public void IndexOf_MultipleFoundTest()
{
var tab = new PublicSearchTabModel("search");

tab.AddPostQueue(new()
{
StatusId = new TwitterStatusId("100"),
CreatedAtForSorting = new(2023, 1, 1, 0, 0, 0),
TextFromApi = "aaa",
});
tab.AddPostQueue(new()
{
StatusId = new TwitterStatusId("200"),
CreatedAtForSorting = new(2023, 1, 1, 0, 0, 1),
TextFromApi = "bbb",
});
tab.SetSortMode(ComparerMode.Id, SortOrder.Ascending);
tab.AddSubmit();

var actual = tab.IndexOf(new[] { new TwitterStatusId("200"), new TwitterStatusId("100") });
Assert.Equal(new[] { 1, 0 }, actual);
}

[Fact]
public void IndexOf_MultiplePartiallyFoundTest()
{
var tab = new PublicSearchTabModel("search");

tab.AddPostQueue(new()
{
StatusId = new TwitterStatusId("100"),
CreatedAtForSorting = new(2023, 1, 1, 0, 0, 0),
TextFromApi = "aaa",
});
tab.AddPostQueue(new()
{
StatusId = new TwitterStatusId("200"),
CreatedAtForSorting = new(2023, 1, 1, 0, 0, 1),
TextFromApi = "bbb",
});
tab.SetSortMode(ComparerMode.Id, SortOrder.Ascending);
tab.AddSubmit();

var actual = tab.IndexOf(new[] { new TwitterStatusId("100"), new TwitterStatusId("999") });
Assert.Equal(new[] { 0, -1 }, actual);
}

[Fact]
public void SearchPostsAll_Test()
{
Expand Down
21 changes: 21 additions & 0 deletions OpenTween.Tests/Models/TwitterPostFactoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,27 @@ public void CreateFromDirectMessageEvent_SenderTest()
Assert.True(post.IsMe);
}

[Fact]
public void GetReceivedHashtags_Test()
{
var factory = new TwitterPostFactory(this.CreateTabinfo());
var status = this.CreateStatus();
status.FullText = "hoge #OpenTween";
status.Entities.Hashtags = new[]
{
new TwitterEntityHashtag
{
Indices = new[] { 5, 15 },
Text = "OpenTween",
},
};

_ = factory.CreateFromStatus(status, selfUserId: 20000L, followerIds: EmptyIdSet);

Assert.Equal(new[] { "#OpenTween" }, factory.GetReceivedHashtags());
Assert.Empty(factory.GetReceivedHashtags());
}

[Fact]
public void CreateFromStatus_MediaAltTest()
{
Expand Down
Loading

0 comments on commit a632e4f

Please sign in to comment.