Browse Source

Fixed unit tests

MarcinZiabek 3 years ago
parent
commit
af2229eabe

+ 40 - 0
QuestPDF.UnitTests/AspectRatioTests.cs

@@ -153,7 +153,9 @@ namespace QuestPDF.UnitTests
                     Ratio = 2f
                 })
                 .DrawElement(new Size(500, 200))
+                .ExpectCanvasTranslate(0, 0)
                 .ExpectChildDraw(new Size(400, 200))
+                .ExpectCanvasTranslate(0, 0)
                 .CheckDrawResult();
         }
         
@@ -168,7 +170,45 @@ namespace QuestPDF.UnitTests
                     Ratio = 2f
                 })
                 .DrawElement(new Size(400, 300))
+                .ExpectCanvasTranslate(0, 0)
                 .ExpectChildDraw(new Size(400, 200))
+                .ExpectCanvasTranslate(0, 0)
+                .CheckDrawResult();
+        } 
+        
+        [Test]
+        public void DrawChild_PerWidth_RightToLeft()
+        {
+            TestPlan
+                .For(x => new AspectRatio
+                {
+                    Child = x.CreateChild(),
+                    Option = AspectRatioOption.FitArea,
+                    Ratio = 2f,
+                    ContentDirection = ContentDirection.RightToLeft
+                })
+                .DrawElement(new Size(500, 200))
+                .ExpectCanvasTranslate(100, 0)
+                .ExpectChildDraw(new Size(400, 200))
+                .ExpectCanvasTranslate(-100, 0)
+                .CheckDrawResult();
+        }
+        
+        [Test]
+        public void DrawChild_PerHeight_RightToLeft()
+        {
+            TestPlan
+                .For(x => new AspectRatio
+                {
+                    Child = x.CreateChild(),
+                    Option = AspectRatioOption.FitArea,
+                    Ratio = 2f,
+                    ContentDirection = ContentDirection.RightToLeft
+                })
+                .DrawElement(new Size(400, 300))
+                .ExpectCanvasTranslate(0, 0)
+                .ExpectChildDraw(new Size(400, 200))
+                .ExpectCanvasTranslate(0, 0)
                 .CheckDrawResult();
         } 
     }

+ 38 - 0
QuestPDF.UnitTests/BoxTests.cs

@@ -35,7 +35,9 @@ namespace QuestPDF.UnitTests
                 })
                 .MeasureElement(new Size(400, 300))
                 .ExpectChildMeasure(expectedInput: new Size(400, 300), returns: SpacePlan.PartialRender(200, 100))
+                .ExpectCanvasTranslate(0, 0)
                 .ExpectChildDraw(new Size(200, 100))
+                .ExpectCanvasTranslate(0, 0)
                 .CheckDrawResult();
         }
         
@@ -49,7 +51,43 @@ namespace QuestPDF.UnitTests
                 })
                 .MeasureElement(new Size(500, 400))
                 .ExpectChildMeasure(expectedInput: new Size(500, 400), returns: SpacePlan.FullRender(300, 200))
+                .ExpectCanvasTranslate(0, 0)
                 .ExpectChildDraw(new Size(300, 200))
+                .ExpectCanvasTranslate(0, 0)
+                .CheckDrawResult();
+        }
+        
+        [Test]
+        public void Measure_PartialRender_RightToLeft()
+        {
+            TestPlan
+                .For(x => new MinimalBox
+                {
+                    Child = x.CreateChild(),
+                    ContentDirection = ContentDirection.RightToLeft
+                })
+                .MeasureElement(new Size(400, 300))
+                .ExpectChildMeasure(expectedInput: new Size(400, 300), returns: SpacePlan.PartialRender(200, 100))
+                .ExpectCanvasTranslate(200, 0)
+                .ExpectChildDraw(new Size(200, 100))
+                .ExpectCanvasTranslate(-200, 0)
+                .CheckDrawResult();
+        }
+        
+        [Test]
+        public void Measure_FullRender_RightToLeft()
+        {
+            TestPlan
+                .For(x => new MinimalBox
+                {
+                    Child = x.CreateChild(),
+                    ContentDirection = ContentDirection.RightToLeft
+                })
+                .MeasureElement(new Size(500, 400))
+                .ExpectChildMeasure(expectedInput: new Size(500, 400), returns: SpacePlan.FullRender(350, 200))
+                .ExpectCanvasTranslate(150, 0)
+                .ExpectChildDraw(new Size(350, 200))
+                .ExpectCanvasTranslate(-150, 0)
                 .CheckDrawResult();
         }
     }

+ 38 - 0
QuestPDF.UnitTests/UnconstrainedTests.cs

@@ -77,7 +77,9 @@ namespace QuestPDF.UnitTests
                 })
                 .DrawElement(new Size(900, 800))
                 .ExpectChildMeasure(Size.Max, SpacePlan.PartialRender(1200, 1600))
+                .ExpectCanvasTranslate(0, 0)
                 .ExpectChildDraw(new Size(1200, 1600))
+                .ExpectCanvasTranslate(0, 0)
                 .CheckDrawResult();
         }
         
@@ -91,7 +93,43 @@ namespace QuestPDF.UnitTests
                 })
                 .DrawElement(new Size(900, 800))
                 .ExpectChildMeasure(Size.Max, SpacePlan.FullRender(1600, 1000))
+                .ExpectCanvasTranslate(0, 0)
                 .ExpectChildDraw(new Size(1600, 1000))
+                .ExpectCanvasTranslate(0, 0)
+                .CheckDrawResult();
+        }
+        
+        [Test]
+        public void Draw_WhenChildPartiallyRenders_RightToLeft()
+        {
+            TestPlan
+                .For(x => new Unconstrained
+                {
+                    Child = x.CreateChild(),
+                    ContentDirection = ContentDirection.RightToLeft
+                })
+                .DrawElement(new Size(900, 800))
+                .ExpectChildMeasure(Size.Max, SpacePlan.PartialRender(1200, 1600))
+                .ExpectCanvasTranslate(-1200, 0)
+                .ExpectChildDraw(new Size(1200, 1600))
+                .ExpectCanvasTranslate(1200, 0)
+                .CheckDrawResult();
+        }
+        
+        [Test]
+        public void Draw_WhenChildFullyRenders_RightToLeft()
+        {
+            TestPlan
+                .For(x => new Unconstrained
+                {
+                    Child = x.CreateChild(),
+                    ContentDirection = ContentDirection.RightToLeft
+                })
+                .DrawElement(new Size(900, 800))
+                .ExpectChildMeasure(Size.Max, SpacePlan.FullRender(1600, 1000))
+                .ExpectCanvasTranslate(-1600, 0)
+                .ExpectChildDraw(new Size(1600, 1000))
+                .ExpectCanvasTranslate(1600, 0)
                 .CheckDrawResult();
         }