summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml.UnitTests
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-12-01 22:34:39 +0100
committerGitHub <noreply@github.com>2016-12-01 22:34:39 +0100
commite413e0cf331ae1512e2d8a6fcc89446c1cf2225c (patch)
tree5aad168ffd3e0679bb36b4a54f5465e501629411 /Xamarin.Forms.Xaml.UnitTests
parent00b652cd43902b4499706d1f9172041c20083ae8 (diff)
downloadxamarin-forms-e413e0cf331ae1512e2d8a6fcc89446c1cf2225c.tar.gz
xamarin-forms-e413e0cf331ae1512e2d8a6fcc89446c1cf2225c.tar.bz2
xamarin-forms-e413e0cf331ae1512e2d8a6fcc89446c1cf2225c.zip
[XamlC] use op_implicit where we should (#580)
* [XamlC] (passing) test for 48242 * [XamlC] (failing) test for 48242 * [XamlC] more op_implicit conversions * additional test * fix rebase
Diffstat (limited to 'Xamarin.Forms.Xaml.UnitTests')
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Issues/Unreported007.xaml11
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Issues/Unreported007.xaml.cs47
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/SetValue.xaml14
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/SetValue.xaml.cs64
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/XStatic.xaml5
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/XStatic.xaml.cs24
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj6
7 files changed, 169 insertions, 2 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported007.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported007.xaml
new file mode 100644
index 00000000..4132f908
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported007.xaml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
+ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
+ x:Class="Xamarin.Forms.Xaml.UnitTests.Unreported007">
+
+ <Label Text="Foo" x:Name="label">
+ <RelativeLayout.XConstraint>
+ <OnPlatform x:TypeArguments="Constraint" Android="{ConstraintExpression Type=Constant,Constant=6}" iOS="{ConstraintExpression Type=Constant,Constant=3}" />
+ </RelativeLayout.XConstraint>
+ </Label>
+</ContentPage>
diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported007.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported007.xaml.cs
new file mode 100644
index 00000000..279deed4
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported007.xaml.cs
@@ -0,0 +1,47 @@
+´╗┐using System;
+using System.Collections.Generic;
+using NUnit.Framework;
+using Xamarin.Forms;
+using Xamarin.Forms.Core.UnitTests;
+
+namespace Xamarin.Forms.Xaml.UnitTests
+{
+ public partial class Unreported007 : ContentPage
+ {
+ public Unreported007()
+ {
+ InitializeComponent();
+ }
+ public Unreported007(bool useCompiledXaml)
+ {
+ //this stub will be replaced at compile time
+ }
+
+ [TestFixture]
+ class Tests
+ {
+ [SetUp]
+ public void Setup()
+ {
+ Device.PlatformServices = new MockPlatformServices();
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ Device.PlatformServices = null;
+ }
+
+ [TestCase(true), TestCase(false)]
+ public void ConstraintsAreEvaluatedWithOnPlatform(bool useCompiledXaml)
+ {
+ if (useCompiledXaml)
+ MockCompiler.Compile(typeof(Unreported007));
+ Device.OS = TargetPlatform.iOS;
+ var page = new Unreported007(useCompiledXaml);
+ Assert.That(RelativeLayout.GetXConstraint(page.label), Is.TypeOf<Constraint>());
+ Assert.AreEqual(3, RelativeLayout.GetXConstraint(page.label).Compute(null));
+ }
+ }
+ }
+}
diff --git a/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml b/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml
index 4beec041..fd11bd5a 100644
--- a/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml
+++ b/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml
@@ -85,5 +85,17 @@
</ContentView>
<local:MockViewWithValues x:Name="mockView0" UShort="32" ADecimal="42" />
<local:ViewWithEnums x:Name="enums" IntEnum="Foo" ByteEnum="Bar" />
+ <local:MockViewWithValues x:Name="implicit0">
+ <local:MockViewWithValues.BPBar>
+ <local:SV_Foo Value="Bar"/>
+ </local:MockViewWithValues.BPBar>
+ </local:MockViewWithValues>
+ <!--<local:MockViewWithValues x:Name="implicit1" BPFoo="Foo" />-->
+ <local:MockViewWithValues x:Name="implicit2">
+ <local:MockViewWithValues.Bar>
+ <local:SV_Foo Value="Bar"/>
+ </local:MockViewWithValues.Bar>
+ </local:MockViewWithValues>
+ <!--<local:MockViewWithValues x:Name="implicit3" Foo="Foo" />-->
</StackLayout>
-</ContentPage> \ No newline at end of file
+</ContentPage>
diff --git a/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml.cs
index c6c362c2..0f632e30 100644
--- a/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/SetValue.xaml.cs
@@ -18,6 +18,38 @@ namespace Xamarin.Forms.Xaml.UnitTests
{
public UInt16 UShort { get; set; }
public decimal ADecimal { get; set; }
+ public SV_Foo Foo { get; set; }
+ public string Bar { get; set; }
+
+ public static readonly BindableProperty BPFooProperty =
+ BindableProperty.Create("BPFoo", typeof(SV_Foo), typeof(MockViewWithValues), default(SV_Foo));
+
+ public SV_Foo BPFoo {
+ get { throw new NotImplementedException(); }
+ set { throw new NotImplementedException(); }
+ }
+
+ public static readonly BindableProperty BPBarProperty =
+ BindableProperty.Create("BPBar", typeof(string), typeof(MockViewWithValues), default(string));
+
+ public string BPBar {
+ get { throw new NotImplementedException(); }
+ set { throw new NotImplementedException(); }
+ }
+ }
+
+ public class SV_Foo
+ {
+ public string Value { get; set; }
+ public static implicit operator SV_Foo(string value)
+ {
+ return new SV_Foo { Value = value };
+ }
+
+ public static implicit operator string(SV_Foo foo)
+ {
+ return foo.Value;
+ }
}
public enum IntEnum
@@ -276,6 +308,36 @@ namespace Xamarin.Forms.Xaml.UnitTests
Assert.AreEqual(IntEnum.Foo, page.enums.IntEnum);
Assert.AreEqual(ByteEnum.Bar, page.enums.ByteEnum);
}
+
+ public void SetValueWithImplicitOperatorOnSource(bool useCompiledXaml)
+ {
+ var page = new SetValue(useCompiledXaml);
+ Assert.AreEqual("Bar", page.implicit0.GetValue(MockViewWithValues.BPBarProperty));
+ }
+
+ //[TestCase(false)]
+ //[TestCase(true)]
+ //public void SetValueWithImplicitOperatorOnTarget(bool useCompiledXaml)
+ //{
+ // var page = new SetValue(useCompiledXaml);
+ // Assert.AreEqual("Foo", ((SV_Foo)page.implicit1.GetValue(MockViewWithValues.BPFooProperty)).Value);
+ //}
+
+ [TestCase(false)]
+ [TestCase(true)]
+ public void SetWithImplicitOperatorOnSource(bool useCompiledXaml)
+ {
+ var page = new SetValue(useCompiledXaml);
+ Assert.AreEqual("Bar", page.implicit2.Bar);
+ }
+
+ //[TestCase(false)]
+ //[TestCase(true)]
+ //public void SetWithImplicitOperatorOnTarget(bool useCompiledXaml)
+ //{
+ // var page = new SetValue(useCompiledXaml);
+ // Assert.AreEqual("Foo", page.implicit3.Foo.Value);
+ //}
}
}
-} \ No newline at end of file
+}
diff --git a/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml b/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml
index 32d2945e..cf68525b 100644
--- a/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml
+++ b/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml
@@ -3,6 +3,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests"
x:Class="Xamarin.Forms.Xaml.UnitTests.XStatic">
+ <ContentPage.ToolbarItems>
+ <ToolbarItem Icon="{x:Static local:MockxStatic.MockFieldRef}" />
+ </ContentPage.ToolbarItems>
<StackLayout>
<Label x:Name="staticproperty"
Text="{x:Static Member=local:MockxStatic.MockStaticProperty}" />
@@ -16,5 +19,7 @@
Text="{x:Static local:MockxStatic.MockField}"/>
<ScrollView x:Name="enuM"
Orientation="{x:Static ScrollOrientation.Both}"/>
+ <Label x:Name="field2"
+ Text="{x:Static local:MockxStatic.MockFieldRef}" />
</StackLayout>
</ContentPage> \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml.cs
index d8a466e9..19c62630 100644
--- a/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/XStatic.xaml.cs
@@ -3,11 +3,18 @@ using Xamarin.Forms.Core.UnitTests;
namespace Xamarin.Forms.Xaml.UnitTests
{
+
+ public class Icons
+ {
+ public const string CLOSE = "ic_close.png";
+ }
+
public class MockxStatic
{
public static string MockStaticProperty { get { return "Property"; } }
public const string MockConstant = "Constant";
public static string MockField = "Field";
+ public static string MockFieldRef = Icons.CLOSE;
public string InstanceProperty { get { return "InstanceProperty"; } }
public static readonly Color BackgroundColor = Color.Fuchsia;
}
@@ -102,6 +109,23 @@ namespace Xamarin.Forms.Xaml.UnitTests
var layout = new XStatic(useCompiledXaml);
Assert.AreEqual(ScrollOrientation.Both, layout.enuM.Orientation);
}
+
+ [TestCase(false)]
+ [TestCase(true)]
+ public void FieldRef(bool useCompiledXaml)
+ {
+ var layout = new XStatic(useCompiledXaml);
+ Assert.AreEqual("ic_close.png", layout.field2.Text);
+ }
+
+ [TestCase(false)]
+ [TestCase(true)]
+ // https://bugzilla.xamarin.com/show_bug.cgi?id=48242
+ public void xStaticAndImplicitOperators(bool useCompiledXaml)
+ {
+ var layout = new XStatic(useCompiledXaml);
+ Assert.AreEqual("ic_close.png", layout.ToolbarItems[0].Icon.File);
+ }
}
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
index 3708d1f1..7886649c 100644
--- a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
+++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
@@ -385,6 +385,9 @@
<Compile Include="Issues\Bz48554.xaml.cs">
<DependentUpon>Bz48554.xaml</DependentUpon>
</Compile>
+ <Compile Include="Issues\Unreported007.xaml.cs">
+ <DependentUpon>Unreported007.xaml</DependentUpon>
+ </Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" />
@@ -691,6 +694,9 @@
<EmbeddedResource Include="Issues\Bz48554.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
+ <EmbeddedResource Include="Issues\Unreported007.xaml">
+ <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+ </EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />