@@ -17,19 +17,21 @@ public abstract class BaseWindowsRuntimeProjectionsTests : BaseTestFixture {
1717 protected abstract string [ ] ManagedClassTypeNames { get ; }
1818 protected abstract string [ ] CustomListTypeNames { get ; }
1919
20- [ Test ]
21- public void CanReadMetadataType ( )
20+ [ TestCase ( true ) ]
21+ [ TestCase ( false ) ]
22+ public void CanReadMetadataType ( bool readSdkAssembliesWithApplyWindowsRuntimeProjections )
2223 {
2324 if ( Platform . OnMono )
2425 return ;
2526
2627 TestModule ( ModuleName , ( module ) => {
2728 Assert . AreEqual ( ExpectedMetadataKind , module . MetadataKind ) ;
28- } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( ) , applyWindowsRuntimeProjections : true ) ;
29+ } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( readSdkAssembliesWithApplyWindowsRuntimeProjections ) , applyWindowsRuntimeProjections : true ) ;
2930 }
3031
31- [ Test ]
32- public void CanProjectParametersAndReturnTypes ( )
32+ [ TestCase ( true ) ]
33+ [ TestCase ( false ) ]
34+ public void CanProjectParametersAndReturnTypes ( bool readSdkAssembliesWithApplyWindowsRuntimeProjections )
3335 {
3436 if ( Platform . OnMono )
3537 return ;
@@ -48,11 +50,12 @@ public void CanProjectParametersAndReturnTypes ()
4850 Assert . AreEqual ( listSetter . Parameters . Count , 1 ) ;
4951 Assert . AreEqual ( listSetter . Parameters [ 0 ] . ParameterType . FullName , "System.Collections.Generic.IList`1<System.Int32>" ) ;
5052 }
51- } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( ) , applyWindowsRuntimeProjections : true ) ;
53+ } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( readSdkAssembliesWithApplyWindowsRuntimeProjections ) , applyWindowsRuntimeProjections : true ) ;
5254 }
5355
54- [ Test ]
55- public void CanProjectInterfaces ( )
56+ [ TestCase ( true ) ]
57+ [ TestCase ( false ) ]
58+ public void CanProjectInterfaces ( bool readSdkAssembliesWithApplyWindowsRuntimeProjections )
5659 {
5760 if ( Platform . OnMono )
5861 return ;
@@ -64,16 +67,41 @@ public void CanProjectInterfaces ()
6467 Assert . IsNotNull ( type . Interfaces . SingleOrDefault ( i => i . InterfaceType . FullName == "System.Collections.Generic.IList`1<System.Int32>" ) ) ;
6568 Assert . IsNotNull ( type . Interfaces . SingleOrDefault ( i => i . InterfaceType . FullName == "System.Collections.Generic.IEnumerable`1<System.Int32>" ) ) ;
6669 }
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 ) ;
6895 }
6996
70- [ Test ]
71- public void CanStripType ( )
97+ [ TestCase ( true ) ]
98+ [ TestCase ( false ) ]
99+ public void CanStripType ( bool readSdkAssembliesWithApplyWindowsRuntimeProjections )
72100 {
73101 if ( Platform . OnMono )
74102 return ;
75103
76- var assemblyResolver = WindowsRuntimeAssemblyResolver . CreateInstance ( ) ;
104+ var assemblyResolver = WindowsRuntimeAssemblyResolver . CreateInstance ( readSdkAssembliesWithApplyWindowsRuntimeProjections ) ;
77105
78106 TestModule ( ModuleName , ( originalModule ) => {
79107 var types = CustomListTypeNames . Select ( typeName => originalModule . Types . Single ( t => t . Name == typeName ) ) . ToArray ( ) ;
@@ -107,8 +135,9 @@ public class ManagedWindowsRuntimeProjectionsTests : BaseWindowsRuntimeProjectio
107135
108136 protected override string [ ] CustomListTypeNames { get { return new [ ] { "CustomList" , "<WinRT>CustomList" } ; } }
109137
110- [ Test ]
111- public void CanProjectClasses ( )
138+ [ TestCase ( true ) ]
139+ [ TestCase ( false ) ]
140+ public void CanProjectClasses ( bool readSdkAssembliesWithApplyWindowsRuntimeProjections )
112141 {
113142 if ( Platform . OnMono )
114143 return ;
@@ -129,11 +158,12 @@ public void CanProjectClasses ()
129158 var winrtSomeOtherClassType = module . Types . Single ( t => t . Name == "<WinRT>SomeOtherClass" ) ;
130159 Assert . AreEqual ( "SomeOtherClass" , winrtSomeOtherClassType . WindowsRuntimeProjection . Name ) ;
131160 Assert . AreEqual ( TypeDefinitionTreatment . PrefixWindowsRuntimeName , winrtSomeOtherClassType . WindowsRuntimeProjection . Treatment ) ;
132- } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( ) , applyWindowsRuntimeProjections : true ) ;
161+ } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( readSdkAssembliesWithApplyWindowsRuntimeProjections ) , applyWindowsRuntimeProjections : true ) ;
133162 }
134163
135- [ Test ]
136- public void VerifyTypeReferenceToProjectedTypeInAttributeArgumentReferencesUnmangledTypeName ( )
164+ [ TestCase ( true ) ]
165+ [ TestCase ( false ) ]
166+ public void VerifyTypeReferenceToProjectedTypeInAttributeArgumentReferencesUnmangledTypeName ( bool readSdkAssembliesWithApplyWindowsRuntimeProjections )
137167 {
138168 if ( Platform . OnMono )
139169 return ;
@@ -147,7 +177,7 @@ public void VerifyTypeReferenceToProjectedTypeInAttributeArgumentReferencesUnman
147177 var attributeArgument = ( TypeReference ) attribute . ConstructorArguments [ 0 ] . Value ;
148178
149179 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 ) ;
151181 }
152182 }
153183
@@ -162,8 +192,9 @@ public class NativeWindowsRuntimeProjectionsTests : BaseWindowsRuntimeProjection
162192
163193 protected override string [ ] CustomListTypeNames { get { return new [ ] { "CustomList" } ; } }
164194
165- [ Test ]
166- public void CanProjectAndRedirectInterfaces ( )
195+ [ TestCase ( true ) ]
196+ [ TestCase ( false ) ]
197+ public void CanProjectAndRedirectInterfaces ( bool readSdkAssembliesWithApplyWindowsRuntimeProjections )
167198 {
168199 if ( Platform . OnMono )
169200 return ;
@@ -213,11 +244,12 @@ public void CanProjectAndRedirectInterfaces ()
213244 Assert . AreEqual ( 0 , customPropertySetClass . Interfaces [ 6 ] . CustomAttributes . Count ) ;
214245 Assert . AreEqual ( "Windows.Foundation.Collections.IIterable`1<System.Collections.Generic.KeyValuePair`2<System.String,System.Object>>" , customPropertySetClass . Interfaces [ 6 ] . InterfaceType . FullName ) ;
215246
216- } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( ) , applyWindowsRuntimeProjections : true ) ;
247+ } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( readSdkAssembliesWithApplyWindowsRuntimeProjections ) , applyWindowsRuntimeProjections : true ) ;
217248 }
218249
219- [ Test ]
220- public void CanProjectInterfaceMethods ( )
250+ [ TestCase ( true ) ]
251+ [ TestCase ( false ) ]
252+ public void CanProjectInterfaceMethods ( bool readSdkAssembliesWithApplyWindowsRuntimeProjections )
221253 {
222254 if ( Platform . OnMono )
223255 return ;
@@ -256,11 +288,12 @@ public void CanProjectInterfaceMethods ()
256288 Assert . AreEqual ( customListClass . Methods [ 25 ] . FullName , "System.Boolean NativeWinmd.CustomList::Remove(System.Int32)" ) ;
257289 Assert . AreEqual ( customListClass . Methods [ 26 ] . FullName , "System.Collections.Generic.IEnumerator`1<System.Int32> NativeWinmd.CustomList::GetEnumerator()" ) ;
258290 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 ) ;
260292 }
261293
262- [ Test ]
263- public void CanProjectMethodOverrides ( )
294+ [ TestCase ( true ) ]
295+ [ TestCase ( false ) ]
296+ public void CanProjectMethodOverrides ( bool readSdkAssembliesWithApplyWindowsRuntimeProjections )
264297 {
265298 if ( Platform . OnMono )
266299 return ;
@@ -299,7 +332,7 @@ public void CanProjectMethodOverrides ()
299332 Assert . AreEqual ( customListClass . Methods [ 26 ] . Overrides [ 0 ] . FullName , "System.Collections.Generic.IEnumerator`1<T> System.Collections.Generic.IEnumerable`1<System.Int32>::GetEnumerator()" ) ;
300333 Assert . AreEqual ( customListClass . Methods [ 27 ] . Overrides [ 0 ] . FullName , "System.Collections.IEnumerator System.Collections.IEnumerable::GetEnumerator()" ) ;
301334
302- } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( ) , applyWindowsRuntimeProjections : true ) ;
335+ } , verify : false , assemblyResolver : WindowsRuntimeAssemblyResolver . CreateInstance ( readSdkAssembliesWithApplyWindowsRuntimeProjections ) , applyWindowsRuntimeProjections : true ) ;
303336 }
304337 }
305338}
0 commit comments