Ejemplo n.º 1
0
        /// <summary>
        /// This method has been never run.
        /// </summary>
        public void Show()
        {
            PropertyObject mainSequenceResult = null;

            // 1. Define column descriptions.
            IRowQuery columnNamesRow =
                FluentRowBuilder.CreateRowBuilder().AddColWithStr("No.")
                .AddColWithStr("Name")
                .AddColWithStr("Result")
                .AddColWithStr("Time")
                .BuildOneTimeRow();

            // 2. Define rows made from NumericLimitTest steps.
            IRowQuery numericLimitTestRow =
                FluentRowBuilder.CreateRowBuilder().AddColCounter()
                .AddColWithFormattedValue("TS.StepName")
                .AddColWithFormattedValue("Value: ", "Numeric", string.Empty)
                .AddColNumericDiff(mainSequenceResult.GetValNumber("TS.StartTime", 0x0), "TS.StartTime")
                .BuildRowByStepType("NumericLimitTest");

            // 3. Define rows made from MultipleNumericLimitTest steps.
            IRowQuery multipleNumericLimitTestRow =
                FluentRowBuilder.CreateRowBuilder().AddColCounter()
                .AddColWithFormattedValue("TS.StepName")
                .AddColWithRowsFromPropertyObject("Measurement",
                                                  FluentRowBuilder.CreateRowBuilder().AddColWithFormattedValue("Data", "%.3f").BuildEveryRow())
                .AddColNumericDiff(mainSequenceResult.GetValNumber("TS.StartTime", 0x0), "TS.StartTime")
                .BuildRowByStepType("NI_MultipleNumericLimitTest");

            // 4. Report (the projection happens here).
            IColumn reportColumn = new Reporter().Report(mainSequenceResult, columnNamesRow, numericLimitTestRow, multipleNumericLimitTestRow);

            // 5. Format to textual table.
            string reportStr = new SimpleTextFormatter().Format(reportColumn);
        }
Ejemplo n.º 2
0
        public void Should_Format_TextRuns_With_Default_Style()
        {
            using (Start())
            {
                const string text = "0123456789";

                var defaultTextRunStyle = new TextStyle(Typeface.Default, 12, Brushes.Black);

                var textSource = new SimpleTextSource(text, defaultTextRunStyle);

                var formatter = new SimpleTextFormatter();

                var textLine = formatter.FormatLine(textSource, 0, double.PositiveInfinity, new TextParagraphProperties());

                Assert.Single(textLine.TextRuns);

                var textRun = textLine.TextRuns[0];

                Assert.Equal(defaultTextRunStyle.TextFormat, textRun.Style.TextFormat);

                Assert.Equal(defaultTextRunStyle.Foreground, textRun.Style.Foreground);

                Assert.Equal(text.Length, textRun.Text.Length);
            }
        }
