public void TestNRules() { HSSFWorkbook workbook = new HSSFWorkbook(); CellRangeAddress[] cellRanges = { new CellRangeAddress(0, 1, 0, 0), new CellRangeAddress(0, 1, 2, 2), }; CFRuleRecord[] rules = { CFRuleRecord.Create(workbook, "7"), CFRuleRecord.Create(workbook, ComparisonOperator.BETWEEN,"2", "5"), }; CFRecordsAggregate agg = new CFRecordsAggregate(cellRanges, rules); byte[] serializedRecord = new byte[agg.RecordSize]; agg.Serialize(0, serializedRecord); int nRules = NPOI.Util.LittleEndian.GetUShort(serializedRecord, 4); if (nRules == 0) { throw new AssertFailedException("Identified bug 45682 b"); } Assert.AreEqual(rules.Length, nRules); }
public void TestCFRecordsAggregate1() { HSSFWorkbook workbook = new HSSFWorkbook(); HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet(); List <Record> recs = new List <Record>(); CFHeaderBase header = new CFHeaderRecord(); CFRuleBase rule1 = CFRuleRecord.Create(sheet, "7"); CFRuleBase rule2 = CFRuleRecord.Create(sheet, (byte)ComparisonOperator.Between, "2", "5"); CFRuleBase rule3 = CFRuleRecord.Create(sheet, (byte)ComparisonOperator.GreaterThanOrEqual, "100", null); header.NumberOfConditionalFormats = (3); CellRangeAddress[] cellRanges = { new CellRangeAddress(0, 1, 0, 0), new CellRangeAddress(0, 1, 2, 2), }; header.CellRanges = (cellRanges); recs.Add(header); recs.Add(rule1); recs.Add(rule2); recs.Add(rule3); CFRecordsAggregate record = CFRecordsAggregate.CreateCFAggregate(new RecordStream(recs, 0)); // Serialize byte [] serializedRecord = new byte[record.RecordSize]; record.Serialize(0, serializedRecord); Stream in1 = new MemoryStream(serializedRecord); //Parse recs = RecordFactory.CreateRecords(in1); // Verify Assert.IsNotNull(recs); Assert.AreEqual(4, recs.Count); header = (CFHeaderRecord)recs[0]; rule1 = (CFRuleRecord)recs[1]; Assert.IsNotNull(rule1); rule2 = (CFRuleRecord)recs[2]; Assert.IsNotNull(rule2); rule3 = (CFRuleRecord)recs[3]; Assert.IsNotNull(rule3); cellRanges = header.CellRanges; Assert.AreEqual(2, cellRanges.Length); Assert.AreEqual(3, header.NumberOfConditionalFormats); Assert.IsFalse(header.NeedRecalculation); record = CFRecordsAggregate.CreateCFAggregate(new RecordStream(recs, 0)); record = record.CloneCFAggregate(); Assert.IsNotNull(record.Header); Assert.AreEqual(3, record.NumberOfRules); header = record.Header; rule1 = record.GetRule(0); Assert.IsNotNull(rule1); rule2 = record.GetRule(1); Assert.IsNotNull(rule2); rule3 = record.GetRule(2); Assert.IsNotNull(rule3); cellRanges = header.CellRanges; Assert.AreEqual(2, cellRanges.Length); Assert.AreEqual(3, header.NumberOfConditionalFormats); Assert.IsFalse(header.NeedRecalculation); }