incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From liu...@apache.org
Subject svn commit: r1383828 - in /incubator/ooo/trunk/test/testuno/source: testcase/uno/sc/cell/CellProtected.java testcase/uno/sc/chart/ testcase/uno/sc/chart/ChartLegend.java testcase/uno/sc/chart/ChartType.java testlib/uno/SCUtil.java
Date Wed, 12 Sep 2012 08:00:32 GMT
Author: liuzhe
Date: Wed Sep 12 08:00:32 2012
New Revision: 1383828

URL: http://svn.apache.org/viewvc?rev=1383828&view=rev
Log:
#120844 - [testUNO]Utility methods added for spreadsheet chart, test cases for cell and chart.
Patch By: Zhu Shan <shanzhu33@gmail.com>
Review By: Liu Zhe <aliuzhe@gmail.com>

Added:
    incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/cell/CellProtected.java
    incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/chart/
    incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/chart/ChartLegend.java
    incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/chart/ChartType.java
Modified:
    incubator/ooo/trunk/test/testuno/source/testlib/uno/SCUtil.java

Added: incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/cell/CellProtected.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/cell/CellProtected.java?rev=1383828&view=auto
==============================================================================
--- incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/cell/CellProtected.java (added)
+++ incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/cell/CellProtected.java Wed Sep
12 08:00:32 2012
@@ -0,0 +1,178 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+
+package testcase.uno.sc.cell;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.openoffice.test.uno.UnoApp;
+
+import testlib.uno.SCUtil;
+import testlib.uno.TestUtil;
+import testlib.uno.CellInfo;
+
+import com.sun.star.lang.XComponent;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.table.XCell;
+import com.sun.star.util.CellProtection;
+
+
+/**
+ *  Check the cell protection setting can be applied and saved
+ * 
+ */
+@RunWith(value = Parameterized.class)
+public class CellProtected {
+
+	private Boolean[] expected;
+	private String inputType;
+	private CellProtection inputProtectProps;
+	private String fileType;
+	
+	private static final UnoApp unoApp = new UnoApp();
+	
+	XComponent scComponent = null;
+	XSpreadsheetDocument scDocument = null;
+	
+	@Parameters
+	public static Collection<Object[]> data() throws Exception {
+		Boolean[][] list = {
+				{true, false, false, false}, //lock cell
+				{false, true, false, false}, //hide formula
+				{false, false, true, false}, //hide cell
+				{false, false, false, true}, //hide cell from print
+				
+				{true, true, true, false}		
+		};
+
+		return Arrays.asList(new Object[][] {
+			{list[0], "CellProtection", list[0], "ods"}, 
+			{list[1], "CellProtection", list[1], "ods"},
+			{list[4], "CellProtection", list[2], "ods"},
+			{list[3], "CellProtection", list[3], "ods"}
+		});
+	}
+	
+	public CellProtected(Boolean[] expected, String inputType, Boolean[] inputData, String fileType)
{
+		
+		CellProtection protection = new CellProtection();
+		
+		protection.IsLocked = inputData[0];
+		protection.IsFormulaHidden = inputData[1];
+		protection.IsHidden = inputData[2];
+		protection.IsPrintHidden = inputData[3];
+		
+		this.expected = expected;
+		this.inputType = inputType;
+		this.inputProtectProps = protection;
+		this.fileType = fileType;
+	}
+	
+	
+	@Before
+	public void setUp() throws Exception {
+		scComponent = unoApp.newDocument("scalc");
+		scDocument = SCUtil.getSCDocument(scComponent);
+	}
+
+	@After
+	public void tearDown() throws Exception {
+		unoApp.closeDocument(scComponent);
+		
+	}
+	
+	@BeforeClass
+	public static void setUpConnection() throws Exception {
+		unoApp.start();
+	}
+
+	@AfterClass
+	public static void tearDownConnection() throws InterruptedException, Exception {
+		unoApp.close();
+		SCUtil.clearTempDir();	
+	}
+	
+	/**
+	 * Check the cell protection settings
+	 * 1. Create a spreadsheet file.
+	 * 2. Input number, text, formula into many cell.
+	 * 3. Set cell protection properties. (Clock, HiddenFormula, Hidden Cell, Hidden Cell from
Printing)
+	 * 4. Save file as ODF/MSBinary format.
+	 * 5. Close and reopen file.  -> Check the cell protection setting.
+	 * @throws Exception
+	 */
+	@Test
+	public void testCellProtected() throws Exception {
+		String fileName = "testCellProtected";
+		
+		int cellNum = 5;
+		XCell[] cells = new XCell[cellNum];
+		CellProtection[] results = new CellProtection[cellNum];
+		CellInfo cInfo = TestUtil.randCell(10, 10);
+		
+		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
+		
+		for (int i = 0; i < cellNum; i++) {
+			cells[i] = sheet.getCellByPosition(cInfo.getCol() + i, cInfo.getRow());
+		}
+		
+		cells[0].setValue(2134359.343223);
+		SCUtil. setTextToCell(cells[1], inputType);
+		cells[2].setFormula("=Average(A1:A10)");
+		cells[3].setValue(-0.0003424);
+
+		for (int i = 0; i < cellNum; i++) {
+			SCUtil.setCellProperties(cells[i], inputType, inputProtectProps);
+		}
+		
+		SCUtil.saveFileAs(scComponent, fileName, fileType);
+		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
+		sheet = SCUtil.getCurrentSheet(scDocument);
+		
+		for (int i = 0; i < cellNum; i++) {
+			cells[i] = sheet.getCellByPosition(cInfo.getCol() + i, cInfo.getRow());
+			results[i] = (CellProtection) SCUtil.getCellProperties(cells[i], inputType);
+		}
+		
+		SCUtil.closeFile(scDocument);
+		
+		for (int i = 0; i < cellNum; i++) {
+			assertEquals("Incorrect cell protection (IsLocked) value got in ." + fileType + " file.",
expected[0], results[i].IsLocked);
+			assertEquals("Incorrect cell protection(IsFormulaHidden) value got in ." + fileType +
" file.", expected[1], results[i].IsFormulaHidden);
+			assertEquals("Incorrect cell protection(IsHidden) value got in ." + fileType + " file.",
expected[2], results[i].IsHidden);
+			assertEquals("Incorrect cell protection(IsPrintHidden) value got in ." + fileType + "
file.", expected[3], results[i].IsPrintHidden);
+		}	
+	}	
+
+}

Added: incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/chart/ChartLegend.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/chart/ChartLegend.java?rev=1383828&view=auto
==============================================================================
--- incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/chart/ChartLegend.java (added)
+++ incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/chart/ChartLegend.java Wed Sep
12 08:00:32 2012
@@ -0,0 +1,235 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+package testcase.uno.sc.chart;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.openoffice.test.uno.UnoApp;
+
+import testlib.uno.SCUtil;
+
+import com.sun.star.awt.Point;
+import com.sun.star.awt.Rectangle;
+import com.sun.star.chart.XChartDocument;
+import com.sun.star.drawing.XShape;
+import com.sun.star.lang.XComponent;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.table.CellRangeAddress;
+
+/**
+ *  Check the chart legend and the position can be applied and saved
+ * 
+ */
+@RunWith(value = Parameterized.class)
+public class ChartLegend {
+
+	private String inputType;
+	private double[][] numberData;
+	private int[] offset;
+	private String fileType;
+	
+	private static final UnoApp unoApp = new UnoApp();
+	
+	XComponent scComponent = null;
+	XSpreadsheetDocument scDocument = null;
+	
+	@Parameters
+	public static Collection<Object[]> data() throws Exception {
+		int[][] offsetList = {
+				{-50, -2000},
+				{-1000, 3000},
+				{-4000, -1000}
+		};
+		
+		double[][] numberData1 = {
+				{1, 2, 3, 4},
+				{2, 4.3, 5, 8},
+				{4, 2, 3, 1},
+				{1, -1, 0, 3}
+		};
+		return Arrays.asList(new Object[][] {
+			{"com.sun.star.chart.BarDiagram", numberData1, offsetList[0], "ods"},
+			{"com.sun.star.chart.BubbleDiagram", numberData1, offsetList[1], "ods"},
+			{"com.sun.star.chart.NetDiagram", numberData1, offsetList[2], "ods"},
+			{"com.sun.star.chart.BarDiagram", numberData1, offsetList[0], "xls"},
+			{"com.sun.star.chart.BubbleDiagram", numberData1, offsetList[1], "xls"},
+			{"com.sun.star.chart.NetDiagram", numberData1, offsetList[2], "xls"}
+		});
+	}
+	
+	public ChartLegend(String inputType, double[][] numberData, int[] offset, String fileType)
{
+		this.inputType = inputType;
+		this.numberData = numberData;
+		this.offset = offset;
+		this.fileType = fileType;
+	}
+	
+	
+	@Before
+	public void setUp() throws Exception {
+		scComponent = unoApp.newDocument("scalc");
+		scDocument = SCUtil.getSCDocument(scComponent);
+	}
+
+	@After
+	public void tearDown() throws Exception {
+		unoApp.closeDocument(scComponent);
+		
+	}
+	
+	@BeforeClass
+	public static void setUpConnection() throws Exception {
+		unoApp.start();
+	}
+
+	@AfterClass
+	public static void tearDownConnection() throws InterruptedException, Exception {
+		unoApp.close();
+		SCUtil.clearTempDir();	
+	}
+	
+	/**
+	 * Check remove the legend of chart
+	 * 1. Create a spreadsheet file.
+	 * 2. Input number in a cell range.
+	 * 3. Use the data to create a chart, set the chart type.
+	 * 4. Remove the legend.
+	 * 5. Save file as ODF/MSBinary format.
+	 * 6. Close and reopen file.  -> Check the legend status.
+	 * @throws Exception
+	 */
+	@Test
+	public void testDisableLegend() throws Exception {
+		String fileName = "testDisableLegend";
+		String chartName = "testChart";
+		String cellRangeName = "A1:D4";
+		Boolean result = true;		
+
+		if (fileType.equalsIgnoreCase("xls")) {
+			chartName = "Object 1";			
+		}
+		
+		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
+		
+		SCUtil.setValueToCellRange(sheet, 0, 0, numberData);
+		CellRangeAddress[] cellAddress = new CellRangeAddress[1];
+		cellAddress[0] = SCUtil.getChartDataRangeByName(sheet, cellRangeName);
+		Rectangle rectangle = new Rectangle(1000, 1000, 15000, 9500);
+		XChartDocument xChartDocument = null; 		
+		xChartDocument = SCUtil.createChart(sheet, rectangle, cellAddress, chartName);
+
+		SCUtil.setChartType(xChartDocument, inputType);
+		result = (Boolean) SCUtil.getProperties(xChartDocument, "HasLegend");
+		if (result) {
+			SCUtil.setProperties(xChartDocument, "HasLegend", false);
+		}
+		
+		SCUtil.saveFileAs(scComponent, fileName, fileType);
+		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
+		sheet = SCUtil.getCurrentSheet(scDocument);
+		
+		xChartDocument = SCUtil.getChartByName(sheet, chartName);
+		result = (Boolean) SCUtil.getProperties(xChartDocument, "HasLegend");
+
+		SCUtil.closeFile(scDocument);
+		
+		assertFalse("Chart legend has not been disabled in " + fileType + " file.", result);
+
+	}
+	
+	/**
+	 * Check change the position of legend in chart
+	 * 1. Create a spreadsheet file.
+	 * 2. Input number in a cell range.
+	 * 3. Use the data to create a chart, set the chart type.
+	 * 4. Change the position of legend in chart.
+	 * 5. Save file as ODF/MSBinary format.
+	 * 6. Close and reopen file.  -> Check the legend position.
+	 * @throws Exception
+	 */
+	@Test
+	public void testLegendPosition() throws Exception {
+		String fileName = "testDisableLegend";
+		String chartName = "testChart";
+		String cellRangeName = "A1:D4";
+		Boolean result = true;
+		int delta = 4;//Save as .xls file, the legend position may change a little, set acceptable
range.
+
+		if (fileType.equalsIgnoreCase("xls")) {
+			chartName = "Object 1";			
+		}
+		
+		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
+		
+		SCUtil.setValueToCellRange(sheet, 0, 0, numberData);
+		CellRangeAddress[] cellAddress = new CellRangeAddress[1];
+		cellAddress[0] = SCUtil.getChartDataRangeByName(sheet, cellRangeName);
+		Rectangle rectangle = new Rectangle(1000, 1000, 15000, 9500);
+		XChartDocument xChartDocument = null; 		
+		xChartDocument = SCUtil.createChart(sheet, rectangle, cellAddress, chartName);
+
+		SCUtil.setChartType(xChartDocument, inputType);
+		
+		XShape legend = xChartDocument.getLegend();
+		Point aPoint = legend.getPosition();
+		aPoint = new Point(aPoint.X + offset[0], aPoint.Y + offset[1]);
+		legend.setPosition(aPoint);
+		
+		SCUtil.saveFileAs(scComponent, fileName, fileType);
+		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
+		sheet = SCUtil.getCurrentSheet(scDocument);
+		
+		xChartDocument = SCUtil.getChartByName(sheet, chartName);
+		result = (Boolean) SCUtil.getProperties(xChartDocument, "HasLegend");
+		legend = xChartDocument.getLegend();
+		Point resultPoint = legend.getPosition();
+
+		SCUtil.closeFile(scDocument);
+		
+		assertTrue("Chart legend has not been enabled in ." + fileType + " file.", result);
+		
+		if (fileType.equalsIgnoreCase("xls")) {
+			assertEquals("Incorrect chart legend position X got in ." + fileType + " file.", aPoint.X,
resultPoint.X, delta);
+			assertEquals("Incorrect chart legend position X got in ." + fileType + " file.", aPoint.Y,
resultPoint.Y, delta);
+		}
+		else {
+			assertEquals("Incorrect chart legend position X got in ." + fileType + " file.", aPoint.X,
resultPoint.X);
+			assertEquals("Incorrect chart legend position X got in ." + fileType + " file.", aPoint.Y,
resultPoint.Y);
+		}
+		
+	}
+
+}
\ No newline at end of file

Added: incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/chart/ChartType.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/chart/ChartType.java?rev=1383828&view=auto
==============================================================================
--- incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/chart/ChartType.java (added)
+++ incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/chart/ChartType.java Wed Sep 12
08:00:32 2012
@@ -0,0 +1,180 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+package testcase.uno.sc.chart;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.openoffice.test.uno.UnoApp;
+
+import testlib.uno.SCUtil;
+import com.sun.star.awt.Rectangle;
+import com.sun.star.chart.XChartDocument;
+import com.sun.star.lang.XComponent;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.table.CellRangeAddress;
+
+/**
+ *  Check the chart type setting can be applied and saved
+ * 
+ */
+@RunWith(value = Parameterized.class)
+public class ChartType {
+
+	private String expected;
+	private String inputType;
+	private double[][] numberData;
+	private String fileType;
+	
+	private static final UnoApp unoApp = new UnoApp();
+	
+	XComponent scComponent = null;
+	XSpreadsheetDocument scDocument = null;
+	
+	@Parameters
+	public static Collection<Object[]> data() throws Exception {
+		double[][] numberData1 = {
+				{1, 2, 3, 4},
+				{2, 4.3, 5, 8},
+				{4, 2, 3, 1},
+				{1, -1, 0, 3}
+		};
+		double[][] numberData2 = {
+				{22, 12, 15},
+				{20, 11, 20},
+				{40, 37, 38},
+				{3.01, 2.2, 2.2}
+		};
+
+		return Arrays.asList(new Object[][] {
+			{"com.sun.star.chart.BarDiagram", "com.sun.star.chart.BarDiagram", numberData1, "ods"},
+			{"com.sun.star.chart.AreaDiagram", "com.sun.star.chart.AreaDiagram", numberData1, "ods"},
+			{"com.sun.star.chart.LineDiagram", "com.sun.star.chart.LineDiagram", numberData1, "ods"},
+			{"com.sun.star.chart.PieDiagram", "com.sun.star.chart.PieDiagram", numberData1, "ods"},
+			{"com.sun.star.chart.DonutDiagram", "com.sun.star.chart.DonutDiagram", numberData1, "ods"},
+			{"com.sun.star.chart.NetDiagram", "com.sun.star.chart.NetDiagram", numberData1, "ods"},
+			{"com.sun.star.chart.XYDiagram", "com.sun.star.chart.XYDiagram", numberData1, "ods"},
+			{"com.sun.star.chart.StockDiagram", "com.sun.star.chart.StockDiagram", numberData2, "ods"},
+			{"com.sun.star.chart.BubbleDiagram", "com.sun.star.chart.BubbleDiagram", numberData1,
"ods"},
+			
+			{"com.sun.star.chart.BarDiagram", "com.sun.star.chart.BarDiagram", numberData1, "xls"},
+			{"com.sun.star.chart.AreaDiagram", "com.sun.star.chart.AreaDiagram", numberData1, "xls"},
+			{"com.sun.star.chart.LineDiagram", "com.sun.star.chart.LineDiagram", numberData1, "xls"},
+			{"com.sun.star.chart.PieDiagram", "com.sun.star.chart.PieDiagram", numberData1, "xls"},
+			{"com.sun.star.chart.DonutDiagram", "com.sun.star.chart.DonutDiagram", numberData1, "xls"},
+			{"com.sun.star.chart.NetDiagram", "com.sun.star.chart.NetDiagram", numberData1, "xls"},
+			{"com.sun.star.chart.XYDiagram", "com.sun.star.chart.XYDiagram", numberData1, "xls"},
+			{"com.sun.star.chart.StockDiagram", "com.sun.star.chart.StockDiagram", numberData2, "xls"},
+			{"com.sun.star.chart.BubbleDiagram", "com.sun.star.chart.BubbleDiagram", numberData1,
"xls"}		
+		});
+	}
+	
+	public ChartType(String expected, String inputType, double[][] numberData, String fileType)
{
+		this.expected = expected;
+		this.inputType = inputType;
+		this.numberData = numberData;
+		this.fileType = fileType;
+	}
+	
+	
+	@Before
+	public void setUp() throws Exception {
+		scComponent = unoApp.newDocument("scalc");
+		scDocument = SCUtil.getSCDocument(scComponent);
+	}
+
+	@After
+	public void tearDown() throws Exception {
+		unoApp.closeDocument(scComponent);
+		
+	}
+	
+	@BeforeClass
+	public static void setUpConnection() throws Exception {
+		unoApp.start();
+	}
+
+	@AfterClass
+	public static void tearDownConnection() throws InterruptedException, Exception {
+		unoApp.close();
+		SCUtil.clearTempDir();	
+	}
+	
+	/**
+	 * Check the basic types of chart
+	 * 1. Create a spreadsheet file.
+	 * 2. Input number in a cell range.
+	 * 3. Use the data to create a chart, change the chart type.
+	 * 4. Save file as ODF/MSBinary format.
+	 * 5. Close and reopen file.  -> Check the chart type setting.
+	 * @throws Exception
+	 */
+	@Test
+	public void testCreateChart() throws Exception {
+		String fileName = "testCreateChart";
+		String chartName = "testChart";
+		String cellRangeName = "A1:D4";
+		String result = null;		
+		if (inputType.equals("com.sun.star.chart.StockDiagram")) {
+			cellRangeName = "A1:C4";
+		}	
+		if (fileType.equalsIgnoreCase("xls")) {
+			chartName = "Object 1";			
+		}
+		
+		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
+		
+		SCUtil.setValueToCellRange(sheet, 0, 0, numberData);
+
+		CellRangeAddress[] cellAddress = new CellRangeAddress[1];
+		cellAddress[0] = SCUtil.getChartDataRangeByName(sheet, cellRangeName);
+		Rectangle rectangle = new Rectangle(1000, 1000, 15000, 9500);
+		XChartDocument xChartDocument = null; 		
+		xChartDocument = SCUtil.createChart(sheet, rectangle, cellAddress, chartName);
+
+		SCUtil.setChartType(xChartDocument, inputType);
+		
+		SCUtil.saveFileAs(scComponent, fileName, fileType);
+		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
+		sheet = SCUtil.getCurrentSheet(scDocument);
+		
+		xChartDocument = SCUtil.getChartByName(sheet, chartName);
+		result = xChartDocument.getDiagram().getDiagramType();
+		
+		SCUtil.closeFile(scDocument);
+		
+		assertEquals("Incorrect chart type string got in ." + fileType + " file.", expected, result);
+
+	}
+
+}
\ No newline at end of file

Modified: incubator/ooo/trunk/test/testuno/source/testlib/uno/SCUtil.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testuno/source/testlib/uno/SCUtil.java?rev=1383828&r1=1383827&r2=1383828&view=diff
==============================================================================
--- incubator/ooo/trunk/test/testuno/source/testlib/uno/SCUtil.java (original)
+++ incubator/ooo/trunk/test/testuno/source/testlib/uno/SCUtil.java Wed Sep 12 08:00:32 2012
@@ -28,21 +28,32 @@ import org.openoffice.test.common.FileUt
 import org.openoffice.test.common.Testspace;
 import org.openoffice.test.uno.UnoApp;
 
+import com.sun.star.awt.Rectangle;
 import com.sun.star.beans.PropertyValue;
 import com.sun.star.beans.XPropertySet;
+import com.sun.star.chart.XChartDocument;
+import com.sun.star.chart.XDiagram;
 import com.sun.star.container.XIndexAccess;
+import com.sun.star.container.XNameAccess;
 import com.sun.star.container.XNamed;
+import com.sun.star.document.XEmbeddedObjectSupplier;
 import com.sun.star.frame.XController;
 import com.sun.star.frame.XModel;
 import com.sun.star.frame.XStorable;
 import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.sheet.XCellRangeAddressable;
 import com.sun.star.sheet.XSpreadsheet;
 import com.sun.star.sheet.XSpreadsheetDocument;
 import com.sun.star.sheet.XSpreadsheetView;
 import com.sun.star.sheet.XSpreadsheets;
+import com.sun.star.table.CellRangeAddress;
 import com.sun.star.table.XCell;
 import com.sun.star.table.XCellRange;
 import com.sun.star.table.XColumnRowRange;
+import com.sun.star.table.XTableChart;
+import com.sun.star.table.XTableCharts;
+import com.sun.star.table.XTableChartsSupplier;
 import com.sun.star.table.XTableColumns;
 import com.sun.star.table.XTableRows;
 import com.sun.star.text.XText;
@@ -288,6 +299,7 @@ public class SCUtil {
 	 * @param values
 	 * @throws Exception
 	 */
+	@Deprecated
 	public static void setValueToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row,
int end_col, int end_row,  double[][] values) throws Exception {
 		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col,
end_row);
 		XCell xCell = null;
@@ -299,6 +311,17 @@ public class SCUtil {
 		}
 	}
 	
