\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