public void TestExtraStringRecord_bug46213()
        {
            FormulaRecord fr = new FormulaRecord();
            fr.Value = (2.0);
            StringRecord sr = new StringRecord();
            sr.String = ("NA");
            SharedValueManager svm = SharedValueManager.CreateEmpty();
            FormulaRecordAggregate fra;

            try
            {
                fra = new FormulaRecordAggregate(fr, sr, svm);
            }
            catch (RecordFormatException e)
            {
                if ("String record was  supplied but formula record flag is not  set".Equals(e.Message))
                {
                    throw new AssertionException("Identified bug 46213");
                }
                throw e;
            }
            TestCases.HSSF.UserModel.RecordInspector.RecordCollector rc = new TestCases.HSSF.UserModel.RecordInspector.RecordCollector();
            fra.VisitContainedRecords(rc);
            Record[] vraRecs = rc.Records;
            Assert.AreEqual(1, vraRecs.Length);
            Assert.AreEqual(fr, vraRecs[0]);
        }
Esempio n. 2
0
        public void TestLoad()
        {

            StringRecord record = new StringRecord(TestcaseRecordInputStream.Create(0x207, data));
            Assert.AreEqual("Fahrzeugtyp", record.String);

            Assert.AreEqual(18, record.RecordSize);
        }
 public void TestBasic()
 {
     FormulaRecord f = new FormulaRecord();
     f.SetCachedResultTypeString();
     StringRecord s = new StringRecord();
     s.String = ("abc");
     FormulaRecordAggregate fagg = new FormulaRecordAggregate(f, s, SharedValueManager.CreateEmpty());
     Assert.AreEqual("abc", fagg.StringValue);
 }
Esempio n. 4
0
        public void TestStore()
        {
            StringRecord record = new StringRecord();
            record.String = (/*setter*/"Fahrzeugtyp");

            byte[] recordBytes = record.Serialize();
            Assert.AreEqual(recordBytes.Length - 4, data.Length);
            for (int i = 0; i < data.Length; i++)
                Assert.AreEqual(data[i], recordBytes[i + 4], "At offset " + i);
        }