+	public static void setValueToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row,
double[][] values) throws Exception {
+		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, start_col
+ values[0].length - 1, start_row + values.length - 1);
+		XCell xCell = null;
+		for (int i = 0; i < values.length; i++ ) {
+			for(int j = 0; j < values[0].length; j++) {
+				xCell = xCellRange.getCellByPosition(j, i);
+				xCell.setValue(values[i][j]);
+			}
+		}
+	}
+	
 	/**
 	 * Set text into a cell range
 	 * @param xSpreadsheet
@@ -309,6 +332,7 @@ public class SCUtil {
 	 * @param texts
 	 * @throws Exception
 	 */
+	@Deprecated  
 	public static void setTextToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row,
int end_col, int end_row,  String[][] texts) throws Exception {
 		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, end_col,
end_row);
 		XCell xCell = null;
@@ -322,6 +346,19 @@ public class SCUtil {
 		}
 	}
 	
+	public static void setTextToCellRange(XSpreadsheet xSpreadsheet, int start_col, int start_row,
String[][] texts) throws Exception {
+		XCellRange xCellRange = xSpreadsheet.getCellRangeByPosition(start_col, start_row, start_col
+ texts[0].length - 1, start_row + texts.length - 1);
+		XCell xCell = null;
+		XText xText = null;
+		for (int i = 0; i < texts.length; i++ ) {
+			for(int j = 0; j < texts[0].length; j++) {
+				xCell = xCellRange.getCellByPosition(j, i);
+				xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
+				xText.setString(texts[i][j]);
+			}
+		}
+	}
+	
 	/**
 	 * Get number content from a cell range
 	 * @param xSpreadsheet
@@ -423,6 +460,34 @@ public class SCUtil {
 	}
 	
 	/**
+	 * Set specific property's value for an object
+	 * @param obj
+	 * @param propName
+	 * @param value
+	 * @throws Exception
+	 */
+	public static void setProperties(Object obj, String propName, Object value) throws Exception
{
+		XPropertySet xPropertySet = 
+				(XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, obj);
+		xPropertySet.setPropertyValue(propName, value);
+	}
+	
+	/**
+	 * Get specific property's value of an object
+	 * @param obj
+	 * @param propName
+	 * @return
+	 * @throws Exception
+	 */
+	public static Object getProperties(Object obj, String propName) throws Exception {
+		XPropertySet xPropertySet = 
+				(XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, obj);
+		Object value = xPropertySet.getPropertyValue(propName);
+		
+		return value;
+	}	
+	
+	/**
 	 * Set value of specific property from a cell
 	 * @param xCell
 	 * @param propName
@@ -431,8 +496,7 @@ public class SCUtil {
 	 */
 	public static void setCellProperties(XCell xCell, String propName, Object value) throws
