| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788 |
- namespace QuestPDF.LayoutTests;
- [TestFixture]
- public class RowTests
- {
- #region General Item Positioning
-
- [Test]
- public void SingleConstantItem()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.ConstantItem(40).Mock("a").Height(30);
- });
- })
- .ExpectDrawResult(document =>
- {
- document
- .Page()
- .RequiredAreaSize(40, 30)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(40, 30);
- });
- });
- }
-
- [Test]
- public void MultipleConstantItems()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.ConstantItem(20).Mock("a").Height(30);
- row.ConstantItem(30).Mock("b").Height(40);
- row.ConstantItem(40).Mock("c").Height(20);
- });
- })
- .ExpectDrawResult(document =>
- {
- document
- .Page()
- .RequiredAreaSize(90, 40)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(20, 40);
- page.Mock("b").Position(20, 0).Size(30, 40);
- page.Mock("c").Position(50, 0).Size(40, 40);
- });
- });
- }
-
- [Test]
- public void SingleRelativeItem()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.RelativeItem().Mock("a").Height(30);
- });
- })
- .ExpectDrawResult(document =>
- {
- document
- .Page()
- .RequiredAreaSize(100, 30)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(100, 30);
- });
- });
- }
-
- [Test]
- public void TwoRelativeItems()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.RelativeItem(2).Mock("a").Height(40);
- row.RelativeItem(3).Mock("b").Height(50);
- });
- })
- .ExpectDrawResult(document =>
- {
- document
- .Page()
- .RequiredAreaSize(100, 50)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(40, 50);
- page.Mock("b").Position(40, 0).Size(60, 50);
- });
- });
- }
-
- [Test]
- public void SingleAutoItem()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.AutoItem().Mock("a").Size(60, 40);
- });
- })
- .ExpectDrawResult(document =>
- {
- document
- .Page()
- .RequiredAreaSize(60, 40)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(60, 40);
- });
- });
- }
-
- [Test]
- public void RelativeItemFillsRemainingSpace()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.ConstantItem(20).Mock("a").Height(30);
- row.ConstantItem(30).Mock("b").Height(50);
- row.RelativeItem().Mock("c").Height(40);
- });
- })
- .ExpectDrawResult(document =>
- {
- document
- .Page()
- .RequiredAreaSize(100, 50)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(20, 50);
- page.Mock("b").Position(20, 0).Size(30, 50);
- page.Mock("c").Position(50, 0).Size(50, 50);
- });
- });
- }
-
- [Test]
- public void RelativeItemsSplitRemainingSpaceAccordingToProportions()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.ConstantItem(30).Mock("a").Height(60);
- row.RelativeItem(4).Mock("b").Height(40);
- row.RelativeItem(3).Mock("c").Height(30);
- });
- })
- .ExpectDrawResult(document =>
- {
- document
- .Page()
- .RequiredAreaSize(100, 60)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(30, 60);
- page.Mock("b").Position(30, 0).Size(40, 60);
- page.Mock("c").Position(70, 0).Size(30, 60);
- });
- });
- }
-
- [Test]
- public void ComplexItems()
- {
- LayoutTest
- .HavingSpaceOfSize(200, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.ConstantItem(30).Mock("a").Height(60);
- row.RelativeItem(1).Mock("b").Height(40);
- row.RelativeItem(2).Mock("c").Height(30);
- row.ConstantItem(20).Mock("d").Height(30);
- row.RelativeItem(3).Mock("e").Height(20);
- row.RelativeItem(2).Mock("f").Height(70);
- row.AutoItem().Mock("g").Size(40, 50);
- row.AutoItem().Mock("h").Size(30, 40);
- });
- })
- .ExpectDrawResult(document =>
- {
- document
- .Page()
- .RequiredAreaSize(200, 70)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(30, 70);
- page.Mock("b").Position(30, 0).Size(10, 70);
- page.Mock("c").Position(40, 0).Size(20, 70);
- page.Mock("d").Position(60, 0).Size(20, 70);
- page.Mock("e").Position(80, 0).Size(30, 70);
- page.Mock("f").Position(110, 0).Size(20, 70);
- page.Mock("g").Position(130, 0).Size(40, 70);
- page.Mock("h").Position(170, 0).Size(30, 70);
- });
- });
- }
-
- #endregion
-
- #region Drawing On Multiple Pages
-
- [Test]
- public void OneItemSpansTwoPages()
- {
- LayoutTest
- .HavingSpaceOfSize(80, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.RelativeItem().Mock("a").SolidBlock(height: 40);
- row.RelativeItem().Mock("b").SolidBlock(height: 80);
- row.RelativeItem(2).Mock("c").ContinuousBlock(20, 140);
- });
- })
- .ExpectDrawResult(document =>
- {
- document
- .Page()
- .RequiredAreaSize(80, 100)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(20, 100);
- page.Mock("b").Position(20, 0).Size(20, 100);
- page.Mock("c").Position(40, 0).Size(40, 100);
- });
-
- document
- .Page()
- .RequiredAreaSize(80, 40)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(20, 40);
- page.Mock("b").Position(20, 0).Size(20, 40);
- page.Mock("c").Position(40, 0).Size(40, 40);
- });
- });
- }
-
- #endregion
- #region Spacing
- [Test]
- public void NoSpacing()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.ConstantItem(10).Mock("a").SolidBlock(height: 40);
- row.ConstantItem(20).Mock("b").SolidBlock(height: 50);
- row.ConstantItem(30).Mock("c").SolidBlock(height: 30);
- });
- })
- .ExpectDrawResult(document =>
- {
- document
- .Page()
- .RequiredAreaSize(60, 50)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(10, 50);
- page.Mock("b").Position(10, 0).Size(20, 50);
- page.Mock("c").Position(30, 0).Size(30, 50);
- });
- });
- }
-
- [Test]
- public void NormalSpacing()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.Spacing(10);
-
- row.ConstantItem(10).Mock("a").SolidBlock(height: 40);
- row.ConstantItem(20).Mock("b").SolidBlock(height: 50);
- row.ConstantItem(30).Mock("c").SolidBlock(height: 30);
- });
- })
- .ExpectDrawResult(document =>
- {
- document
- .Page()
- .RequiredAreaSize(80, 50)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(10, 50);
- page.Mock("b").Position(20, 0).Size(20, 50);
- page.Mock("c").Position(50, 0).Size(30, 50);
- });
- });
- }
-
- [Test]
- public void BiggerSpacing()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.Spacing(15);
-
- row.ConstantItem(10).Mock("a").SolidBlock(height: 40);
- row.ConstantItem(20).Mock("b").SolidBlock(height: 50);
- row.ConstantItem(30).Mock("c").SolidBlock(height: 30);
- });
- })
- .ExpectDrawResult(document =>
- {
- document
- .Page()
- .RequiredAreaSize(90, 50)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(10, 50);
- page.Mock("b").Position(25, 0).Size(20, 50);
- page.Mock("c").Position(60, 0).Size(30, 50);
- });
- });
- }
-
- [Test]
- public void SpacingDoesNotFitInAvailableSpace()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.Spacing(20);
- row.ConstantItem(30).Height(50);
- row.ConstantItem(30).Height(50);
- row.ConstantItem(30).Height(50);
- });
- })
- .ExpectLayoutException("The content requires more horizontal space than available.");
- }
-
- [Test]
- public void SpacingIsLargerThanAvailableSpace()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.Spacing(200);
-
- row.ConstantItem(10).SolidBlock(height: 40); // <-
- });
- })
- .ExpectLayoutException("The content requires more horizontal space than available.");
- }
-
- [Test]
- public void NotEnoughSpaceForRelativeItemsAfterApplyingSpacing()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.Spacing(20);
-
- row.ConstantItem(40);
- row.ConstantItem(40);
- row.RelativeItem();
- });
- })
- .ExpectLayoutException("One of the items has a negative size, indicating insufficient horizontal space. Usually, constant items require more space than is available, potentially causing other content to overflow.");
- }
- #endregion
-
- #region Paging
-
- [Test]
- public void OneItemRequiresTwoPages()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.RelativeItem(2).Mock("a").Height(30);
- row.RelativeItem(3).Mock("b").ContinuousBlock(height: 140);
- });
- })
- .ExpectDrawResult(document =>
- {
- document
- .Page()
- .RequiredAreaSize(100, 100)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(40, 100);
- page.Mock("b").Position(40, 0).Size(60, 100);
- });
-
- document
- .Page()
- .RequiredAreaSize(100, 40)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(40, 40);
- page.Mock("b").Position(40, 0).Size(60, 40);
- });
- });
- }
-
- [Test]
- public void ItemsRequireMultiplePages()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.RelativeItem(2).Mock("a").ContinuousBlock(height: 230);
- row.RelativeItem(3).Mock("b").ContinuousBlock(height: 140);
- });
- })
- .ExpectDrawResult(document =>
- {
- document
- .Page()
- .RequiredAreaSize(100, 100)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(40, 100);
- page.Mock("b").Position(40, 0).Size(60, 100);
- });
-
- document
- .Page()
- .RequiredAreaSize(100, 100)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(40, 100);
- page.Mock("b").Position(40, 0).Size(60, 100);
- });
-
- document
- .Page()
- .RequiredAreaSize(100, 30)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(40, 30);
- page.Mock("b").Position(40, 0).Size(60, 30);
- });
- });
- }
-
- [Test]
- public void ItemHeightExceedsAvailableHeight()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.ConstantItem(40).Height(50);
- row.ConstantItem(40).Height(200); // <-
- });
- })
- .ExpectLayoutException("The available vertical space is less than the minimum height.");
- }
-
- #endregion
-
- #region Right-To-Left Direction
-
- [Test]
- public void RightToLeftDirection()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.ContentFromRightToLeft().Shrink().Row(row =>
- {
- row.ConstantItem(20).Mock("a").Height(30);
- row.ConstantItem(30).Mock("b").Height(40);
- row.ConstantItem(40).Mock("c").Height(20);
- });
- })
- .ExpectDrawResult(document =>
- {
- document
- .Page()
- .RequiredAreaSize(90, 40)
- .Content(page =>
- {
- page.Mock("a").Position(80, 0).Size(20, 40);
- page.Mock("b").Position(50, 0).Size(30, 40);
- page.Mock("c").Position(10, 0).Size(40, 40);
- });
- });
- }
-
- #endregion
-
- #region Layout Exceptions
-
- [Test]
- public void ConstantItemOfTooLargeSize()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.ConstantItem(200); // <-
- });
- })
- .ExpectLayoutException("The content requires more horizontal space than available.");
- }
-
- [Test]
- public void ConstantItemHasChildOfTooLargeSize()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.ConstantItem(30).Width(20);
- row.ConstantItem(40).Width(200); // <-
- });
- })
- .ExpectLayoutException("The available horizontal space is less than the minimum width.");
- }
-
- [Test]
- public void SumOfConstantItemsExceedsAvailableWidth()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.ConstantItem(40);
- row.ConstantItem(40);
- row.ConstantItem(40);
- });
- })
- .ExpectLayoutException("The content requires more horizontal space than available.");
- }
-
- [Test]
- public void RelativeItemHasChildOfTooLargeSize()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.RelativeItem(2).Width(30);
- row.RelativeItem(3).Width(200); // <-
- });
- })
- .ExpectLayoutException("The available horizontal space is less than the minimum width.");
- }
-
- [Test]
- public void AutoItemHasChildOfTooLargeSize()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.ConstantItem(30);
- row.AutoItem().Width(80);
- });
- })
- .ExpectLayoutException("The content requires more horizontal space than available.");
- }
-
- [Test]
- public void SumOfAutoItemsExceedsAvailableWidth()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.AutoItem().Width(30);
- row.AutoItem().Width(40);
- row.AutoItem().Width(50);
- });
- })
- .ExpectLayoutException("The content requires more horizontal space than available.");
- }
-
- [Test]
- public void SumOfVariousItemsExceedsAvailableWidth()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.ConstantItem(60);
- row.AutoItem().Width(50);
- });
- })
- .ExpectLayoutException("The content requires more horizontal space than available.");
- }
-
- #endregion
-
- #region Corner Cases
-
- [Test]
- public void NoItems()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- // <-
- });
- })
- .ExpectDrawResult(document =>
- {
- document
- .Page()
- .RequiredAreaSize(0, 0)
- .Content(page => { });
- });
- }
-
- [Test]
- public void RerenderingOfFullyDrawnRow()
- {
- LayoutTest
- .HavingSpaceOfSize(100, 100)
- .ForContent(content =>
- {
- content.Shrink().Row(row =>
- {
- row.RelativeItem().Mock("a").Row(innerRow =>
- {
- innerRow.RelativeItem().Mock("b").SolidBlock(20, 50);
- innerRow.RelativeItem().Mock("c").SolidBlock(15, 40);
- });
-
- row.RelativeItem().Mock("d").ContinuousBlock(40, 140);
- });
- })
- .ExpectDrawResult(document =>
- {
- document
- .Page()
- .RequiredAreaSize(100, 100)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(50, 100);
- page.Mock("b").Position(0, 0).Size(25, 100);
- page.Mock("c").Position(25, 0).Size(25, 100);
- page.Mock("d").Position(50, 0).Size(50, 100);
- });
-
- document
- .Page()
- .RequiredAreaSize(100, 40)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(50, 40);
- page.Mock("d").Position(50, 0).Size(50, 40);
- });
- });
- }
-
- #endregion
-
- #region Stateful
-
- [Test]
- public void CheckRenderingState()
- {
- LayoutTest
- .HavingSpaceOfSize(240, 100)
- .ForContent(content =>
- {
- content.Shrink().Mock("a").Row(innerRow =>
- {
- innerRow.RelativeItem().ContinuousBlock(50, 80);
- innerRow.RelativeItem().ContinuousBlock(50, 250);
- innerRow.RelativeItem().ContinuousBlock(50, 170);
- innerRow.RelativeItem().ContinuousBlock(50, 320);
- });
- })
- .ExpectDrawResult(document =>
- {
- document
- .Page()
- .RequiredAreaSize(240, 100)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(240, 100).State(new[] { true, false, false, false });
- });
-
- document
- .Page()
- .RequiredAreaSize(240, 100)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(240, 100).State(new[] { true, false, true, false });
- });
-
- document
- .Page()
- .RequiredAreaSize(240, 100)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(240, 100).State(new[] { true, true, true, false });
- });
-
- document
- .Page()
- .RequiredAreaSize(240, 20)
- .Content(page =>
- {
- page.Mock("a").Position(0, 0).Size(240, 20).State(new[] { true, true, true, true });
- });
- });
- }
-
- #endregion
- }
|