]> source.dussan.org Git - poi.git/commitdiff
add tests
authorPJ Fanning <fanningpj@apache.org>
Wed, 22 Dec 2021 19:32:58 +0000 (19:32 +0000)
committerPJ Fanning <fanningpj@apache.org>
Wed, 22 Dec 2021 19:32:58 +0000 (19:32 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896287 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/ReadOnlySharedStringsTable.java
poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java
poi-ooxml/src/test/java/org/apache/poi/xssf/model/TestThemesTable.java

index d27bd37666cc39a4cd0e1639e739d72db161a334..0ca6e685df0d54965c3cd80ca44654e780c4430a 100644 (file)
@@ -194,7 +194,7 @@ public class ReadOnlySharedStringsTable extends DefaultHandler implements Shared
                 sheetParser.setContentHandler(this);
                 sheetParser.parse(sheetSource);
             } 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());
             }
         }
     }
index 6b814589e460e81ad841a6e8f2fc3ba8392b0938..992dc32113ecfecb1c688333062e57295e16d604 100644 (file)
@@ -22,6 +22,7 @@ package org.apache.poi.xssf.eventusermodel;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.List;
 import java.util.regex.Pattern;
 
@@ -48,16 +49,22 @@ public final class TestReadOnlySharedStringsTable {
 
             SharedStringsTable stbl = new SharedStringsTable(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.getUniqueCount(), rtbl.getUniqueCount());
+            assertEquals(stbl.getUniqueCount(), rtbl2.getUniqueCount());
 
             assertEquals(stbl.getCount(), stbl.getUniqueCount());
             assertEquals(rtbl.getCount(), rtbl.getUniqueCount());
+            assertEquals(rtbl.getCount(), rtbl2.getUniqueCount());
             for (int i = 0; i < stbl.getUniqueCount(); i++) {
                 RichTextString i1 = stbl.getItemAt(i);
-                RichTextString i2 = rtbl.getItemAt(i);
-                assertEquals(i1.getString(), i2.getString());
+                assertEquals(i1.getString(), rtbl.getItemAt(i).getString());
+                assertEquals(i1.getString(), rtbl2.getItemAt(i).getString());
             }
         }
     }
index b50d6911852a149e70e3aa51622dc0d573e9aa6f..225d3f3f67ebe50caea0074ba2e15b99ea4331f0 100644 (file)
 
 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.IOException;
+import java.io.InputStream;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
 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.util.CellReference;
 import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.model.ThemesTable.ThemeElement;
-import org.apache.poi.xssf.usermodel.XSSFCell;
-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.apache.poi.xssf.usermodel.*;
 import org.junit.jupiter.api.Test;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
 
+import static org.junit.jupiter.api.Assertions.*;
+
 class TestThemesTable {
     private static final String testFileComplex = "Themes2.xlsx";
     // TODO .xls version available too, add HSSF support then check
@@ -165,6 +158,16 @@ class TestThemesTable {
     void themedAndNonThemedColours() throws IOException {
         try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook(testFileComplex)) {
             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[] explicitFHexes = {"FFFFFFFF", "FF000000", "FFC0C0C0", "FF002060",