bug 59212: Do not check for overlapping regions when adding merged regions to a sheet
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1736165 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e2615ce68e
commit
1128818a70
@ -24,6 +24,7 @@ import static org.junit.Assert.assertNull;
|
|||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -442,6 +443,54 @@ public abstract class BaseTestSheet {
|
|||||||
wb.close();
|
wb.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* bug 58885: checking for overlapping merged regions when
|
||||||
|
* adding a merged region is safe, but runs in O(n).
|
||||||
|
* the check for merged regions when adding a merged region
|
||||||
|
* can be skipped (unsafe) and run in O(1).
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void addMergedRegionUnsafe() throws IOException {
|
||||||
|
Workbook wb = _testDataProvider.createWorkbook();
|
||||||
|
Sheet sh = wb.createSheet();
|
||||||
|
CellRangeAddress region1 = CellRangeAddress.valueOf("A1:B2");
|
||||||
|
CellRangeAddress region2 = CellRangeAddress.valueOf("B2:C3");
|
||||||
|
CellRangeAddress region3 = CellRangeAddress.valueOf("C3:D4");
|
||||||
|
CellRangeAddress region4 = CellRangeAddress.valueOf("J10:K11");
|
||||||
|
assumeTrue(region1.intersects(region2));
|
||||||
|
assumeTrue(region2.intersects(region3));
|
||||||
|
|
||||||
|
sh.addMergedRegionUnsafe(region1);
|
||||||
|
assertTrue(sh.getMergedRegions().contains(region1));
|
||||||
|
|
||||||
|
// adding a duplicate or overlapping merged region should not
|
||||||
|
// raise an exception with the unsafe version of addMergedRegion.
|
||||||
|
|
||||||
|
sh.addMergedRegionUnsafe(region2);
|
||||||
|
|
||||||
|
// the safe version of addMergedRegion should throw when trying to add a merged region that overlaps an existing region
|
||||||
|
assertTrue(sh.getMergedRegions().contains(region2));
|
||||||
|
try {
|
||||||
|
sh.addMergedRegion(region3);
|
||||||
|
fail("Expected IllegalStateException. region3 overlaps already added merged region2.");
|
||||||
|
} catch (final IllegalStateException e) {
|
||||||
|
// expected
|
||||||
|
assertFalse(sh.getMergedRegions().contains(region3));
|
||||||
|
}
|
||||||
|
// addMergedRegion should not re-validate previously-added merged regions
|
||||||
|
sh.addMergedRegion(region4);
|
||||||
|
|
||||||
|
// validation methods should detect a problem with previously added merged regions (runs in O(n^2) time)
|
||||||
|
try {
|
||||||
|
sh.validateMergedRegions();
|
||||||
|
fail("Expected validation to fail. Sheet contains merged regions A1:B2 and B2:C3, which overlap at B2.");
|
||||||
|
} catch (final IllegalStateException e) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
|
||||||
|
wb.close();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the display of gridlines, formulas, and rowcolheadings.
|
* Tests the display of gridlines, formulas, and rowcolheadings.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user