1b164ae3eSLei De Bin /************************************************************** 2b164ae3eSLei De Bin * 3b164ae3eSLei De Bin * Licensed to the Apache Software Foundation (ASF) under one 4b164ae3eSLei De Bin * or more contributor license agreements. See the NOTICE file 5b164ae3eSLei De Bin * distributed with this work for additional information 6b164ae3eSLei De Bin * regarding copyright ownership. The ASF licenses this file 7b164ae3eSLei De Bin * to you under the Apache License, Version 2.0 (the 8b164ae3eSLei De Bin * "License"); you may not use this file except in compliance 9b164ae3eSLei De Bin * with the License. You may obtain a copy of the License at 10b164ae3eSLei De Bin * 11b164ae3eSLei De Bin * http://www.apache.org/licenses/LICENSE-2.0 12b164ae3eSLei De Bin * 13b164ae3eSLei De Bin * Unless required by applicable law or agreed to in writing, 14b164ae3eSLei De Bin * software distributed under the License is distributed on an 15b164ae3eSLei De Bin * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16b164ae3eSLei De Bin * KIND, either express or implied. See the License for the 17b164ae3eSLei De Bin * specific language governing permissions and limitations 18b164ae3eSLei De Bin * under the License. 19b164ae3eSLei De Bin * 20b164ae3eSLei De Bin *************************************************************/ 21b164ae3eSLei De Bin 22faa4b864SLei De Bin /** 23faa4b864SLei De Bin * 24faa4b864SLei De Bin */ 2580a6f5c5SLiu Zhe package fvt.gui.formula.importexport; 26faa4b864SLei De Bin 27faa4b864SLei De Bin import static org.junit.Assert.*; 283816404dSLiu Zhe import static org.openoffice.test.common.Testspace.*; 2922a14f28SLiu Zhe import static org.openoffice.test.vcl.Tester.*; 30b4d2d410SLiu Zhe import static testlib.gui.AppTool.*; 3122a14f28SLiu Zhe import static testlib.gui.UIMap.*; 3222a14f28SLiu Zhe 332aaec72aSLiu Zhe import org.junit.After; 34faa4b864SLei De Bin import org.junit.Before; 3522a14f28SLiu Zhe import org.junit.Ignore; 36fd348426SLi Feng Wang import org.junit.Rule; 37faa4b864SLei De Bin import org.junit.Test; 38faa4b864SLei De Bin import org.openoffice.test.common.FileUtil; 39fd348426SLi Feng Wang import org.openoffice.test.common.Logger; 40faa4b864SLei De Bin 4138c338dbSLi Feng Wang import testlib.gui.AppTool; 4238c338dbSLi Feng Wang 432aaec72aSLiu Zhe 4438c338dbSLi Feng Wang public class FormulaInDifferentWays { 45fd348426SLi Feng Wang 46fd348426SLi Feng Wang @Rule 47fd348426SLi Feng Wang public Logger log = Logger.getLogger(this); 4822a14f28SLiu Zhe 49faa4b864SLei De Bin @Before setUp()50faa4b864SLei De Bin public void setUp() throws Exception { 514d3496b1SLiu Zhe app.start(true); 5238c338dbSLi Feng Wang newFormula(); 532aaec72aSLiu Zhe } 542aaec72aSLiu Zhe 552aaec72aSLiu Zhe @After tearDown()562aaec72aSLiu Zhe public void tearDown() throws Exception { 57*44cf0280SCarl Marcum discard(); 584a13b48eSLi Feng Wang app.stop(); 592aaec72aSLiu Zhe } 6022a14f28SLiu Zhe 612aaec72aSLiu Zhe /** 622aaec72aSLiu Zhe * Test elements window active and inactive 6322a14f28SLiu Zhe * 642aaec72aSLiu Zhe * @throws Exception 652aaec72aSLiu Zhe */ 662aaec72aSLiu Zhe @Test testElementsWindowActive()6722a14f28SLiu Zhe public void testElementsWindowActive() throws Exception { 682aaec72aSLiu Zhe // Check if the "View->Elements" menu is selected 69b4d2d410SLiu Zhe boolean viewElements = mathElementsWindow.exists(); 703816404dSLiu Zhe // Active or inactive the Elements window 713816404dSLiu Zhe app.dispatch(".uno:ToolBox"); 72b4d2d410SLiu Zhe assertNotSame("Elements window active/inactive failed", viewElements, mathElementsWindow.exists()); 73faa4b864SLei De Bin } 7422a14f28SLiu Zhe 75faa4b864SLei De Bin /** 76faa4b864SLei De Bin * Test create a formula from Elements window 7722a14f28SLiu Zhe * 78faa4b864SLei De Bin * @throws Exception 79faa4b864SLei De Bin */ 80faa4b864SLei De Bin @Test testCreateFormulaFromElementsWindow()8122a14f28SLiu Zhe public void testCreateFormulaFromElementsWindow() throws Exception { 823816404dSLiu Zhe String saveTo = getPath("temp/" + "FormulaFromElements.odf"); 83faa4b864SLei De Bin 842aaec72aSLiu Zhe // Make Elements window pop up 85b4d2d410SLiu Zhe if (!mathElementsWindow.exists()) { 863816404dSLiu Zhe app.dispatch(".uno:ToolBox"); 87faa4b864SLei De Bin } 8822a14f28SLiu Zhe // Click a formula in Elements window and edit the formula in the 8922a14f28SLiu Zhe // commands window 90b4d2d410SLiu Zhe mathElementsRelations.click(); 91b4d2d410SLiu Zhe mathElementsRelationsNotEqual.click(); 92*44cf0280SCarl Marcum sleep(1); 93faa4b864SLei De Bin typeKeys("a"); 943816404dSLiu Zhe app.dispatch(".uno:NextMark"); 95faa4b864SLei De Bin typeKeys("b"); 96faa4b864SLei De Bin String insertedFormula = "a <> b"; 9722a14f28SLiu Zhe 98faa4b864SLei De Bin // Verify if the formula is correct 992aaec72aSLiu Zhe app.dispatch(".uno:Select"); 1002aaec72aSLiu Zhe app.dispatch(".uno:Copy"); 10138c338dbSLi Feng Wang assertEquals("The inserted formula into math", insertedFormula.concat(" "), app.getClipboard()); 10238c338dbSLi Feng Wang 10338c338dbSLi Feng Wang // Save and reopen the formula 104faa4b864SLei De Bin FileUtil.deleteFile(saveTo); 105b23eb6e1SLi Feng Wang saveAndReopen(saveTo); 106b4d2d410SLiu Zhe mathEditWindow.waitForExistence(10, 2); 10722a14f28SLiu Zhe 108faa4b864SLei De Bin // Verify if the formula still exists in the file, and correct 1093816404dSLiu Zhe app.dispatch(".uno:Select"); 1102aaec72aSLiu Zhe app.dispatch(".uno:Copy"); 11138c338dbSLi Feng Wang assertEquals("The inserted formula into math", insertedFormula.concat(" "), app.getClipboard()); 11238c338dbSLi Feng Wang 113faa4b864SLei De Bin } 11422a14f28SLiu Zhe 115faa4b864SLei De Bin /** 116faa4b864SLei De Bin * Test create a formula from right click menu in equation editor 11722a14f28SLiu Zhe * 118faa4b864SLei De Bin * @throws Exception 119faa4b864SLei De Bin */ 120faa4b864SLei De Bin @Test testCreateFormulaFromRightClickMenu()12122a14f28SLiu Zhe public void testCreateFormulaFromRightClickMenu() throws Exception { 1223816404dSLiu Zhe String saveTo = getPath("temp/" + "FormulaFromRightClickMenu.odf"); 12322a14f28SLiu Zhe 12422a14f28SLiu Zhe // Right click in equation editor, choose "Functions->More->arcsin(x)", 125b4d2d410SLiu Zhe mathEditWindow.rightClick(5, 5); 126faa4b864SLei De Bin typeKeys("<down>"); 127faa4b864SLei De Bin typeKeys("<down>"); 128faa4b864SLei De Bin typeKeys("<down>"); 129faa4b864SLei De Bin typeKeys("<down>"); 130faa4b864SLei De Bin typeKeys("<enter>"); 131faa4b864SLei De Bin typeKeys("<up>"); 132faa4b864SLei De Bin typeKeys("<enter>"); 133faa4b864SLei De Bin typeKeys("<enter>"); 134faa4b864SLei De Bin typeKeys("a"); 13538c338dbSLi Feng Wang sleep(2); 136faa4b864SLei De Bin String insertedFormula = "arcsin(a)"; 13722a14f28SLiu Zhe 138faa4b864SLei De Bin // Verify if the formula is correct 1393816404dSLiu Zhe app.dispatch(".uno:Select"); 1402aaec72aSLiu Zhe app.dispatch(".uno:Copy"); 1413816404dSLiu Zhe 14238c338dbSLi Feng Wang assertEquals("The inserted formula into math", insertedFormula.concat(" "), app.getClipboard()); 14338c338dbSLi Feng Wang // Save and reopen the formula 144faa4b864SLei De Bin FileUtil.deleteFile(saveTo); 145b23eb6e1SLi Feng Wang saveAndReopen(saveTo); 14638c338dbSLi Feng Wang 147b4d2d410SLiu Zhe mathEditWindow.waitForExistence(10, 2); 148faa4b864SLei De Bin // Verify if the formula still exists in the file, and correct 1493816404dSLiu Zhe app.dispatch(".uno:Select"); 1502aaec72aSLiu Zhe app.dispatch(".uno:Copy"); 15138c338dbSLi Feng Wang assertEquals("The inserted formula into math", insertedFormula.concat(" "), app.getClipboard()); 152faa4b864SLei De Bin } 15322a14f28SLiu Zhe 154faa4b864SLei De Bin /** 155faa4b864SLei De Bin * Test undo/redo in math 15622a14f28SLiu Zhe * 157faa4b864SLei De Bin * @throws Exception 158faa4b864SLei De Bin */ 15983ae2205SHerbert Dürr @Test testUndoRedoInMath()16022a14f28SLiu Zhe public void testUndoRedoInMath() throws Exception { 161faa4b864SLei De Bin 1623816404dSLiu Zhe // Make Elements window pop up 163b4d2d410SLiu Zhe if (!mathElementsWindow.exists()) { 1643816404dSLiu Zhe app.dispatch(".uno:ToolBox"); 165faa4b864SLei De Bin } 16622a14f28SLiu Zhe 16722a14f28SLiu Zhe // Click a formula in Elements window and edit the formula in the 16822a14f28SLiu Zhe // commands window 169b4d2d410SLiu Zhe mathElementsUnaryBinary.click(); 170b4d2d410SLiu Zhe mathElementsUnaryBinaryPlus.click(); 171*44cf0280SCarl Marcum sleep(1); 17222a14f28SLiu Zhe typeKeys("a"); // "+a"; 17322a14f28SLiu Zhe 174faa4b864SLei De Bin // Undo and verify if it works fine 1753816404dSLiu Zhe app.dispatch(".uno:Undo"); 1763816404dSLiu Zhe app.dispatch(".uno:Select"); 1772aaec72aSLiu Zhe app.dispatch(".uno:Copy"); 17838c338dbSLi Feng Wang assertEquals("The inserted formula into math", "+<?> ", app.getClipboard()); 17922a14f28SLiu Zhe 180faa4b864SLei De Bin // Redo and verify if it works fine 1813816404dSLiu Zhe app.dispatch(".uno:Redo"); 1823816404dSLiu Zhe app.dispatch(".uno:Select"); 1832aaec72aSLiu Zhe app.dispatch(".uno:Copy"); 18438c338dbSLi Feng Wang assertEquals("The inserted formula into math", "+a ", app.getClipboard()); 185faa4b864SLei De Bin } 186faa4b864SLei De Bin } 187