1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 package fvt.uno.sc.object; 23 24 import static org.junit.Assert.assertEquals; 25 26 import java.util.Arrays; 27 import java.util.Collection; 28 29 import org.junit.After; 30 import org.junit.AfterClass; 31 import org.junit.Before; 32 import org.junit.BeforeClass; 33 import org.junit.Test; 34 import org.junit.runner.RunWith; 35 import org.junit.runners.Parameterized; 36 import org.junit.runners.Parameterized.Parameters; 37 import org.openoffice.test.uno.UnoApp; 38 39 import testlib.uno.SCUtil; 40 import testlib.uno.ShapeUtil; 41 42 import com.sun.star.awt.Point; 43 import com.sun.star.awt.Size; 44 import com.sun.star.drawing.XDrawPage; 45 import com.sun.star.drawing.XDrawPageSupplier; 46 import com.sun.star.drawing.XShape; 47 import com.sun.star.drawing.XShapes; 48 import com.sun.star.lang.XComponent; 49 import com.sun.star.sheet.XSpreadsheet; 50 import com.sun.star.sheet.XSpreadsheetDocument; 51 import com.sun.star.uno.UnoRuntime; 52 53 /** 54 * Check the shapes can be added and removed 55 * 56 */ 57 @RunWith(value = Parameterized.class) 58 public class DrawingObject { 59 60 private String inputType; 61 private String fileType; 62 63 private static final UnoApp unoApp = new UnoApp(); 64 65 XComponent scComponent = null; 66 XSpreadsheetDocument scDocument = null; 67 68 @Parameters data()69 public static Collection<Object[]> data() throws Exception { 70 71 return Arrays.asList(new Object[][] { 72 {"com.sun.star.drawing.RectangleShape", "ods"}, 73 {"com.sun.star.drawing.EllipseShape", "ods"}, 74 {"com.sun.star.drawing.LineShape", "ods"}, 75 {"com.sun.star.drawing.GraphicObjectShape", "ods"}, 76 {"com.sun.star.drawing.MeasureShape", "ods"}, 77 {"com.sun.star.drawing.PageShape", "ods"}, 78 {"com.sun.star.drawing.TextShape", "ods"}, 79 {"com.sun.star.drawing.RectangleShape", "xls"}, 80 {"com.sun.star.drawing.EllipseShape", "xls"}, 81 {"com.sun.star.drawing.LineShape", "xls"}, 82 {"com.sun.star.drawing.MeasureShape", "xls"}, 83 {"com.sun.star.drawing.PageShape", "xls"}, 84 {"com.sun.star.drawing.TextShape", "xls"}, 85 }); 86 } 87 DrawingObject( String inputType, String fileType)88 public DrawingObject( String inputType, String fileType) { 89 // this.expected = expected; 90 this.inputType = inputType; 91 // this.numberData = numberData; 92 this.fileType = fileType; 93 } 94 95 @Before setUp()96 public void setUp() throws Exception { 97 scComponent = unoApp.newDocument("scalc"); 98 scDocument = SCUtil.getSCDocument(scComponent); 99 } 100 101 @After tearDown()102 public void tearDown() throws Exception { 103 unoApp.closeDocument(scComponent); 104 105 } 106 107 @BeforeClass setUpConnection()108 public static void setUpConnection() throws Exception { 109 unoApp.start(); 110 } 111 112 @AfterClass tearDownConnection()113 public static void tearDownConnection() throws InterruptedException, Exception { 114 unoApp.close(); 115 SCUtil.clearTempDir(); 116 } 117 118 /** 119 * Check Drawing Object 120 * 1. Create a spreadsheet file. 121 * 2. Add shape. 122 * 3. Save file as ODF/MSBinary format. 123 * 4. Close and reopen file. -> Check the shape added. 124 * 5. Remove shape. 125 * 6. Save file as ODF/MSBinary format. 126 * 7. Close and reopen file. -> Check the shape removed. 127 * @throws Exception 128 */ 129 130 @Test testDrawingObject()131 public void testDrawingObject() throws Exception { 132 133 String fileName = inputType; 134 135 scDocument = SCUtil.getSCDocument(scComponent); 136 XSpreadsheet xSheet = SCUtil.getCurrentSheet(scDocument); 137 XDrawPageSupplier xDrawPageSupplier = 138 (XDrawPageSupplier)UnoRuntime.queryInterface(XDrawPageSupplier.class, xSheet); 139 XDrawPage xDrawPage = xDrawPageSupplier.getDrawPage(); 140 XShapes xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xDrawPage); 141 142 //Execute add shape action 143 Point po = new Point(100, 100); 144 Size Si = new Size(5000, 5000); 145 XShape xShape = ShapeUtil.createShape(scComponent, po, Si, inputType); 146 xShapes.add(xShape); 147 148 //Verify shape is added correctly 149 150 //Verify number of shape in sheet. 151 assertEquals("Verify number of shape in sheet add execute add action.",1, xShapes.getCount()); 152 153 //Save it, close and reopen it 154 SCUtil.saveFileAs(scComponent, fileName, fileType); 155 scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType); 156 157 xSheet = SCUtil.getCurrentSheet(scDocument); 158 xDrawPageSupplier = 159 (XDrawPageSupplier)UnoRuntime.queryInterface(XDrawPageSupplier.class, xSheet); 160 xDrawPage = xDrawPageSupplier.getDrawPage(); 161 xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xDrawPage); 162 163 //Verify number of shape in sheet. 164 assertEquals("Verify number of shape in sheet.",1, xShapes.getCount()); 165 166 //Verify correct shape type added. 167 assertEquals("Verify shape type is correct.",inputType, xShape.getShapeType()); 168 169 xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xShapes.getByIndex(0)); 170 171 //Execute remove drawing objects 172 xShapes.remove(xShape); 173 174 //Verify results after remove shape 175 assertEquals("Verify results after remove shape.",0, xShapes.getCount()); 176 177 //Save and reload document 178 179 //Save the modified spreadsheet first 180 SCUtil.save(scDocument); 181 182 //close it and reload it 183 scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType); 184 185 //Get Draw page 186 xSheet = SCUtil.getCurrentSheet(scDocument); 187 xDrawPageSupplier = 188 (XDrawPageSupplier)UnoRuntime.queryInterface(XDrawPageSupplier.class, xSheet); 189 xDrawPage = xDrawPageSupplier.getDrawPage(); 190 xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xDrawPage); 191 192 //Verify number of shape in sheet after executing remove action. 193 assertEquals("Verify 0 shape in sheet after executing remove action.", 194 0, xShapes.getCount()); 195 196 197 198 199 200 } 201 202 } 203