mirror of https://github.com/apache/poi.git
*** empty log message ***
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353517 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6c081547dd
commit
84927c7243
|
@ -0,0 +1,131 @@
|
|||
/* ====================================================================
|
||||
* The Apache Software License, Version 1.1
|
||||
*
|
||||
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
||||
* reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by the
|
||||
* Apache Software Foundation (http://www.apache.org/)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Apache" and "Apache Software Foundation" and
|
||||
* "Apache POI" must not be used to endorse or promote products
|
||||
* derived from this software without prior written permission. For
|
||||
* written permission, please contact apache@apache.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Apache",
|
||||
* "Apache POI", nor may "Apache" appear in their name, without
|
||||
* prior written permission of the Apache Software Foundation.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*/
|
||||
|
||||
package org.apache.poi.hwpf.model;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import junit.framework.*;
|
||||
|
||||
import org.apache.poi.hwpf.*;
|
||||
import org.apache.poi.hwpf.model.io.*;
|
||||
|
||||
public class TestCHPBinTable
|
||||
extends TestCase
|
||||
{
|
||||
private CHPBinTable _cHPBinTable = null;
|
||||
private HWPFDocFixture _hWPFDocFixture;
|
||||
|
||||
public TestCHPBinTable(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void testReadWrite()
|
||||
throws Exception
|
||||
{
|
||||
FileInformationBlock fib = _hWPFDocFixture._fib;
|
||||
byte[] mainStream = _hWPFDocFixture._mainStream;
|
||||
byte[] tableStream = _hWPFDocFixture._tableStream;
|
||||
int fcMin = fib.getFcMin();
|
||||
|
||||
_cHPBinTable = new CHPBinTable(mainStream, tableStream, fib.getFcPlcfbteChpx(), fib.getLcbPlcfbteChpx(), fcMin);
|
||||
|
||||
HWPFFileSystem fileSys = new HWPFFileSystem();
|
||||
|
||||
_cHPBinTable.writeTo(fileSys, 0);
|
||||
ByteArrayOutputStream tableOut = fileSys.getStream("1Table");
|
||||
ByteArrayOutputStream mainOut = fileSys.getStream("WordDocument");
|
||||
|
||||
byte[] newTableStream = tableOut.toByteArray();
|
||||
byte[] newMainStream = mainOut.toByteArray();
|
||||
|
||||
CHPBinTable newBinTable = new CHPBinTable(newMainStream, newTableStream, 0, newTableStream.length, 0);
|
||||
|
||||
ArrayList oldTextRuns = _cHPBinTable._textRuns;
|
||||
ArrayList newTextRuns = newBinTable._textRuns;
|
||||
|
||||
assertEquals(oldTextRuns.size(), newTextRuns.size());
|
||||
|
||||
int size = oldTextRuns.size();
|
||||
for (int x = 0; x < size; x++)
|
||||
{
|
||||
PropertyNode oldNode = (PropertyNode)oldTextRuns.get(x);
|
||||
PropertyNode newNode = (PropertyNode)newTextRuns.get(x);
|
||||
|
||||
assertTrue(oldNode.equals(newNode));
|
||||
}
|
||||
|
||||
}
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
_hWPFDocFixture = new HWPFDocFixture(this);
|
||||
|
||||
_hWPFDocFixture.setUp();
|
||||
}
|
||||
|
||||
protected void tearDown()
|
||||
throws Exception
|
||||
{
|
||||
_cHPBinTable = null;
|
||||
_hWPFDocFixture.tearDown();
|
||||
|
||||
_hWPFDocFixture = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package org.apache.poi.hwpf.model;
|
||||
|
||||
import junit.framework.*;
|
||||
import org.apache.poi.hwpf.*;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class TestDocumentProperties
|
||||
extends TestCase
|
||||
{
|
||||
private DocumentProperties _documentProperties = null;
|
||||
private HWPFDocFixture _hWPFDocFixture;
|
||||
|
||||
public TestDocumentProperties(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
|
||||
public void testReadWrite()
|
||||
throws Exception
|
||||
{
|
||||
int size = _documentProperties.getSize();
|
||||
byte[] buf = new byte[size];
|
||||
|
||||
_documentProperties.serialize(buf, 0);
|
||||
|
||||
DocumentProperties newDocProperties =
|
||||
new DocumentProperties(buf, 0);
|
||||
|
||||
Field[] fields = DocumentProperties.class.getSuperclass().getDeclaredFields();
|
||||
AccessibleObject.setAccessible(fields, true);
|
||||
|
||||
for (int x = 0; x < fields.length; x++)
|
||||
{
|
||||
if (!fields[x].getType().isArray())
|
||||
{
|
||||
assertEquals(fields[x].get(_documentProperties),
|
||||
fields[x].get(newDocProperties));
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] buf1 = (byte[])fields[x].get(_documentProperties);
|
||||
byte[] buf2 = (byte[])fields[x].get(newDocProperties);
|
||||
Arrays.equals(buf1, buf2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
/**@todo verify the constructors*/
|
||||
|
||||
_hWPFDocFixture = new HWPFDocFixture(this);
|
||||
|
||||
_hWPFDocFixture.setUp();
|
||||
|
||||
_documentProperties = new DocumentProperties(_hWPFDocFixture._tableStream, _hWPFDocFixture._fib.getFcDop());
|
||||
}
|
||||
|
||||
protected void tearDown()
|
||||
throws Exception
|
||||
{
|
||||
_documentProperties = null;
|
||||
_hWPFDocFixture.tearDown();
|
||||
|
||||
_hWPFDocFixture = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package org.apache.poi.hwpf.model;
|
||||
|
||||
import junit.framework.*;
|
||||
import org.apache.poi.hwpf.*;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
|
||||
public class TestFileInformationBlock
|
||||
extends TestCase
|
||||
{
|
||||
private FileInformationBlock _fileInformationBlock = null;
|
||||
private HWPFDocFixture _hWPFDocFixture;
|
||||
|
||||
public TestFileInformationBlock(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void testReadWrite()
|
||||
throws Exception
|
||||
{
|
||||
int size = _fileInformationBlock.getSize();
|
||||
byte[] buf = new byte[size];
|
||||
|
||||
_fileInformationBlock.serialize(buf, 0);
|
||||
|
||||
FileInformationBlock newFileInformationBlock =
|
||||
new FileInformationBlock(buf);
|
||||
|
||||
Field[] fields = FileInformationBlock.class.getSuperclass().getDeclaredFields();
|
||||
AccessibleObject.setAccessible(fields, true);
|
||||
|
||||
for (int x = 0; x < fields.length; x++)
|
||||
{
|
||||
assertEquals(fields[x].get(_fileInformationBlock), fields[x].get(newFileInformationBlock));
|
||||
}
|
||||
}
|
||||
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
/**@todo verify the constructors*/
|
||||
_hWPFDocFixture = new HWPFDocFixture(this);
|
||||
|
||||
_hWPFDocFixture.setUp();
|
||||
_fileInformationBlock = _hWPFDocFixture._fib;
|
||||
}
|
||||
|
||||
protected void tearDown()
|
||||
throws Exception
|
||||
{
|
||||
_fileInformationBlock = null;
|
||||
_hWPFDocFixture.tearDown();
|
||||
|
||||
_hWPFDocFixture = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,121 @@
|
|||
/* ====================================================================
|
||||
* The Apache Software License, Version 1.1
|
||||
*
|
||||
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
||||
* reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by the
|
||||
* Apache Software Foundation (http://www.apache.org/)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Apache" and "Apache Software Foundation" and
|
||||
* "Apache POI" must not be used to endorse or promote products
|
||||
* derived from this software without prior written permission. For
|
||||
* written permission, please contact apache@apache.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Apache",
|
||||
* "Apache POI", nor may "Apache" appear in their name, without
|
||||
* prior written permission of the Apache Software Foundation.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*/
|
||||
|
||||
package org.apache.poi.hwpf.model;
|
||||
|
||||
import junit.framework.*;
|
||||
import org.apache.poi.hwpf.*;
|
||||
import org.apache.poi.hwpf.model.io.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class TestFontTable
|
||||
extends TestCase
|
||||
{
|
||||
private FontTable _fontTable = null;
|
||||
private HWPFDocFixture _hWPFDocFixture;
|
||||
|
||||
public TestFontTable(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void testReadWrite()
|
||||
throws Exception
|
||||
{
|
||||
FileInformationBlock fib = _hWPFDocFixture._fib;
|
||||
byte[] tableStream = _hWPFDocFixture._tableStream;
|
||||
|
||||
int fcSttbfffn = fib.getFcSttbfffn();
|
||||
int lcbSttbfffn = fib.getLcbSttbfffn();
|
||||
|
||||
_fontTable = new FontTable(tableStream, fcSttbfffn, lcbSttbfffn);
|
||||
|
||||
HWPFFileSystem fileSys = new HWPFFileSystem();
|
||||
|
||||
_fontTable.writeTo(fileSys);
|
||||
HWPFOutputStream tableOut = fileSys.getStream("1Table");
|
||||
|
||||
|
||||
byte[] newTableStream = tableOut.toByteArray();
|
||||
|
||||
|
||||
FontTable newFontTable = new FontTable(newTableStream, 0, newTableStream.length);
|
||||
|
||||
assertTrue(_fontTable.equals(newFontTable));
|
||||
|
||||
}
|
||||
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
/**@todo verify the constructors*/
|
||||
_hWPFDocFixture = new HWPFDocFixture(this);
|
||||
|
||||
_hWPFDocFixture.setUp();
|
||||
}
|
||||
|
||||
protected void tearDown()
|
||||
throws Exception
|
||||
{
|
||||
_hWPFDocFixture.tearDown();
|
||||
|
||||
_hWPFDocFixture = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
/* ====================================================================
|
||||
* The Apache Software License, Version 1.1
|
||||
*
|
||||
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
||||
* reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by the
|
||||
* Apache Software Foundation (http://www.apache.org/)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Apache" and "Apache Software Foundation" and
|
||||
* "Apache POI" must not be used to endorse or promote products
|
||||
* derived from this software without prior written permission. For
|
||||
* written permission, please contact apache@apache.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Apache",
|
||||
* "Apache POI", nor may "Apache" appear in their name, without
|
||||
* prior written permission of the Apache Software Foundation.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*/
|
||||
|
||||
package org.apache.poi.hwpf.model;
|
||||
|
||||
import junit.framework.*;
|
||||
import org.apache.poi.hwpf.*;
|
||||
import org.apache.poi.hwpf.model.io.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class TestPAPBinTable
|
||||
extends TestCase
|
||||
{
|
||||
private PAPBinTable _pAPBinTable = null;
|
||||
private HWPFDocFixture _hWPFDocFixture;
|
||||
|
||||
public TestPAPBinTable(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void testReadWrite()
|
||||
throws Exception
|
||||
{
|
||||
FileInformationBlock fib = _hWPFDocFixture._fib;
|
||||
byte[] mainStream = _hWPFDocFixture._mainStream;
|
||||
byte[] tableStream = _hWPFDocFixture._tableStream;
|
||||
int fcMin = fib.getFcMin();
|
||||
|
||||
_pAPBinTable = new PAPBinTable(mainStream, tableStream, fib.getFcPlcfbtePapx(), fib.getLcbPlcfbtePapx(), fcMin);
|
||||
|
||||
HWPFFileSystem fileSys = new HWPFFileSystem();
|
||||
|
||||
_pAPBinTable.writeTo(fileSys, 0);
|
||||
ByteArrayOutputStream tableOut = fileSys.getStream("1Table");
|
||||
ByteArrayOutputStream mainOut = fileSys.getStream("WordDocument");
|
||||
|
||||
byte[] newTableStream = tableOut.toByteArray();
|
||||
byte[] newMainStream = mainOut.toByteArray();
|
||||
|
||||
PAPBinTable newBinTable = new PAPBinTable(newMainStream, newTableStream, 0, newTableStream.length, 0);
|
||||
|
||||
ArrayList oldTextRuns = _pAPBinTable.getParagraphs();
|
||||
ArrayList newTextRuns = newBinTable.getParagraphs();
|
||||
|
||||
assertEquals(oldTextRuns.size(), newTextRuns.size());
|
||||
|
||||
int size = oldTextRuns.size();
|
||||
for (int x = 0; x < size; x++)
|
||||
{
|
||||
PropertyNode oldNode = (PropertyNode)oldTextRuns.get(x);
|
||||
PropertyNode newNode = (PropertyNode)newTextRuns.get(x);
|
||||
|
||||
assertTrue(oldNode.equals(newNode));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
/**@todo verify the constructors*/
|
||||
_hWPFDocFixture = new HWPFDocFixture(this);
|
||||
|
||||
_hWPFDocFixture.setUp();
|
||||
}
|
||||
|
||||
protected void tearDown()
|
||||
throws Exception
|
||||
{
|
||||
_hWPFDocFixture.tearDown();
|
||||
|
||||
_hWPFDocFixture = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
/* ====================================================================
|
||||
* The Apache Software License, Version 1.1
|
||||
*
|
||||
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
||||
* reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by the
|
||||
* Apache Software Foundation (http://www.apache.org/)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Apache" and "Apache Software Foundation" and
|
||||
* "Apache POI" must not be used to endorse or promote products
|
||||
* derived from this software without prior written permission. For
|
||||
* written permission, please contact apache@apache.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Apache",
|
||||
* "Apache POI", nor may "Apache" appear in their name, without
|
||||
* prior written permission of the Apache Software Foundation.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*/
|
||||
|
||||
package org.apache.poi.hwpf.model;
|
||||
|
||||
import junit.framework.*;
|
||||
import org.apache.poi.hwpf.*;
|
||||
|
||||
import org.apache.poi.util.LittleEndian;
|
||||
|
||||
public class TestPlexOfCps
|
||||
extends TestCase
|
||||
{
|
||||
private PlexOfCps _plexOfCps = null;
|
||||
private HWPFDocFixture _hWPFDocFixture;
|
||||
|
||||
public TestPlexOfCps(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
public void testWriteRead()
|
||||
throws Exception
|
||||
{
|
||||
_plexOfCps = new PlexOfCps(4);
|
||||
|
||||
int last = 0;
|
||||
for (int x = 0; x < 110; x++)
|
||||
{
|
||||
byte[] intHolder = new byte[4];
|
||||
int span = (int)(110.0f * Math.random());
|
||||
LittleEndian.putInt(intHolder, span);
|
||||
_plexOfCps.addProperty(new GenericPropertyNode(last, last + span, intHolder));
|
||||
last += span;
|
||||
}
|
||||
|
||||
byte[] output = _plexOfCps.toByteArray();
|
||||
_plexOfCps = new PlexOfCps(output, 0, output.length, 4);
|
||||
int len = _plexOfCps.length();
|
||||
assertEquals(len, 110);
|
||||
|
||||
last = 0;
|
||||
for (int x = 0; x < len; x++)
|
||||
{
|
||||
GenericPropertyNode node = _plexOfCps.getProperty(x);
|
||||
assertEquals(node.getStart(), last);
|
||||
last = node.getEnd();
|
||||
int span = LittleEndian.getInt(node.getBytes());
|
||||
assertEquals(node.getEnd()-node.getStart(), span);
|
||||
}
|
||||
}
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
/**@todo verify the constructors*/
|
||||
_hWPFDocFixture = new HWPFDocFixture(this);
|
||||
|
||||
_hWPFDocFixture.setUp();
|
||||
}
|
||||
|
||||
protected void tearDown()
|
||||
throws Exception
|
||||
{
|
||||
_plexOfCps = null;
|
||||
_hWPFDocFixture.tearDown();
|
||||
|
||||
_hWPFDocFixture = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,131 @@
|
|||
/* ====================================================================
|
||||
* The Apache Software License, Version 1.1
|
||||
*
|
||||
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
||||
* reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by the
|
||||
* Apache Software Foundation (http://www.apache.org/)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Apache" and "Apache Software Foundation" and
|
||||
* "Apache POI" must not be used to endorse or promote products
|
||||
* derived from this software without prior written permission. For
|
||||
* written permission, please contact apache@apache.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Apache",
|
||||
* "Apache POI", nor may "Apache" appear in their name, without
|
||||
* prior written permission of the Apache Software Foundation.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*/
|
||||
|
||||
package org.apache.poi.hwpf.model;
|
||||
|
||||
import junit.framework.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.apache.poi.hwpf.*;
|
||||
import org.apache.poi.hwpf.model.io.*;
|
||||
|
||||
public class TestSectionTable
|
||||
extends TestCase
|
||||
{
|
||||
private HWPFDocFixture _hWPFDocFixture;
|
||||
|
||||
public TestSectionTable(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void testReadWrite()
|
||||
throws Exception
|
||||
{
|
||||
FileInformationBlock fib = _hWPFDocFixture._fib;
|
||||
byte[] mainStream = _hWPFDocFixture._mainStream;
|
||||
byte[] tableStream = _hWPFDocFixture._tableStream;
|
||||
int fcMin = fib.getFcMin();
|
||||
|
||||
SectionTable sectionTable = new SectionTable(mainStream, tableStream,
|
||||
fib.getFcPlcfsed(),
|
||||
fib.getLcbPlcfsed(),
|
||||
fcMin);
|
||||
HWPFFileSystem fileSys = new HWPFFileSystem();
|
||||
|
||||
sectionTable.writeTo(fileSys, 0);
|
||||
ByteArrayOutputStream tableOut = fileSys.getStream("1Table");
|
||||
ByteArrayOutputStream mainOut = fileSys.getStream("WordDocument");
|
||||
|
||||
byte[] newTableStream = tableOut.toByteArray();
|
||||
byte[] newMainStream = mainOut.toByteArray();
|
||||
|
||||
SectionTable newSectionTable = new SectionTable(newMainStream, newTableStream, 0, newTableStream.length, 0);
|
||||
|
||||
ArrayList oldSections = sectionTable.getSections();
|
||||
ArrayList newSections = newSectionTable.getSections();
|
||||
|
||||
assertEquals(oldSections.size(), newSections.size());
|
||||
|
||||
int size = oldSections.size();
|
||||
for (int x = 0; x < size; x++)
|
||||
{
|
||||
PropertyNode oldNode = (PropertyNode)oldSections.get(x);
|
||||
PropertyNode newNode = (PropertyNode)newSections.get(x);
|
||||
assertEquals(oldNode, newNode);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
/**@todo verify the constructors*/
|
||||
_hWPFDocFixture = new HWPFDocFixture(this);
|
||||
|
||||
_hWPFDocFixture.setUp();
|
||||
}
|
||||
|
||||
protected void tearDown()
|
||||
throws Exception
|
||||
{
|
||||
_hWPFDocFixture.tearDown();
|
||||
|
||||
_hWPFDocFixture = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
/* ====================================================================
|
||||
* The Apache Software License, Version 1.1
|
||||
*
|
||||
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
||||
* reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The end-user documentation included with the redistribution,
|
||||
* if any, must include the following acknowledgment:
|
||||
* "This product includes software developed by the
|
||||
* Apache Software Foundation (http://www.apache.org/)."
|
||||
* Alternately, this acknowledgment may appear in the software itself,
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Apache" and "Apache Software Foundation" and
|
||||
* "Apache POI" must not be used to endorse or promote products
|
||||
* derived from this software without prior written permission. For
|
||||
* written permission, please contact apache@apache.org.
|
||||
*
|
||||
* 5. Products derived from this software may not be called "Apache",
|
||||
* "Apache POI", nor may "Apache" appear in their name, without
|
||||
* prior written permission of the Apache Software Foundation.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
||||
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*/
|
||||
|
||||
package org.apache.poi.hwpf.model;
|
||||
|
||||
import junit.framework.*;
|
||||
|
||||
import org.apache.poi.hwpf.*;
|
||||
import org.apache.poi.hwpf.model.io.*;
|
||||
import java.io.*;
|
||||
|
||||
public class TestStyleSheet
|
||||
extends TestCase
|
||||
{
|
||||
private StyleSheet _styleSheet = null;
|
||||
private HWPFDocFixture _hWPFDocFixture;
|
||||
|
||||
|
||||
public TestStyleSheet(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void testReadWrite()
|
||||
throws Exception
|
||||
{
|
||||
HWPFFileSystem fileSys = new HWPFFileSystem();
|
||||
|
||||
|
||||
HWPFOutputStream tableOut = fileSys.getStream("1Table");
|
||||
HWPFOutputStream mainOut = fileSys.getStream("WordDocument");
|
||||
|
||||
_styleSheet.writeTo(tableOut);
|
||||
|
||||
byte[] newTableStream = tableOut.toByteArray();
|
||||
|
||||
StyleSheet newStyleSheet = new StyleSheet(newTableStream, 0);
|
||||
assertEquals(newStyleSheet, _styleSheet);
|
||||
|
||||
}
|
||||
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
/**@todo verify the constructors*/
|
||||
_hWPFDocFixture = new HWPFDocFixture(this);
|
||||
_hWPFDocFixture.setUp();
|
||||
FileInformationBlock fib = _hWPFDocFixture._fib;
|
||||
byte[] mainStream = _hWPFDocFixture._mainStream;
|
||||
byte[] tableStream = _hWPFDocFixture._tableStream;
|
||||
|
||||
_hWPFDocFixture.setUp();
|
||||
_styleSheet = new StyleSheet(tableStream, fib.getFcStshf());
|
||||
}
|
||||
|
||||
protected void tearDown()
|
||||
throws Exception
|
||||
{
|
||||
_styleSheet = null;
|
||||
_hWPFDocFixture.tearDown();
|
||||
|
||||
_hWPFDocFixture = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package org.apache.poi.hwpf.model;
|
||||
|
||||
import junit.framework.*;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.apache.poi.hwpf.*;
|
||||
import org.apache.poi.hwpf.model.io.*;
|
||||
|
||||
|
||||
public class TestTextPieceTable
|
||||
extends TestCase
|
||||
{
|
||||
private HWPFDocFixture _hWPFDocFixture;
|
||||
|
||||
public TestTextPieceTable(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void testReadWrite()
|
||||
throws Exception
|
||||
{
|
||||
FileInformationBlock fib = _hWPFDocFixture._fib;
|
||||
byte[] mainStream = _hWPFDocFixture._mainStream;
|
||||
byte[] tableStream = _hWPFDocFixture._tableStream;
|
||||
int fcMin = fib.getFcMin();
|
||||
|
||||
ComplexFileTable cft = new ComplexFileTable(mainStream, tableStream, fib.getFcClx(), fcMin);
|
||||
|
||||
|
||||
HWPFFileSystem fileSys = new HWPFFileSystem();
|
||||
|
||||
cft.writeTo(fileSys);
|
||||
ByteArrayOutputStream tableOut = fileSys.getStream("1Table");
|
||||
ByteArrayOutputStream mainOut = fileSys.getStream("WordDocument");
|
||||
|
||||
byte[] newTableStream = tableOut.toByteArray();
|
||||
byte[] newMainStream = mainOut.toByteArray();
|
||||
|
||||
ComplexFileTable newCft = new ComplexFileTable(newMainStream, newTableStream, 0,0);
|
||||
|
||||
TextPieceTable oldTextPieceTable = cft.getTextPieceTable();
|
||||
TextPieceTable newTextPieceTable = newCft.getTextPieceTable();
|
||||
|
||||
assertEquals(oldTextPieceTable, newTextPieceTable);
|
||||
|
||||
|
||||
}
|
||||
protected void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
|
||||
_hWPFDocFixture = new HWPFDocFixture(this);
|
||||
_hWPFDocFixture.setUp();
|
||||
}
|
||||
|
||||
protected void tearDown()
|
||||
throws Exception
|
||||
{
|
||||
_hWPFDocFixture.tearDown();
|
||||
|
||||
_hWPFDocFixture = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue