1*eba4d44aSLiu Zhe /************************************************************** 2*eba4d44aSLiu Zhe * 3*eba4d44aSLiu Zhe * Licensed to the Apache Software Foundation (ASF) under one 4*eba4d44aSLiu Zhe * or more contributor license agreements. See the NOTICE file 5*eba4d44aSLiu Zhe * distributed with this work for additional information 6*eba4d44aSLiu Zhe * regarding copyright ownership. The ASF licenses this file 7*eba4d44aSLiu Zhe * to you under the Apache License, Version 2.0 (the 8*eba4d44aSLiu Zhe * "License"); you may not use this file except in compliance 9*eba4d44aSLiu Zhe * with the License. You may obtain a copy of the License at 10*eba4d44aSLiu Zhe * 11*eba4d44aSLiu Zhe * http://www.apache.org/licenses/LICENSE-2.0 12*eba4d44aSLiu Zhe * 13*eba4d44aSLiu Zhe * Unless required by applicable law or agreed to in writing, 14*eba4d44aSLiu Zhe * software distributed under the License is distributed on an 15*eba4d44aSLiu Zhe * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*eba4d44aSLiu Zhe * KIND, either express or implied. See the License for the 17*eba4d44aSLiu Zhe * specific language governing permissions and limitations 18*eba4d44aSLiu Zhe * under the License. 19*eba4d44aSLiu Zhe * 20*eba4d44aSLiu Zhe *************************************************************/ 21*eba4d44aSLiu Zhe 22*eba4d44aSLiu Zhe 23*eba4d44aSLiu Zhe package fvt.uno.sc.cell; 24*eba4d44aSLiu Zhe 25*eba4d44aSLiu Zhe import static org.junit.Assert.assertEquals; 26*eba4d44aSLiu Zhe 27*eba4d44aSLiu Zhe import java.util.Arrays; 28*eba4d44aSLiu Zhe import java.util.Collection; 29*eba4d44aSLiu Zhe 30*eba4d44aSLiu Zhe import org.junit.After; 31*eba4d44aSLiu Zhe import org.junit.AfterClass; 32*eba4d44aSLiu Zhe import org.junit.Before; 33*eba4d44aSLiu Zhe import org.junit.BeforeClass; 34*eba4d44aSLiu Zhe import org.junit.Test; 35*eba4d44aSLiu Zhe import org.junit.runner.RunWith; 36*eba4d44aSLiu Zhe import org.junit.runners.Parameterized; 37*eba4d44aSLiu Zhe import org.junit.runners.Parameterized.Parameters; 38*eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp; 39*eba4d44aSLiu Zhe 40*eba4d44aSLiu Zhe 41*eba4d44aSLiu Zhe import testlib.uno.SCUtil; 42*eba4d44aSLiu Zhe import testlib.uno.TestUtil; 43*eba4d44aSLiu Zhe import testlib.uno.CellInfo; 44*eba4d44aSLiu Zhe 45*eba4d44aSLiu Zhe import com.sun.star.lang.XComponent; 46*eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheet; 47*eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheetDocument; 48*eba4d44aSLiu Zhe import com.sun.star.table.CellHoriJustify; 49*eba4d44aSLiu Zhe import com.sun.star.table.CellVertJustify; 50*eba4d44aSLiu Zhe import com.sun.star.table.XCell; 51*eba4d44aSLiu Zhe import com.sun.star.uno.Enum; 52*eba4d44aSLiu Zhe 53*eba4d44aSLiu Zhe /** 54*eba4d44aSLiu Zhe * Check the cell alignment setting can be applied and saved 55*eba4d44aSLiu Zhe * 56*eba4d44aSLiu Zhe */ 57*eba4d44aSLiu Zhe @RunWith(value = Parameterized.class) 58*eba4d44aSLiu Zhe public class CellAlignment { 59*eba4d44aSLiu Zhe 60*eba4d44aSLiu Zhe private Enum expected; 61*eba4d44aSLiu Zhe private String inputType; 62*eba4d44aSLiu Zhe private Enum inputValue; 63*eba4d44aSLiu Zhe private String fileType; 64*eba4d44aSLiu Zhe 65*eba4d44aSLiu Zhe private static final UnoApp unoApp = new UnoApp(); 66*eba4d44aSLiu Zhe 67*eba4d44aSLiu Zhe XComponent scComponent = null; 68*eba4d44aSLiu Zhe XSpreadsheetDocument scDocument = null; 69*eba4d44aSLiu Zhe 70*eba4d44aSLiu Zhe @Parameters data()71*eba4d44aSLiu Zhe public static Collection<Object[]> data() { 72*eba4d44aSLiu Zhe return Arrays.asList(new Object[][] { 73*eba4d44aSLiu Zhe {CellHoriJustify.STANDARD, "HoriJustify", CellHoriJustify.STANDARD, "ods"}, 74*eba4d44aSLiu Zhe {CellHoriJustify.LEFT, "HoriJustify", CellHoriJustify.LEFT, "ods"}, 75*eba4d44aSLiu Zhe {CellHoriJustify.CENTER, "HoriJustify", CellHoriJustify.CENTER, "ods"}, 76*eba4d44aSLiu Zhe {CellHoriJustify.RIGHT, "HoriJustify", CellHoriJustify.RIGHT, "ods"}, 77*eba4d44aSLiu Zhe {CellHoriJustify.BLOCK, "HoriJustify", CellHoriJustify.BLOCK, "ods"}, 78*eba4d44aSLiu Zhe {CellHoriJustify.REPEAT, "HoriJustify", CellHoriJustify.REPEAT, "ods"}, 79*eba4d44aSLiu Zhe {CellVertJustify.STANDARD, "VertJustify", CellVertJustify.STANDARD, "ods"}, 80*eba4d44aSLiu Zhe {CellVertJustify.TOP, "VertJustify", CellVertJustify.TOP, "ods"}, 81*eba4d44aSLiu Zhe {CellVertJustify.CENTER, "VertJustify", CellVertJustify.CENTER, "ods"}, 82*eba4d44aSLiu Zhe {CellVertJustify.BOTTOM, "VertJustify", CellVertJustify.BOTTOM, "ods"}, 83*eba4d44aSLiu Zhe 84*eba4d44aSLiu Zhe {CellHoriJustify.STANDARD, "HoriJustify", CellHoriJustify.STANDARD, "xls"}, 85*eba4d44aSLiu Zhe {CellHoriJustify.LEFT, "HoriJustify", CellHoriJustify.LEFT, "xls"}, 86*eba4d44aSLiu Zhe {CellHoriJustify.CENTER, "HoriJustify", CellHoriJustify.CENTER, "xls"}, 87*eba4d44aSLiu Zhe {CellHoriJustify.RIGHT, "HoriJustify", CellHoriJustify.RIGHT, "xls"}, 88*eba4d44aSLiu Zhe {CellHoriJustify.BLOCK, "HoriJustify", CellHoriJustify.BLOCK, "xls"}, 89*eba4d44aSLiu Zhe {CellHoriJustify.REPEAT, "HoriJustify", CellHoriJustify.REPEAT, "xls"}, 90*eba4d44aSLiu Zhe {CellVertJustify.STANDARD, "VertJustify", CellVertJustify.STANDARD, "xls"}, 91*eba4d44aSLiu Zhe {CellVertJustify.TOP, "VertJustify", CellVertJustify.TOP, "xls"}, 92*eba4d44aSLiu Zhe {CellVertJustify.CENTER, "VertJustify", CellVertJustify.CENTER, "xls"}//, 93*eba4d44aSLiu Zhe // {CellVertJustify.BOTTOM, "VertJustify", CellVertJustify.BOTTOM, "xls"} Bug 120670 94*eba4d44aSLiu Zhe }); 95*eba4d44aSLiu Zhe } 96*eba4d44aSLiu Zhe CellAlignment(Enum expected, String inputType, Enum inputValue, String fileType)97*eba4d44aSLiu Zhe public CellAlignment(Enum expected, String inputType, Enum inputValue, String fileType) { 98*eba4d44aSLiu Zhe this.expected = expected; 99*eba4d44aSLiu Zhe this.inputType = inputType; 100*eba4d44aSLiu Zhe this.inputValue = inputValue; 101*eba4d44aSLiu Zhe this.fileType = fileType; 102*eba4d44aSLiu Zhe } 103*eba4d44aSLiu Zhe 104*eba4d44aSLiu Zhe @Before setUp()105*eba4d44aSLiu Zhe public void setUp() throws Exception { 106*eba4d44aSLiu Zhe scComponent = unoApp.newDocument("scalc"); 107*eba4d44aSLiu Zhe scDocument = SCUtil.getSCDocument(scComponent); 108*eba4d44aSLiu Zhe } 109*eba4d44aSLiu Zhe 110*eba4d44aSLiu Zhe @After tearDown()111*eba4d44aSLiu Zhe public void tearDown() throws Exception { 112*eba4d44aSLiu Zhe unoApp.closeDocument(scComponent); 113*eba4d44aSLiu Zhe 114*eba4d44aSLiu Zhe } 115*eba4d44aSLiu Zhe 116*eba4d44aSLiu Zhe @BeforeClass setUpConnection()117*eba4d44aSLiu Zhe public static void setUpConnection() throws Exception { 118*eba4d44aSLiu Zhe unoApp.start(); 119*eba4d44aSLiu Zhe } 120*eba4d44aSLiu Zhe 121*eba4d44aSLiu Zhe @AfterClass tearDownConnection()122*eba4d44aSLiu Zhe public static void tearDownConnection() throws InterruptedException, Exception { 123*eba4d44aSLiu Zhe unoApp.close(); 124*eba4d44aSLiu Zhe SCUtil.clearTempDir(); 125*eba4d44aSLiu Zhe } 126*eba4d44aSLiu Zhe 127*eba4d44aSLiu Zhe /** 128*eba4d44aSLiu Zhe * Check the cell alignment setting can be applied and saved 129*eba4d44aSLiu Zhe * 1. Create a spreadsheet file. 130*eba4d44aSLiu Zhe * 2. Input number, text, formula into many cell. 131*eba4d44aSLiu Zhe * 3. Set cell alignment. 132*eba4d44aSLiu Zhe * 4. Save file as ODF/MSBinary format. 133*eba4d44aSLiu Zhe * 5. Close and reopen file. -> Check the alignment setting. 134*eba4d44aSLiu Zhe * @throws Exception 135*eba4d44aSLiu Zhe */ 136*eba4d44aSLiu Zhe @Test testCellAlignment()137*eba4d44aSLiu Zhe public void testCellAlignment() throws Exception { 138*eba4d44aSLiu Zhe String fileName = "testCellAlignment"; 139*eba4d44aSLiu Zhe CellInfo cInfo = TestUtil.randCell(20, 50); 140*eba4d44aSLiu Zhe 141*eba4d44aSLiu Zhe int cellNum = 5; 142*eba4d44aSLiu Zhe XCell[] cells = new XCell[cellNum]; 143*eba4d44aSLiu Zhe Enum[] results = new Enum[cellNum]; 144*eba4d44aSLiu Zhe 145*eba4d44aSLiu Zhe XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument); 146*eba4d44aSLiu Zhe 147*eba4d44aSLiu Zhe //cellNum must be greater than 4 148*eba4d44aSLiu Zhe if (cellNum < 5) { 149*eba4d44aSLiu Zhe cellNum = 5; 150*eba4d44aSLiu Zhe } 151*eba4d44aSLiu Zhe for (int i = 0; i < cellNum; i++) { 152*eba4d44aSLiu Zhe cells[i] = sheet.getCellByPosition(cInfo.getCol(), cInfo.getRow() + i); 153*eba4d44aSLiu Zhe } 154*eba4d44aSLiu Zhe 155*eba4d44aSLiu Zhe cells[0].setValue(13.42); 156*eba4d44aSLiu Zhe SCUtil. setTextToCell(cells[1], "alignment"); 157*eba4d44aSLiu Zhe cells[2].setFormula("=SUM(A100:B100)"); 158*eba4d44aSLiu Zhe cells[3].setValue(-0.2343123); 159*eba4d44aSLiu Zhe 160*eba4d44aSLiu Zhe for (int i = 0; i < cellNum; i++) { 161*eba4d44aSLiu Zhe SCUtil.setCellProperties(cells[i], inputType, inputValue); 162*eba4d44aSLiu Zhe } 163*eba4d44aSLiu Zhe 164*eba4d44aSLiu Zhe SCUtil.saveFileAs(scComponent, fileName, fileType); 165*eba4d44aSLiu Zhe 166*eba4d44aSLiu Zhe scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName+"." + fileType); 167*eba4d44aSLiu Zhe sheet = SCUtil.getCurrentSheet(scDocument); 168*eba4d44aSLiu Zhe for (int i = 0; i < cellNum; i++) { 169*eba4d44aSLiu Zhe cells[i] = sheet.getCellByPosition(cInfo.getCol(), cInfo.getRow() + i); 170*eba4d44aSLiu Zhe results[i] = (Enum) SCUtil.getCellProperties(cells[i], inputType); 171*eba4d44aSLiu Zhe } 172*eba4d44aSLiu Zhe SCUtil.closeFile(scDocument); 173*eba4d44aSLiu Zhe 174*eba4d44aSLiu Zhe for (int i = 0; i < cellNum; i++ ) { 175*eba4d44aSLiu Zhe 176*eba4d44aSLiu Zhe assertEquals("Incorrect cell alignment(" + inputType + ") value got in ." + fileType + " file.", expected, results[i]); 177*eba4d44aSLiu Zhe 178*eba4d44aSLiu Zhe } 179*eba4d44aSLiu Zhe 180*eba4d44aSLiu Zhe } 181*eba4d44aSLiu Zhe 182*eba4d44aSLiu Zhe } 183