Beispiel #1
0
        public void RunWidthLayout()
        {
            MockApplication app = MockApplication.Setup <BasicLayoutTest_GathersDirtyData>();

            BasicLayoutTest_GathersDirtyData root = app.RootElement as BasicLayoutTest_GathersDirtyData;

            app.Update();

            UIElement one   = root[0];
            UIElement two   = root[1];
            UIElement three = root[2];

            Assert.AreEqual(3, root.layoutBox.childCount);
            Assert.AreEqual(100, one.layoutBox.finalWidth);
            Assert.AreEqual(100, two.layoutBox.finalWidth);
            Assert.AreEqual(100, three.layoutBox.finalWidth);

            Assert.AreEqual(0, one.layoutResult.localPosition.x);
            Assert.AreEqual(100, two.layoutResult.localPosition.x);
            Assert.AreEqual(200, three.layoutResult.localPosition.x);

            root.FindById("one").SetEnabled(false);

            app.Update();

            Assert.AreEqual(2, root.layoutBox.childCount);
            Assert.AreEqual(100, two.layoutBox.finalWidth);
            Assert.AreEqual(100, three.layoutBox.finalWidth);

            Assert.AreEqual(0, two.layoutResult.localPosition.x);
            Assert.AreEqual(100, three.layoutResult.localPosition.x);
        }
Beispiel #2
0
        public void HandleEnableDisableElementWithContentAncestor()
        {
            MockApplication app = MockApplication.Setup <BasicLayoutTest_ContentAncestor>();
            BasicLayoutTest_ContentAncestor root = app.RootElement as BasicLayoutTest_ContentAncestor;

            app.Update();

            UIElement toggle  = root["disable-me"];
            UIElement wrapper = root[0];

            Assert.AreEqual(200, root.layoutBox.finalWidth);
            Assert.AreEqual(200, wrapper.layoutBox.finalWidth);
            Assert.AreEqual(100, toggle.layoutBox.finalWidth);

            toggle.SetEnabled(false);

            app.Update();

            Assert.AreEqual(100, root.layoutBox.finalWidth);
            Assert.AreEqual(100, wrapper.layoutBox.finalWidth);

            toggle.SetEnabled(true);

            app.Update();

            Assert.AreEqual(200, root.layoutBox.finalWidth);
            Assert.AreEqual(200, wrapper.layoutBox.finalWidth);
            Assert.AreEqual(100, toggle.layoutBox.finalWidth);
        }
Beispiel #3
0
        public void DragEnter_FiresForReEnteringElement()
        {
            MockApplication testView = MockApplication.Setup <DragHandlerTestThing>();

            testView.Update();
            testView.SetViewportRect(new Rect(0, 0, 1000, 1000));
            DragHandlerTestThing root = (DragHandlerTestThing)testView.RootElement;

            Assert.AreEqual(0, root.dragList.Count);
            root.ignoreExit = true;

            testView.InputSystem.MouseDown(new Vector2(10, 10));
            testView.Update();

            testView.InputSystem.MouseDragMove(new Vector2(30, 30));
            testView.Update();

            testView.InputSystem.MouseDragMove(new Vector2(130, 30));
            testView.Update();

            testView.InputSystem.MouseDragMove(new Vector2(30, 30));
            testView.Update();

            Assert.AreEqual(3, root.dragList.Count);
            Assert.AreEqual(new[] { "enter:child0", "enter:child1", "enter:child0" }, root.dragList.ToArray());
        }
