Esempio n. 1
0
        public void When_DefaultTextBlock_Clip(TextTrimming trimmingMode)
        {
            var SUT = new TextBlockMeasureCache();

            var tb = new TextBlock {
                Text = "42", TextTrimming = trimmingMode
            };                                                                               // Used as key, never measured

            SUT.CacheMeasure(tb, new Size(200, 100), new Size(125, 25));
            SUT.CacheMeasure(tb, new Size(100, 100), new Size(100, 50));
            SUT.CacheMeasure(tb, new Size(75, 100), new Size(75, 100));
            SUT.CacheMeasure(tb, new Size(50, 100), new Size(50, 100));

            Assert.AreEqual(
                new Size(125, 25),
                SUT.FindMeasuredSize(tb, new Size(125, 100))
                );

            Assert.AreEqual(
                new Size(50, 100),
                SUT.FindMeasuredSize(tb, new Size(50, 70))
                );

            Assert.AreEqual(
                null,
                SUT.FindMeasuredSize(tb, new Size(52, 70))
                );

            Assert.AreEqual(
                null,
                SUT.FindMeasuredSize(tb, new Size(500, 500))
                );
        }
Esempio n. 2
0
        public void When_SameSize(double availableWidth1, double measuredWidth1, double findWidth1, double availableWidth2, double measuredWidth2, double measuredWidth3)
        {
            var SUT = new TextBlockMeasureCache();
            var tb  = new TextBlock {
                Text = "42"
            };

            Assert.AreEqual(TextWrapping.NoWrap, tb.TextWrapping);

            SUT.CacheMeasure(tb, new Size(availableWidth1, 10), new Size(measuredWidth1, 10));

            Assert.IsNull(
                SUT.FindMeasuredSize(tb, new Size(findWidth1, 10))
                );

            SUT.CacheMeasure(tb, new Size(availableWidth2, 10), new Size(measuredWidth2, 10));

            Assert.AreEqual(
                new Size(measuredWidth2, 10),
                SUT.FindMeasuredSize(tb, new Size(availableWidth2, 10)).Value
                );

            Assert.AreEqual(
                new Size(measuredWidth3, 10),
                SUT.FindMeasuredSize(tb, new Size(0, 0)).Value
                );
        }
Esempio n. 3
0
        public void When_SmallerAvailableSize()
        {
            var SUT = new TextBlockMeasureCache();
            var tb  = new TextBlock {
                Text = "42"
            };                                                  // Used as key, never measured

            Assert.AreEqual(TextWrapping.NoWrap, tb.TextWrapping);

            SUT.CacheMeasure(tb, new Size(0, 0), new Size(0, 0));

            Assert.IsNull(
                SUT.FindMeasuredSize(tb, new Size(50, 50))
                );

            SUT.CacheMeasure(tb, new Size(100, 100), new Size(50, 10));

            Assert.AreEqual(
                new Size(50, 10),
                SUT.FindMeasuredSize(tb, new Size(100, 100)).Value
                );

            Assert.AreEqual(
                new Size(0, 0),
                SUT.FindMeasuredSize(tb, new Size(0, 0)).Value
                );
        }
Esempio n. 4
0
        public void When_DefaultTextBlock_Wrap()
        {
            var SUT = new TextBlockMeasureCache();

            var tb = new TextBlock()
            {
                Text = "42", TextWrapping = TextWrapping.Wrap
            };

            SUT.CacheMeasure(tb, new Size(50, 100), new Size(50, 70));

            Assert.AreEqual(
                new Size(50, 70),
                SUT.FindMeasuredSize(tb, new Size(50, 100)).Value
                );

            Assert.AreEqual(
                new Size(50, 70),
                SUT.FindMeasuredSize(tb, new Size(50, 70)).Value
                );

            Assert.IsNull(
                SUT.FindMeasuredSize(tb, new Size(50, 69))
                );

            Assert.IsNull(
                SUT.FindMeasuredSize(tb, new Size(49, 100))
                );

            Assert.IsNull(
                SUT.FindMeasuredSize(tb, new Size(50.1, 100))
                );
        }
Esempio n. 5
0
        public void When_DefaultTextBlock()
        {
            var SUT = new TextBlockMeasureCache();

            var tb = new TextBlock()
            {
                Text = "42"
            };

            Assert.AreEqual(TextWrapping.NoWrap, tb.TextWrapping);

            SUT.CacheMeasure(tb, new Size(100, 100), new Size(20, 10));

            Assert.AreEqual(
                new Size(20, 10),
                SUT.FindMeasuredSize(tb, new Size(100, 100)).Value
                );

            Assert.AreEqual(
                new Size(20, 10),
                SUT.FindMeasuredSize(tb, new Size(50, 100)).Value
                );

            Assert.IsNull(
                SUT.FindMeasuredSize(tb, new Size(10, 100))
                );
        }
