Author: liuzhe
Date: Wed Jul  4 06:02:29 2012
New Revision: 1357090

URL: http://svn.apache.org/viewvc?rev=1357090&view=rev
Log:
#119998# - Add JavaDoc to API. Add new methods into VclApp. Merge BVTFunction2 
into BVTFunction. Add two parameters to AppUtil.initApp.

Added:
    
incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/common/StreamPump.java
Removed:
    incubator/ooo/trunk/main/test/testoo/src/testcase/BVTFunction2.java
Modified:
    
incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/common/FileUtil.java
    
incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/common/SystemUtil.java
    
incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/vcl/widgets/VclApp.java
    incubator/ooo/trunk/main/test/testoo/build.xml
    incubator/ooo/trunk/main/test/testoo/src/testcase/BVTFunction.java
    incubator/ooo/trunk/main/test/testoo/src/testcase/SmokeTest.java
    incubator/ooo/trunk/main/test/testoo/src/testlib/AppUtil.java
    incubator/ooo/trunk/main/test/testoo/src/testlib/UIMap.java
    incubator/ooo/trunk/main/test/testoo/src/testsuite/BVT.java

Modified: 
incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/common/FileUtil.java
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/common/FileUtil.java?rev=1357090&r1=1357089&r2=1357090&view=diff
==============================================================================
--- 
incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/common/FileUtil.java
 (original)
+++ 
incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/common/FileUtil.java
 Wed Jul  4 06:02:29 2012
