SF2963102 use varargs in Dispatch instead of a million overloaded methods
This commit is contained in:
@@ -32,14 +32,9 @@ public class LibraryLoaderTest extends TestCase {
|
||||
* verify LibraryLoader.JACOB_DLL_NAME is read by LibraryLoader
|
||||
*/
|
||||
public void testJacobDllNameSystemProperty() {
|
||||
// fill with bad dll name
|
||||
System.setProperty(LibraryLoader.JACOB_DLL_NAME, "xxx");
|
||||
try {
|
||||
LibraryLoader.loadJacobLibrary();
|
||||
fail("Should have been unable to load dll with name xxx");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
// yes, this is what we want to see when using a bad name
|
||||
}
|
||||
// this test used to run in the reverse order but that caused
|
||||
// ClassDefNotFound on DEBUG
|
||||
|
||||
// no way to clear a system property once set so lets try setting to
|
||||
// default
|
||||
System.setProperty(LibraryLoader.JACOB_DLL_NAME, LibraryLoader
|
||||
@@ -52,6 +47,16 @@ public class LibraryLoaderTest extends TestCase {
|
||||
+ LibraryLoader.getPreferredDLLName() + " "
|
||||
+ ule.getMessage());
|
||||
}
|
||||
|
||||
// fill with bad dll name and try again
|
||||
System.setProperty(LibraryLoader.JACOB_DLL_NAME, "xxx");
|
||||
try {
|
||||
LibraryLoader.loadJacobLibrary();
|
||||
fail("Should have been unable to load dll with name xxx");
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
System.out.println("correctly caught UnsatisfiedLinkError");
|
||||
// yes, this is what we want to see when using a bad name
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,6 +11,35 @@ import com.jacob.test.BaseTestCase;
|
||||
*/
|
||||
public class VariantUtilitiesTest extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* verifies our unpacking stuff
|
||||
*/
|
||||
public void testObjectsToVariants() {
|
||||
Object testArray[] = new Object[] { Integer.valueOf(1),
|
||||
Integer.valueOf(2) };
|
||||
Variant resultArray[] = VariantUtilities.objectsToVariants(testArray);
|
||||
assertEquals(2, resultArray.length);
|
||||
|
||||
Variant resultArray2[] = VariantUtilities
|
||||
.objectsToVariants(resultArray);
|
||||
assertEquals(2, resultArray2.length);
|
||||
assertSame(resultArray[0], resultArray2[0]);
|
||||
assertSame(resultArray[1], resultArray2[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* test nested arrays
|
||||
*/
|
||||
public void testObjectsToVariantNestedArray() {
|
||||
Object testArray[] = new Object[] { Integer.valueOf(1),
|
||||
Integer.valueOf(2) };
|
||||
Object testArrayOuter[] = new Object[] { testArray };
|
||||
Variant resultArray[] = VariantUtilities
|
||||
.objectsToVariants(testArrayOuter);
|
||||
// should be a SafeArray
|
||||
assertEquals(1, resultArray.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* verify that dispatch can convert from object to variant and that the
|
||||
* variant holds the right value
|
||||
|
||||
@@ -25,7 +25,7 @@ public class IETest extends BaseTestCase {
|
||||
/**
|
||||
* well known address we can navigate to
|
||||
*/
|
||||
private String testUrls[] = {
|
||||
private final String testUrls[] = {
|
||||
"http://sourceforge.net/projects/jacob-project",
|
||||
"http://www.google.com" };
|
||||
|
||||
@@ -70,6 +70,7 @@ public class IETest extends BaseTestCase {
|
||||
+ Thread.currentThread().getName());
|
||||
|
||||
if (aThread.threadFailedWithException != null) {
|
||||
aThread.threadFailedWithException.printStackTrace();
|
||||
fail("caught an unexpected exception "
|
||||
+ aThread.threadFailedWithException);
|
||||
}
|
||||
@@ -113,6 +114,7 @@ class IETestThread extends Thread {
|
||||
/**
|
||||
* Run through the addresses passed in via the constructor
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
// pick a time that lets sourceforge respond (in msec)
|
||||
int delay = 3000;
|
||||
|
||||
@@ -5,26 +5,65 @@ package com.jacob.test.windowsmedia;
|
||||
* that says you get a random "can't map name to dispid" when
|
||||
* getting the URL from the player
|
||||
* <p>
|
||||
* this doesn't actually play for some reason. It always says the length is 0.
|
||||
* <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.
|
||||
* <p>
|
||||
*/
|
||||
import java.io.File;
|
||||
|
||||
import com.jacob.activeX.ActiveXComponent;
|
||||
import com.jacob.com.Dispatch;
|
||||
import com.jacob.com.Variant;
|
||||
import com.jacob.test.BaseTestCase;
|
||||
|
||||
public class WMPlayer extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* This should demo the media player but it doesn't
|
||||
*/
|
||||
public void testOpenWMPlayer() {
|
||||
// this file exists in windows 7 installations
|
||||
File file = new File(
|
||||
"C:/Windows/winsxs/x86_microsoft-windows-videosamples_31bf3856ad364e35_6.1.7600.16385_none_f583837f77a63ec7");
|
||||
String filePath = file.getAbsolutePath();
|
||||
String microsoftTestURL = filePath;
|
||||
// use these instead if not on windows 7
|
||||
// "http://support.microsoft.com/support/mediaplayer/wmptest/samples/new/mediaexample.wma";
|
||||
// "http://support.microsoft.com/support/mediaplayer/wmptest/samples/new/mediaexample.wmv";
|
||||
ActiveXComponent wmp = null;
|
||||
wmp = new ActiveXComponent("WMPlayer.OCX");
|
||||
// could use WMPlayer.OCX alias also
|
||||
wmp = new ActiveXComponent(
|
||||
"CLSID:{6BF52A52-394A-11D3-B153-00C04F79FAA6}");// ("WMPlayer.OCX");
|
||||
|
||||
wmp.setProperty("URL", microsoftTestURL);
|
||||
assertEquals(wmp.getProperty("URL").toString(), microsoftTestURL);
|
||||
|
||||
// alternative way to get the controls
|
||||
Dispatch controls = Dispatch.get(wmp, "controls").toDispatch();
|
||||
Dispatch.call(controls, "Play");
|
||||
// the sourceforge posting didn't post all the code so this is all we
|
||||
// have we need some other information on how to set the document
|
||||
// so that we have a url to open
|
||||
|
||||
// pause to let it play a second or two
|
||||
try {
|
||||
Thread.sleep(1500);
|
||||
} catch (InterruptedException e) {
|
||||
System.out.println("Thread interrupted");
|
||||
}
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
System.out.println("the wmp url is "
|
||||
+ wmp.getProperty("URL").toString());
|
||||
// Get media object
|
||||
Dispatch vMedObj = wmp.getProperty("currentMedia").toDispatch();
|
||||
// Get duration of media object
|
||||
Variant vdur = Dispatch.call(vMedObj, "duration");
|
||||
// why is this always 0?
|
||||
// System.out.println(microsoftTestURL + " length is "
|
||||
// + vdur.getDouble());
|
||||
// System.out.println("the wmp url is "
|
||||
// + wmp.getProperty("URL").toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user