View | Details | Raw Unified | Return to bug 58466
Collapse All | Expand All

(-)a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/helpers/TestColumnHelper.java (-19 / +96 lines)
Lines 154-189 public final class TestColumnHelper extends TestCase { Link Here
154
        col4.setMax(9);
154
        col4.setMax(9);
155
        assertEquals(4, cols1.sizeOfColArray());
155
        assertEquals(4, cols1.sizeOfColArray());
156
156
157
        CTCol col5 = CTCol.Factory.newInstance();
157
        // No overlap
158
        col5.setMin(4);
158
        helper.addCleanColIntoCols(cols1, createCol(4, 5));
159
        col5.setMax(5);
160
        helper.addCleanColIntoCols(cols1, col5);
161
        assertEquals(5, cols1.sizeOfColArray());
159
        assertEquals(5, cols1.sizeOfColArray());
162
160
163
        CTCol col6 = CTCol.Factory.newInstance();
161
        // Overlaps with 8 - 9 (overlap and after replacements required)
164
        col6.setMin(8);
162
        CTCol col6 = createCol(8, 11);
165
        col6.setMax(11);
166
        col6.setHidden(true);
163
        col6.setHidden(true);
167
        helper.addCleanColIntoCols(cols1, col6);
164
        helper.addCleanColIntoCols(cols1, col6);
168
        assertEquals(6, cols1.sizeOfColArray());
165
        assertEquals(6, cols1.sizeOfColArray());
169
166
170
        CTCol col7 = CTCol.Factory.newInstance();
167
        // Overlaps with 8 - 9 (before and overlap replacements required)
171
        col7.setMin(6);
168
        CTCol col7 = createCol(6, 8);
172
        col7.setMax(8);
173
        col7.setWidth(17.0);
169
        col7.setWidth(17.0);
174
        helper.addCleanColIntoCols(cols1, col7);
170
        helper.addCleanColIntoCols(cols1, col7);
175
        assertEquals(8, cols1.sizeOfColArray());
171
        assertEquals(8, cols1.sizeOfColArray());
176
172
177
        CTCol col8 = CTCol.Factory.newInstance();
173
        // Overlaps with 13 - 16750 (before, overlap and after replacements required)
178
        col8.setMin(20);
174
        helper.addCleanColIntoCols(cols1, createCol(20, 30));
179
        col8.setMax(30);
180
        helper.addCleanColIntoCols(cols1, col8);
181
        assertEquals(10, cols1.sizeOfColArray());
175
        assertEquals(10, cols1.sizeOfColArray());
182
176
183
        CTCol col9 = CTCol.Factory.newInstance();
177
        // Overlaps with 20 - 30 (before, overlap and after replacements required)
184
        col9.setMin(25);
178
        helper.addCleanColIntoCols(cols1, createCol(25, 27));
185
        col9.setMax(27);
186
        helper.addCleanColIntoCols(cols1, col9);
187
179
188
        // TODO - assert something interesting
180
        // TODO - assert something interesting
189
        assertEquals(12, cols1.sizeOfColArray());
181
        assertEquals(12, cols1.sizeOfColArray());
Lines 191-196 public final class TestColumnHelper extends TestCase { Link Here
191
        assertEquals(16750, cols1.getColArray(11).getMax());
183
        assertEquals(16750, cols1.getColArray(11).getMax());
192
    }
184
    }
193
185
186
    public void testAddCleanColIntoColsExactOverlap() throws Exception {
187
        CTCols cols = createHiddenAndBestFitColsWithHelper(1, 1, 1, 1);
188
        assertEquals(1, cols.sizeOfColArray());
189
        assertMinMaxHiddenBestFit(cols, 0, 1, 1, true, true);
190
    }
191
192
    public void testAddCleanColIntoColsOverlapsOverhangingBothSides() throws Exception {
193
        CTCols cols = createHiddenAndBestFitColsWithHelper(2, 2, 1, 3);
194
        assertEquals(3, cols.sizeOfColArray());
195
        assertMinMaxHiddenBestFit(cols, 0, 1, 1, false, true);
196
        assertMinMaxHiddenBestFit(cols, 1, 2, 2, true, true);
197
        assertMinMaxHiddenBestFit(cols, 2, 3, 3, false, true);
198
    }
