1761727 converted unit test programs to JUnit tests and updated the build targets

This commit is contained in:
clay_shooter
2007-07-27 03:28:44 +00:00
parent bfdc36ad30
commit 78c7ddf199
71 changed files with 1459 additions and 1257 deletions

View File

@@ -1,2 +0,0 @@
java ScriptTest "1+2"
java ScriptTest "()1+2"

View File

@@ -1,50 +1,63 @@
package com.jacob.test.vbscript;
import com.jacob.com.*;
import com.jacob.test.BaseTestCase;
import com.jacob.activeX.*;
/**
* In this case the component is created and used in the same thread
* and it's an Apartment Threaded component, so we call InitSTA.
* In this case the component is created and used in the same thread and it's an
* Apartment Threaded component, so we call InitSTA.
* <p>
* May need to run with some command line options (including from inside
* Eclipse). Look in the docs area at the Jacob usage document for command line
* options.
*/
class ScriptTest
{
public static void main(String args[]) throws Exception
{
ComThread.InitSTA(true);
DispatchEvents de = null;
Dispatch sControl = null;
public class ScriptTest extends BaseTestCase {
try {
String lang = "VBScript";
ActiveXComponent sC = new ActiveXComponent("ScriptControl");
sControl = (Dispatch)sC.getObject();
Dispatch.put(sControl, "Language", lang);
ScriptTestErrEvents te = new ScriptTestErrEvents();
de = new DispatchEvents(sControl, te);
if (de == null){
System.out.println("Received null when trying to create new DispatchEvents");
}
Variant result = Dispatch.call(sControl, "Eval", args[0]);
// call it twice to see the objects reused
result = Dispatch.call(sControl, "Eval", args[0]);
// call it 3 times to see the objects reused
result = Dispatch.call(sControl, "Eval", args[0]);
System.out.println("eval("+args[0]+") = "+ result);
} catch (ComException e) {
e.printStackTrace();
}
finally
{
Integer I = null;
for(int i=1;i<1000000;i++)
{
I = new Integer(i);
}
System.out.println(I);
public void testStupidSpeedTest() {
String lang = "VBScript";
ActiveXComponent sC = new ActiveXComponent("ScriptControl");
Dispatch sControl = sC.getObject();
Dispatch.put(sControl, "Language", lang);
for (int i = 0; i < 10000; i++) {
Dispatch.call(sControl, "Eval", "1+1");
}
}
public void testCreatingDispatchEvents() {
ComThread.InitSTA(true);
DispatchEvents de = null;
Dispatch sControl = null;
try {
String scriptCommand = getSampleVPScriptForEval();
String lang = "VBScript";
ActiveXComponent sC = new ActiveXComponent("ScriptControl");
sControl = (Dispatch) sC.getObject();
Dispatch.put(sControl, "Language", lang);
ScriptTestErrEvents te = new ScriptTestErrEvents();
de = new DispatchEvents(sControl, te);
if (de == null) {
System.out
.println("Received null when trying to create new DispatchEvents");
}
Variant result = Dispatch.call(sControl, "Eval", scriptCommand);
// call it twice to see the objects reused
result = Dispatch.call(sControl, "Eval", scriptCommand);
// call it 3 times to see the objects reused
result = Dispatch.call(sControl, "Eval", scriptCommand);
System.out.println("eval(" + scriptCommand + ") = " + result);
} catch (ComException e) {
e.printStackTrace();
fail("Caught Exception " + e);
} finally {
Integer I = null;
for (int i = 1; i < 1000000; i++) {
I = new Integer(i);
}
System.out.println(I);
ComThread.Release();
ComThread.quitMainSTA();
}
}
}
}
}

View File

@@ -1,98 +1,98 @@
package com.jacob.test.vbscript;
import com.jacob.com.*;
import com.jacob.test.BaseTestCase;
import com.jacob.activeX.*;
/**
* This example demonstrates how to make calls between
* two different STA's.
* First, to create an STA, you need to extend the STA class
* and override its OnInit() method. This method will be called
* in the STA's thread so you can use it to create your COM
* components that will run in that STA.
* If you then try to call methods on those components from other
* threads (STA or MTA) - this will fail.
* You cannot create a component in an STA and call its methods
* from another thread.
* You can use the DispatchProxy to get a proxy to any Dispatch
* that lives in another STA. This object has to be created in the
* STA that houses the Dispatch (in this case it's created in the
* OnInit method). Then, another thread can call the toDispatch()
* method of DispatchProxy to get a local proxy. At most ONE (!)
* thread can call toDispatch(), and the call can be made only once.
* This is because a IStream object is used to pass the proxy, and
* it is only written once and closed when you read it.
* If you need multiple threads to access a Dispatch pointer, then
* create that many DispatchProxy objects.
* This example demonstrates how to make calls between two different STA's.
* First, to create an STA, you need to extend the STA class and override its
* OnInit() method. This method will be called in the STA's thread so you can
* use it to create your COM components that will run in that STA. If you then
* try to call methods on those components from other threads (STA or MTA) -
* this will fail. You cannot create a component in an STA and call its methods
* from another thread. You can use the DispatchProxy to get a proxy to any
* Dispatch that lives in another STA. This object has to be created in the STA
* that houses the Dispatch (in this case it's created in the OnInit method).
* Then, another thread can call the toDispatch() method of DispatchProxy to get
* a local proxy. At most ONE (!) thread can call toDispatch(), and the call can
* be made only once. This is because a IStream object is used to pass the
* proxy, and it is only written once and closed when you read it. If you need
* multiple threads to access a Dispatch pointer, then create that many
* DispatchProxy objects.
* <p>
* May need to run with some command line options (including from inside Eclipse).
* Look in the docs area at the Jacob usage document for command line options.
*/
class ScriptTest2 extends STA
{
public static ActiveXComponent sC;
public static DispatchEvents de = null;
public static Dispatch sControl = null;
public static DispatchProxy sCon = null;
public boolean OnInit()
{
try
{
System.out.println("OnInit");
System.out.println(Thread.currentThread());
String lang = "VBScript";
sC = new ActiveXComponent("ScriptControl");
sControl = (Dispatch)sC.getObject();
public class ScriptTest2 extends BaseTestCase {
public void testScript2() {
try {
ComThread.InitSTA();
ScriptTestSTA script = new ScriptTestSTA();
try {
Thread.sleep(1000);
} catch (InterruptedException ie){
// should we get this?
}
// sCon can be called from another thread
sCon = new DispatchProxy(sControl);
String scriptCommand = getSampleVPScriptForEval();
// get a thread-local Dispatch from sCon
Dispatch sc = script.sCon.toDispatch();
Dispatch.put(sControl, "Language", lang);
ScriptTestErrEvents te = new ScriptTestErrEvents();
de = new DispatchEvents(sControl, te);
return true;
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
}
// call a method on the thread-local Dispatch obtained
// from the DispatchProxy. If you try to make the same
// method call on the sControl object - you will get a
// ComException.
Variant result = Dispatch.call(sc, "Eval", scriptCommand);
System.out.println("eval(" + scriptCommand + ") = " + result);
script.quit();
System.out.println("called quit");
} catch (ComException e) {
e.printStackTrace();
fail("caught exception"+e);
} finally {
Integer I = null;
for (int i = 1; i < 1000000; i++) {
I = new Integer(i);
}
System.out.println(I);
ComThread.Release();
}
}
public void OnQuit()
{
System.out.println("OnQuit");
}
public class ScriptTestSTA extends STA {
public static void main(String args[]) throws Exception
{
try {
ComThread.InitSTA();
ScriptTest2 script = new ScriptTest2();
Thread.sleep(1000);
public DispatchEvents de = null;
// get a thread-local Dispatch from sCon
Dispatch sc = sCon.toDispatch();
public Dispatch sControl = null;
public DispatchProxy sCon = null;
public boolean OnInit() {
try {
System.out.println("OnInit");
System.out.println(Thread.currentThread());
String lang = "VBScript";
sControl = new ActiveXComponent("ScriptControl");
// sCon can be called from another thread
sCon = new DispatchProxy(sControl);
Dispatch.put(sControl, "Language", lang);
ScriptTestErrEvents te = new ScriptTestErrEvents();
de = new DispatchEvents(sControl, te);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public void OnQuit() {
System.out.println("OnQuit");
}
}
// call a method on the thread-local Dispatch obtained
// from the DispatchProxy. If you try to make the same
// method call on the sControl object - you will get a
// ComException.
Variant result = Dispatch.call(sc, "Eval", args[0]);
System.out.println("eval("+args[0]+") = "+ result);
script.quit();
System.out.println("called quit");
} catch (ComException e) {
e.printStackTrace();
}
finally
{
Integer I = null;
for(int i=1;i<1000000;i++)
{
I = new Integer(i);
}
System.out.println(I);
ComThread.Release();
}
}
}

View File

@@ -1,96 +1,102 @@
package com.jacob.test.vbscript;
import com.jacob.com.*;
import com.jacob.activeX.*;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComException;
import com.jacob.com.ComThread;
import com.jacob.com.DispatchEvents;
import com.jacob.com.DispatchProxy;
import com.jacob.com.STA;
import com.jacob.com.Variant;
import com.jacob.test.BaseTestCase;
/**
* This example demonstrates how to make calls between
* two different STA's.
* First, to create an STA, you need to extend the STA class
* and override its OnInit() method. This method will be called
* in the STA's thread so you can use it to create your COM
* components that will run in that STA.
* If you then try to call methods on those components from other
* threads (STA or MTA) - this will fail.
* You cannot create a component in an STA and call its methods
* from another thread.
* You can use the DispatchProxy to get a proxy to any Dispatch
* that lives in another STA. This object has to be created in the
* STA that houses the Dispatch (in this case it's created in the
* OnInit method). Then, another thread can call the toDispatch()
* method of DispatchProxy to get a local proxy. At most ONE (!)
* thread can call toDispatch(), and the call can be made only once.
* This is because a IStream object is used to pass the proxy, and
* it is only written once and closed when you read it.
* If you need multiple threads to access a Dispatch pointer, then
* create that many DispatchProxy objects.
* This example demonstrates how to make calls between two different STA's.
* First, to create an STA, you need to extend the STA class and override its
* OnInit() method. This method will be called in the STA's thread so you can
* use it to create your COM components that will run in that STA. If you then
* try to call methods on those components from other threads (STA or MTA) -
* this will fail. You cannot create a component in an STA and call its methods
* from another thread. You can use the DispatchProxy to get a proxy to any
* Dispatch that lives in another STA. This object has to be created in the STA
* that houses the Dispatch (in this case it's created in the OnInit method).
* Then, another thread can call the toDispatch() method of DispatchProxy to get
* a local proxy. At most ONE (!) thread can call toDispatch(), and the call can
* be made only once. This is because a IStream object is used to pass the
* proxy, and it is only written once and closed when you read it. If you need
* multiple threads to access a Dispatch pointer, then create that many
* DispatchProxy objects.
* <p>
* May need to run with some command line options (including from inside Eclipse).
* Look in the docs area at the Jacob usage document for command line options.
*/
class ScriptTest2ActiveX extends STA
{
public static ActiveXComponent sC;
public static DispatchEvents de = null;
public static DispatchProxy sCon = null;
public class ScriptTest2ActiveX extends BaseTestCase {
public static ActiveXComponent sC;
public boolean OnInit()
{
try
{
System.out.println("OnInit");
System.out.println(Thread.currentThread());
String lang = "VBScript";
sC = new ActiveXComponent("ScriptControl");
public static DispatchEvents de = null;
// sCon can be called from another thread
sCon = new DispatchProxy(sC);
public static DispatchProxy sCon = null;
sC.setProperty("Language", lang);
ScriptTestErrEvents te = new ScriptTestErrEvents();
de = new DispatchEvents(sC, te);
return true;
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
}
public void testActiveXSTA() {
try {
ComThread.InitSTA();
ScriptTest2ActiveXSTA script = new ScriptTest2ActiveXSTA();
try {
Thread.sleep(1000);
} catch (InterruptedException ie){
// should we get this?
}
public void OnQuit()
{
System.out.println("OnQuit");
}
// get a thread-local Dispatch from sCon
ActiveXComponent sc = new ActiveXComponent(sCon.toDispatch());
public static void main(String args[]) throws Exception
{
try {
ComThread.InitSTA();
ScriptTest2ActiveX script = new ScriptTest2ActiveX();
Thread.sleep(1000);
// call a method on the thread-local Dispatch obtained
// from the DispatchProxy. If you try to make the same
// method call on the sControl object - you will get a
// ComException.
String scriptCommand = getSampleVPScriptForEval();
Variant result = sc.invoke("Eval", scriptCommand);
System.out.println("eval(" + scriptCommand + ") = " + result);
script.quit();
System.out.println("called quit");
} catch (ComException e) {
e.printStackTrace();
fail("blew up with Com Exception "+e);
} finally {
Integer I = null;
for (int i = 1; i < 1000000; i++) {
I = new Integer(i);
}
System.out.println(I);
ComThread.Release();
}
}
// get a thread-local Dispatch from sCon
ActiveXComponent sc = new ActiveXComponent(sCon.toDispatch());
public class ScriptTest2ActiveXSTA extends STA {
// call a method on the thread-local Dispatch obtained
// from the DispatchProxy. If you try to make the same
// method call on the sControl object - you will get a
// ComException.
Variant result = sc.invoke("Eval", args[0]);
System.out.println("eval("+args[0]+") = "+ result);
script.quit();
System.out.println("called quit");
} catch (ComException e) {
e.printStackTrace();
}
finally
{
Integer I = null;
for(int i=1;i<1000000;i++)
{
I = new Integer(i);
}
System.out.println(I);
ComThread.Release();
}
}
}
public boolean OnInit() {
try {
System.out.println("OnInit");
System.out.println(Thread.currentThread());
String lang = "VBScript";
sC = new ActiveXComponent("ScriptControl");
// sCon can be called from another thread
sCon = new DispatchProxy(sC);
sC.setProperty("Language", lang);
ScriptTestErrEvents te = new ScriptTestErrEvents();
de = new DispatchEvents(sC, te);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public void OnQuit() {
System.out.println("OnQuit");
}
}
}

View File

@@ -1,68 +1,73 @@
package com.jacob.test.vbscript;
import com.jacob.com.*;
import com.jacob.test.BaseTestCase;
import com.jacob.activeX.*;
/**
* Here we create the ScriptControl component in a separate MTA thread
* and then call the Eval method from the main thread. The main thread
* must also be an MTA thread. If you try to create it as an STA
* then you will not be able to make calls into a component running
* in another thread.
* Here we create the ScriptControl component in a separate MTA thread and then
* call the Eval method from the main thread. The main thread must also be an
* MTA thread. If you try to create it as an STA then you will not be able to
* make calls into a component running in another thread.
* <p>
* May need to run with some command line options (including from inside Eclipse).
* Look in the docs area at the Jacob usage document for command line options.
*/
class ScriptTest3 extends Thread
{
public static ActiveXComponent sC;
public static DispatchEvents de = null;
public static Dispatch sControl = null;
public static boolean quit = false;
public class ScriptTest3 extends BaseTestCase {
public void run()
{
try
{
ComThread.InitMTA();
System.out.println("OnInit");
String lang = "VBScript";
sC = new ActiveXComponent("ScriptControl");
sControl = (Dispatch)sC.getObject();
Dispatch.put(sControl, "Language", lang);
ScriptTestErrEvents te = new ScriptTestErrEvents();
de = new DispatchEvents(sControl, te);
System.out.println("sControl="+sControl);
while (!quit) sleep(100);
ComThread.Release();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
System.out.println("worker thread exits");
}
}
public static ActiveXComponent sC;
public static void main(String args[]) throws Exception
{
try {
ComThread.InitMTA();
ScriptTest3 script = new ScriptTest3();
script.start();
Thread.sleep(1000);
public static DispatchEvents de = null;
Variant result = Dispatch.call(sControl, "Eval", args[0]);
System.out.println("eval("+args[0]+") = "+ result);
System.out.println("setting quit");
ScriptTest3.quit = true;
} catch (ComException e) {
e.printStackTrace();
}
finally
{
System.out.println("main done");
ComThread.Release();
}
}
public static Dispatch sControl = null;
public static boolean quit = false;
public void testScript() {
try {
ComThread.InitMTA();
ScriptTest3Inner script = new ScriptTest3Inner();
script.start();
try {
Thread.sleep(1000);
} catch (InterruptedException ie){
// should we get this?
}
Variant result = Dispatch.call(sControl, "Eval", getSampleVPScriptForEval());
System.out.println("eval(" + getSampleVPScriptForEval() + ") = " + result);
System.out.println("setting quit");
ScriptTest3.quit = true;
} catch (ComException e) {
e.printStackTrace();
fail("Caught excpetion running script with MTA");
} finally {
System.out.println("main done");
ComThread.Release();
}
}
class ScriptTest3Inner extends Thread {
public void run() {
try {
ComThread.InitMTA();
System.out.println("OnInit");
String lang = "VBScript";
sC = new ActiveXComponent("ScriptControl");
sControl = (Dispatch) sC.getObject();
Dispatch.put(sControl, "Language", lang);
ScriptTestErrEvents te = new ScriptTestErrEvents();
de = new DispatchEvents(sControl, te);
System.out.println("sControl=" + sControl);
while (!quit)
sleep(100);
ComThread.Release();
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("worker thread exits");
}
}
}
}

View File

@@ -1,66 +1,72 @@
package com.jacob.test.vbscript;
import com.jacob.com.*;
import com.jacob.test.BaseTestCase;
import com.jacob.activeX.*;
/**
* Here we create the ScriptControl component in a separate MTA thread
* and then call the Eval method from the main thread. The main thread
* must also be an MTA thread. If you try to create it as an STA
* then you will not be able to make calls into a component running
* in another thread.
* Here we create the ScriptControl component in a separate MTA thread and then
* call the Eval method from the main thread. The main thread must also be an
* MTA thread. If you try to create it as an STA then you will not be able to
* make calls into a component running in another thread.
* <p>
* May need to run with some command line options (including from inside
* Eclipse). Look in the docs area at the Jacob usage document for command line
* options.
*/
class ScriptTest3ActiveX extends Thread
{
public static ActiveXComponent sC;
public static DispatchEvents de = null;
public static boolean quit = false;
public class ScriptTest3ActiveX extends BaseTestCase {
public static ActiveXComponent sC;
public void run()
{
try
{
ComThread.InitMTA();
System.out.println("OnInit");
String lang = "VBScript";
sC = new ActiveXComponent("ScriptControl");
sC.setProperty("Language", lang);
ScriptTestErrEvents te = new ScriptTestErrEvents();
de = new DispatchEvents(sC, te);
System.out.println("sControl="+sC);
while (!quit) sleep(100);
ComThread.Release();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
System.out.println("worker thread exits");
}
}
public static DispatchEvents de = null;
public static void main(String args[]) throws Exception
{
try {
ComThread.InitMTA();
ScriptTest3ActiveX script = new ScriptTest3ActiveX();
script.start();
Thread.sleep(1000);
public static boolean quit = false;
Variant result = sC.invoke("Eval", args[0]);
System.out.println("eval("+args[0]+") = "+ result);
System.out.println("setting quit");
ScriptTest3ActiveX.quit = true;
} catch (ComException e) {
e.printStackTrace();
}
finally
{
System.out.println("main done");
ComThread.Release();
}
}
public void testYetAnotherScriptTest() {
try {
ComThread.InitMTA();
ScriptTest3ActiveXInner script = new ScriptTest3ActiveXInner();
script.start();
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
// should we get this?
}
Variant result = sC.invoke("Eval", getSampleVPScriptForEval());
System.out
.println("eval(" + getSampleVPScriptForEval()
+ ") = " + result);
System.out.println("setting quit");
ScriptTest3ActiveX.quit = true;
} catch (ComException e) {
e.printStackTrace();
fail("Caught ComException " + e);
} finally {
System.out.println("main done");
ComThread.Release();
}
}
public class ScriptTest3ActiveXInner extends Thread {
public void run() {
try {
ComThread.InitMTA();
System.out.println("OnInit");
String lang = "VBScript";
sC = new ActiveXComponent("ScriptControl");
sC.setProperty("Language", lang);
ScriptTestErrEvents te = new ScriptTestErrEvents();
de = new DispatchEvents(sC, te);
System.out.println("sControl=" + sC);
while (!quit)
sleep(100);
ComThread.Release();
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("worker thread exits");
}
}
}
}

View File

@@ -1,16 +1,19 @@
package com.jacob.test.vbscript;
import com.jacob.com.*;
import com.jacob.test.BaseTestCase;
import com.jacob.activeX.*;
/**
* In this case the component is created and used in the same thread
* and it's an Apartment Threaded component, so we call InitSTA.
* <p>
* May need to run with some command line options (including from inside
* Eclipse). Look in the docs area at the Jacob usage document for command line
* options.
*/
class ScriptTestActiveX
{
public static void main(String args[]) throws Exception
{
public class ScriptTestActiveX extends BaseTestCase {
public void testActiveXScript() {
ComThread.InitSTA(true);
DispatchEvents de = null;
@@ -24,12 +27,12 @@ class ScriptTestActiveX
System.out.println("null returned when trying to create DispatchEvents");
}
Variant result;
result = sC.invoke("Eval",args[0]);
result = sC.invoke("Eval",getSampleVPScriptForEval());
// call it twice to see the objects reused
result = sC.invoke("Eval",args[0]);
result = sC.invoke("Eval",getSampleVPScriptForEval());
// call it 3 times to see the objects reused
result = sC.invoke("Eval",args[0]);
System.out.println("eval("+args[0]+") = "+ result);
result = sC.invoke("Eval",getSampleVPScriptForEval());
System.out.println("eval("+getSampleVPScriptForEval()+") = "+ result);
} catch (ComException e) {
e.printStackTrace();
}

View File

@@ -1,12 +1,13 @@
package com.jacob.test.vbscript;
import com.jacob.com.Variant;
import com.jacob.test.BaseTestCase;
/**
* Extracted from ScriptTest so everyone can see this
* Made a test solely because it made the ant test easier
*/
public class ScriptTestErrEvents {
public class ScriptTestErrEvents extends BaseTestCase {
public void Error(Variant[] args)
{

View File

@@ -1,18 +0,0 @@
package com.jacob.test.vbscript;
import com.jacob.com.*;
import com.jacob.activeX.*;
class speed
{
public static void main(String args[])
{
String lang = "VBScript";
ActiveXComponent sC = new ActiveXComponent("ScriptControl");
Dispatch sControl = sC.getObject();
Dispatch.put(sControl, "Language", lang);
for(int i=0;i<10000;i++) {
Dispatch.call(sControl, "Eval", "1+1");
}
}
}