Ejemplo n.º 3
0
        public void Should_Format_TextRuns_With_TextRunStyles()
        {
            using (Start())
            {
                const string text = "0123456789";

                var defaultStyle = new TextStyle(Typeface.Default, 12, Brushes.Black);

                var textStyleRuns = new[]
                {
                    new TextStyleRun(new TextPointer(0, 3), defaultStyle),
                    new TextStyleRun(new TextPointer(3, 3), new TextStyle(Typeface.Default, 13, Brushes.Black)),
                    new TextStyleRun(new TextPointer(6, 3), new TextStyle(Typeface.Default, 14, Brushes.Black)),
                    new TextStyleRun(new TextPointer(9, 1), defaultStyle)
                };

                var textSource = new FormattableTextSource(text, defaultStyle, textStyleRuns);

                var formatter = new SimpleTextFormatter();

                var textLine = formatter.FormatLine(textSource, 0, double.PositiveInfinity, new TextParagraphProperties());

                Assert.Equal(text.Length, textLine.Text.Length);

                for (var i = 0; i < textStyleRuns.Length; i++)
                {
                    var textStyleRun = textStyleRuns[i];

                    var textRun = textLine.TextRuns[i];

                    Assert.Equal(textStyleRun.TextPointer.Length, textRun.Text.Length);
                }
            }
        }
        public void PrecalculateColumnWidthsWorksCorrectly()
        {
            var sut = new SimpleTextFormatter();

            var actual   = sut.PrecalculateColumnWidths(_reportAsColumn);
            var expected = new Dictionary <Tuple <int[], int[]>, int>(new SimpleTextFormatter.TupleKeyEqualityComparer())
            {
                { new Tuple <int[], int[]>(Array.Empty <int>(), Array.Empty <int>()), 34 },
                { new Tuple <int[], int[]>(new[] { 0 }, new[] { 1 }), 34 },
                { new Tuple <int[], int[]>(new[] { 0 }, new[] { 2 }), 14 },
                { new Tuple <int[], int[]>(new[] { 1 }, new[] { 2 }), 17 },
                { new Tuple <int[], int[]>(new[] { 0, 0 }, new[] { 1, 3 }), 22 },
                { new Tuple <int[], int[]>(new[] { 0, 1 }, new[] { 1, 3 }), 3 },
                { new Tuple <int[], int[]>(new[] { 0, 2 }, new[] { 1, 3 }), 3 },
                { new Tuple <int[], int[]>(new[] { 0, 0, 0 }, new[] { 1, 3, 3 }), 2 },
                { new Tuple <int[], int[]>(new[] { 0, 0, 1 }, new[] { 1, 3, 3 }), 7 },
                { new Tuple <int[], int[]>(new[] { 0, 0, 2 }, new[] { 1, 3, 3 }), 7 },
                { new Tuple <int[], int[]>(new[] { 0, 1, 0 }, new[] { 1, 3, 1 }), 3 },
                { new Tuple <int[], int[]>(new[] { 0, 2, 0 }, new[] { 1, 3, 1 }), 3 },
                { new Tuple <int[], int[]>(new[] { 0, 0, 0 }, new[] { 1, 3, 2 }), 11 },
                { new Tuple <int[], int[]>(new[] { 0, 0, 1 }, new[] { 1, 3, 2 }), 8 },
                { new Tuple <int[], int[]>(new[] { 0, 0 }, new[] { 1, 2 }), 19 },
                { new Tuple <int[], int[]>(new[] { 0, 1 }, new[] { 1, 2 }), 12 }
            };

            Assert.Equal(expected.Count(), actual.Count());

            foreach (var kvp in expected)
            {
                Assert.Equal(kvp.Value, actual[kvp.Key]);
            }
        }
        public void FormatWorksCorrectly()
        {
            var sut = new SimpleTextFormatter()
            {
                MaxColLinesCount = 2
            };

            var actual = sut.Format(_reportAsColumn);

            Assert.Equal(ExpectedTestResults.ExpectedAntonioReport, actual);
        }
Ejemplo n.º 6
0
        public void Should_Wrap_Text(string text, string familyName, int numberOfCharactersPerLine)
        {
            using (Start())
            {
                var lineBreaker = new LineBreakEnumerator(text.AsMemory());

                var expected = new List <int>();

                while (lineBreaker.MoveNext())
                {
                    expected.Add(lineBreaker.Current.PositionWrap - 1);
                }

                var typeface = new Typeface("resm:Avalonia.Skia.UnitTests.Assets?assembly=Avalonia.Skia.UnitTests#" +
                                            familyName);

                var defaultStyle = new TextStyle(typeface);

                var textSource = new SimpleTextSource(text, defaultStyle);

                var formatter = new SimpleTextFormatter();

                var glyph = typeface.GlyphTypeface.GetGlyph('a');

                var advance = typeface.GlyphTypeface.GetGlyphAdvance(glyph) *
                              (12.0 / typeface.GlyphTypeface.DesignEmHeight);

                var paragraphWidth = advance * numberOfCharactersPerLine;

                var currentPosition = 0;

                while (currentPosition < text.Length)
                {
                    var textLine =
                        formatter.FormatLine(textSource, currentPosition, paragraphWidth,
                                             new TextParagraphProperties(defaultStyle, textWrapping: TextWrapping.Wrap));

                    Assert.True(expected.Contains(textLine.Text.End));

                    var index = expected.IndexOf(textLine.Text.End);

                    for (var i = 0; i <= index; i++)
                    {
                        expected.RemoveAt(0);
                    }

                    currentPosition += textLine.Text.Length;
                }
            }
        }
Ejemplo n.º 7
0
        public void Should_Produce_Unique_Runs(string text, int numberOfRuns)
        {
            using (Start())
            {
                var textSource = new SimpleTextSource(text, new TextStyle(Typeface.Default));

                var formatter = new SimpleTextFormatter();

                var textLine =
                    formatter.FormatLine(textSource, 0, double.PositiveInfinity, new TextParagraphProperties());

                Assert.Equal(numberOfRuns, textLine.TextRuns.Count);
            }
        }