199
200
    public void testAddCleanColIntoColsOverlapsCompletelyNested() throws Exception {
201
        CTCols cols = createHiddenAndBestFitColsWithHelper(1, 3, 2, 2);
202
        assertEquals(3, cols.sizeOfColArray());
203
        assertMinMaxHiddenBestFit(cols, 0, 1, 1, true, false);
204
        assertMinMaxHiddenBestFit(cols, 1, 2, 2, true, true);
205
        assertMinMaxHiddenBestFit(cols, 2, 3, 3, true, false);
206
    }
207
208
    public void testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRightExactRight() throws Exception {
209
        CTCols cols = createHiddenAndBestFitColsWithHelper(2, 3, 1, 3);
210
        assertEquals(2, cols.sizeOfColArray());
211
        assertMinMaxHiddenBestFit(cols, 0, 1, 1, false, true);
212
        assertMinMaxHiddenBestFit(cols, 1, 2, 3, true, true);
213
    }
214
215
    public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeftExactLeft() throws Exception {
216
        CTCols cols = createHiddenAndBestFitColsWithHelper(1, 2, 1, 3);
217
        assertEquals(2, cols.sizeOfColArray());
218
        assertMinMaxHiddenBestFit(cols, 0, 1, 2, true, true);
219
        assertMinMaxHiddenBestFit(cols, 1, 3, 3, false, true);
220
    }
221
222
    public void testAddCleanColIntoColsNewOverlapsOverhangingLeftNotRight() throws Exception {
223
        CTCols cols = createHiddenAndBestFitColsWithHelper(2, 3, 1, 2);
224
        assertEquals(3, cols.sizeOfColArray());
225
        assertMinMaxHiddenBestFit(cols, 0, 1, 1, false, true);
226
        assertMinMaxHiddenBestFit(cols, 1, 2, 2, true, true);
227
        assertMinMaxHiddenBestFit(cols, 2, 3, 3, true, false);
228
    }
229
230
    public void testAddCleanColIntoColsNewOverlapsOverhangingRightNotLeft() throws Exception {
231
        CTCols cols = createHiddenAndBestFitColsWithHelper(1, 2, 2, 3);
232
        assertEquals(3, cols.sizeOfColArray());
233
        assertMinMaxHiddenBestFit(cols, 0, 1, 1, true, false);
234
        assertMinMaxHiddenBestFit(cols, 1, 2, 2, true, true);
235
        assertMinMaxHiddenBestFit(cols, 2, 3, 3, false, true);
236
    }
237
238
    /**
239
     * Creates and adds a hidden column and then a best fit column with the given min/max pairs.
240
     * Suitable for testing handling of overlap. 
241
     */
242
    private CTCols createHiddenAndBestFitColsWithHelper(int hiddenMin, int hiddenMax, int bestFitMin, int bestFitMax) {
243
        CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
244
        ColumnHelper helper = new ColumnHelper(worksheet);
245
        CTCols cols = worksheet.getColsArray(0);
246
247
        CTCol hidden = createCol(hiddenMin, hiddenMax);
248
        hidden.setHidden(true);
249
        helper.addCleanColIntoCols(cols, hidden);
250
251
        CTCol bestFit = createCol(bestFitMin, bestFitMax);
252
        bestFit.setBestFit(true);
253
        helper.addCleanColIntoCols(cols, bestFit);
254
        return cols;
255
    }
256
257
    private void assertMinMaxHiddenBestFit(CTCols cols, int index, int min, int max, boolean hidden, boolean bestFit) {
258
        CTCol col = cols.getColArray(index);
259
        assertEquals(min, col.getMin());
260
        assertEquals(max, col.getMax());
261
        assertEquals(hidden, col.getHidden());
262
        assertEquals(bestFit, col.getBestFit());
263
    }
264
265
    private CTCol createCol(int min, int max) {
266
        CTCol col = CTCol.Factory.newInstance();
267
        col.setMin(min);
268
        col.setMax(max);
269
        return col;
270
    }
271
194
    public void testGetColumn() {
272
    public void testGetColumn() {
195
        CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
273
        CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
196
274
197
- 

Return to bug 58466