Language

The Free and Open Productivity Suite
Released: Apache OpenOffice 4.1.15

About Complex-testcases

The structure of the complex tests is quite straightforward. You only have to inherit from a base class, called ComplexTestCase (complexlib.ComplexTestCase) and implement two methods:

The first method has to return all available test methods, while the second should return a sensible name of the object, functionality or combination thereof that is tested.

You may implement two more methods:

The methods are not mandatory and do not have to be implemented if they are not needed. As suggested by their names, before() is called before all other test methods, after() when all the test methods did finish.

Note:

As a general rule, the result of a test is “ok”. There are two functions available to change this:

The OOoRunner that will execute your complex test provides you also with additional helpers and utilities. (See OOoRunner reference for details.) Before your test starts, the OOoRunner will connect or start StarOffice and provide a logging mechanism.

You can reach the office in your test with the test parameters, represented by the variable param. With param.getMSF() you can get a MultiServiceFactory from the office and build your test from there.

The logging is available with the variable log, which offers a println(String message) method so the test run can be monitored.


Sample Complex Test

To illustrate the mechanisms and helpers, a simple commented complex test “for beginners” is listed:

// package name: as default, start with complex
package complex.sample;
// imports import complexlib.ComplexTestCase; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.uno.XInterface; import com.sun.star.beans.PropertyValue; import com.sun.star.container.XIndexContainer; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.Type; import java.io.PrintWriter; /** * The following Complex Test will test the * com.sun.star.document.IndexedPropertyValues * service */ public class CheckIndexedPropertyValues extends ComplexTestCase { // The name of the tested service private final String testedServiceName = "com.sun.star.document.IndexedPropertyValues"; // The first of the mandatory functions: /** * Return the name of the test. * In this case it is the actual name of the service. * @return The tested service. */ public String getTestObjectName() { return testedServiceName; } // The second of the mandatory functions: return all test methods as an // array. There is only one test function in this example. /** * Return all test methods. * @return The test methods. */ public String[] getTestMethodNames() { return new String[]{"checkIndexedPropertyValues"}; } // This test is fairly simple, so there is no need for before() or after() // methods. // The test method itself. /* * Test the com.sun.star.document.IndexedPropertyValues service. * Strategy: create the service, check if it is initially empty, * add and exchange some content. */ public void checkIndexedPropertyValues() { // A test object Object oObj = null; try { // Get the MultiServiceFactory. XMultiServiceFactory xMSF = (XMultiServiceFactory)param.getMSF(); // Create an instance of the service. oObj = xMSF.createInstance(testedServiceName); // Print debug information about the service. // The dbg class of the OOoRunner is used. System.out.println("****************"); System.out.println("Service Name:"); util.dbg.getSuppServices(oObj); System.out.println("****************"); System.out.println("Interfaces:"); util.dbg.printInterfaces((XInterface)oObj, true); System.out.println("****************"); } catch(com.sun.star.uno.Exception e) { // Give some information where the exception happened. // This is information that maybe should be kept, so // the log.println(); method is used. log.println("Cannot create object: '" + testedServiceName + "'"); e.printStackTrace((PrintWriter)log); // After this exception the test has failed and cannot continue. failed(e.getMessage()); return; } // Query for the interface we would like to test. XIndexContainer xCont = (XIndexContainer)UnoRuntime.queryInterface( XIndexContainer.class, oObj); // Assure that the query worked. assure("XIndexContainer was queried but returned null.", xCont != null); // Construct some property values. PropertyValue[] prop1 = new PropertyValue[1]; prop1[0] = new PropertyValue(); prop1[0].Name = "Jupp"; prop1[0].Value = "GoodGuy"; PropertyValue[] prop2 = new PropertyValue[1]; prop2[0] = new PropertyValue(); prop2[0].Name = "Horst"; prop2[0].Value = "BadGuy"; // Really start to test. try { Type t = xCont.getElementType(); log.println("Insertable Type: "+ t.getTypeName()); // Make sure that the container is empty after creation assure("Initial container is not empty: " + xCont.getCount(), xCont.getCount()==0); log.println("Inserting a PropertyValue."); xCont.insertByIndex(0, prop1); PropertyValue[]ret = (PropertyValue[])xCont.getByIndex(0); // Compare the returned value with the original. assure("Got the wrong PropertyValue: " + ret[0].Name + " " +(String)ret[0].Value, ret[0].Name.equals(prop1[0].Name)&& ret[0].Value.equals(prop1[0].Value)); log.println("Replace the PropertyValue."); xCont.replaceByIndex(0, prop2); ret = (PropertyValue[])xCont.getByIndex(0); // Compare the returned value with the original. assure("Got the wrong PropertyValue: " + ret[0].Name + " " +(String)ret[0].Value, ret[0].Name.equals(prop2[0].Name)&& ret[0].Value.equals(prop2[0].Value)); log.println("Remove the PropertyValue."); xCont.removeByIndex(0); // Container has to be empty again. assure("Could not remove PropertyValue.", !xCont.hasElements()&& xCont.getCount()==0); } catch(com.sun.star.lang.IllegalArgumentException e) { failed(e.getMessage()); e.printStackTrace((PrintWriter)log); } catch(com.sun.star.lang.IndexOutOfBoundsException e) { failed(e.getMessage()); e.printStackTrace((PrintWriter)log); } catch(com.sun.star.lang.WrappedTargetException e) { failed(e.getMessage()); e.printStackTrace((PrintWriter)log); } } }


Start The Complex Tests

The complex tests can be started similar to the other tests of the OOoRunner. You have to give a test-base for the complex tests, since as default the test-base for java fat-office tests is used. This can either be done with a “-tb java_complex” in the command-line call of the runner or with a “TestBase=java_complex” if you use an ini-file. Confer the General User Guide for more details on this.

The test has to be given with a full qualified class name. For the sample test above the call would be:

java org.openoffice.Runner -tb java_complex -o complex.sample.CheckIndexedPropertyValues


1 Normally it would have been assert(String message, boolean condition), but assert is a keyword in Java 1.4 and thus forbidden to use.


Last change: $Date: 2004/03/10 15:58:37 $

Apache Software Foundation

Copyright & License | Privacy | Contact Us | Donate | Thanks

Apache, OpenOffice, OpenOffice.org and the seagull logo are registered trademarks of The Apache Software Foundation. The Apache feather logo is a trademark of The Apache Software Foundation. Other names appearing on the site may be trademarks of their respective owners.