Ejemplo n.º 8
0
        public void Should_Split_Run_On_Script()
        {
            using (Start())
            {
                const string text = "1234الدولي";

                var textSource = new SimpleTextSource(text, new TextStyle(Typeface.Default));

                var formatter = new SimpleTextFormatter();

                var textLine =
                    formatter.FormatLine(textSource, 0, double.PositiveInfinity, new TextParagraphProperties());

                Assert.Equal(4, textLine.TextRuns[0].Text.Length);
            }
        }
Ejemplo n.º 9
0
        public void Should_Format_TextRuns_With_Multiple_Buffers()
        {
            using (Start())
            {
                var defaultTextRunStyle = new TextStyle(Typeface.Default, 12, Brushes.Black);

                var textSource = new MultiBufferTextSource(defaultTextRunStyle);

                var formatter = new SimpleTextFormatter();

                var textLine = formatter.FormatLine(textSource, 0, double.PositiveInfinity,
                                                    new TextParagraphProperties(defaultTextRunStyle));

                Assert.Equal(5, textLine.TextRuns.Count);

                Assert.Equal(50, textLine.Text.Length);
            }
        }
Ejemplo n.º 10
0
        public void Should_Get_CharacterHit_From_Distance()
        {
            using (Start())
            {
                var textSource = new MultiBufferTextSource(new TextStyle(Typeface.Default));

                var formatter = new SimpleTextFormatter();

                var textLine =
                    formatter.FormatLine(textSource, 0, double.PositiveInfinity, new TextParagraphProperties());

                var currentDistance = 0.0;

                CharacterHit characterHit;

                foreach (var run in textLine.TextRuns)
                {
                    var textRun = (ShapedTextRun)run;

                    var glyphRun = textRun.GlyphRun;

                    for (var i = 0; i < glyphRun.GlyphClusters.Length; i++)
                    {
                        var cluster = glyphRun.GlyphClusters[i];

                        var glyph = glyphRun.GlyphIndices[i];

                        var advance = glyphRun.GlyphTypeface.GetGlyphAdvance(glyph) * glyphRun.Scale;

                        characterHit = textLine.GetCharacterHitFromDistance(currentDistance);

                        Assert.Equal(cluster, characterHit.FirstCharacterIndex + characterHit.TrailingLength);

                        currentDistance += advance;
                    }
                }

                characterHit = textLine.GetCharacterHitFromDistance(textLine.LineMetrics.Size.Width);

                Assert.Equal(textSource.TextPointer.End, characterHit.FirstCharacterIndex);
            }
        }
