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

@@ -6,6 +6,7 @@ import com.jacob.com.Dispatch;
import com.jacob.com.DispatchEvents;
import com.jacob.com.InvocationProxy;
import com.jacob.com.Variant;
import com.jacob.test.BaseTestCase;
/**
* This test was lifted from a forum posting and shows how you can't listen to
@@ -15,13 +16,13 @@ import com.jacob.com.Variant;
* 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.
*/
public class ExcelEventTest extends InvocationProxy {
public class ExcelEventTest extends BaseTestCase {
/**
* load up excel, register for events and make stuff happen
* @param args
*/
public static void main(String args[]) {
public void testExcelWithInvocationProxy() {
String pid = "Excel.Application";
String typeLibLocation = "C:\\Program Files\\Microsoft Office\\OFFICE11\\EXCEL.EXE";
@@ -31,9 +32,9 @@ public class ExcelEventTest extends InvocationProxy {
// Add a listener (doesn't matter what it is).
DispatchEvents de;
if (typeLibLocation == null) {
de = new DispatchEvents(axc, new ExcelEventTest());
de = new DispatchEvents(axc, new ExcelEvents());
} else {
de = new DispatchEvents(axc, new ExcelEventTest(), pid,
de = new DispatchEvents(axc, new ExcelEvents(), pid,
typeLibLocation);
}
if (de == null) {
@@ -67,16 +68,18 @@ public class ExcelEventTest extends InvocationProxy {
} catch (ComException cfe) {
cfe.printStackTrace();
System.out.println("Failed to attach to " + pid + ": "
fail("Failed to attach to " + pid + ": "
+ cfe.getMessage());
}
}
public class ExcelEvents extends InvocationProxy {
/**
* Constructor so we can create an instance that implements invoke()
*/
public ExcelEventTest() {
public ExcelEvents() {
}
/**
@@ -89,3 +92,4 @@ public class ExcelEventTest extends InvocationProxy {
}
}
}

View File

@@ -1,7 +1,11 @@
package com.jacob.test.events;
import com.jacob.com.*;
import com.jacob.activeX.*;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.DispatchEvents;
import com.jacob.com.Variant;
import com.jacob.test.BaseTestCase;
/**
* This test runs fine against jdk 1.4 and 1.5
*
@@ -15,10 +19,9 @@ import com.jacob.activeX.*;
* Look in the docs area at the Jacob usage document for command line options.
*/
class IETest
{
public static void main(String[] args)
{
public class IETest extends BaseTestCase {
public void testRunIE() {
// this line starts the pump but it runs fine without it
ComThread.startMainSTA();
// remove this line and it dies
@@ -39,6 +42,10 @@ class IETest
ComThread.quitMainSTA();
System.out.println("Main: did quit main sta in thread "
+Thread.currentThread().getName());
if (aThread.threadFailedWithException != null){
fail("caught an unexpected exception "+aThread.threadFailedWithException);
}
}
}
@@ -46,6 +53,11 @@ class IETestThread extends Thread
{
public static boolean quitHandled = false;
/**
* holds any caught exception so the main/test case can see them
*/
public Throwable threadFailedWithException = null;
public IETestThread(){
super();
}
@@ -80,8 +92,10 @@ class IETestThread extends Thread
System.out.println("IETestThread: Did call navigate to yahoo");
try { Thread.sleep(delay); } catch (Exception e) {}
} catch (Exception e) {
threadFailedWithException = e;
e.printStackTrace();
} catch (Throwable re){
threadFailedWithException = re;
re.printStackTrace();
} finally {
System.out.println("IETestThread: About to send Quit");

View File

@@ -5,6 +5,7 @@ import com.jacob.activeX.ActiveXDispatchEvents;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
import com.jacob.test.BaseTestCase;
/**
* This test runs fine against jdk 1.4 and 1.5
*
@@ -18,10 +19,10 @@ import com.jacob.com.Variant;
* Look in the docs area at the Jacob usage document for command line options.
*/
class IETestActiveXProxy
{
public static void main(String[] args)
{
public class IETestActiveXProxy extends BaseTestCase {
public void testIEActiveProxyCallback() {
// this line starts the pump but it runs fine without it
ComThread.startMainSTA();
// remove this line and it dies
@@ -42,6 +43,9 @@ class IETestActiveXProxy
ComThread.quitMainSTA();
System.out.println("Main: did quit main sta in thread "
+Thread.currentThread().getName());
if (aThread.threadFailedWithException != null){
fail("caught an unexpected exception "+aThread.threadFailedWithException);
}
}
}
@@ -49,6 +53,11 @@ class IETestActiveProxyThread extends Thread
{
public static boolean quitHandled = false;
/**
* holds any caught exception so the main/test case can see them
*/
public Throwable threadFailedWithException = null;
public IETestActiveProxyThread(){
super();
}
@@ -83,8 +92,10 @@ class IETestActiveProxyThread extends Thread
System.out.println("IETestActiveProxyThread: Did call navigate to yahoo");
try { Thread.sleep(delay); } catch (Exception e) {}
} catch (Exception e) {
e.printStackTrace();
threadFailedWithException = e;
e.printStackTrace();
} catch (Throwable re){
threadFailedWithException = re;
re.printStackTrace();
} finally {
System.out.println("IETestActiveProxyThread: About to send Quit");

View File

@@ -5,6 +5,7 @@ import com.jacob.com.ComException;
import com.jacob.com.DispatchEvents;
import com.jacob.com.InvocationProxy;
import com.jacob.com.Variant;
import com.jacob.test.BaseTestCase;
/**
* This test was lifted from a forum posting and shows how you can't listen to
@@ -17,13 +18,13 @@ import com.jacob.com.Variant;
* 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.
*/
public class WordEventTest extends InvocationProxy {
public class WordEventTest extends BaseTestCase {
/**
* load up word, register for events and make stuff happen
* @param args
*/
public static void main(String args[]) {
public void testCaptureWordEvents() {
String pid = "Word.Application";
String typeLibLocation = null;
@@ -39,8 +40,7 @@ public class WordEventTest extends InvocationProxy {
typeLibLocation);
}
if (de == null) {
System.out
.println("No exception thrown but no dispatch returned for Word events");
fail("No exception thrown but no dispatch returned for Word events");
} else {
// Yea!
System.out.println("Successfully attached to " + pid);
@@ -52,14 +52,13 @@ public class WordEventTest extends InvocationProxy {
axc.setProperty("Visible",true);
ActiveXComponent documents = axc.getPropertyAsComponent("Documents");
if (documents == null){
System.out.println("unable to get documents");
fail("unable to get documents");
}
axc.invoke("Quit", new Variant[] {});
} catch (ComException cfe) {
cfe.printStackTrace();
System.out.println("Failed to attach to " + pid + ": "
+ cfe.getMessage());
fail("Failed to attach to " + pid + ": " + cfe.getMessage());
}
System.out.println(
@@ -68,10 +67,11 @@ public class WordEventTest extends InvocationProxy {
"thinks we tested something");
}
public class WordEvents extends InvocationProxy {
/**
* Constructor so we can create an instance that implements invoke()
*/
public WordEventTest() {
public WordEvents() {
}
/**
@@ -83,3 +83,4 @@ public class WordEventTest extends InvocationProxy {
}
}
}