getFormula1().serializeTokens(out);
getFormula2().serializeTokens(out);
+ out.writeShort(getFormulaSize(formula_scale));
formula_scale.serializeTokens(out);
out.writeByte(ext_opts);
}
len += getFormulaSize(getFormula1());
len += getFormulaSize(getFormula2());
- len += 4 + getFormulaSize(formula_scale);
+ len += 2 + getFormulaSize(formula_scale);
len += 6 + template_params.length;
byte type = getConditionType();
buffer.append(" .formula_1 =").append(Arrays.toString(getFormula1().getTokens())).append("\n");
buffer.append(" .formula_2 =").append(Arrays.toString(getFormula2().getTokens())).append("\n");
buffer.append(" .formula_S =").append(Arrays.toString(formula_scale.getTokens())).append("\n");
- buffer.append(" .ext Opts =").append(ext_opts).append("\n");
+ buffer.append(" .ext_opts =").append(ext_opts).append("\n");
buffer.append(" .priority =").append(priority).append("\n");
buffer.append(" .template_type =").append(template_type).append("\n");
buffer.append(" .template_params=").append(HexDump.toHex(template_params)).append("\n");
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
+import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.hssf.record.CFRuleBase.ComparisonOperator;
import org.apache.poi.hssf.record.cf.BorderFormatting;
import org.apache.poi.hssf.record.cf.FontFormatting;
/**
* Tests the serialization and deserialization of the TestCFRuleRecord
* class works correctly.
- * TODO Add {@link CFRule12Record} tests
*/
+@SuppressWarnings("resource")
public final class TestCFRuleRecord extends TestCase {
public void testConstructors () {
HSSFWorkbook workbook = new HSSFWorkbook();
}
}
- private void testCFRuleRecord(CFRuleRecord record) {
- FontFormatting fontFormatting = new FontFormatting();
- testFontFormattingAccessors(fontFormatting);
- assertFalse(record.containsFontFormattingBlock());
- record.setFontFormatting(fontFormatting);
- assertTrue(record.containsFontFormattingBlock());
+ public void testCreateCFRule12Record() {
+ HSSFWorkbook workbook = new HSSFWorkbook();
+ HSSFSheet sheet = workbook.createSheet();
+ CFRule12Record record = CFRule12Record.create(sheet, "7");
+ testCFRule12Record(record);
- BorderFormatting borderFormatting = new BorderFormatting();
- testBorderFormattingAccessors(borderFormatting);
- assertFalse(record.containsBorderFormattingBlock());
- record.setBorderFormatting(borderFormatting);
- assertTrue(record.containsBorderFormattingBlock());
+ // Serialize
+ byte [] serializedRecord = record.serialize();
+ // Strip header
+ byte [] recordData = new byte[serializedRecord.length-4];
+ System.arraycopy(serializedRecord, 4, recordData, 0, recordData.length);
+
+ // Deserialize
+ record = new CFRule12Record(TestcaseRecordInputStream.create(CFRule12Record.sid, recordData));
+
+ // Serialize again
+ byte[] output = record.serialize();
+
+ // Compare
+ assertEquals("Output size", recordData.length+4, output.length); //includes sid+recordlength
+
+ for (int i = 0; i < recordData.length;i++)
+ {
+ assertEquals("CFRule12Record doesn't match", recordData[i], output[i+4]);
+ }
+ }
+
+ private void testCFRuleRecord(CFRuleRecord record) {
+ testCFRuleBase(record);
+
assertFalse(record.isLeftBorderModified());
record.setLeftBorderModified(true);
assertTrue(record.isLeftBorderModified());
assertTrue(record.isBottomLeftTopRightBorderModified());
- PatternFormatting patternFormatting = new PatternFormatting();
- testPatternFormattingAccessors(patternFormatting);
- assertFalse(record.containsPatternFormattingBlock());
- record.setPatternFormatting(patternFormatting);
- assertTrue(record.containsPatternFormattingBlock());
-
assertFalse(record.isPatternBackgroundColorModified());
record.setPatternBackgroundColorModified(true);
assertTrue(record.isPatternBackgroundColorModified());
record.setPatternStyleModified(true);
assertTrue(record.isPatternStyleModified());
}
+ private void testCFRule12Record(CFRule12Record record) {
+ assertEquals(CFRule12Record.sid, record.getFutureRecordType());
+ assertEquals("A1", record.getAssociatedRange().formatAsString());
+ testCFRuleBase(record);
+ }
+ private void testCFRuleBase(CFRuleBase record) {
+ FontFormatting fontFormatting = new FontFormatting();
+ testFontFormattingAccessors(fontFormatting);
+ assertFalse(record.containsFontFormattingBlock());
+ record.setFontFormatting(fontFormatting);
+ assertTrue(record.containsFontFormattingBlock());
+
+ BorderFormatting borderFormatting = new BorderFormatting();
+ testBorderFormattingAccessors(borderFormatting);
+ assertFalse(record.containsBorderFormattingBlock());
+ record.setBorderFormatting(borderFormatting);
+ assertTrue(record.containsBorderFormattingBlock());
+
+ PatternFormatting patternFormatting = new PatternFormatting();
+ testPatternFormattingAccessors(patternFormatting);
+ assertFalse(record.containsPatternFormattingBlock());
+ record.setPatternFormatting(patternFormatting);
+ assertTrue(record.containsPatternFormattingBlock());
+ }
private void testPatternFormattingAccessors(PatternFormatting patternFormatting) {
patternFormatting.setFillBackgroundColor(HSSFColor.GREEN.index);
byte [] serializedClone = clone.serialize();
assertArrayEquals(serializedRecord, serializedClone);
}
+
+ // TODO Fix this test!
+ public void IGNORED_testBug57231_rewrite() {
+ HSSFWorkbook wb = HSSFITestDataProvider.instance.openSampleWorkbook("57231_MixedGasReport.xls");
+ assertEquals(7, wb.getNumberOfSheets());
+ wb = HSSFITestDataProvider.instance.writeOutAndReadBack(wb);
+ assertEquals(7, wb.getNumberOfSheets());
+ }
}
import org.apache.poi.ss.util.CellRangeAddress;\r
\r
/**\r
- * @author Dmitriy Kumshayev\r
- * @author Yegor Kozlov\r
+ * Base tests for Conditional Formatting, for both HSSF and XSSF\r
*/\r
public abstract class BaseTestConditionalFormatting extends TestCase {\r
private final ITestDataProvider _testDataProvider;\r
assertEquals("\"AAA\"", rule5.getFormula2());\r
}\r
\r
+ public void testReadOffice2007(String filename) {\r
+ Workbook wb = _testDataProvider.openSampleWorkbook(filename);\r
+ Sheet s = wb.getSheet("CF");\r
+ ConditionalFormatting cf = null;\r
+ \r
+ // Sanity check data\r
+ assertEquals("Values", s.getRow(0).getCell(0).toString());\r
+ assertEquals("10.0", s.getRow(2).getCell(0).toString());\r
+\r
+ // Check we found all the conditional formattings rules we should have\r
+ SheetConditionalFormatting sheetCF = s.getSheetConditionalFormatting();\r
+ assertEquals(1, sheetCF.getNumConditionalFormattings()); // TODO Should be more!\r
+ \r
+ cf = sheetCF.getConditionalFormattingAt(0);\r
+ //System.out.println(cf);\r
+ \r
+ \r
+ // Check the rules / values in detail\r
+ \r
+ // Highlight Positive values - Column C\r
+ // TODO\r
+ \r
+ // Highlight 10-30 - Column D\r
+ // TODO\r
+ }\r
\r
public void testCreateFontFormatting() {\r
Workbook workbook = _testDataProvider.createWorkbook();\r