You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by li...@apache.org on 2012/08/31 07:42:38 UTC

svn commit: r1379295 - in /incubator/ooo/trunk/test/testuno/source: testcase/uno/sd/chart/ testcase/uno/sd/chart/ChartTypes.java testlib/uno/ChartUtil.java

Author: liuzhe
Date: Fri Aug 31 05:42:37 2012
New Revision: 1379295

URL: http://svn.apache.org/viewvc?rev=1379295&view=rev
Log:
#120734 - [testuno]Test scripts about Chart Type in Presentation via UNO API
Patch By: Li Feng Wang <ph...@gmail.com>
Review By: Liu Zhe <al...@gmail.com>

Added:
    incubator/ooo/trunk/test/testuno/source/testcase/uno/sd/chart/
    incubator/ooo/trunk/test/testuno/source/testcase/uno/sd/chart/ChartTypes.java
    incubator/ooo/trunk/test/testuno/source/testlib/uno/ChartUtil.java

Added: incubator/ooo/trunk/test/testuno/source/testcase/uno/sd/chart/ChartTypes.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testuno/source/testcase/uno/sd/chart/ChartTypes.java?rev=1379295&view=auto
==============================================================================
--- incubator/ooo/trunk/test/testuno/source/testcase/uno/sd/chart/ChartTypes.java (added)
+++ incubator/ooo/trunk/test/testuno/source/testcase/uno/sd/chart/ChartTypes.java Fri Aug 31 05:42:37 2012
@@ -0,0 +1,291 @@
+/**************************************************************
+ * 
+ * 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.sd.chart;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.openoffice.test.common.FileUtil;
+import org.openoffice.test.common.Testspace;
+import org.openoffice.test.uno.UnoApp;
+
+import testlib.uno.ChartUtil;
+import testlib.uno.PageUtil;
+import testlib.uno.ShapeUtil;
+import testlib.uno.TestUtil;
+
+import com.sun.star.awt.Point;
+import com.sun.star.awt.Size;
+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.drawing.XDrawPage;
+import com.sun.star.drawing.XDrawPages;
+import com.sun.star.drawing.XDrawPagesSupplier;
+import com.sun.star.drawing.XShape;
+import com.sun.star.drawing.XShapes;
+import com.sun.star.frame.XStorable;
+import com.sun.star.lang.XComponent;
+import com.sun.star.presentation.XPresentation;
+import com.sun.star.presentation.XPresentationSupplier;
+import com.sun.star.uno.UnoRuntime;
+
+public class ChartTypes {
+	UnoApp unoApp = new UnoApp();
+	XPresentationSupplier sdDocument = null;
+	XPresentation pre = null;
+	XComponent precomp = null;
+	XComponent impressDocument = null;
+	XComponent reLoadFile = null;
+	XDrawPagesSupplier drawsupplier = null;
+	XDrawPages drawpages = null;
+	XShapes xShapes = null;
+	XDrawPage xpage = null;
+	String filePath = null;
+
+	@Before
+	public void setUp() throws Exception {
+		unoApp.start();
+		createDocumentAndSlide();
+	}
+
+	@After
+	public void tearDown() throws Exception {
+		unoApp.closeDocument(impressDocument);
+		unoApp.closeDocument(reLoadFile);
+		unoApp.close();
+		if (filePath != null)
+			FileUtil.deleteFile(filePath);
+	}
+
+	/**
+	 * Insert Area Chart
+	 * 
+	 * @throws Exception
+	 */
+	@Test
+	public void testInsertAreaChart() throws Exception {
+		XChartDocument xChartDoc = null;
+		XDiagram aDiagram = null;
+		Point po = new Point(1000, 1000);
+		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
+		XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
+				15000, 9271), "com.sun.star.drawing.OLE2Shape");
+		xShapes.add(xShape);
+		xChartDoc = ChartUtil.retrieveChartDocument(xShape);
+		aDiagram = ChartUtil.createChart(xChartDoc,
+				"com.sun.star.chart.AreaDiagram");
+		xChartDoc.setDiagram(aDiagram);
+		xShape = saveAndLoadShape(1, 0);
+		xChartDoc = ChartUtil.getChartDocument(xShape);
+		assertEquals("Not Area Chart", "com.sun.star.chart.AreaDiagram",
+				xChartDoc.getDiagram().getDiagramType());
+	}
+
+	/**
+	 * Insert Bubble Chart
+	 * 
+	 * @throws Exception
+	 */
+	@Test
+	public void testInsertBubbleChart() throws Exception {
+		XChartDocument xChartDoc = null;
+		XDiagram aDiagram = null;
+		Point po = new Point(1000, 1000);
+		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
+		XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
+				15000, 9271), "com.sun.star.drawing.OLE2Shape");
+		xShapes.add(xShape);
+		xChartDoc = ChartUtil.retrieveChartDocument(xShape);
+		aDiagram = ChartUtil.createChart(xChartDoc,
+				"com.sun.star.chart.BubbleDiagram");
+		xChartDoc.setDiagram(aDiagram);
+		xShape = saveAndLoadShape(1, 0);
+		xChartDoc = ChartUtil.getChartDocument(xShape);
+		assertEquals("Not Area Chart", "com.sun.star.chart.BubbleDiagram",
+				xChartDoc.getDiagram().getDiagramType());
+	}
+
+	/**
+	 * Insert Bar Chart (default chart type)
+	 * 
+	 * @throws Exception
+	 */
+	@Test
+	public void testInsertBarChart() throws Exception {
+		XChartDocument xChartDoc = null;
+		Point po = new Point(1000, 1000);
+		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
+		XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
+				15000, 9271), "com.sun.star.drawing.OLE2Shape");
+		xShapes.add(xShape);
+		ChartUtil.retrieveChartDocument(xShape);
+		xShape = saveAndLoadShape(1, 0);
+		xChartDoc = ChartUtil.getChartDocument(xShape);
+		assertEquals("Not Bar Chart", "com.sun.star.chart.BarDiagram",
+				xChartDoc.getDiagram().getDiagramType());
+
+	}
+
+	/**
+	 * test Insert Cone Chart(3D look of Bar chart)
+	 * 
+	 * @throws Exception
+	 */
+	@Test
+	public void testInsertConeChart() throws Exception {
+		XChartDocument xChartDoc = null;
+		XDiagram aDiagram = null;
+		Point po = new Point(1000, 1000);
+		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
+		XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
+				15000, 9271), "com.sun.star.drawing.OLE2Shape");
+		xShapes.add(xShape);
+		xChartDoc = ChartUtil.retrieveChartDocument(xShape);
+		aDiagram = ChartUtil.createChart(xChartDoc,
+				"com.sun.star.chart.BarDiagram");
+		XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface(
+				XPropertySet.class, aDiagram);
+		aDiaProp.setPropertyValue("Dim3D", true);
+		aDiaProp.setPropertyValue("Deep", true);
+		// from service Chart3DBarProperties:
+		aDiaProp.setPropertyValue("SolidType", new Integer(
+				com.sun.star.chart.ChartSolidType.CONE));
+		xChartDoc.setDiagram(aDiagram);
+		xShape = saveAndLoadShape(1, 0);
+		xChartDoc = ChartUtil.getChartDocument(xShape);
+		aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
+				xChartDoc.getDiagram());
+		assertEquals("Not Cone Chart", com.sun.star.chart.ChartSolidType.CONE,
+				aDiaProp.getPropertyValue("SolidType"));
+
+	}
+
+	/**
+	 * Insert Line Chart
+	 * 
+	 * @throws Exception
+	 */
+	@Test
+	public void testInsertLineChart() throws Exception {
+		XChartDocument xChartDoc = null;
+		XDiagram aDiagram = null;
+		Point po = new Point(1000, 1000);
+		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
+		XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
+				15000, 9271), "com.sun.star.drawing.OLE2Shape");
+		xShapes.add(xShape);
+		xChartDoc = ChartUtil.retrieveChartDocument(xShape);
+		aDiagram = ChartUtil.createChart(xChartDoc,
+				"com.sun.star.chart.LineDiagram");
+		xChartDoc.setDiagram(aDiagram);
+		xShape = saveAndLoadShape(1, 0);
+		xChartDoc = ChartUtil.getChartDocument(xShape);
+		assertEquals("Not Area Chart", "com.sun.star.chart.LineDiagram",
+				xChartDoc.getDiagram().getDiagramType());
+	}
+
+	/**
+	 * Insert Pie Chart
+	 * 
+	 * @throws Exception
+	 */
+	@Test
+	public void testInsertPieChart() throws Exception {
+		XChartDocument xChartDoc = null;
+		XDiagram aDiagram = null;
+		Point po = new Point(1000, 1000);
+		xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage);
+		XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size(
+				15000, 9271), "com.sun.star.drawing.OLE2Shape");
+		xShapes.add(xShape);
+		xChartDoc = ChartUtil.retrieveChartDocument(xShape);
+		aDiagram = ChartUtil.createChart(xChartDoc,
+				"com.sun.star.chart.PieDiagram");
+		xChartDoc.setDiagram(aDiagram);
+		xShape = saveAndLoadShape(1, 0);
+		xChartDoc = ChartUtil.getChartDocument(xShape);
+		assertEquals("Not Area Chart", "com.sun.star.chart.PieDiagram",
+				xChartDoc.getDiagram().getDiagramType());
+	}
+
+	/**
+	 * create a new presentation document and insert a new slide.
+	 * 
+	 * @throws Exception
+	 */
+	public void createDocumentAndSlide() throws Exception {
+		impressDocument = (XComponent) UnoRuntime.queryInterface(
+				XComponent.class, unoApp.newDocument("simpress"));
+		drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(
+				XDrawPagesSupplier.class, impressDocument);
+		drawpages = drawsupplier.getDrawPages();
+		drawpages.insertNewByIndex(1);
+		xpage = PageUtil.getDrawPageByIndex(impressDocument, 1);
+	}
+
+	/**
+	 * Save presentation and reLoad the presentation and shape in it.
+	 * 
+	 * @param po
+	 * @param shapeType
+	 * @return
+	 * @throws Exception
+	 */
+	public XShape saveAndLoadShape(int pageIndex, int shapeIndex)
+			throws Exception {
+		reLoadFile = saveAndReloadDoc(impressDocument,
+				"impress8", "odp");
+		xShapes = ShapeUtil.getShapes(reLoadFile, pageIndex);
+		return (XShape) UnoRuntime.queryInterface(XShape.class,
+				xShapes.getByIndex(shapeIndex));
+	}
+
+	/**
+	 * save and reload Presentation document.
+	 * 
+	 * @param presentationDocument
+	 * @param sFilter
+	 * @param sExtension
+	 * @return
+	 * @throws Exception
+	 */
+	private XComponent saveAndReloadDoc(XComponent presentationDocument,
+			String sFilter, String sExtension) throws Exception {
+		filePath = Testspace.getPath("tmp/presentationtest." + sExtension);
+		PropertyValue[] aStoreProperties = new PropertyValue[2];
+		aStoreProperties[0] = new PropertyValue();
+		aStoreProperties[1] = new PropertyValue();
+		aStoreProperties[0].Name = "Override";
+		aStoreProperties[0].Value = true;
+		aStoreProperties[1].Name = "FilterName";
+		aStoreProperties[1].Value = sFilter;
+		XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
+				XStorable.class, presentationDocument);
+		xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties);
+
+		return UnoRuntime.queryInterface(XComponent.class,
+				unoApp.loadDocument(filePath));
+	}
+}