Beispiel #4
0
        public void Align()
        {
            MockApplication  mockView = MockApplication.Setup <GridLayout_Align>();
            GridLayout_Align root     = (GridLayout_Align)mockView.RootElement;

            mockView.Update();

            Assert.AreEqual(new Vector2(0, 0), root[0].layoutResult.alignedPosition);
            Assert.AreEqual(new Vector2(100, 0), root[1].layoutResult.alignedPosition);
            Assert.AreEqual(new Vector2(200, 0), root[2].layoutResult.alignedPosition);

            root.style.SetAlignItemsHorizontal(0.5f, StyleState.Normal);
            root.style.SetAlignItemsVertical(0.5f, StyleState.Normal);

            mockView.Update();

            Assert.AreEqual(new Vector2(25, 25), root[0].layoutResult.alignedPosition);
            Assert.AreEqual(new Vector2(125, 25), root[1].layoutResult.alignedPosition);
            Assert.AreEqual(new Vector2(225, 25), root[2].layoutResult.alignedPosition);

            root.style.SetAlignItemsHorizontal(1f, StyleState.Normal);
            root.style.SetAlignItemsVertical(1f, StyleState.Normal);

            mockView.Update();

            Assert.AreEqual(new Vector2(50, 50), root[0].layoutResult.alignedPosition);
            Assert.AreEqual(new Vector2(150, 50), root[1].layoutResult.alignedPosition);
            Assert.AreEqual(new Vector2(250, 50), root[2].layoutResult.alignedPosition);
        }
Beispiel #5
0
    public void SizeProperties_OverrideBaseStyleInState()
    {
        Action <string, string, string> TestBody = (setFnName, propName, defaultName) => {
            MockApplication view = MockApplication.Setup <StyleSetTestThing>();

            StyleSetTestThing root = (StyleSetTestThing)view.RootElement;

            UIStyle baseStyle = new UIStyle();
            SetStyleValue(baseStyle, propName, new UIMeasurement(500));

            CallMethod(root.style, setFnName, new UIMeasurement(1500), StyleState.Hover);
            UIStyleGroup group = new UIStyleGroup()
            {
                name   = "Name",
                normal = new UIStyleRunCommand()
                {
                    style = baseStyle
                }
            };
            UIStyleGroupContainer container = new UIStyleGroupContainer(0, "Name", StyleType.Shared, new[] { group });
            root.style.AddStyleGroupContainer(container);
            Assert.AreEqual(new UIMeasurement(500), ComputedValue <UIMeasurement>(root, propName));

            root.style.EnterState(StyleState.Hover);
            Assert.AreEqual(new UIMeasurement(1500), ComputedValue <UIMeasurement>(root, propName));
        };

        RunSizeTests(TestBody);
    }
Beispiel #6
0
        public void CreateAnnotationInvalidParameter()
        {
            CompileException exception = Assert.Throws <CompileException>(() => { MockApplication.Setup <DragTestThing_CreateAnnotationInvalidParameter>(); });

            Assert.IsTrue(
                exception.Message.Contains(CompileException.InvalidInputAnnotation("CreateDrag", typeof(DragTestThing_CreateAnnotationInvalidParameter), typeof(OnDragCreateAttribute), typeof(MouseInputEvent), typeof(int)).Message));
        }
Beispiel #7
0
        public void TestDefaultPathElementWithExplicitPath()
        {
            MockApplication app = MockApplication.Setup <DefaultPathElementWithExplicitPath>();

            app.Update();
            Assert.IsInstanceOf <DefaultPathElementWithExplicitPath>(app.RootElement);
        }
Beispiel #8
0
        public void LoadNestedTemplateDefault()
        {
            MockApplication app = MockApplication.Setup <OuterDefault>();

            Assert.IsInstanceOf <OuterDefault>(app.RootElement);
            Assert.IsInstanceOf <InnerDefault>(app.RootElement[0]);
        }
Beispiel #9
0
        public void MouseHover_DoesNotFireAfterMove()
        {
            MockApplication testView = MockApplication.Setup <InputSystemTestThing2>();

            testView.Update();
            testView.SetViewportRect(new Rect(0, 0, 1000, 1000));
            InputSystemTestThing2 root = (InputSystemTestThing2)testView.RootElement;

            root.ignoreHover = false;

            testView.InputSystem.SetMousePosition(new Vector2(20, 10));
            testView.Update();

            Assert.AreEqual(new string[0], root.clickList.ToArray());

            testView.InputSystem.SetMousePosition(new Vector2(20, 10));
            testView.Update();

            Assert.AreEqual(new[] { "hover:child0", "hover:root" }, root.clickList.ToArray());

            testView.InputSystem.SetMousePosition(new Vector2(21, 10));
            testView.Update();

            Assert.AreEqual(new[] { "hover:child0", "hover:root" }, root.clickList.ToArray());
        }
