|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +namespace System.Windows.Forms.Tests; |
| 5 | + |
| 6 | +public class ListView_IconComparerTests |
| 7 | +{ |
| 8 | + [WinFormsTheory] |
| 9 | + [InlineData(SortOrder.Ascending)] |
| 10 | + [InlineData(SortOrder.Descending)] |
| 11 | + [InlineData(SortOrder.None)] |
| 12 | + public void Constructor_SetsSortOrder_Correctly(SortOrder order) |
| 13 | + { |
| 14 | + ListView.IconComparer comparer = new(order); |
| 15 | + |
| 16 | + ((SortOrder)comparer.TestAccessor().Dynamic._sortOrder).Should().Be(order); |
| 17 | + } |
| 18 | + |
| 19 | + [WinFormsTheory] |
| 20 | + [InlineData(SortOrder.Ascending, SortOrder.Descending)] |
| 21 | + [InlineData(SortOrder.Descending, SortOrder.Ascending)] |
| 22 | + [InlineData(SortOrder.None, SortOrder.Ascending)] |
| 23 | + public void SortOrder_Setter_UpdatesSortOrder(SortOrder initialOrder, SortOrder updatedOrder) |
| 24 | + { |
| 25 | + ListView.IconComparer comparer = new(initialOrder) |
| 26 | + { |
| 27 | + SortOrder = updatedOrder |
| 28 | + }; |
| 29 | + |
| 30 | + ((SortOrder)comparer.TestAccessor().Dynamic._sortOrder).Should().Be(updatedOrder); |
| 31 | + } |
| 32 | + |
| 33 | + [WinFormsTheory] |
| 34 | + [InlineData(SortOrder.Ascending, "A", "B", -1)] |
| 35 | + [InlineData(SortOrder.Ascending, "B", "A", 1)] |
| 36 | + [InlineData(SortOrder.Ascending, "A", "A", 0)] |
| 37 | + [InlineData(SortOrder.Descending, "A", "B", 1)] |
| 38 | + [InlineData(SortOrder.Descending, "B", "A", -1)] |
| 39 | + [InlineData(SortOrder.Descending, "A", "A", 0)] |
| 40 | + public void Compare_ComparesListViewItems_ByText_AndSortOrder(SortOrder order, string text1, string text2, int expectedSign) |
| 41 | + { |
| 42 | + ListView.IconComparer comparer = new(order); |
| 43 | + ListViewItem item1 = new(text1); |
| 44 | + ListViewItem item2 = new(text2); |
| 45 | + int result = comparer.Compare(item1, item2); |
| 46 | + |
| 47 | + Math.Sign(result).Should().Be(expectedSign); |
| 48 | + } |
| 49 | + |
| 50 | + [WinFormsFact] |
| 51 | + public void Compare_NullItems_ReturnsExpected() |
| 52 | + { |
| 53 | + ListView.IconComparer comparer = new(SortOrder.Ascending); |
| 54 | + ListViewItem item = new("A"); |
| 55 | + |
| 56 | + comparer.Compare(null, null).Should().Be(0); |
| 57 | + comparer.Compare(null, item).Should().BeLessThan(0); |
| 58 | + comparer.Compare(item, null).Should().BeGreaterThan(0); |
| 59 | + } |
| 60 | +} |
0 commit comments