diff --git a/docs/ReleaseNotes.html b/docs/ReleaseNotes.html
index 76fd6ae..6426583 100644
--- a/docs/ReleaseNotes.html
+++ b/docs/ReleaseNotes.html
@@ -17,6 +17,8 @@
Redundant constructors removed
Experimental toJavaObject() method added that automatically
converts to appropriate java type
+ Support added for "NOTHING", a Variant of type Dispatch with no value
+ Non functional getNull() and getEmpty() methods deprecated. They were void methods
diff --git a/jni/Variant.cpp b/jni/Variant.cpp
index 315f368..216fc06 100644
--- a/jni/Variant.cpp
+++ b/jni/Variant.cpp
@@ -243,19 +243,6 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toEnumVariant
return NULL;
}
-/**
- * returns nothing.
- * an odd void if there ever was one.
- * It should return null if it is of type VT_NULL and
- * null if it is not of the right type.
- * Ie: there is no good way to differentiate between
- * a null value and a type mismatch
- **/
-JNIEXPORT void JNICALL Java_com_jacob_com_Variant_getNull
- (JNIEnv *env, jobject _this)
-{
-}
-
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putNull
(JNIEnv *env, jobject _this)
{
@@ -487,7 +474,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_VariantClear
/**
* Converts the data to a Dispatch object and then returns it as a Dispatch
*/
-JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toDispatch
+JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toDispatchObject
(JNIEnv *env, jobject _this)
{
VARIANT *v = extractVariant(env, _this);
@@ -693,25 +680,6 @@ JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_toError
return NULL;
}
-/**
- * Not actually supported. Always returns null
- */
-JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toObject
- (JNIEnv *env, jobject _this)
-{
- // not supported
- return NULL;
-}
-
-/**
- * Dummy method to provide symmetry with putEmpty.
- * This get method should probably return null instead of void
- */
-JNIEXPORT void JNICALL Java_com_jacob_com_Variant_getEmpty
- (JNIEnv *env, jobject _this)
-{
-}
-
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putEmpty
(JNIEnv *env, jobject _this)
{
@@ -722,6 +690,19 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putEmpty
}
}
+/**
+ * Sets the variant type to dispatch with no value object
+ **/
+JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putNothing
+ (JNIEnv *env, jobject _this)
+{
+ VARIANT *v = extractVariant(env, _this);
+ if (v) {
+ VariantClear(v); // whatever was there before
+ V_VT(v) = VT_DISPATCH;
+ }
+}
+
JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getError
(JNIEnv *env, jobject _this)
{
@@ -764,16 +745,6 @@ JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getDouble
return NULL;
}
-/**
- * always returns null
- **/
-JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_getObject
- (JNIEnv *env, jobject _this)
-{
- // not supported
- return NULL;
-}
-
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putCurrency
(JNIEnv *env, jobject _this, jlong cur)
{
@@ -792,7 +763,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putCurrency
* There is currently no way to pass NULL into this method
* to create something like "NOTHING" from VB
* */
-JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putObject
+JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putDispatchObject
(JNIEnv *env, jobject _this, jobject _that)
{
VARIANT *v = extractVariant(env, _this);
@@ -1102,7 +1073,9 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putSafeArray
return;
}
-
+/**
+ * sets the type to VT_ERROR and the error message to DISP_E_PARAMNOTFOIUND
+ * */
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_noParam
(JNIEnv *env, jobject _this)
{
diff --git a/jni/Variant.h b/jni/Variant.h
index 37eb5f4..5626b90 100644
--- a/jni/Variant.h
+++ b/jni/Variant.h
@@ -57,14 +57,6 @@ JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_toBoolean
JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toEnumVariant
(JNIEnv *, jobject);
-/*
- * Class: com_jacob_com_Variant
- * Method: getNull
- * Signature: ()V
- */
-JNIEXPORT void JNICALL Java_com_jacob_com_Variant_getNull
- (JNIEnv *, jobject);
-
/*
* Class: com_jacob_com_Variant
* Method: putNull
@@ -206,7 +198,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_com_jacob_com_VariantClear
* Method: toDispatch
* Signature: ()LDispatch;
*/
-JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toDispatch
+JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toDispatchObject
(JNIEnv *, jobject);
/*
@@ -307,18 +299,10 @@ JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_toError
/*
* Class: com_jacob_com_Variant
- * Method: toObject
- * Signature: ()Ljava/lang/Object;
- */
-JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toObject
- (JNIEnv *, jobject);
-
-/*
- * Class: com_jacob_com_Variant
- * Method: getEmpty
+ * Method: putEmpty
* Signature: ()V
*/
-JNIEXPORT void JNICALL Java_com_jacob_com_Variant_getEmpty
+JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putEmpty
(JNIEnv *, jobject);
/*
@@ -326,7 +310,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_getEmpty
* Method: putEmpty
* Signature: ()V
*/
-JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putEmpty
+JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putNothing
(JNIEnv *, jobject);
/*
@@ -353,14 +337,6 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putError
JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getDouble
(JNIEnv *, jobject);
-/*
- * Class: com_jacob_com_Variant
- * Method: getObject
- * Signature: ()Ljava/lang/Object;
- */
-JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_getObject
- (JNIEnv *, jobject);
-
/*
* Class: com_jacob_com_Variant
* Method: putCurrency
@@ -374,7 +350,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putCurrency
* Method: putObject
* Signature: (Ljava/lang/Object;)V
*/
-JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putObject
+JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putDispatchObject
(JNIEnv *, jobject, jobject);
/*
@@ -612,7 +588,7 @@ JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_isNull
* Method: zeroVariant
* Signature: ()V
*
- * This should only be used on variant objects created by teh
+ * This should only be used on variant objects created by the
* com layer as part of a call through EventProxy.
* This zeros out the variant pointer in the Variant object
* so that the calling COM program can free the memory.
diff --git a/src/com/jacob/com/Dispatch.java b/src/com/jacob/com/Dispatch.java
index 8b337f6..bc1bba2 100644
--- a/src/com/jacob/com/Dispatch.java
+++ b/src/com/jacob/com/Dispatch.java
@@ -310,44 +310,37 @@ public class Dispatch extends JacobObject
}
/**
- * map args based on msdn doc
- * @param o
+ * Map args based on msdn doc
+ * This method relies on the variant constructor except for arrays
+ * @param objectToBeMadeIntoVariant
* @return Variant that represents the object
*/
- protected static Variant obj2variant(Object o) {
- if (o == null)
+ protected static Variant obj2variant(Object objectToBeMadeIntoVariant) {
+ if (objectToBeMadeIntoVariant == null)
return new Variant();
- if (o instanceof Variant)
- return (Variant) o;
- if (o instanceof Integer)
- return new Variant(((Integer) o).intValue());
- if (o instanceof Short)
- return new Variant(((Short) o).shortValue());
- if (o instanceof String)
- return new Variant((String) o);
- if (o instanceof Boolean)
- return new Variant(((Boolean) o).booleanValue());
- if (o instanceof Double)
- return new Variant(((Double) o).doubleValue());
- if (o instanceof Float)
- return new Variant(((Float) o).floatValue());
- if (o instanceof SafeArray)
- return new Variant((SafeArray) o);
- if (o instanceof Dispatch) {
- Variant v = new Variant();
- v.putObject((Dispatch) o);
- return v;
- }
+ if (objectToBeMadeIntoVariant instanceof Variant)
+ // if a variant was passed in then be a slacker and just return it
+ return (Variant) objectToBeMadeIntoVariant;
+ if ( objectToBeMadeIntoVariant instanceof Integer
+ || objectToBeMadeIntoVariant instanceof Short
+ || objectToBeMadeIntoVariant instanceof String
+ || objectToBeMadeIntoVariant instanceof Boolean
+ || objectToBeMadeIntoVariant instanceof Double
+ || objectToBeMadeIntoVariant instanceof Float
+ || objectToBeMadeIntoVariant instanceof SafeArray
+ || objectToBeMadeIntoVariant instanceof Dispatch)
+ return new Variant(objectToBeMadeIntoVariant);
+
// automatically convert arrays using reflection
- Class c1 = o.getClass();
+ Class c1 = objectToBeMadeIntoVariant.getClass();
SafeArray sa = null;
if (c1.isArray()) {
- int len1 = Array.getLength(o);
- Object first = Array.get(o, 0);
+ int len1 = Array.getLength(objectToBeMadeIntoVariant);
+ Object first = Array.get(objectToBeMadeIntoVariant, 0);
if (first.getClass().isArray()) {
int max = 0;
for (int i = 0; i < len1; i++) {
- Object e1 = Array.get(o, i);
+ Object e1 = Array.get(objectToBeMadeIntoVariant, i);
int len2 = Array.getLength(e1);
if (max < len2) {
max = len2;
@@ -355,7 +348,7 @@ public class Dispatch extends JacobObject
}
sa = new SafeArray(Variant.VariantVariant, len1, max);
for (int i = 0; i < len1; i++) {
- Object e1 = Array.get(o, i);
+ Object e1 = Array.get(objectToBeMadeIntoVariant, i);
for (int j = 0; j < Array.getLength(e1); j++) {
sa.setVariant(i, j, obj2variant(Array.get(e1, j)));
}
@@ -363,7 +356,7 @@ public class Dispatch extends JacobObject
} else {
sa = new SafeArray(Variant.VariantVariant, len1);
for (int i = 0; i < len1; i++) {
- sa.setVariant(i, obj2variant(Array.get(o, i)));
+ sa.setVariant(i, obj2variant(Array.get(objectToBeMadeIntoVariant, i)));
}
}
return new Variant(sa);
@@ -372,14 +365,15 @@ public class Dispatch extends JacobObject
}
/**
- * same as above, for an array
- * @param o
+ * converts an array of objects into an array of Variants by
+ * repeatedly calling obj2Variant(Object)
+ * @param arrayOfObjectsToBeConverted
* @return Variant[]
*/
- protected static Variant[] obj2variant(Object[] o) {
- Variant vArg[] = new Variant[o.length];
- for (int i = 0; i < o.length; i++) {
- vArg[i] = obj2variant(o[i]);
+ protected static Variant[] obj2variant(Object[] arrayOfObjectsToBeConverted) {
+ Variant vArg[] = new Variant[arrayOfObjectsToBeConverted.length];
+ for (int i = 0; i < arrayOfObjectsToBeConverted.length; i++) {
+ vArg[i] = obj2variant(arrayOfObjectsToBeConverted[i]);
}
return vArg;
}
@@ -463,7 +457,7 @@ public class Dispatch extends JacobObject
/**
* @param dispatchTarget
* @param name
- * @param args
+ * @param args an array of argument objects
*/
public static void callSubN(Dispatch dispatchTarget, String name, Object[] args) {
invokeSubv(dispatchTarget, name, Dispatch.Method | Dispatch.Get, obj2variant(args),
@@ -473,7 +467,7 @@ public class Dispatch extends JacobObject
/**
* @param dispatchTarget
* @param dispID
- * @param args
+ * @param args an array of argument objects
*/
public static void callSubN(Dispatch dispatchTarget, int dispID, Object[] args) {
invokeSubv(dispatchTarget, dispID, Dispatch.Method | Dispatch.Get, obj2variant(args),
diff --git a/src/com/jacob/com/Variant.java b/src/com/jacob/com/Variant.java
index f1ade97..d84aafc 100644
--- a/src/com/jacob/com/Variant.java
+++ b/src/com/jacob/com/Variant.java
@@ -19,7 +19,6 @@
*/
package com.jacob.com;
-import java.io.Serializable;
import java.util.Date;
/**
@@ -131,6 +130,25 @@ public class Variant extends JacobObject {
*/
public native double toDate();
+ /**
+ * Returns the windows time contained in this Variant to a Java Date
+ * should return null if this is not a date Variant
+ * SF 959382.
+ *
+ * This method added 12/2005 for possible use by jacobgen instead of its conversion code
+ * @return java.util.Date
+ * (after possible conversion)
+ */
+ public Date toJavaDate(){
+ double windowsDate = toDate();
+ if (windowsDate == 0){
+ return null;
+ } else {
+ return DateUtilities.convertWindowsTimeToDate(getDate());
+ }
+ }
+
+
/**
* @return the value of this variant as boolean (after possible conversion)
*/
@@ -139,10 +157,17 @@ public class Variant extends JacobObject {
/** @return the value of this variant as an enumeration (java style) */
public native EnumVariant toEnumVariant();
- /** As far as I can tell : this does absolutely nothing */
- public native void getNull();
+ /**
+ * This method would have returned null if the type was VT_NULL.
+ * But because we return null if the data is not of the right type,
+ * this method should have always returned null
+ * @deprecated method never did anything
+ */
+ public void getNull() {};
- /** Set this Variant's type to VT_NULL (the VB equivalent of NULL) */
+ /**
+ * Set this Variant's type to VT_NULL (the VB equivalent of NULL)
+ * */
public native void putNull();
/**
@@ -306,7 +331,13 @@ public class Variant extends JacobObject {
/**
* @return the content of this variant as a Dispatch object
*/
- public native Dispatch toDispatch();
+ public Dispatch toDispatch(){ return toDispatchObject(); }
+
+ /**
+ * native method used by toDispatch()
+ * @return
+ */
+ private native Dispatch toDispatchObject();
/**
* this returns null
@@ -383,19 +414,26 @@ public class Variant extends JacobObject {
public native byte toByte();
/**
- * same as {@link #toDispatch()}
- * @return this object as a dispatch
+ * same as {@link #toDispatch()}
+ * This is different than the other get methods.
+ * It calls toDispatch wich will do type conversion.
+ * Most getXXX() methods will return null if the data is not of
+ * the requested type
+ * @return this object as a dispatch (Why isn't this typed as type Dispatch?)
*/
- public Object getDispatch() {
+ public Dispatch getDispatch() {
return toDispatch();
}
/**
- * same as {@link #putObject(Object)}
+ * This acts a cover for
+ * same as @link #putObject(Object)
+ *
+ * Why isn't this typed as type Dispatch?
* @param in
*/
- public void putDispatch(Object in) {
- putObject(in);
+ public void putDispatch(Dispatch in) {
+ putDispatchObject(in);
}
/**
@@ -416,13 +454,33 @@ public class Variant extends JacobObject {
public native int toError();
+ /**
+ * acts a a cover for toDispatch
+ * @return Object returned by toDispatch()
+ * @deprecated should use toDispatch() instead
+ */
public Object toObject() {
return toDispatch();
}
- public native void getEmpty();
+ /**
+ * Pointless method that was put here so that putEmpty() has a get method.
+ * This would have returned null if the value was VT_EMPTY
+ * or if it wasn't so it would have always returned the same value.
+ * @deprecated method never did anything
+ */
+ public void getEmpty() {};
+ /**
+ * Sets the type to VariantEmpty. No values needed
+ */
public native void putEmpty();
+
+ /**
+ * Sets the type to VariantDispatch and sets teh value to null
+ * Equivalent to VB's nothing
+ */
+ public native void putNothing();
public native int getError();
@@ -432,8 +490,21 @@ public class Variant extends JacobObject {
public native void putCurrency(long in);
- /** puts an object into the */
- public native void putObject(Object in);
+ /**
+ * puts an object into the Variant -- converts to Dispatch
+ * @deprecated use putDispatch()
+ * */
+ public void putObject(Object in){
+ // this should verify in instanceof Dispatch
+ putDispatchObject(in); }
+
+ /**
+ * a cover for putDispatch() but is named differently so that
+ * we can screen the incoming dispatches in putDispatch() before this
+ * is invoked
+ * @param in
+ */
+ private native void putDispatchObject(Object in);
public native void putDouble(double in);
@@ -451,6 +522,11 @@ public class Variant extends JacobObject {
public native void putBooleanRef(boolean in);
+ /**
+ * Just a cover for putObject.
+ * @deprecated we shouldn't accept any old random object
+ * @param in
+ */
public void putObjectRef(Object in) {
putObject(in);
}
@@ -492,6 +568,9 @@ public class Variant extends JacobObject {
public native void putSafeArray(SafeArray in);
+ /**
+ * sets the type to VT_ERROR and the error message to DISP_E_PARAMNOTFOIUND
+ * */
public native void noParam();
/**
@@ -502,15 +581,34 @@ public class Variant extends JacobObject {
throw new NotImplementedException("Not implemented");
}
+ /**
+ *
+ * @return returns the value as a float if the type is of type float
+ */
public native float getFloat();
+ /**
+ * fills the Variant with a float and sets the type to float
+ * @param in
+ */
public native void putFloat(float in);
- public void putDispatchRef(Object in) {
- putDispatch(in);
+ /**
+ * Dispatch and dispatchRef are treated the same
+ * This is a cover for putDispatch().
+ * Dispatch and dispatchRef are treated the same
+ * @param in
+ */
+ public void putDispatchRef(Dispatch in) {
+ putDispatchObject(in);
}
- public Object getDispatchRef() {
+ /**
+ * Dispatch and dispatchRef are treated the same
+ * This is just a cover for getDispatch()
+ * @return the results of getDispatch()
+ */
+ public Dispatch getDispatchRef() {
return getDispatch();
}
@@ -536,6 +634,11 @@ public class Variant extends JacobObject {
changeType((short) in);
}
+ /**
+ * I don't know what this is. Is it some legacy (pre 1.8) thing?
+ * @deprecated
+ * @return
+ */
public Object toScriptObject() {
return toDispatch();
}
@@ -589,55 +692,72 @@ public class Variant extends JacobObject {
/**
* constructor that accepts the data object and informaton about
- * whether this is by reference or not
- * @param o
+ * whether this is by reference or not.
+ * @param pValueObject a null object sets this to "empty"
* @param fByRef
*/
- public Variant(Object o, boolean fByRef) {
+ public Variant(Object pValueObject, boolean fByRef) {
init();
- if (o == null) {
+ if (pValueObject == null) {
putEmpty();
- } else if (o instanceof Integer) {
+ } else if (pValueObject instanceof Integer) {
if (fByRef)
- putIntRef(((Integer) o).intValue());
+ putIntRef(((Integer) pValueObject).intValue());
else
- putInt(((Integer) o).intValue());
- } else if (o instanceof String) {
+ putInt(((Integer) pValueObject).intValue());
+ } else if (pValueObject instanceof Short) {
if (fByRef)
- putStringRef((String) o);
+ putShortRef(((Short) pValueObject).shortValue());
else
- putString((String) o);
- } else if (o instanceof Boolean) {
+ putShort(((Short) pValueObject).shortValue());
+ } else if (pValueObject instanceof String) {
if (fByRef)
- putBooleanRef(((Boolean) o).booleanValue());
+ putStringRef((String) pValueObject);
else
- putBoolean(((Boolean) o).booleanValue());
- } else if (o instanceof Double) {
+ putString((String) pValueObject);
+ } else if (pValueObject instanceof Boolean) {
if (fByRef)
- putDoubleRef(((Double) o).doubleValue());
+ putBooleanRef(((Boolean) pValueObject).booleanValue());
else
- putDouble(((Double) o).doubleValue());
- } else if (o instanceof Float) {
+ putBoolean(((Boolean) pValueObject).booleanValue());
+ } else if (pValueObject instanceof Double) {
if (fByRef)
- putFloatRef(((Float) o).floatValue());
+ putDoubleRef(((Double) pValueObject).doubleValue());
else
- putFloat(((Float) o).floatValue());
- } else if (o instanceof Date){
+ putDouble(((Double) pValueObject).doubleValue());
+ } else if (pValueObject instanceof Float) {
+ if (fByRef)
+ putFloatRef(((Float) pValueObject).floatValue());
+ else
+ putFloat(((Float) pValueObject).floatValue());
+ } else if (pValueObject instanceof Byte){
if (fByRef){
- putDateRef((Date) o);
+ putByteRef(((Byte)pValueObject).byteValue());
} else {
- putDate((Date)o);
+ putByte(((Byte)pValueObject).byteValue());
}
- } else if (o instanceof SafeArray) {
+ } else if (pValueObject instanceof Date){
+ if (fByRef){
+ putDateRef((Date) pValueObject);
+ } else {
+ putDate((Date)pValueObject);
+ }
+ } else if (pValueObject instanceof SafeArray) {
if (fByRef)
- putSafeArrayRef((SafeArray) o);
+ putSafeArrayRef((SafeArray) pValueObject);
else
- putSafeArray((SafeArray) o);
+ putSafeArray((SafeArray) pValueObject);
+ } else if (pValueObject instanceof Dispatch){
+ if (fByRef)
+ putDispatchRef((Dispatch)pValueObject);
+ else
+ putDispatch((Dispatch)pValueObject);
} else {
+ // should really throw an illegal argument exception if its an invalid type
if (fByRef)
- putObjectRef(o);
+ putObjectRef(pValueObject);
else
- putObject(o);
+ putObject(pValueObject);
}
}
@@ -758,7 +878,7 @@ public class Variant extends JacobObject {
}
/**
- * is the variant null or empty or error or null disp
+ * is the variant null or empty or error or null dispatch
* @return true if it is null or false if not
*/
public native boolean isNull();
@@ -831,8 +951,7 @@ public class Variant extends JacobObject {
result = new NotImplementedException("Not implemented: VariantError");
break;
case Variant.VariantBoolean : //11
- result = new Boolean(this.getBoolean
- ());
+ result = new Boolean(this.getBoolean());
break;
case Variant.VariantVariant : //12
result = new NotImplementedException("Not implemented: VariantVariant");
@@ -841,7 +960,8 @@ public class Variant extends JacobObject {
result = new NotImplementedException("Not implemented: VariantObject");
break;
case Variant.VariantByte : //17
- result = new NotImplementedException("Not implemented: VariantByte");
+ result = new Byte(this.getByte());
+ //result = new NotImplementedException("Not implemented: VariantByte");
break;
case Variant.VariantTypeMask : //4095
result = new NotImplementedException("Not implemented: VariantTypeMask");
diff --git a/unittest/com/jacob/com/VariantTest.java b/unittest/com/jacob/com/VariantTest.java
index 1e22f9f..6e2fbe4 100644
--- a/unittest/com/jacob/com/VariantTest.java
+++ b/unittest/com/jacob/com/VariantTest.java
@@ -5,20 +5,61 @@ package com.jacob.com;
*/
class VariantTest {
public static void main(String[] args) {
- //deprecated
- //System.runFinalizersOnExit(true);
+ System.out.println("Testing Started");
Variant v = new Variant();
v.putInt(10);
- System.out.println("got=" + v.toInt());
+ if (v.toInt() != 10){
+ System.out.println("int test failed");
+ }
v.putInt(10);
- System.out.println("got=" + v.toDouble());
+ if (v.toDouble() != 10.0){
+ System.out.println("double test failed");
+ }
v.putString("1234.567");
- System.out.println("got=" + v.toString());
+ if (!"1234.567".equals(v.toString())){
+ System.out.println("string test failed");
+ }
v.putBoolean(true);
- System.out.println("got=" + v.toBoolean());
+ if (v.toBoolean() != true){
+ System.out.println("failed boolean test(true)");
+ }
v.putBoolean(false);
- System.out.println("got=" + v.toBoolean());
+ if (v.toBoolean() != false){
+ System.out.println("failed boolean test(false)");
+ }
v.putCurrency(123456789123456789L);
- System.out.println("got=" + v.toCurrency());
+ if (v.toCurrency()!=123456789123456789L){
+ System.out.println("failed long test");
+ }
+
+ v.putNull();
+ if (!v.isNull()){
+ System.out.println("failed detecting set null");
+ }
+ v.putString("something other than null");
+ if (v.isNull()){
+ System.out.println("failed null replacement with string");
+ }
+
+ v.putEmpty();
+ if (!v.isNull()){
+ System.out.println("failed detecting set empty as null");
+ }
+ v.putString("something other than null");
+ if (v.isNull()){
+ System.out.println("failed empty replacement with string as isNull");
+ }
+
+ Variant v2 = new Variant();
+ v2.putNothing();
+ if (v2.getvt() != Variant.VariantDispatch){
+ System.out.println("putNothing was supposed to set the type to VariantDispatch");
+ }
+ if (!v2.isNull()){
+ System.out.println("putNothing is supposed to cause isNull() to return true");
+ }
+
+ System.out.println("Testing Complete");
+
}
}