Kaydet (Commit) 275f0c7b authored tarafından Noel Grandin's avatar Noel Grandin Kaydeden (comit) Noel Grandin

Let JUnit take care of exceptions

Inspired by commit
4dd0ac62

Change-Id: I6ca29aecde357a3cb5852acfc9b5443761052960
Reviewed-on: https://gerrit.libreoffice.org/16094Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
üst 9eb1bfcb
......@@ -19,37 +19,25 @@ package complex.dbaccess;
import com.sun.star.sdb.XSingleSelectQueryComposer;
import connectivity.tools.CRMDatabase;
import java.util.logging.Level;
import java.util.logging.Logger;
// ---------- junit imports -----------------
import org.junit.After;
import org.junit.Before;
import static org.junit.Assert.*;
public abstract class CRMBasedTestCase extends TestCase
{
protected CRMDatabase m_database;
protected void createTestCase()
protected void createTestCase() throws Exception
{
try
{
m_database = new CRMDatabase( getMSF(), false );
}
catch ( Exception e )
{
e.printStackTrace( System.err );
fail( "caught an exception (" + e.getMessage() + ") while creating the test case");
}
m_database = new CRMDatabase( getMSF(), false );
}
@Before
@Override
public void before()
public void before() throws Exception
{
createTestCase();
}
......@@ -57,18 +45,11 @@ public abstract class CRMBasedTestCase extends TestCase
@After
@Override
public void after()
public void after() throws Exception
{
try
{
if ( m_database != null )
{
m_database.saveAndClose();
}
}
catch ( Exception ex )
if ( m_database != null )
{
Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, null, ex );
m_database.saveAndClose();
}
}
......
......@@ -30,7 +30,6 @@ import com.sun.star.sdb.DataAccessDescriptorFactory;
import com.sun.star.sdbc.XConnection;
import com.sun.star.sdbcx.XTablesSupplier;
import com.sun.star.task.XInteractionHandler;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import connectivity.tools.DbaseDatabase;
......@@ -41,7 +40,6 @@ import util.UITools;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
/** complex test case for Base's application UI
......@@ -55,7 +53,7 @@ public class CopyTableWizard extends CRMBasedTestCase
@After
@Override
public void after()
public void after() throws Exception
{
dest.store();
if ( destinationDB != null )
......@@ -66,19 +64,12 @@ public class CopyTableWizard extends CRMBasedTestCase
@Before
@Override
public void before()
public void before() throws Exception
{
try
{
createTestCase();
source = new DatabaseApplication(m_database.getDatabase());
destinationDB = new DbaseDatabase( getMSF() );
dest = new DatabaseApplication( destinationDB );
}
catch (java.lang.Exception ex)
{
fail("");
}
createTestCase();
source = new DatabaseApplication(m_database.getDatabase());
destinationDB = new DbaseDatabase( getMSF() );
dest = new DatabaseApplication( destinationDB );
}
......
......@@ -18,7 +18,6 @@
package complex.dbaccess;
import com.sun.star.container.XNameAccess;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XNamingService;
import connectivity.tools.CRMDatabase;
......@@ -37,51 +36,33 @@ public class DataSource extends TestCase
connectivity.tools.DataSource m_dataSource;
private void createTestCase()
private void createTestCase() throws Exception
{
try
if (m_database == null)
{
if (m_database == null)
{
final CRMDatabase database = new CRMDatabase( getMSF(), false );
m_database = database.getDatabase();
m_dataSource = m_database.getDataSource();
}
}
catch (Exception e)
{
fail("could not create the test case, error message:\n" + e.getMessage());
}
catch (java.lang.Exception e)
{
fail("could not create the test case, error message:\n" + e.getMessage());
final CRMDatabase database = new CRMDatabase( getMSF(), false );
m_database = database.getDatabase();
m_dataSource = m_database.getDataSource();
}
}
@Test
public void testRegistrationName()
public void testRegistrationName() throws Exception
{
try
{
createTestCase();
// 1. check the existing "Bibliography" data source whether it has the proper name
String dataSourceName = "Bibliography";
final connectivity.tools.DataSource bibliography = new connectivity.tools.DataSource(getMSF(), dataSourceName);
assertEquals("pre-registered database has a wrong name!", dataSourceName, bibliography.getName());
// 2. register a newly created data source, and verify it has the proper name
dataSourceName = "someDataSource";
final XNamingService dataSourceRegistrations = UnoRuntime.queryInterface(
XNamingService.class, getMSF().createInstance( "com.sun.star.sdb.DatabaseContext" ) );
final XNameAccess existenceCheck = UnoRuntime.queryInterface( XNameAccess.class, dataSourceRegistrations );
if ( existenceCheck.hasByName( "someDataSource" ) )
dataSourceRegistrations.revokeObject( "someDataSource" );
dataSourceRegistrations.registerObject("someDataSource", m_dataSource.getXDataSource());
assertEquals("registration name of a newly registered data source is wrong", dataSourceName, m_dataSource.getName());
}
catch (Exception ex)
{
fail();
}
createTestCase();
// 1. check the existing "Bibliography" data source whether it has the proper name
String dataSourceName = "Bibliography";
final connectivity.tools.DataSource bibliography = new connectivity.tools.DataSource(getMSF(), dataSourceName);
assertEquals("pre-registered database has a wrong name!", dataSourceName, bibliography.getName());
// 2. register a newly created data source, and verify it has the proper name
dataSourceName = "someDataSource";
final XNamingService dataSourceRegistrations = UnoRuntime.queryInterface(
XNamingService.class, getMSF().createInstance( "com.sun.star.sdb.DatabaseContext" ) );
final XNameAccess existenceCheck = UnoRuntime.queryInterface( XNameAccess.class, dataSourceRegistrations );
if ( existenceCheck.hasByName( "someDataSource" ) )
dataSourceRegistrations.revokeObject( "someDataSource" );
dataSourceRegistrations.registerObject("someDataSource", m_dataSource.getXDataSource());
assertEquals("registration name of a newly registered data source is wrong", dataSourceName, m_dataSource.getName());
}
}
......@@ -23,7 +23,6 @@ import com.sun.star.sdb.XParametersSupplier;
import com.sun.star.sdb.XSingleSelectQueryComposer;
import com.sun.star.sdbc.DataType;
import com.sun.star.sdbc.SQLException;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime;
......@@ -36,18 +35,10 @@ public class Parser extends CRMBasedTestCase
{
@Override
protected void createTestCase()
protected void createTestCase() throws Exception
{
try
{
super.createTestCase();
m_database.getDatabase().getDataSource().createQuery( "query products", "SELECT * FROM \"products\"" );
}
catch ( Exception e )
{
e.printStackTrace( System.err );
fail( "caught an exception (" + e.getMessage() + ") while creating the test case");
}
super.createTestCase();
m_database.getDatabase().getDataSource().createQuery( "query products", "SELECT * FROM \"products\"" );
}
......
......@@ -55,7 +55,7 @@ public class PropertyBag extends TestCase
}
@Test
public void checkBasics()
public void checkBasics() throws Exception
{
createEmptyBag();
System.out.println("testing the basics");
......@@ -115,19 +115,12 @@ public class PropertyBag extends TestCase
}
// try writing and reading a value for the one property we have so far
try
{
final String testValue = "someArbitraryValue";
m_set.setPropertyValue( VALUE , testValue);
final String currentValue = (String)m_set.getPropertyValue( VALUE);
if ( !currentValue.equals( testValue ) )
{
fail("set property is not remembered");
}
}
catch(com.sun.star.uno.Exception e)
final String testValue = "someArbitraryValue";
m_set.setPropertyValue( VALUE , testValue);
final String currentValue = (String)m_set.getPropertyValue( VALUE);
if ( !currentValue.equals( testValue ) )
{
fail( "setting or getting a property value failed" );
fail("set property is not remembered");
}
// try setting an illegal value for the property
......
......@@ -44,17 +44,15 @@ public class TypeDetection6FileFormat
*/
@Before public void before() throws Exception
{
xMSF = getMSF();
assertNotNull("Could not get XMultiServiceFactory", xMSF);
}
/**
* call the function <CODE>checkFileFormatSupport</CODE> to test <CODE>com.sun.star.document.FilterFactory</CODE>
* @see com.sun.star.document.FilterFactory
*/
@Test public void checkFilterFactory()
@Test public void checkFilterFactory() throws Exception
{
checkFileFormatSupport("com.sun.star.document.FilterFactory");
}
......@@ -63,10 +61,9 @@ public class TypeDetection6FileFormat
* call the function <CODE>checkFileFormatSupport</CODE> to test <CODE>com.sun.star.document.TypeDetection</CODE>
* @see com.sun.star.document.TypeDetection
*/
@Test public void checkTypeDetection()
@Test public void checkTypeDetection() throws Exception
{
checkFileFormatSupport("com.sun.star.document.TypeDetection");
}
/**
......@@ -74,27 +71,18 @@ public class TypeDetection6FileFormat
* The serve was created and the filter 'TypeDetection6FileFormat' was searched
* @param serviceName the name of the service to test
*/
private void checkFileFormatSupport(String serviceName)
private void checkFileFormatSupport(String serviceName) throws Exception
{
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("testing service '" + serviceName + "'");
XInterface oObj = null;
try
{
oObj = getTestObject(serviceName);
System.out.println("ImplName: " + utils.getImplName(oObj));
}
catch (java.lang.Exception e)
{
fail("could not get test object");
}
oObj = getTestObject(serviceName);
System.out.println("ImplName: " + utils.getImplName(oObj));
XNameAccess xNA = UnoRuntime.queryInterface(XNameAccess.class, oObj);
String msg = "Could not find filter 'TypeDetection6FileFormat'!";
msg += "\nMaybe 'TypeDetection6FileFormat.xcu' is not registered.";
assertTrue(msg, xNA.hasByName("TypeDetection6FileFormat"));
}
/**
......
......@@ -18,7 +18,6 @@
package complex.forms;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
......@@ -43,7 +42,6 @@ import com.sun.star.lang.EventObject;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.util.CloseVetoException;
import com.sun.star.util.XCloseable;
/**
......@@ -54,42 +52,28 @@ public class CheckOGroupBoxModel
private XMultiPropertySet m_xPropSet;
private XComponent m_xDrawDoc;
@Before public void before()
@Before public void before() throws Exception
{
SOfficeFactory SOF = SOfficeFactory.getFactory(getMSF());
try
{
System.out.println("creating a draw document");
m_xDrawDoc = SOF.createDrawDoc(null);
}
catch (com.sun.star.uno.Exception e)
{
fail("Couldn't create document.");
}
System.out.println("creating a draw document");
m_xDrawDoc = SOF.createDrawDoc(null);
String objName = "GroupBox";
XControlShape shape = FormTools.insertControlShape(m_xDrawDoc, 5000, 7000, 2000, 2000, objName);
m_xPropSet = UnoRuntime.queryInterface(XMultiPropertySet.class, shape.getControl());
}
@After public void after()
@After public void after() throws Exception
{
XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, m_xDrawDoc);
if (xClose != null)
{
try
{
xClose.close(true);
}
catch (CloseVetoException ex)
{
fail("Can't close document. Exception caught: " + ex.getMessage());
/* ignore! */
}
xClose.close(true);
}
}
@Test public void setPropertyValues()
@Test public void setPropertyValues() throws Exception
{
String[] boundPropsToTest = getBoundPropsToTest();
......@@ -103,22 +87,7 @@ public class CheckOGroupBoxModel
{
newValue[i] = ValueChanger.changePValue(gValues[i]);
}
try
{
m_xPropSet.setPropertyValues(boundPropsToTest, newValue);
}
catch (com.sun.star.beans.PropertyVetoException e)
{
fail("Exception occurred while trying to change the properties.");
}
catch (com.sun.star.lang.IllegalArgumentException e)
{
fail("Exception occurred while trying to change the properties.");
}
catch (com.sun.star.lang.WrappedTargetException e)
{
fail("Exception occurred while trying to change the properties.");
} // end of try-catch
m_xPropSet.setPropertyValues(boundPropsToTest, newValue);
assertTrue("Listener was not called.", ml.wasListenerCalled());
m_xPropSet.removePropertiesChangeListener(ml);
......
......@@ -31,7 +31,6 @@ import com.sun.star.beans.XPropertySet;
import com.sun.star.drawing.XShape;
import com.sun.star.frame.XFrame;
import com.sun.star.frame.XModel;
import com.sun.star.lang.IndexOutOfBoundsException;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.ui.XContextMenuInterception;
import com.sun.star.ui.XContextMenuInterceptor;
......@@ -79,7 +78,7 @@ public class CheckContextMenuInterceptor
}
@After
public void after()
public void after() throws Exception
{
System.out.println("release the popup menu");
try
......@@ -98,116 +97,97 @@ public class CheckContextMenuInterceptor
XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, xFrame);
try
{
xClose.close(true);
}
catch (com.sun.star.util.CloseVetoException exVeto)
{
fail("Test frame couldn't be closed successfully.");
}
xClose.close(true);
xFrame = null;
}
@Test
public void checkContextMenuInterceptor()
public void checkContextMenuInterceptor() throws Exception
{
System.out.println(" **** Context Menu Interceptor *** ");
try
{
// intialize the test document
xDrawDoc = DrawTools.createDrawDoc(xMSF);
// intialize the test document
xDrawDoc = DrawTools.createDrawDoc(xMSF);
SOfficeFactory SOF = SOfficeFactory.getFactory(xMSF);
XShape oShape = SOF.createShape(xDrawDoc, 5000, 5000, 1500, 1000, "GraphicObject");
DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc, 0)).add(oShape);
SOfficeFactory SOF = SOfficeFactory.getFactory(xMSF);
XShape oShape = SOF.createShape(xDrawDoc, 5000, 5000, 1500, 1000, "GraphicObject");
DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc, 0)).add(oShape);
com.sun.star.frame.XModel xModel =
UnoRuntime.queryInterface(com.sun.star.frame.XModel.class, xDrawDoc);
com.sun.star.frame.XModel xModel =
UnoRuntime.queryInterface(com.sun.star.frame.XModel.class, xDrawDoc);
// get the frame for later usage
xFrame = xModel.getCurrentController().getFrame();
// get the frame for later usage
xFrame = xModel.getCurrentController().getFrame();
// ensure that the document content is optimal visible
DesktopTools.zoomToEntirePage(xDrawDoc);
// ensure that the document content is optimal visible
DesktopTools.zoomToEntirePage(xDrawDoc);
XBitmap xBitmap = null;
XBitmap xBitmap = null;
// adding graphic as ObjRelation for GraphicObjectShape
XPropertySet oShapeProps = UnoRuntime.queryInterface(XPropertySet.class, oShape);
System.out.println("Inserting a shape into the document");
// adding graphic as ObjRelation for GraphicObjectShape
XPropertySet oShapeProps = UnoRuntime.queryInterface(XPropertySet.class, oShape);
System.out.println("Inserting a shape into the document");
try
{
String sFile = OfficeFileUrl.getAbsolute(new File("space-metal.jpg"));
oShapeProps.setPropertyValue("GraphicURL", sFile);
Object oProp = oShapeProps.getPropertyValue("GraphicObjectFillBitmap");
xBitmap = (XBitmap) AnyConverter.toObject(new Type(XBitmap.class), oProp);
}
catch (com.sun.star.lang.WrappedTargetException e)
{
}
catch (com.sun.star.lang.IllegalArgumentException e)
{
}
catch (com.sun.star.beans.PropertyVetoException e)
{
}
catch (com.sun.star.beans.UnknownPropertyException e)
{
}
try
{
String sFile = OfficeFileUrl.getAbsolute(new File("space-metal.jpg"));
oShapeProps.setPropertyValue("GraphicURL", sFile);
Object oProp = oShapeProps.getPropertyValue("GraphicObjectFillBitmap");
xBitmap = (XBitmap) AnyConverter.toObject(new Type(XBitmap.class), oProp);
}
catch (com.sun.star.lang.WrappedTargetException e)
{
}
catch (com.sun.star.lang.IllegalArgumentException e)
{
}
catch (com.sun.star.beans.PropertyVetoException e)
{
}
catch (com.sun.star.beans.UnknownPropertyException e)
{
}
// reuse the frame
com.sun.star.frame.XController xController = xFrame.getController();
XContextMenuInterception xContextMenuInterception = null;
XContextMenuInterceptor xContextMenuInterceptor = null;
// reuse the frame
com.sun.star.frame.XController xController = xFrame.getController();
XContextMenuInterception xContextMenuInterception = null;
XContextMenuInterceptor xContextMenuInterceptor = null;
if (xController != null)
{
System.out.println("Creating context menu interceptor");
if (xController != null)
{
System.out.println("Creating context menu interceptor");
// add our context menu interceptor
xContextMenuInterception =
UnoRuntime.queryInterface(XContextMenuInterception.class, xController);
// add our context menu interceptor
xContextMenuInterception =
UnoRuntime.queryInterface(XContextMenuInterception.class, xController);
if (xContextMenuInterception != null)
{
ContextMenuInterceptor aContextMenuInterceptor = new ContextMenuInterceptor(xBitmap);
xContextMenuInterceptor =
UnoRuntime.queryInterface(XContextMenuInterceptor.class, aContextMenuInterceptor);
if (xContextMenuInterception != null)
{
ContextMenuInterceptor aContextMenuInterceptor = new ContextMenuInterceptor(xBitmap);
xContextMenuInterceptor =
UnoRuntime.queryInterface(XContextMenuInterceptor.class, aContextMenuInterceptor);
System.out.println("Register context menu interceptor");
xContextMenuInterception.registerContextMenuInterceptor(xContextMenuInterceptor);
}
System.out.println("Register context menu interceptor");
xContextMenuInterception.registerContextMenuInterceptor(xContextMenuInterceptor);
}
}
openContextMenu(UnoRuntime.queryInterface(XModel.class, xDrawDoc));
openContextMenu(UnoRuntime.queryInterface(XModel.class, xDrawDoc));
checkHelpEntry();
checkHelpEntry();
// remove our context menu interceptor
if (xContextMenuInterception != null
&& xContextMenuInterceptor != null)
{
System.out.println("Release context menu interceptor");
xContextMenuInterception.releaseContextMenuInterceptor(
xContextMenuInterceptor);
}
}
catch (com.sun.star.uno.RuntimeException ex)
// remove our context menu interceptor
if (xContextMenuInterception != null
&& xContextMenuInterceptor != null)
{
fail("Runtime exception caught!" + ex.getMessage());
}
catch (java.lang.Exception ex)
{
fail("Java lang exception caught!" + ex.getMessage());
System.out.println("Release context menu interceptor");
xContextMenuInterception.releaseContextMenuInterceptor(
xContextMenuInterceptor);
}
}
private void checkHelpEntry()
private void checkHelpEntry() throws Exception
{
XInterface toolkit = null;
......@@ -240,24 +220,14 @@ public class CheckContextMenuInterceptor
System.out.println("ImplementationName: " + util.utils.getImplName(oPopMenu));
XAccessible xHelp = null;
try
{
System.out.println("Try to get first entry of context menu...");
xHelp = oPopMenu.getAccessibleChild(0);
}
catch (IndexOutOfBoundsException e)
{
fail("Not possible to get first entry of context menu");
}
System.out.println("Try to get first entry of context menu...");
xHelp = oPopMenu.getAccessibleChild(0);
if (xHelp == null)
{
fail("first entry of context menu is NULL");
}
XAccessibleContext xHelpCont = xHelp.getAccessibleContext();
if (xHelpCont == null)
{
fail("No able to retrieve accessible context from first entry of context menu");
......@@ -270,16 +240,8 @@ public class CheckContextMenuInterceptor
fail("First entry of context menu is not from context menu interceptor");
}
try
{
System.out.println("try to get first children of Help context...");
xHelpCont.getAccessibleChild(0);
}
catch (IndexOutOfBoundsException e)
{
fail("not possible to get first children of Help context");
}
System.out.println("try to get first children of Help context...");
xHelpCont.getAccessibleChild(0);
}
private void openContextMenu(XModel aModel)
......
......@@ -25,7 +25,6 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openoffice.test.OfficeConnection;
import static org.junit.Assert.*;
/**
......@@ -36,19 +35,12 @@ import static org.junit.Assert.*;
public class GetServiceWhileDisposingOffice
{
@Test public void checkServiceWhileDisposing()
@Test public void checkServiceWhileDisposing() throws Exception
{
XMultiServiceFactory xMSF = getMSF();
XDesktop xDesktop = null;
try
{
xDesktop = UnoRuntime.queryInterface(XDesktop.class, xMSF.createInstance("com.sun.star.frame.Desktop"));
}
catch (com.sun.star.uno.Exception e)
{
fail("Could not create a desktop instance.");
}
xDesktop = UnoRuntime.queryInterface(XDesktop.class, xMSF.createInstance("com.sun.star.frame.Desktop"));
int step = 0;
try
{
......@@ -63,11 +55,6 @@ public class GetServiceWhileDisposingOffice
{
System.out.println("DisposedException in step: " + step);
}
catch (Exception e)
{
fail(e.getMessage());
}
}
......
......@@ -114,33 +114,18 @@ public class CheckXComponentLoader
@descr Use either a component loader from desktop or
from frame
*/
@Before public void before()
@Before public void before() throws Exception
{
// get uno service manager from global test environment
/* points to the global uno service manager. */
XMultiServiceFactory xMSF = getMSF();
// create stream provider
try
{
m_xStreamProvider = UnoRuntime.queryInterface(XSimpleFileAccess.class, xMSF.createInstance("com.sun.star.ucb.SimpleFileAccess"));
}
catch(java.lang.Throwable ex)
{
fail("Could not create a stream provider instance.");
}
m_xStreamProvider = UnoRuntime.queryInterface(XSimpleFileAccess.class, xMSF.createInstance("com.sun.star.ucb.SimpleFileAccess"));
// create desktop instance
/* provides XComponentLoader interface. */
XFrame xDesktop = null;
try
{
xDesktop = UnoRuntime.queryInterface(XFrame.class, xMSF.createInstance("com.sun.star.frame.Desktop"));
}
catch(java.lang.Throwable ex)
{
fail("Could not create the desktop instance.");
}
XFrame xDesktop = UnoRuntime.queryInterface(XFrame.class, xMSF.createInstance("com.sun.star.frame.Desktop"));
// create frame instance
m_xFrame = xDesktop.findFrame("testFrame_componentLoader",
......@@ -162,49 +147,37 @@ public class CheckXComponentLoader
m_lTestFiles = new ArrayList<String>();
final String sTestDocURL = OfficeFileUrl.getAbsolute(new File("testdocuments"));
m_sTestDocPath = graphical.FileHelper.getSystemPathFromFileURL(sTestDocURL);
try
File aBaseDir = new File(m_sTestDocPath);
List<File> lDirContent = URLHelper.getSystemFilesFromDir(aBaseDir.getPath());
Iterator<File> lList = lDirContent.iterator();
int nBasePathLength = m_sTestDocPath.length();
while(lList.hasNext())
{
File aBaseDir = new File(m_sTestDocPath);
List<File> lDirContent = URLHelper.getSystemFilesFromDir(aBaseDir.getPath());
Iterator<File> lList = lDirContent.iterator();
int nBasePathLength = m_sTestDocPath.length();
while(lList.hasNext())
{
File aFile = lList.next();
File aFile = lList.next();
// ignore broken links and directories at all
if (
(!aFile.exists()) ||
(!aFile.isFile())
)
{
continue;
}
// ignore broken links and directories at all
if (
(!aFile.exists()) ||
(!aFile.isFile())
)
{
continue;
}
String sCompletePath = aFile.getAbsolutePath();
String sSubPath = sCompletePath.substring(nBasePathLength);
String sCompletePath = aFile.getAbsolutePath();
String sSubPath = sCompletePath.substring(nBasePathLength);
m_lTestFiles.add(sSubPath);
}
}
catch(java.lang.Throwable ex)
{
fail("Couldn't find test documents.");
m_lTestFiles.add(sSubPath);
}
}
/** @short close the environment.
*/
@After public void after()
@After public void after() throws Exception
{
XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, m_xFrame);
try
{
xClose.close(false);
}
catch(com.sun.star.util.CloseVetoException exVeto)
{ fail("Test frame couldn't be closed successfully."); }
xClose.close(false);
m_xFrame = null;
m_xLoader = null;
......@@ -281,7 +254,7 @@ public class CheckXComponentLoader
String sSourceURL,
String sTargetURL,
String sFilter ,
String sPassword )
String sPassword ) throws Exception
{
PropertyValue[] lLoadProps = new PropertyValue[1];
......@@ -304,24 +277,17 @@ public class CheckXComponentLoader
lSaveProps[2].Value = Boolean.TRUE;
XComponent xDoc = null;
try
{
// load it
xDoc = xLoader.loadComponentFromURL(sSourceURL, "_blank", 0, lLoadProps);
assertNotNull("Could create office document, which should be saved as temp one.", xDoc);
// load it
xDoc = xLoader.loadComponentFromURL(sSourceURL, "_blank", 0, lLoadProps);
assertNotNull("Could create office document, which should be saved as temp one.", xDoc);
// save it as temp file
XStorable xStore = UnoRuntime.queryInterface(XStorable.class, xDoc);
xStore.storeAsURL(sTargetURL, lSaveProps);
// save it as temp file
XStorable xStore = UnoRuntime.queryInterface(XStorable.class, xDoc);
xStore.storeAsURL(sTargetURL, lSaveProps);
// Dont forget to close this file. Otherwise the temp file is locked!
XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, xDoc);
xClose.close(false);
}
catch(java.lang.Throwable ex)
{
fail("Could not create temp office document.");
}
// Dont forget to close this file. Otherwise the temp file is locked!
XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, xDoc);
xClose.close(false);
}
......@@ -331,7 +297,7 @@ public class CheckXComponentLoader
as password for the ftp connection,
or - if none given a default one.
*/
@Test public void checkLoadingWithPassword()
@Test public void checkLoadingWithPassword() throws Exception
{
String sTempFile = impl_getTempFileName(m_sTempPath, SUFFIX_PASSWORD_TEMPFILE, PREFIX_PASSWORD_TEMPFILE);
File aTestFile = new File(sTempFile);
......@@ -363,7 +329,7 @@ public class CheckXComponentLoader
* Check URL encoding. The first filename that matches "*.sxw"
* is used as source for several encodings.
*/
@Test public void checkURLEncoding() {
@Test public void checkURLEncoding() throws Exception {
PropertyValue[] lProps = new PropertyValue[1];
lProps[0] = new PropertyValue();
......@@ -409,28 +375,23 @@ public class CheckXComponentLoader
};
for (int i = 0; i < sEncoding.length; i = i + 2) {
try {
String encURL = new String(baURL, sEncoding[i]);
System.out.println("ENC[" + sEncoding[i] + "]");
if (sEncoding[i + 1].equals("TRUE")) {
loadURL(m_xLoader, RESULT_VALID_DOC, encURL, "_blank", 0,
lProps);
} else {
//with cws_loadenv01 changed to IllegalArgumentException
loadURL(m_xLoader, RESULT_ILLEGALARGUMENTEXCEPTION, encURL, "_blank", 0,
lProps);
}
} catch (java.io.UnsupportedEncodingException e) {
fail("Unsopported Encoding: " + sEncoding[i] +
"\n Not able to test encoding on this platform.");
String encURL = new String(baURL, sEncoding[i]);
System.out.println("ENC[" + sEncoding[i] + "]");
if (sEncoding[i + 1].equals("TRUE")) {
loadURL(m_xLoader, RESULT_VALID_DOC, encURL, "_blank", 0,
lProps);
} else {
//with cws_loadenv01 changed to IllegalArgumentException
loadURL(m_xLoader, RESULT_ILLEGALARGUMENTEXCEPTION, encURL, "_blank", 0,
lProps);
}
}
}
/** TODo document me
*/
@Test public void checkStreamLoading()
@Test public void checkStreamLoading() throws Exception
{
PropertyValue[] lProps = new PropertyValue[2];
......@@ -447,19 +408,12 @@ public class CheckXComponentLoader
File aFile = new File(m_sTestDocPath, aSnapshot.next());
String sURL = URLHelper.getFileURLFromSystemPath(aFile);
try
{
XInputStream xStream = m_xStreamProvider.openFileRead(sURL);
lProps[1].Value = xStream;
}
catch(com.sun.star.uno.Exception e)
{
fail("Could not open test file \""+sURL+"\" for stream test.");
}
XInputStream xStream = m_xStreamProvider.openFileRead(sURL);
lProps[1].Value = xStream;
// check different version of "private:stream" URL!
loadURL(m_xLoader, RESULT_VALID_DOC, "private:stream" , "_blank", 0, lProps);
}
}
}
/**
......
......@@ -95,7 +95,7 @@ public class PathSettingsTest
* This methods sets the 'aPathSettings' and 'xPropertyInfoOfPathSettings' variables.
*/
@Before
public void before()
public void before() throws Exception
{
try
{
......@@ -127,10 +127,6 @@ public class PathSettingsTest
System.out.println(e.getClass().getName());
System.out.println("Message: " + e.getMessage());
}
catch (Exception e)
{
fail("What exception?");
}
}
private String convertToString(Object o)
......
......@@ -74,18 +74,11 @@ public class UnitConversion
*/
private void checkSize(com.sun.star.awt.Size _aSize, short _aMeasureUnit, String _sEinheit)
{
try
{
com.sun.star.awt.Size aSizeIn = m_xConversion.convertSizeToLogic(_aSize, _aMeasureUnit);
System.out.println("Window size:");
System.out.println("Width:" + aSizeIn.Width + " " + _sEinheit);
System.out.println("Height:" + aSizeIn.Height + " " + _sEinheit);
System.out.println("");
}
catch (com.sun.star.lang.IllegalArgumentException e)
{
System.out.println("Caught IllegalArgumentException in convertSizeToLogic with '" + _sEinheit + "' " + e.getMessage());
}
com.sun.star.awt.Size aSizeIn = m_xConversion.convertSizeToLogic(_aSize, _aMeasureUnit);
System.out.println("Window size:");
System.out.println("Width:" + aSizeIn.Width + " " + _sEinheit);
System.out.println("Height:" + aSizeIn.Height + " " + _sEinheit);
System.out.println("");
}
/**
......@@ -139,77 +132,56 @@ public class UnitConversion
m_xConversion = UnoRuntime.queryInterface(XUnitConversion.class, xWindowPeer);
// try to get the position of the window in 1/100mm with the XUnitConversion method
try
{
com.sun.star.awt.Point aPointInMM_100TH = m_xConversion.convertPointToLogic(aPoint, com.sun.star.util.MeasureUnit.MM_100TH);
System.out.println("Window position:");
System.out.println("X:" + aPointInMM_100TH.X + " 1/100mm");
System.out.println("Y:" + aPointInMM_100TH.Y + " 1/100mm");
System.out.println("");
}
catch (com.sun.star.lang.IllegalArgumentException e)
{
fail("failed: IllegalArgumentException caught in convertPointToLogic " + e.getMessage());
}
com.sun.star.awt.Point aPointInMM_100TH = m_xConversion.convertPointToLogic(aPoint, com.sun.star.util.MeasureUnit.MM_100TH);
System.out.println("Window position:");
System.out.println("X:" + aPointInMM_100TH.X + " 1/100mm");
System.out.println("Y:" + aPointInMM_100TH.Y + " 1/100mm");
System.out.println("");
// try to get the size of the window in 1/100mm with the XUnitConversion method
com.sun.star.awt.Size aSizeInMM_100TH = null;
com.sun.star.awt.Size aSizeInMM_10TH = null;
try
{
aSizeInMM_100TH = m_xConversion.convertSizeToLogic(aSize, com.sun.star.util.MeasureUnit.MM_100TH);
System.out.println("Window size:");
System.out.println("Width:" + aSizeInMM_100TH.Width + " 1/100mm");
System.out.println("Height:" + aSizeInMM_100TH.Height + " 1/100mm");
System.out.println("");
// try to get the size of the window in 1/10mm with the XUnitConversion method
aSizeInMM_10TH = m_xConversion.convertSizeToLogic(aSize, com.sun.star.util.MeasureUnit.MM_10TH);
System.out.println("Window size:");
System.out.println("Width:" + aSizeInMM_10TH.Width + " 1/10mm");
System.out.println("Height:" + aSizeInMM_10TH.Height + " 1/10mm");
System.out.println("");
// check the size with a delta which must be smaller a given difference
assertTrue("Size.Width not correct", delta(aSizeInMM_100TH.Width, aSizeInMM_10TH.Width * 10) < 10);
assertTrue("Size.Height not correct", delta(aSizeInMM_100TH.Height, aSizeInMM_10TH.Height * 10) < 10);
// new
checkSize(aSize, com.sun.star.util.MeasureUnit.PIXEL, "pixel");
checkSize(aSize, com.sun.star.util.MeasureUnit.APPFONT, "appfont");
checkSize(aSize, com.sun.star.util.MeasureUnit.SYSFONT, "sysfont");
// simply check some more parameters
checkSize(aSize, com.sun.star.util.MeasureUnit.MM, "mm");
checkSize(aSize, com.sun.star.util.MeasureUnit.CM, "cm");
checkSize(aSize, com.sun.star.util.MeasureUnit.INCH_1000TH, "1/1000inch");
checkSize(aSize, com.sun.star.util.MeasureUnit.INCH_100TH, "1/100inch");
checkSize(aSize, com.sun.star.util.MeasureUnit.INCH_10TH, "1/10inch");
checkSize(aSize, com.sun.star.util.MeasureUnit.INCH, "inch");
checkSize(aSize, com.sun.star.util.MeasureUnit.POINT, "point");
checkSize(aSize, com.sun.star.util.MeasureUnit.TWIP, "twip");
}
catch (com.sun.star.lang.IllegalArgumentException e)
{
fail("failed: IllegalArgumentException caught in convertSizeToLogic " + e.getMessage());
}
aSizeInMM_100TH = m_xConversion.convertSizeToLogic(aSize, com.sun.star.util.MeasureUnit.MM_100TH);
System.out.println("Window size:");
System.out.println("Width:" + aSizeInMM_100TH.Width + " 1/100mm");
System.out.println("Height:" + aSizeInMM_100TH.Height + " 1/100mm");
System.out.println("");
// try to get the size of the window in 1/10mm with the XUnitConversion method
aSizeInMM_10TH = m_xConversion.convertSizeToLogic(aSize, com.sun.star.util.MeasureUnit.MM_10TH);
System.out.println("Window size:");
System.out.println("Width:" + aSizeInMM_10TH.Width + " 1/10mm");
System.out.println("Height:" + aSizeInMM_10TH.Height + " 1/10mm");
System.out.println("");
// check the size with a delta which must be smaller a given difference
assertTrue("Size.Width not correct", delta(aSizeInMM_100TH.Width, aSizeInMM_10TH.Width * 10) < 10);
assertTrue("Size.Height not correct", delta(aSizeInMM_100TH.Height, aSizeInMM_10TH.Height * 10) < 10);
// new
checkSize(aSize, com.sun.star.util.MeasureUnit.PIXEL, "pixel");
checkSize(aSize, com.sun.star.util.MeasureUnit.APPFONT, "appfont");
checkSize(aSize, com.sun.star.util.MeasureUnit.SYSFONT, "sysfont");
// simply check some more parameters
checkSize(aSize, com.sun.star.util.MeasureUnit.MM, "mm");
checkSize(aSize, com.sun.star.util.MeasureUnit.CM, "cm");
checkSize(aSize, com.sun.star.util.MeasureUnit.INCH_1000TH, "1/1000inch");
checkSize(aSize, com.sun.star.util.MeasureUnit.INCH_100TH, "1/100inch");
checkSize(aSize, com.sun.star.util.MeasureUnit.INCH_10TH, "1/10inch");
checkSize(aSize, com.sun.star.util.MeasureUnit.INCH, "inch");
checkSize(aSize, com.sun.star.util.MeasureUnit.POINT, "point");
checkSize(aSize, com.sun.star.util.MeasureUnit.TWIP, "twip");
// convert the 1/100mm window size back to pixel
try
{
com.sun.star.awt.Size aNewSize = m_xConversion.convertSizeToPixel(aSizeInMM_100TH, com.sun.star.util.MeasureUnit.MM_100TH);
System.out.println("Window size:");
System.out.println("Width:" + aNewSize.Width + " pixel");
System.out.println("Height:" + aNewSize.Height + " pixel");
// assure the pixels are the same as we already know
assertTrue("failed: Size from pixel to 1/100mm to pixel", aSize.Width == aNewSize.Width && aSize.Height == aNewSize.Height);
}
catch (com.sun.star.lang.IllegalArgumentException e)
{
fail("failed: IllegalArgumentException caught in convertSizeToPixel " + e.getMessage());
}
com.sun.star.awt.Size aNewSize = m_xConversion.convertSizeToPixel(aSizeInMM_100TH, com.sun.star.util.MeasureUnit.MM_100TH);
System.out.println("Window size:");
System.out.println("Width:" + aNewSize.Width + " pixel");
System.out.println("Height:" + aNewSize.Height + " pixel");
// assure the pixels are the same as we already know
assertTrue("failed: Size from pixel to 1/100mm to pixel", aSize.Width == aNewSize.Width && aSize.Height == aNewSize.Height);
// close the window.
// IMHO a little bit stupid, but the XWindow doesn't support a XCloseable interface
......
......@@ -163,7 +163,7 @@ public class CheckMemoryUsage
* for each given document type.
*/
@Test
public void loadAndSaveDocuments()
public void loadAndSaveDocuments() throws Exception
{
int nOk = 0;
int nRunThrough = 0;
......@@ -248,7 +248,7 @@ public class CheckMemoryUsage
/**
* load and save exact one document
*/
private void loadAndSaveNTimesDocument(String _sDocument, int _nCount, String _sStoreExtension)
private void loadAndSaveNTimesDocument(String _sDocument, int _nCount, String _sStoreExtension) throws Exception
{
System.out.println("Document: " + _sDocument);
XComponent xComponent = DesktopTools.loadDoc(getMSF(), _sDocument, null);
......@@ -277,15 +277,7 @@ public class CheckMemoryUsage
}
// close the doc
XCloseable xCloseable = UnoRuntime.queryInterface(XCloseable.class, xStorable);
try
{
xCloseable.close(true);
}
catch (com.sun.star.util.CloseVetoException e)
{
e.printStackTrace();
fail("Cannot close document: test is futile, Office will surely use more space.");
}
xCloseable.close(true);
}
else
{
......
......@@ -282,37 +282,15 @@ public class PersistentWindowTest
return docHandle;
}
private boolean connect()
private boolean connect() throws Exception
{
try
{
connection.setUp();
}
catch (InterruptedException e)
{
fail("can't connect.");
}
catch (Exception e)
{
fail("can't connect.");
}
connection.setUp();
return true;
}
private boolean disconnect()
private boolean disconnect() throws Exception
{
try
{
connection.tearDown();
}
catch (InterruptedException e)
{
fail("can't disconnect.");
}
catch (Exception e)
{
fail("can't disconnect.");
}
connection.tearDown();
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment