xref: /AOO41X/test/testgui/source/fvt/gui/formula/importexport/FormulaInDifferentWays.java (revision 44cf02803b51681da4056cdf9500cc33ee29bd2f)
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  *
24  */
25 package fvt.gui.formula.importexport;
26 
27 import static org.junit.Assert.*;
28 import static org.openoffice.test.common.Testspace.*;
29 import static org.openoffice.test.vcl.Tester.*;
30 import static testlib.gui.AppTool.*;
31 import static testlib.gui.UIMap.*;
32 
33 import org.junit.After;
34 import org.junit.Before;
35 import org.junit.Ignore;
36 import org.junit.Rule;
37 import org.junit.Test;
38 import org.openoffice.test.common.FileUtil;
39 import org.openoffice.test.common.Logger;
40 
41 import testlib.gui.AppTool;
42 
43 
44 public class FormulaInDifferentWays {
45 
46     @Rule
47     public Logger log = Logger.getLogger(this);
48 
49     @Before
setUp()50     public void setUp() throws Exception {
51         app.start(true);
52         newFormula();
53     }
54 
55     @After
tearDown()56     public void tearDown() throws Exception {
57         discard();
58         app.stop();
59     }
60 
61     /**
62      * Test elements window active and inactive
63      *
64      * @throws Exception
65      */
66     @Test
testElementsWindowActive()67     public void testElementsWindowActive() throws Exception {
68         // Check if the "View->Elements" menu is selected
69         boolean viewElements = mathElementsWindow.exists();
70         // Active or inactive the Elements window
71         app.dispatch(".uno:ToolBox");
72         assertNotSame("Elements window active/inactive failed", viewElements, mathElementsWindow.exists());
73     }
74 
75     /**
76      * Test create a formula from Elements window
77      *
78      * @throws Exception
79      */
80     @Test
testCreateFormulaFromElementsWindow()81     public void testCreateFormulaFromElementsWindow() throws Exception {
82         String saveTo = getPath("temp/" + "FormulaFromElements.odf");
83 
84         // Make Elements window pop up
85         if (!mathElementsWindow.exists()) {
86             app.dispatch(".uno:ToolBox");
87         }
88         // Click a formula in Elements window and edit the formula in the
89         // commands window
90         mathElementsRelations.click();
91         mathElementsRelationsNotEqual.click();
92         sleep(1);
93         typeKeys("a");
94         app.dispatch(".uno:NextMark");
95         typeKeys("b");
96         String insertedFormula = "a <> b";
97 
98         // Verify if the formula is correct
99         app.dispatch(".uno:Select");
100         app.dispatch(".uno:Copy");
101         assertEquals("The inserted formula into math", insertedFormula.concat(" "), app.getClipboard());
102 
103         // Save and reopen the formula
104         FileUtil.deleteFile(saveTo);
105         saveAndReopen(saveTo);
106         mathEditWindow.waitForExistence(10, 2);
107 
108         // Verify if the formula still exists in the file, and correct
109         app.dispatch(".uno:Select");
110         app.dispatch(".uno:Copy");
111         assertEquals("The inserted formula into math", insertedFormula.concat(" "), app.getClipboard());
112 
113     }
114 
115     /**
116      * Test create a formula from right click menu in equation editor
117      *
118      * @throws Exception
119      */
120     @Test
testCreateFormulaFromRightClickMenu()121     public void testCreateFormulaFromRightClickMenu() throws Exception {
122         String saveTo = getPath("temp/" + "FormulaFromRightClickMenu.odf");
123 
124         // Right click in equation editor, choose "Functions->More->arcsin(x)",
125         mathEditWindow.rightClick(5, 5);
126         typeKeys("<down>");
127         typeKeys("<down>");
128         typeKeys("<down>");
129         typeKeys("<down>");
130         typeKeys("<enter>");
131         typeKeys("<up>");
132         typeKeys("<enter>");
133         typeKeys("<enter>");
134         typeKeys("a");
135         sleep(2);
136         String insertedFormula = "arcsin(a)";
137 
138         // Verify if the formula is correct
139         app.dispatch(".uno:Select");
140         app.dispatch(".uno:Copy");
141 
142         assertEquals("The inserted formula into math", insertedFormula.concat(" "), app.getClipboard());
143         // Save and reopen the formula
144         FileUtil.deleteFile(saveTo);
145         saveAndReopen(saveTo);
146 
147         mathEditWindow.waitForExistence(10, 2);
148         // Verify if the formula still exists in the file, and correct
149         app.dispatch(".uno:Select");
150         app.dispatch(".uno:Copy");
151         assertEquals("The inserted formula into math", insertedFormula.concat(" "), app.getClipboard());
152     }
153 
154     /**
155      * Test undo/redo in math
156      *
157      * @throws Exception
158      */
159     @Test
testUndoRedoInMath()160     public void testUndoRedoInMath() throws Exception {
161 
162         // Make Elements window pop up
163         if (!mathElementsWindow.exists()) {
164             app.dispatch(".uno:ToolBox");
165         }
166 
167         // Click a formula in Elements window and edit the formula in the
168         // commands window
169         mathElementsUnaryBinary.click();
170         mathElementsUnaryBinaryPlus.click();
171         sleep(1);
172         typeKeys("a"); // "+a";
173 
174         // Undo and verify if it works fine
175         app.dispatch(".uno:Undo");
176         app.dispatch(".uno:Select");
177         app.dispatch(".uno:Copy");
178         assertEquals("The inserted formula into math", "+<?> ", app.getClipboard());
179 
180         // Redo and verify if it works fine
181         app.dispatch(".uno:Redo");
182         app.dispatch(".uno:Select");
183         app.dispatch(".uno:Copy");
184         assertEquals("The inserted formula into math", "+a ", app.getClipboard());
185     }
186 }
187