1
1
// Licensed to the .NET Foundation under one or more agreements.
2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
- #nullable disable
5
-
4
+ using System . ComponentModel ;
5
+ using System . Drawing ;
6
6
using static System . ComponentModel . TypeConverter ;
7
7
8
8
namespace System . Windows . Forms . Tests ;
@@ -25,4 +25,63 @@ public void ListViewItemStateImageIndexConverter_GetStandardValues_Null_Context_
25
25
26
26
Assert . Empty ( result ) ;
27
27
}
28
+
29
+ [ Fact ]
30
+ public void GetStandardValues_ContextWithoutListView_ReturnsEmpty ( )
31
+ {
32
+ object instance = new ( ) ;
33
+ ITypeDescriptorContext context = new TypeDescriptorContextStub ( instance ) ;
34
+ ListViewItemStateImageIndexConverter converter = new ( ) ;
35
+
36
+ StandardValuesCollection result = converter . GetStandardValues ( context ) ;
37
+
38
+ result . Cast < object > ( ) . Should ( ) . BeEmpty ( ) ;
39
+ }
40
+
41
+ [ Fact ]
42
+ public void GetStandardValues_WithListViewWithoutStateImageList_ReturnsEmpty ( )
43
+ {
44
+ using ListView listView = new ( ) ;
45
+ ListViewItem item = listView . Items . Add ( "test" ) ;
46
+
47
+ ITypeDescriptorContext context = new TypeDescriptorContextStub ( item ) ;
48
+ ListViewItemStateImageIndexConverter converter = new ( ) ;
49
+
50
+ StandardValuesCollection result = converter . GetStandardValues ( context ) ;
51
+
52
+ result . Cast < object > ( ) . Should ( ) . BeEmpty ( ) ;
53
+ }
54
+
55
+ [ WinFormsFact ]
56
+ public void GetStandardValues_WithStateImageList_ReturnsCorrectIndexes ( )
57
+ {
58
+ using ListView listView = new ( ) ;
59
+ using ImageList imageList = new ( ) ;
60
+ using Bitmap bmp1 = new ( 16 , 16 ) ;
61
+ using Bitmap bmp2 = new ( 16 , 16 ) ;
62
+ imageList . Images . Add ( bmp1 ) ;
63
+ imageList . Images . Add ( bmp2 ) ;
64
+ listView . StateImageList = imageList ;
65
+
66
+ ListViewItem item = listView . Items . Add ( "test" ) ;
67
+
68
+ ITypeDescriptorContext context = new TypeDescriptorContextStub ( item ) ;
69
+ ListViewItemStateImageIndexConverter converter = new ( ) ;
70
+
71
+ StandardValuesCollection result = converter . GetStandardValues ( context ) ;
72
+
73
+ result . Cast < object > ( ) . Should ( ) . Equal ( 0 , 1 ) ;
74
+ }
75
+
76
+ // Minimal stub for ITypeDescriptorContext
77
+ private sealed class TypeDescriptorContextStub : ITypeDescriptorContext
78
+ {
79
+ public TypeDescriptorContextStub ( object instance ) => Instance = instance ;
80
+ public object Instance { get ; }
81
+ public IContainer ? Container => null ;
82
+ public object ? GetService ( Type serviceType ) => null ;
83
+ public void OnComponentChanged ( ) { }
84
+ public bool OnComponentChanging ( ) => false ;
85
+ public PropertyDescriptor ? PropertyDescriptor => null ;
86
+ }
28
87
}
0 commit comments