aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache/poi/hssf/usermodel/TestUnfixedBugs.java
blob: a059a025f7cec0141ad13ca1229d849e36a599a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* ====================================================================
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
==================================================================== */

package org.apache.poi.hssf.usermodel;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.io.IOException;

import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.RecordFormatException;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.junit.Test;

import junit.framework.AssertionFailedError;

/**
 * @author aviks
 * 
 * This testcase contains tests for bugs that are yet to be fixed. Therefore,
 * the standard ant test target does not run these tests. Run this testcase with
 * the single-test target. The names of the tests usually correspond to the
 * Bugzilla id's PLEASE MOVE tests from this class to TestBugs once the bugs are
 * fixed, so that they are then run automatically.
 */
public final class TestUnfixedBugs {

    @Test
	public void test43493() {
		// Has crazy corrupt sub-records on
		// a EmbeddedObjectRefSubRecord
		try {
			HSSFTestDataSamples.openSampleWorkbook("43493.xls");
		} catch (RecordFormatException e) {
			if (e.getCause().getCause() instanceof ArrayIndexOutOfBoundsException) {
				throw new AssertionFailedError("Identified bug 43493");
			}
			throw e;
		}
	}

	/**
	 * Note - some parts of this bug have been fixed, and have been
	 * transfered over to {@link TestBugs#bug49612_part()}
	 */
    @Test
    public void test49612() throws IOException {
        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("49612.xls");
        HSSFSheet sh = wb.getSheetAt(0);
        HSSFRow row = sh.getRow(0);
        HSSFCell c1 = row.getCell(2);
        HSSFCell d1 = row.getCell(3);
        HSSFCell e1 = row.getCell(2);

        assertEquals("SUM(BOB+JIM)", c1.getCellFormula());

        // Problem 1: Filename missing, see bug #56742
        assertEquals("SUM('49612.xls'!BOB+'49612.xls'!JIM)", d1.getCellFormula());

        //Problem 2: Filename missing, see bug #56742
        //junit.framework.ComparisonFailure:
        //Expected :SUM('49612.xls'!BOB+'49612.xls'!JIM)
        //Actual   :SUM(BOB+JIM)
        assertEquals("SUM('49612.xls'!BOB+'49612.xls'!JIM)", e1.getCellFormula());
        
        // Problem 3 - fixed and transfered
        wb.close();
    }

    @Test
    public void testFormulaRecordAggregate_1() throws Exception {
        // fails at formula "=MEHRFACH.OPERATIONEN(E$3;$B$5;$D4)"
        Workbook wb = HSSFTestDataSamples.openSampleWorkbook("44958_1.xls");
        try {
            for(int i = 0;i < wb.getNumberOfSheets();i++) {
                Sheet sheet = wb.getSheetAt(i);
                assertNotNull(wb.getSheet(sheet.getSheetName()));
                sheet.groupColumn((short) 4, (short) 5);
                sheet.setColumnGroupCollapsed(4, true);
                sheet.setColumnGroupCollapsed(4, false);
                
                for(Row row : sheet) {
                    for(Cell cell : row) {
                        try {
                            cell.toString();
                        } catch (Exception e) {
                            throw new Exception("While handling: " + sheet.getSheetName() + "/" + row.getRowNum() + "/" + cell.getColumnIndex(), e);
                        }
                    }
                }
            }
        } finally {
            wb.close();
        }
    }

    @Test
    public void testFormulaRecordAggregate() throws Exception {
        // fails at formula "=MEHRFACH.OPERATIONEN(E$3;$B$5;$D4)"
        Workbook wb = HSSFTestDataSamples.openSampleWorkbook("44958.xls");
        try {
            for(int i = 0;i < wb.getNumberOfSheets();i++) {
                Sheet sheet = wb.getSheetAt(i);
                assertNotNull(wb.getSheet(sheet.getSheetName()));
                sheet.groupColumn((short) 4, (short) 5);
                sheet.setColumnGroupCollapsed(4, true);
                sheet.setColumnGroupCollapsed(4, false);
                
                for(Row row : sheet) {
                    for(Cell cell : row) {
                        try {
                            cell.toString();
                        } catch (Exception e) {
                            throw new Exception("While handling: " + sheet.getSheetName() + "/" + row.getRowNum() + "/" + cell.getColumnIndex(), e);
                        }
                    }
                }
            } 
        } finally {
            wb.close();
        }
    }

    @Test
    public void testBug57074() throws IOException {
        Workbook wb = HSSFTestDataSamples.openSampleWorkbook("57074.xls");
        Sheet sheet = wb.getSheet("Sheet1");
        Row row = sheet.getRow(0);
        Cell cell = row.getCell(0);
        
        HSSFColor bgColor = (HSSFColor) cell.getCellStyle().getFillBackgroundColorColor();
        String bgColorStr = bgColor.getTriplet()[0]+", "+bgColor.getTriplet()[1]+", "+bgColor.getTriplet()[2];
        //System.out.println(bgColorStr);
        assertEquals("215, 228, 188", bgColorStr);

        HSSFColor fontColor = (HSSFColor) cell.getCellStyle().getFillForegroundColorColor();
        String fontColorStr = fontColor.getTriplet()[0]+", "+fontColor.getTriplet()[1]+", "+fontColor.getTriplet()[2];
        //System.out.println(fontColorStr);
        assertEquals("0, 128, 128", fontColorStr);
        wb.close();
    }
}