blob: 3786ccb51cf4498bbb7bf805dbcc0f72d1cb94f7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
using System;
using System.Collections.Generic;
using Xamarin.Forms;
using Xamarin.Forms.Core.UnitTests;
using NUnit.Framework;
namespace Xamarin.Forms.Xaml.UnitTests
{
public partial class ConstraintExpression : ContentPage
{
public ConstraintExpression ()
{
InitializeComponent ();
}
public ConstraintExpression (bool useCompiledXaml)
{
//this stub will be replaced at compile time
}
[TestFixture]
public class Tests
{
[SetUp]
public void Setup ()
{
Device.PlatformServices = new MockPlatformServices ();
}
[TestCase (false)]
[TestCase (true)]
public void ConstantConstraint (bool useCompiledXaml)
{
var layout = new ConstraintExpression (useCompiledXaml);
var label = layout.constantConstraint;
var constraint = RelativeLayout.GetWidthConstraint (label);
Assert.NotNull (constraint);
Assert.AreEqual (42, constraint.Compute (null));
}
[TestCase (false)]
[TestCase (true)]
public void ConstraintRelativeToParent (bool useCompiledXaml)
{
var layout = new ConstraintExpression (useCompiledXaml);
layout.relativeLayout.Layout (new Rectangle (0, 0, 200, 200));
var label = layout.constraintRelativeToParent;
var constraint = RelativeLayout.GetWidthConstraint (label);
Assert.NotNull (constraint);
Assert.AreEqual (102, constraint.Compute (layout.relativeLayout));
}
[TestCase (false)]
[TestCase (true)]
public void ContraintRelativeToView (bool useCompiledXaml)
{
var layout = new ConstraintExpression (useCompiledXaml) {
IsPlatformEnabled = true
};
layout.relativeLayout.Layout (new Rectangle (0, 0, 200, 100));
layout.foo.Layout (new Rectangle (5, 5, 190, 25));
var label = layout.constraintRelativeToView;
var constraint = RelativeLayout.GetWidthConstraint (label);
Assert.NotNull (constraint);
Assert.AreEqual (97, constraint.Compute (layout.relativeLayout));
}
}
}
}
|