You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by jo...@apache.org on 2008/10/26 08:18:19 UTC
svn commit: r707945 [4/4] - in /poi/branches/ooxml: ./
src/contrib/src/org/apache/poi/contrib/poibrowser/
src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/record/
src/java/org/apache/poi/hssf/record/constant/ src/java/org/apache/poi/hss...
Modified: poi/branches/ooxml/src/java/org/apache/poi/util/LittleEndianInputStream.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/util/LittleEndianInputStream.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/util/LittleEndianInputStream.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/util/LittleEndianInputStream.java Sun Oct 26 00:18:17 2008
@@ -22,6 +22,10 @@
import java.io.InputStream;
/**
+ * Wraps an {@link InputStream} providing {@link LittleEndianInput}<p/>
+ *
+ * This class does not buffer any input, so the stream read position maintained
+ * by this class is consistent with that of the inner stream.
*
* @author Josh Micich
*/
@@ -29,7 +33,13 @@
public LittleEndianInputStream(InputStream is) {
super(is);
}
-
+ public int available() {
+ try {
+ return super.available();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
public byte readByte() {
return (byte)readUByte();
}
@@ -131,34 +141,4 @@
buf[i] = (byte) ch;
}
}
- public String readCompressedUnicode(int nChars) {
- char[] buf = new char[nChars];
- for (int i = 0; i < buf.length; i++) {
- int ch;
- try {
- ch = in.read();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- checkEOF(ch);
- buf[i] = (char) ch;
-
- }
- return new String(buf);
- }
- public String readUnicodeLEString(int nChars) {
- char[] buf = new char[nChars];
- for (int i = 0; i < buf.length; i++) {
- int ch;
- try {
- ch = in.read();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- checkEOF(ch);
- buf[i] = (char) ch;
-
- }
- return new String(buf);
- }
}
Modified: poi/branches/ooxml/src/java/org/apache/poi/util/StringUtil.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/util/StringUtil.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/util/StringUtil.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/util/StringUtil.java Sun Oct 26 00:18:17 2008
@@ -20,9 +20,14 @@
import java.io.UnsupportedEncodingException;
import java.text.FieldPosition;
import java.text.NumberFormat;
+
+import org.apache.poi.hssf.record.RecordInputStream;
/**
- * Title: String Utility Description: Collection of string handling utilities
- *
+ * Title: String Utility Description: Collection of string handling utilities<p/>
+ *
+ * Note - none of the methods in this class deals with {@link ContinueRecord}s. For such
+ * functionality, consider using {@link RecordInputStream
+} *
*
*@author Andrew C. Oliver
*@author Sergei Kozello (sergeikozello at mail.ru)
@@ -84,65 +89,12 @@
* @param string the byte array to be converted
* @return the converted string
*/
- public static String getFromUnicodeLE(final byte[] string) {
+ public static String getFromUnicodeLE(byte[] string) {
if(string.length == 0) { return ""; }
return getFromUnicodeLE(string, 0, string.length / 2);
}
/**
- * Given a byte array of 16-bit unicode characters in big endian
- * format (most important byte first), return a Java String representation
- * of it.
- *
- * { 0x00, 0x16 } -0x16
- *
- * @param string the byte array to be converted
- * @param offset the initial offset into the
- * byte array. it is assumed that string[ offset ] and string[ offset +
- * 1 ] contain the first 16-bit unicode character
- * @param len the length of the final string
- * @return the converted string
- * @exception ArrayIndexOutOfBoundsException if offset is out of bounds for
- * the byte array (i.e., is negative or is greater than or equal to
- * string.length)
- * @exception IllegalArgumentException if len is too large (i.e.,
- * there is not enough data in string to create a String of that
- * length)
- */
- public static String getFromUnicodeBE(
- final byte[] string,
- final int offset,
- final int len)
- throws ArrayIndexOutOfBoundsException, IllegalArgumentException {
- if ((offset < 0) || (offset >= string.length)) {
- throw new ArrayIndexOutOfBoundsException("Illegal offset");
- }
- if ((len < 0) || (((string.length - offset) / 2) < len)) {
- throw new IllegalArgumentException("Illegal length");
- }
- try {
- return new String(string, offset, len * 2, "UTF-16BE");
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Given a byte array of 16-bit unicode characters in big endian
- * format (most important byte first), return a Java String representation
- * of it.
- *
- * { 0x00, 0x16 } -0x16
- *
- * @param string the byte array to be converted
- * @return the converted string
- */
- public static String getFromUnicodeBE(final byte[] string) {
- if(string.length == 0) { return ""; }
- return getFromUnicodeBE(string, 0, string.length / 2);
- }
-
- /**
* Read 8 bit data (in ISO-8859-1 codepage) into a (unicode) Java
* String and return.
* (In Excel terms, read compressed 8 bit unicode as a string)
@@ -163,6 +115,52 @@
throw new RuntimeException(e);
}
}
+ public static String readCompressedUnicode(LittleEndianInput in, int nChars) {
+ char[] buf = new char[nChars];
+ for (int i = 0; i < buf.length; i++) {
+ buf[i] = (char) in.readUByte();
+ }
+ return new String(buf);
+ }
+ /**
+ * InputStream <tt>in</tt> is expected to contain:
+ * <ol>
+ * <li>ushort nChars</li>
+ * <li>byte is16BitFlag</li>
+ * <li>byte[]/char[] characterData</li>
+ * </ol>
+ * For this encoding, the is16BitFlag is always present even if nChars==0.
+ */
+ public static String readUnicodeString(LittleEndianInput in) {
+
+ int nChars = in.readUShort();
+ byte flag = in.readByte();
+ if ((flag & 0x01) == 0) {
+ return readCompressedUnicode(in, nChars);
+ }
+ return readUnicodeLE(in, nChars);
+ }
+ /**
+ * OutputStream <tt>out</tt> will get:
+ * <ol>
+ * <li>ushort nChars</li>
+ * <li>byte is16BitFlag</li>
+ * <li>byte[]/char[] characterData</li>
+ * </ol>
+ * For this encoding, the is16BitFlag is always present even if nChars==0.
+ */
+ public static void writeUnicodeString(LittleEndianOutput out, String value) {
+
+ int nChars = value.length();
+ out.writeShort(nChars);
+ boolean is16Bit = hasMultibyte(value);
+ out.writeByte(is16Bit ? 0x01 : 0x00);
+ if (is16Bit) {
+ putUnicodeLE(value, out);
+ } else {
+ putCompressedUnicode(value, out);
+ }
+ }
/**
* Takes a unicode (java) string, and returns it as 8 bit data (in ISO-8859-1
@@ -220,6 +218,14 @@
}
out.write(bytes);
}
+
+ public static String readUnicodeLE(LittleEndianInput in, int nChars) {
+ char[] buf = new char[nChars];
+ for (int i = 0; i < buf.length; i++) {
+ buf[i] = (char) in.readUShort();
+ }
+ return new String(buf);
+ }
/**
* Apply printf() like formatting to a string.
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/AllRecordTests.java Sun Oct 26 00:18:17 2008
@@ -100,6 +100,7 @@
result.addTestSuite(TestSheetPropertiesRecord.class);
result.addTestSuite(TestSharedFormulaRecord.class);
result.addTestSuite(TestStringRecord.class);
+ result.addTestSuite(TestStyleRecord.class);
result.addTestSuite(TestSubRecord.class);
result.addTestSuite(TestSupBookRecord.class);
result.addTestSuite(TestTableRecord.class);
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestCommonObjectDataSubRecord.java Sun Oct 26 00:18:17 2008
@@ -37,7 +37,7 @@
};
public void testLoad() {
- CommonObjectDataSubRecord record = new CommonObjectDataSubRecord(TestcaseRecordInputStream.createWithFakeSid(data), data.length);
+ CommonObjectDataSubRecord record = new CommonObjectDataSubRecord(TestcaseRecordInputStream.createLittleEndian(data), data.length);
assertEquals( CommonObjectDataSubRecord.OBJECT_TYPE_LIST_BOX, record.getObjectType());
assertEquals((short) 1, record.getObjectId());
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java Sun Oct 26 00:18:17 2008
@@ -14,11 +14,12 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hssf.record;
-import java.io.ByteArrayInputStream;
import java.util.Arrays;
+import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.apache.poi.util.HexRead;
@@ -37,33 +38,43 @@
public void testStore() {
byte[] src = hr(data1);
- src = TestcaseRecordInputStream.mergeDataAndSid(EmbeddedObjectRefSubRecord.sid, (short)src.length, src);
+// src = TestcaseRecordInputStream.mergeDataAndSid(EmbeddedObjectRefSubRecord.sid, (short)src.length, src);
- RecordInputStream in = new RecordInputStream(new ByteArrayInputStream(src));
- in.nextRecord();
+ RecordInputStream in = TestcaseRecordInputStream.create(EmbeddedObjectRefSubRecord.sid, src);
- EmbeddedObjectRefSubRecord record1 = new EmbeddedObjectRefSubRecord(in, src.length-4);
+ EmbeddedObjectRefSubRecord record1 = new EmbeddedObjectRefSubRecord(in, src.length);
byte[] ser = record1.serialize();
- RecordInputStream in2 = new RecordInputStream(new ByteArrayInputStream(ser));
- in2.nextRecord();
+ RecordInputStream in2 = TestcaseRecordInputStream.create(ser);
EmbeddedObjectRefSubRecord record2 = new EmbeddedObjectRefSubRecord(in2, ser.length-4);
- assertTrue(Arrays.equals(src, ser));
+ confirmData(src, ser);
assertEquals(record1.getOLEClassName(), record2.getOLEClassName());
byte[] ser2 = record1.serialize();
assertTrue(Arrays.equals(ser, ser2));
}
+ /**
+ * @param expectedData does not include sid & size
+ * @param actualFullRecordData includes sid & size
+ */
+ private static void confirmData(byte[] expectedData, byte[] actualFullRecordData) {
+ assertEquals(expectedData.length, actualFullRecordData.length-4);
+ for (int i = 0; i < expectedData.length; i++) {
+ if(expectedData[i] != actualFullRecordData[i+4]) {
+ throw new AssertionFailedError("Difference at offset (" + i + ")");
+ }
+ }
+ }
+
public void testCreate() {
EmbeddedObjectRefSubRecord record1 = new EmbeddedObjectRefSubRecord();
byte[] ser = record1.serialize();
- RecordInputStream in2 = new RecordInputStream(new ByteArrayInputStream(ser));
- in2.nextRecord();
+ RecordInputStream in2 = TestcaseRecordInputStream.create(ser);
EmbeddedObjectRefSubRecord record2 = new EmbeddedObjectRefSubRecord(in2, ser.length-4);
assertEquals(record1.getOLEClassName(), record2.getOLEClassName());
@@ -78,21 +89,17 @@
* taken from ftPictFmla sub-record in attachment 22645 (offset 0x40AB).
*/
private static final byte[] data45912 = hr(
- "09 00 14 00 " +
"12 00 0B 00 F8 02 88 04 3B 00 " +
"00 00 00 01 00 00 00 01 " +
"00 00");
public void testCameraTool_bug45912() {
byte[] data = data45912;
- RecordInputStream in = new RecordInputStream(new ByteArrayInputStream(data));
- in.nextRecord();
+ RecordInputStream in = TestcaseRecordInputStream.create(EmbeddedObjectRefSubRecord.sid, data);
- EmbeddedObjectRefSubRecord rec = new EmbeddedObjectRefSubRecord(in, data.length-4);
+ EmbeddedObjectRefSubRecord rec = new EmbeddedObjectRefSubRecord(in, data.length);
byte[] ser2 = rec.serialize();
- assertTrue(Arrays.equals(data, ser2));
-
-
+ confirmData(data, ser2);
}
private static byte[] hr(String string) {
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestFormulaRecord.java Sun Oct 26 00:18:17 2008
@@ -119,7 +119,6 @@
public void testWithConcat() {
// =CHOOSE(2,A2,A3,A4)
byte[] data = {
- 6, 0, 68, 0,
1, 0, 1, 0, 15, 0, 0, 0, 0, 0, 0, 0, 57,
64, 0, 0, 12, 0, 12, -4, 46, 0,
30, 2, 0, // Int - 2
@@ -134,8 +133,7 @@
25, 8, 3, 0, // Attr
66, 4, 100, 0 // CHOOSE
};
- RecordInputStream inp = new RecordInputStream( new ByteArrayInputStream(data));
- inp.nextRecord();
+ RecordInputStream inp = TestcaseRecordInputStream.create(FormatRecord.sid, data);
FormulaRecord fr = new FormulaRecord(inp);
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java Sun Oct 26 00:18:17 2008
@@ -239,8 +239,7 @@
RecordInputStream is = TestcaseRecordInputStream.create(HyperlinkRecord.sid, data);
HyperlinkRecord link = new HyperlinkRecord(is);
byte[] bytes1 = link.serialize();
- is = new RecordInputStream(new ByteArrayInputStream(bytes1));
- is.nextRecord();
+ is = TestcaseRecordInputStream.create(bytes1);
link = new HyperlinkRecord(is);
byte[] bytes2 = link.serialize();
assertEquals(bytes1.length, bytes2.length);
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestSharedFormulaRecord.java Sun Oct 26 00:18:17 2008
@@ -23,6 +23,7 @@
import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.hssf.record.formula.RefPtg;
+import org.apache.poi.util.LittleEndianInput;
/**
* @author Josh Micich
@@ -59,7 +60,7 @@
*/
public void testConvertSharedFormulasOperandClasses_bug45123() {
- RecordInputStream in = TestcaseRecordInputStream.createWithFakeSid(SHARED_FORMULA_WITH_REF_ARRAYS_DATA);
+ LittleEndianInput in = TestcaseRecordInputStream.createLittleEndian(SHARED_FORMULA_WITH_REF_ARRAYS_DATA);
int encodedLen = in.readUShort();
Ptg[] sharedFormula = Ptg.readTokens(encodedLen, in);
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTextObjectBaseRecord.java Sun Oct 26 00:18:17 2008
@@ -55,11 +55,9 @@
public void testLoad() {
- RecordInputStream in = new RecordInputStream(new ByteArrayInputStream(data));
- in.nextRecord();
+ RecordInputStream in = TestcaseRecordInputStream.create(data);
TextObjectRecord record = new TextObjectRecord(in);
-
assertEquals(TextObjectRecord.HORIZONTAL_TEXT_ALIGNMENT_CENTERED, record.getHorizontalTextAlignment());
assertEquals(TextObjectRecord.VERTICAL_TEXT_ALIGNMENT_JUSTIFY, record.getVerticalTextAlignment());
assertEquals(true, record.isTextLocked());
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestTextObjectRecord.java Sun Oct 26 00:18:17 2008
@@ -52,8 +52,7 @@
public void testRead() {
- RecordInputStream is = new RecordInputStream(new ByteArrayInputStream(simpleData));
- is.nextRecord();
+ RecordInputStream is =TestcaseRecordInputStream.create(simpleData);
TextObjectRecord record = new TextObjectRecord(is);
assertEquals(TextObjectRecord.sid, record.getSid());
@@ -79,8 +78,7 @@
assertTrue(Arrays.equals(simpleData, ser));
//read again
- RecordInputStream is = new RecordInputStream(new ByteArrayInputStream(simpleData));
- is.nextRecord();
+ RecordInputStream is = TestcaseRecordInputStream.create(simpleData);
record = new TextObjectRecord(is);
}
@@ -101,8 +99,7 @@
assertEquals(22, ser.length); // just the TXO record
//read again
- RecordInputStream is = new RecordInputStream(new ByteArrayInputStream(ser));
- is.nextRecord();
+ RecordInputStream is = TestcaseRecordInputStream.create(ser);
record = new TextObjectRecord(is);
assertEquals(0, record.getStr().length());
}
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestcaseRecordInputStream.java Sun Oct 26 00:18:17 2008
@@ -23,6 +23,8 @@
import junit.framework.Assert;
import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.LittleEndianByteArrayInputStream;
+import org.apache.poi.util.LittleEndianInput;
/**
* A Record Input Stream derivative that makes access to byte arrays used in the
@@ -40,8 +42,8 @@
/**
* Prepends a mock record identifier to the supplied data and opens a record input stream
*/
- public static RecordInputStream createWithFakeSid(byte[] data) {
- return create(-5555, data);
+ public static LittleEndianInput createLittleEndian(byte[] data) {
+ return new LittleEndianByteArrayInputStream(data);
}
public static RecordInputStream create(int sid, byte[] data) {
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/constant/TestConstantValueParser.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/constant/TestConstantValueParser.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/constant/TestConstantValueParser.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/constant/TestConstantValueParser.java Sun Oct 26 00:18:17 2008
@@ -21,11 +21,12 @@
import junit.framework.TestCase;
-import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
import org.apache.poi.hssf.record.UnicodeString;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
import org.apache.poi.util.HexRead;
+import org.apache.poi.util.LittleEndianByteArrayOutputStream;
+import org.apache.poi.util.LittleEndianInput;
/**
*
* @author Josh Micich
@@ -52,14 +53,15 @@
public void testEncode() {
int size = ConstantValueParser.getEncodedSize(SAMPLE_VALUES);
byte[] data = new byte[size];
- ConstantValueParser.encode(data, 0, SAMPLE_VALUES);
+
+ ConstantValueParser.encode(new LittleEndianByteArrayOutputStream(data, 0), SAMPLE_VALUES);
if (!Arrays.equals(data, SAMPLE_ENCODING)) {
fail("Encoding differs");
}
}
public void testDecode() {
- RecordInputStream in = TestcaseRecordInputStream.createWithFakeSid(SAMPLE_ENCODING);
+ LittleEndianInput in = TestcaseRecordInputStream.createLittleEndian(SAMPLE_ENCODING);
Object[] values = ConstantValueParser.parse(in, 4);
for (int i = 0; i < values.length; i++) {
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestArrayPtg.java Sun Oct 26 00:18:17 2008
@@ -24,6 +24,8 @@
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
import org.apache.poi.hssf.record.UnicodeString;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.util.LittleEndianByteArrayOutputStream;
+import org.apache.poi.util.LittleEndianInput;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
@@ -54,9 +56,9 @@
*/
public void testReadWriteTokenValueBytes() {
- ArrayPtg ptg = new ArrayPtg(TestcaseRecordInputStream.createWithFakeSid(ENCODED_PTG_DATA));
+ ArrayPtg ptg = new ArrayPtg(TestcaseRecordInputStream.createLittleEndian(ENCODED_PTG_DATA));
- ptg.readTokenValues(TestcaseRecordInputStream.createWithFakeSid(ENCODED_CONSTANT_DATA));
+ ptg.readTokenValues(TestcaseRecordInputStream.createLittleEndian(ENCODED_CONSTANT_DATA));
assertEquals(3, ptg.getColumnCount());
assertEquals(2, ptg.getRowCount());
Object[][] values = ptg.getTokenArrayValues();
@@ -70,7 +72,7 @@
assertEquals(new UnicodeString("FG"), values[1][2]);
byte[] outBuf = new byte[ENCODED_CONSTANT_DATA.length];
- ptg.writeTokenValueBytes(outBuf, 0);
+ ptg.writeTokenValueBytes(new LittleEndianByteArrayOutputStream(outBuf, 0));
if(outBuf[0] == 4) {
throw new AssertionFailedError("Identified bug 42564b");
@@ -82,8 +84,8 @@
* Excel stores array elements column by column. This test makes sure POI does the same.
*/
public void testElementOrdering() {
- ArrayPtg ptg = new ArrayPtg(TestcaseRecordInputStream.createWithFakeSid(ENCODED_PTG_DATA));
- ptg.readTokenValues(TestcaseRecordInputStream.createWithFakeSid(ENCODED_CONSTANT_DATA));
+ ArrayPtg ptg = new ArrayPtg(TestcaseRecordInputStream.createLittleEndian(ENCODED_PTG_DATA));
+ ptg.readTokenValues(TestcaseRecordInputStream.createLittleEndian(ENCODED_CONSTANT_DATA));
assertEquals(3, ptg.getColumnCount());
assertEquals(2, ptg.getRowCount());
@@ -113,9 +115,9 @@
}
public void testToFormulaString() {
- ArrayPtg ptg = new ArrayPtg(TestcaseRecordInputStream.createWithFakeSid(ENCODED_PTG_DATA));
+ ArrayPtg ptg = new ArrayPtg(TestcaseRecordInputStream.createLittleEndian(ENCODED_PTG_DATA));
- ptg.readTokenValues(TestcaseRecordInputStream.createWithFakeSid(ENCODED_CONSTANT_DATA));
+ ptg.readTokenValues(TestcaseRecordInputStream.createLittleEndian(ENCODED_CONSTANT_DATA));
String actualFormula;
try {
@@ -146,7 +148,7 @@
// Force encoded operand class for tArray
fullData[0] = (byte) (ArrayPtg.sid + operandClass);
- RecordInputStream in = TestcaseRecordInputStream.createWithFakeSid(fullData);
+ LittleEndianInput in = TestcaseRecordInputStream.createLittleEndian(fullData);
Ptg[] ptgs = Ptg.readTokens(ENCODED_PTG_DATA.length, in);
assertEquals(1, ptgs.length);
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestAttrPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestAttrPtg.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestAttrPtg.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestAttrPtg.java Sun Oct 26 00:18:17 2008
@@ -21,9 +21,9 @@
import junit.framework.AssertionFailedError;
-import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
import org.apache.poi.util.HexRead;
+import org.apache.poi.util.LittleEndianInput;
/**
* Tests for {@link AttrPtg}.
@@ -37,7 +37,7 @@
*/
public void testReserializeAttrChoose() {
byte[] data = HexRead.readFromString("19, 04, 03, 00, 08, 00, 11, 00, 1A, 00, 23, 00");
- RecordInputStream in = TestcaseRecordInputStream.createWithFakeSid(data);
+ LittleEndianInput in = TestcaseRecordInputStream.createLittleEndian(data);
Ptg[] ptgs = Ptg.readTokens(data.length, in);
byte[] data2 = new byte[data.length];
try {
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestFuncPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestFuncPtg.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestFuncPtg.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestFuncPtg.java Sun Oct 26 00:18:17 2008
@@ -34,7 +34,7 @@
0,
};
- FuncPtg ptg = new FuncPtg(TestcaseRecordInputStream.createWithFakeSid(fakeData) );
+ FuncPtg ptg = new FuncPtg(TestcaseRecordInputStream.createLittleEndian(fakeData) );
assertEquals( "Len formula index is not 32(20H)", 0x20, ptg.getFunctionIndex() );
assertEquals( "Number of operands in the len formula", 1, ptg.getNumberOfOperands() );
assertEquals( "Function Name", "LEN", ptg.getName() );
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java Sun Oct 26 00:18:17 2008
@@ -23,10 +23,10 @@
import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.TestcaseRecordInputStream;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.util.LittleEndianInput;
/**
* Tests for {@link RefPtg}.
@@ -94,7 +94,7 @@
0x2C, 33, 44, 55, 66,
};
public void testReadWrite_tRefN_bug45091() {
- RecordInputStream in = TestcaseRecordInputStream.createWithFakeSid(tRefN_data);
+ LittleEndianInput in = TestcaseRecordInputStream.createLittleEndian(tRefN_data);
Ptg[] ptgs = Ptg.readTokens(tRefN_data.length, in);
byte[] outData = new byte[5];
Ptg.serializePtgs(ptgs, outData, 0);
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/poifs/filesystem/TestDocumentInputStream.java Sun Oct 26 00:18:17 2008
@@ -1,4 +1,3 @@
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -15,18 +14,16 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.filesystem;
-import java.io.*;
-
-import java.util.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Arrays;
-import junit.framework.*;
+import junit.framework.TestCase;
import org.apache.poi.poifs.property.DirectoryProperty;
-import org.apache.poi.poifs.property.DocumentProperty;
import org.apache.poi.poifs.storage.RawDataBlock;
/**
@@ -35,22 +32,9 @@
* @author Marc Johnson
*/
-public class TestDocumentInputStream
- extends TestCase
-{
+public final class TestDocumentInputStream extends TestCase {
- /**
- * Constructor TestDocumentInputStream
- *
- * @param name
- *
- * @exception IOException
- */
-
- public TestDocumentInputStream(String name)
- throws IOException
- {
- super(name);
+ protected void setUp() throws Exception {
int blocks = (_workbook_size + 511) / 512;
_workbook_data = new byte[ 512 * blocks ];
@@ -86,13 +70,8 @@
/**
* test constructor
- *
- * @exception IOException
*/
-
- public void testConstructor()
- throws IOException
- {
+ public void testConstructor() throws IOException {
DocumentInputStream stream = new DocumentInputStream(_workbook);
assertEquals(_workbook_size, stream.available());
@@ -100,13 +79,8 @@
/**
* test available() behavior
- *
- * @exception IOException
*/
-
- public void testAvailable()
- throws IOException
- {
+ public void testAvailable() throws IOException {
DocumentInputStream stream = new DocumentInputStream(_workbook);
assertEquals(_workbook_size, stream.available());
@@ -115,9 +89,7 @@
{
stream.available();
fail("Should have caught IOException");
- }
- catch (IOException ignored)
- {
+ } catch (IllegalStateException ignored) {
// as expected
}
@@ -125,13 +97,8 @@
/**
* test mark/reset/markSupported.
- *
- * @exception IOException
*/
-
- public void testMarkFunctions()
- throws IOException
- {
+ public void testMarkFunctions() throws IOException {
DocumentInputStream stream = new DocumentInputStream(_workbook);
byte[] buffer = new byte[ _workbook_size / 5 ];
@@ -169,13 +136,8 @@
/**
* test simple read method
- *
- * @exception IOException
*/
-
- public void testReadSingleByte()
- throws IOException
- {
+ public void testReadSingleByte() throws IOException {
DocumentInputStream stream = new DocumentInputStream(_workbook);
int remaining = _workbook_size;
@@ -205,13 +167,8 @@
/**
* Test buffered read
- *
- * @exception IOException
*/
-
- public void testBufferRead()
- throws IOException
- {
+ public void testBufferRead() throws IOException {
DocumentInputStream stream = new DocumentInputStream(_workbook);
try
@@ -275,23 +232,14 @@
/**
* Test complex buffered read
- *
- * @exception IOException
*/
-
- public void testComplexBufferRead()
- throws IOException
- {
+ public void testComplexBufferRead() throws IOException {
DocumentInputStream stream = new DocumentInputStream(_workbook);
- try
- {
+ try {
stream.read(null, 0, 1);
fail("Should have caught NullPointerException");
- }
- catch (NullPointerException ignored)
- {
-
+ } catch (IllegalArgumentException ignored) {
// as expected
}
@@ -391,13 +339,8 @@
/**
* test skip
- *
- * @exception IOException
*/
-
- public void testSkip()
- throws IOException
- {
+ public void testSkip() throws IOException {
DocumentInputStream stream = new DocumentInputStream(_workbook);
assertEquals(_workbook_size, stream.available());
@@ -422,17 +365,4 @@
stream.skip(2 + ( long ) Integer.MAX_VALUE));
assertEquals(0, stream.available());
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out.println(
- "Testing org.apache.poi.poifs.filesystem.DocumentInputStream");
- junit.textui.TestRunner.run(TestDocumentInputStream.class);
- }
}
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/AllPOIFSStorageTests.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/AllPOIFSStorageTests.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/AllPOIFSStorageTests.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/AllPOIFSStorageTests.java Sun Oct 26 00:18:17 2008
@@ -26,22 +26,22 @@
*/
public final class AllPOIFSStorageTests {
- public static Test suite() {
- TestSuite result = new TestSuite("Tests for org.apache.poi.poifs.storage");
- result.addTestSuite(TestBATBlock.class);
- result.addTestSuite(TestBlockAllocationTableReader.class);
- result.addTestSuite(TestBlockAllocationTableWriter.class);
- result.addTestSuite(TestBlockListImpl.class);
- result.addTestSuite(TestDocumentBlock.class);
- result.addTestSuite(TestHeaderBlockReader.class);
- result.addTestSuite(TestHeaderBlockWriter.class);
- result.addTestSuite(TestPropertyBlock.class);
- result.addTestSuite(TestRawDataBlock.class);
- result.addTestSuite(TestRawDataBlockList.class);
- result.addTestSuite(TestSmallBlockTableReader.class);
- result.addTestSuite(TestSmallBlockTableWriter.class);
- result.addTestSuite(TestSmallDocumentBlock.class);
- result.addTestSuite(TestSmallDocumentBlockList.class);
- return result;
- }
+ public static Test suite() {
+ TestSuite result = new TestSuite(AllPOIFSStorageTests.class.getName());
+ result.addTestSuite(TestBATBlock.class);
+ result.addTestSuite(TestBlockAllocationTableReader.class);
+ result.addTestSuite(TestBlockAllocationTableWriter.class);
+ result.addTestSuite(TestBlockListImpl.class);
+ result.addTestSuite(TestDocumentBlock.class);
+ result.addTestSuite(TestHeaderBlockReader.class);
+ result.addTestSuite(TestHeaderBlockWriter.class);
+ result.addTestSuite(TestPropertyBlock.class);
+ result.addTestSuite(TestRawDataBlock.class);
+ result.addTestSuite(TestRawDataBlockList.class);
+ result.addTestSuite(TestSmallBlockTableReader.class);
+ result.addTestSuite(TestSmallBlockTableWriter.class);
+ result.addTestSuite(TestSmallDocumentBlock.class);
+ result.addTestSuite(TestSmallDocumentBlockList.class);
+ return result;
+ }
}
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestDocumentBlock.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestDocumentBlock.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestDocumentBlock.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestDocumentBlock.java Sun Oct 26 00:18:17 2008
@@ -1,4 +1,3 @@
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -15,25 +14,21 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.storage;
-import java.io.*;
-
-import java.util.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
-import junit.framework.*;
+import junit.framework.TestCase;
/**
* Class to test DocumentBlock functionality
*
* @author Marc Johnson
*/
-
-public class TestDocumentBlock
- extends TestCase
-{
+public final class TestDocumentBlock extends TestCase {
static final private byte[] _testdata;
static
@@ -44,25 +39,10 @@
_testdata[ j ] = ( byte ) j;
}
}
- ;
-
- /**
- * Constructor TestDocumentBlock
- *
- * @param name
- */
-
- public TestDocumentBlock(String name)
- {
- super(name);
- }
/**
* Test the writing DocumentBlock constructor.
- *
- * @exception IOException
*/
-
public void testConstructor()
throws IOException
{
@@ -88,46 +68,10 @@
assertEquals(_testdata.length, size);
}
- /**
- * test static read method
- *
- * @exception IOException
- */
-
- public void testRead()
- throws IOException
- {
- DocumentBlock[] blocks = new DocumentBlock[ 4 ];
- ByteArrayInputStream input = new ByteArrayInputStream(_testdata);
-
- for (int j = 0; j < 4; j++)
- {
- blocks[ j ] = new DocumentBlock(input);
- }
- for (int j = 1; j <= 2000; j += 17)
- {
- byte[] buffer = new byte[ j ];
- int offset = 0;
-
- for (int k = 0; k < (2000 / j); k++)
- {
- DocumentBlock.read(blocks, buffer, offset);
- for (int n = 0; n < buffer.length; n++)
- {
- assertEquals("checking byte " + (k * j) + n,
- _testdata[ (k * j) + n ], buffer[ n ]);
- }
- offset += j;
- }
- }
- }
/**
* Test 'reading' constructor
- *
- * @exception IOException
*/
-
public void testReadingConstructor()
throws IOException
{
@@ -164,17 +108,4 @@
assertEquals(( byte ) 0xFF, copy[ j ]);
}
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out
- .println("Testing org.apache.poi.poifs.storage.DocumentBlock");
- junit.textui.TestRunner.run(TestDocumentBlock.class);
- }
}
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestSmallDocumentBlock.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestSmallDocumentBlock.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestSmallDocumentBlock.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/poifs/storage/TestSmallDocumentBlock.java Sun Oct 26 00:18:17 2008
@@ -1,4 +1,3 @@
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@@ -15,25 +14,24 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.poifs.storage;
-import java.io.*;
-
-import java.util.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
-import junit.framework.*;
+import junit.framework.TestCase;
/**
* Class to test SmallDocumentBlock functionality
*
* @author Marc Johnson
*/
-
-public class TestSmallDocumentBlock
- extends TestCase
-{
+public final class TestSmallDocumentBlock extends TestCase {
static final private byte[] _testdata;
static final private int _testdata_size = 2999;
@@ -45,25 +43,10 @@
_testdata[ j ] = ( byte ) j;
}
}
- ;
-
- /**
- * constructor
- *
- * @param name
- */
-
- public TestSmallDocumentBlock(String name)
- {
- super(name);
- }
/**
* Test conversion from DocumentBlocks
- *
- * @exception IOException
*/
-
public void testConvert1()
throws IOException
{
@@ -113,12 +96,7 @@
/**
* Test conversion from byte array
- *
- * @exception IOException;
- *
- * @exception IOException
*/
-
public void testConvert2()
throws IOException
{
@@ -155,56 +133,8 @@
}
/**
- * Test read method
- *
- * @exception IOException
- */
-
- public void testRead()
- throws IOException
- {
- ByteArrayInputStream stream = new ByteArrayInputStream(_testdata);
- List documents = new ArrayList();
-
- while (true)
- {
- DocumentBlock block = new DocumentBlock(stream);
-
- documents.add(block);
- if (block.partiallyRead())
- {
- break;
- }
- }
- SmallDocumentBlock[] blocks =
- SmallDocumentBlock
- .convert(( BlockWritable [] ) documents
- .toArray(new DocumentBlock[ 0 ]), _testdata_size);
-
- for (int j = 1; j <= _testdata_size; j += 38)
- {
- byte[] buffer = new byte[ j ];
- int offset = 0;
-
- for (int k = 0; k < (_testdata_size / j); k++)
- {
- SmallDocumentBlock.read(blocks, buffer, offset);
- for (int n = 0; n < buffer.length; n++)
- {
- assertEquals("checking byte " + (k * j) + n,
- _testdata[ (k * j) + n ], buffer[ n ]);
- }
- offset += j;
- }
- }
- }
-
- /**
* test fill
- *
- * @exception IOException
*/
-
public void testFill()
throws IOException
{
@@ -294,17 +224,4 @@
}
}
}
-
- /**
- * main method to run the unit tests
- *
- * @param ignored_args
- */
-
- public static void main(String [] ignored_args)
- {
- System.out.println(
- "Testing org.apache.poi.poifs.storage.SmallDocumentBlock");
- junit.textui.TestRunner.run(TestSmallDocumentBlock.class);
- }
}
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/util/AllPOIUtilTests.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/util/AllPOIUtilTests.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/util/AllPOIUtilTests.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/util/AllPOIUtilTests.java Sun Oct 26 00:18:17 2008
@@ -27,12 +27,11 @@
public final class AllPOIUtilTests {
public static Test suite() {
- TestSuite result = new TestSuite("Tests for org.apache.poi.util");
+ TestSuite result = new TestSuite(AllPOIUtilTests.class.getName());
result.addTestSuite(TestArrayUtil.class);
result.addTestSuite(TestBinaryTree.class);
result.addTestSuite(TestBitField.class);
result.addTestSuite(TestByteField.class);
- result.addTestSuite(TestDoubleList2d.class);
result.addTestSuite(TestHexDump.class);
result.addTestSuite(TestIntegerField.class);
result.addTestSuite(TestIntList.class);
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/util/TestLittleEndian.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/util/TestLittleEndian.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/util/TestLittleEndian.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/util/TestLittleEndian.java Sun Oct 26 00:18:17 2008
@@ -97,13 +97,13 @@
* test the getDouble() method
*/
public void testGetDouble() {
- assertEquals(_doubles[0], LittleEndian.getDouble(_double_array), 0.000001 );
+ assertEquals(_doubles[0], LittleEndian.getDouble(_double_array, 0), 0.000001 );
assertEquals(_doubles[1], LittleEndian.getDouble( _double_array, LittleEndian.DOUBLE_SIZE), 0.000001);
- assertTrue(Double.isNaN(LittleEndian.getDouble(_nan_double_array)));
+ assertTrue(Double.isNaN(LittleEndian.getDouble(_nan_double_array, 0)));
- double nan = LittleEndian.getDouble(_nan_double_array);
+ double nan = LittleEndian.getDouble(_nan_double_array, 0);
byte[] data = new byte[8];
- LittleEndian.putDouble(data, nan);
+ LittleEndian.putDouble(data, 0, nan);
for ( int i = 0; i < data.length; i++ ) {
assertEquals(data[i], _nan_double_array[i]);
}
@@ -144,7 +144,7 @@
(byte) 0x02,
};
- assertEquals(0xFFFFFFFFFFFFFF01L, LittleEndian.getLong(testdata));
+ assertEquals(0xFFFFFFFFFFFFFF01L, LittleEndian.getLong(testdata, 0));
assertEquals(0x02FFFFFFFFFFFFFFL, LittleEndian.getLong(testdata, 1));
}
@@ -194,7 +194,7 @@
public void testPutDouble() {
byte[] received = new byte[ LittleEndian.DOUBLE_SIZE + 1 ];
- LittleEndian.putDouble(received, _doubles[0]);
+ LittleEndian.putDouble(received, 0, _doubles[0]);
assertTrue(compareByteArrays(received, _double_array, 0, LittleEndian.DOUBLE_SIZE));
LittleEndian.putDouble(received, 1, _doubles[1]);
byte[] expected = new byte[ LittleEndian.DOUBLE_SIZE + 1 ];
@@ -224,7 +224,7 @@
long testdata0 = 0xFFFFFFFFFFFFFF01L;
long testdata1 = 0x02FFFFFFFFFFFFFFL;
- LittleEndian.putLong(received, testdata0);
+ LittleEndian.putLong(received, 0, testdata0);
assertTrue(compareByteArrays(received, expected, 0, LittleEndian.LONG_SIZE));
LittleEndian.putLong(received, 1, testdata1);
assertTrue(compareByteArrays(received, expected, 1, LittleEndian.LONG_SIZE));
Modified: poi/branches/ooxml/src/testcases/org/apache/poi/util/TestStringUtil.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/util/TestStringUtil.java?rev=707945&r1=707944&r2=707945&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/util/TestStringUtil.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/util/TestStringUtil.java Sun Oct 26 00:18:17 2008
@@ -42,43 +42,7 @@
super( name );
}
- /**
- * test simple form of getFromUnicode
- */
- public void testSimpleGetFromUnicode()
- {
- byte[] test_data = new byte[32];
- int index = 0;
-
- for ( int k = 0; k < 16; k++ )
- {
- test_data[index++] = (byte) 0;
- test_data[index++] = (byte) ( 'a' + k );
- }
-
- assertEquals( "abcdefghijklmnop",
- StringUtil.getFromUnicodeBE( test_data ) );
- }
-
- /**
- * test simple form of getFromUnicode with symbols with code below and more 127
- */
- public void testGetFromUnicodeSymbolsWithCodesMoreThan127()
- {
- byte[] test_data = new byte[]{0x04, 0x22,
- 0x04, 0x35,
- 0x04, 0x41,
- 0x04, 0x42,
- 0x00, 0x20,
- 0x00, 0x74,
- 0x00, 0x65,
- 0x00, 0x73,
- 0x00, 0x74,
- };
- assertEquals( "\u0422\u0435\u0441\u0442 test",
- StringUtil.getFromUnicodeBE( test_data ) );
- }
/**
* test getFromUnicodeHigh for symbols with code below and more 127
@@ -101,62 +65,7 @@
StringUtil.getFromUnicodeLE( test_data ) );
}
- /**
- * Test more complex form of getFromUnicode
- */
- public void testComplexGetFromUnicode()
- {
- byte[] test_data = new byte[32];
- int index = 0;
- for ( int k = 0; k < 16; k++ )
- {
- test_data[index++] = (byte) 0;
- test_data[index++] = (byte) ( 'a' + k );
- }
- assertEquals( "abcdefghijklmno",
- StringUtil.getFromUnicodeBE( test_data, 0, 15 ) );
- assertEquals( "bcdefghijklmnop",
- StringUtil.getFromUnicodeBE( test_data, 2, 15 ) );
- try
- {
- StringUtil.getFromUnicodeBE( test_data, -1, 16 );
- fail( "Should have caught ArrayIndexOutOfBoundsException" );
- }
- catch ( ArrayIndexOutOfBoundsException ignored )
- {
- // as expected
- }
- try
- {
- StringUtil.getFromUnicodeBE( test_data, 32, 16 );
- fail( "Should have caught ArrayIndexOutOfBoundsException" );
- }
- catch ( ArrayIndexOutOfBoundsException ignored )
- {
- // as expected
- }
-
- try
- {
- StringUtil.getFromUnicodeBE( test_data, 1, 16 );
- fail( "Should have caught IllegalArgumentException" );
- }
- catch ( IllegalArgumentException ignored )
- {
- // as expected
- }
-
- try
- {
- StringUtil.getFromUnicodeBE( test_data, 1, -1 );
- fail( "Should have caught IllegalArgumentException" );
- }
- catch ( IllegalArgumentException ignored )
- {
- // as expected
- }
- }
/**
* Test putCompressedUnicode
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org