SF1570270 Proxy unhook detatched threads.

SF1538011 toString() not compliant, large ripple into toXXX() methods
SF1478172 Variant jni methods public without protection.  Now JNI methods behind java methods
This commit is contained in:
clay_shooter
2006-10-04 03:18:59 +00:00
parent a50685d412
commit 0b16b2eeae
14 changed files with 1306 additions and 738 deletions

View File

@@ -1,5 +1,7 @@
package com.jacob.com;
import java.util.Date;
/**
* runs through some of the get and set methods on Variant
*
@@ -9,6 +11,8 @@ class VariantTest {
public static void main(String[] args) {
System.out.println("Testing Started");
VariantTest testJig = new VariantTest();
testJig.testUninitializedVariant();
testJig.testToStringDoesNotConvert();
testJig.testPutsAndGets();
testJig.testSafeReleaseBoolean();
testJig.testSafeReleaseConstant();
@@ -26,40 +30,103 @@ class VariantTest {
}
private void testSafeReleaseBoolean(){
Variant v = new Variant(true);
System.out.println("Newly created Variant ("+ v.getBoolean()+") "+
"trying to create access violation but it doesn't seem to be easy");
v.safeRelease();
if (v.getBoolean() != true){
System.out.println("Variant value ("+v.getBoolean()+") "
+"has been broken by SafeRelease()");
} else {
System.out.println("Variant value ("+v.getBoolean()+") "
+"has survived SafeRelease()");
/**
* make sure variant with no backing store works.
*
*/
private void testUninitializedVariant(){
Variant v;
// Variants created without parameters are auto set to VariantEmpty
v = new Variant();
try {
if (v.getvt() == Variant.VariantEmpty){
// successful
// System.out.println("Variant initialized without parameters correctly set to empty");
} else {
throw new RuntimeException("getvt() on uninitialized variant shoud have returned VariantEmpty, instead returned "+v.getvt());
}
} catch (IllegalStateException ise){
throw new RuntimeException("getvt() on uninitialized variant shoud have succeeded, but instead threw exception");
}
try {
v.toString();
} catch (IllegalStateException ise){
System.out.println("toString() should never throw a runtime exception");
throw new RuntimeException("toString() should not blow up even with uninitialized Variant");
}
}
/**
*
* verify the toString() method does not do type conversion
*/
private void testToStringDoesNotConvert(){
Variant v;
v = new Variant(true);
v.toString();
if (v.getvt() != Variant.VariantBoolean){
throw new RuntimeException("toString() converted boolean to something else");
} else {
//System.out.println("toString() correctly does not convert type");
}
if (v.getBoolean() != true){
System.out.println("toString() converted boolean true to "+ v.getBoolean());
}
v = new Variant(false);
v.toString();
if (v.getvt() != Variant.VariantBoolean){
throw new RuntimeException("toString() converted boolean to something else");
} else {
//System.out.println("toString() correctly does not convert type");
}
if (v.getBoolean() != false){
System.out.println("toString() converted boolean false to "+ v.getBoolean());
}
}
private void testSafeReleaseBoolean(){
Variant v;
v = new Variant(true);
//System.out.println("Newly created Variant ("+ v.getBoolean()+") "+
// "trying to create access violation but it doesn't seem to be easy");
v.safeRelease();
try {
v.getBoolean();
System.out.println("IllegalStateException should have been thrown when querying safeReleased object");
throw new RuntimeException("test failed");
} catch (IllegalStateException ise){
//System.out.println("IllegalStateException correctly thrown after safeRelease");
}
v = new Variant(true);
for ( int i = 0 ; i < 10; i ++){
new Variant ("xxx"+i);
new Variant(i);
new Variant ("yyy"+i);
}
ComThread.Release();
if (v.getBoolean() != true){
System.out.println("Variant value ("+v.getBoolean()+") "
+"has been broken by ComThread.Release()");
} else {
System.out.println("Variant value ("+v.getBoolean()+") "
+"has been survived by ComThread.Release()");
try {
v.getBoolean();
System.out.println("IllegalStateException should have been thrown when querying ComThread.Release");
throw new RuntimeException("test failed");
} catch (IllegalStateException ise){
//System.out.println("IllegalStateException correctly thrown after ComThread.Release");
}
}
/**
* verify the constant values aren't released with safeRelease
*
*/
private void testSafeReleaseConstant(){
System.out.println("Using Static constant Variant - should never throw access violation");
Variant.VT_TRUE.safeRelease();
if (Variant.VT_TRUE.getBoolean() != true){
System.out.println("VT_TRUE has been broken by SafeRelease()");
throw new RuntimeException("test failed");
} else {
System.out.println("VT_TRUE survived SafeRelease()");
//System.out.println("VT_TRUE survived SafeRelease()");
}
for ( int i = 0 ; i < 10; i ++){
@@ -71,24 +138,31 @@ class VariantTest {
if (Variant.VT_TRUE.getBoolean() != true){
System.out.println("VT_TRUE has been broken by ComThread.Release()");
throw new RuntimeException("test failed");
} else {
System.out.println("VT_TRUE survived ComThread.Release()");
//System.out.println("VT_TRUE survived ComThread.Release()");
}
}
/**
* this used to try and and create an access violation but that
* didn't work and now the methods on the Variant are smarter about
* working after a release
*
*/
private void testSafeReleaseString(){
String mTestString = "Guitar Hero";
Variant v = new Variant(mTestString);
System.out.println("Newly created Variant ("+ v.getString()+") "+
"trying to create access violation but it doesn't seem to be easy");
//System.out.println("Newly created Variant ("+ v.getString()+") "+
// "about to safe release and then access");
v.safeRelease();
if (v.getString() == null || !v.getString().equals(mTestString)){
System.out.println("Variant value ("+v.getString()+") "
+"has been broken by SafeRelease()");
} else {
System.out.println("Variant value ("+v.getString()+") "
+"has survived SafeRelease()");
try {
v.getString();
System.out.println("IllegalStateException should have been thrown when querying safeReleased object");
throw new RuntimeException("test failed");
} catch (IllegalStateException ise){
//System.out.println("IllegalStateException correctly thrown after safeRelease");
}
}
@@ -127,28 +201,47 @@ class VariantTest {
private void testPutsAndGets(){
Variant v = new Variant();
v.putInt(10);
if (v.toInt() != 10){
if (v.getInt() != 10){
System.out.println("int test failed");
}
v.putInt(10);
if (v.toDouble() != 10.0){
v.putShort((short)10);
if (v.getShort() != 10){
System.out.println("short test failed");
}
v.putByte((byte)10);
if (v.getByte() != 10){
System.out.println("int test failed");
}
v.putFloat(10);
if (v.getFloat() != 10.0){
System.out.println("float test failed");
}
v.putDouble(10);
if (v.getDouble() != 10.0){
System.out.println("double test failed");
}
v.putString("1234.567");
if (!"1234.567".equals(v.toString())){
if (!"1234.567".equals(v.getString())){
System.out.println("string test failed");
}
v.putBoolean(true);
if (v.toBoolean() != true){
if (v.getBoolean() != true){
System.out.println("failed boolean test(true)");
}
v.putBoolean(false);
if (v.toBoolean() != false){
if (v.getBoolean() != false){
System.out.println("failed boolean test(false)");
}
v.putCurrency(123456789123456789L);
if (v.toCurrency()!=123456789123456789L){
System.out.println("failed long test");
if (v.getCurrency()!=123456789123456789L){
System.out.println("failed currency test");
}
Date ourDate = new Date();
v.putDate(ourDate);
Date retrievedDate = v.getJavaDate();
if (!retrievedDate.equals(ourDate)){
System.out.println("failed java date load and unload");
}
v.putNull();

View File

@@ -34,10 +34,12 @@ class IETest
//e.printStackTrace();
}
}
System.out.println("Thread quit, about to quit main sta");
System.out.println("Main: Thread quit, about to quit main sta in thread "
+Thread.currentThread().getName());
// this line only does someting if startMainSTA() was called
ComThread.quitMainSTA();
System.out.println("did quit main sta");
System.out.println("Main: did quit main sta in thread "
+Thread.currentThread().getName());
}
}
@@ -59,22 +61,33 @@ class IETestThread extends Thread
try {
Dispatch.put(ie, "Visible", new Variant(true));
Dispatch.put(ie, "AddressBar", new Variant(true));
System.out.println(Dispatch.get(ie, "Path"));
System.out.println("IETestThread: " + Dispatch.get(ie, "Path"));
Dispatch.put(ie, "StatusText", new Variant("My Status Text"));
System.out.println("IETestThread: About to hookup event listener");
IEEvents ieE = new IEEvents();
new DispatchEvents((Dispatch) ie, ieE,"InternetExplorer.Application.1");
System.out.println("IETestThread: Did hookup event listener");
/// why is this here? Was there some other code here in the past?
Variant optional = new Variant();
optional.noParam();
optional.putNoParam();
System.out.println("IETestThread: About to call navigate to sourceforge");
Dispatch.call(ie, "Navigate", new Variant("http://sourceforge.net/projects/jacob-project"));
System.out.println("IETestThread: Did call navigate to sourceforge");
try { Thread.sleep(delay); } catch (Exception e) {}
System.out.println("IETestThread: About to call navigate to yahoo");
Dispatch.call(ie, "Navigate", new Variant("http://groups.yahoo.com/group/jacob-project"));
System.out.println("IETestThread: Did call navigate to yahoo");
try { Thread.sleep(delay); } catch (Exception e) {}
} catch (Exception e) {
e.printStackTrace();
} catch (Throwable re){
re.printStackTrace();
} finally {
ie.invoke("Quit", new Variant[] {});
System.out.println("IETestThread: About to send Quit");
ie.invoke("Quit", new Variant[] {});
System.out.println("IETestThread: Did send Quit");
}
// this blows up when it tries to release a DispatchEvents object
// I think this is because there is still one event we should get back
@@ -83,13 +96,14 @@ class IETestThread extends Thread
// freed before the callback
// commenting out ie.invoke(quit...) causes this to work without error
// this code tries to wait until the quit has been handled but that doesn't work
System.out.println("IETest: Waiting until we've received the quit callback");
System.out.println("IETestThread: Waiting until we've received the quit callback");
while (!quitHandled){
try { Thread.sleep(delay/5);} catch (InterruptedException e) {}
}
System.out.println("IETestThread: Received the quit callback");
// wait a little while for it to end
try {Thread.sleep(delay); } catch (InterruptedException e) {}
System.out.println("IETest: about to call release in thread " +
//try {Thread.sleep(delay); } catch (InterruptedException e) {}
System.out.println("IETestThread: about to call ComThread.Release in thread " +
Thread.currentThread().getName());
ComThread.Release();
@@ -101,76 +115,76 @@ class IETestThread extends Thread
public class IEEvents
{
public void BeforeNavigate2(Variant[] args) {
System.out.println("IEEvents: BeforeNavigate2");
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): BeforeNavigate2 "+args.length);
}
public void CommandStateChange(Variant[] args) {
System.out.println("IEEvents: CommandStateChange");
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): CommandStateChange "+args.length);
}
public void DocumentComplete(Variant[] args) {
System.out.println("IEEvents: DocumentComplete");
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): DocumentComplete "+args.length);
}
public void DownloadBegin(Variant[] args) {
System.out.println("IEEvents: DownloadBegin");
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): DownloadBegin "+args.length);
}
public void DownloadComplete(Variant[] args) {
System.out.println("IEEvents: DownloadComplete");
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): DownloadComplete "+args.length);
}
public void NavigateComplete2(Variant[] args) {
System.out.println("IEEvents: NavigateComplete2");
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): NavigateComplete "+args.length);
}
public void NewWindow2(Variant[] args) {
System.out.println("IEEvents: NewWindow2");
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): NewWindow2 "+args.length);
}
public void OnFullScreen(Variant[] args) {
System.out.println("IEEvents: OnFullScreen");
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): OnFullScreen "+args.length);
}
public void OnMenuBar(Variant[] args) {
System.out.println("IEEvents: OnMenuBar");
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): OnMenuBar "+args.length);
}
public void OnQuit(Variant[] args) {
System.out.println("IEEvents: OnQuit");
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): OnQuit "+args.length);
IETestThread.quitHandled = true;
}
public void OnStatusBar(Variant[] args) {
System.out.println("IEEvents: OnStatusBar");
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): OnStatusBar "+args.length);
}
public void OnTheaterMode(Variant[] args) {
System.out.println("IEEvents: OnTheaterMode");
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): OnTheaterMode "+args.length);
}
public void OnToolBar(Variant[] args) {
System.out.println("IEEvents: OnToolBar");
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): OnToolBar "+args.length);
}
public void OnVisible(Variant[] args) {
System.out.println("IEEvents: OnVisible");
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): OnVisible "+args.length);
}
public void ProgressChange(Variant[] args) {
System.out.println("IEEvents: ProgressChange");
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): ProgressChange "+args.length);
}
public void PropertyChange(Variant[] args) {
System.out.println("IEEvents: PropertyChange");
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): PropertyChange "+args.length);
}
public void StatusTextChange(Variant[] args) {
System.out.println("IEEvents: StatusTextChange");
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): StatusTextChange "+args.length);
}
public void TitleChange(Variant[] args) {
System.out.println("IEEvents: TitleChange");
System.out.println("IEEvents Received ("+Thread.currentThread().getName()+"): TitleChange "+args.length);
}
}