Esempio n. 5
0
        public void TestContinue()
        {
            int MAX_BIFF_DATA = RecordInputStream.MAX_RECORD_DATA_SIZE;
            int TEXT_LEN = MAX_BIFF_DATA + 1000; // deliberately over-size
            String textChunk = "ABCDEGGHIJKLMNOP"; // 16 chars
            StringBuilder sb = new StringBuilder(16384);
            while (sb.Length < TEXT_LEN)
            {
                sb.Append(textChunk);
            }
            sb.Length = (/*setter*/TEXT_LEN);

            StringRecord sr = new StringRecord();
            sr.String = (/*setter*/sb.ToString());
            byte[] ser = sr.Serialize();
            Assert.AreEqual(StringRecord.sid, LittleEndian.GetUShort(ser, 0));
            if (LittleEndian.GetUShort(ser, 2) > MAX_BIFF_DATA)
            {
                throw new AssertionException(
                        "StringRecord should have been split with a continue record");
            }
            // Confirm expected size of first record, and ushort strLen.
            Assert.AreEqual(MAX_BIFF_DATA, LittleEndian.GetUShort(ser, 2));
            Assert.AreEqual(TEXT_LEN, LittleEndian.GetUShort(ser, 4));

            // Confirm first few bytes of ContinueRecord
            ILittleEndianInput crIn = new LittleEndianByteArrayInputStream(ser, (MAX_BIFF_DATA + 4));
            int nCharsInFirstRec = MAX_BIFF_DATA - (2 + 1); // strLen, optionFlags
            int nCharsInSecondRec = TEXT_LEN - nCharsInFirstRec;
            Assert.AreEqual(ContinueRecord.sid, crIn.ReadUShort());
            Assert.AreEqual(1 + nCharsInSecondRec, crIn.ReadUShort());
            Assert.AreEqual(0, crIn.ReadUByte());
            Assert.AreEqual('N', crIn.ReadUByte());
            Assert.AreEqual('O', crIn.ReadUByte());

            // re-read and make sure string value is the same
            RecordInputStream in1 = TestcaseRecordInputStream.Create(ser);
            StringRecord sr2 = new StringRecord(in1);
            Assert.AreEqual(sb.ToString(), sr2.String);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FormulaRecordAggregate"/> class.
        /// </summary>
        /// <param name="formulaRec">The formula rec.</param>
        /// <param name="stringRec">The string rec.</param>
        /// <param name="svm">The SVM.</param>
        public FormulaRecordAggregate(FormulaRecord formulaRec, StringRecord stringRec, SharedValueManager svm)
        {
            if (svm == null)
            {
                throw new ArgumentException("sfm must not be null");
            }
            bool hasStringRec = stringRec != null;
            bool hasCachedStringFlag = formulaRec.HasCachedResultString;
            if (hasStringRec != hasCachedStringFlag)
            {
                throw new RecordFormatException("String record was "
                        + (hasStringRec ? "" : "not ") + " supplied but formula record flag is "
                        + (hasCachedStringFlag ? "" : "not ") + " set");
            }

            if (formulaRec.IsSharedFormula)
            {
                svm.ConvertSharedFormulaRecord(formulaRec);
            }
            _formulaRecord = formulaRec;
            _sharedValueManager = svm;
            _stringRecord = stringRec;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FormulaRecordAggregate"/> class.
        /// </summary>
        /// <param name="formulaRec">The formula rec.</param>
        /// <param name="stringRec">The string rec.</param>
        /// <param name="svm">The SVM.</param>
        public FormulaRecordAggregate(FormulaRecord formulaRec, StringRecord stringRec, SharedValueManager svm)
        {
            if (svm == null)
            {
                throw new ArgumentException("sfm must not be null");
            }
            if (formulaRec.HasCachedResultString)
            {
                if (stringRec == null)
                {
                    throw new RecordFormatException("Formula record flag is set but String record was not found");
                }
                _stringRecord = stringRec;
            }
            else
            {
                // Usually stringRec is null here (in agreement with what the formula rec says).
                // In the case where an extra StringRecord is erroneously present, Excel (2007)
                // ignores it (see bug 46213).
                _stringRecord = null;
            }

            _formulaRecord = formulaRec;
            _sharedValueManager = svm;
            if (formulaRec.IsSharedFormula)
            {
                CellReference firstCell = formulaRec.Formula.ExpReference;
                if (firstCell == null)
                {
                    HandleMissingSharedFormulaRecord(formulaRec);
                }
                else
                {
                    _sharedFormulaRecord = svm.LinkSharedFormulaRecord(firstCell, this);
                }
            }
        }
 public override void Dispose()
 {
     _formulaRecord = null;
     _sharedValueManager.Dispose();
     _stringRecord = null;
 }
 /// <summary>
 /// Sets the cached error result.
 /// </summary>
 /// <param name="errorCode">The error code.</param>
 public void SetCachedErrorResult(int errorCode)
 {
     _stringRecord = null;
     _formulaRecord.SetCachedResultErrorCode(errorCode);
 }
 /// <summary>
 /// Sets the cached boolean result.
 /// </summary>
 /// <param name="value">if set to <c>true</c> [value].</param>
 public void SetCachedBooleanResult(bool value)
 {
     _stringRecord = null;
     _formulaRecord.SetCachedResultBoolean(value);
 }
        /// <summary>
        /// Sets the cached string result.
        /// </summary>
        /// <param name="value">The value.</param>
        public void SetCachedStringResult(String value)
        {

            // Save the string into a String Record, creating one if required
            if (_stringRecord == null)
            {
                _stringRecord = new StringRecord();
            }
            _stringRecord.String=(value);
            if (value.Length < 1)
            {
                _formulaRecord.SetCachedResultTypeEmptyString();
            }
            else
            {
                _formulaRecord.SetCachedResultTypeString();
            }
        }
 public void SetCachedDoubleResult(double value)
 {
     _stringRecord = null;
     _formulaRecord.Value = value;
 }
Esempio n. 13
0
 public override Object Clone()
 {
     StringRecord rec = new StringRecord();
     rec._is16bitUnicode = this._is16bitUnicode;
     rec._text = this._text;
     return rec;
 }
Esempio n. 14
0
 public override Object Clone()
 {
     StringRecord rec = new StringRecord();
     rec.field_2_unicode_flag = this.field_2_unicode_flag;
     rec.field_3_string = this.field_3_string;
     return rec;
 }