* completely clear in all cases what it's supposed to
* be doing... Someone who understands the goals a little
* better should really review this!
+ *
+ * Graphically, this is what we're creating:
+ *
+ * Column
+ *
+ * 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
+ *
+ * After groupColumn(4,7)
+ * 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
+ * +--------+ +-----------+
+ *
*/
@Test
public void setColumnGroupCollapsed() throws IOException {
CTCols cols = sheet1.getCTWorksheet().getColsArray(0);
assertEquals(0, cols.sizeOfColArray());
+ // Column
+ // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
+ // ++++++++++
+ //
sheet1.groupColumn( 4, 7 );
assertEquals(1, cols.sizeOfColArray());
checkColumnGroup(cols.getColArray(0), 4, 7); // false, true
+ // Column
+ // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
+ // ++++++++++ +++++++++++++
+ //
sheet1.groupColumn( 9, 12 );
assertEquals(2, cols.sizeOfColArray());
checkColumnGroup(cols.getColArray(0), 4, 7); // false, true
checkColumnGroup(cols.getColArray(1), 9, 12); // false, true
+ // Column
+ // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
+ // ++++++++++ +++++++++++++
+ // ++++++
sheet1.groupColumn( 10, 11 );
assertEquals(4, cols.sizeOfColArray());
checkColumnGroup(cols.getColArray(3), 12, 12); // false, true
// collapse columns - 1
+ // Column
+ // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
+ // ---------- +++++++++++++
+ // ++++++
sheet1.setColumnGroupCollapsed( 5, true );
-
+
// FIXME: we grew a column?
assertEquals(5, cols.sizeOfColArray());
checkColumnGroupIsCollapsed(cols.getColArray(0), 4, 7); // true, true
// expand columns - 1
+ // Column
+ // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
+ // ++++++++++ +++++++++++++
+ // ++++++
sheet1.setColumnGroupCollapsed( 5, false );
assertEquals(5, cols.sizeOfColArray());
//collapse - 2
+ // Column
+ // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
+ // ++++++++++ -------------
+ // -----
+ // can lower-level outlines be expanded if their parents are collapsed?
sheet1.setColumnGroupCollapsed( 9, true );
- // it grew again?
+ // FIXME: it grew again?
assertEquals(6, cols.sizeOfColArray());
checkColumnGroup(cols.getColArray(0), 4, 7); // false, true
checkColumnGroup(cols.getColArray(1), 8, 8, false, false);
//expand - 2
+ // Column
+ // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
+ // ++++++++++ +++++++++++++
+ // ++++++
+ // do collapsed lower-level outlines get expanded if their parents are expanded?
+ // how much of this is Excel GUI behavior convenience and what is allowed
+ // per the OOXML format?
sheet1.setColumnGroupCollapsed( 9, false );
assertEquals(6, cols.sizeOfColArray());
//outline level 2: the line under ==> collapsed==True
assertEquals(2, cols.getColArray(3).getOutlineLevel());
+ assertTrue(cols.getColArray(3).getCollapsed());
assertTrue(cols.getColArray(4).isSetCollapsed());
checkColumnGroup(cols.getColArray(0), 4, 7);
wb1.close();
sheet1 = wb2.getSheetAt(0);
// FIXME: forgot to reassign!
- //cols = sheet1.getCTWorksheet().getColsArray(0);
+ cols = sheet1.getCTWorksheet().getColsArray(0);
assertEquals(6, cols.sizeOfColArray());
checkColumnGroup(cols.getColArray(0), 4, 7); // false, true
) {
assertEquals("from column index", fromColumnIndex, col.getMin() - 1); // 1 based
assertEquals("to column index", toColumnIndex, col.getMax() - 1); // 1 based
- assertFalse("isSetHidden", col.isSetHidden());
- assertTrue("isSetCollapsed", col.isSetCollapsed()); //not necessarily set
+ //assertFalse("isSetHidden", col.isSetHidden());
+ // group collapse state is either unset or not collapsed
+ assertFalse("collapsed", col.isSetCollapsed() && col.getCollapsed());
}
/**
* Verify that column groups were created correctly after Sheet.groupColumn
) {
assertEquals("from column index", fromColumnIndex, col.getMin() - 1); // 1 based
assertEquals("to column index", toColumnIndex, col.getMax() - 1); // 1 based
- assertTrue("isSetHidden", col.isSetHidden());
- assertTrue("isSetCollapsed", col.isSetCollapsed());
- //assertTrue("getCollapsed", col.getCollapsed());
+ // assertTrue("isSetHidden", col.isSetHidden());
+ assertTrue("collapsed", col.isSetCollapsed() && col.getCollapsed());
}
/**
* Verify that column groups were created correctly after Sheet.groupColumn
) {
assertEquals("from column index", fromColumnIndex, col.getMin() - 1); // 1 based
assertEquals("to column index", toColumnIndex, col.getMax() - 1); // 1 based
- assertFalse("isSetHidden", col.isSetHidden());
- assertTrue("isSetCollapsed", col.isSetCollapsed());
- //assertTrue("isSetCollapsed", !col.isSetCollapsed() || !col.getCollapsed());
- //assertFalse("getCollapsed", col.getCollapsed());
+ // assertFalse("isSetHidden", col.isSetHidden());
+ // group collapse state is either unset or not collapsed
+ assertFalse("collapsed", col.isSetCollapsed() && col.getCollapsed());
}
/**
package org.apache.poi.hsmf;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.IOException;
-import junit.framework.TestCase;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hsmf.datatypes.AttachmentChunks;
/**
* Tests to verify that we can read attachments from msg file
*/
-public class TestFileWithAttachmentsRead extends TestCase {
- private final MAPIMessage twoSimpleAttachments;
- private final MAPIMessage pdfMsgAttachments;
- private final MAPIMessage inlineImgMsgAttachments;
+public class TestFileWithAttachmentsRead {
+ private static MAPIMessage twoSimpleAttachments;
+ private static MAPIMessage pdfMsgAttachments;
+ private static MAPIMessage inlineImgMsgAttachments;
/**
* Initialize this test, load up the attachment_test_msg.msg mapi message.
*
* @throws Exception
*/
- public TestFileWithAttachmentsRead() throws IOException {
+ @BeforeClass
+ public static void setUp() throws IOException {
POIDataSamples samples = POIDataSamples.getHSMFInstance();
- this.twoSimpleAttachments = new MAPIMessage(samples.openResourceAsStream("attachment_test_msg.msg"));
- this.pdfMsgAttachments = new MAPIMessage(samples.openResourceAsStream("attachment_msg_pdf.msg"));
- this.inlineImgMsgAttachments = new MAPIMessage(samples.openResourceAsStream("attachment_msg_inlineImg.msg"));
+ twoSimpleAttachments = new MAPIMessage(samples.openResourceAsStream("attachment_test_msg.msg"));
+ pdfMsgAttachments = new MAPIMessage(samples.openResourceAsStream("attachment_msg_pdf.msg"));
+ inlineImgMsgAttachments = new MAPIMessage(samples.openResourceAsStream("attachment_msg_inlineImg.msg"));
+ }
+
+ @AfterClass
+ public static void tearDown() throws IOException {
+ twoSimpleAttachments.close();
+ pdfMsgAttachments.close();
+ inlineImgMsgAttachments.close();
}
/**
* @throws ChunkNotFoundException
*
*/
+ @Test
public void testRetrieveAttachments() {
// Simple file
AttachmentChunks[] attachments = twoSimpleAttachments.getAttachmentFiles();
/**
* Bug 60550: Test to see if we get the correct Content-IDs of inline images`.
*/
+ @Test
public void testReadContentIDField() throws IOException {
AttachmentChunks[] attachments = inlineImgMsgAttachments.getAttachmentFiles();
/**
* Test to see if attachments are not empty.
*/
+ @Test
public void testReadAttachments() throws IOException {
AttachmentChunks[] attachments = twoSimpleAttachments.getAttachmentFiles();
/**
* Test that we can handle both PDF and MSG attachments
*/
+ @Test
public void testReadMsgAttachments() throws Exception {
AttachmentChunks[] attachments = pdfMsgAttachments.getAttachmentFiles();
assertEquals(2, attachments.length);