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; ...@@ -19,37 +19,25 @@ package complex.dbaccess;
import com.sun.star.sdb.XSingleSelectQueryComposer; import com.sun.star.sdb.XSingleSelectQueryComposer;
import connectivity.tools.CRMDatabase; import connectivity.tools.CRMDatabase;
import java.util.logging.Level;
import java.util.logging.Logger;
// ---------- junit imports ----------------- // ---------- junit imports -----------------
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import static org.junit.Assert.*;
public abstract class CRMBasedTestCase extends TestCase public abstract class CRMBasedTestCase extends TestCase
{ {
protected CRMDatabase m_database; protected CRMDatabase m_database;
protected void createTestCase() throws Exception
protected void createTestCase()
{ {
try m_database = new CRMDatabase( getMSF(), false );
{
m_database = new CRMDatabase( getMSF(), false );
}
catch ( Exception e )
{
e.printStackTrace( System.err );
fail( "caught an exception (" + e.getMessage() + ") while creating the test case");
}
} }
@Before @Before
@Override @Override
public void before() public void before() throws Exception
{ {
createTestCase(); createTestCase();
} }
...@@ -57,18 +45,11 @@ public abstract class CRMBasedTestCase extends TestCase ...@@ -57,18 +45,11 @@ public abstract class CRMBasedTestCase extends TestCase
@After @After
@Override @Override
public void after() public void after() throws Exception
{ {
try if ( m_database != null )
{
if ( m_database != null )
{
m_database.saveAndClose();
}
}
catch ( Exception ex )
{ {
Logger.getLogger( this.getClass().getName() ).log( Level.SEVERE, null, ex ); m_database.saveAndClose();
} }
} }
......
...@@ -30,7 +30,6 @@ import com.sun.star.sdb.DataAccessDescriptorFactory; ...@@ -30,7 +30,6 @@ import com.sun.star.sdb.DataAccessDescriptorFactory;
import com.sun.star.sdbc.XConnection; import com.sun.star.sdbc.XConnection;
import com.sun.star.sdbcx.XTablesSupplier; import com.sun.star.sdbcx.XTablesSupplier;
import com.sun.star.task.XInteractionHandler; import com.sun.star.task.XInteractionHandler;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext; import com.sun.star.uno.XComponentContext;
import connectivity.tools.DbaseDatabase; import connectivity.tools.DbaseDatabase;
...@@ -41,7 +40,6 @@ import util.UITools; ...@@ -41,7 +40,6 @@ import util.UITools;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*;
/** complex test case for Base's application UI /** complex test case for Base's application UI
...@@ -55,7 +53,7 @@ public class CopyTableWizard extends CRMBasedTestCase ...@@ -55,7 +53,7 @@ public class CopyTableWizard extends CRMBasedTestCase
@After @After
@Override @Override
public void after() public void after() throws Exception
{ {
dest.store(); dest.store();
if ( destinationDB != null ) if ( destinationDB != null )
...@@ -66,19 +64,12 @@ public class CopyTableWizard extends CRMBasedTestCase ...@@ -66,19 +64,12 @@ public class CopyTableWizard extends CRMBasedTestCase
@Before @Before
@Override @Override
public void before() public void before() throws Exception
{ {
try createTestCase();
{ source = new DatabaseApplication(m_database.getDatabase());
createTestCase(); destinationDB = new DbaseDatabase( getMSF() );
source = new DatabaseApplication(m_database.getDatabase()); dest = new DatabaseApplication( destinationDB );
destinationDB = new DbaseDatabase( getMSF() );
dest = new DatabaseApplication( destinationDB );
}
catch (java.lang.Exception ex)
{
fail("");
}
} }
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
package complex.dbaccess; package complex.dbaccess;
import com.sun.star.container.XNameAccess; import com.sun.star.container.XNameAccess;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XNamingService; import com.sun.star.uno.XNamingService;
import connectivity.tools.CRMDatabase; import connectivity.tools.CRMDatabase;
...@@ -37,51 +36,33 @@ public class DataSource extends TestCase ...@@ -37,51 +36,33 @@ public class DataSource extends TestCase
connectivity.tools.DataSource m_dataSource; 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();
final CRMDatabase database = new CRMDatabase( getMSF(), false ); m_dataSource = m_database.getDataSource();
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());
} }
} }
@Test @Test
public void testRegistrationName() public void testRegistrationName() throws Exception
{ {
try createTestCase();
{ // 1. check the existing "Bibliography" data source whether it has the proper name
createTestCase(); String dataSourceName = "Bibliography";
// 1. check the existing "Bibliography" data source whether it has the proper name final connectivity.tools.DataSource bibliography = new connectivity.tools.DataSource(getMSF(), dataSourceName);
String dataSourceName = "Bibliography"; assertEquals("pre-registered database has a wrong name!", dataSourceName, bibliography.getName());
final connectivity.tools.DataSource bibliography = new connectivity.tools.DataSource(getMSF(), dataSourceName); // 2. register a newly created data source, and verify it has the proper name
assertEquals("pre-registered database has a wrong name!", dataSourceName, bibliography.getName()); dataSourceName = "someDataSource";
// 2. register a newly created data source, and verify it has the proper name final XNamingService dataSourceRegistrations = UnoRuntime.queryInterface(
dataSourceName = "someDataSource"; XNamingService.class, getMSF().createInstance( "com.sun.star.sdb.DatabaseContext" ) );
final XNamingService dataSourceRegistrations = UnoRuntime.queryInterface( final XNameAccess existenceCheck = UnoRuntime.queryInterface( XNameAccess.class, dataSourceRegistrations );
XNamingService.class, getMSF().createInstance( "com.sun.star.sdb.DatabaseContext" ) ); if ( existenceCheck.hasByName( "someDataSource" ) )
final XNameAccess existenceCheck = UnoRuntime.queryInterface( XNameAccess.class, dataSourceRegistrations ); dataSourceRegistrations.revokeObject( "someDataSource" );
if ( existenceCheck.hasByName( "someDataSource" ) ) dataSourceRegistrations.registerObject("someDataSource", m_dataSource.getXDataSource());
dataSourceRegistrations.revokeObject( "someDataSource" ); assertEquals("registration name of a newly registered data source is wrong", dataSourceName, m_dataSource.getName());
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();
}
} }
} }
...@@ -23,7 +23,6 @@ import com.sun.star.sdb.XParametersSupplier; ...@@ -23,7 +23,6 @@ import com.sun.star.sdb.XParametersSupplier;
import com.sun.star.sdb.XSingleSelectQueryComposer; import com.sun.star.sdb.XSingleSelectQueryComposer;
import com.sun.star.sdbc.DataType; import com.sun.star.sdbc.DataType;
import com.sun.star.sdbc.SQLException; import com.sun.star.sdbc.SQLException;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
...@@ -36,18 +35,10 @@ public class Parser extends CRMBasedTestCase ...@@ -36,18 +35,10 @@ public class Parser extends CRMBasedTestCase
{ {
@Override @Override
protected void createTestCase() protected void createTestCase() throws Exception
{ {
try super.createTestCase();
{ m_database.getDatabase().getDataSource().createQuery( "query products", "SELECT * FROM \"products\"" );
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");
}
} }
......
...@@ -55,7 +55,7 @@ public class PropertyBag extends TestCase ...@@ -55,7 +55,7 @@ public class PropertyBag extends TestCase
} }
@Test @Test
public void checkBasics() public void checkBasics() throws Exception
{ {
createEmptyBag(); createEmptyBag();
System.out.println("testing the basics"); System.out.println("testing the basics");
...@@ -115,19 +115,12 @@ public class PropertyBag extends TestCase ...@@ -115,19 +115,12 @@ public class PropertyBag extends TestCase
} }
// try writing and reading a value for the one property we have so far // 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 testValue = "someArbitraryValue"; final String currentValue = (String)m_set.getPropertyValue( VALUE);
m_set.setPropertyValue( VALUE , testValue); if ( !currentValue.equals( 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)
{ {
fail( "setting or getting a property value failed" ); fail("set property is not remembered");
} }
// try setting an illegal value for the property // try setting an illegal value for the property
......
...@@ -32,13 +32,16 @@ import com.sun.star.container.XIndexAccess; ...@@ -32,13 +32,16 @@ import com.sun.star.container.XIndexAccess;
import com.sun.star.sdb.CommandType; import com.sun.star.sdb.CommandType;
import com.sun.star.sdb.XSingleSelectQueryComposer; import com.sun.star.sdb.XSingleSelectQueryComposer;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.sdbc.DataType; import com.sun.star.sdbc.DataType;
import com.sun.star.sdbc.SQLException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
// ---------- junit imports ----------------- // ---------- junit imports -----------------
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*; import static org.junit.Assert.*;
...@@ -62,21 +65,13 @@ public class SingleSelectQueryComposer extends CRMBasedTestCase ...@@ -62,21 +65,13 @@ public class SingleSelectQueryComposer extends CRMBasedTestCase
@Override @Override
protected void createTestCase() protected void createTestCase() throws Exception
{ {
try super.createTestCase();
{
super.createTestCase();
createQueries();
m_composer = createQueryComposer(); createQueries();
} m_composer = createQueryComposer();
catch (Exception e)
{
fail("caught an exception (" + e.getMessage() + ") while creating the test case");
}
} }
...@@ -120,92 +115,78 @@ public class SingleSelectQueryComposer extends CRMBasedTestCase ...@@ -120,92 +115,78 @@ public class SingleSelectQueryComposer extends CRMBasedTestCase
/** tests setCommand of the composer /** tests setCommand of the composer
*/ */
@Test @Test
public void testSetCommand() public void testSetCommand() throws Exception
{ {
System.out.println("testing SingleSelectQueryComposer's setCommand"); System.out.println("testing SingleSelectQueryComposer's setCommand");
try final String table = "SELECT * FROM \"customers\"";
{ m_composer.setCommand("customers", CommandType.TABLE);
final String table = "SELECT * FROM \"customers\""; assertTrue("setCommand/getQuery TABLE inconsistent", m_composer.getQuery().equals(table));
m_composer.setCommand("customers", CommandType.TABLE);
assertTrue("setCommand/getQuery TABLE inconsistent", m_composer.getQuery().equals(table));
m_database.getDatabase().getDataSource().createQuery("set command test", "SELECT * FROM \"orders for customer\" \"a\", \"customers\" \"b\" WHERE \"a\".\"Product Name\" = \"b\".\"Name\""); m_database.getDatabase().getDataSource().createQuery("set command test", "SELECT * FROM \"orders for customer\" \"a\", \"customers\" \"b\" WHERE \"a\".\"Product Name\" = \"b\".\"Name\"");
m_composer.setCommand("set command test", CommandType.QUERY); m_composer.setCommand("set command test", CommandType.QUERY);
assertTrue("setCommand/getQuery QUERY inconsistent", m_composer.getQuery().equals(m_database.getDatabase().getDataSource().getQueryDefinition("set command test").getCommand())); assertTrue("setCommand/getQuery QUERY inconsistent", m_composer.getQuery().equals(m_database.getDatabase().getDataSource().getQueryDefinition("set command test").getCommand()));
final String sql = "SELECT * FROM \"orders for customer\" WHERE \"Product Name\" = 'test'"; final String sql = "SELECT * FROM \"orders for customer\" WHERE \"Product Name\" = 'test'";
m_composer.setCommand(sql, CommandType.COMMAND); m_composer.setCommand(sql, CommandType.COMMAND);
assertTrue("setCommand/getQuery COMMAND inconsistent", m_composer.getQuery().equals(sql)); assertTrue("setCommand/getQuery COMMAND inconsistent", m_composer.getQuery().equals(sql));
}
catch (Exception e)
{
fail("Exception caught: " + e);
}
} }
/** tests accessing attributes of the composer (order, filter, group by, having) /** tests accessing attributes of the composer (order, filter, group by, having)
*/ */
@Test @Test
public void testAttributes() public void testAttributes() throws Exception
{ {
System.out.println("testing SingleSelectQueryComposer's attributes (order, filter, group by, having)"); System.out.println("testing SingleSelectQueryComposer's attributes (order, filter, group by, having)");
try System.out.println("check setElementaryQuery");
{
System.out.println("check setElementaryQuery"); final String simpleQuery2 = "SELECT * FROM \"customers\" WHERE \"Name\" = 'oranges'";
m_composer.setElementaryQuery(simpleQuery2);
final String simpleQuery2 = "SELECT * FROM \"customers\" WHERE \"Name\" = 'oranges'"; assertTrue("setElementaryQuery/getQuery inconsistent", m_composer.getQuery().equals(simpleQuery2));
m_composer.setElementaryQuery(simpleQuery2);
assertTrue("setElementaryQuery/getQuery inconsistent", m_composer.getQuery().equals(simpleQuery2)); System.out.println("check setQuery");
final String simpleQuery = "SELECT * FROM \"customers\"";
System.out.println("check setQuery"); m_composer.setQuery(simpleQuery);
final String simpleQuery = "SELECT * FROM \"customers\""; assertTrue("set/getQuery inconsistent", m_composer.getQuery().equals(simpleQuery));
m_composer.setQuery(simpleQuery);
assertTrue("set/getQuery inconsistent", m_composer.getQuery().equals(simpleQuery)); checkAttributeAccess("Filter", "\"Name\" = 'oranges'");
checkAttributeAccess("Group", "\"City\"");
checkAttributeAccess("Filter", "\"Name\" = 'oranges'"); checkAttributeAccess("Order", "\"Address\"");
checkAttributeAccess("Group", "\"City\""); checkAttributeAccess("HavingClause", "\"ID\" <> 4");
checkAttributeAccess("Order", "\"Address\"");
checkAttributeAccess("HavingClause", "\"ID\" <> 4"); final XIndexAccess orderColumns = m_composer.getOrderColumns();
assertTrue("Order columns doesn't exist: \"Address\"",
final XIndexAccess orderColumns = m_composer.getOrderColumns(); orderColumns != null && orderColumns.getCount() == 1 && orderColumns.getByIndex(0) != null);
assertTrue("Order columns doesn't exist: \"Address\"",
orderColumns != null && orderColumns.getCount() == 1 && orderColumns.getByIndex(0) != null); final XIndexAccess groupColumns = m_composer.getGroupColumns();
assertTrue("Group columns doesn't exist: \"City\"",
final XIndexAccess groupColumns = m_composer.getGroupColumns(); groupColumns != null && groupColumns.getCount() == 1 && groupColumns.getByIndex(0) != null);
assertTrue("Group columns doesn't exist: \"City\"",
groupColumns != null && groupColumns.getCount() == 1 && groupColumns.getByIndex(0) != null); // XColumnsSupplier
final XColumnsSupplier xSelectColumns = UnoRuntime.queryInterface(XColumnsSupplier.class, m_composer);
// XColumnsSupplier assertTrue("no select columns, or wrong number of select columns",
final XColumnsSupplier xSelectColumns = UnoRuntime.queryInterface(XColumnsSupplier.class, m_composer); xSelectColumns != null && xSelectColumns.getColumns() != null && xSelectColumns.getColumns().getElementNames().length == 6);
assertTrue("no select columns, or wrong number of select columns",
xSelectColumns != null && xSelectColumns.getColumns() != null && xSelectColumns.getColumns().getElementNames().length == 6); // structured filter
m_composer.setQuery("SELECT \"ID\", \"Postal\", \"Address\" FROM \"customers\"");
// structured filter m_composer.setFilter(COMPLEXFILTER);
m_composer.setQuery("SELECT \"ID\", \"Postal\", \"Address\" FROM \"customers\""); final PropertyValue[][] aStructuredFilter = m_composer.getStructuredFilter();
m_composer.setFilter(COMPLEXFILTER); m_composer.setFilter("");
final PropertyValue[][] aStructuredFilter = m_composer.getStructuredFilter(); m_composer.setStructuredFilter(aStructuredFilter);
m_composer.setFilter(""); if (!m_composer.getFilter().equals(COMPLEXFILTER))
m_composer.setStructuredFilter(aStructuredFilter);
if (!m_composer.getFilter().equals(COMPLEXFILTER))
{
System.out.println(COMPLEXFILTER);
System.out.println(m_composer.getFilter());
}
assertTrue("Structured Filter not identical", m_composer.getFilter().equals(COMPLEXFILTER));
// structured having clause
m_composer.setHavingClause(COMPLEXFILTER);
final PropertyValue[][] aStructuredHaving = m_composer.getStructuredHavingClause();
m_composer.setHavingClause("");
m_composer.setStructuredHavingClause(aStructuredHaving);
assertTrue("Structured Having Clause not identical", m_composer.getHavingClause().equals(COMPLEXFILTER));
}
catch (Exception e)
{ {
fail("Exception caught: " + e); System.out.println(COMPLEXFILTER);
System.out.println(m_composer.getFilter());
} }
assertTrue("Structured Filter not identical", m_composer.getFilter().equals(COMPLEXFILTER));
// structured having clause
m_composer.setHavingClause(COMPLEXFILTER);
final PropertyValue[][] aStructuredHaving = m_composer.getStructuredHavingClause();
m_composer.setHavingClause("");
m_composer.setStructuredHavingClause(aStructuredHaving);
assertTrue("Structured Having Clause not identical", m_composer.getHavingClause().equals(COMPLEXFILTER));
} }
/** test various sub query related features ("queries in queries") /** test various sub query related features ("queries in queries")
...@@ -228,89 +209,65 @@ public class SingleSelectQueryComposer extends CRMBasedTestCase ...@@ -228,89 +209,65 @@ public class SingleSelectQueryComposer extends CRMBasedTestCase
/** tests the XParametersSupplier functionality /** tests the XParametersSupplier functionality
*/ */
@Test @Test
public void testParameters() public void testParameters() throws Exception
{ {
try // "orders for customers" is a query with a named parameter (based on another query)
{ m_database.getDatabase().getDataSource().createQuery("orders for customer", "SELECT * FROM \"all orders\" WHERE \"Customer Name\" LIKE :cname");
// "orders for customers" is a query with a named parameter (based on another query) // "orders for customer and product" is query based on "orders for customers", adding an additional,
m_database.getDatabase().getDataSource().createQuery("orders for customer", "SELECT * FROM \"all orders\" WHERE \"Customer Name\" LIKE :cname"); // anonymous parameter
// "orders for customer and product" is query based on "orders for customers", adding an additional, m_database.getDatabase().getDataSource().createQuery("orders for customer and product", "SELECT * FROM \"orders for customer\" WHERE \"Product Name\" LIKE ?");
// anonymous parameter
m_database.getDatabase().getDataSource().createQuery("orders for customer and product", "SELECT * FROM \"orders for customer\" WHERE \"Product Name\" LIKE ?");
m_composer.setQuery(m_database.getDatabase().getDataSource().getQueryDefinition("orders for customer and product").getCommand()); m_composer.setQuery(m_database.getDatabase().getDataSource().getQueryDefinition("orders for customer and product").getCommand());
final XParametersSupplier suppParams = UnoRuntime.queryInterface(XParametersSupplier.class, m_composer); final XParametersSupplier suppParams = UnoRuntime.queryInterface(XParametersSupplier.class, m_composer);
final XIndexAccess parameters = suppParams.getParameters(); final XIndexAccess parameters = suppParams.getParameters();
final String expectedParamNames[] = final String expectedParamNames[] =
{ {
"cname", "cname",
"Product Name" "Product Name"
}; };
final int paramCount = parameters.getCount();
assertTrue("composer did find wrong number of parameters in the nested queries.",
paramCount == expectedParamNames.length);
for (int i = 0; i < paramCount; ++i) final int paramCount = parameters.getCount();
{ assertTrue("composer did find wrong number of parameters in the nested queries.",
final XPropertySet parameter = UnoRuntime.queryInterface(XPropertySet.class, parameters.getByIndex(i)); paramCount == expectedParamNames.length);
final String paramName = (String) parameter.getPropertyValue("Name");
assertTrue("wrong parameter name at position " + (i + 1) + " (expected: " + expectedParamNames[i] + ", found: " + paramName + ")",
paramName.equals(expectedParamNames[i]));
} for (int i = 0; i < paramCount; ++i)
}
catch (Exception e)
{ {
fail("caught an exception: " + e); final XPropertySet parameter = UnoRuntime.queryInterface(XPropertySet.class, parameters.getByIndex(i));
final String paramName = (String) parameter.getPropertyValue("Name");
assertTrue("wrong parameter name at position " + (i + 1) + " (expected: " + expectedParamNames[i] + ", found: " + paramName + ")",
paramName.equals(expectedParamNames[i]));
} }
} }
@Test @Test
public void testConditionByColumn() public void testConditionByColumn() throws Exception
{ {
try m_composer.setQuery("SELECT * FROM \"customers\"");
{
m_composer.setQuery("SELECT * FROM \"customers\"");
final Object initArgs[] =
{ final Object initArgs[] =
new NamedValue("AutomaticAddition", Boolean.TRUE)
};
final String serviceName = "com.sun.star.beans.PropertyBag";
final XPropertyContainer filter = UnoRuntime.queryInterface(XPropertyContainer.class, getMSF().createInstanceWithArguments(serviceName, initArgs));
filter.addProperty("Name", PropertyAttribute.MAYBEVOID, "Comment");
filter.addProperty("RealName", PropertyAttribute.MAYBEVOID, "Comment");
filter.addProperty("TableName", PropertyAttribute.MAYBEVOID, "customers");
filter.addProperty("Value", PropertyAttribute.MAYBEVOID, "Good one.");
filter.addProperty("Type", PropertyAttribute.MAYBEVOID, Integer.valueOf(DataType.LONGVARCHAR));
final XPropertySet column = UnoRuntime.queryInterface(XPropertySet.class, filter);
m_composer.appendFilterByColumn(column, true, SQLFilterOperator.LIKE);
assertTrue("At least one row should exist", m_database.getConnection().createStatement().executeQuery(m_composer.getQuery()).next());
}
catch (Exception e)
{ {
// this is an error: the query is expected to be parseable new NamedValue("AutomaticAddition", Boolean.TRUE)
fail("caught an exception: " + e); };
} final String serviceName = "com.sun.star.beans.PropertyBag";
final XPropertyContainer filter = UnoRuntime.queryInterface(XPropertyContainer.class, getMSF().createInstanceWithArguments(serviceName, initArgs));
filter.addProperty("Name", PropertyAttribute.MAYBEVOID, "Comment");
filter.addProperty("RealName", PropertyAttribute.MAYBEVOID, "Comment");
filter.addProperty("TableName", PropertyAttribute.MAYBEVOID, "customers");
filter.addProperty("Value", PropertyAttribute.MAYBEVOID, "Good one.");
filter.addProperty("Type", PropertyAttribute.MAYBEVOID, Integer.valueOf(DataType.LONGVARCHAR));
final XPropertySet column = UnoRuntime.queryInterface(XPropertySet.class, filter);
m_composer.appendFilterByColumn(column, true, SQLFilterOperator.LIKE);
assertTrue("At least one row should exist", m_database.getConnection().createStatement().executeQuery(m_composer.getQuery()).next());
} }
private void impl_testDisjunctiveNormalForm(String _query, PropertyValue[][] _expectedDNF) private void impl_testDisjunctiveNormalForm(String _query, PropertyValue[][] _expectedDNF) throws SQLException
{ {
try m_composer.setQuery(_query);
{
m_composer.setQuery(_query);
}
catch (Exception e)
{
// this is an error: the query is expected to be parseable
fail("caught an exception: " + e);
}
final PropertyValue[][] disjunctiveNormalForm = m_composer.getStructuredFilter(); final PropertyValue[][] disjunctiveNormalForm = m_composer.getStructuredFilter();
...@@ -330,7 +287,7 @@ public class SingleSelectQueryComposer extends CRMBasedTestCase ...@@ -330,7 +287,7 @@ public class SingleSelectQueryComposer extends CRMBasedTestCase
* of the composer * of the composer
*/ */
@Test @Test
public void testDisjunctiveNormalForm() public void testDisjunctiveNormalForm() throws Exception
{ {
// a simple case: WHERE clause simply is a combination of predicates knitted with AND // a simple case: WHERE clause simply is a combination of predicates knitted with AND
String query = String query =
......
...@@ -17,26 +17,25 @@ ...@@ -17,26 +17,25 @@
*/ */
package complex.filter.misc; package complex.filter.misc;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openoffice.test.OfficeConnection;
import com.sun.star.beans.PropertyValue; import com.sun.star.beans.PropertyValue;
import com.sun.star.container.NoSuchElementException;
import com.sun.star.container.XNameAccess; import com.sun.star.container.XNameAccess;
import com.sun.star.container.XNameContainer; import com.sun.star.container.XNameContainer;
import com.sun.star.container.XNameReplace; import com.sun.star.container.XNameReplace;
import com.sun.star.lang.IllegalArgumentException;
import com.sun.star.lang.WrappedTargetException;
import com.sun.star.lang.WrappedTargetRuntimeException; import com.sun.star.lang.WrappedTargetRuntimeException;
import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface; import com.sun.star.uno.XInterface;
import com.sun.star.util.XFlushable; import com.sun.star.util.XFlushable;
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 * This complex test checks the functionality of the properties "Finalized" and "Mandatory" of
...@@ -106,7 +105,7 @@ public class FinalizedMandatoryTest ...@@ -106,7 +105,7 @@ public class FinalizedMandatoryTest
* call the function <CODE>checkReadonlySupport</CODE> to test <CODE>com.sun.star.document.FilterFactory</CODE> * call the function <CODE>checkReadonlySupport</CODE> to test <CODE>com.sun.star.document.FilterFactory</CODE>
* @see com.sun.star.document.FilterFactory * @see com.sun.star.document.FilterFactory
*/ */
@Test public void checkReadonlySupportFilterFactory() @Test public void checkReadonlySupportFilterFactory() throws Exception
{ {
checkReadonlySupport("com.sun.star.document.FilterFactory"); checkReadonlySupport("com.sun.star.document.FilterFactory");
} }
...@@ -115,7 +114,7 @@ public class FinalizedMandatoryTest ...@@ -115,7 +114,7 @@ public class FinalizedMandatoryTest
* call the function <CODE>checkReadonlySupport</CODE> to test <CODE>com.sun.star.document.TypeDetection</CODE> * call the function <CODE>checkReadonlySupport</CODE> to test <CODE>com.sun.star.document.TypeDetection</CODE>
* @see com.sun.star.document.TypeDetection * @see com.sun.star.document.TypeDetection
*/ */
@Test public void checkReadonlySupportTypeDetection() @Test public void checkReadonlySupportTypeDetection() throws Exception
{ {
checkReadonlySupport("com.sun.star.document.TypeDetection"); checkReadonlySupport("com.sun.star.document.TypeDetection");
} }
...@@ -125,21 +124,14 @@ public class FinalizedMandatoryTest ...@@ -125,21 +124,14 @@ public class FinalizedMandatoryTest
* For every filter a new instace was created and the tests started. * For every filter a new instace was created and the tests started.
* @param serviceName the name of the service to test * @param serviceName the name of the service to test
*/ */
private void checkReadonlySupport(String serviceName) private void checkReadonlySupport(String serviceName) throws Exception
{ {
System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("testing service '" + serviceName + "'"); System.out.println("testing service '" + serviceName + "'");
XInterface oObj = null; XInterface oObj = null;
try oObj = getTestObject(serviceName);
{ System.out.println("ImplName: " + util.utils.getImplName(oObj));
oObj = getTestObject(serviceName);
System.out.println("ImplName: " + util.utils.getImplName(oObj));
}
catch (java.lang.Exception e)
{
fail("could not get test object");
}
boolean mandantoryTrue = false; boolean mandantoryTrue = false;
boolean mandantoryFalse = false; boolean mandantoryFalse = false;
...@@ -157,109 +149,76 @@ public class FinalizedMandatoryTest ...@@ -157,109 +149,76 @@ public class FinalizedMandatoryTest
for (int i = 0; i < filterNames.length; i++) for (int i = 0; i < filterNames.length; i++)
{ {
System.out.println("------------------------------------------------"); System.out.println("------------------------------------------------");
filterName = filterNames[i];
System.out.println(filterName);
// testobject must new created for every test.
// We change in a loop the container and try to flush this changes.
// If we get an expected exception this container is corrupt. It's
// similar to a document which could not be saved because of invalid
// contend. While you don't remove the invalid conted you will never
// be able to save the document. Same here.
oObj = getTestObject(serviceName);
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;
printPropertyValues(props);
boolean isMandatory = ((Boolean) getPropertyValueValue(props, "Mandatory")).booleanValue();
boolean isFinalized = ((Boolean) getPropertyValueValue(props, "Finalized")).booleanValue();
// memory if every state is available
mandantoryTrue |= isMandatory;
mandantoryFalse |= !isMandatory;
finalizedTrue |= isFinalized;
finalizedFalse |= !isFinalized;
//change the filter
setPropertyValueValue((PropertyValue[]) instance, "UIName", "dummy");
// 1a.) try to change the filter in the container
xNR.replaceByName(filterName, instance);
// 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
{ {
filterName = filterNames[i]; xFlush.flush();
System.out.println(filterName); }
catch (WrappedTargetRuntimeException e)
// testobject must new created for every test. {
// We change in a loop the container and try to flush this changes. flushError = true;
// If we get an expected exception this container is corrupt. It's assertTrue("Unexpected exception wihle flushing changed filter '" + filterName + "'", isFinalized);
// similar to a document which could not be saved because of invalid
// contend. While you don't remove the invalid conted you will never
// be able to save the document. Same here.
try
{
oObj = getTestObject(serviceName);
}
catch (java.lang.Exception e)
{
fail("could not get test object");
}
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;
printPropertyValues(props);
boolean isMandatory = ((Boolean) getPropertyValueValue(props, "Mandatory")).booleanValue();
boolean isFinalized = ((Boolean) getPropertyValueValue(props, "Finalized")).booleanValue();
// memory if every state is available
mandantoryTrue |= isMandatory;
mandantoryFalse |= !isMandatory;
finalizedTrue |= isFinalized;
finalizedFalse |= !isFinalized;
//change the filter
setPropertyValueValue((PropertyValue[]) instance, "UIName", "dummy");
// 1a.) try to change the filter in the container
try
{
xNR.replaceByName(filterName, instance);
}
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
{
xFlush.flush();
}
catch (WrappedTargetRuntimeException e)
{
flushError = true;
assertTrue("Unexpected exception wihle flushing changed filter '" + filterName + "'", isFinalized);
}
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
{
xNC.removeByName(filterName);
}
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
{
xFlush.flush();
}
catch (WrappedTargetRuntimeException e)
{
flushError = true;
assertTrue("Unexpected exception wihle flushing removed filter '" + filterName + "'", isMandatory);
}
assertTrue("Expected exception was not thorwn while flushing removed filter '" + filterName + "' Mandatory:" + isMandatory,
!(flushError ^ isMandatory));
} }
catch (NoSuchElementException e) assertTrue("Expected exception was not thorwn while flushing changed filter '" + filterName + "' Finalized:" + isFinalized,
!(flushError ^ isFinalized));
// 2a.) try to remove the filter from the container
xNC.removeByName(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
{ {
fail("Couldn't get elements from object"); xFlush.flush();
} }
catch (WrappedTargetException e) catch (WrappedTargetRuntimeException e)
{ {
fail("Couldn't get elements from object"); flushError = true;
assertTrue("Unexpected exception wihle flushing removed filter '" + filterName + "'", isMandatory);
} }
assertTrue("Expected exception was not thorwn while flushing removed filter '" + filterName + "' Mandatory:" + isMandatory,
!(flushError ^ isMandatory));
} }
String preMsg = "Could not find filter with state "; String preMsg = "Could not find filter with state ";
String postMsg = " Please check if such filter is installed!"; String postMsg = " Please check if such filter is installed!";
......
...@@ -44,17 +44,15 @@ public class TypeDetection6FileFormat ...@@ -44,17 +44,15 @@ public class TypeDetection6FileFormat
*/ */
@Before public void before() throws Exception @Before public void before() throws Exception
{ {
xMSF = getMSF(); xMSF = getMSF();
assertNotNull("Could not get XMultiServiceFactory", xMSF); assertNotNull("Could not get XMultiServiceFactory", xMSF);
} }
/** /**
* call the function <CODE>checkFileFormatSupport</CODE> to test <CODE>com.sun.star.document.FilterFactory</CODE> * call the function <CODE>checkFileFormatSupport</CODE> to test <CODE>com.sun.star.document.FilterFactory</CODE>
* @see com.sun.star.document.FilterFactory * @see com.sun.star.document.FilterFactory
*/ */
@Test public void checkFilterFactory() @Test public void checkFilterFactory() throws Exception
{ {
checkFileFormatSupport("com.sun.star.document.FilterFactory"); checkFileFormatSupport("com.sun.star.document.FilterFactory");
} }
...@@ -63,10 +61,9 @@ public class TypeDetection6FileFormat ...@@ -63,10 +61,9 @@ public class TypeDetection6FileFormat
* call the function <CODE>checkFileFormatSupport</CODE> to test <CODE>com.sun.star.document.TypeDetection</CODE> * call the function <CODE>checkFileFormatSupport</CODE> to test <CODE>com.sun.star.document.TypeDetection</CODE>
* @see com.sun.star.document.TypeDetection * @see com.sun.star.document.TypeDetection
*/ */
@Test public void checkTypeDetection() @Test public void checkTypeDetection() throws Exception
{ {
checkFileFormatSupport("com.sun.star.document.TypeDetection"); checkFileFormatSupport("com.sun.star.document.TypeDetection");
} }
/** /**
...@@ -74,27 +71,18 @@ public class TypeDetection6FileFormat ...@@ -74,27 +71,18 @@ public class TypeDetection6FileFormat
* The serve was created and the filter 'TypeDetection6FileFormat' was searched * The serve was created and the filter 'TypeDetection6FileFormat' was searched
* @param serviceName the name of the service to test * @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("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
System.out.println("testing service '" + serviceName + "'"); System.out.println("testing service '" + serviceName + "'");
XInterface oObj = null; XInterface oObj = null;
try oObj = getTestObject(serviceName);
{ System.out.println("ImplName: " + utils.getImplName(oObj));
oObj = getTestObject(serviceName);
System.out.println("ImplName: " + utils.getImplName(oObj));
}
catch (java.lang.Exception e)
{
fail("could not get test object");
}
XNameAccess xNA = UnoRuntime.queryInterface(XNameAccess.class, oObj); XNameAccess xNA = UnoRuntime.queryInterface(XNameAccess.class, oObj);
String msg = "Could not find filter 'TypeDetection6FileFormat'!"; String msg = "Could not find filter 'TypeDetection6FileFormat'!";
msg += "\nMaybe 'TypeDetection6FileFormat.xcu' is not registered."; msg += "\nMaybe 'TypeDetection6FileFormat.xcu' is not registered.";
assertTrue(msg, xNA.hasByName("TypeDetection6FileFormat")); assertTrue(msg, xNA.hasByName("TypeDetection6FileFormat"));
} }
/** /**
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
package complex.forms; package complex.forms;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -43,7 +42,6 @@ import com.sun.star.lang.EventObject; ...@@ -43,7 +42,6 @@ import com.sun.star.lang.EventObject;
import com.sun.star.lang.XComponent; import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.util.CloseVetoException;
import com.sun.star.util.XCloseable; import com.sun.star.util.XCloseable;
/** /**
...@@ -54,42 +52,28 @@ public class CheckOGroupBoxModel ...@@ -54,42 +52,28 @@ public class CheckOGroupBoxModel
private XMultiPropertySet m_xPropSet; private XMultiPropertySet m_xPropSet;
private XComponent m_xDrawDoc; private XComponent m_xDrawDoc;
@Before public void before() @Before public void before() throws Exception
{ {
SOfficeFactory SOF = SOfficeFactory.getFactory(getMSF()); SOfficeFactory SOF = SOfficeFactory.getFactory(getMSF());
try System.out.println("creating a draw document");
{ m_xDrawDoc = SOF.createDrawDoc(null);
System.out.println("creating a draw document");
m_xDrawDoc = SOF.createDrawDoc(null);
}
catch (com.sun.star.uno.Exception e)
{
fail("Couldn't create document.");
}
String objName = "GroupBox"; String objName = "GroupBox";
XControlShape shape = FormTools.insertControlShape(m_xDrawDoc, 5000, 7000, 2000, 2000, objName); XControlShape shape = FormTools.insertControlShape(m_xDrawDoc, 5000, 7000, 2000, 2000, objName);
m_xPropSet = UnoRuntime.queryInterface(XMultiPropertySet.class, shape.getControl()); 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); XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, m_xDrawDoc);
if (xClose != null) if (xClose != null)
{ {
try xClose.close(true);
{
xClose.close(true);
}
catch (CloseVetoException ex)
{
fail("Can't close document. Exception caught: " + ex.getMessage());
/* ignore! */
}
} }
} }
@Test public void setPropertyValues()
@Test public void setPropertyValues() throws Exception
{ {
String[] boundPropsToTest = getBoundPropsToTest(); String[] boundPropsToTest = getBoundPropsToTest();
...@@ -103,22 +87,7 @@ public class CheckOGroupBoxModel ...@@ -103,22 +87,7 @@ public class CheckOGroupBoxModel
{ {
newValue[i] = ValueChanger.changePValue(gValues[i]); newValue[i] = ValueChanger.changePValue(gValues[i]);
} }
try m_xPropSet.setPropertyValues(boundPropsToTest, newValue);
{
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
assertTrue("Listener was not called.", ml.wasListenerCalled()); assertTrue("Listener was not called.", ml.wasListenerCalled());
m_xPropSet.removePropertiesChangeListener(ml); m_xPropSet.removePropertiesChangeListener(ml);
......
...@@ -31,7 +31,6 @@ import com.sun.star.beans.XPropertySet; ...@@ -31,7 +31,6 @@ import com.sun.star.beans.XPropertySet;
import com.sun.star.drawing.XShape; import com.sun.star.drawing.XShape;
import com.sun.star.frame.XFrame; import com.sun.star.frame.XFrame;
import com.sun.star.frame.XModel; import com.sun.star.frame.XModel;
import com.sun.star.lang.IndexOutOfBoundsException;
import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.ui.XContextMenuInterception; import com.sun.star.ui.XContextMenuInterception;
import com.sun.star.ui.XContextMenuInterceptor; import com.sun.star.ui.XContextMenuInterceptor;
...@@ -79,7 +78,7 @@ public class CheckContextMenuInterceptor ...@@ -79,7 +78,7 @@ public class CheckContextMenuInterceptor
} }
@After @After
public void after() public void after() throws Exception
{ {
System.out.println("release the popup menu"); System.out.println("release the popup menu");
try try
...@@ -98,116 +97,97 @@ public class CheckContextMenuInterceptor ...@@ -98,116 +97,97 @@ public class CheckContextMenuInterceptor
XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, xFrame); XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, xFrame);
try xClose.close(true);
{
xClose.close(true);
}
catch (com.sun.star.util.CloseVetoException exVeto)
{
fail("Test frame couldn't be closed successfully.");
}
xFrame = null; xFrame = null;
} }
@Test @Test
public void checkContextMenuInterceptor() public void checkContextMenuInterceptor() throws Exception
{ {
System.out.println(" **** Context Menu Interceptor *** "); 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); SOfficeFactory SOF = SOfficeFactory.getFactory(xMSF);
XShape oShape = SOF.createShape(xDrawDoc, 5000, 5000, 1500, 1000, "GraphicObject"); XShape oShape = SOF.createShape(xDrawDoc, 5000, 5000, 1500, 1000, "GraphicObject");
DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc, 0)).add(oShape); DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc, 0)).add(oShape);
com.sun.star.frame.XModel xModel = com.sun.star.frame.XModel xModel =
UnoRuntime.queryInterface(com.sun.star.frame.XModel.class, xDrawDoc); UnoRuntime.queryInterface(com.sun.star.frame.XModel.class, xDrawDoc);
// get the frame for later usage // get the frame for later usage
xFrame = xModel.getCurrentController().getFrame(); xFrame = xModel.getCurrentController().getFrame();
// ensure that the document content is optimal visible // ensure that the document content is optimal visible
DesktopTools.zoomToEntirePage(xDrawDoc); DesktopTools.zoomToEntirePage(xDrawDoc);
XBitmap xBitmap = null; XBitmap xBitmap = null;
// adding graphic as ObjRelation for GraphicObjectShape // adding graphic as ObjRelation for GraphicObjectShape
XPropertySet oShapeProps = UnoRuntime.queryInterface(XPropertySet.class, oShape); XPropertySet oShapeProps = UnoRuntime.queryInterface(XPropertySet.class, oShape);
System.out.println("Inserting a shape into the document"); System.out.println("Inserting a shape into the document");
try try
{ {
String sFile = OfficeFileUrl.getAbsolute(new File("space-metal.jpg")); String sFile = OfficeFileUrl.getAbsolute(new File("space-metal.jpg"));
oShapeProps.setPropertyValue("GraphicURL", sFile); oShapeProps.setPropertyValue("GraphicURL", sFile);
Object oProp = oShapeProps.getPropertyValue("GraphicObjectFillBitmap"); Object oProp = oShapeProps.getPropertyValue("GraphicObjectFillBitmap");
xBitmap = (XBitmap) AnyConverter.toObject(new Type(XBitmap.class), oProp); xBitmap = (XBitmap) AnyConverter.toObject(new Type(XBitmap.class), oProp);
} }
catch (com.sun.star.lang.WrappedTargetException e) catch (com.sun.star.lang.WrappedTargetException e)
{ {
} }
catch (com.sun.star.lang.IllegalArgumentException e) catch (com.sun.star.lang.IllegalArgumentException e)
{ {
} }
catch (com.sun.star.beans.PropertyVetoException e) catch (com.sun.star.beans.PropertyVetoException e)
{ {
} }
catch (com.sun.star.beans.UnknownPropertyException e) catch (com.sun.star.beans.UnknownPropertyException e)
{ {
} }
// reuse the frame // reuse the frame
com.sun.star.frame.XController xController = xFrame.getController(); com.sun.star.frame.XController xController = xFrame.getController();
XContextMenuInterception xContextMenuInterception = null; XContextMenuInterception xContextMenuInterception = null;
XContextMenuInterceptor xContextMenuInterceptor = null; XContextMenuInterceptor xContextMenuInterceptor = null;
if (xController != null) if (xController != null)
{ {
System.out.println("Creating context menu interceptor"); System.out.println("Creating context menu interceptor");
// add our context menu interceptor // add our context menu interceptor
xContextMenuInterception = xContextMenuInterception =
UnoRuntime.queryInterface(XContextMenuInterception.class, xController); UnoRuntime.queryInterface(XContextMenuInterception.class, xController);
if (xContextMenuInterception != null) if (xContextMenuInterception != null)
{ {
ContextMenuInterceptor aContextMenuInterceptor = new ContextMenuInterceptor(xBitmap); ContextMenuInterceptor aContextMenuInterceptor = new ContextMenuInterceptor(xBitmap);
xContextMenuInterceptor = xContextMenuInterceptor =
UnoRuntime.queryInterface(XContextMenuInterceptor.class, aContextMenuInterceptor); UnoRuntime.queryInterface(XContextMenuInterceptor.class, aContextMenuInterceptor);
System.out.println("Register context menu interceptor"); System.out.println("Register context menu interceptor");
xContextMenuInterception.registerContextMenuInterceptor(xContextMenuInterceptor); xContextMenuInterception.registerContextMenuInterceptor(xContextMenuInterceptor);
}
} }
}
openContextMenu(UnoRuntime.queryInterface(XModel.class, xDrawDoc)); openContextMenu(UnoRuntime.queryInterface(XModel.class, xDrawDoc));
checkHelpEntry(); checkHelpEntry();
// remove our context menu interceptor // remove our context menu interceptor
if (xContextMenuInterception != null if (xContextMenuInterception != null
&& xContextMenuInterceptor != null) && xContextMenuInterceptor != null)
{
System.out.println("Release context menu interceptor");
xContextMenuInterception.releaseContextMenuInterceptor(
xContextMenuInterceptor);
}
}
catch (com.sun.star.uno.RuntimeException ex)
{ {
fail("Runtime exception caught!" + ex.getMessage()); System.out.println("Release context menu interceptor");
} xContextMenuInterception.releaseContextMenuInterceptor(
catch (java.lang.Exception ex) xContextMenuInterceptor);
{
fail("Java lang exception caught!" + ex.getMessage());
} }
} }
private void checkHelpEntry() private void checkHelpEntry() throws Exception
{ {
XInterface toolkit = null; XInterface toolkit = null;
...@@ -240,24 +220,14 @@ public class CheckContextMenuInterceptor ...@@ -240,24 +220,14 @@ public class CheckContextMenuInterceptor
System.out.println("ImplementationName: " + util.utils.getImplName(oPopMenu)); System.out.println("ImplementationName: " + util.utils.getImplName(oPopMenu));
XAccessible xHelp = null; XAccessible xHelp = null;
try System.out.println("Try to get first entry of context menu...");
{ xHelp = oPopMenu.getAccessibleChild(0);
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");
}
if (xHelp == null) if (xHelp == null)
{ {
fail("first entry of context menu is NULL"); fail("first entry of context menu is NULL");
} }
XAccessibleContext xHelpCont = xHelp.getAccessibleContext(); XAccessibleContext xHelpCont = xHelp.getAccessibleContext();
if (xHelpCont == null) if (xHelpCont == null)
{ {
fail("No able to retrieve accessible context from first entry of context menu"); fail("No able to retrieve accessible context from first entry of context menu");
...@@ -270,16 +240,8 @@ public class CheckContextMenuInterceptor ...@@ -270,16 +240,8 @@ public class CheckContextMenuInterceptor
fail("First entry of context menu is not from context menu interceptor"); 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);
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");
}
} }
private void openContextMenu(XModel aModel) private void openContextMenu(XModel aModel)
......
...@@ -68,30 +68,23 @@ public class checkdispatchapi ...@@ -68,30 +68,23 @@ public class checkdispatchapi
@descr create an empty test frame, where we can load @descr create an empty test frame, where we can load
different components inside. different components inside.
*/ */
@Before public void before() @Before public void before() throws Exception
{ {
try // get uno service manager from global test environment
{ m_xMSF = getMSF();
// get uno service manager from global test environment
m_xMSF = getMSF();
db = new connectivity.tools.HsqlDatabase(m_xMSF); db = new connectivity.tools.HsqlDatabase(m_xMSF);
// create desktop // create desktop
m_xDesktop = UnoRuntime.queryInterface(XFrame.class, m_xMSF.createInstance("com.sun.star.frame.Desktop")); m_xDesktop = UnoRuntime.queryInterface(XFrame.class, m_xMSF.createInstance("com.sun.star.frame.Desktop"));
m_xFrame = impl_createNewFrame(); m_xFrame = impl_createNewFrame();
}
catch (java.lang.Throwable ex)
{
fail("Can't initialize test environment.");
}
} }
/** @short close the environment. /** @short close the environment.
*/ */
@After public void after() @After public void after() throws Exception
{ {
db.close(); db.close();
impl_closeFrame(m_xFrame); impl_closeFrame(m_xFrame);
...@@ -99,49 +92,49 @@ public class checkdispatchapi ...@@ -99,49 +92,49 @@ public class checkdispatchapi
} }
@Test public void checkDispatchInfoOfWriter() @Test public void checkDispatchInfoOfWriter() throws Exception
{ {
impl_checkDispatchInfoOfXXX("private:factory/swriter"); impl_checkDispatchInfoOfXXX("private:factory/swriter");
} }
@Test public void checkDispatchInfoOfCalc() @Test public void checkDispatchInfoOfCalc() throws Exception
{ {
impl_checkDispatchInfoOfXXX("private:factory/scalc"); impl_checkDispatchInfoOfXXX("private:factory/scalc");
} }
@Test public void checkDispatchInfoOfDraw() @Test public void checkDispatchInfoOfDraw() throws Exception
{ {
impl_checkDispatchInfoOfXXX("private:factory/sdraw"); impl_checkDispatchInfoOfXXX("private:factory/sdraw");
} }
@Test public void checkDispatchInfoOfImpress() @Test public void checkDispatchInfoOfImpress() throws Exception
{ {
impl_checkDispatchInfoOfXXX("private:factory/simpress"); impl_checkDispatchInfoOfXXX("private:factory/simpress");
} }
@Test public void checkDispatchInfoOfChart() @Test public void checkDispatchInfoOfChart() throws Exception
{ {
impl_checkDispatchInfoOfXXX("private:factory/schart"); impl_checkDispatchInfoOfXXX("private:factory/schart");
} }
@Test public void checkDispatchInfoOfMath() @Test public void checkDispatchInfoOfMath() throws Exception
{ {
impl_checkDispatchInfoOfXXX("private:factory/smath"); impl_checkDispatchInfoOfXXX("private:factory/smath");
} }
@Test public void checkDispatchInfoOfDataBase() @Test public void checkDispatchInfoOfDataBase() throws Exception
{ {
impl_checkDispatchInfoOfXXX("private:factory/sdatabase"); impl_checkDispatchInfoOfXXX("private:factory/sdatabase");
} }
@Test public void checkDispatchInfoOfBibliography() @Test public void checkDispatchInfoOfBibliography() throws Exception
{ {
impl_checkDispatchInfoOfXXX(".component:Bibliography/View1"); impl_checkDispatchInfoOfXXX(".component:Bibliography/View1");
} }
...@@ -153,19 +146,19 @@ public class checkdispatchapi ...@@ -153,19 +146,19 @@ public class checkdispatchapi
} }
@Test public void checkDispatchInfoOfTableDesign() @Test public void checkDispatchInfoOfTableDesign() throws Exception
{ {
callDatabaseDispatch(".component:DB/TableDesign"); callDatabaseDispatch(".component:DB/TableDesign");
} }
@Test public void checkDispatchInfoOfFormGridView() @Test public void checkDispatchInfoOfFormGridView() throws Exception
{ {
impl_checkDispatchInfoOfXXX(".component:DB/FormGridView"); impl_checkDispatchInfoOfXXX(".component:DB/FormGridView");
} }
@Test public void checkDispatchInfoOfDataSourceBrowser() @Test public void checkDispatchInfoOfDataSourceBrowser() throws Exception
{ {
impl_checkDispatchInfoOfXXX(".component:DB/DataSourceBrowser"); impl_checkDispatchInfoOfXXX(".component:DB/DataSourceBrowser");
} }
...@@ -200,21 +193,21 @@ public class checkdispatchapi ...@@ -200,21 +193,21 @@ public class checkdispatchapi
} }
@Test public void checkDispatchInfoOfBasic() @Test public void checkDispatchInfoOfBasic() throws Exception
{ {
Object aComponent = impl_createUNOComponent("com.sun.star.script.BasicIDE"); Object aComponent = impl_createUNOComponent("com.sun.star.script.BasicIDE");
impl_checkDispatchInfo(aComponent); impl_checkDispatchInfo(aComponent);
} }
@Test public void checkDispatchInfoOfStartModule() @Test public void checkDispatchInfoOfStartModule() throws Exception
{ {
Object aComponent = impl_createUNOComponent("com.sun.star.frame.StartModule"); Object aComponent = impl_createUNOComponent("com.sun.star.frame.StartModule");
impl_checkDispatchInfo(aComponent); impl_checkDispatchInfo(aComponent);
} }
public void checkInterceptorLifeTime() public void checkInterceptorLifeTime() throws Exception
{ {
// Note: It's important for the following test, that aInterceptor will be hold alive by the uno reference // Note: It's important for the following test, that aInterceptor will be hold alive by the uno reference
// xInterceptor. Otherwhise we can't check some internal states of aInterceptor at the end of this method, because // xInterceptor. Otherwhise we can't check some internal states of aInterceptor at the end of this method, because
...@@ -249,7 +242,7 @@ public class checkdispatchapi ...@@ -249,7 +242,7 @@ public class checkdispatchapi
} }
public void checkInterception() public void checkInterception() throws Exception
{ {
String[] lDisabledURLs = new String[] { ".uno:Open" }; String[] lDisabledURLs = new String[] { ".uno:Open" };
...@@ -273,7 +266,7 @@ public class checkdispatchapi ...@@ -273,7 +266,7 @@ public class checkdispatchapi
} }
private void impl_checkDispatchInfoOfXXX(String sXXX) private void impl_checkDispatchInfoOfXXX(String sXXX) throws Exception
{ {
XFrame xFrame = impl_createNewFrame(); XFrame xFrame = impl_createNewFrame();
impl_loadIntoFrame(xFrame, sXXX, null); impl_loadIntoFrame(xFrame, sXXX, null);
...@@ -284,7 +277,7 @@ public class checkdispatchapi ...@@ -284,7 +277,7 @@ public class checkdispatchapi
/** @short load an URL into the current test frame. /** @short load an URL into the current test frame.
*/ */
private void impl_loadIntoFrame(XFrame xFrame, String sURL, PropertyValue args[]) private void impl_loadIntoFrame(XFrame xFrame, String sURL, PropertyValue args[]) throws Exception
{ {
XComponentLoader xLoader = UnoRuntime.queryInterface(XComponentLoader.class, xFrame); XComponentLoader xLoader = UnoRuntime.queryInterface(XComponentLoader.class, xFrame);
if (xLoader == null) if (xLoader == null)
...@@ -292,15 +285,7 @@ public class checkdispatchapi ...@@ -292,15 +285,7 @@ public class checkdispatchapi
fail("Frame does not provide required interface XComponentLoader."); fail("Frame does not provide required interface XComponentLoader.");
} }
XComponent xDoc = null; XComponent xDoc = xLoader.loadComponentFromURL(sURL, "_self", 0, args);
try
{
xDoc = xLoader.loadComponentFromURL(sURL, "_self", 0, args);
}
catch (java.lang.Throwable ex)
{
xDoc = null;
}
if (xDoc == null) if (xDoc == null)
{ {
...@@ -334,7 +319,7 @@ public class checkdispatchapi ...@@ -334,7 +319,7 @@ public class checkdispatchapi
/** @short check the interface XDispatchInformationProvider /** @short check the interface XDispatchInformationProvider
at the specified component. at the specified component.
*/ */
private void impl_checkDispatchInfo(Object aComponent) private void impl_checkDispatchInfo(Object aComponent) throws Exception
{ {
XDispatchInformationProvider xInfoProvider = UnoRuntime.queryInterface(XDispatchInformationProvider.class, aComponent); XDispatchInformationProvider xInfoProvider = UnoRuntime.queryInterface(XDispatchInformationProvider.class, aComponent);
if (xInfoProvider == null) if (xInfoProvider == null)
...@@ -344,86 +329,62 @@ public class checkdispatchapi ...@@ -344,86 +329,62 @@ public class checkdispatchapi
return; return;
} }
try short[] lGroups = xInfoProvider.getSupportedCommandGroups();
int c1 = lGroups.length;
int i1 = 0;
for (i1 = 0; i1 < c1; ++i1)
{ {
short[] lGroups = xInfoProvider.getSupportedCommandGroups(); short nGroup = lGroups[i1];
int c1 = lGroups.length; DispatchInformation[] lInfos = xInfoProvider.getConfigurableDispatchInformation(nGroup);
int i1 = 0; int c2 = lInfos.length;
for (i1 = 0; i1 < c1; ++i1) int i2 = 0;
// check for empty lists
// Warning
if (lInfos.length < 1)
{ {
short nGroup = lGroups[i1]; System.out.println("Warning:\tCould not get any DispatchInformation for group [" + nGroup + "].");
DispatchInformation[] lInfos = xInfoProvider.getConfigurableDispatchInformation(nGroup); }
int c2 = lInfos.length;
int i2 = 0; // check for duplicates (and by the way, if the info item match the requested group)
HashMap<String, String> aCheckMap = new HashMap<String, String>(c2);
// check for empty lists for (i2 = 0; i2 < c2; ++i2)
// Warning {
if (lInfos.length < 1) DispatchInformation aInfo = lInfos[i2];
if (aInfo.GroupId != nGroup)
{ {
System.out.println("Warning:\tCould not get any DispatchInformation for group [" + nGroup + "]."); // Error
fail("At least one DispatchInformation item does not match the requested group.\n\trequested group=[" + nGroup
+ "] returned groupd=[" + aInfo.GroupId + "] command=\"" + aInfo.Command + "\""); // true => dont break this test
continue;
} }
// check for duplicates (and by the way, if the info item match the requested group) if (aCheckMap.containsKey(aInfo.Command))
HashMap<String, String> aCheckMap = new HashMap<String, String>(c2);
for (i2 = 0; i2 < c2; ++i2)
{ {
DispatchInformation aInfo = lInfos[i2]; // Error
if (aInfo.GroupId != nGroup) fail("Found a duplicate item: group=[" + aInfo.GroupId + "] command=\"" + aInfo.Command + "\""); // true => dont break this test
{ continue;
// Error
fail("At least one DispatchInformation item does not match the requested group.\n\trequested group=[" + nGroup
+ "] returned groupd=[" + aInfo.GroupId + "] command=\"" + aInfo.Command + "\""); // true => dont break this test
continue;
}
if (aCheckMap.containsKey(aInfo.Command))
{
// Error
fail("Found a duplicate item: group=[" + aInfo.GroupId + "] command=\"" + aInfo.Command + "\""); // true => dont break this test
continue;
}
aCheckMap.put(aInfo.Command, aInfo.Command);
System.out.println("\t[" + aInfo.GroupId + "] \"" + aInfo.Command + "\"");
} }
aCheckMap.put(aInfo.Command, aInfo.Command);
System.out.println("\t[" + aInfo.GroupId + "] \"" + aInfo.Command + "\"");
} }
} }
catch (java.lang.Throwable ex)
{
fail("Exception caught during using XDispatchInformationProvider.");
}
} }
private synchronized XFrame impl_createNewFrame() private synchronized XFrame impl_createNewFrame()
{ {
XFrame xFrame = null; XFrame xFrame = m_xDesktop.findFrame("_blank", 0);
xFrame.getContainerWindow().setVisible(true);
try
{
xFrame = m_xDesktop.findFrame("_blank", 0);
xFrame.getContainerWindow().setVisible(true);
}
catch (java.lang.Throwable ex)
{
fail("Could not create the frame instance.");
}
return xFrame; return xFrame;
} }
private synchronized void impl_closeFrame(XFrame xFrame) private synchronized void impl_closeFrame(XFrame xFrame) throws Exception
{ {
XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, xFrame); XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, xFrame);
try xClose.close(false);
{
xClose.close(false);
}
catch (com.sun.star.util.CloseVetoException exVeto)
{
fail("Test frame couldn't be closed successfully.");
}
} }
private XMultiServiceFactory getMSF() private XMultiServiceFactory getMSF()
......
...@@ -25,7 +25,6 @@ import org.junit.AfterClass; ...@@ -25,7 +25,6 @@ import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.openoffice.test.OfficeConnection; import org.openoffice.test.OfficeConnection;
import static org.junit.Assert.*;
/** /**
...@@ -36,19 +35,12 @@ import static org.junit.Assert.*; ...@@ -36,19 +35,12 @@ import static org.junit.Assert.*;
public class GetServiceWhileDisposingOffice public class GetServiceWhileDisposingOffice
{ {
@Test public void checkServiceWhileDisposing() @Test public void checkServiceWhileDisposing() throws Exception
{ {
XMultiServiceFactory xMSF = getMSF(); XMultiServiceFactory xMSF = getMSF();
XDesktop xDesktop = null; XDesktop xDesktop = null;
try xDesktop = UnoRuntime.queryInterface(XDesktop.class, xMSF.createInstance("com.sun.star.frame.Desktop"));
{
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.");
}
int step = 0; int step = 0;
try try
{ {
...@@ -63,11 +55,6 @@ public class GetServiceWhileDisposingOffice ...@@ -63,11 +55,6 @@ public class GetServiceWhileDisposingOffice
{ {
System.out.println("DisposedException in step: " + step); System.out.println("DisposedException in step: " + step);
} }
catch (Exception e)
{
fail(e.getMessage());
}
} }
......
...@@ -114,33 +114,18 @@ public class CheckXComponentLoader ...@@ -114,33 +114,18 @@ public class CheckXComponentLoader
@descr Use either a component loader from desktop or @descr Use either a component loader from desktop or
from frame from frame
*/ */
@Before public void before() @Before public void before() throws Exception
{ {
// get uno service manager from global test environment // get uno service manager from global test environment
/* points to the global uno service manager. */ /* points to the global uno service manager. */
XMultiServiceFactory xMSF = getMSF(); XMultiServiceFactory xMSF = getMSF();
// create stream provider // create stream provider
try m_xStreamProvider = UnoRuntime.queryInterface(XSimpleFileAccess.class, xMSF.createInstance("com.sun.star.ucb.SimpleFileAccess"));
{
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.");
}
// create desktop instance // create desktop instance
/* provides XComponentLoader interface. */ /* provides XComponentLoader interface. */
XFrame xDesktop = null; XFrame xDesktop = UnoRuntime.queryInterface(XFrame.class, xMSF.createInstance("com.sun.star.frame.Desktop"));
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.");
}
// create frame instance // create frame instance
m_xFrame = xDesktop.findFrame("testFrame_componentLoader", m_xFrame = xDesktop.findFrame("testFrame_componentLoader",
...@@ -162,49 +147,37 @@ public class CheckXComponentLoader ...@@ -162,49 +147,37 @@ public class CheckXComponentLoader
m_lTestFiles = new ArrayList<String>(); m_lTestFiles = new ArrayList<String>();
final String sTestDocURL = OfficeFileUrl.getAbsolute(new File("testdocuments")); final String sTestDocURL = OfficeFileUrl.getAbsolute(new File("testdocuments"));
m_sTestDocPath = graphical.FileHelper.getSystemPathFromFileURL(sTestDocURL); 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); File aFile = lList.next();
List<File> lDirContent = URLHelper.getSystemFilesFromDir(aBaseDir.getPath());
Iterator<File> lList = lDirContent.iterator();
int nBasePathLength = m_sTestDocPath.length();
while(lList.hasNext())
{
File aFile = lList.next();
// ignore broken links and directories at all // ignore broken links and directories at all
if ( if (
(!aFile.exists()) || (!aFile.exists()) ||
(!aFile.isFile()) (!aFile.isFile())
) )
{ {
continue; continue;
} }
String sCompletePath = aFile.getAbsolutePath(); String sCompletePath = aFile.getAbsolutePath();
String sSubPath = sCompletePath.substring(nBasePathLength); String sSubPath = sCompletePath.substring(nBasePathLength);
m_lTestFiles.add(sSubPath); m_lTestFiles.add(sSubPath);
}
}
catch(java.lang.Throwable ex)
{
fail("Couldn't find test documents.");
} }
} }
/** @short close the environment. /** @short close the environment.
*/ */
@After public void after() @After public void after() throws Exception
{ {
XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, m_xFrame); XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, m_xFrame);
try xClose.close(false);
{
xClose.close(false);
}
catch(com.sun.star.util.CloseVetoException exVeto)
{ fail("Test frame couldn't be closed successfully."); }
m_xFrame = null; m_xFrame = null;
m_xLoader = null; m_xLoader = null;
...@@ -281,7 +254,7 @@ public class CheckXComponentLoader ...@@ -281,7 +254,7 @@ public class CheckXComponentLoader
String sSourceURL, String sSourceURL,
String sTargetURL, String sTargetURL,
String sFilter , String sFilter ,
String sPassword ) String sPassword ) throws Exception
{ {
PropertyValue[] lLoadProps = new PropertyValue[1]; PropertyValue[] lLoadProps = new PropertyValue[1];
...@@ -304,24 +277,17 @@ public class CheckXComponentLoader ...@@ -304,24 +277,17 @@ public class CheckXComponentLoader
lSaveProps[2].Value = Boolean.TRUE; lSaveProps[2].Value = Boolean.TRUE;
XComponent xDoc = null; XComponent xDoc = null;
try // load it
{ xDoc = xLoader.loadComponentFromURL(sSourceURL, "_blank", 0, lLoadProps);
// load it assertNotNull("Could create office document, which should be saved as temp one.", xDoc);
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 // save it as temp file
XStorable xStore = UnoRuntime.queryInterface(XStorable.class, xDoc); XStorable xStore = UnoRuntime.queryInterface(XStorable.class, xDoc);
xStore.storeAsURL(sTargetURL, lSaveProps); xStore.storeAsURL(sTargetURL, lSaveProps);
// Dont forget to close this file. Otherwise the temp file is locked! // Dont forget to close this file. Otherwise the temp file is locked!
XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, xDoc); XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, xDoc);
xClose.close(false); xClose.close(false);
}
catch(java.lang.Throwable ex)
{
fail("Could not create temp office document.");
}
} }
...@@ -331,7 +297,7 @@ public class CheckXComponentLoader ...@@ -331,7 +297,7 @@ public class CheckXComponentLoader
as password for the ftp connection, as password for the ftp connection,
or - if none given a default one. 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); String sTempFile = impl_getTempFileName(m_sTempPath, SUFFIX_PASSWORD_TEMPFILE, PREFIX_PASSWORD_TEMPFILE);
File aTestFile = new File(sTempFile); File aTestFile = new File(sTempFile);
...@@ -363,7 +329,7 @@ public class CheckXComponentLoader ...@@ -363,7 +329,7 @@ public class CheckXComponentLoader
* Check URL encoding. The first filename that matches "*.sxw" * Check URL encoding. The first filename that matches "*.sxw"
* is used as source for several encodings. * is used as source for several encodings.
*/ */
@Test public void checkURLEncoding() { @Test public void checkURLEncoding() throws Exception {
PropertyValue[] lProps = new PropertyValue[1]; PropertyValue[] lProps = new PropertyValue[1];
lProps[0] = new PropertyValue(); lProps[0] = new PropertyValue();
...@@ -409,28 +375,23 @@ public class CheckXComponentLoader ...@@ -409,28 +375,23 @@ public class CheckXComponentLoader
}; };
for (int i = 0; i < sEncoding.length; i = i + 2) { for (int i = 0; i < sEncoding.length; i = i + 2) {
try { String encURL = new String(baURL, sEncoding[i]);
String encURL = new String(baURL, sEncoding[i]); System.out.println("ENC[" + sEncoding[i] + "]");
System.out.println("ENC[" + sEncoding[i] + "]");
if (sEncoding[i + 1].equals("TRUE")) {
if (sEncoding[i + 1].equals("TRUE")) { loadURL(m_xLoader, RESULT_VALID_DOC, encURL, "_blank", 0,
loadURL(m_xLoader, RESULT_VALID_DOC, encURL, "_blank", 0, lProps);
lProps); } else {
} else { //with cws_loadenv01 changed to IllegalArgumentException
//with cws_loadenv01 changed to IllegalArgumentException loadURL(m_xLoader, RESULT_ILLEGALARGUMENTEXCEPTION, encURL, "_blank", 0,
loadURL(m_xLoader, RESULT_ILLEGALARGUMENTEXCEPTION, encURL, "_blank", 0, lProps);
lProps);
}
} catch (java.io.UnsupportedEncodingException e) {
fail("Unsopported Encoding: " + sEncoding[i] +
"\n Not able to test encoding on this platform.");
} }
} }
} }
/** TODo document me /** TODo document me
*/ */
@Test public void checkStreamLoading() @Test public void checkStreamLoading() throws Exception
{ {
PropertyValue[] lProps = new PropertyValue[2]; PropertyValue[] lProps = new PropertyValue[2];
...@@ -447,19 +408,12 @@ public class CheckXComponentLoader ...@@ -447,19 +408,12 @@ public class CheckXComponentLoader
File aFile = new File(m_sTestDocPath, aSnapshot.next()); File aFile = new File(m_sTestDocPath, aSnapshot.next());
String sURL = URLHelper.getFileURLFromSystemPath(aFile); String sURL = URLHelper.getFileURLFromSystemPath(aFile);
try XInputStream xStream = m_xStreamProvider.openFileRead(sURL);
{ lProps[1].Value = xStream;
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.");
}
// check different version of "private:stream" URL! // check different version of "private:stream" URL!
loadURL(m_xLoader, RESULT_VALID_DOC, "private:stream" , "_blank", 0, lProps); loadURL(m_xLoader, RESULT_VALID_DOC, "private:stream" , "_blank", 0, lProps);
} }
} }
/** /**
......
...@@ -95,7 +95,7 @@ public class PathSettingsTest ...@@ -95,7 +95,7 @@ public class PathSettingsTest
* This methods sets the 'aPathSettings' and 'xPropertyInfoOfPathSettings' variables. * This methods sets the 'aPathSettings' and 'xPropertyInfoOfPathSettings' variables.
*/ */
@Before @Before
public void before() public void before() throws Exception
{ {
try try
{ {
...@@ -127,10 +127,6 @@ public class PathSettingsTest ...@@ -127,10 +127,6 @@ public class PathSettingsTest
System.out.println(e.getClass().getName()); System.out.println(e.getClass().getName());
System.out.println("Message: " + e.getMessage()); System.out.println("Message: " + e.getMessage());
} }
catch (Exception e)
{
fail("What exception?");
}
} }
private String convertToString(Object o) private String convertToString(Object o)
......
...@@ -18,9 +18,20 @@ ...@@ -18,9 +18,20 @@
package complex.reportdesign; package complex.reportdesign;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import helper.URLHelper;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
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 com.sun.star.beans.PropertyValue; import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet; import com.sun.star.beans.XPropertySet;
import com.sun.star.container.XNameAccess; import com.sun.star.container.XNameAccess;
...@@ -28,28 +39,21 @@ import com.sun.star.frame.XComponentLoader; ...@@ -28,28 +39,21 @@ import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XDesktop; import com.sun.star.frame.XDesktop;
import com.sun.star.frame.XModel; import com.sun.star.frame.XModel;
import com.sun.star.frame.XStorable; import com.sun.star.frame.XStorable;
import com.sun.star.io.IOException;
import com.sun.star.lang.XComponent; import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.sdb.XDocumentDataSource; import com.sun.star.sdb.XDocumentDataSource;
import com.sun.star.sdb.XOfficeDatabaseDocument; import com.sun.star.sdb.XOfficeDatabaseDocument;
import com.sun.star.sdb.XReportDocumentsSupplier; import com.sun.star.sdb.XReportDocumentsSupplier;
import com.sun.star.sdb.application.XDatabaseDocumentUI; import com.sun.star.sdb.application.XDatabaseDocumentUI;
import com.sun.star.uno.RuntimeException;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface; import com.sun.star.uno.XInterface;
import com.sun.star.util.CloseVetoException;
import com.sun.star.util.XCloseable; import com.sun.star.util.XCloseable;
import helper.URLHelper;
import convwatch.DB; import convwatch.DB;
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.*;
class PropertySetHelper class PropertySetHelper
{ {
XPropertySet m_xPropertySet; XPropertySet m_xPropertySet;
...@@ -137,22 +141,14 @@ public class ReportDesignerTest ...@@ -137,22 +141,14 @@ public class ReportDesignerTest
} }
private XDesktop m_xDesktop = null; private XDesktop m_xDesktop = null;
public XDesktop getXDesktop() public XDesktop getXDesktop() throws com.sun.star.uno.Exception
{ {
if (m_xDesktop == null) if (m_xDesktop == null)
{ {
try
{
XInterface xInterface = (XInterface) getMSF().createInstance( "com.sun.star.frame.Desktop" ); XInterface xInterface = (XInterface) getMSF().createInstance( "com.sun.star.frame.Desktop" );
m_xDesktop = UnoRuntime.queryInterface(XDesktop.class, xInterface); m_xDesktop = UnoRuntime.queryInterface(XDesktop.class, xInterface);
assertNotNull("Can't get XDesktop", m_xDesktop); assertNotNull("Can't get XDesktop", m_xDesktop);
}
catch (com.sun.star.uno.Exception e)
{
System.out.println("ERROR: uno.Exception caught");
System.out.println("Message: " + e.getMessage());
}
} }
return m_xDesktop; return m_xDesktop;
} }
...@@ -177,7 +173,7 @@ public class ReportDesignerTest ...@@ -177,7 +173,7 @@ public class ReportDesignerTest
private static final int WRITER = 1; private static final int WRITER = 1;
private static final int CALC = 2; private static final int CALC = 2;
@Test public void firsttest() @Test public void firsttest() throws Exception
{ {
// -------------------- preconditions, try to find an office -------------------- // -------------------- preconditions, try to find an office --------------------
...@@ -206,7 +202,7 @@ public class ReportDesignerTest ...@@ -206,7 +202,7 @@ public class ReportDesignerTest
} }
private void startTestForFile(String _sDocument, int _nType) private void startTestForFile(String _sDocument, int _nType) throws Exception
{ {
FileURL aFileURL = new FileURL(_sDocument); FileURL aFileURL = new FileURL(_sDocument);
assertTrue("Test File doesn't '" + _sDocument + "'exist.", aFileURL.exists()); assertTrue("Test File doesn't '" + _sDocument + "'exist.", aFileURL.exists());
...@@ -219,55 +215,48 @@ public class ReportDesignerTest ...@@ -219,55 +215,48 @@ public class ReportDesignerTest
assertNotNull("Can't load document ", xDocComponent); assertNotNull("Can't load document ", xDocComponent);
try XInterface x = (XInterface)getMSF().createInstance("com.sun.star.sdb.DatabaseContext");
{ assertNotNull("can't create instance of com.sun.star.sdb.DatabaseContext", x);
XInterface x = (XInterface)getMSF().createInstance("com.sun.star.sdb.DatabaseContext"); System.out.println("createInstance com.sun.star.sdb.DatabaseContext done");
assertNotNull("can't create instance of com.sun.star.sdb.DatabaseContext", x);
System.out.println("createInstance com.sun.star.sdb.DatabaseContext done");
XNameAccess xNameAccess = UnoRuntime.queryInterface(XNameAccess.class, x); XNameAccess xNameAccess = UnoRuntime.queryInterface(XNameAccess.class, x);
showElements(xNameAccess); showElements(xNameAccess);
Object aObj = xNameAccess.getByName(sFileURL); Object aObj = xNameAccess.getByName(sFileURL);
XDocumentDataSource xDataSource = UnoRuntime.queryInterface(XDocumentDataSource.class, aObj); XDocumentDataSource xDataSource = UnoRuntime.queryInterface(XDocumentDataSource.class, aObj);
XOfficeDatabaseDocument xOfficeDBDoc = xDataSource.getDatabaseDocument(); XOfficeDatabaseDocument xOfficeDBDoc = xDataSource.getDatabaseDocument();
assertNotNull("can't access DatabaseDocument", xOfficeDBDoc); assertNotNull("can't access DatabaseDocument", xOfficeDBDoc);
XModel xDBSource = UnoRuntime.queryInterface(XModel.class, xOfficeDBDoc); XModel xDBSource = UnoRuntime.queryInterface(XModel.class, xOfficeDBDoc);
Object aController = xDBSource.getCurrentController(); Object aController = xDBSource.getCurrentController();
assertNotNull("Controller of xOfficeDatabaseDocument is empty!", aController); assertNotNull("Controller of xOfficeDatabaseDocument is empty!", aController);
XDatabaseDocumentUI aDBDocUI = UnoRuntime.queryInterface(XDatabaseDocumentUI.class, aController); XDatabaseDocumentUI aDBDocUI = UnoRuntime.queryInterface(XDatabaseDocumentUI.class, aController);
/* boolean isConnect = */ /* boolean isConnect = */
// TODO: throws an exception in DEV300m78 // TODO: throws an exception in DEV300m78
aDBDocUI.connect(); aDBDocUI.connect();
Object aActiveConnectionObj = aDBDocUI.getActiveConnection(); Object aActiveConnectionObj = aDBDocUI.getActiveConnection();
assertNotNull("ActiveConnection is empty", aActiveConnectionObj); assertNotNull("ActiveConnection is empty", aActiveConnectionObj);
XReportDocumentsSupplier xSupplier = UnoRuntime.queryInterface(XReportDocumentsSupplier.class, xOfficeDBDoc); XReportDocumentsSupplier xSupplier = UnoRuntime.queryInterface(XReportDocumentsSupplier.class, xOfficeDBDoc);
xNameAccess = xSupplier.getReportDocuments(); xNameAccess = xSupplier.getReportDocuments();
assertNotNull("xOfficeDatabaseDocument returns no Report Document", xNameAccess); assertNotNull("xOfficeDatabaseDocument returns no Report Document", xNameAccess);
showElements(xNameAccess); showElements(xNameAccess);
ArrayList<PropertyValue> aPropertyList = new ArrayList<PropertyValue>(); ArrayList<PropertyValue> aPropertyList = new ArrayList<PropertyValue>();
PropertyValue aActiveConnection = new PropertyValue(); PropertyValue aActiveConnection = new PropertyValue();
aActiveConnection.Name = "ActiveConnection"; aActiveConnection.Name = "ActiveConnection";
aActiveConnection.Value = aActiveConnectionObj; aActiveConnection.Value = aActiveConnectionObj;
aPropertyList.add(aActiveConnection); aPropertyList.add(aActiveConnection);
loadAndStoreReports(xNameAccess, aPropertyList, _nType); loadAndStoreReports(xNameAccess, aPropertyList, _nType);
createDBEntry(); createDBEntry();
}
catch(com.sun.star.uno.Exception e)
{
fail("ERROR: Exception caught" + e.getMessage());
}
// Close the document // Close the document
closeComponent(xDocComponent); closeComponent(xDocComponent);
} }
private String getDocumentPoolName(int _nType) private String getDocumentPoolName(int _nType)
...@@ -295,7 +284,7 @@ public class ReportDesignerTest ...@@ -295,7 +284,7 @@ public class ReportDesignerTest
// sSpecial); // sSpecial);
} }
private void loadAndStoreReports(XNameAccess _xNameAccess, ArrayList<PropertyValue> _aPropertyList, int _nType) private void loadAndStoreReports(XNameAccess _xNameAccess, ArrayList<PropertyValue> _aPropertyList, int _nType) throws Exception
{ {
if (_xNameAccess != null) if (_xNameAccess != null)
{ {
...@@ -365,7 +354,7 @@ public class ReportDesignerTest ...@@ -365,7 +354,7 @@ public class ReportDesignerTest
/* /*
store given _xComponent under the given Name in DOC_COMPARATOR_INPUTPATH store given _xComponent under the given Name in DOC_COMPARATOR_INPUTPATH
*/ */
private void storeComponent(String _sName, Object _xComponent, int _nType) private void storeComponent(String _sName, Object _xComponent, int _nType) throws Exception
{ {
String sOutputPath = getOutputPath(); String sOutputPath = getOutputPath();
...@@ -398,59 +387,26 @@ public class ReportDesignerTest ...@@ -398,59 +387,26 @@ public class ReportDesignerTest
if (aStorable != null) if (aStorable != null)
{ {
System.out.println("store document as URL: '" + sOutputURL + "'"); System.out.println("store document as URL: '" + sOutputURL + "'");
try aStorable.storeAsURL(sOutputURL, PropertyHelper.createPropertyValueArrayFormArrayList(aPropertyList));
{
aStorable.storeAsURL(sOutputURL, PropertyHelper.createPropertyValueArrayFormArrayList(aPropertyList));
}
catch (com.sun.star.io.IOException e)
{
System.out.println("ERROR: Exception caught");
System.out.println("Can't write document URL: '" + sOutputURL + "'");
System.out.println("Message: " + e.getMessage());
}
} }
} }
private XComponent loadComponent(String _sName, Object _xComponent, ArrayList<PropertyValue> _aPropertyList) private XComponent loadComponent(String _sName, Object _xComponent, ArrayList<PropertyValue> _aPropertyList) throws RuntimeException, IOException
{ {
XComponent xDocComponent = null; XComponent xDocComponent = null;
XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, _xComponent); XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, _xComponent);
try PropertyValue[] aLoadProperties = PropertyHelper.createPropertyValueArrayFormArrayList(_aPropertyList);
{ System.out.println("Load component: '" + _sName + "'");
PropertyValue[] aLoadProperties = PropertyHelper.createPropertyValueArrayFormArrayList(_aPropertyList); xDocComponent = xComponentLoader.loadComponentFromURL(_sName, "_blank", 0, aLoadProperties);
System.out.println("Load component: '" + _sName + "'");
xDocComponent = xComponentLoader.loadComponentFromURL(_sName, "_blank", 0, aLoadProperties);
}
catch (com.sun.star.io.IOException e)
{
System.out.println("ERROR: Exception caught");
System.out.println("Can't load document '" + _sName + "'");
System.out.println("Message: " + e.getMessage());
}
catch (com.sun.star.lang.IllegalArgumentException e)
{
System.out.println("ERROR: Exception caught");
System.out.println("Illegal Arguments given to loadComponentFromURL.");
System.out.println("Message: " + e.getMessage());
}
return xDocComponent; return xDocComponent;
} }
private void closeComponent(XComponent _xDoc) private void closeComponent(XComponent _xDoc) throws CloseVetoException
{ {
// Close the document // Close the document
XCloseable xCloseable = UnoRuntime.queryInterface(XCloseable.class, _xDoc); XCloseable xCloseable = UnoRuntime.queryInterface(XCloseable.class, _xDoc);
try xCloseable.close(true);
{
xCloseable.close(true);
}
catch (com.sun.star.util.CloseVetoException e)
{
System.out.println("ERROR: CloseVetoException caught");
System.out.println("CloseVetoException occurred. Can't close document.");
System.out.println("Message: " + e.getMessage());
}
} }
......
...@@ -74,18 +74,11 @@ public class UnitConversion ...@@ -74,18 +74,11 @@ public class UnitConversion
*/ */
private void checkSize(com.sun.star.awt.Size _aSize, short _aMeasureUnit, String _sEinheit) 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:");
com.sun.star.awt.Size aSizeIn = m_xConversion.convertSizeToLogic(_aSize, _aMeasureUnit); System.out.println("Width:" + aSizeIn.Width + " " + _sEinheit);
System.out.println("Window size:"); System.out.println("Height:" + aSizeIn.Height + " " + _sEinheit);
System.out.println("Width:" + aSizeIn.Width + " " + _sEinheit); System.out.println("");
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());
}
} }
/** /**
...@@ -139,77 +132,56 @@ public class UnitConversion ...@@ -139,77 +132,56 @@ public class UnitConversion
m_xConversion = UnoRuntime.queryInterface(XUnitConversion.class, xWindowPeer); m_xConversion = UnoRuntime.queryInterface(XUnitConversion.class, xWindowPeer);
// try to get the position of the window in 1/100mm with the XUnitConversion method // 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:");
com.sun.star.awt.Point aPointInMM_100TH = m_xConversion.convertPointToLogic(aPoint, com.sun.star.util.MeasureUnit.MM_100TH); System.out.println("X:" + aPointInMM_100TH.X + " 1/100mm");
System.out.println("Window position:"); System.out.println("Y:" + aPointInMM_100TH.Y + " 1/100mm");
System.out.println("X:" + aPointInMM_100TH.X + " 1/100mm"); System.out.println("");
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());
}
// try to get the size of the window in 1/100mm with the XUnitConversion method // 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_100TH = null;
com.sun.star.awt.Size aSizeInMM_10TH = 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:");
aSizeInMM_100TH = m_xConversion.convertSizeToLogic(aSize, com.sun.star.util.MeasureUnit.MM_100TH); System.out.println("Width:" + aSizeInMM_100TH.Width + " 1/100mm");
System.out.println("Window size:"); System.out.println("Height:" + aSizeInMM_100TH.Height + " 1/100mm");
System.out.println("Width:" + aSizeInMM_100TH.Width + " 1/100mm"); System.out.println("");
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
// 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:");
aSizeInMM_10TH = m_xConversion.convertSizeToLogic(aSize, com.sun.star.util.MeasureUnit.MM_10TH); System.out.println("Width:" + aSizeInMM_10TH.Width + " 1/10mm");
System.out.println("Window size:"); System.out.println("Height:" + aSizeInMM_10TH.Height + " 1/10mm");
System.out.println("Width:" + aSizeInMM_10TH.Width + " 1/10mm"); System.out.println("");
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);
// check the size with a delta which must be smaller a given difference assertTrue("Size.Height not correct", delta(aSizeInMM_100TH.Height, aSizeInMM_10TH.Height * 10) < 10);
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");
// new checkSize(aSize, com.sun.star.util.MeasureUnit.APPFONT, "appfont");
checkSize(aSize, com.sun.star.util.MeasureUnit.PIXEL, "pixel"); checkSize(aSize, com.sun.star.util.MeasureUnit.SYSFONT, "sysfont");
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");
// simply check some more parameters checkSize(aSize, com.sun.star.util.MeasureUnit.CM, "cm");
checkSize(aSize, com.sun.star.util.MeasureUnit.MM, "mm"); checkSize(aSize, com.sun.star.util.MeasureUnit.INCH_1000TH, "1/1000inch");
checkSize(aSize, com.sun.star.util.MeasureUnit.CM, "cm"); checkSize(aSize, com.sun.star.util.MeasureUnit.INCH_100TH, "1/100inch");
checkSize(aSize, com.sun.star.util.MeasureUnit.INCH_1000TH, "1/1000inch"); checkSize(aSize, com.sun.star.util.MeasureUnit.INCH_10TH, "1/10inch");
checkSize(aSize, com.sun.star.util.MeasureUnit.INCH_100TH, "1/100inch"); checkSize(aSize, com.sun.star.util.MeasureUnit.INCH, "inch");
checkSize(aSize, com.sun.star.util.MeasureUnit.INCH_10TH, "1/10inch"); checkSize(aSize, com.sun.star.util.MeasureUnit.POINT, "point");
checkSize(aSize, com.sun.star.util.MeasureUnit.INCH, "inch"); checkSize(aSize, com.sun.star.util.MeasureUnit.TWIP, "twip");
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());
}
// convert the 1/100mm window size back to pixel // 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:");
com.sun.star.awt.Size aNewSize = m_xConversion.convertSizeToPixel(aSizeInMM_100TH, com.sun.star.util.MeasureUnit.MM_100TH); System.out.println("Width:" + aNewSize.Width + " pixel");
System.out.println("Window size:"); System.out.println("Height:" + aNewSize.Height + " pixel");
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);
// 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());
}
// close the window. // close the window.
// IMHO a little bit stupid, but the XWindow doesn't support a XCloseable interface // IMHO a little bit stupid, but the XWindow doesn't support a XCloseable interface
......
...@@ -163,7 +163,7 @@ public class CheckMemoryUsage ...@@ -163,7 +163,7 @@ public class CheckMemoryUsage
* for each given document type. * for each given document type.
*/ */
@Test @Test
public void loadAndSaveDocuments() public void loadAndSaveDocuments() throws Exception
{ {
int nOk = 0; int nOk = 0;
int nRunThrough = 0; int nRunThrough = 0;
...@@ -248,7 +248,7 @@ public class CheckMemoryUsage ...@@ -248,7 +248,7 @@ public class CheckMemoryUsage
/** /**
* load and save exact one document * 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); System.out.println("Document: " + _sDocument);
XComponent xComponent = DesktopTools.loadDoc(getMSF(), _sDocument, null); XComponent xComponent = DesktopTools.loadDoc(getMSF(), _sDocument, null);
...@@ -277,15 +277,7 @@ public class CheckMemoryUsage ...@@ -277,15 +277,7 @@ public class CheckMemoryUsage
} }
// close the doc // close the doc
XCloseable xCloseable = UnoRuntime.queryInterface(XCloseable.class, xStorable); XCloseable xCloseable = UnoRuntime.queryInterface(XCloseable.class, xStorable);
try xCloseable.close(true);
{
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.");
}
} }
else else
{ {
......
...@@ -282,37 +282,15 @@ public class PersistentWindowTest ...@@ -282,37 +282,15 @@ public class PersistentWindowTest
return docHandle; return docHandle;
} }
private boolean connect() private boolean connect() throws Exception
{ {
try connection.setUp();
{
connection.setUp();
}
catch (InterruptedException e)
{
fail("can't connect.");
}
catch (Exception e)
{
fail("can't connect.");
}
return true; return true;
} }
private boolean disconnect() private boolean disconnect() throws Exception
{ {
try connection.tearDown();
{
connection.tearDown();
}
catch (InterruptedException e)
{
fail("can't disconnect.");
}
catch (Exception e)
{
fail("can't disconnect.");
}
return true; 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