@@ -124,6 +124,15 @@ public class FileUtil {
         * @return
         */
        public static Properties loadProperties(String file) {
+               return loadProperties(new File(file));
+       }
+       
+       /**
+        * Load a properties file to Properties class
+        * @param file the properties file
+        * @return
+        */
+       public static Properties loadProperties(File file) {
                Properties properties = new Properties();
                FileInputStream fis = null;
                try {

Added: 
incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/common/StreamPump.java
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/common/StreamPump.java?rev=1357090&view=auto
==============================================================================
--- 
incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/common/StreamPump.java
 (added)
+++ 
incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/common/StreamPump.java
 Wed Jul  4 06:02:29 2012
@@ -0,0 +1,63 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+package org.openoffice.test.common;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+/**
+ * Pump data from input stream into a StringBuffer
+ *
+ */
+public class StreamPump extends Thread {
+       StringBuffer stringBuffer = null;
+       InputStream inputStream = null;
+
+       public StreamPump(StringBuffer stringBuffer, InputStream inputStream) {
+               this.stringBuffer = stringBuffer;
+               this.inputStream = inputStream;
+       }
+
+       public void run() {
+               InputStreamReader reader = null;
+               try {
+                       reader = new InputStreamReader(inputStream);
+                       char[] buf = new char[1024];
+                       int count = 0;
+                       while ((count = reader.read(buf)) != -1) {
+                               // If we need collect the output
+                               if (stringBuffer != null)
+                                       stringBuffer.append(buf, 0, count);
+                       }
+               } catch (IOException e) {
+                       // ignore.
+               } finally {
+                       if (reader != null)
+                               try {
+                                       reader.close();
+                               } catch (IOException e) {
+                                       // ignore
+                               }
+               }
+       }
+}
\ No newline at end of file

Modified: 
incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/common/SystemUtil.java
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/common/SystemUtil.java?rev=1357090&r1=1357089&r2=1357090&view=diff
==============================================================================
--- 
incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/common/SystemUtil.java
 (original)
+++ 
incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/common/SystemUtil.java
 Wed Jul  4 06:02:29 2012
@@ -31,8 +31,6 @@ import java.awt.datatransfer.Transferabl
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.io.StringReader;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
@@ -143,6 +141,21 @@ public class SystemUtil {
                throw new RuntimeException("System Clipboard is not ready");
        }
 
+       /**
+        * Execute a script and waiting it for finishing
+        * @param content
+        * @return
+        */
+       public static int execScript(String content) {
+               return execScript(content, false);
+       }
+       
+       /**
+        * Execute a script. bat on Windows, bash on Linux
+        * @param content
+        * @param spawn
+        * @return
+        */
        public static int execScript(String content, boolean spawn) {
                File file = null;
                try {
@@ -199,39 +212,10 @@ public class SystemUtil {
                }
        }
 
-       public static class StreamPump extends Thread {
-               StringBuffer stringBuffer = null;
-               InputStream inputStream = null;
-
-               public StreamPump(StringBuffer stringBuffer, InputStream 
inputStream) {
-                       this.stringBuffer = stringBuffer;
-                       this.inputStream = inputStream;
-               }
-
-               public void run() {
-                       InputStreamReader reader = null;
-                       try {
-                               reader = new InputStreamReader(inputStream);
-                               char[] buf = new char[1024];
-                               int count = 0;
-                               while ((count = reader.read(buf)) != -1) {
-                                       // If we need collect the output
-                                       if (stringBuffer != null)
-                                               stringBuffer.append(buf, 0, 
count);
-                               }
-                       } catch (IOException e) {
-                               // ignore.
-                       } finally {
-                               if (reader != null)
-                                       try {
-                                               reader.close();
-                                       } catch (IOException e) {
-                                               // ignore
-                                       }
-                       }
-               }
-       }
-
+       /**
+        * Make the current thread sleep some seconds.
+        * @param second
+        */
        public static void sleep(double second) {
                try {
                        Thread.sleep((long) (second * 1000));

Modified: 
incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/vcl/widgets/VclApp.java
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/vcl/widgets/VclApp.java?rev=1357090&r1=1357089&r2=1357090&view=diff
==============================================================================
--- 
incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/vcl/widgets/VclApp.java
 (original)
+++ 
incubator/ooo/trunk/main/test/testcommon/source/org/openoffice/test/vcl/widgets/VclApp.java
 Wed Jul  4 06:02:29 2012
@@ -19,11 +19,10 @@
  * 
  *************************************************************/
 
-
-
 package org.openoffice.test.vcl.widgets;
 
-
+import java.io.File;
+import java.net.MalformedURLException;
 import java.util.Properties;
 
 import org.openoffice.test.common.FileUtil;
@@ -32,112 +31,232 @@ import org.openoffice.test.vcl.Tester;
 import org.openoffice.test.vcl.client.Constant;
 import org.openoffice.test.vcl.client.VclHook;
 
+/**
+ * This class provides a proxy to interact with OpenOffice application.
+ * 
+ */
 public class VclApp {
-       String home = null;
-       
-       public static final String CMD_KILL_WINDOWS = "taskkill /F /IM 
soffice.bin /IM soffice.exe";
-       
-       public static final String CMD_KILL_LINUX = "killall -9 soffice 
soffice.bin";
-       
-       String cmdKill = null;
-       
-       String cmdStart = null;
-       
-       String versionFile = null;
-       
-       Properties version = null;
-       
-       String port = System.getProperty("openoffice.automation.port", "12479");
+
+       private String port = System.getProperty("openoffice.automation.port", 
"12479");
+
+       private File userInstallation = null;
+
+       private File defaultUserInstallation = null;
        
+       private File home = null;
+
+       private String args = null;
+
+       private boolean automationEnabled = true;
+
+       /**
+        * Construct VclApp with the home path of OpenOffice. The home is the
+        * directory which contains soffice.bin.
+        * 
+        * @param appHome
+        */
        public VclApp(String appHome) {
-               setHome(appHome);
-       }
+               if (appHome == null)
+                       appHome = System.getProperty("openoffice.home");
+               if (appHome == null)
+                       appHome = System.getenv("OPENOFFICE_HOME");
+               if (appHome == null) {
+                       if (SystemUtil.isWindows()) {
+                               appHome = "C:/Program Files/OpenOffice.org 
3/program";
+                       } else if (SystemUtil.isMac()) {
+                               appHome = 
"/Applications/OpenOffice.org/Contents/MacOS";
+                       } else {
+                               appHome = "/opt/openoffice.org3/program";
+                       }
+               }
 
-       public VclApp() {
-               this(null);
-       }
-       
-       public void setHome(String home) {
-               this.home = home;
-               if (home == null)
-                       home = System.getProperty("openoffice.home");
-               if (home == null)
-                       home = System.getenv("OPENOFFICE_HOME");
-               if (home == null) 
-                       home = "unkown";
-               
-               versionFile = "versionrc";
+               home = new File(appHome);
                
-               cmdKill = CMD_KILL_LINUX;
-               cmdStart = "cd \"" + home + "\" ; ./soffice";
+               File bootstrapFile = new File(home, "bootstraprc");
+               if (!bootstrapFile.exists())
+                       bootstrapFile = new File(home, "bootstrap.ini");
+               if (!bootstrapFile.exists())
+                       throw new RuntimeException("OpenOffice can not be found 
or it's broken.");
+
+               Properties props = FileUtil.loadProperties(bootstrapFile);
+               String defaultUserInstallationPath = 
props.getProperty("UserInstallation");
+               String sysUserConfig = null;
                if (SystemUtil.isWindows()) {
-                       cmdKill = CMD_KILL_WINDOWS;
-                       cmdStart = "\"" + home + "\\soffice.exe\"";
-                       versionFile = "version.ini";
-                       
+                       sysUserConfig = System.getenv("APPDATA");
                } else if (SystemUtil.isMac()) {
-                       
+                       sysUserConfig = System.getProperty("user.home") + 
"/Library/Application Support";
                } else {
-                       
+                       sysUserConfig = System.getProperty("user.home");
                }
-               
+
+               defaultUserInstallationPath = 
defaultUserInstallationPath.replace("$ORIGIN", 
home.getAbsolutePath()).replace("$SYSUSERCONFIG", sysUserConfig);
+               defaultUserInstallation = new File(defaultUserInstallationPath);
        }
-       public String getHome() {
-               return home;
+
+       /**
+        * Set UserInstallation directory. When openoffice is launched, the 
argument
+        * "-env:UserInstallation" will be enabled.
+        * 
+        * @param dir
+        *            user installation directory. If null is given, the default
+        *            will be used.
+        */
+       public void setUserInstallation(File dir) {
+               userInstallation = dir;
        }
-       
-       public void kill() {
-               SystemUtil.execScript(cmdKill, false);
+
+       /**
+        * Get UserInstallation directory
+        * 
+        * @return
+        */
+       public File getUserInstallation() {
+               return userInstallation == null ? defaultUserInstallation : 
userInstallation;
        }
-       
-       public int start(String args) {
-               if (args == null)
-                       args = "";
-               
-               return SystemUtil.execScript(cmdStart + " -norestore 
-quickstart=no -nofirststartwizard -enableautomation -automationport=" + port + 
" " + args, true);
+
+       /**
+        * Get default UserInstallation directory
+        * 
+        * @return
+        */
+       public File getDefaultUserInstallation() {
+               return defaultUserInstallation;
        }
        
-       public void start() {
-               start(null);
+       /**
+        * Get installation directory of OpenOffice.
+        * 
+        * @return
+        */
+       public File getHome() {
+               return home;
        }
-       
+
        /**
-        * Activate the document window at the given index
+        * Set other command line arguments
+        * 
+        * @param args
+        */
+       public void setArgs(String args) {
+               this.args = args;
+       }
+
+       public boolean isAutomationEnabled() {
+               return automationEnabled;
+       }
+
+       public void setAutomationEnabled(boolean automationEnabled) {
+               this.automationEnabled = automationEnabled;
+       }
+
+       /**
+        * Kill OpenOffice
+        */
+       public void kill() {
+               if (SystemUtil.isWindows()) {
+                       SystemUtil.execScript("taskkill /F /IM soffice.bin /IM 
soffice.exe", false);
+               } else {
+                       SystemUtil.execScript("killall -9 soffice soffice.bin", 
false);
+               }
+
+       }
+
+       /**
+        * Start OpenOffice
         * 
+        * @return
+        */
+       public int start() {
+               String cmd = null;
+
+               if (SystemUtil.isWindows()) {
+                       cmd = "\"" + home + "\\soffice.exe\"";
+               } else {
+                       cmd = "cd \"" + home + "\" ; ./soffice";
+               }
+
+               if (automationEnabled) {
+                       cmd += " -norestore -quickstart=no -nofirststartwizard 
-enableautomation -automationport=" + port;
+               }
+
+               if (userInstallation != null) {
+                       try {
+                               String url = 
userInstallation.toURL().toString();
+                               url = url.replace("file:/", "file:///");
+                               cmd += " -env:UserInstallation=" + url;
+                       } catch (MalformedURLException e) {
+                               // ignore never to occur
+                       }
+               }
+
+               if (args != null)
+                       cmd += " " + args;
+
+               return SystemUtil.execScript(cmd, true);
+       }
+
+       /**
+        * Activate the document window at the given index
+        * Note: this method requires automation enabled.
         * @param i
         * @return
         */
        public void activateDoc(int i) {
-               VclHook.invokeCommand(Constant.RC_ActivateDocument,
-                               new Object[] { i + 1 });
+               VclHook.invokeCommand(Constant.RC_ActivateDocument, new 
Object[] { i + 1 });
        }
 
+       /**
+        * Try to close all OpenOffice windows, until startcenter window 
appears.
+        * The method does not always succeed.
+        * Note: this method requires automation enabled.
+        */
        public void reset() {
                VclHook.invokeCommand(Constant.RC_ResetApplication);
        }
 
+       /**
+        * Note: this method requires automation enabled.
+        * @return
+        */
        public boolean existsSysDialog() {
                return (Boolean) 
VclHook.invokeCommand(Constant.RC_ExistsSysDialog);
        }
 
+       /**
+        * Note: this method requires automation enabled.
+        */
        public void closeSysDialog() {
                VclHook.invokeCommand(Constant.RC_CloseSysDialog);
        }
 
+       /**
+        * Note: this method requires automation enabled.
+        * @return
+        */
        public String getClipboard() {
                return (String) VclHook.invokeCommand(Constant.RC_GetClipboard);
        }
 
+       /**
+        * Note: this method requires automation enabled.
+        * @param content
+        */
        public void setClipboard(String content) {
                VclHook.invokeCommand(Constant.RC_SetClipboard, content);
        }
 
+       /**
+        * Check if OpenOffice exists.
+        * Note: this method requires automation enabled.
+        * @return
+        */
        public boolean exists() {
                return VclHook.available();
        }
 
        /**
         * Check if the control exists in a period of time
+        * Note: this method requires automation enabled.
         */
        public boolean exists(double iTimeout) {
                return exists(iTimeout, 1);
@@ -145,6 +264,7 @@ public class VclApp {
 
        /**
         * Check if the control exists in a period of time
+        * Note: this method requires automation enabled.
         */
        public boolean exists(double iTimeout, double interval) {
                long startTime = System.currentTimeMillis();
@@ -157,6 +277,13 @@ public class VclApp {
                return exists();
        }
 
+       /**
+        * Wait OpenOffice for existence in the given period.
+        * When time is out, an runtime exception will be thrown.
+        * Note: this method requires automation enabled.
+        * @param iTimeout
+        * @param interval
+        */
        public void waitForExistence(double iTimeout, double interval) {
                if (!exists(iTimeout, interval))
                        throw new RuntimeException("OpenOffice is not found!");
@@ -164,28 +291,34 @@ public class VclApp {
 
        /**
         * Get document window count
-        * 
+        * Note: this method requires automation enabled.
         * @return
         */
        public int getDocCount() {
                return (Integer) 
VclHook.invokeCommand(Constant.RC_GetDocumentCount);
        }
-       
-       public Properties getVersion() {
-               if (version == null)
-                       version = FileUtil.loadProperties(home + "/" + 
versionFile);
-               return version;
-       }
-       
-       
+
+       /**
+        * Run a dispatch
+        * Note: this method requires automation enabled.
+        * @param url
+        */
        public void dispatch(String url) {
                VclHook.invokeUNOSlot(url);
        }
-       
+
        private static final int CONST_WSTimeout = 701;
-//     private static final int CONST_WSAborted = 702; // Not used now!
-//     private static final int CONST_WSFinished = 703; //
-       
+
+       // private static final int CONST_WSAborted = 702; // Not used now!
+       // private static final int CONST_WSFinished = 703; //
+
+       /**
+        * Run a dispatch and then wait some time.
+        * If time is out, an runtime exception will be thrown
+        * Note: this method requires automation enabled.
+        * @param url
+        * @param time timeout
+        */
        public void dispatch(String url, double time) {
                VclHook.invokeUNOSlot(url);
                int result = (Integer) 
VclHook.invokeCommand(Constant.RC_WaitSlot, (int) time * 1000);

Modified: incubator/ooo/trunk/main/test/testoo/build.xml
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testoo/build.xml?rev=1357090&r1=1357089&r2=1357090&view=diff
==============================================================================
--- incubator/ooo/trunk/main/test/testoo/build.xml (original)
+++ incubator/ooo/trunk/main/test/testoo/build.xml Wed Jul  4 06:02:29 2012
@@ -39,7 +39,7 @@
        <property name="test.result" value="${test.output}/result" />
        <property name="test.report" value="${test.output}/report" />
        <property name="junit.style.dir" value="./reportstyle" />
-       
+
        <path id="classpath">
                <pathelement location="${classes}" />
                <fileset dir="${lib}" erroronmissingdir="false">
@@ -232,13 +232,24 @@
 
        <target name="report.test" unless="report.test.skip" 
description="Upload the testing result to report repository.">
                <exec executable="hostname" outputproperty="host.name" />
-               <property name="report.to" 
value="${openoffice.build}/${host.name}" />
+               <property name="report.to" 
value="${openoffice.build}_${host.name}" />
+               <!--
                <echo>Sending report to 
${report.repos.server}/${report.repos.dir}/${report.to}</echo>
                <ftp server="${report.repos.server}" 
remotedir="${report.repos.dir}/${report.to}" userid="${report.repos.user}" 
password="${report.repos.password}" action="mkdir" />
                <ftp server="${report.repos.server}" 
remotedir="${report.repos.dir}/${report.to}" userid="${report.repos.user}" 
password="${report.repos.password}" depends="yes">
                        <fileset dir="${test.output}">
                        </fileset>
                </ftp>
+               -->
+               <echo>Uploading report to ${report.repos}/${report.to}</echo>
+               <tempfile property="report.to.temp" suffix=".output" 
destDir="${testspace}" deleteonexit="true"/>
+               <copy todir="${report.to.temp}/${report.to}">
+                       <fileset dir="${test.output}" />
+               </copy>
+
+               <scp todir="${report.repos}">
+                       <fileset dir="${report.to.temp}"/>
+               </scp>
        </target>
 
        <target name="detect.build" depends="find.build" description="Check if 
new build is available. If no new build is available, the target will be 
failed.">

Modified: incubator/ooo/trunk/main/test/testoo/src/testcase/BVTFunction.java
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testoo/src/testcase/BVTFunction.java?rev=1357090&r1=1357089&r2=1357090&view=diff
==============================================================================
--- incubator/ooo/trunk/main/test/testoo/src/testcase/BVTFunction.java 
(original)
+++ incubator/ooo/trunk/main/test/testoo/src/testcase/BVTFunction.java Wed Jul  
4 06:02:29 2012
@@ -60,7 +60,7 @@ public class BVTFunction {
         */
        @Before
        public void setUp() throws Exception {
-               initApp();
+               setUp();
        }
        
        
@@ -113,7 +113,7 @@ public class BVTFunction {
                
                //Create a new text document and launch a Wizards dialog which 
need JVM work correctly.
                startcenter.menuItem("File->New->Text Document").select();
-               File tempfile=new 
File(getUserInstallationDir(),"user/template/myAgendaTemplate.ott");
+               File tempfile=new 
File(app.getUserInstallation(),"user/template/myAgendaTemplate.ott");
                FileUtil.deleteFile(tempfile);
                sleep(3);       
                writer.menuItem("File->Wizards->Agenda").select();
@@ -486,6 +486,294 @@ public class BVTFunction {
                assertArrayEquals("Sorted Data", expected4, 
CalcUtil.getCellTexts("E1:E10"));
        }
        
+       /**
+        * Test insert a chart in a draw document
+        * 1. New a draw document
+        * 2. Insert a chart
+        * 3. Check if the chart is inserted successfully
+        * @throws Exception
+        */
+       @Test
+       public void testInsertChartInDraw() throws Exception{
+               
+               // Create a new drawing document
+               startcenter.menuItem("File->New->Drawing").select();
+               sleep(3);
+               
+               // Insert a chart
+               draw.menuItem("Insert->Chart...").select();
+               sleep(3);
+               
+               // Verify if the chart is inserted successfully
+               assertTrue(chart.exists(3));
+               // Focus on edit pane
+               draw.click(5,5);
+               sleep(1);
+       }
+       
+       /**
+        * Test insert a chart in a text document
+        * 1. New a text document
+        * 2. Insert a chart
+        * 3. Check if the chart is inserted successfully
+        * @throws Exception
+        */
+       @Test
+       public void testInsertChartInDocument() throws Exception{
+               
+               // Create a new text document
+               startcenter.menuItem("File->New->Text Document").select();
+               sleep(3);
+               
+               // Insert a chart
+               writer.menuItem("Insert->Object->Chart...").select();
+               sleep(3);
+               
+               // Verify if the chart is inserted successfully
+               assertTrue(chart.exists(3));
+               // Focus on edit pane
+               writer.click(5,5);
+               sleep(1);
+       }
+       
+       /**
+        * Test insert a chart in a spreadsheet document
+        * 1. New a spreadsheet document
+        * 2. Insert a chart
+        * 3. Check if the chart is inserted successfully
+        * @throws Exception
+        */
+       @Test
+       public void testInsertChartInSpreadsheet() throws Exception{
+               
+               // Create a new spreadsheet document
+               startcenter.menuItem("File->New->Spreadsheet").select();
+               sleep(3);
+               
+               // Insert a chart
+               calc.menuItem("Insert->Chart...").select();
+               sleep(3);
+               Chart_Wizard.ok();
+               
+               // Verify if the chart is inserted successfully
+               assertTrue(chart.exists(3));
+               // Focus on edit pane
+               calc.click(5,5);
+               sleep(1);       
+       }
+       
+       /**
+        * Test insert a chart in a presentation document
+        * 1. New a presentation document
+        * 2. Insert a chart
+        * 3. Check if the chart is inserted successfully
+        * @throws Exception
+        */
+       @Ignore("There is bug in presentation")
+       public void testInsertChartInPresentation() throws Exception{
+               
+               // Create a new presentation document
+               startcenter.menuItem("File->New->Presentation").select();
+               PresentationWizard.ok();
+               sleep(3);
+               
+               // Insert a chart
+               impress.menuItem("Insert->Chart...").select();
+               sleep(3);
+               
+               // Verify if the chart is inserted successfully
+               assertTrue(chart.exists(3));
+               // Focus on edit pane
+               impress.click(5,5);
+               sleep(1);       
+       }
+       
+       /**
+        * Test insert a table in a draw document
+        * 1. New a draw document
+        * 2. Insert a default table
+        * 3. Check if the table is inserted successfully
+        * @throws Exception
+        */
+       @Test
+       public void testInsertTableInDraw() throws Exception{
+               
+               // Create a new drawing document
+               startcenter.menuItem("File->New->Drawing").select();
+               sleep(3);
+               
+               // Insert a table
+               draw.menuItem("Insert->Table...").select();
+               InsertTable.ok();
+               sleep(3);
+               
+               // Verify if the table toolbar is active
+//             assertTrue(Table_Toolbar.exists(3));
+               
+               // Check the statusbar to verify if the table is inserted 
successfully
+               assertEquals("Table selected", StatusBar.getItemText(0));
+               // Focus on edit pane
+               draw.click(5,5);
+               sleep(1);
+       }
+       
+       /**
+        * Test insert a table in a text document
+        * 1. New a text document
+        * 2. Insert a default table
+        * 3. Check if the table is inserted successfully
+        * @throws Exception
+        */
+       @Test
+       public void testInsertTableInDocument() throws Exception{
+               
+               // Create a new text document
+               startcenter.menuItem("File->New->Text Document").select();
+               sleep(3);
+               
+               // Insert a table
+               writer.menuItem("Insert->Table...").select();
+               writer_InsertTable.ok();
+               sleep(3);
+               
+               // Verify if the table toolbar is active
+               assertTrue(Table_Toolbar.exists(3));
+               
+               // Check the statusbar to verify if the table is inserted 
successfully
+               assertEquals("Table1:A1", StatusBar.getItemText(7));
+               // Focus on edit pane
+               writer.click(5,5);
+               sleep(1);
+       }
+       
+       /**
+        * Test insert a table in a presentation document
+        * 1. New a presentation document
+        * 2. Insert a default table
+        * 3. Check if the table is inserted successfully
+        * @throws Exception
+        */
+       @Test
+       public void testInsertTableInPresentation() throws Exception{
+               
+               // Create a new presentation document
+               startcenter.menuItem("File->New->Presentation").select();
+               PresentationWizard.ok();
+               sleep(3);
+               
+               // Insert a table
+               impress.menuItem("Insert->Table...").select();
+               InsertTable.ok();
+               sleep(3);
+               
+               // Verify if the table toolbar is active
+               assertTrue(Table_Toolbar.exists(3));
+               
+               // Check the statusbar to verify if the table is inserted 
successfully
+               assertEquals("Table selected", StatusBar.getItemText(0));
+               // Focus on edit pane
+               impress.click(5,5);
+               sleep(1);
+       }
+       
+
+       /**
+        * Test insert a function in a spreadsheet document via Sum button
+        * 1. New a spreadsheet document
+        * 2. Insert a function via Sum button
+        * 3. Check if the result is correct
+        * @throws Exception
+        */
+       @Test
+       public void testInsertFunctionInSCViaSumButton() throws Exception{
+               
+               // Create a new spreadsheet document
+               startcenter.menuItem("File->New->Spreadsheet").select();
+               sleep(3);
+               
+               // Insert source numbers
+               String sourceNumber1 = "5";
+               String sourceNumber2 = "3";
+               String expectedResult = "8";
+               CalcUtil.selectRange("A1");
+               typeKeys(sourceNumber1);
+               CalcUtil.selectRange("B1");
+               typeKeys(sourceNumber2);                
+               
+               // Insert a function via Sum button
+               CalcUtil.selectRange("C1");
+               SC_InputBar_Sum.click();
+               typeKeys("<enter>");
+               
+               // Verify if the calculated result is equal to the expected 
result
+               assertEquals("The calculated result", expectedResult, 
CalcUtil.getCellText("C1"));
+       }
+       
+       /**
+        * Test insert a function in a spreadsheet document via inputbar
+        * 1. New a spreadsheet document
+        * 2. Insert a function via inputbar: POWER
+        * 3. Check if the result is correct
+        * @throws Exception
+        */
+       @Test
+       public void testInsertFunctionInSCViaInputbar() throws Exception{
+               
+               // Create a new spreadsheet document
+               startcenter.menuItem("File->New->Spreadsheet").select();
+               sleep(3);
+               
+               // Insert source numbers and expected result
+               String sourceBase = "5";
+               String sourcePower = "3";
+               String expectedResult = "125";
+               CalcUtil.selectRange("A1");
+               typeKeys(sourceBase);
+               CalcUtil.selectRange("B1");
+               typeKeys(sourcePower);
+               
+               // Insert a function via inputbar: POWER
+               CalcUtil.selectRange("D1");
+               SC_InputBar_Input.inputKeys("=POWER(A1;B1)");
+               typeKeys("<enter>");
+               
+               // Verify if the calculated result is equal to the expected 
result
+               assertEquals("The calculated result", expectedResult, 
CalcUtil.getCellText("D1"));
+       }
+       
+       /**
+        * Test insert a function in a spreadsheet document via Function Wizard 
Dialog
+        * 1. New a spreadsheet document
+        * 2. Insert a function via Function Wizard Dialog: ABS
+        * 3. Check if the result is correct
+        * @throws Exception
+        */
+       @Test
+       public void testInsertFunctionInSCViaFunctionWizard() throws Exception{
+               
+               // Create a new spreadsheet document
+               startcenter.menuItem("File->New->Spreadsheet").select();
+               sleep(3);
+               
+               // Insert source number
+               String sourceNumber = "-5";
+               String expectedResult = "5";
+               CalcUtil.selectRange("A1");
+               typeKeys(sourceNumber);
+               typeKeys("<enter>");
+               
+               // Insert a function via Function Wizard Dialog: ABS
+               CalcUtil.selectRange("B1");
+               calc.menuItem("Insert->Function...").select();
+               SC_FunctionWizardDlg_FunctionList.doubleClick(5,5);
+
+               SC_FunctionWizardDlg_Edit1.inputKeys("A1");
+               SC_FunctionWizardDlg.ok();
+               
+               // Verify if the calculated result is equal to the expected 
result
+               assertEquals("The calculated result", expectedResult, 
CalcUtil.getCellText("B1"));
+       }
+       
        @AfterClass
        public static void afterClass() {
                app.kill();

Modified: incubator/ooo/trunk/main/test/testoo/src/testcase/SmokeTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testoo/src/testcase/SmokeTest.java?rev=1357090&r1=1357089&r2=1357090&view=diff
==============================================================================
--- incubator/ooo/trunk/main/test/testoo/src/testcase/SmokeTest.java (original)
+++ incubator/ooo/trunk/main/test/testoo/src/testcase/SmokeTest.java Wed Jul  4 
06:02:29 2012
@@ -24,9 +24,9 @@
 package testcase;
 
 import static org.junit.Assert.*;
+import static org.openoffice.test.common.FileUtil.*;
 import static testlib.AppUtil.*;
 import static testlib.UIMap.*;
-import static org.openoffice.test.common.FileUtil.*;
 
 import java.io.File;
 
@@ -35,7 +35,6 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
-import testlib.AppUtil;
 import testlib.Log;
 
 public class SmokeTest {
@@ -46,13 +45,13 @@ public class SmokeTest {
        File smoketestOutput;
        @Before
        public void setUp() throws Exception {
-               initApp();
-               smoketestOutput = new File(AppUtil.getUserInstallationDir(), 
"user/temp");
+               initApp(true);
+               smoketestOutput = new File(app.getUserInstallation(), 
"user/temp");
                deleteFile(smoketestOutput);
        }
 
        @Test
-       public void test() {
+       public void testMacro() {
                testFile("TestExtension.oxt");
                String file = testFile("smoketestdoc.sxw");
                // Open sample file smoketestdoc.sxw

Modified: incubator/ooo/trunk/main/test/testoo/src/testlib/AppUtil.java
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testoo/src/testlib/AppUtil.java?rev=1357090&r1=1357089&r2=1357090&view=diff
==============================================================================
--- incubator/ooo/trunk/main/test/testoo/src/testlib/AppUtil.java (original)
+++ incubator/ooo/trunk/main/test/testoo/src/testlib/AppUtil.java Wed Jul  4 
06:02:29 2012
@@ -24,9 +24,7 @@
 package testlib;
 import static testlib.UIMap.*;
 
-
 import java.io.File;
-import java.net.MalformedURLException;
 
 import org.openoffice.test.common.Condition;
 import org.openoffice.test.common.FileUtil;
@@ -35,8 +33,6 @@ import org.openoffice.test.vcl.Tester;
 import org.openoffice.test.vcl.widgets.VclWindow;
 
 public class AppUtil extends Tester {
-       static String user_installation = Testspace.getPath("oouser"); // Use 
automation special user data
-       static String user_installation_url = null;
        static {
                Testspace.getFile("temp").mkdirs();
                // TODO move these shortcut into a file
@@ -60,62 +56,58 @@ public class AppUtil extends Tester {
                } else if (SystemUtil.isLinux()) {
                        
                } 
-               patch();
+//             patch();
        }
        
-       private static boolean isFirstInitApp = true;
-       
-       public static void initApp() {
-               
-               // kill all soffice processes to avoid testing the wrong 
instance
-               if (isFirstInitApp) {
-                       isFirstInitApp = false;
+       /**
+        * This method is used to start OpenOffice and make it ready for 
testing.
+        * 
+        * @param cleanUserInstallation if use a totally clean user 
installation data
+        * @param userInstallation Specify user installation directory. If it's 
null, the default will be used.
+        */
+       public static void initApp(boolean cleanUserInstallation, String 
userInstallation) {
+               File newUserInstallation = userInstallation == null ? 
app.getDefaultUserInstallation() : new File(fullPath(userInstallation));
+               if (!newUserInstallation.equals(app.getUserInstallation())) {
+                       // user installation changed...
                        app.kill();
-                       sleep(2);
+                       app.setUserInstallation(userInstallation == null ? null 
: newUserInstallation);
                }
                
-               // Start soffice if necessary
-               if (!app.exists()) {
-                       int code = app.start("\"-env:UserInstallation=" + 
user_installation_url + "\"");
-                       if (code != 0) {
-                               throw new Error("OpenOffice can't be started! 
Testing aborted!");
-                       }
-                       sleep(3); // this sleep is important. 
-                       app.waitForExistence(30, 5);
-               }
+               patch(cleanUserInstallation);
                
-               boolean tryAgain = false;
-               try {
-                       app.reset();
-                       if (!startcenter.exists()) {
-                               if (SystemUtil.isMac()) {
-                                       SystemUtil.execScript("osascript -e 
'tell app \"OpenOffice.org\" to activate'", false);
-                                       typeKeys("<command n>");
-                                       if (!startcenter.exists())
-                                               tryAgain = true;
-                                               
-                               } else {
-                                       tryAgain = true;
+               //try to reset application
+               for (int i = 0; i < 3; i++) {
+                       try {
+                               if (app.exists()) {
+                                       app.reset();
+                                       openStartcenter();
+                                       if (startcenter.exists(2))
+                                               return;
                                }
+                       } catch (Exception e){
+                               
                        }
-               } catch (Exception e) {
-                       tryAgain = true;
-               }
-               
-               // Give the second chance
-               if (tryAgain) {
+                       
                        app.kill();
-                       sleep(2);
-                       int code = app.start("\"-env:UserInstallation=" + 
user_installation_url + "\"");
-                       if (code != 0) {
+                       if (app.start() != 0)
                                throw new Error("OpenOffice can't be started! 
Testing aborted!");
-                       }
                        sleep(3); // this sleep is important. 
                        app.waitForExistence(30, 5);
-                       app.reset();
                }
-               
-               openStartcenter();
+       }
+
+       /**
+        * @see initApp(boolean cleanUserInstallation, String userInstallation)
+        */
+       public static void initApp(boolean cleanUserInstallation) {
+               initApp(cleanUserInstallation, 
System.getProperty("openoffice.userinstallation"));
+       }
+       
+       /**
+        * @see initApp(boolean cleanUserInstallation, String userInstallation)
+        */
+       public static void initApp() {
+               initApp(false);
        }
        
        public static void openStartcenter() {
@@ -199,51 +191,30 @@ public class AppUtil extends Tester {
                sleep(1);
        }
        
-       public static File getUserInstallationDir() {
-               return new File(user_installation);
-       }
        /**
         * In order to automatically test OO, some settings/files need to be 
modified
         */
-       public static void patch() {            
-               File profileDir = new File(user_installation);
-               try {
-                       user_installation_url = profileDir.toURL().toString();
-               } catch (MalformedURLException e) {
-                       //ignore never to occur
-               }
-               user_installation_url = user_installation_url.replace("file:/", 
"file:///");
-               if (profileDir.exists()) 
+       public static void patch(boolean force) {
+               File userInstallationDir = app.getUserInstallation();
+               File patchMark = new File(userInstallationDir, 
"automationenabled");
+               if (!force && patchMark.exists())
                        return;
-               
-               app.kill(); // make sure no any soffice process exists
-               sleep(2);
-               app.start("\"-env:UserInstallation=" + user_installation_url + 
"\"");
+       
+               // remove user installation dir
+               app.kill();
+               sleep(1);               
+               FileUtil.deleteFile(userInstallationDir);
+               app.start();
                sleep(10);
                app.kill();
-               sleep(2);
-               FileUtil.copyFile(new File("patch/Common.xcu"), new 
File(user_installation, "user/registry/data/org/openoffice/Office/Common.xcu"));
-               FileUtil.copyFile(new File("patch/Setup.xcu"), new 
File(user_installation, "user/registry/data/org/openoffice/Setup.xcu"));
-               FileUtil.copyFile(new File("patch/registrymodifications.xml"), 
new File(user_installation, "user/registrymodifications.xcu"));
+               sleep(1);
                
+               FileUtil.copyFile(new File("patch/Common.xcu"), new 
File(userInstallationDir, 
"user/registry/data/org/openoffice/Office/Common.xcu"));
+               FileUtil.copyFile(new File("patch/Setup.xcu"), new 
File(userInstallationDir, "user/registry/data/org/openoffice/Setup.xcu"));
+               FileUtil.copyFile(new File("patch/registrymodifications.xml"), 
new File(userInstallationDir, "user/registrymodifications.xcu"));
+               FileUtil.writeStringToFile(patchMark.getAbsolutePath(), 
"patched for automation");
        }
        
-//     private static final Pattern VARIABLE_PATTERN = 
Pattern.compile("\\$\\{([^\\}]+)\\} | \\$([^/]+)");
-//     
-//     public static String resolveEnv(String text) {
-//             Matcher matcher = VARIABLE_PATTERN.matcher(text);
-//             StringBuffer result = new StringBuffer();
-//             while (matcher.find()) {
-//                     String str = System.getenv(matcher.group(1));
-//                     if (str == null)
-//                             str = matcher.group();
-//                     matcher.appendReplacement(result, str.replace("\\", 
"\\\\")
-//                                     .replace("$", "\\$"));
-//             }
-//             matcher.appendTail(result);
-//             return result.toString();
-//     }
-       
        public static void handleBlocker(final VclWindow... windows) {
                new Condition() {
                        @Override
@@ -287,8 +258,4 @@ public class AppUtil extends Tester {
                        
                }.waitForTrue("Time out wait window to be active.",  120, 2);
        }
-       
-       public static void main(String[] args) {
-//             initApp();
-       }
 }

Modified: incubator/ooo/trunk/main/test/testoo/src/testlib/UIMap.java
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testoo/src/testlib/UIMap.java?rev=1357090&r1=1357089&r2=1357090&view=diff
==============================================================================
--- incubator/ooo/trunk/main/test/testoo/src/testlib/UIMap.java (original)
+++ incubator/ooo/trunk/main/test/testoo/src/testlib/UIMap.java Wed Jul  4 
06:02:29 2012
@@ -113,7 +113,7 @@ public class UIMap {
                return new VclDockingWin(idList.getId(id));
        }
        
-       public static final VclApp app = new VclApp();
+       public static final VclApp app = new VclApp(null);
        public static final VclWindow writer = window("SW_HID_EDIT_WIN");
        public static final VclWindow startcenter = 
window("FWK_HID_BACKINGWINDOW");
        public static final VclWindow calc = window("SC_HID_SC_WIN_GRIDWIN");

Modified: incubator/ooo/trunk/main/test/testoo/src/testsuite/BVT.java
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testoo/src/testsuite/BVT.java?rev=1357090&r1=1357089&r2=1357090&view=diff
==============================================================================
--- incubator/ooo/trunk/main/test/testoo/src/testsuite/BVT.java (original)
+++ incubator/ooo/trunk/main/test/testoo/src/testsuite/BVT.java Wed Jul  4 
06:02:29 2012
@@ -29,11 +29,10 @@ import org.junit.runners.Suite.SuiteClas
 
 import testcase.BVTFileType;
 import testcase.BVTFunction;
-import testcase.BVTFunction2;
 import testcase.SmokeTest;
 
 @RunWith(Suite.class)
-@SuiteClasses({SmokeTest.class, BVTFileType.class, BVTFunction.class, 
BVTFunction2.class })
+@SuiteClasses({SmokeTest.class, BVTFileType.class, BVTFunction.class})
 public class BVT {
 
 }


Reply via email to