cleaned up variant serialization code. Its still broken. There just isn't as much of it now.

This commit is contained in:
clay_shooter
2005-10-29 16:01:30 +00:00
parent 4e2d45e3ff
commit 38c5d9d358
20 changed files with 281 additions and 304 deletions

View File

@@ -1,7 +1,6 @@
package com.jacob.com;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComFailException;
import com.jacob.com.DispatchEvents;
/**
@@ -60,7 +59,7 @@ public class ExcelEventTest extends InvocationProxy {
Dispatch.call(workbook, "Close", f);
axc.invoke("Quit", new Variant[] {});
} catch (ComFailException cfe) {
} catch (ComException cfe) {
cfe.printStackTrace();
System.out.println("Failed to attach to " + pid + ": "
+ cfe.getMessage());

View File

@@ -0,0 +1,61 @@
package com.jacob.com;
import java.io.*;
/**
* Verifies serialization works for variants.
* Variant serialization is BROKEN and has been since 1.7
* <pre>-Djava.library.path=d:/jacob/release</pre>
*/
class VariantSerializationTest {
static Variant vs1 = new Variant("hi");
static Variant vs2 = new Variant(123.456);
public static void main(String[] args) throws Exception {
doJustSerialization();
compareVariantBytes();
}
private static void compareVariantBytes() throws Exception{
System.out.println("compareVariantBytes");
Variant var1 = new Variant("hello");
Variant var2 = new Variant("hello");
byte[] var1Bytes = var1.SerializationWriteToBytes();
byte[] var2Bytes = var2.SerializationWriteToBytes();
for ( int i = 0 ; i < var1Bytes.length; i++){
if (var1Bytes[i]!=var2Bytes[i]){
System.out.println("variant strings differ at position "+i);
return;
}
}
System.out.println("two strings return identical serialization data");
}
private static void doJustSerialization() throws Exception {
System.out.println("doJustSerialization");
// same thing with serialization
FileOutputStream fos;
FileInputStream fis;
fos = new FileOutputStream("foo.ser");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(vs1);
//oos.writeObject(vs2);
oos.close();
fos.close();
fis = new FileInputStream("foo.ser");
ObjectInputStream ois = new ObjectInputStream(fis);
Variant vss1 = null;
Variant vss2 = null;
vss1 = (Variant) ois.readObject();
//vss2 = (Variant) ois.readObject();
ois.close();
fis.close();
System.out.println(vss1);
System.out.println(vss2);
}
}

View File

@@ -0,0 +1,24 @@
package com.jacob.com;
/**
* runs through some of the get and set methods on Variant
*/
class VariantTest {
public static void main(String[] args) {
//deprecated
//System.runFinalizersOnExit(true);
Variant v = new Variant();
v.putInt(10);
System.out.println("got=" + v.toInt());
v.putInt(10);
System.out.println("got=" + v.toDouble());
v.putString("1234.567");
System.out.println("got=" + v.toString());
v.putBoolean(true);
System.out.println("got=" + v.toBoolean());
v.putBoolean(false);
System.out.println("got=" + v.toBoolean());
v.putCurrency(123456789123456789L);
System.out.println("got=" + v.toCurrency());
}
}

View File

@@ -1,7 +1,7 @@
package com.jacob.com;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComFailException;
import com.jacob.com.ComException;
import com.jacob.com.DispatchEvents;
/**
@@ -51,7 +51,7 @@ public class WordEventTest extends InvocationProxy {
}
axc.invoke("Quit", new Variant[] {});
} catch (ComFailException cfe) {
} catch (ComException cfe) {
cfe.printStackTrace();
System.out.println("Failed to attach to " + pid + ": "
+ cfe.getMessage());