Beispiel #10
0
        public void MouseExit_FireAgainWhenReenteredElement()
        {
            MockApplication testView = MockApplication.Setup <InputSystemTestThing2>();

            testView.Update();
            testView.SetViewportRect(new Rect(0, 0, 1000, 1000));
            InputSystemTestThing2 root = (InputSystemTestThing2)testView.RootElement;

            root.ignoreExit = false;

            testView.InputSystem.SetMousePosition(new Vector2(20, 10));
            testView.Update();

            Assert.AreEqual(new string[0], root.clickList.ToArray());

            testView.InputSystem.SetMousePosition(new Vector2(120, 10));
            testView.Update();

            testView.InputSystem.SetMousePosition(new Vector2(20, 10));
            testView.Update();

            testView.InputSystem.SetMousePosition(new Vector2(120, 10));
            testView.Update();

            Assert.AreEqual(new[] { "exit:child0", "exit:child0" }, root.clickList.ToArray());
        }
Beispiel #11
0
        public void MouseEnter_FiresForReEnteringElement()
        {
            MockApplication testView = MockApplication.Setup <InputSystemTestThing2>();

            testView.Update();
            testView.SetViewportRect(new Rect(0, 0, 1000, 1000));
            InputSystemTestThing2 root = (InputSystemTestThing2)testView.RootElement;

            root.ignoreEnter = false;
            MouseState mouseState = new MouseState();

            mouseState.mousePosition = new Vector2(20, 10);
            testView.InputSystem.SetMouseState(mouseState);
            testView.Update();

            mouseState.mousePosition = new Vector2(240, 10);
            testView.InputSystem.SetMouseState(mouseState);
            testView.Update();

            mouseState.mousePosition = new Vector2(20, 10);
            testView.InputSystem.SetMouseState(mouseState);
            testView.Update();

            Assert.AreEqual(new[] { "enter:child0", "enter:root", "enter:child2", "enter:child0" }, root.clickList.ToArray());
        }
Beispiel #12
0
        public void Updates()
        {
            MockApplication app = MockApplication.Setup <LayoutTestThing>();

            app.SetViewportRect(new Rect(0, 0, 1000f, 1000f));
            LayoutTestThing root = (LayoutTestThing)app.RootElement;

            app.Update();
            Assert.AreEqual(Vector2.zero, root.child0.layoutResult.localPosition);
            Assert.AreEqual(new Vector2(0, 100), root.child1.layoutResult.localPosition);
            Assert.AreEqual(100, root.child1.layoutResult.actualSize.width);
            Assert.AreEqual(100, root.child1.layoutResult.actualSize.height);

            Assert.AreEqual(new Vector2(0, 200), root.child2.layoutResult.localPosition);
            Assert.AreEqual(100, root.child2.layoutResult.actualSize.width);
            Assert.AreEqual(100, root.child2.layoutResult.actualSize.height);

            root.child2.style.SetPreferredWidth(200, StyleState.Normal);
            app.Update();
            Assert.AreEqual(Vector2.zero, root.child0.layoutResult.localPosition);
            Assert.AreEqual(new Vector2(0, 100), root.child1.layoutResult.localPosition);
            Assert.AreEqual(100, root.child1.layoutResult.actualSize.width);
            Assert.AreEqual(100, root.child1.layoutResult.actualSize.height);

            Assert.AreEqual(new Vector2(0, 200), root.child2.layoutResult.localPosition);
            Assert.AreEqual(200, root.child2.layoutResult.actualSize.width);
            Assert.AreEqual(100, root.child2.layoutResult.actualSize.height);
        }
