public void FaceReductionTest_AllDifferent() { // add a ballot style with 2 contests, each contest has 2 candidates // ballot style 1 // contest 1 // candidate 1 // candidate 2 // contest 2 // candidate 3 // candidate 4 this.mockData.AddStpBallotContest(1, 1, 1, 0, 2, 1); // add a page break on this contest to place it entirely on another // face. (contest display format == 1 means page break) this.mockData.AddStpBallotContest(1, 2, 2, 1, 2, 3); // add a second ballot style // ballot style 2 // contest 1 // candidate 1 // candidate 2 // contest 3 // candidate 5 // candidate 6 this.mockData.AddStpBallotContest(2, 1, 1, 0, 2, 1); // add a page break on this contest to place it entirely on another // face. At this point, front faces are identical for both ballots // back faces are not this.mockData.AddStpBallotContest(2, 3, 3, 1, 2, 5); // now add header texts for all contests // 3 contests, 1 text per contest, first id is 1 this.mockData.AddStpContBallot(new int[] { 1, 1, 1 }, 1); // add candidate texts for all candidates // 6 candidates total, first candidate id is 1 this.mockData.AddStpCandBallot(6, 1); // load parameters from DB this.mockData.LoadStpParams(); this.mockData.SetTarget(0.12, 0.08, 0, 0, 0.0035, 100); // make sure the barcode location is on the front of the paper // take the parameters entry set and set the IdentifierLocation // parameter to Front BallotPdfTestObject.SetIdentifierFace( this.mockData.parameters, PaperSide.Front); // make sure that at least 1 field is included on the barcode BallotPdfTestObject.SetIdentifierMask(this.mockData.parameters, 1); // create paper ballot objects for both ballot styles PaperBallot ballot1 = new PaperBallot( this.mockData.ballots, this.mockData.contests, this.mockData.candidates, this.mockData.parameters, this.mockData.target, 1, 0, 0), // for the second ballot, we already have 1 card and // 2 faces ballot2 = new PaperBallot( this.mockData.ballots, this.mockData.contests, this.mockData.candidates, this.mockData.parameters, this.mockData.target, 2, 1, 2); // create a paper binder PaperBinder binder = new PaperBinder(); binder.AddBallot(ballot1); binder.AddBallot(ballot2); binder.Generate(OutputFolder); // wait a few seconds to let the PDF library flush all docs System.Threading.Thread.Sleep(4000); string[] files = Directory.GetFiles(OutputFolder, "*.pdf"); Assert.AreEqual(4, files.Length); }
public void FaceReductionTest_OddFacesWithBarcodeInTheBack() { // add a ballot style with 2 contests, each contest has 2 candidates // ballot style 3 // contest 1 // candidate 1 // candidate 2 // contest 2 // candidate 3 // candidate 4 this.mockData.AddStpBallotContest(3, 1, 1, 0, 2, 1); // add a page break on this contest to place it entirely on another // face. (contest display format == 1 means page break) this.mockData.AddStpBallotContest(3, 2, 2, 1, 2, 3); // add a second ballot style // ballot style 4 // contest 1 // candidate 1 // candidate 2 // contest 3 // candidate 5 // candidate 6 this.mockData.AddStpBallotContest(4, 1, 1, 0, 2, 1); // add a page break on this contest to place it entirely on another // face. At this point, front faces are identical for both ballots // back faces are not this.mockData.AddStpBallotContest(4, 3, 3, 1, 2, 5); // add a third face to test that a 4th empty face is added just for // the barcode this.mockData.AddStpBallotContest(4, 4, 4, 1, 10, 7); // now add header texts for all contests // 4 contests, 1 text per contest, first id is 1 this.mockData.AddStpContBallot(new int[] { 1, 1, 1, 1 }, 1); // add candidate texts for all candidates // 16 candidates total, first candidate id is 1 this.mockData.AddStpCandBallot(16, 1); // load parameters from DB this.mockData.LoadStpParams(); this.mockData.SetTarget(0.12, 0.08, 0, 0, 0.0035, 100); // make sure the barcode location is on the back of the paper BallotPdfTestObject.SetIdentifierFace( this.mockData.parameters, PaperSide.Back); // make sure that at least 1 field is included on the barcode BallotPdfTestObject.SetIdentifierMask(this.mockData.parameters, 1); int cardCount = 0, faceCount = 0; // create paper ballot objects for both ballot styles PaperBallot ballot1 = new PaperBallot( this.mockData.ballots, this.mockData.contests, this.mockData.candidates, this.mockData.parameters, this.mockData.target, 3, cardCount, faceCount); // for the second ballot, we already have 1 card and 2 faces cardCount += ballot1.CardCount; faceCount += ballot1.FaceCount; PaperBallot ballot2 = new PaperBallot( this.mockData.ballots, this.mockData.contests, this.mockData.candidates, this.mockData.parameters, this.mockData.target, 4, cardCount, faceCount); // create a paper binder PaperBinder binder = new PaperBinder(); binder.AddBallot(ballot1); binder.AddBallot(ballot2); binder.Generate(OutputFolder); // wait a few seconds to let the PDF library flush all docs System.Threading.Thread.Sleep(4000); string[] files = Directory.GetFiles(OutputFolder, "*.pdf"); // 1 face is reused, and 1 blank face is added so 5 files // should be found Assert.AreEqual(5, files.Length); }
public void FaceReductionTest_OddFacesWithBarcodeInTheBack() { // add a ballot style with 2 contests, each contest has 2 candidates // ballot style 1 // contest 1 // candidate 1 // candidate 2 // contest 2 // candidate 3 // candidate 4 this.objTest.AddStpBallotContest(1, 1, 1, 0, 2, 1); // add a page break on this contest to place it entirely on another // face. (contest display format == 1 means page break) this.objTest.AddStpBallotContest(1, 2, 2, 1, 2, 3); // add a second ballot style // ballot style 2 // contest 1 // candidate 1 // candidate 2 // contest 3 // candidate 5 // candidate 6 this.objTest.AddStpBallotContest(2, 1, 1, 0, 2, 1); // add a page break on this contest to place it entirely on another // face. At this point, front faces are identical for both ballots // back faces are not this.objTest.AddStpBallotContest(2, 3, 3, 1, 2, 5); // add a third face to test that a 4th empty face is added just for // the barcode this.objTest.AddStpBallotContest(2, 4, 4, 1, 10, 7); // now add header texts for all contests // 4 contests, 1 text per contest, first id is 1 this.objTest.AddStpContBallot(new int[] { 1, 1, 1, 1 }, 1); // add candidate texts for all candidates // 16 candidates total, first candidate id is 1 this.objTest.AddStpCandBallot(16, 1); // load parameters from DB this.objTest.LoadStpParams(); this.objTest.SetTarget(0.12, 0.08, 0, 0, 0.0035, 100); // make sure the barcode location is on the back of the paper BallotPdfTestObject.SetIdentifierFace( this.objTest.parameters, PaperSide.Back); // make sure that at least 1 field is included on the barcode BallotPdfTestObject.SetIdentifierMask(this.objTest.parameters, 1); // create paper ballot objects for both ballot styles PaperBallot ballot1 = new PaperBallot( this.objTest.ballots, this.objTest.contests, this.objTest.candidates, this.objTest.parameters, this.objTest.target, 1, 1, 1), // for the second ballot, we already have 1 card and // 2 faces ballot2 = new PaperBallot( this.objTest.ballots, this.objTest.contests, this.objTest.candidates, this.objTest.parameters, this.objTest.target, 2, 2, 3); ballot1.Precinct = 1; ballot2.Precinct = 2; // create a definition binder and add both ballots // the definition binder should be smart enough to notice that the // first face of both ballot cards are identical, resulting in only // 3 faces for 2 cards, 1 card per ballot DefinitionBinder binder = new DefinitionBinder(); binder.AddBallot(ballot1.ExportPositions()); binder.AddBallot(ballot2.ExportPositions()); // generated PDFs to manually compare barcodes PaperBinder binder2 = new PaperBinder(); binder2.AddBallot(ballot1); binder2.AddBallot(ballot2); binder2.Generate(@"..\..\TestData"); // save files for further inspection this.objTest.Serialize( @"..\..\TestData\Ballots.B.xml", binder.Ballots, typeof(BallotList)); this.objTest.Serialize( @"..\..\TestData\Cards.B.xml", binder.Cards, typeof(CardList)); this.objTest.Serialize( @"..\..\TestData\Faces.B.xml", binder.Faces, typeof(FaceList)); // check the results // 3 faces expected, not 4 even though there are 2 cards, // 2 faces each Assert.AreEqual(5, binder.Faces.Count); // 3 cards, 1 + 2 Assert.AreEqual(3, binder.Cards.Count); // the second face of both cards are the same Assert.AreEqual(binder.Cards[0].Faces[1].Id, binder.Cards[1].Faces[1].Id); // verify face ids Assert.AreEqual(1, binder.Cards[0].Faces[0].Id); Assert.AreEqual(2, binder.Cards[0].Faces[1].Id); // the second card reuses the first face Assert.AreEqual(3, binder.Cards[1].Faces[0].Id); Assert.AreEqual(2, binder.Cards[1].Faces[1].Id); Assert.AreEqual(5, binder.Cards[2].Faces[0].Id); // an additional blank face just for the barcode Assert.AreEqual(6, binder.Cards[2].Faces[1].Id); // verify card ids Assert.AreEqual(1, binder.Cards[0].Id); Assert.AreEqual(2, binder.Cards[1].Id); Assert.AreEqual(3, binder.Cards[2].Id); // verify ballot ids Assert.AreEqual(1, binder.Ballots[0].Id); Assert.AreEqual(2, binder.Ballots[1].Id); }