public void TestLongRecords() { int[] length = { 1024, 2048, 4096, 8192, 16384 }; //test against strings of different length for (int i = 0; i < length.Length; i++) { StringBuilder buff = new StringBuilder(length[i]); for (int j = 0; j < length[i]; j++) { buff.Append("x"); } NPOI.SS.UserModel.RichTextString str = new HSSFRichTextString(buff.ToString()); TextObjectRecord obj = new TextObjectRecord(); obj.Str = (str); byte[] data = obj.Serialize(); RecordInputStream is1 = new RecordInputStream(new MemoryStream(data)); is1.NextRecord(); TextObjectRecord record = new TextObjectRecord(is1); str = record.Str; Assert.AreEqual(buff.Length, str.Length); Assert.AreEqual(buff.ToString(), str.String); } }
public void TestResultEqualsToAbstractShape() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFTextbox textbox = patriarch.CreateTextbox(new HSSFClientAnchor()) as HSSFTextbox; TextboxShape textboxShape = HSSFTestModelHelper.CreateTextboxShape(1025, textbox); Assert.AreEqual(textbox.GetEscherContainer().ChildRecords.Count, 5); Assert.AreEqual(textboxShape.SpContainer.ChildRecords.Count, 5); //sp record byte[] expected = textboxShape.SpContainer.GetChild(0).Serialize(); byte[] actual = textbox.GetEscherContainer().GetChild(0).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = textboxShape.SpContainer.GetChild(2).Serialize(); actual = textbox.GetEscherContainer().GetChild(2).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = textboxShape.SpContainer.GetChild(3).Serialize(); actual = textbox.GetEscherContainer().GetChild(3).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = textboxShape.SpContainer.GetChild(4).Serialize(); actual = textbox.GetEscherContainer().GetChild(4).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); ObjRecord obj = textbox.GetObjRecord(); ObjRecord objShape = textboxShape.ObjRecord; expected = obj.Serialize(); actual = objShape.Serialize(); TextObjectRecord tor = textbox.GetTextObjectRecord(); TextObjectRecord torShape = textboxShape.TextObjectRecord; expected = tor.Serialize(); actual = torShape.Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); }
public void TestLinkFormula() { RecordInputStream is1 = new RecordInputStream(new MemoryStream(linkData)); is1.NextRecord(); TextObjectRecord rec = new TextObjectRecord(is1); Ptg ptg = rec.LinkRefPtg; Assert.IsNotNull(ptg); Assert.AreEqual(typeof(RefPtg), ptg.GetType()); RefPtg rptg = (RefPtg)ptg; Assert.AreEqual("T2", rptg.ToFormulaString()); byte[] data2 = rec.Serialize(); Assert.AreEqual(linkData.Length, data2.Length); Assert.IsTrue(Arrays.Equals(linkData, data2)); }
public void TestResultEqualsToNonExistingAbstractShape() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFTextbox textbox = patriarch.CreateTextbox(new HSSFClientAnchor()) as HSSFTextbox; Assert.AreEqual(textbox.GetEscherContainer().ChildRecords.Count, 5); //sp record byte[] expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAFvEw/WBg4GBgZEFSHAxMAAA9gX7nhAAAAA="); byte[] actual = textbox.GetEscherContainer().GetChild(0).Serialize(); Assert.AreEqual(expected.Length, actual.Length); //assertArrayEquals(expected, actual) CollectionAssert.AreEqual(expected, actual); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNgEPggxIANAABK4+laGgAAAA=="); actual = textbox.GetEscherContainer().GetChild(2).Serialize(); Assert.AreEqual(expected.Length, actual.Length); CollectionAssert.AreEqual(expected, actual); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNgEPzAAAQACl6c5QgAAAA="); actual = textbox.GetEscherContainer().GetChild(3).Serialize(); Assert.AreEqual(expected.Length, actual.Length); CollectionAssert.AreEqual(expected, actual); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNg4P3AAAQA6pyIkQgAAAA="); actual = textbox.GetEscherContainer().GetChild(4).Serialize(); Assert.AreEqual(expected.Length, actual.Length); CollectionAssert.AreEqual(expected, actual); ObjRecord obj = textbox.GetObjRecord(); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAItlkGIQZRBiYGNgZBBMYEADAOdCLuweAAAA"); actual = obj.Serialize(); Assert.AreEqual(expected.Length, actual.Length); CollectionAssert.AreEqual(expected, actual); TextObjectRecord tor = textbox.GetTextObjectRecord(); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAANvGKMQgxMSABgBGi8T+FgAAAA=="); actual = tor.Serialize(); Assert.AreEqual(expected.Length, actual.Length); CollectionAssert.AreEqual(expected, actual); wb.Close(); }
public void TestClone() { String text = "Hello, World"; HSSFRichTextString str = new HSSFRichTextString(text); TextObjectRecord obj = new TextObjectRecord(); obj.Str = (str); TextObjectRecord cloned = (TextObjectRecord)obj.Clone(); Assert.AreEqual(obj.RecordSize, cloned.RecordSize); Assert.AreEqual(obj.HorizontalTextAlignment, cloned.HorizontalTextAlignment); Assert.AreEqual(obj.Str.String, cloned.Str.String); //finally check that the serialized data is the same byte[] src = obj.Serialize(); byte[] cln = cloned.Serialize(); Assert.IsTrue(NPOI.Util.Arrays.Equals(src, cln)); }
public void TestStore() { TextObjectRecord record = new TextObjectRecord(); HSSFRichTextString str = new HSSFRichTextString("AB"); str.ApplyFont(0, 2, (short)0x0018); str.ApplyFont(2, 2, (short)0x0320); record.HorizontalTextAlignment = HorizontalAlignment.Center; record.VerticalTextAlignment = VerticalAlignment.Justify; record.IsTextLocked = (true); record.TextOrientation = TextOrientation.RotRight; record.Str = (str); byte[] recordBytes = record.Serialize(); Assert.AreEqual(recordBytes.Length, data.Length); for (int i = 0; i < data.Length; i++) { Assert.AreEqual(data[i], recordBytes[i], "At offset " + i); } }
public void TestStore() { TextObjectRecord record = new TextObjectRecord(); HSSFRichTextString str = new HSSFRichTextString("AB"); str.ApplyFont(0, 2, (short)0x0018); str.ApplyFont(2, 2, (short)0x0320); record.HorizontalTextAlignment = (TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_CENTERED); record.VerticalTextAlignment = (TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_JUSTIFY); record.IsTextLocked = (true); record.TextOrientation = (TextObjectRecord.TEXT_ORIENTATION_ROT_RIGHT); record.Str = (str); byte[] recordBytes = record.Serialize(); Assert.AreEqual(recordBytes.Length, data.Length); for (int i = 0; i < data.Length; i++) { Assert.AreEqual(data[i], recordBytes[i], "At offset " + i); } }
public void TestWriteEmpty() { HSSFRichTextString str = new HSSFRichTextString(""); TextObjectRecord record = new TextObjectRecord(); record.Str = (/*setter*/ str); byte[] ser = record.Serialize(); int formatDataLen = LittleEndian.GetUShort(ser, 16); Assert.AreEqual(0, formatDataLen, "formatDataLength"); Assert.AreEqual(22, ser.Length); // just the TXO record //read again RecordInputStream is1 = TestcaseRecordInputStream.Create(ser); record = new TextObjectRecord(is1); Assert.AreEqual(0, record.Str.Length); }
public void TestWrite() { HSSFRichTextString str = new HSSFRichTextString("Hello, World!"); TextObjectRecord record = new TextObjectRecord(); record.Str = (/*setter*/ str); record.HorizontalTextAlignment = (/*setter*/ TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED); record.VerticalTextAlignment = (/*setter*/ TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_TOP); record.IsTextLocked = (/*setter*/ true); record.TextOrientation = (/*setter*/ TextObjectRecord.TEXT_ORIENTATION_NONE); byte[] ser = record.Serialize(); Assert.AreEqual(ser.Length, simpleData.Length); Assert.IsTrue(Arrays.Equals(simpleData, ser)); //read again RecordInputStream is1 = TestcaseRecordInputStream.Create(simpleData); record = new TextObjectRecord(is1); }
public void TestWrite() { HSSFRichTextString str = new HSSFRichTextString("Hello, World!"); TextObjectRecord record = new TextObjectRecord(); record.Str = (/*setter*/ str); record.HorizontalTextAlignment = (/*setter*/ HorizontalTextAlignment.Left); record.VerticalTextAlignment = (/*setter*/ VerticalTextAlignment.Top); record.IsTextLocked = (/*setter*/ true); record.TextOrientation = (/*setter*/ TextOrientation.None); byte[] ser = record.Serialize(); Assert.AreEqual(ser.Length, simpleData.Length); Assert.IsTrue(Arrays.Equals(simpleData, ser)); //read again RecordInputStream is1 = TestcaseRecordInputStream.Create(simpleData); record = new TextObjectRecord(is1); }
public void TestWriteEmpty() { HSSFRichTextString str = new HSSFRichTextString(""); TextObjectRecord record = new TextObjectRecord(); record.Str = (str); byte[] ser = record.Serialize(); int formatDataLen = NPOI.Util.LittleEndian.GetUShort(ser, 16); Assert.AreEqual(0, formatDataLen, "formatDataLength"); Assert.AreEqual(22, ser.Length); // just the TXO record //read again RecordInputStream is1 = new RecordInputStream(new MemoryStream(ser)); is1.NextRecord(); record = new TextObjectRecord(is1); Assert.AreEqual(0, record.Str.Length); }
public void TestWrite() { HSSFRichTextString str = new HSSFRichTextString("Hello, World!"); TextObjectRecord record = new TextObjectRecord(); record.Str = (str); record.HorizontalTextAlignment = (TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_LEFT_ALIGNED); record.VerticalTextAlignment = (TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_TOP); record.IsTextLocked = (true); record.TextOrientation = (TextObjectRecord.TEXT_ORIENTATION_NONE); byte[] ser = record.Serialize(); //Assert.AreEqual(ser.Length , data.Length); //Assert.IsTrue(Arrays.Equals(data, ser)); //Read again RecordInputStream is1 = new RecordInputStream(new MemoryStream(data)); is1.NextRecord(); record = new TextObjectRecord(is1); }
public void TestResultEqualsToAbstractShape() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFComment comment = patriarch.CreateCellComment(new HSSFClientAnchor()) as HSSFComment; HSSFRow row = sh.CreateRow(0) as HSSFRow; HSSFCell cell = row.CreateCell(0) as HSSFCell; cell.CellComment = (comment); CommentShape commentShape = HSSFTestModelHelper.CreateCommentShape(1025, comment); Assert.AreEqual(comment.GetEscherContainer().ChildRecords.Count, 5); Assert.AreEqual(commentShape.SpContainer.ChildRecords.Count, 5); //sp record byte[] expected = commentShape.SpContainer.GetChild(0).Serialize(); byte[] actual = comment.GetEscherContainer().GetChild(0).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = commentShape.SpContainer.GetChild(2).Serialize(); actual = comment.GetEscherContainer().GetChild(2).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = commentShape.SpContainer.GetChild(3).Serialize(); actual = comment.GetEscherContainer().GetChild(3).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = commentShape.SpContainer.GetChild(4).Serialize(); actual = comment.GetEscherContainer().GetChild(4).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); ObjRecord obj = comment.GetObjRecord(); ObjRecord objShape = commentShape.ObjRecord; expected = obj.Serialize(); actual = objShape.Serialize(); Assert.AreEqual(expected.Length, actual.Length); //assertArrayEquals(expected, actual); TextObjectRecord tor = comment.GetTextObjectRecord(); TextObjectRecord torShape = commentShape.TextObjectRecord; expected = tor.Serialize(); actual = torShape.Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); NoteRecord note = comment.NoteRecord; NoteRecord noteShape = commentShape.NoteRecord; expected = note.Serialize(); actual = noteShape.Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); wb.Close(); }
public void ResultEqualsToNonExistingAbstractShape() { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sh = wb.CreateSheet() as HSSFSheet; HSSFPatriarch patriarch = sh.CreateDrawingPatriarch() as HSSFPatriarch; HSSFComment comment = patriarch.CreateCellComment(new HSSFClientAnchor()) as HSSFComment; HSSFRow row = sh.CreateRow(0) as HSSFRow; HSSFCell cell = row.CreateCell(0) as HSSFCell; cell.CellComment = (comment); Assert.AreEqual(comment.GetEscherContainer().ChildRecords.Count, 5); //sp record byte[] expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAFvEw/WBg4GBgZEFSHAxMAAA9gX7nhAAAAA="); byte[] actual = comment.GetEscherContainer().GetChild(0).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNgEPggxIANAABK4+laGgAAAA=="); actual = comment.GetEscherContainer().GetChild(2).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNgEPzAAAQACl6c5QgAAAA="); actual = comment.GetEscherContainer().GetChild(3).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAGNg4P3AAAQA6pyIkQgAAAA="); actual = comment.GetEscherContainer().GetChild(4).Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); ObjRecord obj = comment.GetObjRecord(); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAItlMGEQZRBikGRgZBF0YEACvAxiDLgBAJZsuoU4AAAA"); actual = obj.Serialize(); Assert.AreEqual(expected.Length, actual.Length); //assertArrayEquals(expected, actual); TextObjectRecord tor = comment.GetTextObjectRecord(); expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAANvGKMQgxMSABgBGi8T+FgAAAA=="); actual = tor.Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); NoteRecord note = comment.NoteRecord; expected = TestDrawingAggregate.decompress("H4sIAAAAAAAAAJNh4GGAAEYWEAkAS0KXuRAAAAA="); actual = note.Serialize(); Assert.AreEqual(expected.Length, actual.Length); Assert.IsTrue(Arrays.Equals(expected, actual)); wb.Close(); }