Skip to content

Commit 763f750

Browse files
various fixes
1 parent 5008a11 commit 763f750

15 files changed

+101
-104
lines changed

src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
<!-- We can't yet disable the namescope generation, ConstraintTypeConverter and ReferenceTypeConverter need to be ported to sourcegen
1616
<DefineConstants>$(DefineConstants);_MAUIXAML_SG_NAMESCOPE_DISABLE</DefineConstants>
1717
-->
18-
18+
<DefineConstants>$(DefineConstants);FIXME_BEFORE_PUBLIC_RELEASE</DefineConstants>
19+
1920
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
2021
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
2122
<EnablePreviewFeatures>True</EnablePreviewFeatures>

src/Controls/tests/Xaml.UnitTests/GlobalXmlns.xaml.cs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,24 @@ public partial class GlobalXmlns
1111
{
1212
public GlobalXmlns() => InitializeComponent();
1313

14-
[SetUp]
15-
public void Setup()
14+
[TestFixture]
15+
class Tests
1616
{
17-
Application.SetCurrentApplication(new MockApplication());
18-
DispatcherProvider.SetCurrent(new DispatcherProviderStub());
19-
}
17+
[SetUp]
18+
public void Setup()
19+
{
20+
Application.SetCurrentApplication(new MockApplication());
21+
DispatcherProvider.SetCurrent(new DispatcherProviderStub());
22+
}
2023

21-
[TearDown] public void TearDown() => AppInfo.SetCurrent(null);
24+
[TearDown] public void TearDown() => AppInfo.SetCurrent(null);
2225

23-
[Test]
24-
internal void WorksWithoutXDeclaration([Values] XamlInflator inflator)
25-
{
26-
var page = new GlobalXmlns(inflator);
27-
Assert.That(page.label, Is.Not.Null);
28-
Assert.That(page.label.Text, Is.EqualTo("No xmlns:x declaration, but x: usage anyway"));
26+
[Test]
27+
public void WorksWithoutXDeclaration([Values] XamlInflator inflator)
28+
{
29+
var page = new GlobalXmlns(inflator);
30+
Assert.That(page.label, Is.Not.Null);
31+
Assert.That(page.label.Text, Is.EqualTo("No xmlns:x declaration, but x: usage anyway"));
32+
}
2933
}
3034
}

src/Controls/tests/Xaml.UnitTests/GlobalXmlnsWithDataTemplate.xaml.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ public partial class GlobalXmlnsWithDataTemplate : ContentPage
66
{
77
public GlobalXmlnsWithDataTemplate() => InitializeComponent();
88

9-
[Test]
10-
internal void GlobalXmlnsWithDataTemplateTest([Values] XamlInflator inflator)
9+
[TestFixture]
10+
class Tests
1111
{
12-
var page = new GlobalXmlnsWithDataTemplate(inflator);
12+
[Test]
13+
public void GlobalXmlnsWithDataTemplateTest([Values] XamlInflator inflator)
14+
{
15+
var page = new GlobalXmlnsWithDataTemplate(inflator);
16+
}
1317
}
1418
}

src/Controls/tests/Xaml.UnitTests/GlobalXmlnsWithStyle.xaml.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,25 @@ public GlobalXmlnsWithStyle()
1111
InitializeComponent();
1212
}
1313

