Search in sources :

Example 1 with LittleEndianInput

use of org.apache.poi.util.LittleEndianInput in project poi by apache.

the class EmbeddedObjectRefSubRecord method readRefPtg.

private static Ptg readRefPtg(byte[] formulaRawBytes) {
    LittleEndianInput in = new LittleEndianInputStream(new ByteArrayInputStream(formulaRawBytes));
    byte ptgSid = in.readByte();
    switch(ptgSid) {
        case AreaPtg.sid:
            return new AreaPtg(in);
        case Area3DPtg.sid:
            return new Area3DPtg(in);
        case RefPtg.sid:
            return new RefPtg(in);
        case Ref3DPtg.sid:
            return new Ref3DPtg(in);
    }
    return null;
}
Also used : LittleEndianInput(org.apache.poi.util.LittleEndianInput) ByteArrayInputStream(java.io.ByteArrayInputStream) Area3DPtg(org.apache.poi.ss.formula.ptg.Area3DPtg) LittleEndianInputStream(org.apache.poi.util.LittleEndianInputStream) AreaPtg(org.apache.poi.ss.formula.ptg.AreaPtg) RefPtg(org.apache.poi.ss.formula.ptg.RefPtg) Ref3DPtg(org.apache.poi.ss.formula.ptg.Ref3DPtg)

Example 2 with LittleEndianInput

use of org.apache.poi.util.LittleEndianInput in project poi by apache.

the class TestUnicodeString method extRstEqualsAndHashCode.

@Test
public void extRstEqualsAndHashCode() {
    byte[] buf = new byte[200];
    LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(buf, 0);
    String str = "ᴂᴒᴢ";
    bos.writeShort(1);
    // data size
    bos.writeShort(5 * LittleEndianConsts.SHORT_SIZE + str.length() * 2 + 3 * LittleEndianConsts.SHORT_SIZE + 2);
    bos.writeShort(0x4711);
    bos.writeShort(0x0815);
    bos.writeShort(1);
    bos.writeShort(str.length());
    bos.writeShort(str.length());
    StringUtil.putUnicodeLE(str, bos);
    bos.writeShort(1);
    bos.writeShort(1);
    bos.writeShort(3);
    bos.writeShort(42);
    LittleEndianInput in = new LittleEndianByteArrayInputStream(buf, 0, bos.getWriteIndex());
    UnicodeString.ExtRst extRst1 = new UnicodeString.ExtRst(in, bos.getWriteIndex());
    in = new LittleEndianByteArrayInputStream(buf, 0, bos.getWriteIndex());
    UnicodeString.ExtRst extRst2 = new UnicodeString.ExtRst(in, bos.getWriteIndex());
    assertEquals(extRst1, extRst2);
    assertEquals(extRst1.hashCode(), extRst2.hashCode());
}
Also used : LittleEndianByteArrayOutputStream(org.apache.poi.util.LittleEndianByteArrayOutputStream) LittleEndianInput(org.apache.poi.util.LittleEndianInput) LittleEndianByteArrayInputStream(org.apache.poi.util.LittleEndianByteArrayInputStream) ExtRst(org.apache.poi.hssf.record.common.UnicodeString.ExtRst) ExtRst(org.apache.poi.hssf.record.common.UnicodeString.ExtRst) Test(org.junit.Test)

Example 3 with LittleEndianInput

use of org.apache.poi.util.LittleEndianInput in project poi by apache.

the class TestConstantValueParser method testDecode.

@Test
public void testDecode() {
    LittleEndianInput in = TestcaseRecordInputStream.createLittleEndian(SAMPLE_ENCODING);
    Object[] values = ConstantValueParser.parse(in, 4);
    for (int i = 0; i < values.length; i++) {
        if (!isEqual(SAMPLE_VALUES[i], values[i])) {
            fail("Decoded result differs");
        }
    }
}
Also used : LittleEndianInput(org.apache.poi.util.LittleEndianInput) Test(org.junit.Test)

Example 4 with LittleEndianInput

use of org.apache.poi.util.LittleEndianInput in project poi by apache.

the class TestSharedFormulaRecord method testConvertSharedFormulasOperandClasses_bug45123.

/**
     * The method <tt>SharedFormulaRecord.convertSharedFormulas()</tt> converts formulas from
     * 'shared formula' to 'single cell formula' format.  It is important that token operand
     * classes are preserved during this transformation, because Excel may not tolerate the
     * incorrect encoding.  The formula here is one such example (Excel displays #VALUE!).
     */
public void testConvertSharedFormulasOperandClasses_bug45123() {
    LittleEndianInput in = TestcaseRecordInputStream.createLittleEndian(SHARED_FORMULA_WITH_REF_ARRAYS_DATA);
    int encodedLen = in.readUShort();
    Ptg[] sharedFormula = Ptg.readTokens(encodedLen, in);
    SharedFormula sf = new SharedFormula(SpreadsheetVersion.EXCEL97);
    Ptg[] convertedFormula = sf.convertSharedFormulas(sharedFormula, 100, 200);
    RefPtg refPtg = (RefPtg) convertedFormula[1];
    assertEquals("$C101", refPtg.toFormulaString());
    if (refPtg.getPtgClass() == Ptg.CLASS_REF) {
        throw new AssertionFailedError("Identified bug 45123");
    }
    confirmOperandClasses(sharedFormula, convertedFormula);
}
Also used : Ptg(org.apache.poi.ss.formula.ptg.Ptg) RefPtg(org.apache.poi.ss.formula.ptg.RefPtg) LittleEndianInput(org.apache.poi.util.LittleEndianInput) RefPtg(org.apache.poi.ss.formula.ptg.RefPtg) AssertionFailedError(junit.framework.AssertionFailedError) SharedFormula(org.apache.poi.ss.formula.SharedFormula)

Example 5 with LittleEndianInput

use of org.apache.poi.util.LittleEndianInput in project poi by apache.

the class TestReferencePtg method testReadWrite_tRefN_bug45091.

public void testReadWrite_tRefN_bug45091() {
    LittleEndianInput in = TestcaseRecordInputStream.createLittleEndian(tRefN_data);
    Ptg[] ptgs = Ptg.readTokens(tRefN_data.length, in);
    byte[] outData = new byte[5];
    Ptg.serializePtgs(ptgs, outData, 0);
    if (outData[0] == 0x24) {
        throw new AssertionFailedError("Identified bug 45091");
    }
    assertArrayEquals(tRefN_data, outData);
}
Also used : LittleEndianInput(org.apache.poi.util.LittleEndianInput) AssertionFailedError(junit.framework.AssertionFailedError)

Aggregations

LittleEndianInput (org.apache.poi.util.LittleEndianInput)7 AssertionFailedError (junit.framework.AssertionFailedError)3 RefPtg (org.apache.poi.ss.formula.ptg.RefPtg)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ExtRst (org.apache.poi.hssf.record.common.UnicodeString.ExtRst)1 SharedFormula (org.apache.poi.ss.formula.SharedFormula)1 Area3DPtg (org.apache.poi.ss.formula.ptg.Area3DPtg)1 AreaPtg (org.apache.poi.ss.formula.ptg.AreaPtg)1 Ptg (org.apache.poi.ss.formula.ptg.Ptg)1 Ref3DPtg (org.apache.poi.ss.formula.ptg.Ref3DPtg)1 LittleEndianByteArrayInputStream (org.apache.poi.util.LittleEndianByteArrayInputStream)1 LittleEndianByteArrayOutputStream (org.apache.poi.util.LittleEndianByteArrayOutputStream)1 LittleEndianInputStream (org.apache.poi.util.LittleEndianInputStream)1