]> source.dussan.org Git - poi.git/commitdiff
Begin Themes+Normal colour tests
authorNick Burch <nick@apache.org>
Sun, 9 Aug 2015 13:06:40 +0000 (13:06 +0000)
committerNick Burch <nick@apache.org>
Sun, 9 Aug 2015 13:06:40 +0000 (13:06 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1694887 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/testcases/org/apache/poi/xssf/model/TestThemesTable.java

index fde748815a28c2d69155590e39d1555923085419..d572aa623ee5933185e8b36708f4ce9c3067b396 100644 (file)
@@ -144,11 +144,68 @@ public class TestThemesTable {
 \r
     /**\r
      * Ensure that, for a file with themes, we can correctly\r
-     *  read both the themed and non-themed colours back\r
+     *  read both the themed and non-themed colours back.\r
+     * Column A = Theme Foreground\r
+     * Column B = Theme Foreground\r
+     * Column C = Explicit Colour Foreground\r
+     * Column E = Explicit Colour Background, Black Foreground\r
+     * Column G = Conditional Formatting Backgrounds\r
+     * (Row 4 = White by Lt2)\r
      */\r
     @Test\r
     public void themedAndNonThemedColours() {\r
-        // TODO Implement this using Theme2.xls{x}\r
+        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook(testFileComplex);\r
+        XSSFSheet sheet = wb.getSheetAt(0);\r
+        XSSFCellStyle style;\r
+        XSSFColor color;\r
+        \r
+        String[] names = {"Black","White","Grey","Blue","Red","Green"};\r
+        int[] themes = {1,0,2,3,4,5};\r
+        assertEquals(names.length, themes.length);\r
+        \r
+        // Check the non-CF colours in Columns A, B, C and E\r
+        for (int rn=2; rn<8; rn++) {\r
+            int idx = rn-2;\r
+            XSSFRow row = sheet.getRow(rn);\r
+            assertNotNull("Missing row " + rn, row);\r
+            \r
+            // Theme cells aren't quite in the same order...\r
+            XSSFCell themeCell = row.getCell(0);\r
+            if (idx == 1) themeCell = sheet.getRow(idx).getCell(0);\r
+            if (idx >= 2) themeCell = sheet.getRow(idx+1).getCell(0);\r
+\r
+            // Sanity check names\r
+            int themeIdx = themes[idx];\r
+            ThemeElement themeElem = ThemeElement.byId(themeIdx);\r
+            assertCellContents(themeElem.name, themeCell);\r
+            assertCellContents(names[idx], row.getCell(1));\r
+            assertCellContents(names[idx], row.getCell(2));\r
+            assertCellContents(names[idx], row.getCell(4));\r
+            \r
+            // Check the colours\r
+            //  A: Theme Based, Foreground\r
+            style = themeCell.getCellStyle();\r
+            color = style.getFont().getXSSFColor();\r
+            assertEquals(true, color.isThemed());\r
+            assertEquals(themeIdx, color.getTheme());\r
+            assertEquals(rgbExpected[themeIdx], Hex.encodeHexString(color.getRGB()));\r
+            //  B: Theme Based, Foreground\r
+            style = row.getCell(1).getCellStyle();\r
+            color = style.getFont().getXSSFColor();\r
+            // TODO Fix this!\r
+            if (idx < 2) {\r
+                assertEquals(true, color.isThemed());\r
+                assertEquals(themeIdx, color.getTheme());\r
+                assertEquals(rgbExpected[themeIdx], Hex.encodeHexString(color.getRGB()));\r
+            }\r
+        }\r
+        \r
+        // Check the CF colours\r
+        // TODO\r
+    }\r
+    private static void assertCellContents(String expected, XSSFCell cell) {\r
+        assertNotNull(cell);\r
+        assertEquals(expected.toLowerCase(), cell.getStringCellValue().toLowerCase());\r
     }\r
     \r
     @Test\r