Ejemplo n.º 11
0
        public void Should_Get_Distance_From_CharacterHit()
        {
            using (Start())
            {
                var textSource = new MultiBufferTextSource(new TextStyle(Typeface.Default));

                var formatter = new SimpleTextFormatter();

                var textLine =
                    formatter.FormatLine(textSource, 0, double.PositiveInfinity, new TextParagraphProperties());

                var currentDistance = 0.0;

                foreach (var run in textLine.TextRuns)
                {
                    var textRun = (ShapedTextRun)run;

                    var glyphRun = textRun.GlyphRun;

                    for (var i = 0; i < glyphRun.GlyphClusters.Length; i++)
                    {
                        var cluster = glyphRun.GlyphClusters[i];

                        var glyph = glyphRun.GlyphIndices[i];

                        var advance = glyphRun.GlyphTypeface.GetGlyphAdvance(glyph) * glyphRun.Scale;

                        var distance = textLine.GetDistanceFromCharacterHit(new CharacterHit(cluster));

                        Assert.Equal(currentDistance, distance);

                        currentDistance += advance;
                    }
                }

                Assert.Equal(currentDistance, textLine.GetDistanceFromCharacterHit(new CharacterHit(textSource.TextPointer.Length)));
            }
        }
        public void PrecalculateRowHeightsWorksCorrectly()
        {
            var sut = new SimpleTextFormatter();

            var actual = sut.PrecalculateRowHeights(_reportAsColumn);

            var expected = new Dictionary <IRowLocation, int>()
            {
                { ColumnLocation.Root.NestOpen(0), 2 },
                { ColumnLocation.Root.NestOpen(1), 1 },
                { ColumnLocation.Root.NestOpen(2), 1 },
                { ColumnLocation.Root.NestOpen(3), 14 },
                { ColumnLocation.Root.NestOpen(4), 1 },
                { ColumnLocation.Root.NestOpen(3).Nest(0, 0), 1 },
                { ColumnLocation.Root.NestOpen(3).Nest(1, 0), 1 },
                { ColumnLocation.Root.NestOpen(3).Nest(2, 0), 6 },
                { ColumnLocation.Root.NestOpen(3).Nest(3, 0), 3 },
                { ColumnLocation.Root.NestOpen(4).Nest(0, 0), 1 },
                { ColumnLocation.Root.NestOpen(3).Nest(2, 0).Nest(0, 0), 1 },
                { ColumnLocation.Root.NestOpen(3).Nest(2, 0).Nest(1, 0), 1 },
                { ColumnLocation.Root.NestOpen(3).Nest(2, 0).Nest(2, 0), 2 },
                { ColumnLocation.Root.NestOpen(3).Nest(3, 0).Nest(0, 0), 1 },
                { ColumnLocation.Root.NestOpen(3).Nest(3, 0).Nest(1, 0), 1 },
                { ColumnLocation.Root.NestOpen(3).Nest(2, 0).Nest(0, 1), 2 },
                { ColumnLocation.Root.NestOpen(3).Nest(2, 0).Nest(1, 1), 1 },
                { ColumnLocation.Root.NestOpen(3).Nest(2, 0).Nest(2, 1), 1 },
                { ColumnLocation.Root.NestOpen(3).Nest(2, 0).Nest(0, 2), 3 },
                { ColumnLocation.Root.NestOpen(3).Nest(2, 0).Nest(1, 2), 2 }
            };

            Assert.Equal(expected.Count, actual.Count);

            foreach (var kvp in expected)
            {
                Assert.Equal(kvp.Value, actual[kvp.Key]);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// This code is for demo purpose
        /// </summary>
        // [Fact]
        public void Show()
        {
            // 1. Prepare result
            IEnumerable <TestResult> result = new[] {
                new TestResult("TestMethod0", TimeSpan.FromSeconds(2), true, "Equal", null),
                new TestResult("TestMethod1", TimeSpan.FromSeconds(2), false, "MultiTrue",
                               new TestResult("Subtest0", TimeSpan.FromSeconds(1), true, "True", null),
                               new TestResult("Subtest1", TimeSpan.FromSeconds(1), false, "True", null)),
                new TestResult("TestMethod2", TimeSpan.FromSeconds(2), true, "Contains", null),
                new TestResult("TestMethod3", TimeSpan.FromSeconds(2), true, "Equal", null),
                new TestResult("TestMethod4", TimeSpan.FromSeconds(2), true, "Empty", null)
            };

            // 2. Define column (report) query
            IColumnQuery            counterColQuery = new CounterColumnQuery(); // Mutable class - it's an ordinal column
            IEnumerable <IRowQuery> reportQueries   = new IRowQuery[] {
                new OneTimeRowQuery(                                            // 2a. Define first header row
                    new ColumnWithStrQuery("Date"),
                    new ColumnWithStrQuery(DateTime.Now.ToShortDateString())),
                new OneTimeRowQuery(     // 2b. Define second header row
                    new ColumnWithStrQuery("Tested by"),
                    new ColumnWithStrQuery("Me")),
                new OneTimeRowQuery(     // 2c. Define third header row
                    new ColumnWithStrQuery("Final result"),
                    new ColumnWithStrQuery(result.All(tr => tr.Result) ? "Passed" : "Failed")),
                // 2c. Define body
                new ByAssertTypeFilter("Equal",
                                       counterColQuery,
                                       new NameGetter(),
                                       new ExecTimeInSecondsGetter(),
                                       new ResultGetter()),
                new ByAssertTypeFilter("MultiTrue",
                                       counterColQuery,
                                       new NameGetter(),
                                       new ExecTimeInSecondsGetter(),
                                       new ColumnWithRowsBranchedQuery <TestResult>(tr => tr.InnerTests,
                                                                                    new EveryRowQuery(
                                                                                        new NameGetter(),
                                                                                        new ExecTimeInSecondsGetter(),
                                                                                        new ResultGetter()))
                                       )
            };

            // 3. Report
            IColumn reportedColumn =
                new Reporter <TestResult>().Report(result, reportQueries);

            // 3a. Preview column
            string columnStr = reportedColumn.ToXml().ToString();

            // 4. Format
            string formattedReport = new SimpleTextFormatter().Format(reportedColumn);

            // 5. Write
            string reportPath = new SimpleTextWriter().WriteReport(formattedReport, Path.GetTempPath(), "MyReport");

            // 6. Read
            string readReport = new SimpleTextReader().ReadReport(reportPath);

            // 7. Parse
            IColumn parsedColumn = new SimpleTextParser().Parse(readReport);

            // 8. Interpret
            string finalResult = parsedColumn[ColumnLocation.Root.Nest(2, 1)].ToString();
            // etc...
        }