Exemple #1
0
        public void LinearLayoutOnLayout()
        {
            tlog.Debug(tag, $"LinearLayoutOnLayout START");

            flagOnLayoutOverride = false;
            Assert.False(flagOnLayoutOverride, "flagOnLayoutOverride should be false initial");

            LayoutItem layoutItem = new LinearLayout();

            View view = new View()
            {
                ExcludeLayouting    = false,
                Weight              = 10,
                WidthSpecification  = 0,
                HeightSpecification = 0,
                Layout              = new LinearLayout(),
                LayoutDirection     = ViewLayoutDirectionType.RTL
            };

            layoutItem.AttachToOwner(view);

            var testingTarget = new MyLinearLayout()
            {
                LinearAlignment = LinearLayout.Alignment.Begin,
            };

            Assert.IsNotNull(testingTarget, "null handle returned");
            Assert.IsInstanceOf <LinearLayout>(testingTarget, "Should be an instance of LinearLayout type.");

            testingTarget.AttachToOwner(view);
            testingTarget.Add(layoutItem);

            testingTarget.OnLayoutTest(true, new LayoutLength(5), new LayoutLength(5), new LayoutLength(10), new LayoutLength(10));
            Assert.True(flagOnLayoutOverride, "LinearLayout overridden method not invoked.");

            /** Alignment.End */
            flagOnLayoutOverride = false;
            Assert.False(flagOnLayoutOverride, "flagOnLayoutOverride should be false initial");

            testingTarget.LinearAlignment = LinearLayout.Alignment.End;

            testingTarget.OnLayoutTest(true, new LayoutLength(5), new LayoutLength(5), new LayoutLength(10), new LayoutLength(10));
            Assert.True(flagOnLayoutOverride, "LinearLayout overridden method not invoked.");

            /** Alignment.CenterHorizontal */
            flagOnLayoutOverride = false;
            Assert.False(flagOnLayoutOverride, "flagOnLayoutOverride should be false initial");

            testingTarget.LinearAlignment = LinearLayout.Alignment.CenterHorizontal;

            testingTarget.OnLayoutTest(true, new LayoutLength(5), new LayoutLength(5), new LayoutLength(10), new LayoutLength(10));
            Assert.True(flagOnLayoutOverride, "LinearLayout overridden method not invoked.");

            /** Alignment.Center */
            flagOnLayoutOverride = false;
            Assert.False(flagOnLayoutOverride, "flagOnLayoutOverride should be false initial");

            testingTarget.LinearAlignment = LinearLayout.Alignment.Center;

            testingTarget.OnLayoutTest(true, new LayoutLength(5), new LayoutLength(5), new LayoutLength(10), new LayoutLength(10));
            Assert.True(flagOnLayoutOverride, "LinearLayout overridden method not invoked.");

            /** Alignment.CenterVertical */
            flagOnLayoutOverride = false;
            Assert.False(flagOnLayoutOverride, "flagOnLayoutOverride should be false initial");

            testingTarget.LinearAlignment = LinearLayout.Alignment.CenterVertical;

            testingTarget.OnLayoutTest(true, new LayoutLength(5), new LayoutLength(5), new LayoutLength(10), new LayoutLength(10));
            Assert.True(flagOnLayoutOverride, "LinearLayout overridden method not invoked.");

            /** Alignment.Bottom */
            flagOnLayoutOverride = false;
            Assert.False(flagOnLayoutOverride, "flagOnLayoutOverride should be false initial");

            testingTarget.LinearAlignment = LinearLayout.Alignment.Bottom;

            testingTarget.OnLayoutTest(true, new LayoutLength(5), new LayoutLength(5), new LayoutLength(10), new LayoutLength(10));
            Assert.True(flagOnLayoutOverride, "LinearLayout overridden method not invoked.");

            /** Alignment.Top */
            flagOnLayoutOverride = false;
            Assert.False(flagOnLayoutOverride, "flagOnLayoutOverride should be false initial");

            testingTarget.LinearAlignment = LinearLayout.Alignment.Top;

            testingTarget.OnLayoutTest(true, new LayoutLength(5), new LayoutLength(5), new LayoutLength(10), new LayoutLength(10));
            Assert.True(flagOnLayoutOverride, "LinearLayout overridden method not invoked.");

            /** Owner.LayoutDirection == ViewLayoutDirectionType.LTR */
            view.LayoutDirection = ViewLayoutDirectionType.LTR;

            flagOnLayoutOverride = false;
            Assert.False(flagOnLayoutOverride, "flagOnLayoutOverride should be false initial");

            testingTarget.OnLayoutTest(true, new LayoutLength(5), new LayoutLength(5), new LayoutLength(10), new LayoutLength(10));
            Assert.True(flagOnLayoutOverride, "LinearLayout overridden method not invoked.");

            /** Alignment.End */
            flagOnLayoutOverride = false;
            Assert.False(flagOnLayoutOverride, "flagOnLayoutOverride should be false initial");

            testingTarget.LinearAlignment = LinearLayout.Alignment.End;

            testingTarget.OnLayoutTest(true, new LayoutLength(5), new LayoutLength(5), new LayoutLength(10), new LayoutLength(10));
            Assert.True(flagOnLayoutOverride, "LinearLayout overridden method not invoked.");

            /** Alignment.CenterHorizontal */
            flagOnLayoutOverride = false;
            Assert.False(flagOnLayoutOverride, "flagOnLayoutOverride should be false initial");

            testingTarget.LinearAlignment = LinearLayout.Alignment.CenterHorizontal;

            testingTarget.OnLayoutTest(true, new LayoutLength(5), new LayoutLength(5), new LayoutLength(10), new LayoutLength(10));
            Assert.True(flagOnLayoutOverride, "LinearLayout overridden method not invoked.");

            /** Alignment.Center */
            flagOnLayoutOverride = false;
            Assert.False(flagOnLayoutOverride, "flagOnLayoutOverride should be false initial");

            testingTarget.LinearAlignment = LinearLayout.Alignment.Center;

            testingTarget.OnLayoutTest(true, new LayoutLength(5), new LayoutLength(5), new LayoutLength(10), new LayoutLength(10));
            Assert.True(flagOnLayoutOverride, "LinearLayout overridden method not invoked.");

            /** Alignment.CenterVertical */
            flagOnLayoutOverride = false;
            Assert.False(flagOnLayoutOverride, "flagOnLayoutOverride should be false initial");

            testingTarget.LinearAlignment = LinearLayout.Alignment.CenterVertical;

            testingTarget.OnLayoutTest(true, new LayoutLength(5), new LayoutLength(5), new LayoutLength(10), new LayoutLength(10));
            Assert.True(flagOnLayoutOverride, "LinearLayout overridden method not invoked.");

            /** Alignment.Bottom */
            flagOnLayoutOverride = false;
            Assert.False(flagOnLayoutOverride, "flagOnLayoutOverride should be false initial");

            testingTarget.LinearAlignment = LinearLayout.Alignment.Bottom;

            testingTarget.OnLayoutTest(true, new LayoutLength(5), new LayoutLength(5), new LayoutLength(10), new LayoutLength(10));
            Assert.True(flagOnLayoutOverride, "LinearLayout overridden method not invoked.");

            /** Alignment.Begin */
            flagOnLayoutOverride = false;
            Assert.False(flagOnLayoutOverride, "flagOnLayoutOverride should be false initial");

            testingTarget.LinearAlignment = LinearLayout.Alignment.Begin;

            testingTarget.OnLayoutTest(true, new LayoutLength(5), new LayoutLength(5), new LayoutLength(10), new LayoutLength(10));
            Assert.True(flagOnLayoutOverride, "LinearLayout overridden method not invoked.");

            /**
             * Test LinearLayout.Orientation.Vertical
             */
            flagOnLayoutOverride = false;
            Assert.False(flagOnLayoutOverride, "flagOnLayoutOverride should be false initial");

            testingTarget.LinearOrientation = LinearLayout.Orientation.Vertical;

            /** Alignment.Bottom */
            flagOnLayoutOverride = false;
            Assert.False(flagOnLayoutOverride, "flagOnLayoutOverride should be false initial");

            testingTarget.LinearAlignment = LinearLayout.Alignment.Bottom;

            testingTarget.OnLayoutTest(true, new LayoutLength(5), new LayoutLength(5), new LayoutLength(10), new LayoutLength(10));
            Assert.True(flagOnLayoutOverride, "LinearLayout overridden method not invoked.");

            /** Alignment.Center */
            flagOnLayoutOverride = false;
            Assert.False(flagOnLayoutOverride, "flagOnLayoutOverride should be false initial");

            testingTarget.LinearAlignment = LinearLayout.Alignment.Center;

            testingTarget.OnLayoutTest(true, new LayoutLength(5), new LayoutLength(5), new LayoutLength(10), new LayoutLength(10));
            Assert.True(flagOnLayoutOverride, "LinearLayout overridden method not invoked.");

            /** Alignment.End */
            flagOnLayoutOverride = false;
            Assert.False(flagOnLayoutOverride, "flagOnLayoutOverride should be false initial");

            testingTarget.LinearAlignment = LinearLayout.Alignment.End;

            testingTarget.OnLayoutTest(true, new LayoutLength(5), new LayoutLength(5), new LayoutLength(10), new LayoutLength(10));
            Assert.True(flagOnLayoutOverride, "LinearLayout overridden method not invoked.");

            /**Test false method override works with false flag too */
            flagOnLayoutOverride = false;
            Assert.False(flagOnLayoutOverride, "flagOnLayoutOverride should be false initial");

            testingTarget.OnLayoutTest(false, new LayoutLength(10), new LayoutLength(10), new LayoutLength(20), new LayoutLength(20));
            Assert.True(flagOnLayoutOverride, "LinearLayout overridden method not invoked.");

            testingTarget.Dispose();
            tlog.Debug(tag, $"LinearLayoutOnLayout END (OK)");
        }
