Beispiel #1
0
        public void LayoutManager_Should_Recover_From_Infinite_Loop_On_Measure()
        {
            // Test for issue #3041.
            var control = new LayoutTestControl();
            var root    = new LayoutTestRoot {
                Child = control
            };

            root.LayoutManager.ExecuteInitialLayoutPass(root);
            control.Measured = false;

            control.DoMeasureOverride = (l, s) =>
            {
                control.InvalidateMeasure();
                return(new Size(100, 100));
            };

            control.InvalidateMeasure();
            root.LayoutManager.ExecuteLayoutPass();

            // This is the important part: running a second layout pass in which we exceed the maximum
            // retries causes LayoutQueue<T>.Info.Count to exceed _maxEnqueueCountPerLoop.
            root.LayoutManager.ExecuteLayoutPass();

            control.Measured          = false;
            control.DoMeasureOverride = null;

            root.LayoutManager.ExecuteLayoutPass();

            Assert.True(control.Measured);
            Assert.True(control.IsMeasureValid);
        }
Beispiel #2
0
        public void LayoutManager_Should_Prevent_Infinite_Loop_On_Measure()
        {
            var control = new LayoutTestControl();
            var root    = new LayoutTestRoot {
                Child = control
            };

            root.LayoutManager.ExecuteInitialLayoutPass(root);
            control.Measured = false;

            int cnt    = 0;
            int maxcnt = 100;

            control.DoMeasureOverride = (l, s) =>
            {
                //emulate a problem in the logic of a control that triggers
                //invalidate measure during measure
                //it can lead to an infinite loop in layoutmanager
                if (++cnt < maxcnt)
                {
                    control.InvalidateMeasure();
                }

                return(new Size(100, 100));
            };

            control.InvalidateMeasure();

            root.LayoutManager.ExecuteLayoutPass();

            Assert.True(cnt < 100);
        }
Beispiel #3
0
        public void Calling_ExecuteLayoutPass_From_ExecuteInitialLayoutPass_Does_Not_Break_Measure()
        {
            // Test for issue #3550.
            var control = new LayoutTestControl();
            var root    = new LayoutTestRoot {
                Child = control
            };
            var count = 0;

            root.LayoutManager.ExecuteInitialLayoutPass(root);
            control.Measured = false;

            control.DoMeasureOverride = (l, s) =>
            {
                if (count++ == 0)
                {
                    control.InvalidateMeasure();
                    root.LayoutManager.ExecuteLayoutPass();
                    return(new Size(100, 100));
                }
                else
                {
                    return(new Size(200, 200));
                }
            };

            root.InvalidateMeasure();
            control.InvalidateMeasure();
            root.LayoutManager.ExecuteInitialLayoutPass(root);

            Assert.Equal(new Size(200, 200), control.Bounds.Size);
            Assert.Equal(new Size(200, 200), control.DesiredSize);
        }
Beispiel #4
0
        public void Measures_In_Correct_Order()
        {
            LayoutTestControl control1;
            LayoutTestControl control2;
            var root = new LayoutTestRoot
            {
                Child = control1 = new LayoutTestControl
                {
                    Child = control2 = new LayoutTestControl(),
                }
            };


            var order = new List <ILayoutable>();

            Size MeasureOverride(ILayoutable control, Size size)
            {
                order.Add(control);
                return(new Size(10, 10));
            }

            root.DoMeasureOverride     = MeasureOverride;
            control1.DoMeasureOverride = MeasureOverride;
            control2.DoMeasureOverride = MeasureOverride;
            root.LayoutManager.ExecuteInitialLayoutPass(root);

            control2.InvalidateMeasure();
            control1.InvalidateMeasure();
            root.InvalidateMeasure();

            order.Clear();
            root.LayoutManager.ExecuteLayoutPass();

            Assert.Equal(new ILayoutable[] { root, control1, control2 }, order);
        }
Beispiel #5
0
        public void Measures_And_Arranges_InvalidateMeasured_Control()
        {
            var control = new LayoutTestControl();
            var root    = new LayoutTestRoot {
                Child = control
            };

            root.LayoutManager.ExecuteInitialLayoutPass(root);
            control.Measured = control.Arranged = false;

            control.InvalidateMeasure();
            root.LayoutManager.ExecuteLayoutPass();

            Assert.True(control.Measured);
            Assert.True(control.Arranged);
        }
        public void Doesnt_Measure_And_Arrange_InvalidateMeasured_Control_When_TopLevel_Is_Not_Visible()
        {
            var control = new LayoutTestControl();
            var root    = new LayoutTestRoot {
                Child = control, IsVisible = false
            };

            root.LayoutManager.ExecuteInitialLayoutPass();
            control.Measured = control.Arranged = false;

            control.InvalidateMeasure();
            root.LayoutManager.ExecuteLayoutPass();

            Assert.False(control.Measured);
            Assert.False(control.Arranged);
        }
Beispiel #7
0
        public void Doesnt_Measure_Removed_Control()
        {
            var control = new LayoutTestControl();
            var root    = new LayoutTestRoot {
                Child = control
            };

            root.LayoutManager.ExecuteInitialLayoutPass(root);
            control.Measured = control.Arranged = false;

            control.InvalidateMeasure();
            root.Child = null;
            root.LayoutManager.ExecuteLayoutPass();

            Assert.False(control.Measured);
            Assert.False(control.Arranged);
        }
        public void Doesnt_Measure_Non_Invalidated_Root()
        {
            var control = new LayoutTestControl();
            var root    = new LayoutTestRoot {
                Child = control
            };

            root.LayoutManager.ExecuteInitialLayoutPass();
            root.Measured    = root.Arranged = false;
            control.Measured = control.Arranged = false;

            control.InvalidateMeasure();
            root.LayoutManager.ExecuteLayoutPass();

            Assert.False(root.Measured);
            Assert.False(root.Arranged);
            Assert.True(control.Measured);
            Assert.True(control.Arranged);
        }