104813259SLiu Zhe /************************************************************** 204813259SLiu Zhe * 304813259SLiu Zhe * Licensed to the Apache Software Foundation (ASF) under one 404813259SLiu Zhe * or more contributor license agreements. See the NOTICE file 504813259SLiu Zhe * distributed with this work for additional information 604813259SLiu Zhe * regarding copyright ownership. The ASF licenses this file 704813259SLiu Zhe * to you under the Apache License, Version 2.0 (the 804813259SLiu Zhe * "License"); you may not use this file except in compliance 904813259SLiu Zhe * with the License. You may obtain a copy of the License at 1004813259SLiu Zhe * 1104813259SLiu Zhe * http://www.apache.org/licenses/LICENSE-2.0 1204813259SLiu Zhe * 1304813259SLiu Zhe * Unless required by applicable law or agreed to in writing, 1404813259SLiu Zhe * software distributed under the License is distributed on an 1504813259SLiu Zhe * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1604813259SLiu Zhe * KIND, either express or implied. See the License for the 1704813259SLiu Zhe * specific language governing permissions and limitations 1804813259SLiu Zhe * under the License. 1904813259SLiu Zhe * 2004813259SLiu Zhe *************************************************************/ 21*eba4d44aSLiu Zhe package fvt.uno.sd.chart; 2204813259SLiu Zhe 2304813259SLiu Zhe import static org.junit.Assert.assertEquals; 2404813259SLiu Zhe 2504813259SLiu Zhe import org.junit.After; 2604813259SLiu Zhe import org.junit.Before; 2704813259SLiu Zhe import org.junit.Test; 2804813259SLiu Zhe import org.openoffice.test.common.FileUtil; 2904813259SLiu Zhe import org.openoffice.test.common.Testspace; 3004813259SLiu Zhe import org.openoffice.test.uno.UnoApp; 3104813259SLiu Zhe 3204813259SLiu Zhe import testlib.uno.ChartUtil; 3304813259SLiu Zhe import testlib.uno.PageUtil; 3404813259SLiu Zhe import testlib.uno.ShapeUtil; 3504813259SLiu Zhe import testlib.uno.TestUtil; 3604813259SLiu Zhe 3704813259SLiu Zhe import com.sun.star.awt.Point; 3804813259SLiu Zhe import com.sun.star.awt.Size; 3904813259SLiu Zhe import com.sun.star.beans.PropertyValue; 4004813259SLiu Zhe import com.sun.star.beans.XPropertySet; 4104813259SLiu Zhe import com.sun.star.chart.XChartDocument; 4204813259SLiu Zhe import com.sun.star.chart.XDiagram; 4304813259SLiu Zhe import com.sun.star.drawing.XDrawPage; 4404813259SLiu Zhe import com.sun.star.drawing.XDrawPages; 4504813259SLiu Zhe import com.sun.star.drawing.XDrawPagesSupplier; 4604813259SLiu Zhe import com.sun.star.drawing.XShape; 4704813259SLiu Zhe import com.sun.star.drawing.XShapes; 4804813259SLiu Zhe import com.sun.star.frame.XStorable; 4904813259SLiu Zhe import com.sun.star.lang.XComponent; 5004813259SLiu Zhe import com.sun.star.presentation.XPresentation; 5104813259SLiu Zhe import com.sun.star.presentation.XPresentationSupplier; 5204813259SLiu Zhe import com.sun.star.uno.UnoRuntime; 5304813259SLiu Zhe 5404813259SLiu Zhe public class ChartTypes { 5504813259SLiu Zhe UnoApp unoApp = new UnoApp(); 5604813259SLiu Zhe XPresentationSupplier sdDocument = null; 5704813259SLiu Zhe XPresentation pre = null; 5804813259SLiu Zhe XComponent precomp = null; 5904813259SLiu Zhe XComponent impressDocument = null; 6004813259SLiu Zhe XComponent reLoadFile = null; 6104813259SLiu Zhe XDrawPagesSupplier drawsupplier = null; 6204813259SLiu Zhe XDrawPages drawpages = null; 6304813259SLiu Zhe XShapes xShapes = null; 6404813259SLiu Zhe XDrawPage xpage = null; 6504813259SLiu Zhe String filePath = null; 6604813259SLiu Zhe 6704813259SLiu Zhe @Before setUp()6804813259SLiu Zhe public void setUp() throws Exception { 6904813259SLiu Zhe unoApp.start(); 7004813259SLiu Zhe createDocumentAndSlide(); 7104813259SLiu Zhe } 7204813259SLiu Zhe 7304813259SLiu Zhe @After tearDown()7404813259SLiu Zhe public void tearDown() throws Exception { 7504813259SLiu Zhe unoApp.closeDocument(impressDocument); 7604813259SLiu Zhe unoApp.closeDocument(reLoadFile); 7704813259SLiu Zhe unoApp.close(); 7804813259SLiu Zhe if (filePath != null) 7904813259SLiu Zhe FileUtil.deleteFile(filePath); 8004813259SLiu Zhe } 8104813259SLiu Zhe 8204813259SLiu Zhe /** 8304813259SLiu Zhe * Insert Area Chart 8404813259SLiu Zhe * 8504813259SLiu Zhe * @throws Exception 8604813259SLiu Zhe */ 8704813259SLiu Zhe @Test testInsertAreaChart()8804813259SLiu Zhe public void testInsertAreaChart() throws Exception { 8904813259SLiu Zhe XChartDocument xChartDoc = null; 9004813259SLiu Zhe XDiagram aDiagram = null; 9104813259SLiu Zhe Point po = new Point(1000, 1000); 9204813259SLiu Zhe xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); 9304813259SLiu Zhe XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( 9404813259SLiu Zhe 15000, 9271), "com.sun.star.drawing.OLE2Shape"); 9504813259SLiu Zhe xShapes.add(xShape); 9604813259SLiu Zhe xChartDoc = ChartUtil.retrieveChartDocument(xShape); 9704813259SLiu Zhe aDiagram = ChartUtil.createChart(xChartDoc, 9804813259SLiu Zhe "com.sun.star.chart.AreaDiagram"); 9904813259SLiu Zhe xChartDoc.setDiagram(aDiagram); 10004813259SLiu Zhe xShape = saveAndLoadShape(1, 0); 10104813259SLiu Zhe xChartDoc = ChartUtil.getChartDocument(xShape); 10204813259SLiu Zhe assertEquals("Not Area Chart", "com.sun.star.chart.AreaDiagram", 10304813259SLiu Zhe xChartDoc.getDiagram().getDiagramType()); 10404813259SLiu Zhe } 10504813259SLiu Zhe 10604813259SLiu Zhe /** 10704813259SLiu Zhe * Insert Bubble Chart 10804813259SLiu Zhe * 10904813259SLiu Zhe * @throws Exception 11004813259SLiu Zhe */ 11104813259SLiu Zhe @Test testInsertBubbleChart()11204813259SLiu Zhe public void testInsertBubbleChart() throws Exception { 11304813259SLiu Zhe XChartDocument xChartDoc = null; 11404813259SLiu Zhe XDiagram aDiagram = null; 11504813259SLiu Zhe Point po = new Point(1000, 1000); 11604813259SLiu Zhe xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); 11704813259SLiu Zhe XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( 11804813259SLiu Zhe 15000, 9271), "com.sun.star.drawing.OLE2Shape"); 11904813259SLiu Zhe xShapes.add(xShape); 12004813259SLiu Zhe xChartDoc = ChartUtil.retrieveChartDocument(xShape); 12104813259SLiu Zhe aDiagram = ChartUtil.createChart(xChartDoc, 12204813259SLiu Zhe "com.sun.star.chart.BubbleDiagram"); 12304813259SLiu Zhe xChartDoc.setDiagram(aDiagram); 12404813259SLiu Zhe xShape = saveAndLoadShape(1, 0); 12504813259SLiu Zhe xChartDoc = ChartUtil.getChartDocument(xShape); 12604813259SLiu Zhe assertEquals("Not Area Chart", "com.sun.star.chart.BubbleDiagram", 12704813259SLiu Zhe xChartDoc.getDiagram().getDiagramType()); 12804813259SLiu Zhe } 12904813259SLiu Zhe 13004813259SLiu Zhe /** 13104813259SLiu Zhe * Insert Bar Chart (default chart type) 13204813259SLiu Zhe * 13304813259SLiu Zhe * @throws Exception 13404813259SLiu Zhe */ 13504813259SLiu Zhe @Test testInsertBarChart()13604813259SLiu Zhe public void testInsertBarChart() throws Exception { 13704813259SLiu Zhe XChartDocument xChartDoc = null; 13804813259SLiu Zhe Point po = new Point(1000, 1000); 13904813259SLiu Zhe xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); 14004813259SLiu Zhe XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( 14104813259SLiu Zhe 15000, 9271), "com.sun.star.drawing.OLE2Shape"); 14204813259SLiu Zhe xShapes.add(xShape); 14304813259SLiu Zhe ChartUtil.retrieveChartDocument(xShape); 14404813259SLiu Zhe xShape = saveAndLoadShape(1, 0); 14504813259SLiu Zhe xChartDoc = ChartUtil.getChartDocument(xShape); 14604813259SLiu Zhe assertEquals("Not Bar Chart", "com.sun.star.chart.BarDiagram", 14704813259SLiu Zhe xChartDoc.getDiagram().getDiagramType()); 14804813259SLiu Zhe 14904813259SLiu Zhe } 15004813259SLiu Zhe 15104813259SLiu Zhe /** 15204813259SLiu Zhe * test Insert Cone Chart(3D look of Bar chart) 15304813259SLiu Zhe * 15404813259SLiu Zhe * @throws Exception 15504813259SLiu Zhe */ 15604813259SLiu Zhe @Test testInsertConeChart()15704813259SLiu Zhe public void testInsertConeChart() throws Exception { 15804813259SLiu Zhe XChartDocument xChartDoc = null; 15904813259SLiu Zhe XDiagram aDiagram = null; 16004813259SLiu Zhe Point po = new Point(1000, 1000); 16104813259SLiu Zhe xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); 16204813259SLiu Zhe XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( 16304813259SLiu Zhe 15000, 9271), "com.sun.star.drawing.OLE2Shape"); 16404813259SLiu Zhe xShapes.add(xShape); 16504813259SLiu Zhe xChartDoc = ChartUtil.retrieveChartDocument(xShape); 16604813259SLiu Zhe aDiagram = ChartUtil.createChart(xChartDoc, 16704813259SLiu Zhe "com.sun.star.chart.BarDiagram"); 16804813259SLiu Zhe XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface( 16904813259SLiu Zhe XPropertySet.class, aDiagram); 17004813259SLiu Zhe aDiaProp.setPropertyValue("Dim3D", true); 17104813259SLiu Zhe aDiaProp.setPropertyValue("Deep", true); 17204813259SLiu Zhe // from service Chart3DBarProperties: 17304813259SLiu Zhe aDiaProp.setPropertyValue("SolidType", new Integer( 17404813259SLiu Zhe com.sun.star.chart.ChartSolidType.CONE)); 17504813259SLiu Zhe xChartDoc.setDiagram(aDiagram); 17604813259SLiu Zhe xShape = saveAndLoadShape(1, 0); 17704813259SLiu Zhe xChartDoc = ChartUtil.getChartDocument(xShape); 17804813259SLiu Zhe aDiaProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, 17904813259SLiu Zhe xChartDoc.getDiagram()); 18004813259SLiu Zhe assertEquals("Not Cone Chart", com.sun.star.chart.ChartSolidType.CONE, 18104813259SLiu Zhe aDiaProp.getPropertyValue("SolidType")); 18204813259SLiu Zhe 18304813259SLiu Zhe } 18404813259SLiu Zhe 18504813259SLiu Zhe /** 18604813259SLiu Zhe * Insert Line Chart 18704813259SLiu Zhe * 18804813259SLiu Zhe * @throws Exception 18904813259SLiu Zhe */ 19004813259SLiu Zhe @Test testInsertLineChart()19104813259SLiu Zhe public void testInsertLineChart() throws Exception { 19204813259SLiu Zhe XChartDocument xChartDoc = null; 19304813259SLiu Zhe XDiagram aDiagram = null; 19404813259SLiu Zhe Point po = new Point(1000, 1000); 19504813259SLiu Zhe xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); 19604813259SLiu Zhe XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( 19704813259SLiu Zhe 15000, 9271), "com.sun.star.drawing.OLE2Shape"); 19804813259SLiu Zhe xShapes.add(xShape); 19904813259SLiu Zhe xChartDoc = ChartUtil.retrieveChartDocument(xShape); 20004813259SLiu Zhe aDiagram = ChartUtil.createChart(xChartDoc, 20104813259SLiu Zhe "com.sun.star.chart.LineDiagram"); 20204813259SLiu Zhe xChartDoc.setDiagram(aDiagram); 20304813259SLiu Zhe xShape = saveAndLoadShape(1, 0); 20404813259SLiu Zhe xChartDoc = ChartUtil.getChartDocument(xShape); 20504813259SLiu Zhe assertEquals("Not Area Chart", "com.sun.star.chart.LineDiagram", 20604813259SLiu Zhe xChartDoc.getDiagram().getDiagramType()); 20704813259SLiu Zhe } 20804813259SLiu Zhe 20904813259SLiu Zhe /** 21004813259SLiu Zhe * Insert Pie Chart 21104813259SLiu Zhe * 21204813259SLiu Zhe * @throws Exception 21304813259SLiu Zhe */ 21404813259SLiu Zhe @Test testInsertPieChart()21504813259SLiu Zhe public void testInsertPieChart() throws Exception { 21604813259SLiu Zhe XChartDocument xChartDoc = null; 21704813259SLiu Zhe XDiagram aDiagram = null; 21804813259SLiu Zhe Point po = new Point(1000, 1000); 21904813259SLiu Zhe xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xpage); 22004813259SLiu Zhe XShape xShape = ShapeUtil.createShape(impressDocument, po, new Size( 22104813259SLiu Zhe 15000, 9271), "com.sun.star.drawing.OLE2Shape"); 22204813259SLiu Zhe xShapes.add(xShape); 22304813259SLiu Zhe xChartDoc = ChartUtil.retrieveChartDocument(xShape); 22404813259SLiu Zhe aDiagram = ChartUtil.createChart(xChartDoc, 22504813259SLiu Zhe "com.sun.star.chart.PieDiagram"); 22604813259SLiu Zhe xChartDoc.setDiagram(aDiagram); 22704813259SLiu Zhe xShape = saveAndLoadShape(1, 0); 22804813259SLiu Zhe xChartDoc = ChartUtil.getChartDocument(xShape); 22904813259SLiu Zhe assertEquals("Not Area Chart", "com.sun.star.chart.PieDiagram", 23004813259SLiu Zhe xChartDoc.getDiagram().getDiagramType()); 23104813259SLiu Zhe } 23204813259SLiu Zhe 23304813259SLiu Zhe /** 23404813259SLiu Zhe * create a new presentation document and insert a new slide. 23504813259SLiu Zhe * 23604813259SLiu Zhe * @throws Exception 23704813259SLiu Zhe */ createDocumentAndSlide()23804813259SLiu Zhe public void createDocumentAndSlide() throws Exception { 23904813259SLiu Zhe impressDocument = (XComponent) UnoRuntime.queryInterface( 24004813259SLiu Zhe XComponent.class, unoApp.newDocument("simpress")); 24104813259SLiu Zhe drawsupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface( 24204813259SLiu Zhe XDrawPagesSupplier.class, impressDocument); 24304813259SLiu Zhe drawpages = drawsupplier.getDrawPages(); 24404813259SLiu Zhe drawpages.insertNewByIndex(1); 24504813259SLiu Zhe xpage = PageUtil.getDrawPageByIndex(impressDocument, 1); 24604813259SLiu Zhe } 24704813259SLiu Zhe 24804813259SLiu Zhe /** 24904813259SLiu Zhe * Save presentation and reLoad the presentation and shape in it. 25004813259SLiu Zhe * 25104813259SLiu Zhe * @param po 25204813259SLiu Zhe * @param shapeType 25304813259SLiu Zhe * @return 25404813259SLiu Zhe * @throws Exception 25504813259SLiu Zhe */ saveAndLoadShape(int pageIndex, int shapeIndex)25604813259SLiu Zhe public XShape saveAndLoadShape(int pageIndex, int shapeIndex) 25704813259SLiu Zhe throws Exception { 25804813259SLiu Zhe reLoadFile = saveAndReloadDoc(impressDocument, 25904813259SLiu Zhe "impress8", "odp"); 26004813259SLiu Zhe xShapes = ShapeUtil.getShapes(reLoadFile, pageIndex); 26104813259SLiu Zhe return (XShape) UnoRuntime.queryInterface(XShape.class, 26204813259SLiu Zhe xShapes.getByIndex(shapeIndex)); 26304813259SLiu Zhe } 26404813259SLiu Zhe 26504813259SLiu Zhe /** 26604813259SLiu Zhe * save and reload Presentation document. 26704813259SLiu Zhe * 26804813259SLiu Zhe * @param presentationDocument 26904813259SLiu Zhe * @param sFilter 27004813259SLiu Zhe * @param sExtension 27104813259SLiu Zhe * @return 27204813259SLiu Zhe * @throws Exception 27304813259SLiu Zhe */ saveAndReloadDoc(XComponent presentationDocument, String sFilter, String sExtension)27404813259SLiu Zhe private XComponent saveAndReloadDoc(XComponent presentationDocument, 27504813259SLiu Zhe String sFilter, String sExtension) throws Exception { 27604813259SLiu Zhe filePath = Testspace.getPath("tmp/presentationtest." + sExtension); 27704813259SLiu Zhe PropertyValue[] aStoreProperties = new PropertyValue[2]; 27804813259SLiu Zhe aStoreProperties[0] = new PropertyValue(); 27904813259SLiu Zhe aStoreProperties[1] = new PropertyValue(); 28004813259SLiu Zhe aStoreProperties[0].Name = "Override"; 28104813259SLiu Zhe aStoreProperties[0].Value = true; 28204813259SLiu Zhe aStoreProperties[1].Name = "FilterName"; 28304813259SLiu Zhe aStoreProperties[1].Value = sFilter; 28404813259SLiu Zhe XStorable xStorable = (XStorable) UnoRuntime.queryInterface( 28504813259SLiu Zhe XStorable.class, presentationDocument); 28604813259SLiu Zhe xStorable.storeToURL(FileUtil.getUrl(filePath), aStoreProperties); 28704813259SLiu Zhe 288cebb507aSLiu Zhe return (XComponent) UnoRuntime.queryInterface(XComponent.class, 28904813259SLiu Zhe unoApp.loadDocument(filePath)); 29004813259SLiu Zhe } 29104813259SLiu Zhe } 292