xref: /trunk/test/testuno/source/fvt/uno/sc/formula/TestFormulaRoundTrip.java (revision cf8e6a53ed981a205d7700be9a04dd40a005f9f6)
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 
23 package fvt.uno.sc.formula;
24 
25 import static org.junit.Assert.assertEquals;
26 
27 import java.util.Arrays;
28 import java.util.Collection;
29 
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.junit.runners.Parameterized;
35 import org.junit.runners.Parameterized.Parameters;
36 
37 import org.openoffice.test.common.Testspace;
38 import org.openoffice.test.uno.UnoApp;
39 
40 import testlib.uno.SCUtil;
41 import static testlib.uno.TestUtil.*;
42 
43 import com.sun.star.beans.PropertyValue;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.frame.XStorable;
46 import com.sun.star.lang.XComponent;
47 import com.sun.star.sheet.XSpreadsheet;
48 import com.sun.star.sheet.XSpreadsheetDocument;
49 import com.sun.star.sheet.XSpreadsheets;
50 import com.sun.star.table.XCell;
51 
52 public class TestFormulaRoundTrip {
53     private UnoApp unoApp = new UnoApp();
54 
55     private XSpreadsheetDocument scDocument = null;
56     private XComponent scComponent = null;
57 
58     @Before
59     public void setUp() throws Exception {
60         unoApp.start();
61         scComponent = unoApp.newDocument("scalc");
62         scDocument = SCUtil.getSCDocument(scComponent);
63     }
64 
65     @After
66     public void tearDown() throws Exception {
67         unoApp.closeDocument(scComponent);
68         unoApp.close();
69     }
70 
71     @Test
72     public void testMSExcel2003XMLFormulaRoundTrip() throws Exception {
73         XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
74         SCUtil.setTextToCell(sheet, 0, 0, "Hello world");
75         SCUtil.setFormulaToCell(sheet, 0, 1, "=A1");
76         String formulaValue = SCUtil.getTextFromCell(sheet, 0, 1);
77         assertEquals("Hello world", formulaValue);
78 
79         String storeUrl = Testspace.getUrl("output/sc/temp.xml");
80         PropertyValue[] storeProps = new PropertyValue[2];
81         storeProps[0] = new PropertyValue();
82         storeProps[0].Name = "FilterName";
83         storeProps[0].Value = "MS Excel 2003 XML";
84         storeProps[1] = new PropertyValue();
85         storeProps[1].Name = "Overwrite";
86         storeProps[1].Value = new Boolean(true);
87         XStorable scStorable =
88             (XStorable) UnoRuntime.queryInterface(XStorable.class, scComponent);
89         scStorable.storeAsURL(storeUrl, storeProps);
90 
91         unoApp.closeDocument(scComponent);
92 
93         scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(
94             XSpreadsheetDocument.class, unoApp.loadDocument(Testspace.getPath("output/sc/temp.xml")));
95         sheet = SCUtil.getCurrentSheet(scDocument);
96         String formulaValue2 = SCUtil.getTextFromCell(sheet, 0, 1);
97         assertEquals("Hello world", formulaValue2);
98         String formula2 = SCUtil.getFormulaFromCell(sheet, 0, 1);
99         assertEquals("=A1", formula2);
100     }
101 }
102