Beispiel #13
0
        public void Drag_element_and_update_synced_value_while_not_hovering_draggeed_element()
        {
            MockApplication testView = MockApplication.Setup <DragElementWithSyncBindingTestWrapper>();

            testView.Update();
            testView.SetViewportRect(new Rect(0, 0, 1000, 1000));
            DragElementWithSyncBindingTestWrapper root = (DragElementWithSyncBindingTestWrapper)testView.RootElement;

            testView.InputSystem.MouseDown(new Vector2(10, 10));
            testView.Update();

            // drag move the mouse over to the sibling element
            testView.InputSystem.MouseDragMove(new Vector2(20, 90));
            testView.Update();
            Assert.AreEqual(20, root.children[0].layoutResult.screenPosition.x);

            testView.InputSystem.MouseDragMove(new Vector2(31, 89));
            testView.Update();
            Assert.AreEqual(31, root.children[0].layoutResult.screenPosition.x);

            testView.InputSystem.MouseDragMove(new Vector2(30, 75));
            testView.Update();
            Assert.AreEqual(30, root.children[0].layoutResult.screenPosition.x);

            testView.InputSystem.MouseDragMove(new Vector2(400, 120));
            testView.Update();
            Assert.AreEqual(400, root.children[0].layoutResult.screenPosition.x);
        }
Beispiel #14
0
    public void IntProperties_EnterSecondState()
    {
        Action <string, string, string> TestBody = (setFnName, propName, defaultName) => {
            MockApplication view = MockApplication.Setup <StyleSetTestThing>();

            StyleSetTestThing root = (StyleSetTestThing)view.RootElement;

            CallMethod(root.style, setFnName, DefaultValue <int>(defaultName) + 1, StyleState.Hover);
            CallMethod(root.style, setFnName, DefaultValue <int>(defaultName) + 5, StyleState.Focused);

            root.style.EnterState(StyleState.Hover);

            Assert.AreEqual(DefaultValue <int>(defaultName) + 1, ComputedValue <int>(root, propName));

            root.style.EnterState(StyleState.Focused);

            Assert.AreEqual(DefaultValue <int>(defaultName) + 5, ComputedValue <int>(root, propName));

            root.style.ExitState(StyleState.Focused);

            Assert.AreEqual(DefaultValue <int>(defaultName) + 1, ComputedValue <int>(root, propName));
        };

        RunIntTests(TestBody);
    }
Beispiel #15
0
        public void MouseDown_StopPropagationInBubble()
        {
            MockApplication testView = MockApplication.Setup <InputSystemTestThing2>();

            testView.Update();
            testView.SetViewportRect(new Rect(0, 0, 1000, 1000));
            InputSystemTestThing2 root = (InputSystemTestThing2)testView.RootElement;

            testView.InputSystem.MouseDown(new Vector2(120, 10));
            root.shouldStopPropagation = true;
            testView.Update();

            Assert.AreEqual(-1, root.clickedChildIndex);
            Assert.IsTrue(root.wasMouseDown);

            testView.InputSystem.ClearClickState();
            testView.Update();

            root.wasMouseDown = false;

            root.shouldStopPropagation = false;
            testView.InputSystem.MouseDown(new Vector2(120, 10));
            testView.Update();

            Assert.AreEqual(1, root.clickedChildIndex);
            Assert.IsTrue(root.wasMouseDown);
        }
        public void ModifySlot_TypedWithField()
        {
            MockApplication app = MockApplication.Setup <TestTemplateStructure_ModifySlot_TypedWithFieldMain>();
            TestTemplateStructure_ModifySlot_TypedWithFieldMain root = (TestTemplateStructure_ModifySlot_TypedWithFieldMain)app.RootElement;

            TestTemplateStructure_ModifySlot_TypedWithFieldInner inner = (TestTemplateStructure_ModifySlot_TypedWithFieldInner)root[0];

            TestTemplateStructure_ModifySlot_TypedWithFieldInnerThing c0 = inner[0][0] as TestTemplateStructure_ModifySlot_TypedWithFieldInnerThing;
            TestTemplateStructure_ModifySlot_TypedWithFieldInnerThing c1 = inner[0][1] as TestTemplateStructure_ModifySlot_TypedWithFieldInnerThing;
            TestTemplateStructure_ModifySlot_TypedWithFieldInnerThing c2 = inner[0][2] as TestTemplateStructure_ModifySlot_TypedWithFieldInnerThing;

            inner.value = 10;

            app.Update();

            Assert.AreEqual(c0.typedField, 0 * inner.value);
            Assert.AreEqual(c1.typedField, 1 * inner.value);
            Assert.AreEqual(c2.typedField, 2 * inner.value);

            inner.value = 20;

            app.Update();

            Assert.AreEqual(c0.typedField, 0 * inner.value);
            Assert.AreEqual(c1.typedField, 1 * inner.value);
            Assert.AreEqual(c2.typedField, 2 * inner.value);
        }