14-
[Test]
15-
internal void GlobalXmlnsWithStyleTest([Values] XamlInflator inflator)
14+
[TestFixture]
15+
class Tests
1616
{
17-
if (inflator == XamlInflator.SourceGen)
17+
[Test]
18+
public void GlobalXmlnsWithStyleTest([Values] XamlInflator inflator)
1819
{
19-
var compilation = MockSourceGenerator.CreateMauiCompilation();
20-
compilation = compilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(
21-
"""
20+
if (inflator == XamlInflator.SourceGen)
21+
{
22+
var compilation = MockSourceGenerator.CreateMauiCompilation();
23+
compilation = compilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(
24+
"""
2225
[assembly: global::Microsoft.Maui.Controls.Xaml.Internals.AllowImplicitXmlnsDeclaration]
2326
"""));
24-
compilation.RunMauiSourceGenerator(typeof(GlobalXmlnsWithStyle));
25-
}
26-
27-
var page = new GlobalXmlnsWithStyle(inflator);
28-
Assert.That(page.label0.TextColor, Is.EqualTo(Colors.Red));
29-
Assert.That(page.label0.BackgroundColor, Is.EqualTo(Colors.Blue));
27+
compilation.RunMauiSourceGenerator(typeof(GlobalXmlnsWithStyle));
28+
}
3029

30+
var page = new GlobalXmlnsWithStyle(inflator);
31+
Assert.That(page.label0.TextColor, Is.EqualTo(Colors.Red));
32+
Assert.That(page.label0.BackgroundColor, Is.EqualTo(Colors.Blue));
33+
}
3134
}
3235
}

src/Controls/tests/Xaml.UnitTests/GlobalXmlnsWithXStatic.xaml.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,19 @@ public partial class GlobalXmlnsWithXStatic : ContentPage
2828
{
2929
public GlobalXmlnsWithXStatic() => InitializeComponent();
3030

31-
[Test]
32-
internal void XStaticWithAggregatedXmlns([Values] XamlInflator inflator)
31+
[TestFixture]
32+
class Tests
3333
{
34-
if (inflator == XamlInflator.XamlC)
35-
MockCompiler.Compile(typeof(GlobalXmlnsWithXStatic));
36-
37-
var page = new GlobalXmlnsWithXStatic(inflator);
38-
Assert.That(page.label0.Text, Is.EqualTo("MConstant"));
34+
[Test]
35+
public void XStaticWithAggregatedXmlns([Values] XamlInflator inflator)
36+
{
37+
if (inflator == XamlInflator.XamlC)
38+
MockCompiler.Compile(typeof(GlobalXmlnsWithXStatic));
39+
40+
var page = new GlobalXmlnsWithXStatic(inflator);
41+
Assert.That(page.label0.Text, Is.EqualTo("MConstant"));
42+
}
3943
}
4044

41-
4245
}
4346
}

src/Controls/tests/Xaml.UnitTests/ImplicitResourceDictionaries.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ public partial class ImplicitResourceDictionaries : ContentPage
88
public ImplicitResourceDictionaries() => InitializeComponent();
99

1010
[TestFixture]
11-
public class Tests
11+
class Tests
1212
{
1313
[Test]
14-
internal void ImplicitRDonContentViews([Values] XamlInflator inflator)
14+
public void ImplicitRDonContentViews([Values] XamlInflator inflator)
1515
{
1616
var layout = new ImplicitResourceDictionaries(inflator);
1717
Assert.That(layout.label.TextColor, Is.EqualTo(Colors.Purple));

src/Controls/tests/Xaml.UnitTests/InflatorSwitch/XamlInflatorDefault.xaml

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/Controls/tests/Xaml.UnitTests/InflatorSwitch/XamlInflatorDefault.xaml.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/Controls/tests/Xaml.UnitTests/InflatorSwitch/XamlInflatorRuntime.rt.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace Microsoft.Maui.Controls.Xaml.UnitTests;
44
public partial class XamlInflatorRuntime : ContentPage
55
{
66
public XamlInflatorRuntime() => InitializeComponent();
7-
[Test] public void TestRuntimeInflator() => XamlInflatorRuntimeTestsHelpers.TestInflator(typeof(XamlInflatorRuntime), XamlInflator.Runtime);
7+
[Test] public void TestRuntimeInflator() => XamlInflatorRuntimeTestsHelpers.TestInflator(typeof(XamlInflatorRuntime), XamlInflator.Runtime, true);
88

99
[Test]
1010
public void TestInflation()

src/Controls/tests/Xaml.UnitTests/InflatorSwitch/XamlInflatorRuntimeTestsHelpers.cs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Microsoft.Maui.Controls.Xaml.UnitTests;
55

66
public 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

Comments
 (0)