Esempio n. 6
0
        public void When_MaxMeasureKeyEntries_Reached()
        {
            var SUT = new TextBlockMeasureCache();

            TextBlockMeasureCache.MaxMeasureKeyEntries     = 2;
            TextBlockMeasureCache.MaxMeasureSizeKeyEntries = 2;

            var tb1 = new TextBlock()
            {
                Text = "42", TextWrapping = TextWrapping.Wrap
            };

            SUT.CacheMeasure(tb1, new Size(11, 11), new Size(1, 1));
            Assert.AreEqual(
                new Size(1, 1),
                SUT.FindMeasuredSize(tb1, new Size(11, 11)).Value
                );

            var tb2 = new TextBlock()
            {
                Text = "43", TextWrapping = TextWrapping.Wrap
            };

            SUT.CacheMeasure(tb2, new Size(11, 11), new Size(1, 1));
            Assert.AreEqual(
                new Size(1, 1),
                SUT.FindMeasuredSize(tb2, new Size(11, 11)).Value
                );
            Assert.AreEqual(
                new Size(1, 1),
                SUT.FindMeasuredSize(tb1, new Size(11, 11)).Value
                );

            var tb3 = new TextBlock()
            {
                Text = "44", TextWrapping = TextWrapping.Wrap
            };

            SUT.CacheMeasure(tb3, new Size(11, 11), new Size(1, 1));
            Assert.AreEqual(
                new Size(1, 1),
                SUT.FindMeasuredSize(tb3, new Size(11, 11)).Value
                );
            Assert.AreEqual(
                new Size(1, 1),
                SUT.FindMeasuredSize(tb2, new Size(11, 11)).Value
                );
            Assert.IsNull(
                SUT.FindMeasuredSize(tb1, new Size(11, 11))
                );
        }
Esempio n. 7
0
        public void When_DefaultTextBlock()
        {
            var SUT = new TextBlockMeasureCache();

            var tb = new TextBlock {
                Text = "42"
            };                                                  // Used as key, never measured

            Assert.AreEqual(TextWrapping.NoWrap, tb.TextWrapping);

            SUT.CacheMeasure(tb, new Size(5, 25), new Size(5, 25));
            SUT.CacheMeasure(tb, new Size(12, 20), new Size(12, 15));
            SUT.CacheMeasure(tb, new Size(100, 100), new Size(20, 10));

            var size20x10 = new Size(20, 10);

            var resultFor100x100 = SUT.FindMeasuredSize(tb, new Size(100, 100));

            Assert.AreEqual(size20x10, resultFor100x100);

            var resultFor50x100 = SUT.FindMeasuredSize(tb, new Size(50, 100));

            Assert.AreEqual(size20x10, resultFor50x100);

            var resultFor20x10 = SUT.FindMeasuredSize(tb, size20x10);

            Assert.AreEqual(size20x10, resultFor20x10);

            var resultFor10x100 = SUT.FindMeasuredSize(tb, new Size(10, 100));

            Assert.AreEqual(size20x10, resultFor10x100);

            var resultFor5x20 = SUT.FindMeasuredSize(tb, new Size(5, 20));

            Assert.AreEqual(new Size(5, 25), resultFor5x20);

            var resultFor5x35 = SUT.FindMeasuredSize(tb, new Size(5, 35));

            Assert.AreEqual(resultFor10x100, resultFor5x35);
        }
Esempio n. 8
0
        public void When_MaxMeasureSizeKeyEntries_Reached()
        {
            var SUT = new TextBlockMeasureCache();

            TextBlockMeasureCache.MaxMeasureKeyEntries     = 2;
            TextBlockMeasureCache.MaxMeasureSizeKeyEntries = 2;

            var tb = new TextBlock {
                Text = "42", TextWrapping = TextWrapping.Wrap
            };                                                                                    // Used as key, never measured

            SUT.CacheMeasure(tb, new Size(11, 11), new Size(11, 11));
            Assert.AreEqual(
                new Size(11, 11),
                SUT.FindMeasuredSize(tb, new Size(11, 11))
                );

            SUT.CacheMeasure(tb, new Size(22, 22), new Size(22, 22));
            Assert.AreEqual(
                new Size(11, 11),
                SUT.FindMeasuredSize(tb, new Size(11, 11))
                );
            Assert.AreEqual(
                new Size(22, 22),
                SUT.FindMeasuredSize(tb, new Size(22, 22))
                );

            SUT.CacheMeasure(tb, new Size(33, 33), new Size(33, 33));
            Assert.IsNull(
                SUT.FindMeasuredSize(tb, new Size(11, 11))
                );
            Assert.AreEqual(
                new Size(22, 22),
                SUT.FindMeasuredSize(tb, new Size(22, 22))
                );
            Assert.AreEqual(
                new Size(33, 33),
                SUT.FindMeasuredSize(tb, new Size(33, 33))
                );
        }