1761727 converted unit test programs to JUnit tests and updated the build targets
This commit is contained in:
@@ -9,8 +9,10 @@ package com.jacob.test.powerpoint;
|
||||
* Look in the docs area at the Jacob usage document for command line options.
|
||||
*/
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.ComFailException;
|
||||
import com.jacob.com.ComThread;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.test.BaseTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -18,67 +20,31 @@ import com.jacob.com.Dispatch;
|
||||
* The submitter stated they had the problem on windows 2000 with office 2000
|
||||
* I have been unable to duplicate on windows XP with office 2003.
|
||||
* I am comitting this to the tree just in case we need to come back to it.
|
||||
* <P>
|
||||
* This relies on BaseTestCase to provide the root path to the file under test
|
||||
* <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.
|
||||
*/
|
||||
public class PowerpointTest extends Thread {
|
||||
public class PowerpointTest extends BaseTestCase {
|
||||
private static final int NUM_THREADS = 5;
|
||||
protected static final int NUM_ITERATIONS = 50;
|
||||
|
||||
private static String POWERPOINT_TEST_PATH =
|
||||
"D:\\jacob\\samples\\com\\jacob\\test\\powerpoint";
|
||||
//"c:\\PowerpointTest\test";
|
||||
|
||||
private int threadID;
|
||||
private Dispatch comPowerpoint;
|
||||
|
||||
public PowerpointTest(int threadID, Dispatch comPowerpoint) {
|
||||
super("TestThread "+threadID);
|
||||
this.threadID = threadID;
|
||||
this.comPowerpoint = comPowerpoint;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
System.out.println("Thread \""+Thread.currentThread().getName()+"\" started");
|
||||
System.out.flush();
|
||||
ComThread.InitMTA();
|
||||
try {
|
||||
for (int i=0; i<NUM_ITERATIONS; i++) {
|
||||
if (i % 10 == 0) {
|
||||
System.out.println(Thread.currentThread().getName()+": Iteration "+i);
|
||||
System.out.flush();
|
||||
}
|
||||
Dispatch comPresentations = Dispatch.get(comPowerpoint,"Presentations").toDispatch();
|
||||
Dispatch comPresentation = Dispatch.call(comPresentations,
|
||||
"Open",
|
||||
POWERPOINT_TEST_PATH+"\\test"+threadID+".ppt",
|
||||
new Integer(0),
|
||||
new Integer(0),
|
||||
new Integer(0)).toDispatch();
|
||||
Dispatch.call(comPresentation, "Close");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error in Thread \""+Thread.currentThread().getName()+"\":");
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
ComThread.Release();
|
||||
System.out.println("Thread \""+Thread.currentThread().getName()+"\" finished");
|
||||
System.out.flush();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* main program that lets us run this as a test
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
public void testPowerpoint() {
|
||||
ComThread.InitMTA();
|
||||
|
||||
ActiveXComponent component = new ActiveXComponent("Powerpoint.Application");
|
||||
Dispatch comPowerpoint = component.getObject();
|
||||
|
||||
try {
|
||||
PowerpointTest[] threads = new PowerpointTest[NUM_THREADS];
|
||||
try {
|
||||
PowerpointTestThread[] threads = new PowerpointTestThread[NUM_THREADS];
|
||||
for (int i=0; i<NUM_THREADS; i++) {
|
||||
threads[i] = new PowerpointTest(i+1, comPowerpoint);
|
||||
threads[i] = new PowerpointTestThread(i+1, comPowerpoint);
|
||||
threads[i].start();
|
||||
}
|
||||
|
||||
@@ -100,9 +66,68 @@ public class PowerpointTest extends Thread {
|
||||
}
|
||||
}
|
||||
|
||||
Dispatch.call(comPowerpoint,"Quit");
|
||||
Dispatch.call(comPowerpoint,"Quit");
|
||||
for (int i = 0 ; i < NUM_THREADS; i++){
|
||||
if (threads[i].threadFailedWithException != null){
|
||||
fail ("caught unexpected exception in thread "+
|
||||
threads[i].threadFailedWithException);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
ComThread.Release();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class PowerpointTestThread extends Thread {
|
||||
/**
|
||||
* holds any caught exception so the main/test case can see them
|
||||
*/
|
||||
public Throwable threadFailedWithException = null;
|
||||
|
||||
private int threadID;
|
||||
private Dispatch comPowerpoint;
|
||||
|
||||
public PowerpointTestThread(int threadID, Dispatch comPowerpoint) {
|
||||
super("TestThread "+threadID);
|
||||
this.threadID = threadID;
|
||||
this.comPowerpoint = comPowerpoint;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
System.out.println("Thread \""+Thread.currentThread().getName()+"\" started");
|
||||
System.out.flush();
|
||||
ComThread.InitMTA();
|
||||
try {
|
||||
for (int i=0; i<NUM_ITERATIONS; i++) {
|
||||
if (i % 10 == 0) {
|
||||
System.out.println(Thread.currentThread().getName()+": Iteration "+i);
|
||||
System.out.flush();
|
||||
}
|
||||
Dispatch comPresentations = Dispatch.get(comPowerpoint,"Presentations").toDispatch();
|
||||
Dispatch comPresentation = Dispatch.call(comPresentations,
|
||||
"Open",
|
||||
getWindowsFilePathToPackageResource("test"+threadID+".ppt",this.getClass()),
|
||||
new Integer(0),
|
||||
new Integer(0),
|
||||
new Integer(0)).toDispatch();
|
||||
Dispatch.call(comPresentation, "Close");
|
||||
}
|
||||
} catch (ComFailException cfe){
|
||||
threadFailedWithException = cfe;
|
||||
System.err.println(Thread.currentThread().getName()+"\" while working on: "+
|
||||
getWindowsFilePathToPackageResource("test"+threadID+".ppt",this.getClass()));
|
||||
cfe.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
threadFailedWithException = e;
|
||||
System.err.println("Error in Thread \""+Thread.currentThread().getName()+"\":");
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
ComThread.Release();
|
||||
System.out.println("Thread \""+Thread.currentThread().getName()+"\" finished");
|
||||
System.out.flush();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user