@@ -17,19 +17,21 @@ public abstract class BaseWindowsRuntimeProjectionsTests : BaseTestFixture {
17
17
protected abstract string [ ] ManagedClassTypeNames { get ; }
18
18
protected abstract string [ ] CustomListTypeNames { get ; }
19
19
20
- [ Test ]
21
- public void CanReadMetadataType ( )
20
+ [ TestCase ( true ) ]
21
+ [ TestCase ( false ) ]
22
+ public void CanReadMetadataType ( bool readSdkAssembliesWithApplyWindowsRuntimeProjections )
22
23
{
23
24
if ( Platform . OnMono )
24
25
return ;
25
26
26
27
TestModule ( ModuleName , ( module ) => {
27
28
Assert . AreEqual ( ExpectedMetadataKind , module . MetadataKind ) ;
28
- } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( ) , applyWindowsRuntimeProjections : true ) ;
29
+ } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( readSdkAssembliesWithApplyWindowsRuntimeProjections ) , applyWindowsRuntimeProjections : true ) ;
29
30
}
30
31
31
- [ Test ]
32
- public void CanProjectParametersAndReturnTypes ( )
32
+ [ TestCase ( true ) ]
33
+ [ TestCase ( false ) ]
34
+ public void CanProjectParametersAndReturnTypes ( bool readSdkAssembliesWithApplyWindowsRuntimeProjections )
33
35
{
34
36
if ( Platform . OnMono )
35
37
return ;
@@ -48,11 +50,12 @@ public void CanProjectParametersAndReturnTypes ()
48
50
Assert . AreEqual ( listSetter . Parameters . Count , 1 ) ;
49
51
Assert . AreEqual ( listSetter . Parameters [ 0 ] . ParameterType . FullName , "System.Collections.Generic.IList`1<System.Int32>" ) ;
50
52
}
51
- } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( ) , applyWindowsRuntimeProjections : true ) ;
53
+ } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( readSdkAssembliesWithApplyWindowsRuntimeProjections ) , applyWindowsRuntimeProjections : true ) ;
52
54
}
53
55
54
- [ Test ]
55
- public void CanProjectInterfaces ( )
56
+ [ TestCase ( true ) ]
57
+ [ TestCase ( false ) ]
58
+ public void CanProjectInterfaces ( bool readSdkAssembliesWithApplyWindowsRuntimeProjections )
56
59
{
57
60
if ( Platform . OnMono )
58
61
return ;
@@ -64,16 +67,41 @@ public void CanProjectInterfaces ()
64
67
Assert . IsNotNull ( type . Interfaces . SingleOrDefault ( i => i . InterfaceType . FullName == "System.Collections.Generic.IList`1<System.Int32>" ) ) ;
65
68
Assert . IsNotNull ( type . Interfaces . SingleOrDefault ( i => i . InterfaceType . FullName == "System.Collections.Generic.IEnumerable`1<System.Int32>" ) ) ;
66
69
}
67
- } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( ) , applyWindowsRuntimeProjections : true ) ;
70
+ } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( readSdkAssembliesWithApplyWindowsRuntimeProjections ) , applyWindowsRuntimeProjections : true ) ;
71
+ }
72
+
73
+ /// <summary>
74
+ /// This test exists to verify a StackOverflowException that started happening with https://github.com/jbevain/cecil/pull/843
75
+ /// and was fixed by https://github.com/jbevain/cecil/pull/879
76
+ ///
77
+ /// The windows runtime sdk assemblies must be read with ApplyWindowsRuntimeProjections in order for the StackOverflowException to happen
78
+ /// </summary>
79
+ [ TestCase ( true ) ]
80
+ [ TestCase ( false ) ]
81
+ public void CanAvoidCircleAttributeReading ( bool readSdkAssembliesWithApplyWindowsRuntimeProjections )
82
+ {
83
+ if ( Platform . OnMono )
84
+ return ;
85
+
86
+ TestModule ( ModuleName , ( module ) => {
87
+
88
+ var windowsWinMd = module . AssemblyResolver . Resolve ( new AssemblyNameReference ( "Windows" , null ) ) ;
89
+
90
+ var problematicType = windowsWinMd . MainModule . GetType ( "Windows.Foundation.Metadata.ActivatableAttribute" ) ;
91
+
92
+ Assert . Greater ( problematicType . CustomAttributes . Count , 0 , "Expected one or more attributes" ) ;
93
+
94
+ } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( readSdkAssembliesWithApplyWindowsRuntimeProjections ) , applyWindowsRuntimeProjections : true ) ;
68
95
}
69
96
70
- [ Test ]
71
- public void CanStripType ( )
97
+ [ TestCase ( true ) ]
98
+ [ TestCase ( false ) ]
99
+ public void CanStripType ( bool readSdkAssembliesWithApplyWindowsRuntimeProjections )
72
100
{
73
101
if ( Platform . OnMono )
74
102
return ;
75
103
76
- var assemblyResolver = WindowsRuntimeAssemblyResolver . CreateInstance ( ) ;
104
+ var assemblyResolver = WindowsRuntimeAssemblyResolver . CreateInstance ( readSdkAssembliesWithApplyWindowsRuntimeProjections ) ;
77
105
78
106
TestModule ( ModuleName , ( originalModule ) => {
79
107
var types = CustomListTypeNames . Select ( typeName => originalModule . Types . Single ( t => t . Name == typeName ) ) . ToArray ( ) ;
@@ -107,8 +135,9 @@ public class ManagedWindowsRuntimeProjectionsTests : BaseWindowsRuntimeProjectio
107
135
108
136
protected override string [ ] CustomListTypeNames { get { return new [ ] { "CustomList" , "<WinRT>CustomList" } ; } }
109
137
110
- [ Test ]
111
- public void CanProjectClasses ( )
138
+ [ TestCase ( true ) ]
139
+ [ TestCase ( false ) ]
140
+ public void CanProjectClasses ( bool readSdkAssembliesWithApplyWindowsRuntimeProjections )
112
141
{
113
142
if ( Platform . OnMono )
114
143
return ;
@@ -129,11 +158,12 @@ public void CanProjectClasses ()
129
158
var winrtSomeOtherClassType = module . Types . Single ( t => t . Name == "<WinRT>SomeOtherClass" ) ;
130
159
Assert . AreEqual ( "SomeOtherClass" , winrtSomeOtherClassType . WindowsRuntimeProjection . Name ) ;
131
160
Assert . AreEqual ( TypeDefinitionTreatment . PrefixWindowsRuntimeName , winrtSomeOtherClassType . WindowsRuntimeProjection . Treatment ) ;
132
- } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( ) , applyWindowsRuntimeProjections : true ) ;
161
+ } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( readSdkAssembliesWithApplyWindowsRuntimeProjections ) , applyWindowsRuntimeProjections : true ) ;
133
162
}
134
163
135
- [ Test ]
136
- public void VerifyTypeReferenceToProjectedTypeInAttributeArgumentReferencesUnmangledTypeName ( )
164
+ [ TestCase ( true ) ]
165
+ [ TestCase ( false ) ]
166
+ public void VerifyTypeReferenceToProjectedTypeInAttributeArgumentReferencesUnmangledTypeName ( bool readSdkAssembliesWithApplyWindowsRuntimeProjections )
137
167
{
138
168
if ( Platform . OnMono )
139
169
return ;
@@ -147,7 +177,7 @@ public void VerifyTypeReferenceToProjectedTypeInAttributeArgumentReferencesUnman
147
177
var attributeArgument = ( TypeReference ) attribute . ConstructorArguments [ 0 ] . Value ;
148
178
149
179
Assert . AreEqual ( "ManagedWinmd.ClassWithAsyncMethod/<DoStuffAsync>d__0" , attributeArgument . FullName ) ;
150
- } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( ) , applyWindowsRuntimeProjections : true ) ;
180
+ } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( readSdkAssembliesWithApplyWindowsRuntimeProjections ) , applyWindowsRuntimeProjections : true ) ;
151
181
}
152
182
}
153
183
@@ -162,8 +192,9 @@ public class NativeWindowsRuntimeProjectionsTests : BaseWindowsRuntimeProjection
162
192
163
193
protected override string [ ] CustomListTypeNames { get { return new [ ] { "CustomList" } ; } }
164
194
165
- [ Test ]
166
- public void CanProjectAndRedirectInterfaces ( )
195
+ [ TestCase ( true ) ]
196
+ [ TestCase ( false ) ]
197
+ public void CanProjectAndRedirectInterfaces ( bool readSdkAssembliesWithApplyWindowsRuntimeProjections )
167
198
{
168
199
if ( Platform . OnMono )
169
200
return ;
@@ -213,11 +244,12 @@ public void CanProjectAndRedirectInterfaces ()
213
244
Assert . AreEqual ( 0 , customPropertySetClass . Interfaces [ 6 ] . CustomAttributes . Count ) ;
214
245
Assert . AreEqual ( "Windows.Foundation.Collections.IIterable`1<System.Collections.Generic.KeyValuePair`2<System.String,System.Object>>" , customPropertySetClass . Interfaces [ 6 ] . InterfaceType . FullName ) ;
215
246
216
- } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( ) , applyWindowsRuntimeProjections : true ) ;
247
+ } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( readSdkAssembliesWithApplyWindowsRuntimeProjections ) , applyWindowsRuntimeProjections : true ) ;
217
248
}
218
249
219
- [ Test ]
220
- public void CanProjectInterfaceMethods ( )
250
+ [ TestCase ( true ) ]
251
+ [ TestCase ( false ) ]
252
+ public void CanProjectInterfaceMethods ( bool readSdkAssembliesWithApplyWindowsRuntimeProjections )
221
253
{
222
254
if ( Platform . OnMono )
223
255
return ;
@@ -256,11 +288,12 @@ public void CanProjectInterfaceMethods ()
256
288
Assert . AreEqual ( customListClass . Methods [ 25 ] . FullName , "System.Boolean NativeWinmd.CustomList::Remove(System.Int32)" ) ;
257
289
Assert . AreEqual ( customListClass . Methods [ 26 ] . FullName , "System.Collections.Generic.IEnumerator`1<System.Int32> NativeWinmd.CustomList::GetEnumerator()" ) ;
258
290
Assert . AreEqual ( customListClass . Methods [ 27 ] . FullName , "System.Collections.IEnumerator NativeWinmd.CustomList::GetEnumerator()" ) ;
259
- } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( ) , applyWindowsRuntimeProjections : true ) ;
291
+ } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( readSdkAssembliesWithApplyWindowsRuntimeProjections ) , applyWindowsRuntimeProjections : true ) ;
260
292
}
261
293
262
- [ Test ]
263
- public void CanProjectMethodOverrides ( )
294
+ [ TestCase ( true ) ]
295
+ [ TestCase ( false ) ]
296
+ public void CanProjectMethodOverrides ( bool readSdkAssembliesWithApplyWindowsRuntimeProjections )
264
297
{
265
298
if ( Platform . OnMono )
266
299
return ;
@@ -299,7 +332,7 @@ public void CanProjectMethodOverrides ()
299
332
Assert . AreEqual ( customListClass . Methods [ 26 ] . Overrides [ 0 ] . FullName , "System.Collections.Generic.IEnumerator`1<T> System.Collections.Generic.IEnumerable`1<System.Int32>::GetEnumerator()" ) ;
300
333
Assert . AreEqual ( customListClass . Methods [ 27 ] . Overrides [ 0 ] . FullName , "System.Collections.IEnumerator System.Collections.IEnumerable::GetEnumerator()" ) ;
301
334
302
- } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( ) , applyWindowsRuntimeProjections : true ) ;
335
+ } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( readSdkAssembliesWithApplyWindowsRuntimeProjections ) , applyWindowsRuntimeProjections : true ) ;
303
336
}
304
337
}
305
338
}
0 commit comments