Beispiel #17
0
    public void IntProperties_OverrideBaseStyle()
    {
        Action <string, string, string> TestBody = (setFnName, propName, defaultName) => {
            MockApplication view = MockApplication.Setup <StyleSetTestThing>();

            StyleSetTestThing root = (StyleSetTestThing)view.RootElement;

            UIStyle baseStyle = new UIStyle();
            SetStyleValue(baseStyle, propName, 5);

            CallMethod(root.style, setFnName, 15, StyleState.Normal);
            UIStyleGroup group = new UIStyleGroup()
            {
                name   = "Name",
                normal = new UIStyleRunCommand()
                {
                    style = baseStyle
                }
            };
            group.styleType = StyleType.Shared;

            UIStyleGroupContainer container = new UIStyleGroupContainer(0, "Name", StyleType.Shared, new[] { group });
            root.style.AddStyleGroupContainer(container);

            Assert.AreEqual(15, ComputedValue <int>(root, propName));

            root.style.RemoveStyleGroupContainer(container);

            Assert.AreEqual(15, ComputedValue <int>(root, propName));
        };

        RunIntTests(TestBody);
    }
Beispiel #18
0
    public void SizeProperties_EnterSecondState()
    {
        Action <string, string, string> TestBody = (setFnName, propName, defaultName) => {
            MockApplication view = MockApplication.Setup <StyleSetTestThing>();

            StyleSetTestThing root = (StyleSetTestThing)view.RootElement;

            CallMethod(root.style, setFnName, new UIMeasurement(1000), StyleState.Hover);
            CallMethod(root.style, setFnName, new UIMeasurement(5000), StyleState.Focused);

            root.style.EnterState(StyleState.Hover);

            Assert.AreEqual(new UIMeasurement(1000), ComputedValue <UIMeasurement>(root, propName));

            root.style.EnterState(StyleState.Focused);

            Assert.AreEqual(new UIMeasurement(5000), ComputedValue <UIMeasurement>(root, propName));

            root.style.ExitState(StyleState.Focused);

            Assert.AreEqual(new UIMeasurement(1000), ComputedValue <UIMeasurement>(root, propName));
        };

        RunSizeTests(TestBody);
    }
Beispiel #19
0
        public void MouseDown_WithPropagation()
        {
            MockApplication application = MockApplication.Setup <InputSystemTestThing>();

            application.Update();
            application.SetViewportRect(new Rect(0, 0, 1000, 1000));
            InputSystemTestThing root = (InputSystemTestThing)application.RootElement;

            application.Update();

            application.InputSystem.MouseDown(new Vector2(20, 10));
            application.Update();

            Assert.AreEqual(0, root.clickedChildIndex);
            Assert.IsTrue(root.wasMouseDown);

            application.InputSystem.ClearClickState();
            application.Update();

            application.InputSystem.MouseDown(new Vector2(120, 10));
            application.Update();
            Assert.AreEqual(1, root.clickedChildIndex);

            application.InputSystem.ClearClickState();
            application.Update();

            application.InputSystem.MouseDown(new Vector2(220, 10));
            application.Update();
            Assert.AreEqual(2, root.clickedChildIndex);
        }
Beispiel #20
0
        public void ContentSized()
        {
            MockApplication          app  = MockApplication.Setup <LayoutSystemTest_Content>();
            LayoutSystemTest_Content root = (LayoutSystemTest_Content)app.RootElement;

            app.Update();
            Assert.AreEqual(new Rect(0, 100, 300, 50), root[1].layoutResult.AllocatedRect);
        }
