Ejemplo n.º 1
0
        public void TestDuplicatePLS_bug47415()
        {
            NPOI.HSSF.Record.Record plsA = ur(UnknownRecord.PLS_004D, "BA AD F0 0D");
            NPOI.HSSF.Record.Record plsB = ur(UnknownRecord.PLS_004D, "DE AD BE EF");
            NPOI.HSSF.Record.Record contB1 = new ContinueRecord(HexRead.ReadFromString("FE ED"));
            NPOI.HSSF.Record.Record contB2 = new ContinueRecord(HexRead.ReadFromString("FA CE"));
            NPOI.HSSF.Record.Record[] recs = {
				new HeaderRecord("&LSales Figures"),
				new FooterRecord("&LInventory"),
				new HCenterRecord(),
				new VCenterRecord(),
				plsA,
				plsB, contB1, contB2, // make sure continuing PLS is still OK
		};
            RecordStream rs = new RecordStream(Arrays.AsList(recs), 0);
            PageSettingsBlock psb;
            try
            {
                psb = new PageSettingsBlock(rs);
            }
            catch (RecordFormatException e)
            {
                if ("Duplicate PageSettingsBlock record (sid=0x4d)".Equals(e.Message))
                {
                    throw new AssertionException("Identified bug 47415");
                }
                throw e;
            }

            // serialize the PSB to see what records come out
            RecordInspector.RecordCollector rc = new RecordInspector.RecordCollector();
            psb.VisitContainedRecords(rc);
            NPOI.HSSF.Record.Record[] outRecs = rc.Records;

            // records were assembled in standard order, so this simple check is OK
            Assert.IsTrue(Arrays.Equals(recs, outRecs));
        }
Ejemplo n.º 2
0
        public void TestMissingHeaderFooter()
        {
            // Initialise PSB with some records, but not the header / footer
            NPOI.HSSF.Record.Record[] recs = {
				new HCenterRecord(),
				new VCenterRecord(),
		};
            RecordStream rs = new RecordStream(Arrays.AsList(recs), 0);
            PageSettingsBlock psb = new PageSettingsBlock(rs);

            // serialize the PSB to see what records come out
            RecordInspector.RecordCollector rc = new RecordInspector.RecordCollector();
            psb.VisitContainedRecords(rc);
            NPOI.HSSF.Record.Record[] outRecs = rc.Records;

            if (outRecs.Length == 2)
            {
                throw new AssertionException("PageSettingsBlock didn't add missing header/footer records");
            }
            Assert.AreEqual(4, outRecs.Length);
            Assert.AreEqual(typeof(HeaderRecord), outRecs[0].GetType());
            Assert.AreEqual(typeof(FooterRecord), outRecs[1].GetType());
            Assert.AreEqual(typeof(HCenterRecord), outRecs[2].GetType());
            Assert.AreEqual(typeof(VCenterRecord), outRecs[3].GetType());

            // make sure the Added header / footer records are empty
            HeaderRecord hr = (HeaderRecord)outRecs[0];
            Assert.AreEqual("", hr.Text);
            FooterRecord fr = (FooterRecord)outRecs[1];
            Assert.AreEqual("", fr.Text);
        }