Added: incubator/ooo/trunk/test/testuno/source/testlib/uno/ChartUtil.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testuno/source/testlib/uno/ChartUtil.java?rev=1379295&view=auto
==============================================================================
--- incubator/ooo/trunk/test/testuno/source/testlib/uno/ChartUtil.java (added)
+++ incubator/ooo/trunk/test/testuno/source/testlib/uno/ChartUtil.java Fri Aug 31 05:42:37 2012
@@ -0,0 +1,88 @@
+/**************************************************************
+ * 
+ * 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 testlib.uno;
+
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.chart.XChartDocument;
+import com.sun.star.chart.XDiagram;
+import com.sun.star.drawing.XShape;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.uno.UnoRuntime;
+
+public class ChartUtil {
+
+	/**
+	 * Retrieve Chart document as model of the OLE Shape(use to create chart)
+	 * @param xShape
+	 * @return
+	 * @throws Exception
+	 */
+	public static XChartDocument retrieveChartDocument(XShape xShape)throws Exception{
+		XChartDocument aChartDoc = null;
+		final String msChartClassID = "12dcae26-281f-416f-a234-c3086127382e";
+		// make the OLE shape a chart
+		XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface(
+				XPropertySet.class, xShape);
+		// set the class id for charts
+		aShapeProp.setPropertyValue("CLSID", msChartClassID);
+		// retrieve the chart document as model of the OLE shape
+		aChartDoc = (XChartDocument) UnoRuntime.queryInterface(
+				XChartDocument.class, aShapeProp.getPropertyValue("Model"));
+		return aChartDoc;
+	}
+	
+	/**
+	 * Create Chart in ChartDocument.
+	 * @param aChartDoc
+	 * @param ChartType
+	 * @return
+	 * @throws Exception
+	 */
+	public static XDiagram createChart(XChartDocument aChartDoc, String ChartType)
+			throws Exception {
+	
+		// let aChartDoc be a valid XChartDocument
+		// get the factory that can create diagrams
+		XMultiServiceFactory aFact = (XMultiServiceFactory) UnoRuntime
+				.queryInterface(XMultiServiceFactory.class, aChartDoc);
+		XDiagram aDiagram = (XDiagram) UnoRuntime.queryInterface(
+				XDiagram.class, aFact.createInstance(ChartType));
+		return aDiagram;
+	}
+	
+	
+	/**
+	 * Get Chart Doc from a Shape
+	 * @param xShape
+	 * @return
+	 * @throws Exception
+	 */
+	public static XChartDocument getChartDocument(XShape xShape)throws Exception{
+		XChartDocument aChartDoc = null;
+		XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface(
+				XPropertySet.class, xShape);
+		// retrieve the chart document as model of the OLE shape
+		aChartDoc = (XChartDocument) UnoRuntime.queryInterface(
+				XChartDocument.class, aShapeProp.getPropertyValue("Model"));
+		return aChartDoc;
+		
+	}
+}