add tests

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896287 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-12-22 19:32:58 +00:00
parent 5df24b681f
commit 4f03da511a
3 changed files with 26 additions and 16 deletions

View File

@ -194,7 +194,7 @@ public class ReadOnlySharedStringsTable extends DefaultHandler implements Shared
sheetParser.setContentHandler(this); sheetParser.setContentHandler(this);
sheetParser.parse(sheetSource); sheetParser.parse(sheetSource);
} catch(ParserConfigurationException e) { } catch(ParserConfigurationException e) {
throw new RuntimeException("SAX parser appears to be broken - " + e.getMessage()); throw new SAXException("SAX parser appears to be broken - " + e.getMessage());
} }
} }
} }

View File

@ -22,6 +22,7 @@ package org.apache.poi.xssf.eventusermodel;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -48,16 +49,22 @@ public final class TestReadOnlySharedStringsTable {
SharedStringsTable stbl = new SharedStringsTable(parts.get(0)); SharedStringsTable stbl = new SharedStringsTable(parts.get(0));
ReadOnlySharedStringsTable rtbl = new ReadOnlySharedStringsTable(parts.get(0)); ReadOnlySharedStringsTable rtbl = new ReadOnlySharedStringsTable(parts.get(0));
ReadOnlySharedStringsTable rtbl2;
try (InputStream stream = parts.get(0).getInputStream()){
rtbl2 = new ReadOnlySharedStringsTable(stream);
}
assertEquals(stbl.getCount(), rtbl.getCount()); assertEquals(stbl.getCount(), rtbl.getCount());
assertEquals(stbl.getUniqueCount(), rtbl.getUniqueCount()); assertEquals(stbl.getUniqueCount(), rtbl.getUniqueCount());
assertEquals(stbl.getUniqueCount(), rtbl2.getUniqueCount());
assertEquals(stbl.getCount(), stbl.getUniqueCount()); assertEquals(stbl.getCount(), stbl.getUniqueCount());
assertEquals(rtbl.getCount(), rtbl.getUniqueCount()); assertEquals(rtbl.getCount(), rtbl.getUniqueCount());
assertEquals(rtbl.getCount(), rtbl2.getUniqueCount());
for (int i = 0; i < stbl.getUniqueCount(); i++) { for (int i = 0; i < stbl.getUniqueCount(); i++) {
RichTextString i1 = stbl.getItemAt(i); RichTextString i1 = stbl.getItemAt(i);
RichTextString i2 = rtbl.getItemAt(i); assertEquals(i1.getString(), rtbl.getItemAt(i).getString());
assertEquals(i1.getString(), i2.getString()); assertEquals(i1.getString(), rtbl2.getItemAt(i).getString());
} }
} }
} }

View File

@ -17,33 +17,26 @@
package org.apache.poi.xssf.model; package org.apache.poi.xssf.model;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.binary.Hex;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.ss.usermodel.FillPatternType; import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.util.CellReference; import org.apache.poi.ss.util.CellReference;
import org.apache.poi.xssf.XSSFTestDataSamples; import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.model.ThemesTable.ThemeElement; import org.apache.poi.xssf.model.ThemesTable.ThemeElement;
import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
import static org.junit.jupiter.api.Assertions.*;
class TestThemesTable { class TestThemesTable {
private static final String testFileComplex = "Themes2.xlsx"; private static final String testFileComplex = "Themes2.xlsx";
// TODO .xls version available too, add HSSF support then check // TODO .xls version available too, add HSSF support then check
@ -165,6 +158,16 @@ class TestThemesTable {
void themedAndNonThemedColours() throws IOException { void themedAndNonThemedColours() throws IOException {
try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook(testFileComplex)) { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook(testFileComplex)) {
XSSFSheet sheet = wb.getSheetAt(0); XSSFSheet sheet = wb.getSheetAt(0);
ThemesTable themesTable = wb.getTheme();
XSSFColor color1 = themesTable.getThemeColor(0);
assertNotNull(color1);
assertNotEquals(0, color1.getRGB().length);
List<PackagePart> themeParts = wb.getPackage().getPartsByContentType(XSSFRelation.THEME.getContentType());
assertEquals(1, themeParts.size());
try (InputStream themeStream = themeParts.get(0).getInputStream()) {
ThemesTable themesTable2 = new ThemesTable(themeStream);
assertArrayEquals(color1.getRGB(), themesTable2.getThemeColor(0).getRGB());
}
String[] names = {"White", "Black", "Grey", "Dark Blue", "Blue", "Red", "Green"}; String[] names = {"White", "Black", "Grey", "Dark Blue", "Blue", "Red", "Green"};
String[] explicitFHexes = {"FFFFFFFF", "FF000000", "FFC0C0C0", "FF002060", String[] explicitFHexes = {"FFFFFFFF", "FF000000", "FFC0C0C0", "FF002060",