Cleaned up test code
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@699991 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0c602f354f
commit
0d50343293
@ -1,11 +1,5 @@
|
|||||||
package org.apache.poi.xssf.usermodel;
|
package org.apache.poi.xssf.usermodel;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
@ -13,8 +7,8 @@ import org.apache.poi.ss.usermodel.CellStyle;
|
|||||||
import org.apache.poi.ss.usermodel.Font;
|
import org.apache.poi.ss.usermodel.Font;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||||
import org.apache.poi.xssf.usermodel.extensions.XSSFColor;
|
import org.apache.poi.xssf.usermodel.extensions.XSSFColor;
|
||||||
import org.openxml4j.opc.Package;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
|
||||||
@ -28,15 +22,13 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.STFontScheme;
|
|||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignRun;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignRun;
|
||||||
|
|
||||||
public class TestXSSFFont extends TestCase{
|
public final class TestXSSFFont extends TestCase{
|
||||||
|
|
||||||
public void testConstructor() {
|
public void testConstructor() {
|
||||||
XSSFFont xssfFont=new XSSFFont();
|
XSSFFont xssfFont=new XSSFFont();
|
||||||
assertNotNull(xssfFont);
|
|
||||||
assertNotNull(xssfFont.getCTFont());
|
assertNotNull(xssfFont.getCTFont());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testBoldweight() {
|
public void testBoldweight() {
|
||||||
CTFont ctFont=CTFont.Factory.newInstance();
|
CTFont ctFont=CTFont.Factory.newInstance();
|
||||||
CTBooleanProperty bool=ctFont.addNewB();
|
CTBooleanProperty bool=ctFont.addNewB();
|
||||||
@ -64,7 +56,6 @@ public class TestXSSFFont extends TestCase{
|
|||||||
assertEquals(FontCharset.DEFAULT.getValue(),ctFont.getCharsetArray(0).getVal());
|
assertEquals(FontCharset.DEFAULT.getValue(),ctFont.getCharsetArray(0).getVal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testFontName() {
|
public void testFontName() {
|
||||||
CTFont ctFont=CTFont.Factory.newInstance();
|
CTFont ctFont=CTFont.Factory.newInstance();
|
||||||
CTFontName fname=ctFont.addNewName();
|
CTFontName fname=ctFont.addNewName();
|
||||||
@ -78,7 +69,6 @@ public class TestXSSFFont extends TestCase{
|
|||||||
assertEquals("Courier",ctFont.getNameArray(0).getVal());
|
assertEquals("Courier",ctFont.getNameArray(0).getVal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testItalic() {
|
public void testItalic() {
|
||||||
CTFont ctFont=CTFont.Factory.newInstance();
|
CTFont ctFont=CTFont.Factory.newInstance();
|
||||||
CTBooleanProperty bool=ctFont.addNewI();
|
CTBooleanProperty bool=ctFont.addNewI();
|
||||||
@ -94,7 +84,6 @@ public class TestXSSFFont extends TestCase{
|
|||||||
assertEquals(true,ctFont.getIArray(0).getVal());
|
assertEquals(true,ctFont.getIArray(0).getVal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testStrikeout() {
|
public void testStrikeout() {
|
||||||
CTFont ctFont=CTFont.Factory.newInstance();
|
CTFont ctFont=CTFont.Factory.newInstance();
|
||||||
CTBooleanProperty bool=ctFont.addNewStrike();
|
CTBooleanProperty bool=ctFont.addNewStrike();
|
||||||
@ -110,7 +99,6 @@ public class TestXSSFFont extends TestCase{
|
|||||||
assertEquals(true,ctFont.getStrikeArray(0).getVal());
|
assertEquals(true,ctFont.getStrikeArray(0).getVal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testFontHeight() {
|
public void testFontHeight() {
|
||||||
CTFont ctFont=CTFont.Factory.newInstance();
|
CTFont ctFont=CTFont.Factory.newInstance();
|
||||||
CTFontSize size=ctFont.addNewSz();
|
CTFontSize size=ctFont.addNewSz();
|
||||||
@ -124,7 +112,6 @@ public class TestXSSFFont extends TestCase{
|
|||||||
assertEquals(new Double(20).doubleValue(),ctFont.getSzArray(0).getVal());
|
assertEquals(new Double(20).doubleValue(),ctFont.getSzArray(0).getVal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testFontHeightInPoint() {
|
public void testFontHeightInPoint() {
|
||||||
CTFont ctFont=CTFont.Factory.newInstance();
|
CTFont ctFont=CTFont.Factory.newInstance();
|
||||||
CTFontSize size=ctFont.addNewSz();
|
CTFontSize size=ctFont.addNewSz();
|
||||||
@ -138,7 +125,6 @@ public class TestXSSFFont extends TestCase{
|
|||||||
assertEquals(new Double(20).doubleValue(),ctFont.getSzArray(0).getVal());
|
assertEquals(new Double(20).doubleValue(),ctFont.getSzArray(0).getVal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testUnderline() {
|
public void testUnderline() {
|
||||||
CTFont ctFont=CTFont.Factory.newInstance();
|
CTFont ctFont=CTFont.Factory.newInstance();
|
||||||
CTUnderlineProperty underlinePropr=ctFont.addNewU();
|
CTUnderlineProperty underlinePropr=ctFont.addNewU();
|
||||||
@ -192,7 +178,7 @@ public class TestXSSFFont extends TestCase{
|
|||||||
public void testThemeColor() {
|
public void testThemeColor() {
|
||||||
CTFont ctFont=CTFont.Factory.newInstance();
|
CTFont ctFont=CTFont.Factory.newInstance();
|
||||||
CTColor color=ctFont.addNewColor();
|
CTColor color=ctFont.addNewColor();
|
||||||
color.setTheme((long)1);
|
color.setTheme(1);
|
||||||
ctFont.setColorArray(0,color);
|
ctFont.setColorArray(0,color);
|
||||||
|
|
||||||
XSSFFont xssfFont=new XSSFFont(ctFont);
|
XSSFFont xssfFont=new XSSFFont(ctFont);
|
||||||
@ -212,7 +198,6 @@ public class TestXSSFFont extends TestCase{
|
|||||||
assertEquals(FontFamily.MODERN.getValue(),xssfFont.getFamily());
|
assertEquals(FontFamily.MODERN.getValue(),xssfFont.getFamily());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testScheme() {
|
public void testScheme() {
|
||||||
CTFont ctFont=CTFont.Factory.newInstance();
|
CTFont ctFont=CTFont.Factory.newInstance();
|
||||||
CTFontScheme scheme=ctFont.addNewScheme();
|
CTFontScheme scheme=ctFont.addNewScheme();
|
||||||
@ -244,9 +229,9 @@ public class TestXSSFFont extends TestCase{
|
|||||||
* file, save, load, and still see them
|
* file, save, load, and still see them
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public void testCreateSave() throws Exception {
|
public void testCreateSave() {
|
||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
XSSFSheet s1 = (XSSFSheet)wb.createSheet();
|
XSSFSheet s1 = wb.createSheet();
|
||||||
Row r1 = s1.createRow(0);
|
Row r1 = s1.createRow(0);
|
||||||
Cell r1c1 = r1.createCell(0);
|
Cell r1c1 = r1.createCell(0);
|
||||||
r1c1.setCellValue(2.2);
|
r1c1.setCellValue(2.2);
|
||||||
@ -266,12 +251,8 @@ public class TestXSSFFont extends TestCase{
|
|||||||
r1c1.setCellStyle(cellStyleTitle);
|
r1c1.setCellStyle(cellStyleTitle);
|
||||||
|
|
||||||
// Save and re-load
|
// Save and re-load
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
|
||||||
wb.write(baos);
|
s1 = wb.getSheetAt(0);
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
|
||||||
|
|
||||||
wb = new XSSFWorkbook(Package.open(bais));
|
|
||||||
s1 = (XSSFSheet)wb.getSheetAt(0);
|
|
||||||
|
|
||||||
assertEquals(2, wb.getNumberOfFonts());
|
assertEquals(2, wb.getNumberOfFonts());
|
||||||
assertNotNull(s1.getRow(0).getCell(0).getCellStyle().getFont(wb));
|
assertNotNull(s1.getRow(0).getCell(0).getCellStyle().getFont(wb));
|
||||||
@ -286,12 +267,8 @@ public class TestXSSFFont extends TestCase{
|
|||||||
assertEquals(3, wb.getNumberOfFonts());
|
assertEquals(3, wb.getNumberOfFonts());
|
||||||
|
|
||||||
// Save and re-load
|
// Save and re-load
|
||||||
baos = new ByteArrayOutputStream();
|
wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
|
||||||
wb.write(baos);
|
s1 = wb.getSheetAt(0);
|
||||||
bais = new ByteArrayInputStream(baos.toByteArray());
|
|
||||||
|
|
||||||
wb = new XSSFWorkbook(Package.open(bais));
|
|
||||||
s1 = (XSSFSheet)wb.getSheetAt(0);
|
|
||||||
|
|
||||||
assertEquals(3, wb.getNumberOfFonts());
|
assertEquals(3, wb.getNumberOfFonts());
|
||||||
assertNotNull(wb.getFontAt((short)1));
|
assertNotNull(wb.getFontAt((short)1));
|
||||||
@ -301,8 +278,7 @@ public class TestXSSFFont extends TestCase{
|
|||||||
assertEquals(true, wb.getFontAt((short)2).getItalic());
|
assertEquals(true, wb.getFontAt((short)2).getItalic());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testXSSFFont() {
|
||||||
public void testXSSFFont() throws IOException{
|
|
||||||
XSSFWorkbook workbook=new XSSFWorkbook();
|
XSSFWorkbook workbook=new XSSFWorkbook();
|
||||||
//Font font1=workbook.createFont();
|
//Font font1=workbook.createFont();
|
||||||
|
|
||||||
@ -364,11 +340,6 @@ public class TestXSSFFont extends TestCase{
|
|||||||
cell1.setCellValue(new XSSFRichTextString("pink italic Times 9pt strikeout!!!"));
|
cell1.setCellValue(new XSSFRichTextString("pink italic Times 9pt strikeout!!!"));
|
||||||
cell1.setCellStyle(cellStyle3);
|
cell1.setCellStyle(cellStyle3);
|
||||||
|
|
||||||
File tmpFile = new File("test-ooxml-font.xlsx");
|
XSSFTestDataSamples.writeOutAndReadBack(workbook);
|
||||||
if(tmpFile.exists()) tmpFile.delete();
|
|
||||||
FileOutputStream out = new FileOutputStream(tmpFile);
|
|
||||||
workbook.write(out);
|
|
||||||
out.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user