Exception {
 		
-		XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
xCell);
-		xPropertySet.setPropertyValue(propName, value);
+		setProperties(xCell, propName, value);
 	}
 
 	/**
@@ -443,10 +507,7 @@ public class SCUtil {
 	 * @throws Exception
 	 */
 	public static Object getCellProperties(XCell xCell, String propName) throws Exception {
-		XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
xCell);
-		Object value = xPropertySet.getPropertyValue(propName);
-		
-		return value;
+			return getProperties(xCell, propName);
 	}
 	
 	/**
@@ -483,18 +544,15 @@ public class SCUtil {
 	}
 	
 	/**
-	 * Save file after open file.
-	 * 
+	 * Save file after open file. 
 	 * @param xSpreadsheetDocument
 	 * @throws Exception
 	 */
 	public static void save(XSpreadsheetDocument xSpreadsheetDocument)
 			throws Exception {
-
 		XStorable scStorable = (XStorable) UnoRuntime.queryInterface(
 				XStorable.class, xSpreadsheetDocument);
 		scStorable.store();
-
 	}
 
 	
@@ -527,8 +585,8 @@ public class SCUtil {
 	
 	/**
 	 * open file in Spreadsheet.
-	 * @param unoApp
-	 * @param filtpath   File path with the extension name. (e.g. "testcase/uno/sc/data/sample.xls")
+	 * @param app  
+	 * @param filePath   File path with the extension name. (e.g. "testcase/uno/sc/data/sample.xls")
 	 * @return
 	 * @throws Exception
 	 */
@@ -551,5 +609,123 @@ public class SCUtil {
 		filterName.put("xlt", "MS Excel 97 Vorlage/Template");
 		filterName.put("csv", "Text - txt - csv (StarCalc)");
 	}
+	
+	
+	/***************************************************************
+	 *      Chart Utility method - using chart interface           *
+	****************************************************************/
+
+	/**
+	 * Get a CellRangeAddress by cell range reference name
+	 * @param xSpreadsheet
+	 * @param rangeName    a cell range reference name(e.g. "A1:B2")
+	 * @return
+	 */
+	public static CellRangeAddress getChartDataRangeByName(XSpreadsheet xSpreadsheet, String
rangeName) {
+		XCellRange cellRange = xSpreadsheet.getCellRangeByName(rangeName);
+		XCellRangeAddressable xCellRangeAddressable = 
+			(XCellRangeAddressable) UnoRuntime.queryInterface(XCellRangeAddressable.class, cellRange);
+	
+		CellRangeAddress cellRangeAddress = xCellRangeAddressable.getRangeAddress();
+		return cellRangeAddress;
+	}
+	
+	/**
+	 * Create a spreadsheet chart with data in a specific cell range.
+	 * @param xSpreadsheet
+	 * @param rec   a rectangle shape object
+	 * @param dataRangeAddress   the CellRangeAddress array of chart data source
+	 * @param chartName
+	 * @return
+	 * @throws Exception
+	 */
+	public static XChartDocument createChart(XSpreadsheet xSpreadsheet, Rectangle rec, CellRangeAddress[]
dataRangeAddress, String chartName) throws Exception {
+		XChartDocument xChartDocument = null;
+		XTableChartsSupplier xTChartSupplier = 
+				(XTableChartsSupplier) UnoRuntime.queryInterface(XTableChartsSupplier.class, xSpreadsheet);
+		XTableCharts xTableCharts = xTChartSupplier.getCharts();
+		XNameAccess xNameAccess = 
+				(XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xTableCharts);
+		if (xNameAccess != null && !xNameAccess.hasByName(chartName)) {
+			
+			xTableCharts.addNewByName(chartName, rec, dataRangeAddress, true, false);
+			XTableChart xTableChart = (XTableChart) UnoRuntime.queryInterface(
+					XTableChart.class, xNameAccess.getByName(chartName));
+			XEmbeddedObjectSupplier xEmbeddedObjectSupplier = (XEmbeddedObjectSupplier) UnoRuntime.queryInterface(
+					XEmbeddedObjectSupplier.class, xTableChart);
+			xChartDocument = (XChartDocument) UnoRuntime.queryInterface(
+					XChartDocument.class, xEmbeddedObjectSupplier.getEmbeddedObject());
+		}
+		
+		return xChartDocument;
+	}
+	
+	/**
+	 * Get XChartDocument object via the chart name.
+	 * @param xSpreadsheet
+	 * @param chartName
+	 * @return
+	 * @throws Exception
+	 */
+	public static XChartDocument getChartByName(XSpreadsheet xSpreadsheet, String chartName)
throws Exception {
+		XChartDocument xChartDocument = null;
+		XTableChartsSupplier xTChartSupplier = 
+				(XTableChartsSupplier) UnoRuntime.queryInterface(XTableChartsSupplier.class, xSpreadsheet);
+		XTableCharts xTableCharts = xTChartSupplier.getCharts();
+		XNameAccess xNameAccess = 
+				(XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xTableCharts);
+		
+		if (xNameAccess != null && xNameAccess.hasByName(chartName)) {
+			XTableChart xTableChart = (XTableChart) UnoRuntime.queryInterface(
+					XTableChart.class, xNameAccess.getByName(chartName));
+			XEmbeddedObjectSupplier xEmbeddedObjectSupplier = (XEmbeddedObjectSupplier) UnoRuntime.queryInterface(
+					XEmbeddedObjectSupplier.class, xTableChart);
+			xChartDocument = (XChartDocument) UnoRuntime.queryInterface(
+					XChartDocument.class, xEmbeddedObjectSupplier.getEmbeddedObject());
+		}
+		
+		return xChartDocument;
+	}
+	
+	/**
+	 * Set specific basic type to chart
+	 * @param xChartDocument
+	 * @param chartType
+	 * @throws Exception
+	 */
+	public static void setChartType(XChartDocument xChartDocument, String chartType) throws
Exception {
+		XMultiServiceFactory xMultiServiceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(
+			XMultiServiceFactory.class, xChartDocument);
+		XDiagram xDiagram = (XDiagram) UnoRuntime.queryInterface(
+			XDiagram.class, xMultiServiceFactory.createInstance(chartType));
+		xChartDocument.setDiagram(xDiagram);
+	}
+	
+	/**
+	 * Get the type string of a chart
+	 * @param xChartDocument
+	 * @return
+	 * @throws Exception
+	 */
+	public static String getChartType(XChartDocument xChartDocument) throws Exception {
+		return xChartDocument.getDiagram().getDiagramType();
+	}
+	
+	/**
+	 * Get the names of charts in specific sheet
+	 * @param xSpreadsheet
+	 * @return
+	 * @throws Exception
+	 */
+	public static String[] getChartNameList(XSpreadsheet xSpreadsheet) throws Exception {
+		XChartDocument xChartDocument = null;
+		XTableChartsSupplier xTChartSupplier = 
+				(XTableChartsSupplier) UnoRuntime.queryInterface(XTableChartsSupplier.class, xSpreadsheet);
+		XTableCharts xTableCharts = xTChartSupplier.getCharts();
+		String[] chartNames = xTableCharts.getElementNames();
+		return chartNames;
+	}
+	
+
 
 }



Mime
View raw message