diff options
author | Lars Langhans <lla@openoffice.org> | 2010-07-01 10:26:00 +0200 |
---|---|---|
committer | Lars Langhans <lla@openoffice.org> | 2010-07-01 10:26:00 +0200 |
commit | 977267816232b602b174c19c0944de0a4715302f (patch) | |
tree | 4b5667edd88e703a18f4fa67d5e610a940d65d28 /filter/qa | |
parent | 50dcf3ec33ebc67cf35652d1b76819433455ac95 (diff) |
sb123:#i111449# cleanups in filter for qa/complex tests
Diffstat (limited to 'filter/qa')
-rw-r--r-- | filter/qa/complex/filter/misc/FinalizedMandatoryTest.java | 217 | ||||
-rw-r--r-- | filter/qa/complex/filter/misc/TypeDetection6FileFormat.java | 93 | ||||
-rwxr-xr-x | filter/qa/complex/filter/misc/makefile.mk | 80 |
3 files changed, 227 insertions, 163 deletions
diff --git a/filter/qa/complex/filter/misc/FinalizedMandatoryTest.java b/filter/qa/complex/filter/misc/FinalizedMandatoryTest.java index e32b81caa85b..a269afec836d 100644 --- a/filter/qa/complex/filter/misc/FinalizedMandatoryTest.java +++ b/filter/qa/complex/filter/misc/FinalizedMandatoryTest.java @@ -24,7 +24,6 @@ * for a copy of the LGPLv3 License. * ************************************************************************/ - package complex.filter.misc; import com.sun.star.beans.PropertyValue; @@ -39,10 +38,18 @@ import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XInterface; import com.sun.star.util.XFlushable; -import complexlib.ComplexTestCase; -import util.utils; - - +// import complexlib.ComplexTestCase; +// import util.utils; + +// ---------- junit imports ----------------- +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openoffice.test.OfficeConnection; +import static org.junit.Assert.*; +// ------------------------------------------ /** * This complex test checks the functionality of the properties "Finalized" and "Mandatory" of @@ -74,7 +81,8 @@ import util.utils; * <CODE>Mandatory=true</CODE> * <CODE>Mandatory=false</CODE> */ -public class FinalizedMandatoryTest extends ComplexTestCase { +public class FinalizedMandatoryTest +{ static XMultiServiceFactory xMSF; @@ -82,21 +90,21 @@ public class FinalizedMandatoryTest extends ComplexTestCase { * A function to tell the framework, which test functions are available. * @return All test methods. */ - public String[] getTestMethodNames() { - return new String[]{"checkReadonlySupportFilterFactory", - "checkReadonlySupportTypeDetection"}; - } - +// public String[] getTestMethodNames() { +// return new String[]{"checkReadonlySupportFilterFactory", +// "checkReadonlySupportTypeDetection"}; +// } /** Create the environment for following tests. * Use either a component loader from desktop or * from frame * @throws Exception Exception */ - public void before() throws Exception { + @Before public void before() throws Exception + { // create TypeDetection - xMSF = (XMultiServiceFactory)param.getMSF(); - assure("Could not get XMultiServiceFactory", xMSF != null); + xMSF = getMSF(); + assertNotNull("Could not get XMultiServiceFactory", xMSF); } @@ -106,14 +114,16 @@ public class FinalizedMandatoryTest extends ComplexTestCase { * @throws Exception was thrown if creataion failes * @return <CODE>XInterface</CODE> of service */ - public XInterface getTestObject(String serviceName) throws Exception{ + private XInterface getTestObject(String serviceName) throws Exception + { Object oInterface = xMSF.createInstance(serviceName); - if (oInterface == null) { - failed("Service wasn't created") ; - throw new Exception("could not create service '"+serviceName+"'"); - } + assertNotNull("Service wan't created", oInterface); +// if (oInterface == null) { +// failed("Service wasn't created") ; +// throw new Exception("could not create service '"+serviceName+"'"); +// } return (XInterface) oInterface; } @@ -121,7 +131,8 @@ public class FinalizedMandatoryTest extends ComplexTestCase { * call the function <CODE>checkReadonlySupport</CODE> to test <CODE>com.sun.star.document.FilterFactory</CODE> * @see com.sun.star.document.FilterFactory */ - public void checkReadonlySupportFilterFactory(){ + @Test public void checkReadonlySupportFilterFactory() + { checkReadonlySupport("com.sun.star.document.FilterFactory"); } @@ -129,26 +140,30 @@ public class FinalizedMandatoryTest extends ComplexTestCase { * call the function <CODE>checkReadonlySupport</CODE> to test <CODE>com.sun.star.document.TypeDetection</CODE> * @see com.sun.star.document.TypeDetection */ - public void checkReadonlySupportTypeDetection(){ + @Test public void checkReadonlySupportTypeDetection() + { checkReadonlySupport("com.sun.star.document.TypeDetection"); } - /** * test the given service <CODE>serviceName</CODE>. * For every filter a new instace was created and the tests started. * @param serviceName the name of the service to test */ - private void checkReadonlySupport(String serviceName){ - log.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); - log.println("testing service '" + serviceName + "'"); + private void checkReadonlySupport(String serviceName) + { + System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); + System.out.println("testing service '" + serviceName + "'"); XInterface oObj = null; - try{ + try + { oObj = getTestObject(serviceName); - log.println("ImplName: "+utils.getImplName(oObj)); - } catch (java.lang.Exception e){ - failed("could not get test object"); + System.out.println("ImplName: " + util.utils.getImplName(oObj)); + } + catch (java.lang.Exception e) + { + fail("could not get test object"); } boolean mandantoryTrue = false; @@ -157,19 +172,21 @@ public class FinalizedMandatoryTest extends ComplexTestCase { boolean finalizedFalse = false; - XNameAccess xNA = (XNameAccess) UnoRuntime.queryInterface - (XNameAccess.class, oObj); + XNameAccess xNA = UnoRuntime.queryInterface(XNameAccess.class, oObj); String[] filterNames = xNA.getElementNames(); // XNameContainer; XNameReplace String filterName = filterNames[0]; - Object[] instance = null;; - for (int i = 0; i < filterNames.length; i++) { - log.println("------------------------------------------------"); - try{ + Object[] instance = null; + + for (int i = 0; i < filterNames.length; i++) + { + System.out.println("------------------------------------------------"); + try + { PropertyValue instanceProp = new PropertyValue(); filterName = filterNames[i]; - log.println(filterName); + System.out.println(filterName); // testobject must new created for every test. // We change in a loop the container and try to flush this changes. @@ -177,16 +194,19 @@ public class FinalizedMandatoryTest extends ComplexTestCase { // similar to a document which could not be saved beacuse of invalid // contend. While you don't remove the invalid conted you will never // be able to save the document. Same here. - try{ + try + { oObj = getTestObject(serviceName); - } catch (java.lang.Exception e){ - failed("could not get test object", CONTINUE); + } + catch (java.lang.Exception e) + { + fail("could not get test object"); } - xNA = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, oObj); - XNameContainer xNC = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, oObj); - XNameReplace xNR = (XNameReplace) UnoRuntime.queryInterface(XNameReplace.class, oObj); - XFlushable xFlush = (XFlushable) UnoRuntime.queryInterface(XFlushable.class, oObj); + xNA = UnoRuntime.queryInterface(XNameAccess.class, oObj); + XNameContainer xNC = UnoRuntime.queryInterface(XNameContainer.class, oObj); + XNameReplace xNR = UnoRuntime.queryInterface(XNameReplace.class, oObj); + XFlushable xFlush = UnoRuntime.queryInterface(XFlushable.class, oObj); instance = (Object[]) xNA.getByName(filterName); PropertyValue[] props = (PropertyValue[]) instance; @@ -204,59 +224,75 @@ public class FinalizedMandatoryTest extends ComplexTestCase { finalizedFalse |= !isFinalized; //change the filter - setPropertyValueValue((PropertyValue[])instance, "UIName", "dummy"); + setPropertyValueValue((PropertyValue[]) instance, "UIName", "dummy"); // 1a.) try to change the filter in the container - try{ + try + { xNR.replaceByName(filterName, instance); - }catch (IllegalArgumentException e){ - failed("could not replace filter properties ('" + filterName + "')", CONTINUE); + } + catch (IllegalArgumentException e) + { + fail("could not replace filter properties ('" + filterName + "')"); } // 1b.) try to wirte the changed filter to the configuration. // This must result in a exception if the filter is finalized. boolean flushError = false; - try{ + try + { xFlush.flush(); - } catch (WrappedTargetRuntimeException e){ + } + catch (WrappedTargetRuntimeException e) + { flushError = true; - assure("Unexpected exception wihle flushing changed filter '"+ filterName + "'", isFinalized,CONTINUE); + assertTrue("Unexpected exception wihle flushing changed filter '" + filterName + "'", isFinalized); } - assure("Expected exception was not thorwn while flushing changed filter '"+ filterName + "' Finalized:" + isFinalized, - !(flushError ^ isFinalized), CONTINUE); + assertTrue("Expected exception was not thorwn while flushing changed filter '" + filterName + "' Finalized:" + isFinalized, + !(flushError ^ isFinalized)); // 2a.) try to remove the filter from the container - try{ + try + { xNC.removeByName(filterName); - }catch (NoSuchElementException e){ - failed("could not remove filter from container ('" + filterName + "')", CONTINUE); + } + catch (NoSuchElementException e) + { + fail("could not remove filter from container ('" + filterName + "')"); } // 1b.) try to wirte the changed filter to the configuration. // This must result in a exception if the filter is mandatory flushError = false; - try{ + try + { xFlush.flush(); - } catch (WrappedTargetRuntimeException e){ + } + catch (WrappedTargetRuntimeException e) + { flushError = true; - assure("Unexpected exception wihle flushing removed filter '"+ filterName + "'", isMandatory,CONTINUE); + assertTrue("Unexpected exception wihle flushing removed filter '" + filterName + "'", isMandatory); } - assure("Expected exception was not thorwn while flushing removed filter '"+ filterName + "' Mandatory:" + isMandatory, - !(flushError ^ isMandatory), CONTINUE); + assertTrue("Expected exception was not thorwn while flushing removed filter '" + filterName + "' Mandatory:" + isMandatory, + !(flushError ^ isMandatory)); - } catch (NoSuchElementException e){ - failed("Couldn't get elements from object", true); - } catch (WrappedTargetException e){ - failed("Couldn't get elements from object", true); + } + catch (NoSuchElementException e) + { + fail("Couldn't get elements from object"); + } + catch (WrappedTargetException e) + { + fail("Couldn't get elements from object"); } } String preMsg = "Could not find filter with state "; String postMsg = " Please check if such filter is installed!"; - assure(preMsg + "'Mandatory=true'" + postMsg ,mandantoryTrue, CONTINUE); - assure(preMsg + "'Mandatory=false'" + postMsg ,mandantoryFalse, CONTINUE); - assure(preMsg + "'Finalized=true'" + postMsg ,finalizedTrue, CONTINUE); - assure(preMsg + "'Finalized=false'" + postMsg ,finalizedFalse, CONTINUE); + assertTrue(preMsg + "'Mandatory=true'" + postMsg, mandantoryTrue); + assertTrue(preMsg + "'Mandatory=false'" + postMsg, mandantoryFalse); + assertTrue(preMsg + "'Finalized=true'" + postMsg, finalizedTrue); + assertTrue(preMsg + "'Finalized=false'" + postMsg, finalizedFalse); } /** @@ -265,13 +301,18 @@ public class FinalizedMandatoryTest extends ComplexTestCase { * @see com.sun.star.beans.PropertyValue * @param props Sequenze of PropertyValue */ - protected void printPropertyValues(PropertyValue[] props) { + protected void printPropertyValues(PropertyValue[] props) + { int i = 0; - while (i < props.length ) { - log.println(props[i].Name + ":" + props[i].Value.toString()); + while (i < props.length) + { + System.out.println(props[i].Name + ":" + props[i].Value.toString()); i++; } - if (i < props.length) log.println(props[i].Name + ":" + props[i].Value.toString()); + if (i < props.length) + { + System.out.println(props[i].Name + ":" + props[i].Value.toString()); + } } /** @@ -280,9 +321,11 @@ public class FinalizedMandatoryTest extends ComplexTestCase { * @param pName the name of the property the value shoud be returned * @return the value of the property */ - protected Object getPropertyValueValue(PropertyValue[] props, String pName) { + protected Object getPropertyValueValue(PropertyValue[] props, String pName) + { int i = 0; - while (i < props.length && !props[i].Name.equals(pName)) { + while (i < props.length && !props[i].Name.equals(pName)) + { i++; } return i < props.length ? props[i].Value : null; @@ -294,14 +337,36 @@ public class FinalizedMandatoryTest extends ComplexTestCase { * @param pName name of the property which should be changed * @param pValue the value the property should be assigned */ - protected void setPropertyValueValue(PropertyValue[] props, String pName, Object pValue) { + protected void setPropertyValueValue(PropertyValue[] props, String pName, Object pValue) + { int i = 0; - while (i < props.length && !props[i].Name.equals(pName)) { + while (i < props.length && !props[i].Name.equals(pName)) + { i++; } props[i].Value = pValue; } + private XMultiServiceFactory getMSF() + { + final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); + return xMSF1; + } + // setup and close connections + @BeforeClass + public static void setUpConnection() throws Exception + { + System.out.println("setUpConnection()"); + connection.setUp(); + } + @AfterClass + public static void tearDownConnection() + throws InterruptedException, com.sun.star.uno.Exception + { + System.out.println("tearDownConnection()"); + connection.tearDown(); + } + private static final OfficeConnection connection = new OfficeConnection(); } diff --git a/filter/qa/complex/filter/misc/TypeDetection6FileFormat.java b/filter/qa/complex/filter/misc/TypeDetection6FileFormat.java index 842a365d4714..6fda574ae8f5 100644 --- a/filter/qa/complex/filter/misc/TypeDetection6FileFormat.java +++ b/filter/qa/complex/filter/misc/TypeDetection6FileFormat.java @@ -3,21 +3,31 @@ * * Created on 26. April 2004, 10:37 */ - package complex.filter.misc; import com.sun.star.container.XNameAccess; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XInterface; -import complexlib.ComplexTestCase; + import util.utils; +// ---------- junit imports ----------------- +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openoffice.test.OfficeConnection; +import static org.junit.Assert.*; +// ------------------------------------------ + /** * * @author cn93815 */ -public class TypeDetection6FileFormat extends ComplexTestCase { +public class TypeDetection6FileFormat +{ static XMultiServiceFactory xMSF; @@ -25,20 +35,20 @@ public class TypeDetection6FileFormat extends ComplexTestCase { * A function to tell the framework, which test functions are available. * @return All test methods. */ - public String[] getTestMethodNames() { - return new String[]{"checkFilterFactory", - "checkTypeDetection"}; - } - +// public String[] getTestMethodNames() { +// return new String[]{"checkFilterFactory", +// "checkTypeDetection"}; +// } /** Create the environment for following tests. * Use either a component loader from desktop or * from frame * @throws Exception Exception */ - public void before() throws Exception { + @Before public void before() throws Exception + { - xMSF = (XMultiServiceFactory)param.getMSF(); - assure("Could not get XMultiServiceFactory", xMSF != null); + xMSF = getMSF(); + assertNotNull("Could not get XMultiServiceFactory", xMSF); } @@ -46,7 +56,8 @@ public class TypeDetection6FileFormat extends ComplexTestCase { * call the function <CODE>checkFileFormatSupport</CODE> to test <CODE>com.sun.star.document.FilterFactory</CODE> * @see com.sun.star.document.FilterFactory */ - public void checkFilterFactory(){ + @Test public void checkFilterFactory() + { checkFileFormatSupport("com.sun.star.document.FilterFactory"); } @@ -54,7 +65,8 @@ public class TypeDetection6FileFormat extends ComplexTestCase { * call the function <CODE>checkFileFormatSupport</CODE> to test <CODE>com.sun.star.document.TypeDetection</CODE> * @see com.sun.star.document.TypeDetection */ - public void checkTypeDetection(){ + @Test public void checkTypeDetection() + { checkFileFormatSupport("com.sun.star.document.TypeDetection"); } @@ -64,42 +76,67 @@ public class TypeDetection6FileFormat extends ComplexTestCase { * The serve was created and the filter 'TypeDetection6FileFormat' was searched * @param serviceName the name of the service to test */ - private void checkFileFormatSupport(String serviceName){ - log.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); - log.println("testing service '" + serviceName + "'"); + private void checkFileFormatSupport(String serviceName) + { + System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); + System.out.println("testing service '" + serviceName + "'"); XInterface oObj = null; - try{ + try + { oObj = getTestObject(serviceName); - log.println("ImplName: "+utils.getImplName(oObj)); - } catch (java.lang.Exception e){ - failed("could not get test object"); + System.out.println("ImplName: " + utils.getImplName(oObj)); + } + catch (java.lang.Exception e) + { + fail("could not get test object"); } - XNameAccess xNA = (XNameAccess) UnoRuntime.queryInterface - (XNameAccess.class, oObj); + XNameAccess xNA = UnoRuntime.queryInterface(XNameAccess.class, oObj); String msg = "Could not find filter 'TypeDetection6FileFormat'!"; msg += "\nMaybe 'TypeDetection6FileFormat.xcu' is not registered."; - assure(msg, xNA.hasByName("TypeDetection6FileFormat"),CONTINUE); + assertTrue(msg, xNA.hasByName("TypeDetection6FileFormat")); } - /** + /** * Creates an instance for the given <CODE>serviceName</CODE> * @param serviceName the name of the service which should be created * @throws Exception was thrown if creataion failes * @return <CODE>XInterface</CODE> of service */ - public XInterface getTestObject(String serviceName) throws Exception{ + public XInterface getTestObject(String serviceName) throws Exception + { Object oInterface = xMSF.createInstance(serviceName); - if (oInterface == null) { - failed("Service wasn't created") ; - throw new Exception("could not create service '"+serviceName+"'"); + if (oInterface == null) + { + fail("Service wasn't created"); + throw new Exception("could not create service '" + serviceName + "'"); } return (XInterface) oInterface; } + private XMultiServiceFactory getMSF() + { + final XMultiServiceFactory xMSF1 = UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager()); + return xMSF1; + } + + // setup and close connections + @BeforeClass public static void setUpConnection() throws Exception { + System.out.println("setUpConnection()"); + connection.setUp(); + } + + @AfterClass public static void tearDownConnection() + throws InterruptedException, com.sun.star.uno.Exception + { + System.out.println("tearDownConnection()"); + connection.tearDown(); + } + + private static final OfficeConnection connection = new OfficeConnection(); } diff --git a/filter/qa/complex/filter/misc/makefile.mk b/filter/qa/complex/filter/misc/makefile.mk index 2792b2438b6e..5ac072a2e071 100755 --- a/filter/qa/complex/filter/misc/makefile.mk +++ b/filter/qa/complex/filter/misc/makefile.mk @@ -25,73 +25,35 @@ # #************************************************************************* -PRJ = ..$/..$/..$/.. -PRJNAME = filter -TARGET = Filter -PACKAGE = complex$/filter$/misc - -# --- Settings ----------------------------------------------------- -.INCLUDE: settings.mk - - -#----- compile .java files ----------------------------------------- - -JARFILES = mysql.jar ridl.jar unoil.jar jurt.jar juh.jar java_uno.jar OOoRunner.jar -JAVAFILES = FinalizedMandatoryTest.java TypeDetection6FileFormat.java -JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) - -#----- make a jar from compiled files ------------------------------ - -MAXLINELENGTH = 100000 - -JARCLASSDIRS = $(PACKAGE) -JARTARGET = $(TARGET).jar -JARCOMPRESS = TRUE - -# --- Parameters for the test -------------------------------------- - -# start an office if the parameter is set for the makefile -.IF "$(OFFICE)" == "" -CT_APPEXECCOMMAND = +.IF "$(OOO_SUBSEQUENT_TESTS)" == "" +nothing .PHONY: .ELSE -CT_APPEXECCOMMAND = -AppExecutionCommand \ - "$(OFFICE)$/soffice -accept=socket,host=localhost,port=8100;urp;" -.ENDIF - -# test base is java complex -CT_TESTBASE = -TestBase java_complex - -# replace $/ with . in package name -CT_PACKAGE = -o $(PACKAGE:s\$/\.\) - -# start the runner application -CT_APP = org.openoffice.Runner +PRJ = ../../../.. +PRJNAME = filter +TARGET = qa_complex_filter_misc -# --- Targets ------------------------------------------------------ +.IF "$(OOO_JUNIT_JAR)" != "" +PACKAGE = complex/filter/misc +JAVATESTFILES = \ + TypeDetection6FileFormat.java \ + FinalizedMandatoryTest.java -.IF "$(depend)" == "" -DisplayHint : ALLTAR -.ELSE -DisplayHint : ALLDEP -.ENDIF +JAVAFILES = $(JAVATESTFILES) -.INCLUDE : target.mk +JARFILES = OOoRunner.jar ridl.jar test.jar unoil.jar jurt.jar +EXTRAJARFILES = $(OOO_JUNIT_JAR) +.END -DisplayHint: - @echo "\ntype 'dmake FinalizedMandatoryTest'" - @echo "\ntype 'dmake TypeDetection6FileFormat'" - @echo "! BE SHURE YOU HAVE 'TypeDetection6FileFormat.xcu' SUCCESSFUL REGISTERED IN YOU OFFICE !" +# Sample how to debug +# JAVAIFLAGS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=9003,suspend=y -RUN: run +.INCLUDE: settings.mk +.INCLUDE: target.mk +.INCLUDE: installationtest.mk -run: \ - DisplayHint +ALLTAR : javatest +.END -FinalizedMandatoryTest: - java -cp $(CLASSPATH) $(CT_APP) $(CT_TESTBASE) $(CT_APPEXECCOMMAND) $(CT_PACKAGE).FinalizedMandatoryTest - -TypeDetection6FileFormat: - java -cp $(CLASSPATH) $(CT_APP) $(CT_TESTBASE) $(CT_APPEXECCOMMAND) $(CT_PACKAGE).TypeDetection6FileFormat |