Exemple #2
0
        public void LinearLayoutOnMeasure()
        {
            tlog.Debug(tag, $"LinearLayoutOnMeasure START");

            flagOnMeasureOverride = false;
            Assert.False(flagOnMeasureOverride, "flagOnMeasureOverride should be false initial");

            LayoutItem layoutItem = new LinearLayout();

            View view = new View()
            {
                ExcludeLayouting    = false,
                Weight              = 10,
                WidthSpecification  = 0,
                HeightSpecification = 0,
                Layout              = new LinearLayout()
            };

            layoutItem.AttachToOwner(view);

            var testingTarget = new MyLinearLayout();

            Assert.IsNotNull(testingTarget, "null handle returned");
            Assert.IsInstanceOf <LinearLayout>(testingTarget, "Should be an instance of LinearLayout type.");

            testingTarget.AttachToOwner(view);
            testingTarget.Add(layoutItem);

            MeasureSpecification measureWidth  = new MeasureSpecification(new LayoutLength(50.0f), MeasureSpecification.ModeType.Exactly);
            MeasureSpecification measureHeight = new MeasureSpecification(new LayoutLength(50.0f), MeasureSpecification.ModeType.Exactly);

            /**
             * isExactly is true
             * useExcessSpace is true :(childLayout.Owner.WidthSpecification == 0) && (childWeight > 0)
             */
            testingTarget.OnMeasureTest(measureWidth, measureHeight);
            Assert.True(flagOnMeasureOverride, "LinearLayout overridden method not invoked.");

            /**
             * isExactly is false
             * useExcessSpace is true :(childLayout.Owner.WidthSpecification == 0) && (childWeight > 0)
             */
            flagOnMeasureOverride = false;
            Assert.False(flagOnMeasureOverride, "flagOnMeasureOverride should be false initial");

            MeasureSpecification measureWidth2  = new MeasureSpecification(new LayoutLength(50.0f), MeasureSpecification.ModeType.AtMost);
            MeasureSpecification measureHeight2 = new MeasureSpecification(new LayoutLength(50.0f), MeasureSpecification.ModeType.Unspecified);

            testingTarget.OnMeasureTest(measureWidth2, measureHeight2);
            Assert.True(flagOnMeasureOverride, "LinearLayout overridden method not invoked.");

            /**
             *  matchHeight
             *  heightMode != MeasureSpecification.ModeType.Exactly && childDesiredHeight == LayoutParamPolicies.MatchParent
             */
            view.HeightSpecification = LayoutParamPolicies.MatchParent;
            testingTarget.OnMeasureTest(measureWidth2, measureHeight2);

            /**Test LinearLayout.Orientation.Vertical */
            testingTarget.LinearOrientation = LinearLayout.Orientation.Vertical;
            view.HeightSpecification        = 0;

            flagOnMeasureOverride = false;
            Assert.False(flagOnMeasureOverride, "flagOnMeasureOverride should be false initial");

            /**
             * isExactly is true
             * useExcessSpace is true :(childLayout.Owner.HeightSpecification == 0) && (childWeight > 0)
             */
            testingTarget.OnMeasureTest(measureWidth, measureHeight);
            Assert.True(flagOnMeasureOverride, "LinearLayout overridden method not invoked.");

            flagOnMeasureOverride = false;
            Assert.False(flagOnMeasureOverride, "flagOnMeasureOverride should be false initial");

            /**
             * isExactly is true
             * useExcessSpace is true :(childLayout.Owner.HeightSpecification == 0) && (childWeight > 0)
             *
             * matchWidth
             * widthMode != MeasureSpecification.ModeType.Exactly && childDesiredWidth == LayoutParamPolicies.MatchParent
             */
            view.WidthSpecification = LayoutParamPolicies.MatchParent;
            testingTarget.OnMeasureTest(measureWidth2, measureHeight2);
            Assert.True(flagOnMeasureOverride, "LinearLayout overridden method not invoked.");

            testingTarget.Dispose();
            tlog.Debug(tag, $"LinearLayoutOnMeasure END (OK)");
        }