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 close(); 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 typeKeys("a"); 93 app.dispatch(".uno:NextMark"); 94 typeKeys("b"); 95 String insertedFormula = "a <> b"; 96 97 // Verify if the formula is correct 98 app.dispatch(".uno:Select"); 99 app.dispatch(".uno:Copy"); 100 assertEquals("The inserted formula into math", insertedFormula.concat(" "), app.getClipboard()); 101 102 // Save and reopen the formula 103 FileUtil.deleteFile(saveTo); 104 saveAndReopen(saveTo); 105 mathEditWindow.waitForExistence(10, 2); 106 107 // Verify if the formula still exists in the file, and correct 108 app.dispatch(".uno:Select"); 109 app.dispatch(".uno:Copy"); 110 assertEquals("The inserted formula into math", insertedFormula.concat(" "), app.getClipboard()); 111 112 } 113 114 /** 115 * Test create a formula from right click menu in equation editor 116 * 117 * @throws Exception 118 */ 119 @Test testCreateFormulaFromRightClickMenu()120 public void testCreateFormulaFromRightClickMenu() throws Exception { 121 String saveTo = getPath("temp/" + "FormulaFromRightClickMenu.odf"); 122 123 // Right click in equation editor, choose "Functions->More->arcsin(x)", 124 mathEditWindow.rightClick(5, 5); 125 typeKeys("<down>"); 126 typeKeys("<down>"); 127 typeKeys("<down>"); 128 typeKeys("<down>"); 129 typeKeys("<enter>"); 130 typeKeys("<up>"); 131 typeKeys("<enter>"); 132 typeKeys("<enter>"); 133 typeKeys("a"); 134 sleep(2); 135 String insertedFormula = "arcsin(a)"; 136 137 // Verify if the formula is correct 138 app.dispatch(".uno:Select"); 139 app.dispatch(".uno:Copy"); 140 141 assertEquals("The inserted formula into math", insertedFormula.concat(" "), app.getClipboard()); 142 // Save and reopen the formula 143 FileUtil.deleteFile(saveTo); 144 saveAndReopen(saveTo); 145 146 mathEditWindow.waitForExistence(10, 2); 147 // Verify if the formula still exists in the file, and correct 148 app.dispatch(".uno:Select"); 149 app.dispatch(".uno:Copy"); 150 assertEquals("The inserted formula into math", insertedFormula.concat(" "), app.getClipboard()); 151 } 152 153 /** 154 * Test undo/redo in math 155 * 156 * @throws Exception 157 */ 158 @Test testUndoRedoInMath()159 public void testUndoRedoInMath() throws Exception { 160 161 // Make Elements window pop up 162 if (!mathElementsWindow.exists()) { 163 app.dispatch(".uno:ToolBox"); 164 } 165 166 // Click a formula in Elements window and edit the formula in the 167 // commands window 168 mathElementsUnaryBinary.click(); 169 mathElementsUnaryBinaryPlus.click(); 170 typeKeys("a"); // "+a"; 171 172 // Undo and verify if it works fine 173 app.dispatch(".uno:Undo"); 174 app.dispatch(".uno:Select"); 175 app.dispatch(".uno:Copy"); 176 assertEquals("The inserted formula into math", "+<?> ", app.getClipboard()); 177 178 // Redo and verify if it works fine 179 app.dispatch(".uno:Redo"); 180 app.dispatch(".uno:Select"); 181 app.dispatch(".uno:Copy"); 182 assertEquals("The inserted formula into math", "+a ", app.getClipboard()); 183 } 184 } 185