Kaydet (Commit) fa0f14fa authored tarafından Tomas O'Connor's avatar Tomas O'Connor

Make interface tests generic.

üst 511b0590
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: _XFunction.java,v $ * $RCSfile: _XFunction.java,v $
* *
* $Revision: 1.1 $ * $Revision: 1.2 $
* *
* last change:$Date: 2002-11-20 14:29:36 $ * last change:$Date: 2002-12-10 14:12:05 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -73,6 +73,10 @@ import com.sun.star.beans.XPropertySet; ...@@ -73,6 +73,10 @@ import com.sun.star.beans.XPropertySet;
import java.io.PrintWriter; import java.io.PrintWriter;
import lib.MultiMethodTest; import lib.MultiMethodTest;
import lib.StatusException; import lib.StatusException;
import lib.Parameters;
import java.util.Collection;
import java.util.Iterator;
public class _XFunction extends MultiMethodTest { public class _XFunction extends MultiMethodTest {
...@@ -84,41 +88,69 @@ public class _XFunction extends MultiMethodTest { ...@@ -84,41 +88,69 @@ public class _XFunction extends MultiMethodTest {
} }
public void _invoke() { public void _invoke() {
boolean result = true;
Collection c =
(Collection) tEnv.getObjRelation("_invoke");
Iterator tests;
if (c != null) {
tests = c.iterator();
while (tests.hasNext()) {
result &= runInvokeTest((Parameters)tests.next());
}
}
else {
result = false;
}
tRes.tested("invoke()", result);
}
private boolean runInvokeTest(Parameters testdata) {
String description = testdata.get("description");
String expected = testdata.get("expected");
String output = "";
log.println(testdata.get("description"));
try{ try{
System.out.println("Here we are"); Object[] aParams = new Object[0];
Object[] aParams = new Object[0]; short[][] aOutParamIndex = new short[1][];
short[][] aOutParamIndex = new short[1][]; aOutParamIndex[0] = new short[0];
aOutParamIndex[0] = new short[0]; Object[][] aOutParam = new Object[1][];
Object[][] aOutParam = new Object[1][]; aOutParam[0] = new Object[0];
aOutParam[0] = new Object[0];
oObj.invoke( aParams, aOutParamIndex, aOutParam ); oObj.invoke( aParams, aOutParamIndex, aOutParam );
System.out.println("invoke finished"); output = "success";
} }
catch (com.sun.star.lang.IllegalArgumentException iae) { catch (com.sun.star.lang.IllegalArgumentException iae) {
log.println("Couldn't invoke script:" + iae); log.println("Couldn't invoke script:" + iae);
tRes.tested("invoke()", false); output = "com.sun.star.lang.IllegalArgumentException";
return;
} }
catch (com.sun.star.script.CannotConvertException cce) { catch (com.sun.star.script.CannotConvertException cce) {
log.println("Couldn't invoke script:" + cce); log.println("Couldn't invoke script:" + cce);
tRes.tested("invoke()", false); output = "com.sun.star.script.CannotConvertException";
return;
} }
catch (com.sun.star.reflection.InvocationTargetException ite) { catch (com.sun.star.reflection.InvocationTargetException ite) {
log.println("Couldn't invoke script:" + ite); log.println("Couldn't invoke script:" + ite);
tRes.tested("invoke()", false); output = "com.sun.star.reflection.InvocationTargetException";
return;
} }
catch (com.sun.star.uno.RuntimeException re) { catch (com.sun.star.uno.RuntimeException re) {
log.println("Couldn't invoke script:" + re); log.println("Couldn't invoke script:" + re);
tRes.tested("invoke()", false); output = "com.sun.star.uno.RuntimeException";
return;
} }
catch(Exception e){ catch(java.lang.Exception e){
log.println("Couldn't invoke script:" + e); log.println("Couldn't invoke script:" + e);
tRes.tested("invoke()", false); output = "java.lang.Exception";
return;
} }
tRes.tested("invoke()", true);
log.println("expected: " + expected + ", output: " + output);
if (output.equals(expected))
return true;
else
return false;
} }
} }
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: _XFunctionProvider.java,v $ * $RCSfile: _XFunctionProvider.java,v $
* *
* $Revision: 1.1 $ * $Revision: 1.2 $
* *
* last change:$Date: 2002-11-20 14:29:36 $ * last change:$Date: 2002-12-10 14:12:05 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -74,11 +74,15 @@ import com.sun.star.beans.XPropertySet; ...@@ -74,11 +74,15 @@ import com.sun.star.beans.XPropertySet;
import java.io.PrintWriter; import java.io.PrintWriter;
import lib.MultiMethodTest; import lib.MultiMethodTest;
import lib.StatusException; import lib.StatusException;
import lib.Parameters;
import java.util.Collection;
import java.util.Iterator;
public class _XFunctionProvider extends MultiMethodTest { public class _XFunctionProvider extends MultiMethodTest {
private String defaultScript = "script://MemoryUtils.MemUsage";
public XFunctionProvider oObj = null; public XFunctionProvider oObj = null;
/** /**
* Retrieves object relation. * Retrieves object relation.
*/ */
...@@ -86,12 +90,46 @@ public class _XFunctionProvider extends MultiMethodTest { ...@@ -86,12 +90,46 @@ public class _XFunctionProvider extends MultiMethodTest {
} }
public void _getFunction() { public void _getFunction() {
XFunction function = oObj.getFunction( defaultScript ); boolean result = true;
if ( function == null ) {
log.println("Failed:_XFunctionProvider.getFunction(), no function returned."); Collection c =
tRes.tested("getScriptLogicalNames()", false); (Collection) tEnv.getObjRelation("_getFunction");
return;
Iterator tests;
if (c != null) {
tests = c.iterator();
while (tests.hasNext()) {
result &= runGetFunctionTest((Parameters)tests.next());
}
}
else {
result = false;
} }
tRes.tested("getFunction()", true);
tRes.tested("getFunction()", result);
}
private boolean runGetFunctionTest(Parameters testdata) {
String description = testdata.get("description");
String logicalname = testdata.get("logicalname");
String expected = testdata.get("expected");
String output = "";
log.println(testdata.get("description"));
XFunction function = oObj.getFunction(logicalname);
if (function == null)
output = "null";
else
output = "XFunction.class";
log.println("expected: " + expected + ", output: " + output);
if (output.equals(expected))
return true;
else
return false;
} }
} }
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: _XScriptInfoAccess.java,v $ * $RCSfile: _XScriptInfoAccess.java,v $
* *
* $Revision: 1.1 $ * $Revision: 1.2 $
* *
* last change:$Date: 2002-11-20 14:29:37 $ * last change:$Date: 2002-12-10 14:12:05 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -75,6 +75,10 @@ import com.sun.star.beans.XPropertySet; ...@@ -75,6 +75,10 @@ import com.sun.star.beans.XPropertySet;
import java.io.PrintWriter; import java.io.PrintWriter;
import lib.MultiMethodTest; import lib.MultiMethodTest;
import lib.StatusException; import lib.StatusException;
import lib.Parameters;
import java.util.Collection;
import java.util.Iterator;
public class _XScriptInfoAccess extends MultiMethodTest { public class _XScriptInfoAccess extends MultiMethodTest {
...@@ -87,59 +91,117 @@ public class _XScriptInfoAccess extends MultiMethodTest { ...@@ -87,59 +91,117 @@ public class _XScriptInfoAccess extends MultiMethodTest {
} }
public void _getScriptLogicalNames() { public void _getScriptLogicalNames() {
boolean result = true;
Collection c =
(Collection) tEnv.getObjRelation("_getScriptLogicalNames");
Iterator tests;
if (c != null) {
tests = c.iterator();
while (tests.hasNext()) {
result &= runGetScriptLogicalNamesTest((Parameters)tests.next());
}
}
else {
result = false;
}
tRes.tested("getScriptLogicalNames()", result);
}
private boolean runGetScriptLogicalNamesTest(Parameters testdata) {
String description = testdata.get("description");
String expected = testdata.get("expected");
String output = "";
log.println(testdata.get("description"));
try { try {
log.println("In _XScriptInfoAccess.getScriptLogicalNames()"); log.println("In _XScriptInfoAccess.getScriptLogicalNames()");
String[] logicalNames = oObj.getScriptLogicalNames(); String[] logicalNames = oObj.getScriptLogicalNames();
log.println("Retrieved " + logicalNames.length + " entries from storage" );
for ( int idx=0; idx < logicalNames.length; idx++ ){
log.println("logical name [" + idx + "] = " + logicalNames[idx]);
}
if ( logicalNames.length == 0 ){
log.println( "Failed:_XScriptInfoAccess.getScriptLogicalNames(), no logical names returned" );
tRes.tested( "getScriptLogicalNames()", false );
}
if (logicalNames == null)
output = "null";
else if (logicalNames.length == 0)
output = "empty";
else {
for (int i = 0; i < logicalNames.length; i++) {
if (logicalNames[i].equals(expected)) {
output = logicalNames[i];
break;
}
}
}
} }
catch (com.sun.star.uno.Exception e) { catch (com.sun.star.uno.Exception e) {
log.println("Failed:_XScriptInfoAccess.getScriptLogicalNames() :" + e); log.println("Caught UNO Exception :" + e);
tRes.tested("getScriptLogicalNames()", false); output = "com.sun.star.uno.Exception";
return;
} }
tRes.tested("getScriptLogicalNames()", true);
log.println("expected: " + expected + ", output: " + output);
if (output.equals(expected))
return true;
else
return false;
} }
public void _getImplementations() { public void _getImplementations() {
boolean result = true;
Collection c =
(Collection) tEnv.getObjRelation("_getImplementations");
Iterator tests;
if (c != null) {
tests = c.iterator();
while (tests.hasNext()) {
result &= runGetImplementationsTest((Parameters)tests.next());
}
}
else {
result = false;
}
tRes.tested("getImplementations()", result);
}
private boolean runGetImplementationsTest(Parameters testdata) {
String description = testdata.get("description");
String logicalname = testdata.get("logicalname");
String expected = testdata.get("expected");
String output = "";
log.println(testdata.get("description"));
// performs a basic check to see if 1 match (XScriptInfo) is returned // performs a basic check to see if 1 match (XScriptInfo) is returned
// the XScriptInfo object is tested more completely in _XScriptInfo // the XScriptInfo object is tested more completely in _XScriptInfo
// which is drive from ScriptInfo // which is drive from ScriptInfo
try {
log.println("In _XScriptInfoAccess._getImplementations()");
XScriptInfo[] impls = oObj.getImplementations("script://MemoryUtils.MemUsage?location=document");
// should only be one match
log.println("_XScriptInfoAccess._getImplementations() returned " + impls.length + " items ");
if ( impls.length != 1 ){
log.println("Expected 1 implementation to be returned, got " +
impls.length + " instead.");
tRes.tested("getImplementations()", false);
return;
}
if ( !impls[0].getLogicalName().equals( "MemoryUtils.MemUsage" ) ){ try {
log.println("Expected logical name = MemoryUtils.MemUsage, got " XScriptInfo[] impls = oObj.getImplementations(logicalname);
+ impls[0].getLogicalName() );
tRes.tested("getImplementations()", false);
return;
}
// should only be one match
if (impls == null)
output = "null";
else if (impls.length == 0)
output = "empty";
else
output = impls[0].getLogicalName();
} }
catch (com.sun.star.uno.Exception e) { catch (com.sun.star.uno.Exception e) {
log.println("getImplementations: failed:" + e); log.println("Caught UNO Exception:" + e);
tRes.tested("getImplementations()()", false); output = "com.sun.star.uno.Exception";
return;
} }
log.println("_XScriptInfoAccess._getImplementations() completed sucessfully");
tRes.tested("getImplementations()", true);
log.println("expected: " + expected + ", output: " + output);
if (output.equals(expected))
return true;
else
return false;
} }
} }
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: _XScriptInvocation.java,v $ * $RCSfile: _XScriptInvocation.java,v $
* *
* $Revision: 1.1 $ * $Revision: 1.2 $
* *
* last change:$Date: 2002-11-20 14:11:23 $ * last change:$Date: 2002-12-10 14:12:05 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -62,14 +62,18 @@ ...@@ -62,14 +62,18 @@
package ifc.script.framework; package ifc.script.framework;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.Collection;
import drafts.com.sun.star.script.framework.XScriptInvocation; import drafts.com.sun.star.script.framework.XScriptInvocation;
import drafts.com.sun.star.script.framework.storage.XScriptInfo; import drafts.com.sun.star.script.framework.storage.XScriptStorageManager;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.ucb.XSimpleFileAccess;
import com.sun.star.beans.XPropertySet;
import com.sun.star.uno.XComponentContext;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.Any;
import com.sun.star.uno.XInterface; import com.sun.star.uno.XInterface;
import com.sun.star.lang.XComponent;
import com.sun.star.frame.XModel; import com.sun.star.frame.XModel;
import lib.MultiMethodTest; import lib.MultiMethodTest;
...@@ -80,88 +84,53 @@ import util.SOfficeFactory; ...@@ -80,88 +84,53 @@ import util.SOfficeFactory;
public class _XScriptInvocation extends MultiMethodTest { public class _XScriptInvocation extends MultiMethodTest {
public XScriptInvocation oObj = null; public XScriptInvocation oObj = null;
private XComponent oDoc = null; private XScriptStorageManager storageManager = null;
/** /**
* Retrieves object relation. * Retrieves object relation.
*/ */
public void before() throws StatusException { public void before() throws StatusException {
SOfficeFactory factory = SOfficeFactory.getFactory(tParam.getMSF());
String name = util.utils.getFullTestURL(
"xscriptcontext_test_document.sxw");
try {
oDoc = factory.loadDocument(name);
}
catch (com.sun.star.lang.IllegalArgumentException iae) {
log.println("Exception while preloading document: " + iae);
}
catch (Exception e) {
log.println("Exception while preloading document: " + e);
}
try {
Thread.sleep(5000);
}
catch (InterruptedException ie) {
}
} }
public void after() throws StatusException { public void after() throws StatusException {
if (oDoc != null)
oDoc.dispose();
} }
public void _invoke() { public void _invoke() {
boolean result = true; boolean result = true;
result &= testUserInvoke(); Collection c =
result &= testUserInvokeWithContext(); (Collection) tEnv.getObjRelation("_invoke");
result &= testUserInvokeScriptInJar();
// if (oDoc != null)
// result &= testDocumentInvoke();
// result &= testInvokeExceptions(); Iterator tests;
tRes.tested("invoke()", result); if (c != null) {
} tests = c.iterator();
private boolean testUserInvoke() {
log.println("Try invoking a user level script");
return testInvoke(ScriptingUtils.USER_LOGICAL_NAME, 1);
}
private boolean testUserInvokeWithContext() { while (tests.hasNext()) {
log.println("Try invoking a user level script with an XScriptContext"); result &= runInvokeTest((Parameters)tests.next());
}
XModel model = (XModel) UnoRuntime.queryInterface(XModel.class, oDoc); }
return testInvoke("script://xscriptcontext.jsuite.test", 1, model); else {
} result = false;
}
private boolean testUserInvokeScriptInJar() {
log.println("Try invoking a user level script in a Jar file");
return testInvoke("script://jarscript.jsuite.test", 1); tRes.tested("invoke()", result);
} }
private boolean testDocumentInvoke() { private boolean runInvokeTest(Parameters testdata) {
log.println("Try invoking a user level script"); String description = testdata.get("description");
String logicalname = testdata.get("logicalname");
String name = util.utils.getFullTestURL( String context = testdata.get("context");
ScriptingUtils.XSCRIPTCONTEXT_TEST_DOCUMENT); String location = testdata.get("location");
String expected = testdata.get("expected");
String output = "";
int storageId = ScriptingUtils.getDefault().getScriptStorageId( int storageId = getStorageId(location);
tParam.getMSF(), name);
return testInvoke("script://xscriptcontext.jsuite.test", storageId);
}
private boolean testInvoke(String logicalName, int storageId) { XModel ctx = null;
return testInvoke(logicalName, storageId, null); if (!context.equals("null"))
} ctx = loadDocument(context);
private boolean testInvoke(String logicalName, int storageId, XModel ctx) {
HashMap map = new HashMap(); HashMap map = new HashMap();
map.put("SCRIPTING_DOC_STORAGE_ID", new Integer(storageId)); map.put("SCRIPTING_DOC_STORAGE_ID", new Integer(storageId));
map.put("SCRIPTING_DOC_URI", "hahaha"); map.put("SCRIPTING_DOC_URI", "hahaha");
...@@ -177,25 +146,119 @@ public class _XScriptInvocation extends MultiMethodTest { ...@@ -177,25 +146,119 @@ public class _XScriptInvocation extends MultiMethodTest {
short[][] num = new short[1][0]; short[][] num = new short[1][0];
num[0] = new short[0]; num[0] = new short[0];
log.println(description + ": " + logicalname);
try { try {
oObj.invoke(logicalName, params, args, num, result); oObj.invoke(logicalname, params, args, num, result);
output = "success";
} }
catch (com.sun.star.lang.IllegalArgumentException iae) { catch (com.sun.star.lang.IllegalArgumentException iae) {
log.println("Couldn't invoke script:" + iae); log.println("Couldn't invoke script:" + iae);
return false; output = "com.sun.star.lang.IllegalArgumentException";
} }
catch (com.sun.star.script.CannotConvertException cce) { catch (com.sun.star.script.CannotConvertException cce) {
log.println("Couldn't invoke script:" + cce); log.println("Couldn't invoke script:" + cce);
return false; output = "com.sun.star.script.CannotConvertException";
} }
catch (com.sun.star.reflection.InvocationTargetException ite) { catch (com.sun.star.reflection.InvocationTargetException ite) {
log.println("Couldn't invoke script:" + ite); log.println("Couldn't invoke script:" + ite);
return false; output = "com.sun.star.reflection.InvocationTargetException";
} }
catch (com.sun.star.uno.RuntimeException re) { catch (com.sun.star.uno.RuntimeException re) {
log.println("Couldn't invoke script:" + re); log.println("Couldn't invoke script:" + re);
output = "com.sun.star.uno.RuntimeException";
}
if (ctx != null)
ctx.dispose();
log.println("expected: " + expected + ", output: " + output);
if (output.equals(expected))
return true;
else
return false; return false;
}
private int getStorageId(String location) {
if (location.equals("share"))
return 0;
if (location.equals("user"))
return 1;
XSimpleFileAccess access = null;
String uri = util.utils.getFullTestURL(location);
if (storageManager == null) {
try {
XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(
XPropertySet.class, tParam.getMSF());
XComponentContext xContext = (XComponentContext)
UnoRuntime.queryInterface(XComponentContext.class,
xProp.getPropertyValue("DefaultContext"));
XInterface ifc = (XInterface)
xContext.getValueByName("/singletons/drafts.com.sun.star." +
"script.framework.storage.theScriptStorageManager");
storageManager = (XScriptStorageManager)
UnoRuntime.queryInterface(XScriptStorageManager.class, ifc);
}
catch( Exception e ) {
return -1;
}
}
access = getXSimpleFileAccess();
if (access == null)
return -1;
int id = storageManager.createScriptStorageWithURI(access, uri);
return id;
}
private XSimpleFileAccess getXSimpleFileAccess() {
XSimpleFileAccess access = null;
try {
Object fa = tParam.getMSF().createInstance(
"com.sun.star.ucb.SimpleFileAccess");
access = (XSimpleFileAccess)
UnoRuntime.queryInterface(XSimpleFileAccess.class, fa);
}
catch (com.sun.star.uno.Exception e) {
return null;
} }
return true; return access;
}
private XModel loadDocument(String name) {
XModel model = null;
SOfficeFactory factory = SOfficeFactory.getFactory(tParam.getMSF());
String fullname = util.utils.getFullTestURL(name);
try {
Object obj = factory.loadDocument(fullname);
model = (XModel) UnoRuntime.queryInterface(XModel.class, obj);
}
catch (com.sun.star.lang.IllegalArgumentException iae) {
return null;
}
catch (Exception e) {
return null;
}
try {
Thread.sleep(5000);
}
catch (InterruptedException ie) {
}
return model;
} }
} }
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: _XScriptNameResolver.java,v $ * $RCSfile: _XScriptNameResolver.java,v $
* *
* $Revision: 1.1 $ * $Revision: 1.2 $
* *
* last change:$Date: 2002-11-20 14:11:23 $ * last change:$Date: 2002-12-10 14:12:06 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -63,12 +63,17 @@ package ifc.script.framework; ...@@ -63,12 +63,17 @@ package ifc.script.framework;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Collection;
import drafts.com.sun.star.script.framework.XScriptNameResolver; import drafts.com.sun.star.script.framework.XScriptNameResolver;
import drafts.com.sun.star.script.framework.storage.XScriptInfo; import drafts.com.sun.star.script.framework.storage.XScriptInfo;
import drafts.com.sun.star.script.framework.storage.XScriptStorageManager;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.ucb.XSimpleFileAccess;
import com.sun.star.beans.XPropertySet;
import com.sun.star.uno.XComponentContext;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.Any;
import com.sun.star.uno.XInterface; import com.sun.star.uno.XInterface;
import lib.MultiMethodTest; import lib.MultiMethodTest;
...@@ -78,6 +83,7 @@ import lib.Parameters; ...@@ -78,6 +83,7 @@ import lib.Parameters;
public class _XScriptNameResolver extends MultiMethodTest { public class _XScriptNameResolver extends MultiMethodTest {
public XScriptNameResolver oObj = null; public XScriptNameResolver oObj = null;
private XScriptStorageManager storageManager = null;
/** /**
* Retrieves object relation. * Retrieves object relation.
...@@ -88,36 +94,36 @@ public class _XScriptNameResolver extends MultiMethodTest { ...@@ -88,36 +94,36 @@ public class _XScriptNameResolver extends MultiMethodTest {
public void _resolve() { public void _resolve() {
boolean result = true; boolean result = true;
result &= testValidURIs(); Collection c =
result &= testInvalidURIs(); (Collection) tEnv.getObjRelation("_resolve");
result &= testNonExistentURIs();
tRes.tested("resolve()", result); Iterator tests;
}
private boolean testValidURIs() {
boolean result = true;
log.println("Try to resolve a valid document script URI"); if (c != null) {
tests = c.iterator();
String name = util.utils.getFullTestURL( while (tests.hasNext()) {
ScriptingUtils.SCRIPT_IN_CLASSFILE_DOC_NAME); result &= runResolveTest((Parameters)tests.next());
}
int storageId = ScriptingUtils.getDefault().getScriptStorageId( }
tParam.getMSF(), name); else {
result = false;
}
result &= testValidURI(ScriptingUtils.DOC_LOGICAL_NAME, storageId); tRes.tested("resolve()", result);
}
log.println("Try to resolve a valid user script URI"); private boolean runResolveTest(Parameters data) {
result &= testValidURI(ScriptingUtils.USER_LOGICAL_NAME, 1); String description = data.get("description");
String location = data.get("location");
String logicalname = data.get("logicalname");
String expected = data.get("expected");
String output = "";
log.println("Try to resolve a valid share script URI"); int storageId = getStorageId(location);
result &= testValidURI(ScriptingUtils.SHARE_LOGICAL_NAME, 0);
return result; log.println(description + ": " + logicalname);
}
private boolean testValidURI(String logicalName, int storageId) {
HashMap map = new HashMap(); HashMap map = new HashMap();
map.put("SCRIPTING_DOC_STORAGE_ID", new Integer(storageId)); map.put("SCRIPTING_DOC_STORAGE_ID", new Integer(storageId));
map.put("SCRIPTING_DOC_URI", "hahaha"); map.put("SCRIPTING_DOC_URI", "hahaha");
...@@ -126,105 +132,89 @@ public class _XScriptNameResolver extends MultiMethodTest { ...@@ -126,105 +132,89 @@ public class _XScriptNameResolver extends MultiMethodTest {
Object[] args = new Object[] {params}; Object[] args = new Object[] {params};
try { try {
XInterface ifc = (XInterface) XInterface ifc = (XInterface) oObj.resolve(logicalname, args);
oObj.resolve(logicalName, args);
if (ifc == null)
Integer resolvedId = (Integer) output = "null";
params.getPropertyValue("SCRIPTING_RESOLVED_STORAGE_ID"); else if (UnoRuntime.queryInterface(XScriptInfo.class, ifc) == null)
output = "null";
if (resolvedId == null) { else
log.println("SCRIPTING_RESOLVED_STORAGE_ID not in return args"); output = "XScriptInfo.class";
return false;
}
if (resolvedId.intValue() != storageId) {
log.println("Wrong SCRIPTING_RESOLVED_STORAGE_ID returned");
return false;
}
if (ifc == null ||
UnoRuntime.queryInterface(XScriptInfo.class, ifc) == null)
{
log.println("Can't get XScriptInfo from resolved interface");
return false;
}
} }
catch (com.sun.star.lang.IllegalArgumentException iae) { catch (com.sun.star.lang.IllegalArgumentException iae) {
log.println("Couldn't resolve URI:" + iae); log.println("caught IllegalArgumentException: " + iae);
return false; output = "com.sun.star.lang.IllegalArgumentException";
} }
catch (com.sun.star.script.CannotConvertException cce) { catch (com.sun.star.script.CannotConvertException cce) {
log.println("Couldn't resolve URI:" + cce); log.println("caught CannotConvertException: " + cce);
return false; output = "com.sun.star.script.CannotConvertException";
} }
catch (com.sun.star.uno.RuntimeException re) { catch (com.sun.star.uno.RuntimeException re) {
log.println("Couldn't resolve URI:" + re); log.println("caught RuntimeException: " + re);
return false; output = "com.sun.star.uno.RuntimeException";
} }
return true;
log.println("expected: " + expected + ", output: " + output);
if (output.equals(expected))
return true;
else
return false;
} }
private boolean testInvalidURIs() { private int getStorageId(String location) {
log.println("Try an invalid URI, should throw IllegalArgumentException");
try {
HashMap map = new HashMap();
map.put("SCRIPTING_DOC_STORAGE_ID", new Integer(0));
map.put("SCRIPTING_DOC_URI", "hahaha");
Parameters params = new Parameters(map); if (location.equals("share"))
Object[] args = new Object[] {params}; return 0;
XInterface ifc = (XInterface) if (location.equals("user"))
oObj.resolve("scrpit://HighlightText.showForm", args); return 1;
log.println("Should not have resolved invalid URI");
return false;
}
catch (com.sun.star.lang.IllegalArgumentException iae) {
log.println("Correctly got exception:" + iae);
}
catch (com.sun.star.script.CannotConvertException cce) {
log.println("Got wrong exception" + cce);
return false;
}
catch (com.sun.star.uno.RuntimeException re) {
log.println("Got wrong exception:" + re);
return false;
}
return true;
}
private boolean testNonExistentURIs() { XSimpleFileAccess access = null;
log.println("Try a valid but non-existent URI"); String uri = util.utils.getFullTestURL(location);
try {
HashMap map = new HashMap(); if (storageManager == null) {
map.put("SCRIPTING_DOC_STORAGE_ID", new Integer(0)); try {
map.put("SCRIPTING_DOC_URI", "hahaha"); XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(
XPropertySet.class, tParam.getMSF());
Parameters params = new Parameters(map); XComponentContext xContext = (XComponentContext)
Object[] args = new Object[] {params}; UnoRuntime.queryInterface(XComponentContext.class,
xProp.getPropertyValue("DefaultContext"));
XInterface ifc = (XInterface) XInterface ifc = (XInterface)
oObj.resolve("script://Non.Existent", args); xContext.getValueByName("/singletons/drafts.com.sun.star." +
"script.framework.storage.theScriptStorageManager");
if (ifc != null && storageManager = (XScriptStorageManager)
UnoRuntime.queryInterface(XScriptInfo.class, ifc) != null) UnoRuntime.queryInterface(XScriptStorageManager.class, ifc);
{ }
log.println("Should not have resolved non-existent URI"); catch( Exception e ) {
return false; return -1;
} }
} }
catch (com.sun.star.lang.IllegalArgumentException iae) {
log.println("Couldn't resolve name:" + iae); access = getXSimpleFileAccess();
return false; if (access == null)
} return -1;
catch (com.sun.star.script.CannotConvertException cce) {
log.println("Couldn't resolve name:" + cce); int id = storageManager.createScriptStorageWithURI(access, uri);
return false;
return id;
}
private XSimpleFileAccess getXSimpleFileAccess() {
XSimpleFileAccess access = null;
try {
Object fa = tParam.getMSF().createInstance(
"com.sun.star.ucb.SimpleFileAccess");
access = (XSimpleFileAccess)
UnoRuntime.queryInterface(XSimpleFileAccess.class, fa);
} }
catch (com.sun.star.uno.RuntimeException re) { catch (com.sun.star.uno.Exception e) {
log.println("Got wrong exception:" + re); return null;
return false;
} }
return true; return access;
} }
} }
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: _XScriptStorageRefresh.java,v $ * $RCSfile: _XScriptStorageRefresh.java,v $
* *
* $Revision: 1.1 $ * $Revision: 1.2 $
* *
* last change:$Date: 2002-11-20 14:29:37 $ * last change:$Date: 2002-12-10 14:12:06 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -63,6 +63,9 @@ package ifc.script.framework.storage; ...@@ -63,6 +63,9 @@ package ifc.script.framework.storage;
import drafts.com.sun.star.script.framework.storage.XScriptStorageRefresh; import drafts.com.sun.star.script.framework.storage.XScriptStorageRefresh;
import java.util.Collection;
import java.util.Iterator;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.XInterface; import com.sun.star.uno.XInterface;
...@@ -73,6 +76,7 @@ import com.sun.star.beans.XPropertySet; ...@@ -73,6 +76,7 @@ import com.sun.star.beans.XPropertySet;
import java.io.PrintWriter; import java.io.PrintWriter;
import lib.MultiMethodTest; import lib.MultiMethodTest;
import lib.StatusException; import lib.StatusException;
import lib.Parameters;
public class _XScriptStorageRefresh extends MultiMethodTest { public class _XScriptStorageRefresh extends MultiMethodTest {
...@@ -85,8 +89,36 @@ public class _XScriptStorageRefresh extends MultiMethodTest { ...@@ -85,8 +89,36 @@ public class _XScriptStorageRefresh extends MultiMethodTest {
} }
public void _refresh() { public void _refresh() {
log.println("In _XScriptStorageRefresh.getScriptLogicalNames()" ); boolean result = true;
oObj.refresh();
tRes.tested("refresh()", true); Collection c =
(Collection) tEnv.getObjRelation("_refresh");
if (c == null) {
tRes.tested("refresh()", false);
return;
}
Iterator tests = c.iterator();
while (tests.hasNext()) {
Parameters testdata = (Parameters)tests.next();
String expected = testdata.get("expected");
String output = "";
log.println(testdata.get("description"));
try {
oObj.refresh();
output = "success";
}
catch (com.sun.star.uno.RuntimeException re) {
log.println("Caught RuntimeException: " + re);
output = "com.sun.star.uno.RuntimeException";
}
log.println("expected: " + expected + ", output: " + output);
result &= output.equals(expected);
}
tRes.tested("refresh()", result);
} }
} }
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