public void TestReadWriteTokenValueBytes() { ArrayPtg ptg = Create(ENCODED_PTG_DATA, ENCODED_CONSTANT_DATA); Assert.AreEqual(3, ptg.ColumnCount); Assert.AreEqual(2, ptg.RowCount); Object[,] values = ptg.GetTokenArrayValues(); Assert.AreEqual(2, values.Length); Assert.AreEqual(true, values[0, 0]); Assert.AreEqual("ABCD", values[0, 1]); Assert.AreEqual(0d, values[1, 0]); Assert.AreEqual(false, values[1, 1]); Assert.AreEqual("FG", values[1, 2]); byte[] outBuf = new byte[ENCODED_CONSTANT_DATA.Length]; ptg.WriteTokenValueBytes(new LittleEndianByteArrayOutputStream(outBuf, 0)); if (outBuf[0] == 4) { throw new AssertionException("Identified bug 42564b"); } Assert.IsTrue(Arrays.Equals(ENCODED_CONSTANT_DATA, outBuf)); }
public void TestReadWriteTokenValueBytes() { ArrayPtg ptg = new ArrayPtg(TestcaseRecordInputStream.CreateWithFakeSid(ENCODED_PTG_DATA)); ptg.ReadTokenValues(TestcaseRecordInputStream.CreateWithFakeSid(ENCODED_CONSTANT_DATA)); Assert.AreEqual(3, ptg.ColumnCount); Assert.AreEqual(2, ptg.RowCount); object[] values = ptg.GetTokenArrayValues(); Assert.AreEqual(6, values.Length); Assert.AreEqual(true, values[0]); Assert.AreEqual("ABCD", values[1]); Assert.AreEqual(0, Convert.ToInt32(values[3])); Assert.AreEqual(false, values[4]); Assert.AreEqual("FG", values[5]); byte[] outBuf = new byte[ENCODED_CONSTANT_DATA.Length]; ptg.WriteTokenValueBytes(new LittleEndianByteArrayOutputStream(outBuf, 0)); if (outBuf[0] == 4) { throw new AssertFailedException("Identified bug 42564b"); } Assert.IsTrue(NPOI.Util.Arrays.Equals(ENCODED_CONSTANT_DATA, outBuf)); }
private void assert_bug50244(NameRecord nr) { Assert.AreEqual("wDataGruppeSerie.", nr.NameText); Ptg[] ptg = nr.NameDefinition; Assert.AreEqual(1, ptg.Length); ArrayPtg arr = (ArrayPtg)ptg[0]; Assert.AreEqual(696, arr.RowCount); Assert.AreEqual(1, arr.ColumnCount); Object[][] vals = arr.GetTokenArrayValues(); Assert.AreEqual("1.T20.001", vals[0][0]); Assert.AreEqual("1.T20.010", vals[vals.Length - 1][0]); }
/** * returns an appropriate Eval impl instance for the Ptg. The Ptg must be * one of: Area3DPtg, AreaPtg, ReferencePtg, Ref3DPtg, IntPtg, NumberPtg, * StringPtg, BoolPtg <br/>special Note: OperationPtg subtypes cannot be * passed here! */ private ValueEval GetEvalForPtg(Ptg ptg, OperationEvaluationContext ec) { // consider converting all these (ptg is XxxPtg) expressions To (ptg.GetType() == XxxPtg.class) if (ptg is NamePtg) { // Named ranges, macro functions NamePtg namePtg = (NamePtg)ptg; IEvaluationName nameRecord = _workbook.GetName(namePtg); return(GetEvalForNameRecord(nameRecord, ec)); } if (ptg is NameXPtg) { // Externally defined named ranges or macro functions return(ProcessNameEval(ec.GetNameXEval((NameXPtg)ptg), ec)); } if (ptg is NameXPxg) { // Externally defined named ranges or macro functions return(ProcessNameEval(ec.GetNameXEval((NameXPxg)ptg), ec)); } if (ptg is IntPtg) { return(new NumberEval(((IntPtg)ptg).Value)); } if (ptg is NumberPtg) { return(new NumberEval(((NumberPtg)ptg).Value)); } if (ptg is StringPtg) { return(new StringEval(((StringPtg)ptg).Value)); } if (ptg is BoolPtg) { return(BoolEval.ValueOf(((BoolPtg)ptg).Value)); } if (ptg is ErrPtg) { return(ErrorEval.ValueOf(((ErrPtg)ptg).ErrorCode)); } if (ptg is MissingArgPtg) { return(MissingArgEval.instance); } if (ptg is AreaErrPtg || ptg is RefErrorPtg || ptg is DeletedArea3DPtg || ptg is DeletedRef3DPtg) { return(ErrorEval.REF_INVALID); } if (ptg is Ref3DPtg) { return(ec.GetRef3DEval((Ref3DPtg)ptg)); } if (ptg is Ref3DPxg) { return(ec.GetRef3DEval((Ref3DPxg)ptg)); } if (ptg is Area3DPtg) { return(ec.GetArea3DEval((Area3DPtg)ptg)); } if (ptg is Area3DPxg) { return(ec.GetArea3DEval((Area3DPxg)ptg)); } if (ptg is RefPtg) { RefPtg rptg = (RefPtg)ptg; return(ec.GetRefEval(rptg.Row, rptg.Column)); } if (ptg is AreaPtg) { AreaPtg aptg = (AreaPtg)ptg; return(ec.GetAreaEval(aptg.FirstRow, aptg.FirstColumn, aptg.LastRow, aptg.LastColumn)); } if (ptg is ArrayPtg) { ArrayPtg aptg = (ArrayPtg)ptg; return(ec.GetAreaValueEval(0, 0, aptg.RowCount - 1, aptg.ColumnCount - 1, aptg.GetTokenArrayValues())); } if (ptg is UnknownPtg) { // POI uses UnknownPtg when the encoded Ptg array seems To be corrupted. // This seems To occur in very rare cases (e.g. unused name formulas in bug 44774, attachment 21790) // In any case, formulas are re-parsed before execution, so UnknownPtg should not Get here throw new RuntimeException("UnknownPtg not allowed"); } if (ptg is ExpPtg) { // ExpPtg is used for array formulas and shared formulas. // it is currently unsupported, and may not even get implemented here throw new RuntimeException("ExpPtg currently not supported"); } throw new RuntimeException("Unexpected ptg class (" + ptg.GetType().Name + ")"); }