public void TestMovingMergedRegion() { List <Record> records = new List <Record>(); CellRangeAddress[] cras = { new CellRangeAddress(0, 1, 0, 2), }; MergeCellsRecord merged = new MergeCellsRecord(cras, 0, cras.Length); records.Add(BOFRecord.CreateSheetBOF()); records.Add(new DimensionsRecord()); records.Add(new RowRecord(0)); records.Add(new RowRecord(1)); records.Add(new RowRecord(2)); records.Add(CreateWindow2Record()); records.Add(EOFRecord.instance); records.Add(merged); InternalSheet sheet = CreateSheet(records); sheet.Records.RemoveAt(0); //stub object to throw off list INDEX operations sheet.RemoveMergedRegion(0); Assert.AreEqual(0, sheet.NumMergedRegions, "Should be no more merged regions"); }
public void TestNonZeroPadding_bug46987() { Record[] recs = { new BOFRecord(), new WriteAccessRecord(), // need *something* between BOF and EOF EOFRecord.instance, BOFRecord.CreateSheetBOF(), EOFRecord.instance, }; MemoryStream baos = new MemoryStream(); for (int i = 0; i < recs.Length; i++) { byte[] data = recs[i].Serialize(); baos.Write(data, 0, data.Length); } //simulate the bad padding at the end of the workbook stream in attachment 23483 of bug 46987 baos.WriteByte(0x00); baos.WriteByte(0x11); baos.WriteByte(0x00); baos.WriteByte(0x02); for (int i = 0; i < 192; i++) { baos.WriteByte(0x00); } POIFSFileSystem fs = new POIFSFileSystem(); Stream is1; fs.CreateDocument(new MemoryStream(baos.ToArray()), "dummy"); is1 = fs.Root.CreatePOIFSDocumentReader("dummy"); List <Record> outRecs; try { outRecs = RecordFactory.CreateRecords(is1); } catch (Exception e) { if (e.Message.Equals("Buffer underrun - requested 512 bytes but 192 was available")) { throw new AssertionException("Identified bug 46987"); } throw e; } Assert.AreEqual(5, outRecs.Count); }
public void TestHeaderFooter_bug46840() { int rowIx = 5; int colIx = 6; NumberRecord nr = new NumberRecord(); nr.Row = (rowIx); nr.Column = ((short)colIx); nr.Value = (3.0); NPOI.HSSF.Record.Record[] recs = { BOFRecord.CreateSheetBOF(), new HeaderRecord("&LSales Figures"), new FooterRecord("&LJanuary"), new HeaderFooterRecord(HexRead.ReadFromString("9C 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 C4 60 00 00 00 00 00 00 00 00")), new DimensionsRecord(), new WindowTwoRecord(), new UserSViewBegin(HexRead.ReadFromString("ED 77 3B 86 BC 3F 37 4C A9 58 60 23 43 68 54 4B 01 00 00 00 64 00 00 00 40 00 00 00 02 00 00 00 3D 80 04 00 00 00 00 00 00 00 0C 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F0 3F FF FF 01 00")), new HeaderRecord("&LSales Figures"), new FooterRecord("&LJanuary"), new HeaderFooterRecord(HexRead.ReadFromString("9C 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 C4 60 00 00 00 00 00 00 00 00")), new UserSViewEnd(HexRead.ReadFromString("01, 00")), EOFRecord.instance, }; RecordStream rs = new RecordStream(Arrays.AsList(recs), 0); InternalSheet sheet; try { sheet = InternalSheet.CreateSheet(rs); } catch (Exception e) { if (e.Message.Equals("two Page Settings Blocks found in the same sheet")) { throw new AssertionException("Identified bug 46480"); } throw e; } TestCases.HSSF.UserModel.RecordInspector.RecordCollector rv = new TestCases.HSSF.UserModel.RecordInspector.RecordCollector(); sheet.VisitContainedRecords(rv, rowIx); NPOI.HSSF.Record.Record[] outRecs = rv.Records; Assert.AreEqual(13, outRecs.Length); }
public void TestMissingDims() { int rowIx = 5; int colIx = 6; NumberRecord nr = new NumberRecord(); nr.Row = (rowIx); nr.Column = ((short)colIx); nr.Value = (3.0); List <Record> inRecs = new List <Record>(); inRecs.Add(BOFRecord.CreateSheetBOF()); inRecs.Add(new RowRecord(rowIx)); inRecs.Add(nr); inRecs.Add(CreateWindow2Record()); inRecs.Add(EOFRecord.instance); InternalSheet sheet; try { sheet = CreateSheet(inRecs); } catch (Exception e) { if ("DimensionsRecord was not found".Equals(e.Message)) { throw new AssertionException("Identified bug 46206"); } throw e; } RecordInspector.RecordCollector rv = new RecordInspector.RecordCollector(); sheet.VisitContainedRecords(rv, rowIx); Record[] outRecs = rv.Records; Assert.AreEqual(8, outRecs.Length); DimensionsRecord dims = (DimensionsRecord)outRecs[5]; Assert.AreEqual(rowIx, dims.FirstRow); Assert.AreEqual(rowIx, dims.LastRow); Assert.AreEqual(colIx, dims.FirstCol); Assert.AreEqual(colIx, dims.LastCol); }
public void TestUncalcSize_bug45066() { List <Record> records = new List <Record>(); records.Add(BOFRecord.CreateSheetBOF()); records.Add(new UncalcedRecord()); records.Add(new DimensionsRecord()); records.Add(CreateWindow2Record()); records.Add(new EOFRecord()); InternalSheet sheet = CreateSheet(records); // The original bug was due to different logic for collecting records for sizing and // serialization. The code has since been refactored into a single method for visiting // all contained records. Now this Test is much less interesting SizeCheckingRecordVisitor scrv = new SizeCheckingRecordVisitor(); sheet.VisitContainedRecords(scrv, 0); Assert.AreEqual(90, scrv.TotalSize); }
public void TestLateMargins_bug47199() { NPOI.HSSF.Record.Record[] recs = { BOFRecord.CreateSheetBOF(), new HeaderRecord("&LSales Figures"), new FooterRecord("&LJanuary"), new DimensionsRecord(), CreateBottomMargin(0.787F), new WindowTwoRecord(), EOFRecord.instance, }; RecordStream rs = new RecordStream(Arrays.AsList(recs), 0); InternalSheet sheet; try { sheet = InternalSheet.CreateSheet(rs); } catch (Exception e) { if (e.Message.Equals("two Page Settings Blocks found in the same sheet")) { throw new AssertionException("Identified bug 47199a - failed to process late margings records"); } throw e; } TestCases.HSSF.UserModel.RecordInspector.RecordCollector rv = new TestCases.HSSF.UserModel.RecordInspector.RecordCollector(); sheet.VisitContainedRecords(rv, 0); NPOI.HSSF.Record.Record[] outRecs = rv.Records; Assert.AreEqual(recs.Length + 1, outRecs.Length); // +1 for index record Assert.AreEqual(typeof(BOFRecord), outRecs[0].GetType()); Assert.AreEqual(typeof(IndexRecord), outRecs[1].GetType()); Assert.AreEqual(typeof(HeaderRecord), outRecs[2].GetType()); Assert.AreEqual(typeof(FooterRecord), outRecs[3].GetType()); Assert.AreEqual(typeof(DimensionsRecord), outRecs[5].GetType()); Assert.AreEqual(typeof(WindowTwoRecord), outRecs[6].GetType()); Assert.AreEqual(typeof(EOFRecord), outRecs[7].GetType()); }
public void TestLateHeaderFooter_bug46953() { int rowIx = 5; int colIx = 6; NumberRecord nr = new NumberRecord(); nr.Row = (rowIx); nr.Column = ((short)colIx); nr.Value = (3.0); NPOI.HSSF.Record.Record[] recs = { BOFRecord.CreateSheetBOF(), new HeaderRecord("&LSales Figures"), new FooterRecord("&LJanuary"), new DimensionsRecord(), new WindowTwoRecord(), new HeaderFooterRecord(HexRead.ReadFromString("9C 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 C4 60 00 00 00 00 00 00 00 00")), EOFRecord.instance, }; RecordStream rs = new RecordStream(Arrays.AsList(recs), 0); InternalSheet sheet = InternalSheet.CreateSheet(rs); RecordInspector.RecordCollector rv = new RecordInspector.RecordCollector(); sheet.VisitContainedRecords(rv, 0); NPOI.HSSF.Record.Record[] outRecs = rv.Records; if (outRecs[4] == EOFRecord.instance) { throw new AssertionException("Identified bug 46953 - EOF incorrectly Appended to PSB"); } Assert.AreEqual(recs.Length + 1, outRecs.Length); // +1 for index record Assert.AreEqual(typeof(BOFRecord), outRecs[0].GetType()); Assert.AreEqual(typeof(IndexRecord), outRecs[1].GetType()); Assert.AreEqual(typeof(HeaderRecord), outRecs[2].GetType()); Assert.AreEqual(typeof(FooterRecord), outRecs[3].GetType()); Assert.AreEqual(typeof(HeaderFooterRecord), outRecs[4].GetType()); Assert.AreEqual(typeof(DimensionsRecord), outRecs[5].GetType()); Assert.AreEqual(typeof(WindowTwoRecord), outRecs[6].GetType()); Assert.AreEqual(typeof(EOFRecord), outRecs[7].GetType()); }
public void TestCreateSheet() { // Check we're Adding row and cell aggregates List <Record> records = new List <Record>(); records.Add(BOFRecord.CreateSheetBOF()); records.Add(new DimensionsRecord()); records.Add(CreateWindow2Record()); records.Add(new EOFRecord()); InternalSheet sheet = CreateSheet(records); Record[] outRecs = GetSheetRecords(sheet, 0); int pos = 0; Assert.IsTrue(outRecs[pos++] is BOFRecord); Assert.IsTrue(outRecs[pos++] is IndexRecord); Assert.IsTrue(outRecs[pos++] is DimensionsRecord); Assert.IsTrue(outRecs[pos++] is WindowTwoRecord); Assert.IsTrue(outRecs[pos++] is EOFRecord); }
public void TestDuplicateHeaderFooter_bug48026() { NPOI.HSSF.Record.Record[] recs = { BOFRecord.CreateSheetBOF(), new IndexRecord(), //PageSettingsBlock new HeaderRecord("&LDecember"), new FooterRecord("&LJanuary"), new DimensionsRecord(), new WindowTwoRecord(), //CustomViewSettingsRecordAggregate new UserSViewBegin(HexRead.ReadFromString("53 CE BD CC DE 38 44 45 97 C1 5C 89 F9 37 32 1B 01 00 00 00 64 00 00 00 40 00 00 00 03 00 00 00 7D 00 00 20 00 00 34 00 00 00 18 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 FF FF FF FF")), new SelectionRecord(0, 0), new UserSViewEnd(HexRead.ReadFromString("01 00")), // two HeaderFooterRecord records, the first one has zero GUID (16 bytes at offset 12) and belongs to the PSB, // the other is matched with a CustomViewSettingsRecordAggregate having UserSViewBegin with the same GUID new HeaderFooterRecord(HexRead.ReadFromString("9C 08 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 34 33 00 00 00 00 00 00 00 00")), new HeaderFooterRecord(HexRead.ReadFromString("9C 08 00 00 00 00 00 00 00 00 00 00 53 CE BD CC DE 38 44 45 97 C1 5C 89 F9 37 32 1B 34 33 00 00 00 00 00 00 00 00")), EOFRecord.instance, }; RecordStream rs = new RecordStream(Arrays.AsList(recs), 0); InternalSheet sheet; try { sheet = InternalSheet.CreateSheet(rs); } catch (Exception e) { if (e.Message.Equals("Duplicate PageSettingsBlock record (sid=0x89c)")) { throw new AssertionException("Identified bug 48026"); } throw e; } RecordInspector.RecordCollector rv = new RecordInspector.RecordCollector(); sheet.VisitContainedRecords(rv, 0); NPOI.HSSF.Record.Record[] outRecs = rv.Records; Assert.AreEqual(recs.Length, outRecs.Length); //expected order of records: NPOI.HSSF.Record.Record[] expectedRecs = { recs[0], //BOFRecord recs[1], //IndexRecord //PageSettingsBlock recs[2], //HeaderRecord recs[3], //FooterRecord recs[9], //HeaderFooterRecord recs[4], // DimensionsRecord recs[5], // WindowTwoRecord //CustomViewSettingsRecordAggregate recs[6], // UserSViewBegin recs[7], // SelectionRecord recs[10], // HeaderFooterRecord recs[8], // UserSViewEnd recs[11], //EOFRecord }; for (int i = 0; i < expectedRecs.Length; i++) { Assert.AreEqual(expectedRecs[i].GetType(), outRecs[i].GetType(), "Record mismatch at index " + i); } HeaderFooterRecord hd1 = (HeaderFooterRecord)expectedRecs[4]; //GUID is zero Assert.IsTrue(Arrays.Equals(new byte[16], hd1.Guid)); Assert.IsTrue(hd1.IsCurrentSheet); UserSViewBegin svb = (UserSViewBegin)expectedRecs[7]; HeaderFooterRecord hd2 = (HeaderFooterRecord)expectedRecs[9]; Assert.IsFalse(hd2.IsCurrentSheet); //GUIDs of HeaderFooterRecord and UserSViewBegin must be the same Assert.IsTrue(Arrays.Equals(svb.Guid, hd2.Guid)); }