Return-Path: Delivered-To: apmail-poi-commits-archive@locus.apache.org Received: (qmail 65719 invoked from network); 3 Apr 2008 19:41:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Apr 2008 19:41:47 -0000 Received: (qmail 53954 invoked by uid 500); 3 Apr 2008 19:41:47 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 53917 invoked by uid 500); 3 Apr 2008 19:41:47 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 53908 invoked by uid 99); 3 Apr 2008 19:41:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Apr 2008 12:41:47 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Apr 2008 19:41:14 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C10ED1A9832; Thu, 3 Apr 2008 12:41:26 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r644460 - in /poi/branches/ooxml/src/ooxml: java/org/apache/poi/xssf/model/CommentsTable.java java/org/apache/poi/xssf/usermodel/XSSFComment.java testcases/org/apache/poi/xssf/model/TestCommentsTable.java Date: Thu, 03 Apr 2008 19:41:25 -0000 To: commits@poi.apache.org From: nick@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080403194126.C10ED1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: nick Date: Thu Apr 3 12:41:23 2008 New Revision: 644460 URL: http://svn.apache.org/viewvc?rev=644460&view=rev Log: More tests for xssf comments. Now almost all there and working, except for rich text formatting, and new line munching (bug #44750) Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java?rev=644460&r1=644459&r2=644460&view=diff ============================================================================== --- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java (original) +++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java Thu Apr 3 12:41:23 2008 @@ -72,6 +72,9 @@ public int getNumberOfComments() { return comments.getCommentList().sizeOfCommentArray(); } + public int getNumberOfAuthors() { + return getCommentsAuthors().sizeOfAuthorArray(); + } public String getAuthor(long authorId) { return getCommentsAuthors().getAuthorArray((int)authorId); Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java?rev=644460&r1=644459&r2=644460&view=diff ============================================================================== --- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java (original) +++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFComment.java Thu Apr 3 12:41:23 2008 @@ -56,7 +56,9 @@ } public void setAuthor(String author) { - comments.findAuthor(author); + comment.setAuthorId( + comments.findAuthor(author) + ); } public void setColumn(short col) { Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java?rev=644460&r1=644459&r2=644460&view=diff ============================================================================== --- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java (original) +++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/model/TestCommentsTable.java Thu Apr 3 12:41:23 2008 @@ -31,6 +31,8 @@ import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.openxml4j.opc.Package; +import org.openxml4j.opc.PackagePart; +import org.openxml4j.opc.PackagingURIHelper; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments; @@ -52,6 +54,8 @@ assertEquals(0, sheetComments.findAuthor(TEST_AUTHOR)); assertEquals(1, sheetComments.findAuthor("another author")); assertEquals(0, sheetComments.findAuthor(TEST_AUTHOR)); + assertEquals(2, sheetComments.findAuthor("YAA")); + assertEquals(1, sheetComments.findAuthor("another author")); } public void testGetCellComment() { @@ -91,6 +95,51 @@ sheetComments.setCellComment("A1", comment); assertEquals(1, commentList.sizeOfCommentArray()); assertEquals("test A1 author", sheetComments.getAuthor(commentList.getCommentArray(0).getAuthorId())); + assertEquals("test A1 author", comment.getAuthor()); + + // Change the author, check it updates + comment.setAuthor("Another Author"); + assertEquals(1, commentList.sizeOfCommentArray()); + assertEquals("Another Author", comment.getAuthor()); + } + + public void testDontLoostNewLines() throws Exception { + File xml = new File( + System.getProperty("HSSF.testdata.path") + + File.separator + "WithVariousData.xlsx" + ); + assertTrue(xml.exists()); + + Package pkg = Package.open(xml.toString()); + PackagePart cpart = pkg.getPart( + PackagingURIHelper.createPartName("/xl/comments1.xml") + ); + + CommentsTable ct = new CommentsTable(cpart.getInputStream()); + assertEquals(2, ct.getNumberOfComments()); + assertEquals(1, ct.getNumberOfAuthors()); + + XSSFComment comment = ct.findCellComment("C5"); + + assertEquals("Nick Burch", comment.getAuthor()); + assertEquals("Nick Burch:\nThis is a comment", comment.getString().getString()); + + // Re-serialise + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ct.writeTo(baos); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + ct = new CommentsTable(bais); + + assertEquals(2, ct.getNumberOfComments()); + assertEquals(1, ct.getNumberOfAuthors()); + + comment = ct.findCellComment("C5"); + + assertEquals("Nick Burch", comment.getAuthor()); + + // TODO: Fix this! + // New line should still be there, but isn't! + //assertEquals("Nick Burch:\nThis is a comment", comment.getString().getString()); } public void testExisting() throws Exception { @@ -163,6 +212,7 @@ // Save, and re-load the file ByteArrayOutputStream baos = new ByteArrayOutputStream(); workbook.write(baos); + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); workbook = new XSSFWorkbook(Package.open(bais)); @@ -174,6 +224,60 @@ assertNotNull(sheet2.getRow(2).getCell(1).getCellComment()); // And check they still have the contents they should do - // TODO + assertEquals("Apache POI", + sheet1.getRow(4).getCell(2).getCellComment().getAuthor()); + assertEquals("Nick Burch", + sheet1.getRow(6).getCell(2).getCellComment().getAuthor()); + assertEquals("Also POI", + sheet2.getRow(2).getCell(1).getCellComment().getAuthor()); + + // TODO: fix xmlbeans so it doesn't eat newlines + assertEquals("Nick Burch:This is a comment", + sheet1.getRow(4).getCell(2).getCellComment().getString().getString()); + } + + public void testReadWriteMultipleAuthors() throws Exception { + File xml = new File( + System.getProperty("HSSF.testdata.path") + + File.separator + "WithMoreVariousData.xlsx" + ); + assertTrue(xml.exists()); + + XSSFWorkbook workbook = new XSSFWorkbook(xml.toString()); + Sheet sheet1 = workbook.getSheetAt(0); + XSSFSheet sheet2 = (XSSFSheet)workbook.getSheetAt(1); + + assertTrue( ((XSSFSheet)sheet1).hasComments() ); + assertFalse( ((XSSFSheet)sheet2).hasComments() ); + + assertEquals("Nick Burch", + sheet1.getRow(4).getCell(2).getCellComment().getAuthor()); + assertEquals("Nick Burch", + sheet1.getRow(6).getCell(2).getCellComment().getAuthor()); + assertEquals("Torchbox", + sheet1.getRow(12).getCell(2).getCellComment().getAuthor()); + + // Save, and re-load the file + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + workbook.write(baos); + + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + workbook = new XSSFWorkbook(Package.open(bais)); + + // Check we still have comments where we should do + sheet1 = workbook.getSheetAt(0); + assertNotNull(sheet1.getRow(4).getCell(2).getCellComment()); + assertNotNull(sheet1.getRow(6).getCell(2).getCellComment()); + assertNotNull(sheet1.getRow(12).getCell(2).getCellComment()); + + // And check they still have the contents they should do + assertEquals("Nick Burch", + sheet1.getRow(4).getCell(2).getCellComment().getAuthor()); + assertEquals("Nick Burch", + sheet1.getRow(6).getCell(2).getCellComment().getAuthor()); + assertEquals("Torchbox", + sheet1.getRow(12).getCell(2).getCellComment().getAuthor()); + + // Todo - check text too, once bug fixed } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org