@@ -5,7 +5,7 @@ namespace Microsoft.Maui.Controls.Xaml.UnitTests;
55
66public class XamlInflatorRuntimeTestsHelpers
77{
8- internal static void TestInflator ( Type type , XamlInflator inflator , bool generateinflatorswitch = false )
8+ internal static void TestInflator ( Type type , XamlInflator inflator , bool generateinflatorswitch )
99 {
1010 if ( ! generateinflatorswitch )
1111 Assert . IsNull ( type . GetMethod ( "InitializeComponentSourceGen" , BindingFlags . Instance | BindingFlags . NonPublic ) , $ "{ type . Name } should not have InitializeComponentSourceGen method") ;
@@ -14,11 +14,11 @@ internal static void TestInflator(Type type, XamlInflator inflator, bool generat
1414
1515 //check that there is an InitializeComponent method that takes an argument of type XamlInflator
1616 if ( generateinflatorswitch )
17- Assert . IsNotNull ( type . GetConstructor ( [ typeof ( XamlInflator ) ] ) , $ "{ type . Name } should have InitializeComponent method with XamlInflator argument") ;
17+ Assert . IsNotNull ( type . GetConstructor ( BindingFlags . Instance | BindingFlags . NonPublic | BindingFlags . Public , [ typeof ( XamlInflator ) ] ) , $ "{ type . Name } should have InitializeComponent method with XamlInflator argument") ;
1818
1919 Assert . IsNotNull ( type . GetMethod ( "InitializeComponent" , BindingFlags . Instance | BindingFlags . NonPublic ) , $ "{ type . Name } should have InitializeComponent method") ;
2020
21- var body = type . GetMethod ( "InitializeComponent " , BindingFlags . Instance | BindingFlags . NonPublic ) . GetMethodBody ( ) ;
21+ var body = type . GetMethod ( "InitializeComponentRuntime " , BindingFlags . Instance | BindingFlags . NonPublic ) . GetMethodBody ( ) ;
2222
2323 //quite bad heuristics. this should use Cecil, and check for known calls, like LoadFromXaml, etc
2424 var instructions = body . GetILAsByteArray ( ) ;
@@ -39,30 +39,34 @@ internal static void TestInflator(Type type, XamlInflator inflator, bool generat
3939
4040 if ( generateinflatorswitch )
4141 {
42- var runtime = type . GetMethod ( "InitializeComponentRuntime" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
43- Assert . IsNotNull ( runtime , $ "{ type . Name } should have InitializeComponentRuntime method") ;
42+ if ( ( inflator & XamlInflator . Runtime ) == XamlInflator . Runtime )
43+ {
44+ var runtime = type . GetMethod ( "InitializeComponentRuntime" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
45+ Assert . IsNotNull ( runtime , $ "{ type . Name } should have InitializeComponentRuntime method") ;
4446#if DEBUG
45- Assert . AreEqual ( 36 , runtime . GetMethodBody ( ) . GetILAsByteArray ( ) . Length , "Method body should be 36 bytes long" ) ;
47+ Assert . AreEqual ( 36 , runtime . GetMethodBody ( ) . GetILAsByteArray ( ) . Length , "Method body should be 36 bytes long" ) ;
4648#else
4749 Assert . AreEqual ( 35 , runtime . GetMethodBody ( ) . GetILAsByteArray ( ) . Length , "Method body should be 35 bytes long" ) ;
4850#endif
51+ }
4952
50- var xamlc = type . GetMethod ( "InitializeComponentXamlC" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
51- Assert . IsNotNull ( xamlc , $ "{ type . Name } should have InitializeComponentXamlC method") ;
52- Assert . AreEqual ( 190 , xamlc . GetMethodBody ( ) . GetILAsByteArray ( ) . Length , "Method body should be 190 bytes long" ) ;
53+ if ( ( inflator & XamlInflator . XamlC ) == XamlInflator . XamlC )
54+ {
55+ var xamlc = type . GetMethod ( "InitializeComponentXamlC" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
56+ Assert . IsNotNull ( xamlc , $ "{ type . Name } should have InitializeComponentXamlC method") ;
57+ Assert . AreEqual ( 190 , xamlc . GetMethodBody ( ) . GetILAsByteArray ( ) . Length , "Method body should be 190 bytes long" ) ;
58+ }
5359
54- var sourcegen = type . GetMethod ( "InitializeComponentSourceGen" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
55- Assert . IsNotNull ( sourcegen , $ "{ type . Name } should have InitializeComponentSourceGen method") ;
60+ if ( ( inflator & XamlInflator . SourceGen ) == XamlInflator . SourceGen )
61+ {
62+ var sourcegen = type . GetMethod ( "InitializeComponentSourceGen" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
63+ Assert . IsNotNull ( sourcegen , $ "{ type . Name } should have InitializeComponentSourceGen method") ;
5664#if DEBUG
57- Assert . AreEqual ( 267 , sourcegen . GetMethodBody ( ) . GetILAsByteArray ( ) . Length , "Method body should be 267 bytes long" ) ;
65+ Assert . AreEqual ( 267 , sourcegen . GetMethodBody ( ) . GetILAsByteArray ( ) . Length , "Method body should be 267 bytes long" ) ;
5866#else
59- Assert . AreEqual ( 254 , sourcegen . GetMethodBody ( ) . GetILAsByteArray ( ) . Length , "Method body should be 254 bytes long" ) ;
60- #endif
61- #if DEBUG
62- Assert . AreEqual ( 8 , instructions . Length , "Method body should be 8 bytes long" ) ;
63- #else
64- Assert . AreEqual ( 7 , instructions . Length , "Method body should be 7 bytes long" ) ;
67+ Assert . AreEqual ( 254 , sourcegen . GetMethodBody ( ) . GetILAsByteArray ( ) . Length , "Method body should be 254 bytes long" ) ;
6568#endif
69+ }
6670
6771 }
6872 }
0 commit comments