CFRule12 tests
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1690778 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
935491b4e2
commit
fdd0d249ca
@ -214,6 +214,7 @@ public final class CFRule12Record extends CFRuleBase implements FutureRecord {
|
|||||||
|
|
||||||
getFormula1().serializeTokens(out);
|
getFormula1().serializeTokens(out);
|
||||||
getFormula2().serializeTokens(out);
|
getFormula2().serializeTokens(out);
|
||||||
|
out.writeShort(getFormulaSize(formula_scale));
|
||||||
formula_scale.serializeTokens(out);
|
formula_scale.serializeTokens(out);
|
||||||
|
|
||||||
out.writeByte(ext_opts);
|
out.writeByte(ext_opts);
|
||||||
@ -243,7 +244,7 @@ public final class CFRule12Record extends CFRuleBase implements FutureRecord {
|
|||||||
}
|
}
|
||||||
len += getFormulaSize(getFormula1());
|
len += getFormulaSize(getFormula1());
|
||||||
len += getFormulaSize(getFormula2());
|
len += getFormulaSize(getFormula2());
|
||||||
len += 4 + getFormulaSize(formula_scale);
|
len += 2 + getFormulaSize(formula_scale);
|
||||||
len += 6 + template_params.length;
|
len += 6 + template_params.length;
|
||||||
|
|
||||||
byte type = getConditionType();
|
byte type = getConditionType();
|
||||||
@ -278,7 +279,7 @@ public final class CFRule12Record extends CFRuleBase implements FutureRecord {
|
|||||||
buffer.append(" .formula_1 =").append(Arrays.toString(getFormula1().getTokens())).append("\n");
|
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_2 =").append(Arrays.toString(getFormula2().getTokens())).append("\n");
|
||||||
buffer.append(" .formula_S =").append(Arrays.toString(formula_scale.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(" .priority =").append(priority).append("\n");
|
||||||
buffer.append(" .template_type =").append(template_type).append("\n");
|
buffer.append(" .template_type =").append(template_type).append("\n");
|
||||||
buffer.append(" .template_params=").append(HexDump.toHex(template_params)).append("\n");
|
buffer.append(" .template_params=").append(HexDump.toHex(template_params)).append("\n");
|
||||||
|
@ -22,7 +22,7 @@ import org.apache.poi.ss.usermodel.BaseTestConditionalFormatting;
|
|||||||
import org.apache.poi.xssf.XSSFITestDataProvider;
|
import org.apache.poi.xssf.XSSFITestDataProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Yegor Kozlov
|
* XSSF-specific Conditional Formatting tests
|
||||||
*/
|
*/
|
||||||
public class TestXSSFConditionalFormatting extends BaseTestConditionalFormatting {
|
public class TestXSSFConditionalFormatting extends BaseTestConditionalFormatting {
|
||||||
public TestXSSFConditionalFormatting(){
|
public TestXSSFConditionalFormatting(){
|
||||||
@ -32,4 +32,9 @@ public class TestXSSFConditionalFormatting extends BaseTestConditionalFormatting
|
|||||||
public void testRead(){
|
public void testRead(){
|
||||||
testRead("WithConditionalFormatting.xlsx");
|
testRead("WithConditionalFormatting.xlsx");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void IGNORED_testReadOffice2007() {
|
||||||
|
// TODO Bring the XSSF support up to the same level
|
||||||
|
testReadOffice2007("NewStyleConditionalFormattings.xlsx");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import static org.junit.Assert.assertArrayEquals;
|
|||||||
import junit.framework.AssertionFailedError;
|
import junit.framework.AssertionFailedError;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.HSSFITestDataProvider;
|
||||||
import org.apache.poi.hssf.record.CFRuleBase.ComparisonOperator;
|
import org.apache.poi.hssf.record.CFRuleBase.ComparisonOperator;
|
||||||
import org.apache.poi.hssf.record.cf.BorderFormatting;
|
import org.apache.poi.hssf.record.cf.BorderFormatting;
|
||||||
import org.apache.poi.hssf.record.cf.FontFormatting;
|
import org.apache.poi.hssf.record.cf.FontFormatting;
|
||||||
@ -36,8 +37,8 @@ import org.apache.poi.util.LittleEndian;
|
|||||||
/**
|
/**
|
||||||
* Tests the serialization and deserialization of the TestCFRuleRecord
|
* Tests the serialization and deserialization of the TestCFRuleRecord
|
||||||
* class works correctly.
|
* class works correctly.
|
||||||
* TODO Add {@link CFRule12Record} tests
|
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("resource")
|
||||||
public final class TestCFRuleRecord extends TestCase {
|
public final class TestCFRuleRecord extends TestCase {
|
||||||
public void testConstructors () {
|
public void testConstructors () {
|
||||||
HSSFWorkbook workbook = new HSSFWorkbook();
|
HSSFWorkbook workbook = new HSSFWorkbook();
|
||||||
@ -90,19 +91,37 @@ public final class TestCFRuleRecord extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCreateCFRule12Record() {
|
||||||
|
HSSFWorkbook workbook = new HSSFWorkbook();
|
||||||
|
HSSFSheet sheet = workbook.createSheet();
|
||||||
|
CFRule12Record record = CFRule12Record.create(sheet, "7");
|
||||||
|
testCFRule12Record(record);
|
||||||
|
|
||||||
|
// 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) {
|
private void testCFRuleRecord(CFRuleRecord record) {
|
||||||
FontFormatting fontFormatting = new FontFormatting();
|
testCFRuleBase(record);
|
||||||
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());
|
|
||||||
|
|
||||||
assertFalse(record.isLeftBorderModified());
|
assertFalse(record.isLeftBorderModified());
|
||||||
record.setLeftBorderModified(true);
|
record.setLeftBorderModified(true);
|
||||||
assertTrue(record.isLeftBorderModified());
|
assertTrue(record.isLeftBorderModified());
|
||||||
@ -128,12 +147,6 @@ public final class TestCFRuleRecord extends TestCase {
|
|||||||
assertTrue(record.isBottomLeftTopRightBorderModified());
|
assertTrue(record.isBottomLeftTopRightBorderModified());
|
||||||
|
|
||||||
|
|
||||||
PatternFormatting patternFormatting = new PatternFormatting();
|
|
||||||
testPatternFormattingAccessors(patternFormatting);
|
|
||||||
assertFalse(record.containsPatternFormattingBlock());
|
|
||||||
record.setPatternFormatting(patternFormatting);
|
|
||||||
assertTrue(record.containsPatternFormattingBlock());
|
|
||||||
|
|
||||||
assertFalse(record.isPatternBackgroundColorModified());
|
assertFalse(record.isPatternBackgroundColorModified());
|
||||||
record.setPatternBackgroundColorModified(true);
|
record.setPatternBackgroundColorModified(true);
|
||||||
assertTrue(record.isPatternBackgroundColorModified());
|
assertTrue(record.isPatternBackgroundColorModified());
|
||||||
@ -146,6 +159,30 @@ public final class TestCFRuleRecord extends TestCase {
|
|||||||
record.setPatternStyleModified(true);
|
record.setPatternStyleModified(true);
|
||||||
assertTrue(record.isPatternStyleModified());
|
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) {
|
private void testPatternFormattingAccessors(PatternFormatting patternFormatting) {
|
||||||
patternFormatting.setFillBackgroundColor(HSSFColor.GREEN.index);
|
patternFormatting.setFillBackgroundColor(HSSFColor.GREEN.index);
|
||||||
@ -364,4 +401,12 @@ public final class TestCFRuleRecord extends TestCase {
|
|||||||
byte [] serializedClone = clone.serialize();
|
byte [] serializedClone = clone.serialize();
|
||||||
assertArrayEquals(serializedRecord, serializedClone);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,17 +28,20 @@ import org.apache.poi.ss.usermodel.SheetConditionalFormatting;
|
|||||||
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* HSSF-specific Conditional Formatting tests
|
||||||
* @author Dmitriy Kumshayev
|
|
||||||
*/
|
*/
|
||||||
public final class TestHSSFConditionalFormatting extends BaseTestConditionalFormatting {
|
public final class TestHSSFConditionalFormatting extends BaseTestConditionalFormatting {
|
||||||
public TestHSSFConditionalFormatting(){
|
public TestHSSFConditionalFormatting(){
|
||||||
super(HSSFITestDataProvider.instance);
|
super(HSSFITestDataProvider.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRead(){
|
public void testRead() {
|
||||||
testRead("WithConditionalFormatting.xls");
|
testRead("WithConditionalFormatting.xls");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testReadOffice2007() {
|
||||||
|
testReadOffice2007("NewStyleConditionalFormattings.xls");
|
||||||
|
}
|
||||||
|
|
||||||
public void test53691() throws IOException {
|
public void test53691() throws IOException {
|
||||||
SheetConditionalFormatting cf;
|
SheetConditionalFormatting cf;
|
||||||
|
@ -24,8 +24,7 @@ import org.apache.poi.ss.ITestDataProvider;
|
|||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dmitriy Kumshayev
|
* Base tests for Conditional Formatting, for both HSSF and XSSF
|
||||||
* @author Yegor Kozlov
|
|
||||||
*/
|
*/
|
||||||
public abstract class BaseTestConditionalFormatting extends TestCase {
|
public abstract class BaseTestConditionalFormatting extends TestCase {
|
||||||
private final ITestDataProvider _testDataProvider;
|
private final ITestDataProvider _testDataProvider;
|
||||||
@ -525,6 +524,31 @@ public abstract class BaseTestConditionalFormatting extends TestCase {
|
|||||||
assertEquals("\"AAA\"", rule5.getFormula2());
|
assertEquals("\"AAA\"", rule5.getFormula2());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testReadOffice2007(String filename) {
|
||||||
|
Workbook wb = _testDataProvider.openSampleWorkbook(filename);
|
||||||
|
Sheet s = wb.getSheet("CF");
|
||||||
|
ConditionalFormatting cf = null;
|
||||||
|
|
||||||
|
// Sanity check data
|
||||||
|
assertEquals("Values", s.getRow(0).getCell(0).toString());
|
||||||
|
assertEquals("10.0", s.getRow(2).getCell(0).toString());
|
||||||
|
|
||||||
|
// Check we found all the conditional formattings rules we should have
|
||||||
|
SheetConditionalFormatting sheetCF = s.getSheetConditionalFormatting();
|
||||||
|
assertEquals(1, sheetCF.getNumConditionalFormattings()); // TODO Should be more!
|
||||||
|
|
||||||
|
cf = sheetCF.getConditionalFormattingAt(0);
|
||||||
|
//System.out.println(cf);
|
||||||
|
|
||||||
|
|
||||||
|
// Check the rules / values in detail
|
||||||
|
|
||||||
|
// Highlight Positive values - Column C
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
// Highlight 10-30 - Column D
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
public void testCreateFontFormatting() {
|
public void testCreateFontFormatting() {
|
||||||
Workbook workbook = _testDataProvider.createWorkbook();
|
Workbook workbook = _testDataProvider.createWorkbook();
|
||||||
|
Loading…
Reference in New Issue
Block a user