Beispiel #21
0
    public void ApplyHeadingStyles()
    {
        MockApplication     app  = MockApplication.Setup <HeadingStyleElement>();
        HeadingStyleElement root = (HeadingStyleElement)app.RootElement;

        app.Update();
        Assert.AreEqual(new UIFixedLength(100), root.FindById("myHeading").style.TextFontSize);
    }
Beispiel #22
0
    public void ApplyDynamicStyleBinding()
    {
        MockApplication   app  = MockApplication.Setup <StyleSetTestThing>();
        StyleSetTestThing root = (StyleSetTestThing)app.RootElement;

        app.Update();
        Assert.AreEqual(100, root.FindById("dynamic").style.MarginTop.value);
    }
Beispiel #23
0
        public void Runs_The_Application()
        {
            var gameSettings = new GameSettings();
            var application  = new MockApplication();

            Program.Run(application, gameSettings);

            application.VerifyRunCalled(gameSettings);
        }
        public void OverrideSlotContent()
        {
            MockApplication app = MockApplication.Setup <TestTemplateStructure_UseDefaultSlotContent_OuterOverride>();
            TestTemplateStructure_UseDefaultSlotContent_OuterOverride root = (TestTemplateStructure_UseDefaultSlotContent_OuterOverride)app.RootElement;

            app.Update();

            Assert.AreEqual("from override slot", GetText(root[0][0][0]));
        }
Beispiel #25
0
        public void ResolveUsingDefaultPathNoAttr()
        {
            MockApplication app = MockApplication.Setup <DefaultPathElementNoAttr>();

            Assert.IsInstanceOf <DefaultPathElementNoAttr>(app.RootElement);
            UITextElement textElement = TestUtils.AssertInstanceOfAndReturn <UITextElement>(app.RootElement[0]);

            Assert.AreEqual("Default Path! No Attr", textElement.text.Trim());
        }
        public void UseDefaultChildren()
        {
            MockApplication         app  = MockApplication.Setup <UseDefaultChildrenOuter>();
            UseDefaultChildrenOuter root = (UseDefaultChildrenOuter)app.RootElement;

            app.Update();

            Assert.AreEqual("default children", GetText(root[0][0][0]));
        }
Beispiel #27
0
        public void ResolveMaxContentTrackSize_WithColGap()
        {
            MockApplication mockView = MockApplication.Setup <GridLayout_ResolveMaxContentTrackSize>();
            GridLayout_ResolveMaxContentTrackSize root = (GridLayout_ResolveMaxContentTrackSize)mockView.RootElement;

            root.style.SetGridLayoutColGap(10, StyleState.Normal);
            mockView.Update();
            Assert.AreEqual(320, root.layoutResult.actualSize.width);
        }
Beispiel #28
0
        public void GapContentSize()
        {
            MockApplication app = MockApplication.Setup <FlexHorizontal_GapContentSize>();
            FlexHorizontal_GapContentSize root = (FlexHorizontal_GapContentSize)app.RootElement;

            app.Update();

            Assert.AreEqual(new Rect(0, 0, 320, 100), root.layoutResult.AllocatedRect);
        }
Beispiel #29
0
        public void NoWrapWithGap()
        {
            MockApplication app = MockApplication.Setup <FlexHorizontalWrap_NoWrapWithGap>();
            FlexHorizontalWrap_NoWrapWithGap root = (FlexHorizontalWrap_NoWrapWithGap)app.RootElement;

            app.Update();

            Assert.AreEqual(new Rect(0, 0, 100, 100), root[0].layoutResult.AllocatedRect);
        }
        public void ParseDynamicElement()
        {
            MockApplication app = MockApplication.Setup <XMLTemplateParsing_UseDynamicElement>();
            XMLTemplateParsing_UseDynamicElement e = (XMLTemplateParsing_UseDynamicElement)app.RootElement;

            app.Update();

            Assert.AreEqual("Hello Matt!", GetText(e[0][0]));
        }