adding new javascript tests - liveconnect

This commit is contained in:
cbegle%netscape.com 1999-05-26 22:14:51 +00:00
Родитель 0d63deaadc
Коммит 7c561ddf70
35 изменённых файлов: 7055 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,756 @@
/* -*- Mode: java; tab-width: 8 -*-
* Copyright © 1997, 1998 Netscape Communications Corporation, All Rights Reserved.
*/
package com.netscape.javascript.qa.liveconnect;
/**
* Attempt to get and set the public fields.
*
* XXX need to override toString, toNumber with values in
* static fields.
*
* XXX override both instance and static versions of the method
* @author christine m begle
*/
public class DataTypeClass {
/**
* Constructor does nothing
*
*/
public DataTypeClass() {
}
/**
* Override toNumber
*
*/
public static double PUB_DOUBLE_REPRESENTATION = 0.2134;
public double doubleValue() {
return PUB_DOUBLE_REPRESENTATION;
}
public int toNumber() {
return PUB_NUMBER_REPRESENTATION;
}
public boolean booleanValue() {
return PUB_BOOLEAN_REPRESENTATION;
}
public boolean PUB_BOOLEAN_REPRESENTATION = true;
public static int PUB_NUMBER_REPRESENTATION = 2134;
/**
* Override toString
*/
public String toString() {
return PUB_STRING_REPRESENTATION;
}
public static String PUB_STRING_REPRESENTATION =
"DataTypeClass Instance";
/**
* Have a method that has the same name as a field.
*/
public String amIAFieldOrAMethod() {
return "METHOD!";
}
public String amIAFieldOrAMethod = "FIELD!";
public static boolean staticGetBoolean() {
return PUB_STATIC_BOOLEAN;
}
public static Boolean staticGetBooleanObject() {
return new Boolean(PUB_STATIC_BOOLEAN);
}
public static byte staticGetByte() {
return PUB_STATIC_BYTE;
}
public static Byte staticGetByteObject() {
return new Byte(PUB_STATIC_BYTE);
}
public static Integer staticGetIntegerObject() {
return new Integer(PUB_STATIC_INT);
}
public static int staticGetInteger() {
return new Integer(PUB_STATIC_INT).intValue();
}
public static Double staticGetDoubleObject() {
return new Double(PUB_STATIC_DOUBLE);
}
public static double staticGetDouble() {
return new Double(PUB_STATIC_DOUBLE).doubleValue();
}
public static Float staticGetFloatObject() {
return new Float(PUB_STATIC_FLOAT);
}
public static float staticGetFloat() {
return new Float(PUB_STATIC_FLOAT).floatValue();
}
public static Long staticGetLongObject() {
return new Long(PUB_STATIC_LONG);
}
public static long staticGetLong() {
return new Long(PUB_STATIC_LONG).longValue();
}
public static Short staticGetShortObject() {
return new Short(PUB_STATIC_SHORT);
}
public static short staticGetShort() {
return new Short(PUB_STATIC_SHORT).shortValue();
}
public static String staticGetStringObject() {
return new String(PUB_STATIC_STRING);
}
public static char staticGetChar() {
return PUB_STATIC_CHAR;
}
public static Character staticGetCharacter() {
return new Character(PUB_STATIC_CHAR);
}
// instance getters
public boolean getBoolean() {
return PUB_BOOLEAN;
}
public Boolean getBooleanObject() {
return PUB_BOOLEAN_OBJECT;
}
public byte getByte() {
return PUB_BYTE;
}
public Byte getByteObject() {
return new Byte(PUB_BYTE);
}
public Integer getIntegerObject() {
return new Integer(PUB_INT);
}
public int getInteger() {
return new Integer(PUB_INT).intValue();
}
public Double getDoubleObject() {
return new Double(PUB_DOUBLE);
}
public double getDouble() {
return new Double(PUB_DOUBLE).doubleValue();
}
public Float getFloatObject() {
return new Float(PUB_FLOAT);
}
public float getFloat() {
return new Float(PUB_FLOAT).floatValue();
}
public Long getLongObject() {
return new Long(PUB_LONG);
}
public long getLong() {
return new Long(PUB_LONG).longValue();
}
public String getStringObject() {
return new String(PUB_STRING);
}
public Object getObject() {
return PUB_OBJECT;
}
public Short getShortObject() {
return new Short(PUB_SHORT);
}
public short getShort() {
return new Short(PUB_SHORT).shortValue();
}
public char getChar() {
return PUB_CHAR;
}
public Character getCharacter() {
return new Character(PUB_CHAR);
}
// SETTERS
public static void staticSetBoolean(boolean b) {
PUB_STATIC_BOOLEAN = b;
}
public static void staticSetBooleanObject(Boolean b) {
PUB_STATIC_BOOLEAN_OBJECT = b;
}
public static void staticSetByte(byte b) {
PUB_STATIC_BYTE = b;
}
public static void staticSetByteObject(Byte b) {
PUB_STATIC_BYTE_OBJECT = b;
}
public static void staticSetIntegerObject(Integer i) {
PUB_STATIC_INTEGER_OBJECT = i;
}
public static void staticSetInteger(int i) {
PUB_STATIC_INT = i;
}
public static void staticSetDoubleObject( Double d ) {
PUB_STATIC_DOUBLE_OBJECT = d;
}
public static void staticSetDouble(double d) {
PUB_STATIC_DOUBLE = d;
}
public static void staticSetFloatObject(Float f) {
PUB_STATIC_FLOAT_OBJECT = f ;
}
public static void staticSetFloat(float f) {
PUB_STATIC_FLOAT = f;
}
public static void staticSetLongObject(Long l) {
PUB_STATIC_LONG_OBJECT = l ;
}
public static void staticSetLong(long l) {
PUB_STATIC_LONG = l ;
}
public static void staticSetShortObject(Short s) {
PUB_STATIC_SHORT_OBJECT = s;
}
public static void staticSetShort(short s) {
PUB_STATIC_SHORT = s;
}
public static void staticSetStringObject(String s) {
PUB_STATIC_STRING = s;
}
public static void staticSetChar(char c) {
PUB_STATIC_CHAR = c;
}
public static void staticSetCharacter(Character c) {
PUB_STATIC_CHAR_OBJECT = c ;
}
// instance setters
public void setBoolean(boolean b) {
PUB_BOOLEAN = b;
}
public void setBooleanObject(Boolean b) {
PUB_BOOLEAN_OBJECT = b;
}
public void setByte(byte b) {
PUB_BYTE = b;
}
public void setByteObject(Byte b) {
PUB_BYTE_OBJECT = b;
}
public void setIntegerObject(Integer i) {
PUB_INTEGER_OBJECT = i;
}
public void setInteger(int i) {
PUB_INT = i;
}
public void setDoubleObject( Double d ) {
PUB_DOUBLE_OBJECT = d;
}
public void setDouble(double d) {
PUB_DOUBLE = d;
}
public void setFloatObject(Float f) {
PUB_FLOAT_OBJECT = f ;
}
public void setFloat(float f) {
PUB_FLOAT = f;
}
public void setLongObject(Long l) {
PUB_LONG_OBJECT = l ;
}
public void setLong(long l) {
PUB_LONG = l ;
}
public void setShortObject(Short s) {
PUB_SHORT_OBJECT = s;
}
public void setShort(short s) {
PUB_SHORT = s;
}
public void setStringObject(String s) {
PUB_STRING = s;
}
public void setObject( Object o ) {
PUB_OBJECT = o;
}
public void setChar(char c) {
PUB_CHAR = c;
}
public void setCharacter(Character c) {
PUB_CHAR_OBJECT = c ;
}
// STATIC FIELDS
public static final Class PUB_STATIC_FINAL_CLASS = null;
public static Class PUB_STATIC_CLASS = PUB_STATIC_FINAL_CLASS;
public Class PUB_CLASS = PUB_STATIC_FINAL_CLASS;
public Class instanceGetClass() {
return PUB_CLASS;
}
public void setClass( Class c ) {
PUB_CLASS = c;
}
public Class staticGetClass() {
return PUB_STATIC_CLASS;
}
public void staticSetClass( Class c ) {
PUB_STATIC_CLASS = c;
}
public static final boolean PUB_STATIC_FINAL_BOOLEAN = true;
public static final byte PUB_STATIC_FINAL_BYTE = Byte.MAX_VALUE;
public static final short PUB_STATIC_FINAL_SHORT = Short.MAX_VALUE;
public static final int PUB_STATIC_FINAL_INT = Integer.MAX_VALUE;
public static final long PUB_STATIC_FINAL_LONG = Long.MAX_VALUE;
public static final float PUB_STATIC_FINAL_FLOAT = Float.MAX_VALUE;
public static final double PUB_STATIC_FINAL_DOUBLE = Double.MAX_VALUE;
public static final char PUB_STATIC_FINAL_CHAR = Character.MAX_VALUE;
public static final Object PUB_STATIC_FINAL_OBJECT = new Object();
public static final Boolean PUB_STATIC_FINAL_BOOLEAN_OBJECT = new Boolean(PUB_STATIC_FINAL_BOOLEAN);
public static final Byte PUB_STATIC_FINAL_BYTE_OBJECT = new Byte(PUB_STATIC_FINAL_BYTE);
public static final Short PUB_STATIC_FINAL_SHORT_OBJECT = new Short(PUB_STATIC_FINAL_SHORT);
public static final Integer PUB_STATIC_FINAL_INTEGER_OBJECT = new Integer(PUB_STATIC_FINAL_INT);
public static final Long PUB_STATIC_FINAL_LONG_OBJECT = new Long(PUB_STATIC_FINAL_LONG);
public static final Float PUB_STATIC_FINAL_FLOAT_OBJECT = new Float(PUB_STATIC_FINAL_FLOAT);
public static final Double PUB_STATIC_FINAL_DOUBLE_OBJECT = new Double(PUB_STATIC_FINAL_DOUBLE);
public static final Character PUB_STATIC_FINAL_CHAR_OBJECT = new Character(PUB_STATIC_FINAL_CHAR);
public static final String PUB_STATIC_FINAL_STRING = new String("JavaScript Test");
public static boolean PUB_STATIC_BOOLEAN = PUB_STATIC_FINAL_BOOLEAN;
public static byte PUB_STATIC_BYTE = PUB_STATIC_FINAL_BYTE;
public static short PUB_STATIC_SHORT = PUB_STATIC_FINAL_SHORT;
public static int PUB_STATIC_INT = PUB_STATIC_FINAL_INT;
public static long PUB_STATIC_LONG = PUB_STATIC_FINAL_LONG;
public static float PUB_STATIC_FLOAT = PUB_STATIC_FINAL_FLOAT;
public static double PUB_STATIC_DOUBLE = PUB_STATIC_FINAL_DOUBLE;
public static char PUB_STATIC_CHAR = PUB_STATIC_FINAL_CHAR;
public static Object PUB_STATIC_OBJECT = PUB_STATIC_FINAL_OBJECT;
public static Boolean PUB_STATIC_BOOLEAN_OBJECT = new Boolean(PUB_STATIC_FINAL_BOOLEAN);
public static Byte PUB_STATIC_BYTE_OBJECT = new Byte(PUB_STATIC_FINAL_BYTE);
public static Short PUB_STATIC_SHORT_OBJECT = new Short(PUB_STATIC_FINAL_SHORT);
public static Integer PUB_STATIC_INTEGER_OBJECT = new Integer(PUB_STATIC_FINAL_INT);
public static Long PUB_STATIC_LONG_OBJECT = new Long(PUB_STATIC_FINAL_LONG);
public static Float PUB_STATIC_FLOAT_OBJECT = new Float(PUB_STATIC_FINAL_FLOAT);
public static Double PUB_STATIC_DOUBLE_OBJECT = new Double(PUB_STATIC_FINAL_DOUBLE);
public static Character PUB_STATIC_CHAR_OBJECT = new Character(PUB_STATIC_FINAL_CHAR);
public static String PUB_STATIC_STRING = PUB_STATIC_FINAL_STRING;
private static final boolean PRI_STATIC_FINAL_BOOLEAN = PUB_STATIC_FINAL_BOOLEAN;
private static final byte PRI_STATIC_FINAL_BYTE = PUB_STATIC_FINAL_BYTE;
private static final short PRI_STATIC_FINAL_SHORT = PUB_STATIC_FINAL_SHORT;
private static final int PRI_STATIC_FINAL_INT = PUB_STATIC_FINAL_INT;
private static final long PRI_STATIC_FINAL_LONG = PUB_STATIC_FINAL_LONG;
private static final float PRI_STATIC_FINAL_FLOAT = PUB_STATIC_FINAL_FLOAT;
private static final double PRI_STATIC_FINAL_DOUBLE = PUB_STATIC_FINAL_DOUBLE;
private static final char PRI_STATIC_FINAL_CHAR = PUB_STATIC_FINAL_CHAR;
private static final Object PRI_STATIC_FINAL_OBJECT = PUB_STATIC_FINAL_OBJECT;
private static final Boolean PRI_STATIC_FINAL_BOOLEAN_OBJECT = new Boolean(PUB_STATIC_FINAL_BOOLEAN);
private static final Byte PRI_STATIC_FINAL_BYTE_OBJECT = new Byte( PUB_STATIC_FINAL_BYTE );
private static final Short PRI_STATIC_FINAL_SHORT_OBJECT = new Short(PUB_STATIC_FINAL_SHORT);
private static final Integer PRI_STATIC_FINAL_INTEGER_OBJECT = new Integer(PUB_STATIC_FINAL_INT);
private static final Long PRI_STATIC_FINAL_LONG_OBJECT = new Long(PUB_STATIC_FINAL_LONG);
private static final Float PRI_STATIC_FINAL_FLOAT_OBJECT = new Float(PUB_STATIC_FINAL_FLOAT);
private static final Double PRI_STATIC_FINAL_DOUBLE_OBJECT = new Double(PUB_STATIC_FINAL_DOUBLE);
private static final Character PRI_STATIC_FINAL_CHAR_OBJECT = new Character(PUB_STATIC_FINAL_CHAR);
private static final String PRI_STATIC_FINAL_STRING = PUB_STATIC_FINAL_STRING;
private static boolean PRI_STATIC_BOOLEAN = PUB_STATIC_FINAL_BOOLEAN;
private static byte PRI_STATIC_BYTE = PUB_STATIC_FINAL_BYTE;
private static short PRI_STATIC_SHORT = PUB_STATIC_FINAL_SHORT;
private static int PRI_STATIC_INT = PUB_STATIC_FINAL_INT;
private static long PRI_STATIC_LONG = PUB_STATIC_FINAL_LONG;
private static float PRI_STATIC_FLOAT = PUB_STATIC_FINAL_FLOAT;
private static double PRI_STATIC_DOUBLE = PUB_STATIC_FINAL_DOUBLE;
private static char PRI_STATIC_CHAR = PUB_STATIC_FINAL_CHAR;
private static Object PRI_STATIC_OBJECT = PUB_STATIC_FINAL_OBJECT;
private static Boolean PRI_STATIC_BOOLEAN_OBJECT = new Boolean(PUB_STATIC_FINAL_BOOLEAN);
private static Byte PRI_STATIC_BYTE_OBJECT = new Byte( PUB_STATIC_FINAL_BYTE );
private static Short PRI_STATIC_SHORT_OBJECT = new Short(PUB_STATIC_FINAL_SHORT);
private static Integer PRI_STATIC_INTEGER_OBJECT = new Integer(PUB_STATIC_FINAL_INT);
private static Long PRI_STATIC_LONG_OBJECT = new Long(PUB_STATIC_FINAL_LONG);
private static Float PRI_STATIC_FLOAT_OBJECT = new Float(PUB_STATIC_FINAL_FLOAT);
private static Double PRI_STATIC_DOUBLE_OBJECT = new Double(PUB_STATIC_FINAL_DOUBLE);
private static Character PRI_STATIC_CHAR_OBJECT = new Character(PUB_STATIC_FINAL_CHAR);
private static String PRI_STATIC_STRING = PUB_STATIC_FINAL_STRING;
protected static final boolean PRO_STATIC_FINAL_BOOLEAN = PUB_STATIC_FINAL_BOOLEAN;
protected static final byte PRO_STATIC_FINAL_BYTE = PUB_STATIC_FINAL_BYTE;
protected static final short PRO_STATIC_FINAL_SHORT = PUB_STATIC_FINAL_SHORT;
protected static final int PRO_STATIC_FINAL_INT = PUB_STATIC_FINAL_INT;
protected static final long PRO_STATIC_FINAL_LONG = PUB_STATIC_FINAL_LONG;
protected static final float PRO_STATIC_FINAL_FLOAT = PUB_STATIC_FINAL_FLOAT;
protected static final double PRO_STATIC_FINAL_DOUBLE = PUB_STATIC_FINAL_DOUBLE;
protected static final char PRO_STATIC_FINAL_CHAR = PUB_STATIC_FINAL_CHAR;
protected static final Object PRO_STATIC_FINAL_OBJECT = PUB_STATIC_FINAL_OBJECT;
protected static final Boolean PRO_STATIC_FINAL_BOOLEAN_OBJECT = new Boolean(PUB_STATIC_FINAL_BOOLEAN);
protected static final Byte PRO_STATIC_FINAL_BYTE_OBJECT = new Byte(PUB_STATIC_FINAL_BYTE);
protected static final Short PRO_STATIC_FINAL_SHORT_OBJECT = new Short(PUB_STATIC_FINAL_SHORT);
protected static final Integer PRO_STATIC_FINAL_INTEGER_OBJECT = new Integer(PUB_STATIC_FINAL_INT);
protected static final Long PRO_STATIC_FINAL_LONG_OBJECT = new Long(PUB_STATIC_FINAL_LONG);
protected static final Float PRO_STATIC_FINAL_FLOAT_OBJECT = new Float(PUB_STATIC_FINAL_FLOAT);
protected static final Double PRO_STATIC_FINAL_DOUBLE_OBJECT = new Double(PUB_STATIC_FINAL_DOUBLE);
protected static final Character PRO_STATIC_FINAL_CHAR_OBJECT = new Character(PUB_STATIC_FINAL_CHAR);
protected static final String PRO_STATIC_FINAL_STRING = PUB_STATIC_FINAL_STRING;
protected static boolean PRO_STATIC_BOOLEAN = PUB_STATIC_FINAL_BOOLEAN;
protected static byte PRO_STATIC_BYTE = PUB_STATIC_FINAL_BYTE;
protected static short PRO_STATIC_SHORT = PUB_STATIC_FINAL_SHORT;
protected static int PRO_STATIC_INT = PUB_STATIC_FINAL_INT;
protected static long PRO_STATIC_LONG = PUB_STATIC_FINAL_LONG;
protected static float PRO_STATIC_FLOAT = PUB_STATIC_FINAL_FLOAT;
protected static double PRO_STATIC_DOUBLE = PUB_STATIC_FINAL_DOUBLE;
protected static char PRO_STATIC_CHAR = PUB_STATIC_FINAL_CHAR;
protected static Object PRO_STATIC_OBJECT;
protected static Boolean PRO_STATIC_BOOLEAN_OBJECT = new Boolean(PUB_STATIC_FINAL_BOOLEAN);
protected static Byte PRO_STATIC_BYTE_OBJECT = new Byte(PUB_STATIC_FINAL_BYTE);
protected static Short PRO_STATIC_SHORT_OBJECT = new Short(PUB_STATIC_FINAL_SHORT);
protected static Integer PRO_STATIC_INTEGER_OBJECT = new Integer(PUB_STATIC_FINAL_INT);
protected static Long PRO_STATIC_LONG_OBJECT = new Long(PUB_STATIC_FINAL_LONG);
protected static Float PRO_STATIC_FLOAT_OBJECT = new Float(PUB_STATIC_FINAL_FLOAT);
protected static Double PRO_STATIC_DOUBLE_OBJECT = new Double(PUB_STATIC_FINAL_DOUBLE);
protected static Character PRO_STATIC_CHAR_OBJECT = new Character(PUB_STATIC_FINAL_CHAR);
protected static String PRO_STATIC_STRING = PUB_STATIC_FINAL_STRING;
static final boolean STATIC_FINAL_BOOLEAN = PUB_STATIC_FINAL_BOOLEAN;
static final byte STATIC_FINAL_BYTE = PUB_STATIC_FINAL_BYTE;
static final short STATIC_FINAL_SHORT = PUB_STATIC_FINAL_SHORT;
static final int STATIC_FINAL_INT = PUB_STATIC_FINAL_INT;
static final long STATIC_FINAL_LONG = PUB_STATIC_FINAL_LONG;
static final float STATIC_FINAL_FLOAT = PUB_STATIC_FINAL_FLOAT;
static final double STATIC_FINAL_DOUBLE = PUB_STATIC_FINAL_DOUBLE;
static final char STATIC_FINAL_CHAR = PUB_STATIC_FINAL_CHAR;
static final Object STATIC_FINAL_OBJECT = PUB_STATIC_FINAL_OBJECT;
static final Boolean STATIC_FINAL_BOOLEAN_OBJECT = new Boolean(PUB_STATIC_FINAL_BOOLEAN);
static final Byte STATIC_FINAL_BYTE_OBJECT = new Byte(PUB_STATIC_FINAL_BYTE);
static final Short STATIC_FINAL_SHORT_OBJECT = new Short(PUB_STATIC_FINAL_SHORT);
static final Integer STATIC_FINAL_INTEGER_OBJECT = new Integer(PUB_STATIC_FINAL_INT);
static final Long STATIC_FINAL_LONG_OBJECT = new Long(PUB_STATIC_FINAL_LONG);
static final Float STATIC_FINAL_FLOAT_OBJECT = new Float(PUB_STATIC_FINAL_FLOAT);
static final Double STATIC_FINAL_DOUBLE_OBJECT = new Double(PUB_STATIC_FINAL_DOUBLE);
static final Character STATIC_FINAL_CHAR_OBJECT = new Character(PUB_STATIC_FINAL_CHAR);
static final String STATIC_FINAL_STRING = PUB_STATIC_FINAL_STRING;
static boolean STATIC_BOOLEAN = PUB_STATIC_FINAL_BOOLEAN;
static byte STATIC_BYTE = PUB_STATIC_FINAL_BYTE;
static short STATIC_SHORT = PUB_STATIC_FINAL_SHORT;
static int STATIC_INT = PUB_STATIC_FINAL_INT;
static long STATIC_LONG = PUB_STATIC_FINAL_LONG;
static float STATIC_FLOAT = PUB_STATIC_FINAL_FLOAT;
static double STATIC_DOUBLE = PUB_STATIC_FINAL_DOUBLE;
static char STATIC_CHAR = PUB_STATIC_FINAL_CHAR;
static Object STATIC_OBJECT = PUB_STATIC_FINAL_OBJECT;
static Boolean STATIC_BOOLEAN_OBJECT = new Boolean(PUB_STATIC_FINAL_BOOLEAN);
static Byte STATIC_BYTE_OBJECT = new Byte(PUB_STATIC_FINAL_BYTE);
static Short STATIC_SHORT_OBJECT = new Short(PUB_STATIC_FINAL_SHORT);
static Integer STATIC_INTEGER_OBJECT = new Integer(PUB_STATIC_FINAL_INT);
static Long STATIC_LONG_OBJECT = new Long(PUB_STATIC_FINAL_LONG);
static Float STATIC_FLOAT_OBJECT = new Float(PUB_STATIC_FINAL_FLOAT);
static Double STATIC_DOUBLE_OBJECT = new Double(PUB_STATIC_FINAL_DOUBLE);
static Character STATIC_CHAR_OBJECT = new Character(PUB_STATIC_FINAL_CHAR);
static String STATIC_STRING = PUB_STATIC_FINAL_STRING;
// INSTANCE FIELDS
boolean BOOLEAN = PUB_STATIC_FINAL_BOOLEAN;
byte BYTE = PUB_STATIC_FINAL_BYTE;
short SHORT = PUB_STATIC_FINAL_SHORT;
int INT = PUB_STATIC_FINAL_INT;
long LONG = PUB_STATIC_FINAL_LONG;
float FLOAT = PUB_STATIC_FINAL_FLOAT;
double DOUBLE = PUB_STATIC_FINAL_DOUBLE;
char CHAR = PUB_STATIC_FINAL_CHAR;
Boolean BOOLEAN_OBJECT = new Boolean( BOOLEAN );
Byte BYTE_OBJECT = new Byte( BYTE );
Integer INTEGER_OBJECT = new Integer( INT );
Long LONG_OBJECT = new Long( LONG );
Float FLOAT_OBJECT = new Float( FLOAT );
Double DOUBLE_OBJECT = new Double( DOUBLE );
Character CHARACTER = new Character( CHAR );
Object OBJECT = new Object();
String STRING = new String("PASSED");
Short SHORT_OBJECT = new Short( SHORT );
public boolean PUB_BOOLEAN = PUB_STATIC_FINAL_BOOLEAN;
public byte PUB_BYTE = PUB_STATIC_FINAL_BYTE;
public short PUB_SHORT = PUB_STATIC_FINAL_SHORT;
public int PUB_INT = PUB_STATIC_FINAL_INT;
public long PUB_LONG = PUB_STATIC_FINAL_LONG;
public float PUB_FLOAT = PUB_STATIC_FINAL_FLOAT;
public double PUB_DOUBLE = PUB_STATIC_FINAL_DOUBLE;
public char PUB_CHAR = PUB_STATIC_FINAL_CHAR;
public Object PUB_OBJECT = new Object();
public Boolean PUB_BOOLEAN_OBJECT = new Boolean(PUB_STATIC_FINAL_BOOLEAN);
public Byte PUB_BYTE_OBJECT = new Byte( BYTE );
public Integer PUB_INTEGER_OBJECT = new Integer(PUB_STATIC_FINAL_INT);
public Short PUB_SHORT_OBJECT = new Short( PUB_STATIC_FINAL_SHORT );
public Long PUB_LONG_OBJECT = new Long(PUB_STATIC_FINAL_LONG);
public Float PUB_FLOAT_OBJECT = new Float(PUB_STATIC_FINAL_FLOAT);
public Double PUB_DOUBLE_OBJECT = new Double(PUB_STATIC_FINAL_DOUBLE);
public Character PUB_CHAR_OBJECT = new Character(PUB_STATIC_FINAL_CHAR);
public String PUB_STRING = PUB_STATIC_FINAL_STRING;
private boolean PRI_BOOLEAN = PUB_STATIC_FINAL_BOOLEAN;
private byte PRI_BYTE = PUB_STATIC_FINAL_BYTE;
private short PRI_SHORT = PUB_STATIC_FINAL_SHORT;
private int PRI_INT = PUB_STATIC_FINAL_INT;
private long PRI_LONG = PUB_STATIC_FINAL_LONG;
private float PRI_FLOAT = PUB_STATIC_FINAL_FLOAT;
private double PRI_DOUBLE = PUB_STATIC_FINAL_DOUBLE;
private char PRI_CHAR = PUB_STATIC_FINAL_CHAR;
private Object PRI_OBJECT = PUB_STATIC_FINAL_OBJECT;
private Boolean PRI_BOOLEAN_OBJECT = new Boolean(PUB_STATIC_FINAL_BOOLEAN);
private Byte PRI_BYTE_OBJECT = new Byte(PUB_STATIC_FINAL_BYTE);
private Short PRI_SHORT_OBJECT = new Short(PUB_STATIC_FINAL_SHORT);
private Integer PRI_INTEGER_OBJECT = new Integer(PUB_STATIC_FINAL_INT);
private Long PRI_LONG_OBJECT = new Long(PUB_STATIC_FINAL_LONG);
private Float PRI_FLOAT_OBJECT = new Float(PUB_STATIC_FINAL_FLOAT);
private Double PRI_DOUBLE_OBJECT = new Double(PUB_STATIC_FINAL_DOUBLE);
private Character PRI_CHAR_OBJECT = new Character(PUB_STATIC_FINAL_CHAR);
private String PRI_STRING = PUB_STATIC_FINAL_STRING;
protected boolean PRO_BOOLEAN = PUB_STATIC_FINAL_BOOLEAN;
protected byte PRO_BYTE = PUB_STATIC_FINAL_BYTE;
protected short PRO_SHORT = PUB_STATIC_FINAL_SHORT;
protected int PRO_INT = PUB_STATIC_FINAL_INT;
protected long PRO_LONG = PUB_STATIC_FINAL_LONG;
protected float PRO_FLOAT = PUB_STATIC_FINAL_FLOAT;
protected double PRO_DOUBLE = PUB_STATIC_FINAL_DOUBLE;
protected char PRO_CHAR = PUB_STATIC_FINAL_CHAR;
protected Object PRO_OBJECT = PUB_STATIC_FINAL_OBJECT;
protected Boolean PRO_BOOLEAN_OBJECT = new Boolean(PUB_STATIC_FINAL_BOOLEAN);
protected Byte PRO_BYTE_OBJECT = new Byte(PUB_STATIC_FINAL_BYTE);
protected Short PRO_SHORT_OBJECT = new Short(PUB_STATIC_FINAL_SHORT);
protected Integer PRO_INTEGER_OBJECT = new Integer(PUB_STATIC_FINAL_INT);
protected Long PRO_LONG_OBJECT = new Long(PUB_STATIC_FINAL_LONG);
protected Float PRO_FLOAT_OBJECT = new Float(PUB_STATIC_FINAL_FLOAT);
protected Double PRO_DOUBLE_OBJECT = new Double(PUB_STATIC_FINAL_DOUBLE);
protected Character PRO_CHAR_OBJECT = new Character(PUB_STATIC_FINAL_CHAR);
protected String PRO_STRING = PUB_STATIC_FINAL_STRING;
// STATIC ARRAYS
public static byte[] staticGetByteArray() {
return PUB_STATIC_ARRAY_BYTE;
}
public static char[] staticGetCharArray() {
return PUB_STATIC_ARRAY_CHAR;
}
public static double[] staticGetDoubleArray() {
return PUB_STATIC_ARRAY_DOUBLE;
}
public static short[] staticGetShortArray() {
return PUB_STATIC_ARRAY_SHORT;
}
public static long[] staticGetLongArray() {
return PUB_STATIC_ARRAY_LONG;
}
public static int[] staticGetIntArray() {
return PUB_STATIC_ARRAY_INT;
}
public static float[] staticGetFloatArray() {
return PUB_STATIC_ARRAY_FLOAT;
}
public static Object[] staticGetObjectArray() {
return PUB_STATIC_ARRAY_OBJECT;
}
// INSTANCE ARRAYS
public byte[] getByteArray() {
return PUB_STATIC_ARRAY_BYTE;
}
public char[] getCharArray() {
return PUB_STATIC_ARRAY_CHAR;
}
public double[] getDoubleArray() {
return PUB_STATIC_ARRAY_DOUBLE;
}
public short[] getShortArray() {
return PUB_STATIC_ARRAY_SHORT;
}
public long[] getLongArray() {
return PUB_STATIC_ARRAY_LONG;
}
public int[] getIntArray() {
return PUB_STATIC_ARRAY_INT;
}
public float[] getFloatArray() {
return PUB_STATIC_ARRAY_FLOAT;
}
public Object[] getObjectArray() {
return PUB_STATIC_ARRAY_OBJECT;
}
// INSTANCE ARRAY SETTERS
public void setByteArray(byte[] b) {
PUB_STATIC_ARRAY_BYTE = b;
}
public void setCharArray(char[] c) {
PUB_STATIC_ARRAY_CHAR = c;
}
public void setDoubleArray(double[] d) {
PUB_STATIC_ARRAY_DOUBLE = d;
}
public void setShortArray(short[] s) {
PUB_STATIC_ARRAY_SHORT = s;
}
public void setLongArray(long[] l) {
PUB_STATIC_ARRAY_LONG = l;
}
public void setIntArray(int[] i) {
PUB_STATIC_ARRAY_INT= i;
}
public void setFloatArray(float[] f) {
PUB_STATIC_ARRAY_FLOAT = f;
}
public void setObjectArray(Object[] o) {
PUB_STATIC_ARRAY_OBJECT = o;
}
// STATIC ARRAY DEFINITIONS
public static byte PUB_STATIC_ARRAY_BYTE[] =
new String( PUB_STATIC_FINAL_STRING ).getBytes();
public static char PUB_STATIC_ARRAY_CHAR[] =
new String( PUB_STATIC_FINAL_STRING).toCharArray();
public static double PUB_STATIC_ARRAY_DOUBLE[] =
{ Double.MIN_VALUE, Double.MAX_VALUE, Double.NaN,
Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY };
public static short PUB_STATIC_ARRAY_SHORT[] =
{ Short.MIN_VALUE, Short.MAX_VALUE };
public static int PUB_STATIC_ARRAY_INT[] =
{ Integer.MIN_VALUE, Integer.MAX_VALUE};
public static long PUB_STATIC_ARRAY_LONG[] =
{ Long.MIN_VALUE, Long.MAX_VALUE};
public static float PUB_STATIC_ARRAY_FLOAT[] =
{ Float.MIN_VALUE, Float.MAX_VALUE, Float.NaN,
Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY };
public static Object PUB_STATIC_ARRAY_OBJECT[] =
{ PUB_STATIC_ARRAY_BYTE, PUB_STATIC_ARRAY_CHAR,
PUB_STATIC_ARRAY_DOUBLE, PUB_STATIC_ARRAY_SHORT,
PUB_STATIC_ARRAY_INT, PUB_STATIC_ARRAY_LONG,
PUB_STATIC_ARRAY_FLOAT };
public static String PUB_STATIC_ARRAY_STRING[] =
{ "JavaScript", "LiveConnect", "Java" };
// public static JSObject PUB_STATIC_ARRAY_JSOBJECT[]
// INSTANCE ARRAY DEFINITIONS
public byte PUB_ARRAY_BYTE[] =
new String( PUB_STATIC_FINAL_STRING ).getBytes();
public char PUB_ARRAY_CHAR[] =
new String( PUB_STATIC_FINAL_STRING ).toCharArray();
public double PUB_ARRAY_DOUBLE[] =
{ Double.MIN_VALUE, Double.MAX_VALUE, Double.NaN,
Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY };
public short PUB_ARRAY_SHORT[] =
{ Short.MIN_VALUE, Short.MAX_VALUE };
public int PUB_ARRAY_INT[] =
{ Integer.MIN_VALUE, Integer.MAX_VALUE};
public long PUB_ARRAY_LONG [] =
{ Long.MIN_VALUE, Long.MAX_VALUE};
public float PUB_ARRAY_FLOAT[] =
{ Float.MIN_VALUE, Float.MAX_VALUE, Float.NaN,
Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY };
public Object PUB_ARRAY_OBJECT[] =
{ PUB_ARRAY_BYTE, PUB_ARRAY_CHAR,
PUB_ARRAY_DOUBLE, PUB_ARRAY_SHORT,
PUB_ARRAY_INT, PUB_ARRAY_LONG,
PUB_ARRAY_FLOAT };
public String PUB_ARRAY_STRING[] =
{ "JavaScript", "LiveConnect", "Java" };
// public JSObject PUB_ARRAY_JSOBJECT[]
}

Просмотреть файл

@ -0,0 +1,94 @@
/* -*- Mode: java; tab-width: 8 -*-
* Copyright © 1997, 1998 Netscape Communications Corporation, All Rights Reserved.
*/
package com.netscape.javascript.qa.liveconnect;
import netscape.javascript.JSObject;
/**
*
* This is the same as DataTypeClass, but only contains conversion fields
* and methods for JSObject. JSObject is not included in DataTypeClass
* so that tests can be run on Rhino (which does not implement JSObject).
*
* Attempt to get and set the public fields.
*
* XXX need to override toString, toNumber with values in
* static fields.
*
* XXX override both instance and static versions of the method
* @author christine m begle
*/
public class JSObjectConversion {
/**
* Override toNumber
*
*/
public static double PUB_DOUBLE_REPRESENTATION = 0.2134;
public double doubleValue() {
return PUB_DOUBLE_REPRESENTATION;
}
public int toNumber() {
return PUB_NUMBER_REPRESENTATION;
}
/**
* Override booleanValue
*
*/
public boolean booleanValue() {
return PUB_BOOLEAN_REPRESENTATION;
}
public boolean PUB_BOOLEAN_REPRESENTATION = true;
public static int PUB_NUMBER_REPRESENTATION = 2134;
/**
* Override toString
*/
public String toString() {
return PUB_STRING_REPRESENTATION;
}
public static String PUB_STRING_REPRESENTATION =
"DataTypeClass Instance";
public static JSObject staticGetJSObject() {
return PUB_STATIC_JSOBJECT;
}
public JSObject getJSObject() {
return PUB_JSOBJECT;
}
public static void staticSetJSObject(JSObject jso) {
PUB_STATIC_JSOBJECT = jso;
}
public void setJSObject(JSObject jso) {
PUB_JSOBJECT = jso;
}
public JSObject[] createJSObjectArray(int length) {
PUB_JSOBJECT_ARRAY = new JSObject[length];
return PUB_JSOBJECT_ARRAY;
}
public static JSObject[] staticCreateJSObjectArray(int length) {
PUB_STATIC_JSOBJECT_ARRAY = new JSObject[length];
return PUB_STATIC_JSOBJECT_ARRAY;
}
// STATIC FIELDS
public static final JSObject PUB_STATIC_FINAL_JSOBJECT = null;
public static JSObject PUB_STATIC_JSOBJECT = PUB_STATIC_FINAL_JSOBJECT;
public JSObject PUB_JSOBJECT = PUB_STATIC_FINAL_JSOBJECT;
public JSObject[] PUB_JSOBJECT_ARRAY;
public static JSObject[] PUB_STATIC_JSOBJECT_ARRAY;
}

Просмотреть файл

@ -0,0 +1,23 @@
package com.netscape.javascript.qa.liveconnect;
import netscape.javascript.JSObject;
/**
* Class with one static method that exercises JSObject.eval with
* any JSObject and any JS code. Used by tests in
* ns/js/tests/lc3/exceptions
*
*
*/
public class JSObjectEval {
/**
* Given a JSObject and some JavaScript code, have the object
* evaluate the JavaScript code.
*
*/
public static Object eval(JSObject obj, String code) {
obj.eval(code);
return null;
}
}

Просмотреть файл

@ -0,0 +1,448 @@
/* -*- Mode: java; tab-width: 8 -*-
* Copyright © 1997, 1998 Netscape Communications Corporation, All Rights Reserved.
*/
package com.netscape.javascript.qa.liveconnect;
import java.applet.Applet;
import java.io.File;
import java.util.Vector;
import netscape.javascript.*;
//import netscape.security.*;
import com.netscape.javascript.qa.drivers.*;
/**
* LiveConnectTest is the parent class for all LiveConnect test applets.
*
* <p> Subclasses must override the executeTest() and main() methods, and
* provide a constructor. To add test cases, subclasses should use the
* addTestCaseMethod.
*
* <p> Each test class creates JavaScript TestCase objects through LiveConnect,
* and prints results to standard output, just like the JavaScript language
* tests do.
*
* <p> To run a test individually, add the test package to your classpath
* and start the LiveConnected JavaScript shell. Instantiate the test class,
* and call the test's run method. Test results will be written to standard
* out.
*
* <p> To run the test in Navigator, create an HTML page for each test applet.
* Load the page in Navigator. Test results will be written to the Java
* console.
*
* <p> To run the test in the LiveConnect test driver, use the class
* LiveConnectDrv. LiveConnectDrv starts an out of process Liveconnect
* enabled jsshell.exe, and passes the shell the arguments necessary to
* start the test application.
*
* <p> LiveConnectTests write results to the log files, using the static
* methods in com.netscape.javascript.qa.drivers.TestDriver.
*
* After each test file is completed, each applet writes test case failures
* to the test case log, and if the test fails, also writes to the file log.
*
* <p> The applet writes a summary of that file's information to a temporary
* log that is parsed by the driver. The temporary log contains name and
* value pairs of the TestFile properties, which the driver uses to generate
* suite and summary logs.
*
* <p> Running the test suite is very dependent on LiveConnect working.ft
* Not sure whether this is a good thing, or not.
*
* @see LiveConnectTest#addTestCase
* @see com.netscape.javascript.qa.drivers.LiveConnectDrv
* @see com.netscape.javascript.qa.drivers.LiveConnectEnv
* @see com.netscape.javascript.qa.drivers.TestDriver
*
* @author christine@netscape.com
*
*/
public class LiveConnectTest extends Applet implements Runnable {
/**
* Create a new LiveConnectTest.
*/
public LiveConnectTest() {
}
/**
* Main method. Used when running as an application.
*/
public static void main( String[] args ) {
LiveConnectTest test = new LiveConnectTest();
}
public void start() {
run();
}
public void stop() {
}
/**
* Main method when run as an Applet.
*
*/
public void run() {
System.out.println("Running the test." );
setupTestEnvironment();
file.startTime = TestDriver.getCurrentTime();
executeTest();
file.endTime= TestDriver.getCurrentTime();
getResults();
cleanupTestEnvironment();
stop();
}
/**
* Initialize variables, open log files.
*/
public void setupTestEnvironment() {
global = JSObject.getWindow( this );
getEnvironment();
if ( ENVIRONMENT == BROWSER ) {
// PrivilegeManager.enablePrivilege( "UniversalFileAccess" );
// PrivilegeManager.enablePrivilege( "UniversalPropertyRead" );
}
output = getOutputDirectory();
if (LOGGING) {
TestDriver.openLogFiles( output );
templog = getTempLog( output );
}
testdir = getTestDirectory();
file = new TestFile( this.getClass().getName(), testdir.toString() +
this.getClass().toString() );
file.bugnumber = this.BUGNUMBER;
file.description = ( this.getClass().toString() );
}
public void getEnvironment() {
this.ENVIRONMENT = ( global.getMember("version").equals( "undefined"))
? BROWSER
: SHELL;
return;
}
/**
* Create a TestLog object which will be used to write the testclass
* results to a temporary log file. If there is an existing log,
* delete it.
*/
public TestLog getTempLog( File output ) {
String templog = "";
try {
TEMP_LOG_NAME = ((String) global.getMember( "OUTPUT_FILE" )).equals
("undefined")
? TEMP_LOG_NAME
: (String) global.getMember("OUTPUT_FILE");
templog = output.getAbsolutePath() + TEMP_LOG_NAME;
} catch ( Exception e ) {
this.exception = e.toString();
p("Exception deleting existing templog: " + e.toString() );
}
return new TestLog( templog, "" );
}
/**
* Get the OUTPUT_FILE if defined, which is where the temp log is written.
* If the file is not defined, assume we are running in the shell, and do
* not write any output.
*
* XXX change this to match description above.
*
* @see com.netscape.javascript.drivers.LiveConnectDrv
*/
public File getOutputDirectory() {
String o = "";
if ( this.ENVIRONMENT == BROWSER ) {
String outputParam = this.getParameter( "output" );
return new File( getParameter( "output" ) );
} else {
try {
o = (String) global.getMember( "OUTPUT_DIRECTORY" );
if ( ! o.equals( "undefined") ) {
LOGGING = true;
}
} catch ( Exception e ) {
System.err.println( "OUTPUT_DIRECTORY threw: " + e );
e.printStackTrace();
System.exit(1);
}
System.out.println( "Output file is " + o.toString() );
return new File( o.toString() );
}
}
/**
* Get the TEST_DIRECTORY variable, which must be defined in the
* JavaScript helper file.
*
* @see com.netscape.javascript.drivers.LiveConnectDrv
*/
public File getTestDirectory() {
try {
String o = (String) global.getMember( "TEST_DIRECTORY" );
o = o.endsWith( File.separator ) ? o : o + File.separator;
return new File( o.toString() );
} catch ( Exception e ) {
System.err.println( "TEST_DIRECTORY is not defined: " + e );
return new File( "." );
}
}
/**
* Execute the test. Subclasses must implement this method. The
* default implemenation does nothing. This method should instantiate
* TestCases, and add them to the testcase Vector.
*
*/
public void executeTest() {
return;
}
/**
* Add a TestCase to the testcase Vector.
*
* @param description a description of the test case
* @param expect a string representation of the expected result
* @param actual a string representation of the actual result
* @param exception the message in any JavaScript runtime error
* or Java exeption that was thrown.
*
*/
public void addTestCase( String description, String expect, String actual,
String exception )
{
String result = ( expect == actual ) ? "true" : "false";
TestCase tc = new TestCase( result, this.getClass().getName().toString(),
description, expect, actual, exception );
file.caseVector.addElement( tc );
file.totalCases++;
if ( result == "false" ) {
file.passed = false;
file.casesFailed++;
} else {
file.casesPassed++;
}
return;
}
/**
* Close all logs.
*
*/
public void closeLogs() {
TestDriver.getLog( output, TestDriver.SUMMARY_LOG_NAME ).closeLog();
TestDriver.getLog( output, TestDriver.SUITE_LOG_NAME ).closeLog();
TestDriver.getLog( output, TestDriver.FILE_LOG_NAME ).closeLog();
TestDriver.getLog( output, TestDriver.CASE_LOG_NAME ).closeLog();
templog.closeLog();
templog = null;
}
/**
* Iterate through the testcase Vector. Populate the properties of the
* TestFile object.
*/
public void getResults() {
displayResults();
if (LOGGING) {
writeResultsToCaseLog();
writeResultsToFileLog();
writeResultsToTempLog();
}
}
/**
* Write a summary of the TestCase to standard out.
*
*/
public void displayResults() {
for ( int i = 0; i < file.caseVector.size(); i++ ) {
TestCase tc = (TestCase) file.caseVector.elementAt(i);
p( tc.description +" = "+ tc.actual+
( tc.expect != tc.actual
? " FAILED! expected: " + tc.expect
: " PASSED!" ) );
}
getFailedCases();
}
/**
* If any test cases did not pass, write a summary of the failed cases
* to the CASE_LOG using static TestDriver methods.
*
* @see com.netscape.javascript.qa.drivers.TestDriver#writeCaseResults
*/
public void writeResultsToCaseLog() {
if ( !file.passed ) {
TestDriver.writeCaseResults( file, file.description, output );
}
}
/**
* If the test failed, write a summary of this test to the FILE_LOG. Use
* static TestDriver methods to write to the FILE_LOG.
*
* @see com.netscape.javascript.qa.drivers.TestDriver#writeFileResult
*/
public void writeResultsToFileLog() {
if ( !file.passed ) {
TestDriver.writeFileResult(file, null, output);
}
}
/**
* Write to a file containing the results of this TestFile. The content
* of this file is parsed by the parseResult() method of LiveConnectEnv,
* which maintains information about all files and suites executed. The
* format of the temp log is a list of name value pairs, one per line.
* The temp log is overwritten each time the LiveConnectDrv executes a
* test.
*
* Changes to the format of the templog file will require changes to
* LiveConnectDrv.parseResult.
*
* <pre>
* CLASSNAME LiveConnectTest
* PASSED [true, false]
* LENGTH [number of testcases in this test]
* NO_PASSED [number of testcases that passed]
* NO_FAILED [number of testcases that failed]
* </pre>
*
* XXX may also want to write bugnumber, time completed, etc?. probably
* what this should do is enumerate all the properties of a TestFile object,
* that the driver can parse and treat as though it had a normal TestFile
* object.
*
* @see com.netscape.javascript.qa.drivers.LiveConnectDrv#parseResult
*/
public void writeResultsToTempLog(){
System.out.println( "Writing results to " + templog.toString() );
templog.writeLine( file.description );
templog.writeLine( file.passed + "" );
templog.writeLine( file.caseVector.size() +"" );
templog.writeLine( file.casesPassed + "");
templog.writeLine( file.casesFailed + "");
templog.writeLine( file.bugnumber );
p( file.name );
p( "passed: " + passed );
p( "total cases: " + file.caseVector.size() );
p( "cases passed: " + file.casesPassed );
p( "cases failed: " + file.casesFailed );
p( "bugnumber: " + file.bugnumber );
return;
}
/**
* Close logs, and set the value of the "completed" variable in the
* JavaScript environment so that the driver knows the test has
* finished.
*/
public void cleanupTestEnvironment() {
try {
if ( LOGGING ) {
// templog.closeLog();
}
// global.eval("var completed = true;");
} catch ( Exception e ) {
p( "exception in cleanupTestEnvironment: " + e.toString() );
e.printStackTrace();
}
}
public void p (String s ) {
System.out.println( s );
}
/**
* This dandy little hack from Nix that is used to test things that
* should fail. It runs a method on a JavaScript object, catching any
* exceptions. It returns the detail message from the exception, or
* NO_EXCEPTION if it succeeds. This is from nix.
*
*/
public static String catchException(JSObject self, String method,
Object args[]) {
Object rval;
String msg;
try {
rval = self.call(method, args);
msg = NO_EXCEPTION;
} catch (Throwable e) {
msg = e.getMessage();
}
return msg;
}
public void getFailedCases() {
if ( file.passed ) {
return;
}
p( "********** Failed Test Cases **********" );
for ( int i = 0; i < file.caseVector.size(); i++ ) {
TestCase tc = (TestCase) file.caseVector.elementAt(i);
if ( tc.passed != "true" ) {
p( tc.description +" = "+ tc.actual+
( tc.expect != tc.actual
? " FAILED! expected: " + tc.expect
: " PASSED!"
) +
( tc.reason.length() > 0
? ": " + tc.reason
: ""
)
);
}
}
}
public File output;
public File testdir;
public TestFile file;
public Vector testcase;
public JSObject global;
public boolean passed = true;
public Vector failedVector = new Vector();
public TestLog templog;
public String exception = "";
public String BUGNUMBER = "";
boolean LOGGING = false;
public static String TEMP_LOG_NAME = "result.tmp";
public static final int BROWSER = 1;
public static final int SHELL = 0;
public int ENVIRONMENT;
public static final String NO_EXCEPTION = "Expected exception not thrown.";
public static final String DATA_CLASS = "com.netscape.javascript.qa.liveconnect.DataTypeClass";
}

Просмотреть файл

@ -0,0 +1,140 @@
package com.netscape.javascript.qa.liveconnect.call;
import com.netscape.javascript.qa.liveconnect.*;
import netscape.javascript.*;
/**
* Instantiate a JavaScript object. From java, use JSObject.call to invoke a
* method of that object. Verify the return value.
*
* call global method. call built in method. cal user defined method. call
* method that takes no arguments.
*
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class Call_001 extends LiveConnectTest {
public Call_001() {
super();
}
public static void main( String[] args ) {
Call_001 test = new Call_001();
test.start();
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
}
public void executeTest() {
Object data[] = getDataArray();
for ( int i = 0; i < data.length; i++ ) {
JSObject jsObject = getJSObject( (Object[]) data[i] );
call( jsObject, (Object[]) data[i] );
}
}
/**
* Create and return a JSObject using data in the data array.
*
* @param data Object array containing name of JSObject, and assignment
* expression
* @return the JSObject
*/
public JSObject getJSObject( Object[] data ) {
String constructor = data[0] +" = " + data[1];
JSObject theThis = (JSObject) global.eval( constructor );
return theThis;
}
/**
* Use JSObject call to invoke a JavaScript method. Verify the value and
* class of the object returned.
*
* @param theThis JSObject whose method will be called will be checked
* @param data Object array containing the name of the method, arguments
* to be passed to that method, and the expected return value of the
* method.
*/
public void call( JSObject theThis, Object[] data ) {
String exception = null;
String method = (String) data[2];
Object args[] = (Object[]) data[3];
Object eValue = data[4];
Object aValue = null;
Class eClass = null;
Class aClass = null;
try {
aValue = theThis.call( method, (Object[]) args );
if ( aValue != null ) {
eClass = eValue.getClass();
aClass = aValue.getClass();
}
} catch ( Exception e ) {
exception = theThis +".call( " + method + ", " + args+" ) threw "+
e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
if ( aValue == null ) {
} else {
// check the value of the property
addTestCase(
"[ getMember returned " + aValue +" ] "+
theThis+".call( "+method+", "+args+" ).equals( "+eValue+" )",
"true",
aValue.equals(eValue) +"",
exception );
// check the class of the property
addTestCase (
"[ "+ aValue+".getClass() returned "+aClass.getName()+"] "+
aClass.getName() +".equals( " +eClass.getName() +" )",
"true",
aClass.getName().equals(eClass.getName()) +"",
exception );
}
}
}
/**
* Get the data array, which is an object array data arrays, which are
* also object arrays.
*
* <ul>
* <li> Identifier for JavaScript object
* <li> Assignment expression to initialize JavaScript object
* <li> Method of the JavaScript object
* <li> Arguments to pass to the method
* <li> Value returned by the method
* </ul>
*
* To add test cases to this test, modify this method.
*
* @return the data array.
*/
public Object[] getDataArray() {
Object d0[] = {
new String( "boo" ), // 0 identifier
new String( "new Boolean()"), // 1 assignment expression
new String( "valueOf" ), // 2 method
null, // 3 argument array
new Boolean( "false" ), // 4 return value
};
Object d1[] = {
new String( "date" ),
new String( "new Date(0)"),
new String( "getUTCFullYear" ),
null,
new Double( "1970" ),
};
Object dataArray[] = { d0, d1 };
return dataArray;
}
}

Просмотреть файл

@ -0,0 +1,355 @@
/* -*- Mode: java; tab-width: 8 -*-
* Copyright © 1997, 1998 Netscape Communications Corporation, All Rights Reserved.
*/
package com.netscape.javascript.qa.liveconnect.datatypes;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Attempt to get public static and public static final fields using
* JSObject.eval.
* <p>
* Assign a Java value to a JavaScript variable. Set the value of that
* variable with JSObject.setMember, and get the new value with
* JSObject.getMember.
*
* @see com.netscape.javascript.qa.liveconnect.DataTypesClass
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class DataTypes_001 extends LiveConnectTest {
public DataTypes_001() {
super();
}
public static void main( String[] args ) {
DataTypes_001 test = new DataTypes_001();
test.start();
}
public void executeTest() {
doStaticFieldTests(
"DT.PUB_STATIC_BOOLEAN",
"java.lang.Boolean",
(Object) new Boolean(DataTypeClass.PUB_STATIC_FINAL_BOOLEAN) );
doStaticFieldTests(
"DT.PUB_STATIC_FINAL_BOOLEAN",
"java.lang.Boolean",
(Object) new Boolean(DataTypeClass.PUB_STATIC_FINAL_BOOLEAN) );
doStaticFieldTests(
"DT.PUB_STATIC_BYTE",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_BYTE) );
doStaticFieldTests(
"DT.PUB_STATIC_FINAL_BYTE",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_BYTE) );
doStaticFieldTests(
"DT.PUB_STATIC_SHORT",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_SHORT) );
doStaticFieldTests(
"DT.PUB_STATIC_FINAL_SHORT",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_SHORT) );
doStaticFieldTests(
"DT.PUB_STATIC_INT",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_INT) );
doStaticFieldTests(
"DT.PUB_STATIC_FINAL_INT",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_INT) );
doStaticFieldTests(
"DT.PUB_STATIC_LONG",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_LONG) );
doStaticFieldTests(
"DT.PUB_STATIC_FINAL_LONG",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_LONG) );
doStaticFieldTests(
"DT.PUB_STATIC_FLOAT",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_FLOAT) );
doStaticFieldTests(
"DT.PUB_STATIC_FINAL_FLOAT",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_FLOAT) );
doStaticFieldTests(
"DT.PUB_STATIC_DOUBLE",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_DOUBLE) );
doStaticFieldTests(
"DT.PUB_STATIC_FINAL_DOUBLE",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_DOUBLE) );
doStaticFieldTests(
"DT.PUB_STATIC_FINAL_CHAR",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_CHAR) );
doStaticFieldTests(
"DT.PUB_STATIC_CHAR",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_CHAR) );
doStaticFieldTests(
"DT.PUB_STATIC_STRING",
"java.lang.String",
(Object) new String(DataTypeClass.PUB_STATIC_FINAL_STRING) );
doStaticFieldTests(
"DT.PUB_STATIC_FINAL_STRING",
"java.lang.String",
(Object) new String(DataTypeClass.PUB_STATIC_FINAL_STRING) );
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
global.eval( "var DT = Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass" );
file.bugnumber= "301113";
}
public void doStaticFieldTests( String field, String className, Object value ) {
getPublicStaticField( field, className, value );
if ( field.startsWith( "DT.PUB_STATIC_FINAL" )) {
setPublicStaticFinalField( field, className, value );
} else {
setPublicStaticField( field, className, value );
}
setJavaScriptVariable( field, className, value );
}
/**
* Set the value of a JavaScript variable to a Java value.
* Get the value of that variable.
*/
public void getPublicStaticField( String field, String className, Object value ) {
String description = field;
String exception = null;
Object actual = null;
String expect = null;
String typeof = null;
String expectedType = null;
// check the class
try {
global.eval( "var myobject = " +description );
actual = global.getMember( "myobject" );
typeof = (String) global.eval( "typeof myobject" );
expect = Class.forName(className).getName();
if ( value instanceof Number ) {
expectedType = "number";
} else if ( value instanceof Boolean ) {
expectedType = "boolean";
} else {
expectedType = "object";
}
} catch ( ClassNotFoundException e ) {
} catch ( Exception e ) {
exception = e.toString();
}
// might want to do all the interesting stuff here in a try/catch block.
addTestCase(
"global.eval( \"var myobject = \" + " + description +");"+
"global.eval( \"typeof myobject\" ).equals(\""+expectedType+"\");",
"true",
typeof.equals(expectedType) +"",
exception );
addTestCase( "( " + description +" ).getClass()",
expect,
actual.getClass().getName(),
exception );
addTestCase( "( " +description + " == " + value.toString() +" )",
"true",
actual.equals( value ) + "",
exception );
addTestCase( "\"" +actual.toString() + "\".equals(\"" + value.toString() +"\")",
"true",
actual.toString().equals(value.toString()) +"",
exception );
}
/**
* Try to set the value of a public static field using
* JSObject.setMember which should succeed.
*/
public void setPublicStaticField( String field, String className, Object value ) {
String description = field;
String exception = null;
Object before = null;
Object after = null;
String expect = null;
Object newValue = className.equals("java.lang.Double")
? new Double(0)
: className.equals("java.lang.Boolean")
? new Boolean(false)
: (Object) new String("New Value!")
;
try {
before = global.eval( description );
// need to quote strings
if ( className.equals("java.lang.String") ){
global.eval( description +" = \"" + newValue.toString() +"\"" );
} else {
global.eval( description +" = " + newValue );
}
after = global.eval( description );
expect = Class.forName( className ).getName();
} catch ( Exception e ) {
exception = e.toString();
}
addTestCase( "global.eval(\""+description+" = "+newValue.toString()+
"\"); after = global.eval( \"" + description +"\" );" +
"after.getClass().getName()",
expect,
after.getClass().getName(),
exception );
addTestCase( "( "+after.toString() +" ).equals(" + newValue.toString() +")",
"true",
after.equals( newValue ) + "",
exception );
addTestCase( "\"" +after.toString() + "\".equals(\"" + newValue.toString() +"\")",
"true",
after.toString().equals(newValue.toString()) +"",
exception );
}
/**
* Assign a value to a public static final java field. The assignment
* should fail (the value should not change), but there should be no error
* message.
*/
public void setPublicStaticFinalField ( String field, String className, Object value ) {
String description = field;
String exception = null;
Object before = null;
Object after = null;
String expect = null;
Object newValue = className.equals("java.lang.Double")
? new Double(0)
: className.equals("java.lang.Boolean")
? new Boolean(false)
: (Object) new String("\"New Value!\"")
;
try {
expect = Class.forName( className ).getName();
} catch ( Exception e ) {
exception = e.toString();
}
before = global.eval( description );
global.eval( description +" = " + newValue.toString() );
after = global.eval( description );
// check the class of the result, which should be the same as expect
addTestCase( "( " + description +" ).getClass()",
expect,
after.getClass().getName(),
exception );
// the value of the actual result should be the original value
addTestCase( "( " +description + " == " + value.toString() +" )",
"true",
after.equals( value ) + "",
exception );
// the string representation of the actual result should be the same
// as the string representation of the expected value
addTestCase( "\"" +after.toString() + "\".equals(\"" + value.toString() +"\")",
"true",
after.toString().equals(value.toString()) +"",
exception );
// getMember( field ) should return the same value before and after the
// assignment
addTestCase( "( " + before +".equals(" + after +") ) ",
"true",
( before.equals(after) ) +"",
exception );
}
public void setJavaScriptVariable( String field, String className, Object value ) {
String description = field;
String exception = null;
Object actual = null;
String expect = null;
Object newValue = className.equals("java.lang.Double")
? new Double(0)
: className.equals("java.lang.Boolean")
? new Boolean(false)
: (Object) new String("New Value!")
;
try {
global.eval( "var myobject = " + description );
global.setMember( "myobject", newValue );
actual = global.getMember( "myobject" );
expect = Class.forName( className ).getName();
} catch ( Exception e ) {
exception = e.toString();
}
addTestCase( "global.eval(\"var myobject = " + description +"\" ); " +
"global.setMember( \"myobject\", " + newValue.toString() +");" +
"actual = global.getMember( \"myobject\" ); "+
"actual.getClass().getName()",
expect,
actual.getClass().getName(),
exception );
addTestCase( "( " + description + " == " + newValue.toString() +" )",
"true",
actual.equals( newValue ) + "",
exception );
addTestCase( "\"" +actual.toString() + "\".equals(\"" + newValue.toString() +"\")",
"true",
actual.toString().equals(newValue.toString()) +"",
exception );
}
}

Просмотреть файл

@ -0,0 +1,142 @@
package com.netscape.javascript.qa.liveconnect.datatypes;
import com.netscape.javascript.qa.liveconnect.*;
import netscape.javascript.*;
/**
* Get and set a public static string. Same as cases in DataTypes_001, but
* pulling out string cases separately, since they need to be quoted right.
*
* @see com.netscape.javascript.qa.liveconnect.DataTypesClass
* @see com.netscape.javascript.qa.datatypes.DataTypes_001
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class DataTypes_002 extends LiveConnectTest {
public DataTypes_002() {
super();
}
public static void main( String[] args ) {
DataTypes_002 test = new DataTypes_002();
test.start();
}
public void executeTest() {
doTestOne();
doTestTwo();
doTestThree();
doTestFour();
}
/**
* String literal gets passed JSObject.eval, and this test succeeds.
*/
public void doTestOne() {
Object before;
Object newValue = (Object) (new String("Test One New Value!"));
Object after;
before = global.eval( "DT.PUB_STATIC_STRING" );
global.eval( "DT.PUB_STATIC_STRING = \"Test One New Value!\"" );
after = global.eval( "DT.PUB_STATIC_STRING" );
addTestCase( "global.eval(\"DT_PUBLIC_STRING = \"Test One New Value!\"); "+
"after = global.eval( \"DT.PUB_STATIC_STRING\" );" +
"(\""+after +"\").toString().equals(\""+newValue.toString()+"\")",
"true",
after.toString().equals(newValue.toString()) + "",
null);
}
/**
* New string value is Object.toString(). This succeeds with the extra quoting.
*
*/
public void doTestTwo() {
Object before;
Object newValue = (Object) (new String("Test Two New Value!"));
Object after;
before = global.eval( "DT.PUB_STATIC_STRING" );
global.eval( "DT.PUB_STATIC_STRING = \"" + newValue.toString()+"\"" );
after = global.eval( "DT.PUB_STATIC_STRING" );
addTestCase( "Object newValue = (Object) new String(\"Test Two New Value!\"); " +
"global.eval(\"DT_PUBLIC_STRING = newValue.toString()); "+
"after = global.eval( \"DT.PUB_STATIC_STRING\" );" +
"(\""+after +"\").toString().equals(\""+newValue.toString()+"\")",
"true",
after.toString().equals(newValue.toString()) + "",
null);
}
/**
* More extra quoting stuff. This succeeds.
*/
public void doTestThree() {
Object before;
Object newValue = (Object) (new String("Test Three New Value!"));
Object after;
String evalArgs = "DT.PUB_STATIC_STRING = \'" + newValue.toString() +"\'";
before = global.eval( "DT.PUB_STATIC_STRING" );
global.eval( evalArgs.toString() );
after = global.eval( "DT.PUB_STATIC_STRING" );
addTestCase( "String evalArgs = "+ evalArgs.toString() +"; " +
"global.eval( evalArgs.toString() )"+
"after = global.eval( \"DT.PUB_STATIC_STRING\" );" +
"(\""+after +"\").toString().equals(\""+newValue.toString()+"\")",
"true",
after.toString().equals(newValue.toString()) + "",
null);
}
/**
* This throws an exception. This does not use the extra quoting.
*/
public void doTestFour() {
Object before;
Object newValue = (Object) (new String("Test Four New Value!"));
Object after;
String exception;
String evalArgs = "DT.PUB_STATIC_STRING = " + newValue.toString() +";";
String EXCEPTION = "JSException thrown!";
try {
before = global.eval( "DT.PUB_STATIC_STRING" );
global.eval( evalArgs.toString() );
after = global.eval( "DT.PUB_STATIC_STRING" );
exception = "";
} catch ( Exception e ) {
if ( e instanceof JSException ) {
after = EXCEPTION;
} else {
after = "Some random exception thrown!";
}
file.exception = e.toString();
}
addTestCase( "String evalArgs = "+ evalArgs.toString() +"; " +
"global.eval( evalArgs.toString() )"+
"after = global.eval( \"DT.PUB_STATIC_STRING\" );" +
"(\""+after +"\").toString().equals(\""+newValue.toString()+"\")",
EXCEPTION,
after.toString(),
file.exception );
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
global.eval( "var DT = Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass");
}
}

Просмотреть файл

@ -0,0 +1,233 @@
package com.netscape.javascript.qa.liveconnect.datatypes;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Tests JavaScript -> Java data type conversion. This test creates a
* JavaScript and sets the value of a variable in the JavaScript context,
* using JSObject.eval. The test gets the value of the JavaScript variable
* in two ways: using JSObject.eval( varname ) and
* JSObject.getMember( varname).
*
* <p>
*
* The test then verifies that the result object is of the correct type, and
* also verifies the value of the object, using the rules defined by JSObject.
*
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class DataTypes_003 extends LiveConnectTest {
public DataTypes_003() {
super();
}
public static void main( String[] args ) {
DataTypes_003 test = new DataTypes_003();
test.start();
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
global.eval( "var DT = Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass" );
}
/**
*
* Values passed from JavaScript to Java are converted as follows:
* <ul>
* <li >
* <li > objects that are wrappers around java objects are unwrapped
* <li > other objects are wrapped with a JSObject
* <li> strings, numbers and booleans are converted to String, Float, and
* Boolean objects, respectively
*
* @see netscape.javascript.JSObject
*/
public void executeTest() {
// java objects are unwrapped
doGetJSVarTests(
"Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass",
"java.lang.Class",
"class com.netscape.javascript.qa.liveconnect.DataTypeClass" );
doGetJSVarTests( "new java.lang.String(\"java string\")",
"java.lang.String",
"java string" );
// strings numbers and booleans are converted to String, Double and
// Boolean objects
doGetJSVarTests( "Boolean(true)", "java.lang.Boolean", "true" );
doGetJSVarTests( "Boolean()", "java.lang.Boolean", "false" );
doGetJSVarTests( "Boolean(false)", "java.lang.Boolean", "false" );
doGetJSVarTests( "Number(12345)", "java.lang.Double", new Double("12345").toString() );
doGetJSVarTests( "12345", "java.lang.Double", new Double("12345").toString() );
doGetJSVarTests( "String(\"hello\")", "java.lang.String", "hello" );
doGetJSVarTests( "\"hello\"", "java.lang.String", "hello" );
doGetJSVarTests( "true", "java.lang.Boolean", "true" );
doGetJSVarTests( "false", "java.lang.Boolean", "false" );
// other objects are wrapped with a JSObject
doGetJSVarTests( "new Number(0)", "netscape.javascript.JSObject", "0" );
// Throws nullPointerException -- put in its own test
// doGetJSVarTests( "null", "netscape.javascript.JSObject", "null" );
// 4.05 returns a java.lang.String which i guess we need to maintain for
// backward compatilibilty
doGetJSVarTests( "void 0", "java.lang.String", "undefined" );
doGetJSVarTests( "new Number(999)", "netscape.javascript.JSObject", "999" );
doGetJSVarTests( "Math", "netscape.javascript.JSObject", "[object Math]" );
doGetJSVarTests( "new Boolean(true)", "netscape.javascript.JSObject", "true" );
doGetJSVarTests( "new Boolean(false)", "netscape.javascript.JSObject", "false" );
doGetJSVarTests( "new String()", "netscape.javascript.JSObject", "" );
doGetJSVarTests( "new String(\"hi\")", "netscape.javascript.JSObject", "hi" );
doGetJSVarTests( "new Array(1,2,3,4,5)", "netscape.javascript.JSObject", "1,2,3,4,5" );
doGetJSVarTests( "[5,4,3,2,1]", "netscape.javascript.JSObject", "5,4,3,2,1" );
}
/**
* Pass the same arguments to two different tests.
*
* @param rightExpr right-hand side to a JavaScript assignment expression
* @param className expected name of the class of the JavaScript object,
* when its value is retrieved from the JavaScript context using
* JSObject.eval or JSObject.getMember
* @param value string representation of the value of the JavaScript
* object.
*
* @see #getJSVarWithEval
* @see #getJSVarWithGetMember
*/
public void doGetJSVarTests( String rightExpr, String className,
String value ) {
getJSVarWithEval( rightExpr, className, value );
getJSVarWithGetMember( rightExpr, className, value );
}
/**
* Use JSObject.eval to create a JavaScript variable of a JavaScript type.
* Get the value of the variable using JSObject.getMember and
* JSObject.eval. The type and value of the object returned by getMember
* and eval should be the same. Add the testcase.
*
* @param rightExpr right-hand side to a JavaScript assignment expression
* @param className string representation of expected type of the result
* @param eValue expected value of the result
*/
public void getJSVarWithEval( String rightExpr, String className,
String value ) {
String varName = "jsVar";
Object jsObject;
Object result;
Class expectedClass = null;
try {
expectedClass = Class.forName( className );
// Create the variable in the JavaScript context.
global.eval( "var " + varName +" = " + rightExpr +";" );
// get the value of varName from the JavaScript context.
jsObject = global.eval( varName );
} catch ( Exception e ) {
System.err.println( "setJSVarWithEval threw " + e.toString() +
" with arguments ( " + rightExpr +", "+
expectedClass.getName() +", "+ value.toString() );
e.printStackTrace();
exception = e.toString();
jsObject = new Object();
}
// compare the class of the jsObject to the expected class
addTestCase(
"global.eval( \"var "+ varName +" = " + rightExpr +"); "+
"jsObject = global.eval( "+ varName +"); " +
"jsObject.getClass.getName().equals("+expectedClass.getName()+")"+
"[ jsObject class is " + jsObject.getClass().getName() +"]",
"true",
jsObject.getClass().getName().equals(expectedClass.getName())+ "",
exception );
// compare the value of the string value of the jsObject to the
// expected string value
addTestCase(
"("+jsObject.toString() +".equals(" + value.toString() +"))",
"true",
jsObject.toString().equals( value ) +"",
exception );
}
/**
* Use JSObject.eval to create a JavaScript variable of a JavaScript type.
* Get the value of the variable using JSObject.getMember. Add the test
* cases.
*
* @param rightExpr right-hand side to a JavaScript assignment expression
* @param className string representation of expected type of the result
* @param eValue expected value of the result
*/
public void getJSVarWithGetMember( String rightExpr, String className,
String value ) {
String varName = "jsVar";
Object jsObject;
Class expectedClass = null;
try {
expectedClass = Class.forName( className );
// Create the variable in the JavaScript context.
global.eval( "var " + varName +" = " + rightExpr +";" );
// get the value of varName from the JavaScript context.
jsObject = global.getMember( varName );
} catch ( Exception e ) {
System.err.println( "getJSVarWithGetMember threw " + e.toString() +
" with arguments ( " + rightExpr +", "+
expectedClass.getName() +", "+ value.toString() );
e.printStackTrace();
exception = e.toString();
jsObject = new Object();
}
// check the class of the jsObject object
addTestCase(
"global.eval( \"var "+ varName +" = " + rightExpr +"); "+
"jsObject = global.getMember( "+ varName +"); " +
"jsObject.getClass.getName().equals(" +
expectedClass.getName() +")"+
"[ jsObject class is "+jsObject.getClass().getName()+"]",
"true",
jsObject.getClass().getName().equals(expectedClass.getName()) +"",
exception );
// check the string representation of the jsObject
addTestCase(
"("+jsObject.toString() +".equals(" + value.toString() +"))",
"true",
jsObject.toString().equals( value ) +"",
exception );
}
}

Просмотреть файл

@ -0,0 +1,140 @@
package com.netscape.javascript.qa.liveconnect.datatypes;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Get the value of JavaScript variable that is set to null.
* It would be nice if nulls were wrapped by JSObjects, but instead they
* are Java nulls.
*
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class DataTypes_004 extends LiveConnectTest {
public DataTypes_004() {
super();
}
public static void main( String[] args ) {
DataTypes_004 test = new DataTypes_004();
test.start();
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
global.eval( "var DT = "+
"Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass"
);
}
/**
*
* Values passed from JavaScript to Java are converted as follows:
* <ul>
* <li >
* <li > objects that are wrappers around java objects are unwrapped
* <li > other objects are wrapped with a JSObject
* <li> strings, numbers and booleans are converted to String, Float, and
* Boolean objects, respectively
*
* @see netscape.javascript.JSObject
*/
public void executeTest() {
getJSVarWithEval( "null", "netscape.javascript.JSObject", "null" );
getJSVarWithGetMember( "null", "netscape.javascript.JSObject", "null" );
}
/**
* Use JSObject.eval to create a JavaScript variable of a JavaScript type.
* Get the value of the variable using JSObject.getMember and
* JSObject.eval. The type and value of the object returned by getMember and
* eval should be the same. Add the testcase.
*
* @param rightExpr right-hand side to the JavaScript assignment
* expression
* @param className string representation of expected type of the result
* @param eValue expected value of the result
*/
public void getJSVarWithEval( String rightExpr, String className,
String value ) {
String varName = "jsVar";
Object result;
Class expectedClass = null;
try {
expectedClass = Class.forName( className );
// Create the variable in the JavaScript context.
global.eval( "var " + varName +" = " + rightExpr +";" );
// get the value of varName from the JavaScript context.
result = global.eval( varName );
System.out.println( "result is " + result );
} catch ( Exception e ) {
System.err.println( "setJSVarWithEval threw " + e.toString() +
" with arguments ( " + rightExpr +", "+
expectedClass.getName() +", "+ value.toString() );
e.printStackTrace();
exception = e.toString();
result = new Object();
}
try {
addTestCase(
"global.eval( \"var "+ varName +" = " + rightExpr +"); "+
"result = global.eval( "+ varName +"); " +
"(result == null)",
"true",
(result == null) + "",
exception );
} catch ( Exception e ) {
file.exception = e.toString();
}
}
public void getJSVarWithGetMember( String rightExpr, String className,
String value ) {
String varName = "jsVar";
Object result;
Class expectedClass = null;
try {
expectedClass = Class.forName( className );
// Create the variable in the JavaScript context.
global.eval( "var " + varName +" = " + rightExpr +";" );
// get the value of varName from the JavaScript context.
result = global.getMember( varName );
} catch ( Exception e ) {
System.err.println( "setJSVarWithGetMember threw " + e.toString() +
" with arguments ( " + rightExpr +", "+
expectedClass.getName() +", "+ value.toString() );
e.printStackTrace();
exception = e.toString();
result = new Object();
}
try {
addTestCase(
"global.eval( \"var "+ varName +" = " + rightExpr +"); "+
"result = global.getMember( "+ varName +"); " +
"(result == null)",
"true",
(result == null) + "",
exception );
} catch ( Exception e ) {
file.exception = e.toString();
}
}
}

Просмотреть файл

@ -0,0 +1,345 @@
package com.netscape.javascript.qa.liveconnect.datatypes;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Attempt to get public instance fields using JSObject.eval.
* <p>
* Assign a Java value to a JavaScript variable. Set the value of that
* variable with JSObject.setMember, and get the new value with
* JSObject.getMember.
*
* @see com.netscape.javascript.qa.liveconnect.DataTypesClass
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class DataTypes_005 extends LiveConnectTest {
public DataTypes_005() {
super();
}
public static void main( String[] args ) {
DataTypes_005 test = new DataTypes_005();
test.start();
}
public void executeTest() {
doFieldTests(
"dt.PUB_BOOLEAN",
"java.lang.Boolean",
(Object) new Boolean(DataTypeClass.PUB_STATIC_FINAL_BOOLEAN) );
doFieldTests(
"dt.PUB_BYTE",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_BYTE) );
doFieldTests(
"dt.PUB_SHORT",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_SHORT) );
doFieldTests(
"dt.PUB_INT",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_INT) );
doFieldTests(
"dt.PUB_LONG",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_LONG) );
doFieldTests(
"dt.PUB_FLOAT",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_FLOAT) );
doFieldTests(
"dt.PUB_DOUBLE",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_DOUBLE) );
doFieldTests(
"dt.PUB_CHAR",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_CHAR) );
doFieldTests(
"dt.PUB_STRING",
"java.lang.String",
(Object) new String(DataTypeClass.PUB_STATIC_FINAL_STRING) );
}
/**
* Call the parent class's setupTestEnvironment method. Use JSObject.eval
* to define the com.netscape.javascript.qa.liveconnect.DataTypeClass. Use
* JSObject.eval to define an instance of the DataTypeClass.
*
* @see com.netscape.javascript.qa.liveconnect.DataTypeClass
*/
public void setupTestEnvironment() {
super.setupTestEnvironment();
global.eval( "var DT = "+
"Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass");
global.eval( "var dt = new DT();" );
}
/**
* Pass the arguments to the different tests, all of which take the same
* arguments.
*
* @param field name of the DataTypeClass field
* @param className name of the class of the DataTypeClass field
* @param value value of the DataTypeClass field
*
* @see com.netscape.javascript.qa.liveconnect.DataTypeClass
*/
public void doFieldTests( String field, String className, Object value ) {
getPublicField( field, className, value );
if ( field.startsWith( "dt.PUB_FINAL" )) {
setPublicFinalField( field, className, value );
} else {
setPublicField( field, className, value );
}
setJavaScriptVariable( field, className, value );
}
/**
* Use JSObject.eval to create a JavaScript variable whose value is the
* value of a Java object instance. Use JSObject.getMember to get the
* value of the JavaScript object, and verify that the value of the
* result object is of the expected class and value.
*
* @param field name of the DataTypeClass field
* @param className name of the class of the DataTypeClass field
* @param value value of the DataTypeClass field
*
* @see com.netscape.javascript.qa.liveconnect.DataTypeClass
*/
public void getPublicField( String field, String className,
Object value )
{
String description = field;
String exception = null;
Object actual = null;
String expect = null;
// check the class
try {
global.eval( "var myobject = " +description );
actual = global.getMember( "myobject" );
expect = Class.forName(className).getName();
} catch ( ClassNotFoundException e ) {
} catch ( Exception e ) {
exception = e.toString();
}
// might want to do all the interesting stuff here in a try/catch block
addTestCase( "( " + description +" ).getClass()",
expect,
actual.getClass().getName(),
exception );
addTestCase( "( " +description + " == " + value.toString() +" )",
"true",
actual.equals( value ) + "",
exception );
addTestCase(
"\"" +actual.toString() + "\".equals(\"" + value.toString() +"\")",
"true",
actual.toString().equals(value.toString()) +"",
exception );
}
/**
* Use JSObject.eval to create a JavaScript variable whose value is the
* value of a Java object instance. Use JSObject.eval to reset the value
* of the JavaScript variable, and then use JSObject.eval to get the new
* value of the JavaScript object. Verify that the value of the result
* object is of the expected class and value.
*
* @param field name of the DataTypeClass field
* @param className name of the class of the DataTypeClass field
* @param value value of the DataTypeClass field
*
* @see com.netscape.javascript.qa.liveconnect.DataTypeClass
*/
public void setPublicField( String field, String className, Object value ) {
String description = field;
String exception = null;
Object before = null;
Object after = null;
String expect = null;
Object newValue = className.equals("java.lang.Double")
? new Double(0)
: className.equals("java.lang.Boolean")
? new Boolean(false)
: (Object) new String("New Value!")
;
try {
before = global.eval( description );
// need to quote strings
if ( className.equals("java.lang.String") ){
global.eval( description +" = \"" + newValue.toString() +"\"" );
} else {
global.eval( description +" = " + newValue );
}
after = global.eval( description );
expect = Class.forName( className ).getName();
} catch ( Exception e ) {
exception = e.toString();
}
addTestCase( "global.eval(\""+description+" = "+newValue.toString()+
"\"); after = global.eval( \"" + description +"\" );" +
"after.getClass().getName()",
expect,
after.getClass().getName(),
exception );
addTestCase(
"( "+after.toString() +" ).equals(" + newValue.toString() +")",
"true",
after.equals( newValue ) + "",
exception );
addTestCase(
"\"" +after.toString() + "\".equals(\""+newValue.toString()+"\")",
"true",
after.toString().equals(newValue.toString()) +"",
exception );
}
/**
* Use JSObject.eval to get the value of a Java object field that has been
* defined as final. Assign a value to a public final instance field.
* The assignment should fail (the value should not change), but there
* should be no error message.
*
* @param field name of the DataTypeClass field
* @param className name of the class of the DataTypeClass field
* @param value value of the DataTypeClass field
*
* @see com.netscape.javascript.qa.liveconnect.DataTypeClass
*/
public void setPublicFinalField ( String field, String className,
Object value )
{
String description = field;
String exception = null;
Object before = null;
Object after = null;
String expect = null;
Object newValue = className.equals("java.lang.Double")
? new Double(0)
: className.equals("java.lang.Boolean")
? new Boolean(false)
: (Object) new String("New Value!")
;
try {
expect = Class.forName( className ).getName();
} catch ( Exception e ) {
exception = e.toString();
}
before = global.eval( description );
global.eval( description +" = " + newValue.toString() );
after = global.eval( description );
// check the class of the result, which should be the same as expect
addTestCase( "( " + description +" ).getClass()",
expect,
after.getClass().getName(),
exception );
// the value of the actual result should be the original value
addTestCase( "( " +description + " == " + value.toString() +" )",
"true",
after.equals( value ) + "",
exception );
// the string representation of the actual result should be the same
// as the string representation of the expected value
addTestCase(
"\"" +after.toString() + "\".equals(\"" + value.toString() +"\")",
"true",
after.toString().equals(value.toString()) +"",
exception );
// getMember( field ) should return the same value before and after the
// assignment
addTestCase( "( " + before +".equals(" + after +") ) ",
"true",
( before.equals(after) ) +"",
exception );
}
/**
* Use JSObject.eval to create a JavaScript variable whose value is the
* value of a Java object instance. Use JSObject.setMember to reset the
* value of the variable, and then use JSObject.getMember to get the value
* of the JavaScript object. Vverify that the value of the result object
* is of the expected class and value.
*
* @param field name of the DataTypeClass field
* @param className name of the class of the DataTypeClass field
* @param value value of the DataTypeClass field
*
* @see com.netscape.javascript.qa.liveconnect.DataTypeClass
*/
public void setJavaScriptVariable( String field, String className, Object value ) {
String description = field;
String exception = null;
Object actual = null;
String expect = null;
Object newValue = className.equals("java.lang.Double")
? new Double(0)
: className.equals("java.lang.Boolean")
? new Boolean(false)
: (Object) new String("New Value!")
;
try {
global.eval( "var myobject = " + description );
global.setMember( "myobject", newValue );
actual = global.getMember( "myobject" );
expect = Class.forName( className ).getName();
} catch ( Exception e ) {
exception = e.toString();
}
addTestCase( "global.eval(\"var myobject = " + description +"\" ); " +
"global.setMember( \"myobject\", " + newValue.toString() +");" +
"actual = global.getMember( \"myobject\" ); "+
"actual.getClass().getName()",
expect,
actual.getClass().getName(),
exception );
addTestCase( "( " + description + " == " + newValue.toString() +" )",
"true",
actual.equals( newValue ) + "",
exception );
addTestCase( "\"" +actual.toString() + "\".equals(\"" + newValue.toString() +"\")",
"true",
actual.toString().equals(newValue.toString()) +"",
exception );
}
}

Просмотреть файл

@ -0,0 +1,317 @@
package com.netscape.javascript.qa.liveconnect.datatypes;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Attempt to get java values via instance methods.
* <p>
* Assign a Java value to a JavaScript variable. Set the value of that
* variable with JSObject.setMember, and get the new value with
* JSObject.getMember.
*
* @see com.netscape.javascript.qa.liveconnect.DataTypesClass
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class DataTypes_006 extends LiveConnectTest {
public DataTypes_006() {
super();
}
public static void main( String[] args ) {
DataTypes_006 test = new DataTypes_006();
test.start();
}
public void executeTest() {
doMethodTests(
"dt.getBooleanObject()",
"java.lang.Boolean",
(Object) new Boolean(DataTypeClass.PUB_STATIC_FINAL_BOOLEAN) );
doMethodTests(
"dt.getBoolean()",
"java.lang.Boolean",
(Object) new Boolean(DataTypeClass.PUB_STATIC_FINAL_BOOLEAN) );
doMethodTests(
"dt.getByte()",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_BYTE) );
doMethodTests(
"dt.getByteObject()",
"java.lang.Byte",
(Object) new Byte(DataTypeClass.PUB_STATIC_FINAL_BYTE) );
doMethodTests(
"dt.getShort()",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_SHORT) );
doMethodTests(
"dt.getShortObject()",
"java.lang.Short",
(Object) new Short(DataTypeClass.PUB_STATIC_FINAL_SHORT) );
doMethodTests(
"dt.getInteger()",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_INT) );
doMethodTests(
"dt.getIntegerObject()",
"java.lang.Integer",
(Object) new Integer(DataTypeClass.PUB_STATIC_FINAL_INT) );
doMethodTests(
"dt.getLong()",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_LONG) );
doMethodTests(
"dt.getLongObject()",
"java.lang.Long",
(Object) new Long(DataTypeClass.PUB_STATIC_FINAL_LONG) );
doMethodTests(
"dt.getFloat()",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_FLOAT) );
doMethodTests(
"dt.getFloatObject()",
"java.lang.Float",
(Object) new Float(DataTypeClass.PUB_STATIC_FINAL_FLOAT) );
doMethodTests(
"dt.getDouble()",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_DOUBLE) );
doMethodTests(
"dt.getDoubleObject()",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_DOUBLE) );
doMethodTests(
"dt.getChar()",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_CHAR) );
doMethodTests(
"dt.getCharacter()",
"java.lang.Character",
(Object) new Character(DataTypeClass.PUB_STATIC_FINAL_CHAR) );
doMethodTests(
"dt.getStringObject()",
"java.lang.String",
(Object) new String(DataTypeClass.PUB_STATIC_FINAL_STRING) );
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
global.eval( "var DT = Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass" );
global.eval( "var dt = new DT();" );
}
public void doMethodTests( String method, String className, Object value ) {
getPublicMethod( method, className, value );
}
/**
* Set the value of a JavaScript variable to a Java value.
* Get the value of that variable.
*/
public void getPublicMethod( String method, String className, Object value ) {
String description = method;
String exception = null;
Object actual = null;
String expect = null;
// check the class
try {
actual = global.eval( method );
expect = Class.forName(className).getName();
} catch ( ClassNotFoundException e ) {
} catch ( Exception e ) {
exception = e.toString();
}
// might want to do all the interesting stuff here in a try/catch block.
addTestCase( "( " + description +" ).getClass()",
expect,
actual.getClass().getName(),
exception );
addTestCase( "( " +description + " == " + value.toString() +" )",
"true",
actual.equals( value ) + "",
exception );
addTestCase( "\"" +actual.toString() + "\".equals(\"" + value.toString() +"\")",
"true",
actual.toString().equals(value.toString()) +"",
exception );
}
/**
* Try to set the value of a public static field using
* JSObject.setMember which should succeed.
*/
/*
public void setPublicField( String field, String className, Object value ) {
String description = field;
String exception = null;
Object before = null;
Object after = null;
String expect = null;
Object newValue = className.equals("java.lang.Double")
? new Double(0)
: className.equals("java.lang.Boolean")
? new Boolean(false)
: (Object) new String("New Value!")
;
try {
before = global.eval( description );
// need to quote strings
if ( className.equals("java.lang.String") ){
global.eval( description +" = \"" + newValue.toString() +"\"" );
} else {
global.eval( description +" = " + newValue );
}
after = global.eval( description );
expect = Class.forName( className ).getName();
} catch ( Exception e ) {
exception = e.toString();
}
addTestCase( "global.eval(\""+description+" = "+newValue.toString()+
"\"); after = global.eval( \"" + description +"\" );" +
"after.getClass().getName()",
expect,
after.getClass().getName(),
exception );
addTestCase( "( "+after.toString() +" ).equals(" + newValue.toString() +")",
"true",
after.equals( newValue ) + "",
exception );
addTestCase( "\"" +after.toString() + "\".equals(\"" + newValue.toString() +"\")",
"true",
after.toString().equals(newValue.toString()) +"",
exception );
}
/**
* Assign a value to a public static final java field. The assignment
* should fail (the value should not change), but there should be no error
* message.
*/
public void setPublicField ( String field, String className, Object value ) {
String description = field;
String exception = null;
Object before = null;
Object after = null;
String expect = null;
Object newValue = className.equals("java.lang.Double")
? new Double(0)
: className.equals("java.lang.Boolean")
? new Boolean(false)
: (Object) new String("New Value!")
;
try {
expect = Class.forName( className ).getName();
} catch ( Exception e ) {
exception = e.toString();
}
before = global.eval( description );
global.eval( description +" = " + newValue.toString() );
after = global.eval( description );
// check the class of the result, which should be the same as expect
addTestCase( "( " + description +" ).getClass()",
expect,
after.getClass().getName(),
exception );
// the value of the actual result should be the original value
addTestCase( "( " +description + " == " + value.toString() +" )",
"true",
after.equals( value ) + "",
exception );
// the string representation of the actual result should be the same
// as the string representation of the expected value
addTestCase( "\"" +after.toString() + "\".equals(\"" + value.toString() +"\")",
"true",
after.toString().equals(value.toString()) +"",
exception );
// getMember( field ) should return the same value before and after the
// assignment
addTestCase( "( " + before +".equals(" + after +") ) ",
"true",
( before.equals(after) ) +"",
exception );
}
/*
public void setJavaScriptVariable( String field, String className, Object value ) {
String description = field;
String exception = null;
Object actual = null;
String expect = null;
Object newValue = className.equals("java.lang.Double")
? new Double(0)
: className.equals("java.lang.Boolean")
? new Boolean(false)
: (Object) new String("New Value!")
;
try {
global.eval( "var myobject = " + description );
global.setMember( "myobject", newValue );
actual = global.getMember( "myobject" );
expect = Class.forName( className ).getName();
} catch ( Exception e ) {
exception = e.toString();
}
addTestCase( "global.eval(\"var myobject = " + description +"\" ); " +
"global.setMember( \"myobject\", " + newValue.toString() +");" +
"actual = global.getMember( \"myobject\" ); "+
"actual.getClass().getName()",
expect,
actual.getClass().getName(),
exception );
addTestCase( "( " + description + " == " + newValue.toString() +" )",
"true",
actual.equals( newValue ) + "",
exception );
addTestCase( "\"" +actual.toString() + "\".equals(\"" + newValue.toString() +"\")",
"true",
actual.toString().equals(newValue.toString()) +"",
exception );
}
*/
}

Просмотреть файл

@ -0,0 +1,319 @@
package com.netscape.javascript.qa.liveconnect.datatypes;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Attempt to get java values via static methods.
* <p>
* Assign a Java value to a JavaScript variable. Set the value of that
* variable with JSObject.setMember, and get the new value with
* JSObject.getMember.
*
* @see com.netscape.javascript.qa.liveconnect.DataTypesClass
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class DataTypes_007 extends LiveConnectTest {
public DataTypes_007() {
super();
}
public static void main( String[] args ) {
DataTypes_007 test = new DataTypes_007();
test.start();
}
public void executeTest() {
doStaticMethodTests(
"DT.staticGetBooleanObject()",
"java.lang.Boolean",
(Object) new Boolean(DataTypeClass.PUB_STATIC_FINAL_BOOLEAN) );
doStaticMethodTests(
"DT.staticGetBoolean()",
"java.lang.Boolean",
(Object) new Boolean(DataTypeClass.PUB_STATIC_FINAL_BOOLEAN) );
doStaticMethodTests(
"DT.staticGetByte()",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_BYTE) );
doStaticMethodTests(
"DT.staticGetByteObject()",
"java.lang.Byte",
(Object) new Byte(DataTypeClass.PUB_STATIC_FINAL_BYTE) );
doStaticMethodTests(
"DT.staticGetChar()",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_CHAR) );
doStaticMethodTests(
"DT.staticGetCharacter()",
"java.lang.Character",
(Object) new Character(DataTypeClass.PUB_STATIC_FINAL_CHAR) );
doStaticMethodTests(
"DT.staticGetShort()",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_SHORT) );
doStaticMethodTests(
"DT.staticGetShortObject()",
"java.lang.Short",
(Object) new Short(DataTypeClass.PUB_STATIC_FINAL_SHORT) );
doStaticMethodTests(
"DT.staticGetInteger()",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_INT) );
doStaticMethodTests(
"DT.staticGetIntegerObject()",
"java.lang.Integer",
(Object) new Integer(DataTypeClass.PUB_STATIC_FINAL_INT) );
doStaticMethodTests(
"DT.staticGetInteger()",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_INT) );
doStaticMethodTests(
"DT.staticGetLong()",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_LONG) );
doStaticMethodTests(
"DT.staticGetLongObject()",
"java.lang.Long",
(Object) new Long(DataTypeClass.PUB_STATIC_FINAL_LONG) );
doStaticMethodTests(
"DT.staticGetFloat()",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_FLOAT) );
doStaticMethodTests(
"DT.staticGetFloatObject()",
"java.lang.Float",
(Object) new Float(DataTypeClass.PUB_STATIC_FINAL_FLOAT) );
doStaticMethodTests(
"DT.staticGetDouble()",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_DOUBLE) );
doStaticMethodTests(
"DT.staticGetDoubleObject()",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_DOUBLE) );
doStaticMethodTests(
"DT.staticGetChar()",
"java.lang.Double",
(Object) new Double(DataTypeClass.PUB_STATIC_FINAL_CHAR) );
doStaticMethodTests(
"DT.staticGetStringObject()",
"java.lang.String",
(Object) new String(DataTypeClass.PUB_STATIC_FINAL_STRING) );
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
global.eval( "var DT = Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass" );
}
public void doStaticMethodTests( String method, String className, Object value ) {
getPublicStaticMethod( method, className, value );
getJavaScriptValue( method, className, value );
}
/**
* Set the value of a JavaScript variable to a Java value.
* Get the value of that variable.
*/
public void getPublicStaticMethod( String method, String className, Object value ) {
String description = method;
String exception = null;
Object actual = null;
String expect = null;
// check the class
try {
actual = global.eval( method );
expect = Class.forName(className).getName();
} catch ( ClassNotFoundException e ) {
} catch ( Exception e ) {
exception = e.toString();
}
// might want to do all the interesting stuff here in a try/catch block.
addTestCase( "( " + description +" ).getClass()",
expect,
actual.getClass().getName(),
exception );
addTestCase( "( " +description + " == " + value.toString() +" )",
"true",
actual.equals( value ) + "",
exception );
addTestCase( "\"" +actual.toString() + "\".equals(\"" + value.toString() +"\")",
"true",
actual.toString().equals(value.toString()) +"",
exception );
}
/**
* Try to set the value of a public static field using
* JSObject.setMember which should succeed.
*/
public void setPublicStaticField( String field, String className, Object value ) {
String description = field;
String exception = null;
Object before = null;
Object after = null;
String expect = null;
Object newValue = className.equals("java.lang.Double")
? new Double(0)
: className.equals("java.lang.Boolean")
? new Boolean(false)
: (Object) new String("New Value!")
;
try {
before = global.eval( description );
// need to quote strings
if ( className.equals("java.lang.String") ){
global.eval( description +" = \"" + newValue.toString() +"\"" );
} else {
global.eval( description +" = " + newValue );
}
after = global.eval( description );
expect = Class.forName( className ).getName();
} catch ( Exception e ) {
exception = e.toString();
}
addTestCase( "global.eval(\""+description+" = "+newValue.toString()+
"\"); after = global.eval( \"" + description +"\" );" +
"after.getClass().getName()",
expect,
after.getClass().getName(),
exception );
addTestCase( "( "+after.toString() +" ).equals(" + newValue.toString() +")",
"true",
after.equals( newValue ) + "",
exception );
addTestCase( "\"" +after.toString() + "\".equals(\"" + newValue.toString() +"\")",
"true",
after.toString().equals(newValue.toString()) +"",
exception );
}
/**
* Assign a value to a public static final java field. The assignment
* should fail (the value should not change), but there should be no error
* message.
*/
public void setPublicStaticFinalField ( String field, String className, Object value ) {
String description = field;
String exception = null;
Object before = null;
Object after = null;
String expect = null;
Object newValue = className.equals("java.lang.Double")
? new Double(0)
: className.equals("java.lang.Boolean")
? new Boolean(false)
: (Object) new String("New Value!")
;
try {
expect = Class.forName( className ).getName();
} catch ( Exception e ) {
exception = e.toString();
}
before = global.eval( description );
global.eval( description +" = " + newValue.toString() );
after = global.eval( description );
// check the class of the result, which should be the same as expect
addTestCase( "( " + description +" ).getClass()",
expect,
after.getClass().getName(),
exception );
// the value of the actual result should be the original value
addTestCase( "( " +description + " == " + value.toString() +" )",
"true",
after.equals( value ) + "",
exception );
// the string representation of the actual result should be the same
// as the string representation of the expected value
addTestCase( "\"" +after.toString() + "\".equals(\"" + value.toString() +"\")",
"true",
after.toString().equals(value.toString()) +"",
exception );
// getMember( field ) should return the same value before and after the
// assignment
addTestCase( "( " + before +".equals(" + after +") ) ",
"true",
( before.equals(after) ) +"",
exception );
}
public void getJavaScriptValue( String field, String className, Object value ) {
String description = field;
String exception = null;
Object actual = null;
String expect = null;
try {
global.eval( "var myobject = " + description );
actual = global.getMember( "myobject" );
expect = Class.forName( className ).getName();
} catch ( Exception e ) {
exception = e.toString();
}
addTestCase( "global.eval(\"var myobject = " + description +"\" ); " +
"actual = global.getMember( \"myobject\" ); "+
"actual.getClass().getName()",
expect,
actual.getClass().getName(),
exception );
addTestCase( "( " + actual + " == " + value.toString() +" )",
"true",
actual.equals( value ) + "",
exception );
addTestCase( "\"" +actual.toString() + "\".equals(\"" + value.toString() +"\")",
"true",
actual.toString().equals(value.toString()) +"",
exception );
}
}

Просмотреть файл

@ -0,0 +1,111 @@
package com.netscape.javascript.qa.liveconnect.datatypes;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Tests for converting Java byte[] to JavaScript variables.
*
* Create a JavaScript variable. Use JSObject.eval to call a Java method
* that returns a Java array. Assign the array to the JavaScript variable.
*
* <p>
*
* Iterate through the array in JavaScript. Get the value, and compare it
* to the value in the original Java array.
*
* <p>
*
* Use JSObject.getMember to get the JavaScript variable. Verify that the
* array is the same object that was used to assign the original JS variable.
*
* @see com.netscape.javascript.qa.liveconnect.DataTypesClass
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class DataTypes_008 extends LiveConnectTest {
public DataTypes_008() {
super();
}
public static void main( String[] args ) {
DataTypes_008 test = new DataTypes_008();
test.start();
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
global.eval( "var DT = "+
"Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass");
global.eval( "var dt = new DT();" );
}
public void executeTest() {
doArrayTest( "DT.PUB_STATIC_ARRAY_BYTE;", true);
doArrayTest( "dt.getByteArray();", true );
doArrayTest( "dt.PUB_ARRAY_BYTE;", false );
}
/**
* Assign a java byte array to a JavaScript variable in the following ways:
* <ul>
* <li> Call a static method
* <li> Get the value of a static field
* <li> Call an instance method
* <li> Get the value of an instance field.
*
* @param command method call or field reference that returns an array
*/
public void doArrayTest( String command, boolean shouldEqual) {
byte array[] = DataTypeClass.PUB_STATIC_ARRAY_BYTE;
byte jsArray[];
int jsArray_length;
try {
// assign the array to a JavaScript variable
global.eval( "var jsArray = " + command );
// get the jsArray object, which should be the java object
jsArray = (byte[]) global.getMember( "jsArray" );
// get the length of the array from JavaScript
jsArray_length =
((Double) global.eval("jsArray.length")).intValue();
// iterate through jsArray in JavaScript. verify that the type and
// value of each object in the array is correct.
for ( int i = 0; i < jsArray_length; i++ ) {
// verify that the array item is the same object as in the
// original array
Double item = (Double) global.eval( "jsArray[" + i +"];" );
addTestCase(
"[jsArray = " + command +"] "+
"global.eval( \"var jsArray = " + command +")"+
"global.eval(\"jsArray["+i+"]\").equals( array["+i+"])",
"true",
(item.equals(new Double(array[i]))) +"",
"" );
}
} catch ( Exception e ) {
e.printStackTrace();
file.exception = e.toString();
jsArray_length = 0;
jsArray = null;
}
// verify that jsArray is the same as the original array
addTestCase(
"[jsArray = "+ command +"] "+
"jsArray = global.getMember( \"jsArray\"); "+
"jsArray == array",
( shouldEqual ) ? "true" : "false",
(jsArray == array ) +"",
"" );
}
}

Просмотреть файл

@ -0,0 +1,114 @@
package com.netscape.javascript.qa.liveconnect.datatypes;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Tests for converting Java char[] to JavaScript variables.
*
* <p>
*
* Create a JavaScript variable. Use JSObject.eval to call a Java method
* that returns a Java array. Assign the array to the JavaScript variable.
*
* <p>
*
* Iterate through the array in JavaScript. Get the value, and compare it
* to the value in the original Java array.
*
* <p>
*
* Use JSObject.getMember to get the JavaScript variable. Verify that the
* array is the same object that was used to assign the original JS variable.
*
* @see com.netscape.javascript.qa.liveconnect.DataTypesClass
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class DataTypes_009 extends LiveConnectTest {
public DataTypes_009() {
super();
}
public static void main( String[] args ) {
DataTypes_009 test = new DataTypes_009();
test.start();
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
global.eval( "var DT = "+
"Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass");
global.eval( "var dt = new DT();" );
}
public void executeTest() {
doArrayTest( "DT.staticGetCharArray();", true );
doArrayTest( "DT.PUB_STATIC_ARRAY_CHAR;", true);
doArrayTest( "dt.getCharArray();", true );
doArrayTest( "dt.PUB_ARRAY_CHAR;", false );
}
/**
* Assign a java array to a JavaScript variable in the following ways:
* <ul>
* <li> Call a static method
* <li> Get the value of a static field
* <li> Call an instance method
* <li> Get the value of an instance field.
*
* @param command the command to eval to get the array
*/
public void doArrayTest( String command, boolean shouldEqual ) {
char array[] = DataTypeClass.PUB_STATIC_ARRAY_CHAR;
char jsArray[];
int jsArray_length;
try {
// assign the array to a JavaScript variable
global.eval( "var jsArray = " + command );
// get the jsArray object, which should be the java object
jsArray = (char[]) global.getMember( "jsArray" );
// get the length of the array from JavaScript
jsArray_length =
((Double) global.eval("jsArray.length")).intValue();
// iterate through jsArray in JavaScript. verify that the type and
// value of each object in the array is correct.
for ( int i = 0; i < jsArray_length; i++ ) {
// verify that the array item is the same object as in the
// original array
Double item = (Double) global.eval( "jsArray[" + i +"];" );
addTestCase(
"[ jsArray = " + command +"] "+
"global.eval(\"jsArray["+i+"]\").equals( array["+i+"])",
"true",
(item.equals(new Double(array[i]))) +"",
"" );
}
} catch ( Exception e ) {
e.printStackTrace();
file.exception = e.toString();
jsArray_length = 0;
jsArray = null;
}
// verify that jsArray is the same as the original array
addTestCase(
"[jsArray = "+ command +"] "+
"jsArray = global.getMember( \"jsArray\"); "+
"jsArray == array",
(shouldEqual) ? "true" : "false",
(jsArray == array ) +"",
"" );
}
}

Просмотреть файл

@ -0,0 +1,116 @@
package com.netscape.javascript.qa.liveconnect.datatypes;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Tests for converting Java double[] to JavaScript variables.
*
* <p>
*
* Create a JavaScript variable. Use JSObject.eval to call a Java method
* that returns a Java array. Assign the array to the JavaScript variable.
*
* <p>
*
* Iterate through the array in JavaScript. Get the value, and compare it
* to the value in the original Java array.
*
* <p>
*
* Use JSObject.getMember to get the JavaScript variable. Verify that the
* array is the same object that was used to assign the original JS variable.
*
* @see com.netscape.javascript.qa.liveconnect.DataTypesClass
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class DataTypes_010 extends LiveConnectTest {
public DataTypes_010() {
super();
}
public static void main( String[] args ) {
DataTypes_010 test = new DataTypes_010();
test.start();
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
global.eval( "var DT = "+
"Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass");
global.eval( "var dt = new DT();" );
}
public void executeTest() {
doArrayTest( "DT.staticGetDoubleArray();", true );
doArrayTest( "DT.PUB_STATIC_ARRAY_DOUBLE;", true);
doArrayTest( "dt.getDoubleArray();", true );
doArrayTest( "dt.PUB_ARRAY_DOUBLE;", false );
}
/**
* Assign a java byte array to a JavaScript variable in the following ways:
* <ul>
* <li> Call a static method
* <li> Get the value of a static field
* <li> Call an instance method
* <li> Get the value of an instance field.
*
* @param command the command to eval to get the byte array
*/
public void doArrayTest( String command, boolean shouldEqual ) {
double array[] = DataTypeClass.PUB_STATIC_ARRAY_DOUBLE;
double jsArray[];
int jsArray_length;
try {
// assign the array to a JavaScript variable
global.eval( "var jsArray = " + command );
// get the jsArray object, which should be the java object
jsArray = (double[]) global.getMember( "jsArray" );
// get the length of the array from JavaScript
jsArray_length =
((Double) global.eval("jsArray.length")).intValue();
// iterate through jsArray in JavaScript. verify that the type and
// value of each object in the array is correct.
for ( int i = 0; i < jsArray_length; i++ ) {
// verify that the array item is the same object as in the
// original array
Double item = (Double) global.eval( "jsArray[" + i +"];" );
addTestCase(
"[ jsArray = " + command +"] "+
"global.eval( \"var jsArray = " + command +")"+
"global.eval(\"jsArray["+i+"]\").equals( array["+i+"])",
"true",
(item.equals(new Double(array[i]))) +"",
"" );
}
} catch ( Exception e ) {
e.printStackTrace();
file.exception = e.toString();
jsArray_length = 0;
jsArray = null;
}
// verify that jsArray is the same as the original array
addTestCase(
"[jsArray = "+ command +"] "+
"jsArray = global.getMember( \"jsArray\"); "+
"jsArray == array",
( shouldEqual ) ? "true" : "false",
(jsArray == array ) +"",
"" );
}
}

Просмотреть файл

@ -0,0 +1,114 @@
package com.netscape.javascript.qa.liveconnect.datatypes;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Tests for converting Java short[] to JavaScript variables.
*
* <p>
*
* Create a JavaScript variable. Use JSObject.eval to call a Java method
* that returns a Java array. Assign the array to the JavaScript variable.
*
* <p>
*
* Iterate through the array in JavaScript. Get the value, and compare it
* to the value in the original Java array.
*
* <p>
*
* Use JSObject.getMember to get the JavaScript variable. Verify that the
* array is the same object that was used to assign the original JS variable.
*
* @see com.netscape.javascript.qa.liveconnect.DataTypesClass
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class DataTypes_011 extends LiveConnectTest {
public DataTypes_011() {
super();
}
public static void main( String[] args ) {
DataTypes_011 test = new DataTypes_011();
test.start();
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
global.eval( "var DT = "+
"Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass");
global.eval( "var dt = new DT();" );
}
public void executeTest() {
doArrayTest( "DT.staticGetShortArray();", true );
doArrayTest( "DT.PUB_STATIC_ARRAY_SHORT;", true);
doArrayTest( "dt.getShortArray();", true );
doArrayTest( "dt.PUB_ARRAY_SHORT;", false );
}
/**
* Assign a java short[] to a JavaScript variable in the following ways:
* <ul>
* <li> Call a static method
* <li> Get the value of a static field
* <li> Call an instance method
* <li> Get the value of an instance field.
*
* @param command the command to eval to get the byte array
*/
public void doArrayTest( String command, boolean shouldEqual ) {
short array[] = DataTypeClass.PUB_STATIC_ARRAY_SHORT;
short jsArray[];
int jsArray_length;
try {
// assign the array to a JavaScript variable
global.eval( "var jsArray = " + command );
// get the jsArray object, which should be the java object
jsArray = (short[]) global.getMember( "jsArray" );
// get the length of the array from JavaScript
jsArray_length =
((Double) global.eval("jsArray.length")).intValue();
// iterate through jsArray in JavaScript. verify that the type and
// value of each object in the array is correct.
for ( int i = 0; i < jsArray_length; i++ ) {
// verify that the array item is the same object as in the
// original array
Double item = (Double) global.eval( "jsArray[" + i +"];" );
addTestCase(
"[ jsArray = " + command +"] "+
"global.eval(\"jsArray["+i+"]\").equals( array["+i+"])",
"true",
(item.equals(new Double(array[i]))) +"",
"" );
}
} catch ( Exception e ) {
e.printStackTrace();
file.exception = e.toString();
jsArray_length = 0;
jsArray = null;
}
// verify that jsArray is the same as the original array
addTestCase(
"[jsArray = "+ command +"] "+
"jsArray = global.getMember( \"jsArray\"); "+
"jsArray == array",
( shouldEqual ) ? "true" : "false",
(jsArray == array ) +"",
"" );
}
}

Просмотреть файл

@ -0,0 +1,114 @@
package com.netscape.javascript.qa.liveconnect.datatypes;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Tests for converting Java long[] to JavaScript variables.
*
* <p>
*
* Create a JavaScript variable. Use JSObject.eval to call a Java method
* that returns a Java array. Assign the array to the JavaScript variable.
*
* <p>
*
* Iterate through the array in JavaScript. Get the value, and compare it
* to the value in the original Java array.
*
* <p>
*
* Use JSObject.getMember to get the JavaScript variable. Verify that the
* array is the same object that was used to assign the original JS variable.
*
* @see com.netscape.javascript.qa.liveconnect.DataTypesClass
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class DataTypes_012 extends LiveConnectTest {
public DataTypes_012() {
super();
}
public static void main( String[] args ) {
DataTypes_012 test = new DataTypes_012();
test.start();
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
global.eval( "var DT = "+
"Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass");
global.eval( "var dt = new DT();" );
}
public void executeTest() {
doArrayTest( "DT.staticGetLongArray();", true );
doArrayTest( "DT.PUB_STATIC_ARRAY_LONG;", true);
doArrayTest( "dt.getLongArray();", true );
doArrayTest( "dt.PUB_ARRAY_LONG;", false );
}
/**
* Assign a java long [] to a JavaScript variable in the following ways:
* <ul>
* <li> Call a static method
* <li> Get the value of a static field
* <li> Call an instance method
* <li> Get the value of an instance field.
*
* @param command the command to eval to get the array
*/
public void doArrayTest( String command, boolean shouldEqual ) {
long array[] = DataTypeClass.PUB_STATIC_ARRAY_LONG;
long jsArray[];
int jsArray_length;
try {
// assign the array to a JavaScript variable
global.eval( "var jsArray = " + command );
// get the jsArray object, which should be the java object
jsArray = (long[]) global.getMember( "jsArray" );
// get the length of the array from JavaScript
jsArray_length =
((Double) global.eval("jsArray.length")).intValue();
// iterate through jsArray in JavaScript. verify that the type and
// value of each object in the array is correct.
for ( int i = 0; i < jsArray_length; i++ ) {
// verify that the array item is the same object as in the
// original array
Double item = (Double) global.eval( "jsArray[" + i +"];" );
addTestCase(
"[jsArray = " + command +"] "+
"global.eval(\"jsArray["+i+"]\").equals( array["+i+"])",
"true",
(item.equals(new Double(array[i]))) +"",
"" );
}
} catch ( Exception e ) {
e.printStackTrace();
file.exception = e.toString();
jsArray_length = 0;
jsArray = null;
}
// verify that jsArray is the same as the original array
addTestCase(
"[jsArray = " + command +"] "+
"jsArray = global.getMember( \"jsArray\"); "+
"jsArray == array",
( shouldEqual ) ? "true" : "false",
(jsArray == array ) +"",
"" );
}
}

Просмотреть файл

@ -0,0 +1,113 @@
package com.netscape.javascript.qa.liveconnect.datatypes;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Call a static method that returns a int[].
*
* <p>
*
* Create a JavaScript variable. Use JSObject.eval to call a Java method
* that returns a Java array. Assign the array to the JavaScript variable.
*
* <p>
*
* Iterate through the array in JavaScript. Get the value, and compare it
* to the value in the original Java array.
*
* <p>
*
* Use JSObject.getMember to get the JavaScript variable. Verify that the
* array is the same object that was used to assign the original JS variable.
*
* @see com.netscape.javascript.qa.liveconnect.DataTypesClass
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class DataTypes_013 extends LiveConnectTest {
public DataTypes_013() {
super();
}
public static void main( String[] args ) {
DataTypes_013 test = new DataTypes_013();
test.start();
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
global.eval( "var DT = "+
"Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass");
global.eval( "var dt = new DT();" );
}
public void executeTest() {
doArrayTest( "DT.staticGetIntArray();", true );
doArrayTest( "DT.PUB_STATIC_ARRAY_INT;", true);
doArrayTest( "dt.getIntArray();", true );
doArrayTest( "dt.PUB_ARRAY_INT;", false );
}
/**
* Assign a java byte array to a JavaScript variable in the following ways:
* <ul>
* <li> Call a static method
* <li> Get the value of a static field
* <li> Call an instance method
* <li> Get the value of an instance field.
*
* @param command the command to eval to get the byte array
*/
public void doArrayTest( String command, boolean shouldEqual ) {
int array[] = DataTypeClass.PUB_STATIC_ARRAY_INT;
int jsArray[];
int jsArray_length;
try {
// assign the array to a JavaScript variable
global.eval( "var jsArray = " + command );
// get the jsArray object, which should be the java object
jsArray = (int[]) global.getMember( "jsArray" );
// get the length of the array from JavaScript
jsArray_length =
((Double) global.eval("jsArray.length")).intValue();
// iterate through jsArray in JavaScript. verify that the type and
// value of each object in the array is correct.
for ( int i = 0; i < jsArray_length; i++ ) {
// verify that the array item is the same object as in the
// original array
Double item = (Double) global.eval( "jsArray[" + i +"];" );
addTestCase(
"[jsArray = " + command +"] "+
"global.eval(\"jsArray["+i+"]\").equals( array["+i+"])",
"true",
(item.equals(new Double(array[i]))) +"",
"" );
}
} catch ( Exception e ) {
e.printStackTrace();
file.exception = e.toString();
jsArray_length = 0;
jsArray = null;
}
// verify that jsArray is the same as the original array
addTestCase(
"[jsArray = " + command +"] "+
"jsArray = global.getMember( \"jsArray\"); "+
"jsArray == array",
( shouldEqual ) ? "true" : "false",
(jsArray == array ) +"",
"" );
}
}

Просмотреть файл

@ -0,0 +1,113 @@
package com.netscape.javascript.qa.liveconnect.datatypes;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Tests for converting Java float[] to JavaScript variables.
*
* <p>
*
* Create a JavaScript variable. Use JSObject.eval to call a Java method
* that returns a Java array. Assign the array to the JavaScript variable.
*
* <p>
*
* Iterate through the array in JavaScript. Get the value, and compare it
* to the value in the original Java array.
*
* <p>
*
* Use JSObject.getMember to get the JavaScript variable. Verify that the
* array is the same object that was used to assign the original JS variable.
*
* @see com.netscape.javascript.qa.liveconnect.DataTypesClass
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class DataTypes_014 extends LiveConnectTest {
public DataTypes_014() {
super();
}
public static void main( String[] args ) {
DataTypes_014 test = new DataTypes_014();
test.start();
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
global.eval( "var DT = "+
"Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass");
global.eval( "var dt = new DT();" );
}
public void executeTest() {
doArrayTest( "DT.staticGetFloatArray();", true );
doArrayTest( "DT.PUB_STATIC_ARRAY_FLOAT;", true);
doArrayTest( "dt.getFloatArray();", true );
doArrayTest( "dt.PUB_ARRAY_FLOAT;", false );
}
/**
* Assign a java float array to a JavaScript variable in the following ways:
* <ul>
* <li> Call a static method
* <li> Get the value of a static field
* <li> Call an instance method
* <li> Get the value of an instance field.
*
* @param command the command to eval to get the float array
*/
public void doArrayTest( String command, boolean shouldEqual ) {
float array[] = DataTypeClass.PUB_STATIC_ARRAY_FLOAT;
float jsArray[];
int jsArray_length;
try {
// assign the array to a JavaScript variable
global.eval( "var jsArray = " + command );
// get the jsArray object, which should be the java object
jsArray = (float[]) global.getMember( "jsArray" );
// get the length of the array from JavaScript
jsArray_length =
((Double) global.eval("jsArray.length")).intValue();
// iterate through jsArray in JavaScript. verify that the type and
// value of each object in the array is correct.
for ( int i = 0; i < jsArray_length; i++ ) {
// verify that the array item is the same object as in the
// original array
Double item = (Double) global.eval( "jsArray[" + i +"];" );
addTestCase(
"[jsArray = " + command +"] "+
"global.eval(\"jsArray["+i+"]\").equals( array["+i+"])",
"true",
(item.equals(new Double(array[i]))) +"",
"" );
}
} catch ( Exception e ) {
e.printStackTrace();
file.exception = e.toString();
jsArray_length = 0;
jsArray = null;
}
// verify that jsArray is the same as the original array
addTestCase(
"[jsArray = "+ command +"] "+
"jsArray = global.getMember( \"jsArray\"); "+
"jsArray == array",
( shouldEqual ) ? "true" : "false",
(jsArray == array ) +"",
"" );
}
}

Просмотреть файл

@ -0,0 +1,113 @@
package com.netscape.javascript.qa.liveconnect.datatypes;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Tests for converting Java Object[] to JavaScript variables.
*
* <p>
*
* Create a JavaScript variable. Use JSObject.eval to call a Java method
* that returns a Java array. Assign the array to the JavaScript variable.
*
* <p>
*
* Iterate through the array in JavaScript. Get the value, and compare it
* to the value in the original Java array.
*
* <p>
*
* Use JSObject.getMember to get the JavaScript variable. Verify that the
* array is the same object that was used to assign the original JS variable.
*
* @see com.netscape.javascript.qa.liveconnect.DataTypesClass
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class DataTypes_015 extends LiveConnectTest {
public DataTypes_015() {
super();
}
public static void main( String[] args ) {
DataTypes_015 test = new DataTypes_015();
test.start();
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
global.eval( "var DT = "+
"Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass;");
global.eval( "var dt = new DT();" );
}
public void executeTest() {
doArrayTest( "DT.staticGetObjectArray();", true );
doArrayTest( "DT.PUB_STATIC_ARRAY_OBJECT;", true);
doArrayTest( "dt.getObjectArray();", true );
doArrayTest( "dt.PUB_ARRAY_OBJECT;", false );
}
/**
* Assign a java object array to a JavaScript variable in the following ways:
* <ul>
* <li> Call a static method
* <li> Get the value of a static field
* <li> Call an instance method
* <li> Get the value of an instance field.
*
* @param command the command to eval to get the object array
*/
public void doArrayTest( String command, boolean shouldEqual ) {
Object array[] = DataTypeClass.PUB_STATIC_ARRAY_OBJECT;
Object jsArray[];
int jsArray_length;
try {
// assign the array to a JavaScript variable
global.eval( "var jsArray = " + command );
// get the jsArray object, which should be the java array
jsArray = (Object[]) global.getMember( "jsArray" );
// get the length of the array from JavaScript
jsArray_length =
((Double) global.eval("jsArray.length")).intValue();
// iterate through jsArray in JavaScript. verify that the type and
// value of each object in the array is correct.
for ( int i = 0; i < jsArray_length; i++ ) {
// verify that the array item is the same object as in the
// original array
Object item = (Object) global.eval( "jsArray[" + i +"];" );
addTestCase(
"[jsArray = " + command +"] "+
"global.eval(\"jsArray["+i+"]\").equals( array["+i+"])",
shouldEqual+"",
item.equals(array[i]) +"",
"" );
}
} catch ( Exception e ) {
e.printStackTrace();
file.exception = e.toString();
jsArray_length = 0;
jsArray = null;
}
// verify that jsArray is the same as the original array
addTestCase(
"[jsArray = "+ command +"] "+
"jsArray = global.getMember( \"jsArray\"); "+
"jsArray == array",
( shouldEqual )+"",
(jsArray == array ) +"",
exception );
}
}

Просмотреть файл

@ -0,0 +1,237 @@
package com.netscape.javascript.qa.liveconnect.datatypes;
import com.netscape.javascript.qa.liveconnect.*;
import netscape.javascript.*;
/**
* From JavaScript, call a static Java method that takes arguments. The
* argument should be correctly cast to the type expected by the Java
* method.
*
* <p>
*
* This test calls a setter method. The test is verified by calling the
* getter method, and verifying that the value is the setter worked
* correctly.
*
* <p>
*
* This tests passing JavaScript values as arguments of the following types:
* double, byte, short, long, float, int.
*
* If JavaScript passes a value that is larger than th MAX_VALUE of that type,
* expect a JSException.
*
* <p>
* Still need tests for the following types: String, Object, char, JSObject
*
* @see com.netscape.javascript.qa.liveconnect.DataTypesClass
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class DataTypes_016 extends LiveConnectTest {
public DataTypes_016() {
super();
}
public static void main( String[] args ) {
DataTypes_016 test = new DataTypes_016();
test.start();
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
global.eval( "var DT = "+
"Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass");
global.eval( "var dt = new DT();" );
}
//XXX need to add special cases: NaN, Infinity, -Infinity, but won't
// work in this framework
String jsVals[] = { "0.0", "3.14159", "-1.159", "-0.01", "0.1",
"4294967295", "4294967296", "-4294967296",
"2147483647", "2147483648", "-2147483648" };
public boolean checkByte( String v ) {
double max = new Double( Byte.MAX_VALUE ).doubleValue();
double min = new Double( Byte.MIN_VALUE ).doubleValue();
double value = new Double(v).doubleValue();
if ( value >= min && value <= max )
return true;
return false;
}
public boolean checkInteger( String v ) {
double max = new Double(Integer.MAX_VALUE ).doubleValue();
double min = new Double( Integer.MIN_VALUE ).doubleValue();
double value = new Double(v).doubleValue();
if ( value >= min && value <= max )
return true;
return false;
}
public boolean checkShort( String v ) {
double max = new Double( Short.MAX_VALUE ).doubleValue();
double min = new Double( Short.MIN_VALUE ).doubleValue();
double value = new Double(v).doubleValue();
if ( value >= min && value <= max )
return true;
return false;
}
public boolean checkFloat( String v ) {
double max = new Double( Float.MAX_VALUE ).doubleValue();
double min = new Double( Float.MIN_VALUE ).doubleValue();
double value = new Double(v).doubleValue();
if ( value >= min && value <= max )
return true;
return false;
}
public boolean checkLong( String v ) {
double max = new Double( Long.MAX_VALUE ).doubleValue();
double min = new Double( Long.MIN_VALUE ).doubleValue();
double value = new Double(v).doubleValue();
if ( value >= min && value <= max )
return true;
return false;
}
public boolean checkDouble( String v ) {
double max = new Double( Double.MAX_VALUE ).doubleValue();
double min = new Double( Double.MIN_VALUE ).doubleValue();
double value = new Double(v).doubleValue();
if ( value >= min && value <= max )
return true;
return false;
}
public void executeTest() {
for ( int i = 0; i < jsVals.length; i++ ) {
doSetterTest( "DT.staticSetDouble",
jsVals[i],
"DT.staticGetDouble",
"DT.PUB_STATIC_DOUBLE",
(Number) new Double(jsVals[i]),
(Number) new Double(DataTypeClass.PUB_STATIC_DOUBLE),
true );
doSetterTest( "DT.staticSetByte",
jsVals[i],
"DT.staticGetByte",
"DT.PUB_STATIC_BYTE",
(Number) new Byte(new Double(jsVals[i]).byteValue()),
(Number) new Byte(DataTypeClass.PUB_STATIC_BYTE),
checkByte( jsVals[i]) );
doSetterTest( "DT.staticSetShort",
jsVals[i],
"DT.staticGetShort",
"DT.PUB_STATIC_SHORT",
(Number) new Short(new Double(jsVals[i]).shortValue()),
(Number) new Short(DataTypeClass.PUB_STATIC_SHORT),
checkShort( jsVals[i]) );
doSetterTest( "DT.staticSetInteger",
jsVals[i],
"DT.staticGetInteger",
"DT.PUB_STATIC_INT",
(Number) new Integer(new Double(jsVals[i]).intValue()),
(Number) new Integer(DataTypeClass.PUB_STATIC_INT),
checkInteger( jsVals[i]) );
doSetterTest( "DT.staticSetFloat",
jsVals[i],
"DT.staticGetFloat",
"DT.PUB_STATIC_FLOAT",
(Number) new Float(new Double(jsVals[i]).floatValue()),
(Number) new Float(DataTypeClass.PUB_STATIC_FLOAT),
true );
doSetterTest( "DT.staticSetLong",
jsVals[i],
"DT.staticGetLong",
"DT.PUB_STATIC_LONG",
(Number) new Long(new Double(jsVals[i]).longValue()),
(Number) new Long(DataTypeClass.PUB_STATIC_LONG),
checkLong( jsVals[i]) );
}
}
/**
* This tests calls a Java setter method from JavaScript. It verifies
* that the setter was called properly in two ways: by checking the
* return value of the getter method, and by checking the value of the
* public field that was set.
*
* @param setter java method that takes an argument, and sets a value
* @param jsValue JavaScript value that is passed to the setter
* @param getter java method that returns the value set by setter
* @param field java field that setter changed
* @param eResult expected result, which should be of some Number type
* @param inRange whether or not the value is in range for the particular
* type. if not, expect a JSExcedeption
*/
public void doSetterTest( String setter, String jsValue, String getter,
String field, Number eResult, Number fieldValue,
boolean inRange )
{
String setMethod = setter +"(" + jsValue +");";
String getMethod = getter + "();";
Double expectedResult = (inRange) ?
new Double( eResult.doubleValue() ) :
new Double(fieldValue.doubleValue());
Double getterResult=null;
Object fieldResult=null;
String setResult = "no exception";
String expectedSetResult = setResult;
try {
expectedSetResult = (inRange) ? "no exception" :
Class.forName("netscape.javascript.JSException").getName();
// From JavaScript, call the setter. will throw exception if
// ! inRange
global.eval( setMethod );
} catch ( Exception e ) {
setResult = e.getClass().getName();
file.exception = e.toString();
} finally {
addTestCase(
setMethod,
expectedSetResult,
setResult,
file.exception );
}
try {
// From JavaScript, call the getter
getterResult = (Double) global.eval( getMethod );
// From JavaSript, access the field
fieldResult = (Double) global.eval( field );
} catch ( Exception e ) {
e.printStackTrace();
file.exception = e.toString();
fieldResult = e.getClass().getName();
} finally {
addTestCase(
"[value: " + getterResult +"; expected: " + expectedResult +"] "+
setMethod + "( " + expectedResult +").equals(" + getterResult +")",
"true",
expectedResult.equals(getterResult) +"",
file.exception );
addTestCase(
"[value: " + fieldResult +"; expected: " + expectedResult +"] "+
setMethod + "(" + expectedResult +").equals(" + fieldResult +")",
"true",
expectedResult.equals(fieldResult) +"",
file.exception );
}
}
}

Просмотреть файл

@ -0,0 +1,211 @@
package com.netscape.javascript.qa.liveconnect.datatypes;
import com.netscape.javascript.qa.liveconnect.*;
/**
* From JavaScript, call an instance Java method that takes arguments. The
* argument should be correctly cast to the type expected by the Java
* method.
*
* <p>
*
* This test calls a setter method. The test is verified by calling the
* getter method, and verifying that the value is the setter worked
* correctly.
*
* <p>
*
* This tests passing JavaScript values as arguments of the following types:
* double, byte, short, long, float, int.
*
* <p>
* Still need tests for the following types: String, Object, char, JSObject
*
* @see com.netscape.javascript.qa.liveconnect.DataTypesClass
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class DataTypes_017 extends LiveConnectTest {
public DataTypes_017() {
super();
}
public static void main( String[] args ) {
DataTypes_017 test = new DataTypes_017();
test.start();
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
global.eval( "var DT = "+
"Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass");
global.eval( "var dt = new DT();" );
}
// XXX need to add special cases: NaN, Infinity, -Infinity, but won't
// work in this framework
String jsVals[] = { "0", "3.14159", "-1.159", "-0.01", "0.1",
"4294967295", "4294967296", "-4294967296",
"2147483647", "2147483648", "-2147483648" };
/**
* call the setter test with 5 values:
* <ul>
* <li> string value to call setters / getters with
* <li> method to set the value
* <li> method to get the value
* <li> field that returns the value
* <li> expected result of getter, field
* <li> whether or not an exception gets thrown
* </ul>
*
* The rules for conversion:
* <ul>
* <li> if the setter sets the value out of the range, return an exception
* <li> if the value is in range, transform value to Math.floor( value )
* <li> NaN returns 0.
* </ul>
*
*
*
*/
public void executeTest() {
for ( int i = 0; i < jsVals.length; i++ ) {
doSetterTest( jsVals[i],
"dt.setDouble",
"dt.getDouble",
"dt.PUB_DOUBLE",
( new Double(jsVals[i]).doubleValue() > Double.MAX_VALUE
? EXCEPTION
: ( new Double(jsVals[i]).doubleValue() < Double.MIN_VALUE
? EXCEPTION
: new Double( jsVals[i] )
)
));
/*
doSetterTest( "dt.setByte",
jsVals[i],
"dt.getByte",
"dt.PUB_BYTE",
(Number) new Byte(new Float(jsVals[i]).byteValue()),
new Float (Byte.MAX_VALUE),
new Float (Byte.MIN_VALUE));
doSetterTest( "dt.setShort",
jsVals[i],
"dt.getShort",
"dt.PUB_SHORT",
(Number) new Short(new Double(jsVals[i]).shortValue()),
new Float (Short.MAX_VALUE),
new Float (Short.MIN_VALUE ));
doSetterTest( "dt.setInteger",
jsVals[i],
"dt.getInteger",
"dt.PUB_INT",
(Number) new Integer(new Double(jsVals[i]).intValue()),
new Float (Integer.MAX_VALUE),
new Float (Integer.MIN_VALUE));
doSetterTest( "dt.setFloat",
jsVals[i],
"dt.getFloat",
"dt.PUB_FLOAT",
(Number) new Float(new Double(jsVals[i]).floatValue()),
new Float (Float.MAX_VALUE),
new Float (Float.MIN_VALUE));
doSetterTest( "dt.setLong",
jsVals[i],
"dt.getLong",
"dt.PUB_LONG",
(Number) new Long(new Double(jsVals[i]).longValue()),
new Float (Long.MAX_VALUE),
new Float (Long.MIN_VALUE));
*/
}
}
/**
* This tests calls a Java setter method from JavaScript. It verifies
* that the setter was called properly in two ways: by checking the
* return value of the getter method, and by checking the value of the
* public field that was set.
*
* @param setter java method that takes an argument, and sets a value
* @param jsValue JavaScript value that is passed to the setter
* @param getter java method that returns the value set by setter
* @param field java field that setter changed
* @param eResult expected result, which should be of some Number type
*/
public void doSetterTest( String jsValue, String setter, String getter,
String field, Object eResult )
{
String setMethod = setter +"(" + jsValue +");";
String getMethod = getter + "();";
String setterResult = "No exception thrown";
Double getterResult = null;
Double fieldResult = null;
Object expectedResult = null;
if ( eResult.getClass().equals(Class.forName("java.lang.String")) ) {
try {
global.eval( setMethod );
} catch ( Exception e ) {
setterResult = EXCEPTION;
file.exception = e.toString();
e.printStackTrace();
} finally {
addTestCase(
setMethod +" should throw a JSException",
EXCEPTION,
setterResult,
file.exception );
}
} else {
try {
// From JavaScript, call the setter
global.eval( setMethod );
// From JavaScript, call the getter
getterResult = (Double) global.eval( getMethod );
// From JavaSript, access the field
fieldResult = (Double) global.eval( field );
} catch ( Exception e ) {
e.printStackTrace();
file.exception = e.toString();
} finally {
addTestCase(
"[value: " + getterResult +"; expected: " + expectedResult +"] "+
setMethod + getMethod + "( " + expectedResult +").equals(" + getterResult +")",
"true",
expectedResult.equals(getterResult) +"",
file.exception );
addTestCase(
"[value: " + fieldResult +"; expected: " + expectedResult +"] "+
setMethod + field +"; (" + expectedResult +").equals(" + fieldResult +")",
"true",
expectedResult.equals(fieldResult) +"",
file.exception );
}
}
}
String EXCEPTION = "JSException expected";
}

Просмотреть файл

@ -0,0 +1,75 @@
package com.netscape.javascript.qa.liveconnect.datatypes;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Given a Java class that has a method and field with the same identifier,
* attempt to call the method and get the value of the field.
*
* @see com.netscape.javascript.qa.liveconnect.DataTypesClass#amIAFieldOrAMethod
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class DataTypes_018 extends LiveConnectTest {
public DataTypes_018() {
super();
}
public static void main( String[] args ) {
DataTypes_018 test = new DataTypes_018();
test.start();
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
global.eval( "var DT = "+
"Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass");
global.eval( "var dt = new DT();" );
file.bugnumber ="301981";
p( "BUGNUMBER: " + file.bugnumber );
}
public void executeTest() {
p( "executing test" );
String expectedFieldValue = "FIELD!";
String expectedMethodValue = "METHOD!";
String actualFieldValue;
String actualMethodValue;
String ambiguousReference = "amIAFieldOrAMethod";
try {
// From JavaScript, call the setter
actualFieldValue =
(String) global.eval( "dt." + ambiguousReference );
actualMethodValue =
(String) global.eval( "dt." + ambiguousReference +"()" );
} catch ( Exception e ) {
e.printStackTrace();
file.exception = e.toString();
actualFieldValue = "";
actualMethodValue= "";
}
addTestCase(
"dt." + ambiguousReference,
expectedFieldValue,
actualFieldValue,
file.exception );
addTestCase(
"dt." + ambiguousReference +"()",
expectedMethodValue,
actualMethodValue,
file.exception );
}
}

Просмотреть файл

@ -0,0 +1,102 @@
package com.netscape.javascript.qa.liveconnect.datatypes;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Get the string and number values of a Java object that overrides the
* default toString and toNumber methods.
*
* @see com.netscape.javascript.qa.liveconnect.DataTypesClass
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class DataTypes_019 extends LiveConnectTest {
public DataTypes_019() {
super();
}
public static void main( String[] args ) {
DataTypes_019 test = new DataTypes_019();
test.start();
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
global.eval( "var DT = "+
"Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass");
global.eval( "var dt = new DT();" );
file.bugnumber = "302019";
}
public void executeTest() {
String expectedStringValue = DataTypeClass.PUB_STRING_REPRESENTATION;
int expectedNumberValue = DataTypeClass.PUB_NUMBER_REPRESENTATION;
double expectedDoubleValue = DataTypeClass.PUB_DOUBLE_REPRESENTATION;
String actualStringValue = "";
double actualNumberValue = 0;
double actualDoubleValue = 0;
String jsString = "";
double jsNumber = 0;
try {
actualStringValue =
(String) global.eval( "dt.toString()");
actualNumberValue =
((Double) global.eval( "dt.toNumber()")).doubleValue();
actualDoubleValue =
((Double) global.eval( "dt.doubleValue()")).doubleValue();
jsString =
(String) global.eval( "var jsString = String(dt); jsString" );
jsNumber =
((Double) global.eval("var jsNumber = Number(dt); jsNumber")).doubleValue();
} catch ( Exception e ) {
e.printStackTrace();
file.exception = e.toString();
}
addTestCase(
"dt.toString()",
expectedStringValue,
actualStringValue,
file.exception );
addTestCase(
"[actualNumberValue: " + expectedNumberValue+"] "+
"dt.toNumber(); " + expectedNumberValue+ " == " +actualNumberValue,
"true",
(expectedNumberValue==actualNumberValue) +"",
file.exception );
addTestCase(
"[actualDoubleValue: " + expectedDoubleValue+"] "+
"dt.doubleValue(); " + expectedDoubleValue+ " == " +actualDoubleValue,
"true",
(expectedDoubleValue == actualDoubleValue) +"",
file.exception );
addTestCase(
"global.eval( \"var jsString = String(dt); jsString\" ); "+
"jsString.equals(" + expectedStringValue +")",
"true",
jsString.equals(expectedStringValue) +"",
file.exception );
addTestCase (
"[jsNumber: " + jsNumber+"] "+
"global.eval( \"var jsNumber = Number(dt); jsNumber\" ); "+
"jsNumber == " + expectedDoubleValue ,
"true",
(jsNumber == expectedDoubleValue) +"",
file.exception );
}
}

Просмотреть файл

@ -0,0 +1,51 @@
package com.netscape.javascript.qa.liveconnect.exception;
import com.netscape.javascript.qa.liveconnect.*;
import netscape.javascript.JSObject;
import netscape.javascript.JSException;
/**
* Evaluate a string that should cause a JavaScript exception. Verify
* that an exception was thrown, and get the exception message.
*
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class Exception_001 extends LiveConnectTest {
public Exception_001() {
super();
}
public static void main( String[] args ) {
Exception_001 test = new Exception_001();
test.start();
}
public void executeTest() {
String result = "No exception thrown.";
try {
// the following statement should throw a JavaScript exception,
// since foo is not defined
global.eval( "foo.bar = 999;" );
} catch (Exception e) {
if ( e instanceof JSException ) {
result = "JSException thrown!";
} else {
result = "Some random exception thrown!";
}
file.exception = e.toString();
e.printStackTrace();
} finally {
addTestCase(
"global.eval(\"foo.bar = 999\") should throw a JavaScript exception:",
"JSException thrown!",
result,
file.exception );
}
}
}

Просмотреть файл

@ -0,0 +1,103 @@
package com.netscape.javascript.qa.liveconnect.jsobject;
import netscape.javascript.*;
import com.netscape.javascript.qa.liveconnect.LiveConnectTest;
/**
* Try to get properties of the global object. This test verifies that
* getMember can access default properties of the global object, and that
* the Object returned is an instance of netscape.javascript.JSObject
* for objects, and java.lang.Double for numbers (NaN, Infinity).
*
* @see com.netscape.javascript.qa.liveconnect.LiveConnectTest
*
* @author christine@netscape.com
*
*/
public class JSObject_001 extends LiveConnectTest {
public JSObject_001() {
super();
}
public static void main( String[] args ) {
JSObject_001 test = new JSObject_001();
test.start();
}
public void executeTest() {
getDouble( "NaN" );
getDouble( "Infinity" );
getJSObject( "parseInt" );
getJSObject( "parseFloat" );
getJSObject( "eval" );
getJSObject( "escape" );
getJSObject( "unescape" );
getJSObject( "isNaN" );
getJSObject( "isFinite" );
getJSObject( "Object" );
getJSObject( "Function" );
getJSObject( "Array" );
getJSObject( "String" );
getJSObject( "Boolean" );
getJSObject( "Number" );
getJSObject( "Date" );
getJSObject( "Math" );
}
/**
* Try to get a property of the JavaScript Global object. The
* type of this property should be a java.lang.Double. If it
* is not, the test will fail with a java.lang.ClassCastException.
*
* @param property name of the JavaScript property to get.
*/
public void getDouble( String property ) {
Object jsobject = null;
String exception = null;
String identifier = this.getClass().toString();
String description = "Object jsobject = global.getMember(\""+
property +"\"); jsobject instanceof java.lang.Double ";
try {
jsobject = global.getMember( property );
} catch ( Exception e ) {
exception = ("Exception getting " + property +": "+ e.toString());
System.err.println( exception );
}
String expect = "true";
String actual = (jsobject instanceof java.lang.Double) +"";
addTestCase( description, expect, actual, exception );
}
/**
* Try to get a property of the JavaScript Global object. The type of
* this property should be a netscape.javascript.JSObject. If it is not,
* the test will fail with a java.lang.ClassCastException.
*
* @param property name of the JavaScript property to get.
*/
public void getJSObject( String property ) {
Object jsobject = null;
String exception = null;
String identifier = this.getClass().toString();
String description = "Object jsobject = global.getMember(\""+
property +"\"); jsobject instanceof JSObject ";
try {
jsobject = global.getMember( property );
} catch ( Exception e ) {
exception = ("Exception getting " + property +": "+ e.toString());
System.err.println( exception );
}
String expect = "true";
String actual = (jsobject instanceof JSObject) +"";
addTestCase( description, expect, actual, exception );
}
}

Просмотреть файл

@ -0,0 +1,205 @@
package com.netscape.javascript.qa.liveconnect.member;
import com.netscape.javascript.qa.liveconnect.*;
import netscape.javascript.*;
/**
* Create JavaScript objects, and set their properties to a Java object or
* JSObject using setMember. Verify the values of the properties using
* getMember.
*
* @see netscape.javascript.JSObject
* @see com.netscape.javascript.qa.liveconnect.datatypes.DataTypes_003
* @see com.netscape.javascript.qa.liveconnect.datatypes.DataTypes_004
*
* @author christine m begle
*/
public class Member_001 extends LiveConnectTest {
public Member_001() {
super();
}
public static void main( String[] args ) {
Member_001 test = new Member_001();
test.start();
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
}
public void executeTest() {
Object data[] = getDataArray();
for ( int i = 0; i < data.length; i++ ) {
JSObject jsObject = getJSObject( (Object[]) data[i] );
// get the initial value of the property
getMember( jsObject, (Object[]) data[i], ((Object[]) data[i])[4] );
// set the value of the property
setMember( jsObject, (Object[]) data[i] );
// verify the value of the property
getMember( jsObject, (Object[]) data[i], ((Object[]) data[i])[5] );
}
}
public JSObject getJSObject( Object[] data ) {
return (JSObject) global.eval( data[0] +" = " + data[1] );
}
/**
* Get the data array, which is an object array data arrays, which are
* also object arrays. The data arrays consist of 3 items
*
* <ul>
* <li> String passed to global.eval to create the "this" object for setMember
* <li> String property of the JSObject to get or set
* <li> Object new value of the property (pass to setMember, and expect
* <li> Object value of the property before setting it (expected result from getMember)
* <li> String representation of the property, as retrieved by getMember
* <li> String class name of the property as retrieved by getMember
* <li> String typeof as determined by JavaScript
* </ul>
*
* To add test cases to this test, modify this method.
*
* @return the data array.
*/
public Object[] getDataArray() {
Object d0[] = {
new String( "d0" ), // 0 identifier
new String( "new Boolean()"), // 1 assignment expression
new String( "foo" ), // 2 property
new String( "bar" ), // 3 value to assign
new String( "undefined" ), // 4 initial value
new String( "bar" ), // 5 value after assignment
"java.lang.String", // 6 class of property
new String( "object") // 7 JS typeof value
};
Object d1[] = {
new String( "d1" ), // 0 identifier
new String( "new String(\"JavaScript\")"), // 1 assignment expression
new String( "foo" ), // 2 property
new Boolean( "true" ), // 3 value to assign
new String( "undefined" ), // 4 initial value
new Boolean( "true" ), // 5 value after assignment
"java.lang.Boolean", // 6 class of property
new String( "object") // 7 JS typeof value
};
Object d2[] = {
new String( "d2" ), // 0 identifier
new String( "new Number(12345)"), // 1 assignment expression
new String( "foo" ), // 2 property
new Double( "0.2134" ), // 3 value to assign
new String( "undefined" ), // 4 initial value
new Double( "0.2134" ), // 5 value after assignment
"java.lang.Double", // 6 class of property
new String( "object") // 7 JS typeof value
};
Object d3[] = {
new String( "d3" ), // 0 identifier
new String( "new Number(12345)"), // 1 assignment expression
new String( "foo" ), // 2 property
new Integer( "987654" ), // 3 value to assign
new String( "undefined" ), // 4 initial value
new Integer( "987654" ), // 5 value after assignment
"java.lang.Integer", // 6 class of property
new String( "object") // 7 JS typeof value
};
Object d4[] = {
new String( "d4" ),
new String ( "new Object()" ),
new String( "property" ),
global,
new String( "undefined" ),
global,
"netscape.javascript.JSObject",
new String ( "object" )
};
Object dataArray[] = { d0, d1, d3, d4 };
return dataArray;
}
/**
* Get the value of a JavaScript property. Check its class.
*
*
*/
public void getMember( JSObject theThis, Object[] data, Object value ) {
String exception = "";
String property = (String) data[2];
Object eValue = value;
Object aValue = null;
Class eClass = null;
Class aClass = null;
try {
aValue = theThis.getMember( property );
if ( aValue != null ) {
eClass = eValue.getClass();
aClass = aValue.getClass();
}
} catch ( Exception e ) {
exception = theThis +".getMember( " + property + " ) threw " +
e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
if ( aValue == null ) {
} else {
// check the value of the property
addTestCase(
"[ getMember returned " + aValue +" ] "+
data[0]+".getMember( " +property+" ).equals( "+eValue+" )",
"true",
aValue.equals(eValue) +"",
exception );
// check the class of the property
addTestCase (
"[ "+ aValue+".getClass() returned "+aClass.getName()+"] "+
aClass.getName() +".equals( " +eClass.getName() +" )",
"true",
aClass.getName().equals(eClass.getName()) +"",
exception );
//
}
}
}
/**
* Set the value of a JavaScript property.
*
*/
public void setMember( JSObject theThis, Object[] data ) {
String exception = "";
String result = "passed";
String property = (String) data[2];
Object value = data[3];
try {
theThis.setMember( property, value );
} catch ( Exception e ) {
result = "failed!";
exception = "("+ theThis+").setMember( " + property +","+ value +" ) "+
"threw " + e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
addTestCase(
"("+theThis+").setMember( "+property +", "+ value +" )",
"passed",
result,
exception );
}
}
}

Просмотреть файл

@ -0,0 +1,269 @@
package com.netscape.javascript.qa.liveconnect.member;
import com.netscape.javascript.qa.liveconnect.*;
import netscape.javascript.*;
/**
* Create JavaScript objects, and set their properties to a JavaScript object
* using eval or call. Verify the values of the properties using getMember.
*
* @see netscape.javascript.JSObject
* @see com.netscape.javascript.qa.liveconnect.datatypes.DataTypes_003
* @see com.netscape.javascript.qa.liveconnect.datatypes.DataTypes_004
*
* @author christine m begle
*/
public class Member_002 extends LiveConnectTest {
public Member_002() {
super();
}
public static void main( String[] args ) {
Member_002 test = new Member_002();
test.start();
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
}
public void executeTest() {
Object data[] = getDataArray();
for ( int i = 0; i < data.length; i++ ) {
JSObject jsObject = getJSObject( (Object[]) data[i] );
setMember( (Object[]) data[i] );
getMember( jsObject, (Object[]) data[i] );
removeMember( jsObject, (Object[]) data[i] );
}
}
/**
* Create and return a JSObject using data in the data array.
*
* @param data Object array containing name of JSObject, and assignment
* expression
* @return the JSObject
*/
public JSObject getJSObject( Object[] data ) {
String constructor = data[0] +" = " + data[1];
JSObject theThis = (JSObject) global.eval( constructor );
return theThis;
}
/**
* Use JSObject.eval to assign a JavaScript value to a property of a
* JavaScript object. Verify that the expression returns the value of
* the assignment expression.
*
* @param data Object array that has items corresponding to the name of
* a JSObject, a property of that object, and a JavaScript assignment
* expression for that property.
*/
public void setMember( Object[] data ) {
Object result = null;
String evalString = (String) data[0] + "." + (String) data[2] +" = "+
(String) data[3];
try {
result = global.eval( evalString );
} catch ( Exception e ) {
exception = evalString + " threw " + e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
addTestCase(
"[ " + evalString+ " returned "+result+" ] " +
result +".equals( " + data[5] +")",
"true",
result.equals(data[5]) +"",
exception );
}
}
/**
* Get the value of a JavaScript property. Check its type and value.
*
* @param theThis JSObject whose property will be checked
* @param data Object array containing the name of the JSObject property
* and the expected value of that property.
*/
public void getMember( JSObject theThis, Object[] data ) {
String exception = null;
String property = (String) data[2];
Object eValue = data[6];
Object aValue = null;
Class eClass = null;
Class aClass = null;
String eType = (String) data[7];
String aType = null;
try {
aValue = theThis.getMember( property );
if ( aValue != null ) {
eClass = eValue.getClass();
aClass = aValue.getClass();
aType = (String) global.eval( "typeof " + ((String) data[0]) +
"." + ((String) data[2]) );
}
} catch ( Exception e ) {
exception = theThis +".getMember( " + property + " ) threw " +
e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
if ( aValue == null ) {
} else {
// check the value of the property
addTestCase(
"[ getMember returned " + aValue +" ] "+
theThis+".getMember( " +property+" ).equals( "+eValue+" )",
"true",
aValue.equals(eValue) +"",
exception );
// check the class of the property
addTestCase (
"[ "+ aValue+".getClass() returned "+aClass.getName()+"] "+
aClass.getName() +".equals( " +eClass.getName() +" )",
"true",
aClass.getName().equals(eClass.getName()) +"",
exception );
// check the JS type of the property value
addTestCase(
"[ typeof " +aValue +" returned " + aType +" ] "+
aType +" .equals( " +eType + " )",
"true",
aType.equals( eType ) +"",
exception );
}
}
}
/**
* Delete a JSObject using JSObject.removeMember. After removing the
* member, check the member's JavaScript value and type.
*
*
*
*
*/
public void removeMember( JSObject theThis, Object[] data ) {
String exception = null;
String property = (String) data[2];
Object eValue = data[8];
Object aValue = null;
Class eClass = null;
Class aClass = null;
String eType = (String) data[9];
String aType = null;
try {
theThis.removeMember( property );
aValue = theThis.getMember( property );
if ( aValue != null ) {
eClass = eValue.getClass();
aClass = aValue.getClass();
aType = (String) global.eval( "typeof " + ((String) data[0]) +
"." + ((String) data[2]) );
}
} catch ( Exception e ) {
exception = theThis +".getMember( " + property + " ) threw " +
e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
if ( aValue == null ) {
} else {
// check the value of the property
addTestCase(
"[ after removing, getMember returned " + aValue +" ] "+
theThis+".getMember( " +property+" ).equals( "+eValue+" )",
"true",
aValue.equals(eValue) +"",
exception );
// check the class of the property
addTestCase (
"[ after removing, "+ aValue+".getClass() returned "+aClass.getName()+"] "+
aClass.getName() +".equals( " +eClass.getName() +" )",
"true",
aClass.getName().equals(eClass.getName()) +"",
exception );
// check the JS type of the property value
addTestCase(
"[ after removing, typeof " +aValue +" returned " + aType +" ] "+
aType +" .equals( " +eType + " )",
"true",
aType.equals( eType ) +"",
exception );
}
}
}
/**
* Get the data array, which is an object array data arrays, which are
* also object arrays. The data arrays consist of 8 items
*
* <ul>
* <li> Identifier for JavaScript object
* <li> Assignment expression to initialize JavaScript object
* <li> Property of JavaScript object to set / get
* <li> Value to assign to property
* <li> Initial value of property
* <li> Value of property before calling setMember
* <li> Value returned by setMember
* <li> Value of property after calling setMember
* <li> String typeof as determined by JavaScript
* </ul>
*
* To add test cases to this test, modify this method.
*
* @return the data array.
*/
public Object[] getDataArray() {
Object d0[] = {
new String( "boo" ), // 0 identifier
new String( "new Boolean()"), // 1 assignment expression
new String( "foo" ), // 2 property
new String( "\"bar\"" ), // 3 JavaScript value to assign
new String( "undefined" ), // 4 value before assignment
new String( "bar" ), // 5 value returned by setter
new String( "bar" ), // 6 value after assignment
new String( "string"), // 7 JS typeof value
new String( "undefined"), // 8 value after removing
new String( "undefined") // 9 typeof after removing
};
Object d1[] = {
new String( "num" ),
new String( "new Number(12345)" ),
new String( "someProperty" ),
new String( ".02134" ),
new String( "undefined" ),
new Double ( "0.02134"),
new Double ( "0.02134"),
new String ("number"),
new String( "undefined"), // 8 value after removing
new String( "undefined") // 9 typeof after removing
};
Object d2[] = {
new String( "number" ),
new String( "Number" ),
new String( "POSITIVE_INFINITY" ),
new String( "0" ),
new Double( Double.POSITIVE_INFINITY ),
new Double("0" ),
new Double( Double.POSITIVE_INFINITY ),
new String( "number" ) ,
new Double( Double.POSITIVE_INFINITY ),
new String( "number" )
};
Object dataArray[] = { d0, d1, d2 };
return dataArray;
}
}

Просмотреть файл

@ -0,0 +1,239 @@
package com.netscape.javascript.qa.liveconnect.slot;
import netscape.javascript.*;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Create a JS Array. Get the length of the array. Get the members of the
* array using JSObject.getSlot. Set the members of the array using
* JSObject.setSlot. Get the members of the array again using getSlot.
*
* This covers the following JavaScript -> Java cases through getSlot:
* <table border = 1>
* <tr>
* <th> JavaScript type
* <th> Java type
* </tr>
* <tr>
* <td> number
* <td> java.lang.Double
* </tr>
* <tr>
* <td> string
* <td> java.lang.String
* </tr>
* <tr>
* <td> boolean
* <td> java.lang.Boolean
* </tr>
* <tr>
* <td> null
* <td> null
* </tr>
* <tr>
* <td> JavaObject
* <td> the unwrapped original java object (use ==, not .equals() )
* </tr>
* <tr>
* <th colspan=2> Not covered in this test
* </tr>
* <tr>
* <td> JavaScript object
* <td> netscape.javascript.JSObject
* </tr>
* </table>
*
* @see netscape.javascript.JSObject#getSlot
* @see netscape.javascript.JSObject#setSlot
*
* @author christine m begle
*/
public class Slot_001 extends LiveConnectTest {
public Slot_001() {
super();
}
public static void main( String[] args ) {
Slot_001 test = new Slot_001();
test.start();
}
// The structure of the arrays is the array expression followed by
// a list of java objects, correctly typed for what we expect to get
// back from getSlot. testMatrix is an array of arrays.
Object test1[] = { new String("null"), null };
Object test2[] = { new String( "" ) };
Object test3[] = { new String("true,\"hi\",3.14159"),
new Boolean(true), new String("hi"), new Double("3.14159") };
Object test4[] = { new String( "new java.lang.Boolean(true), " +
"new java.lang.String(\"hello\"), java.lang.System.out, "+
"new java.lang.Integer(5)"),
new Boolean(true),
new String("hello"),
System.out,
new Integer(5) };
Object testMatrix[] = { test1, test2, test3, test4 };
public void executeTest() {
for ( int i = 0; i < testMatrix.length; i++ ) {
String args = (String) ((Object[]) testMatrix[i])[0];
JSObject jsArray = createJSArray( args );
// get the length of the array using JSObject.getMember
int javaLength = ((Object[]) testMatrix[i]).length -1;
getLength( jsArray, javaLength );
for ( int j = 0; j < javaLength ; j++ ) {
getSlot( jsArray, j, ((Object[]) testMatrix[i])[j+1] );
}
}
}
/**
* Create a JavaScript Array named jsArray.
*
* @param newArrayArguments string containing a list of arguments for the
* JavaScript Array constructor
*
* @return the JSObject array object
*/
public JSObject createJSArray( String newArrayArguments ) {
JSObject jsArray = null;
String args = "var jsArray = new Array( " + newArrayArguments +" )";
String result = "passed!";
try {
System.out.println( args );
global.eval( args );
jsArray = (JSObject) global.getMember("jsArray");
} catch ( Exception e ) {
result = "failed!";
exception = "global.getMember(\"jsArray\")"+
"threw " + e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
addTestCase(
"global.eval(\"var jsArray = "+
"new Array(\""+newArrayArguments+"\"); " +
"JSObject jsArray = (JSObject) global.getMember(\"jsArray\")",
"passed!",
result,
exception );
}
return jsArray;
}
/**
* Use JSObject.getMember to get the length property of a JSObject.
*
* @param jsArray a JSObject with a property named "length"
* @param javaLength the expected length of the JSObject
*/
public void getLength( JSObject jsArray, int javaLength ) {
String exception = "";
int jsLength = 0;
try {
jsLength = ((Double) jsArray.getMember("length")).intValue();
} catch ( Exception e ) {
exception = "jsArray.getMember(\"length\") threw "+
e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
addTestCase(
"[length is " + jsLength +"] "+
"( jsArray.getMember(\"length\")).intValue() == " +
javaLength +" )",
"true",
(jsLength == javaLength) + "",
exception );
}
}
/**
* Use JSObject.getSlot to get an indexed member of a JSObject.
*
* @param jsArray the JSObject with indexed members
* @param slot the index property to retrieve
* @param javaValue a java object whose type and value are what we
* expect jsArray.getSlot(slot) to return.
*/
public void getSlot( JSObject jsArray, int slot, Object javaValue ) {
String exception = "";
Object result = null;
Class eClass = null;
Class aClass = null;
try {
result = jsArray.getSlot( slot );
if ( javaValue != null ) {
eClass = javaValue.getClass();
aClass = result.getClass();
}
} catch ( Exception e ) {
exception = "jsArray.getSlot( " + slot + " ) "+
"threw " + e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
if ( javaValue == null ) {
addTestCase(
"[jsArray.getSlot(" + slot +") returned " + result +"] "+
"( " +javaValue +" == " + result +" )",
"true",
(javaValue == result ) +"",
exception );
} else {
addTestCase(
"[jsArray.getSlot(" + slot +") returned " + result +"] "+
javaValue +".equals( " + result +" ) ",
"true",
javaValue.equals( result ) +"",
exception );
addTestCase(
"( " + eClass +".equals( " + aClass +" ) )",
"true",
eClass.equals( aClass ) +"",
exception );
}
}
}
/**
* JSObject.setSlot returns undefined. This just verifies that we can
* call setSlot without throwing an exception.
*
* @param jsArray the JSObject on which setSlot will be called
* @param slot the indexed member that will be set
* @param javaValue the value to set the indexed member
*/
public void setSlot( JSObject jsArray, int slot, Object javaValue ) {
String exception = null;
String result = "passed!";
try {
jsArray.setSlot( slot, javaValue );
} catch ( Exception e ) {
result = "failed!";
exception = "jsArray.setSlot( " + slot +","+ javaValue +") "+
"threw " + e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
addTestCase(
"jsArray.setSlot( " + slot +", "+ javaValue +")",
"passed!",
result,
exception );
}
}
}

Просмотреть файл

@ -0,0 +1,270 @@
package com.netscape.javascript.qa.liveconnect.slot;
import netscape.javascript.*;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Create a JS Array. Get the length of the array. Get the members of the
* array using JSObject.getSlot. Set the members of the array using
* JSObject.setSlot. Get the members of the array again using getSlot.
*
* This covers the following JavaScript -> Java cases through getSlot:
* <table border = 1>
* <tr>
* <th> JavaScript type
* <th> Java type
* </tr>
* <tr>
* <td> JavaScript object
* <td> netscape.javascript.JSObject
* </tr>
* </table>
*
* @see netscape.javascript.JSObject#getSlot
* @see netscape.javascript.JSObject#setSlot
*
* @author christine m begle
*/
public class Slot_002 extends LiveConnectTest {
public Slot_002() {
super();
}
public static void main( String[] args ) {
Slot_002 test = new Slot_002();
test.start();
}
public void executeTest() {
getBaseObjects();
Object testMatrix[] = getDataArray();
String args = getArrayArguments( testMatrix );
JSObject jsArray = createJSArray( args );
getLength( jsArray, testMatrix.length );
for ( int i = 0; i < testMatrix.length; i++ ) {
getSlot( jsArray, i, (Object[]) testMatrix[i] );
}
}
public String getArrayArguments( Object[] matrix ) {
StringBuffer buffer = new StringBuffer();
for ( int i = 0; i < matrix.length; i++ ) {
buffer.append( ((Object[]) matrix[i]) [0] );
if ( i < matrix.length -1 ) {
buffer.append( ", " );
}
}
return buffer.toString();
}
public JSObject jsNumber;
public JSObject jsFunction;
public JSObject jsBoolean;
public JSObject jsObject;
public JSObject jsString;
public JSObject jsMath;
public JSObject jsDate;
public JSObject jsArray;
public JSObject jsRegExp;
/**
* Get the constructor of all the base JavaScript objects. The test
* will compare the instance constructor to the base object constructor
* to verify that the JavaScript type of the object is corret.
*
*/
public boolean getBaseObjects() {
try {
jsNumber = (JSObject) global.eval( "Number.prototype.constructor" );
jsString = (JSObject) global.eval( "String.prototype.constructor" );
jsFunction = (JSObject) global.eval( "Function.prototype.constructor" );
jsBoolean = (JSObject) global.eval( "Boolean.prototype.constructor" );
jsObject = (JSObject) global.eval( "Object.prototype.constructor" );
jsMath = (JSObject) global.eval("Math");
jsDate = (JSObject) global.eval( "Date.prototype.constructor" );
jsArray = (JSObject) global.eval( "Array.prototype.constructor" );
jsRegExp = (JSObject) global.eval("RegExp.prototype.constructor");
} catch ( Exception e ) {
System.err.println( "Failed in getBaseObjects: " + e.toString() );
e.printStackTrace();
return false;
}
return true;
}
/**
* Get the data array, which is an array of arrays. Each of the internal
* arrays consists of three objects: a string whose value will be passed
* to the JavaScript array constructor; a String which is the expected
* string value of retreiving the JSObject via getSlot; and a JSObject,
* which is the JSObject's constructor, that allows us to verify the type
* of JSObject.
*
* @return the data array.
*/
public Object[] getDataArray() {
Object item0[] = {
new String("new String(\"JavaScript String\")"),
new String ("JavaScript String"),
jsString };
Object item1[] = {
new String( "new Number(12345)" ),
new String( "12345" ),
jsNumber };
Object item2[] = {
new String( "new Boolean(false)" ),
new String( "false" ),
jsBoolean };
Object item3[] = {
new String( "new Array(0,1,2,3,4)" ),
new String( "0,1,2,3,4" ),
jsArray };
Object item4[] = {
new String( "new Object()" ),
new String( "[object Object]" ),
jsObject };
Object dataArray[] = { item0, item1, item2, item3, item4 };
return dataArray;
}
/**
* Create a JavaScript Array named jsArray.
*
* @param newArrayArguments string containing a list of arguments for the
* JavaScript Array constructor
*
* @return the JSObject array object
*/
public JSObject createJSArray( String newArrayArguments ) {
JSObject jsArray = null;
String args = "var jsArray = new Array( " + newArrayArguments +" )";
String result = "passed!";
try {
System.out.println( args );
global.eval( args );
jsArray = (JSObject) global.getMember("jsArray");
} catch ( Exception e ) {
result = "failed!";
exception = "global.getMember(\"jsArray\")"+
"threw " + e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
addTestCase(
"global.eval(\"var jsArray = "+
"new Array(\""+newArrayArguments+"\"); " +
"JSObject jsArray = (JSObject) global.getMember(\"jsArray\")",
"passed!",
result,
exception );
}
return jsArray;
}
/**
* Use JSObject.getMember to get the length property of a JSObject.
*
* @param jsArray a JSObject with a property named "length"
* @param javaLength the expected length of the JSObject
*/
public void getLength( JSObject jsArray, int javaLength ) {
String exception = "";
int jsLength = 0;
try {
jsLength = ((Double) jsArray.getMember("length")).intValue();
} catch ( Exception e ) {
exception = "jsArray.getMember(\"length\") threw "+
e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
addTestCase(
"[length is " + jsLength +"] "+
"( jsArray.getMember(\"length\")).intValue() == " +
javaLength +" )",
"true",
(jsLength == javaLength) + "",
exception );
}
}
/**
* Use JSObject.getSlot to get an indexed member of a JSObject. In this
* test, the expected class of all objects is JSObject.
*
* @param jsArray the JSObject with indexed members
* @param slot the index property to retrieve
* @param data object array containing the string representation of the
* expected result of jsArray.getSlot(slot) and the JSObjectconstructor
* of the expected result, which allows us to verify the value and type
* of the result object.
*/
public void getSlot( JSObject jsArray, int slot, Object[] data ) {
String exception = "";
JSObject constructor = null;
JSObject result = null;
Class eClass = null;
Class aClass = null;
try {
result = (JSObject) jsArray.getSlot( slot );
if ( result != null ) {
eClass = Class.forName( "netscape.javascript.JSObject" );
aClass = result.getClass();
constructor = (JSObject) result.getMember( "constructor" );
}
} catch ( Exception e ) {
exception = "jsArray.getSlot( " + slot + " ) "+
"threw " + e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
if ( result == null ) {
addTestCase(
"[jsArray.getSlot(" + slot +").toString().trim() returned " + result +"] "+
"( " + data[1] +".equals( " + result +" )",
"true",
data[1].toString().trim().equals( result.toString() ) +"",
exception );
} else {
// check the string value of the result
/*
addTestCase(
"[jsArray.getSlot(" + slot +") returned " + result +"] "+
data[1] +".toString().equals( " + result +" ) ",
"true",
data[1].equals( result ) +"",
exception );
*/
// check the class of the result. all should be JSObjects.
addTestCase(
"( " + eClass +".equals( " + aClass +" ) )",
"true",
eClass.equals( aClass ) +"",
exception );
// constructor of the result
addTestCase(
"( " + constructor +".equals( " + data[2] +" ) )",
"true",
constructor.equals( data[2] ) +"",
exception );
}
}
}
}

Просмотреть файл

@ -0,0 +1,282 @@
package com.netscape.javascript.qa.liveconnect.slot;
import netscape.javascript.*;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Create a JS Array. Set the members of the array using JSObject.setSlot.
* Get the members of the array again using getSlot.
*
* This covers the following JavaScript -> Java cases through getSlot:
* <table border = 1>
* <tr>
* <th> Java type
* <th> JavaScript type
* </tr>
* <tr>
* <td> JSObject
* <td> the JavaScript object it refers to
* </tr>
* </table>
*
* @see netscape.javascript.JSObject#getSlot
* @see netscape.javascript.JSObject#setSlot
*
* @author christine m begle
*/
public class Slot_003 extends LiveConnectTest {
public Slot_003() {
super();
}
public static void main( String[] args ) {
Slot_003 test = new Slot_003();
test.start();
}
public void executeTest() {
getBaseObjects();
Object testMatrix[] = getDataArray();
JSObject jsArray = createJSArray();
getLength( jsArray, 0 );
for ( int i = 0; i < testMatrix.length; i++ ) {
setSlot( jsArray, i, (Object[]) testMatrix[i] );
getSlot( jsArray, i, (Object[]) testMatrix[i] );
}
getLength( jsArray, testMatrix.length );
}
public JSObject jsNumber;
public JSObject jsFunction;
public JSObject jsBoolean;
public JSObject jsObject;
public JSObject jsString;
public JSObject jsMath;
public JSObject jsDate;
public JSObject jsArray;
public JSObject jsRegExp;
/**
* Get the constructor of all the base JavaScript objects. The test
* will compare the instance constructor to the base object constructor
* to verify that the JavaScript type of the object is corret.
*
*/
public boolean getBaseObjects() {
try {
jsNumber = (JSObject) global.eval( "Number.prototype.constructor" );
jsString = (JSObject) global.eval( "String.prototype.constructor" );
jsFunction = (JSObject) global.eval( "Function.prototype.constructor" );
jsBoolean = (JSObject) global.eval( "Boolean.prototype.constructor" );
jsObject = (JSObject) global.eval( "Object.prototype.constructor" );
jsMath = (JSObject) global.eval("Math");
jsDate = (JSObject) global.eval( "Date.prototype.constructor" );
jsArray = (JSObject) global.eval( "Array.prototype.constructor" );
jsRegExp = (JSObject) global.eval("RegExp.prototype.constructor");
} catch ( Exception e ) {
System.err.println( "Failed in getBaseObjects: " + e.toString() );
e.printStackTrace();
return false;
}
return true;
}
/**
* Get the data array, which is an array of arrays. Each of the internal
* arrays consists of three objects: a string whose value will be passed
* to the JavaScript array constructor; a String which is the expected
* string value of retreiving the JSObject via getSlot; and a JSObject,
* which is the JSObject's constructor, that allows us to verify the type
* of JSObject.
*
* @return the data array.
*/
public Object[] getDataArray() {
Object item0[] = {
global.eval("new String(\"JavaScript String\")"),
new String ("JavaScript String"),
jsString };
Object item1[] = {
global.eval("new Number(12345)"),
new String( "12345" ),
jsNumber };
Object item2[] = {
global.eval("new Boolean(false)"),
new String( "false" ),
jsBoolean };
Object item3[] = {
global.eval("new Array(0,1,2,3,4)"),
new String( "0,1,2,3,4" ),
jsArray };
Object item4[] = {
global.eval("new Object()"),
new String( "[object Object]" ),
jsObject };
Object dataArray[] = { item0, item1, item2, item3, item4 };
return dataArray;
}
/**
* Create an empty JavaScript Array named jsArray.
*
* @return the JSObject array object
*/
public JSObject createJSArray() {
JSObject jsArray = null;
String args = "var jsArray = new Array()";
String result = "passed!";
try {
System.out.println( args );
global.eval( args );
jsArray = (JSObject) global.getMember("jsArray");
} catch ( Exception e ) {
result = "failed!";
exception = "global.getMember(\"jsArray\")"+
"threw " + e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
addTestCase(
"global.eval(\"var jsArray = "+
"new Array(); " +
"JSObject jsArray = (JSObject) global.getMember(\"jsArray\")",
"passed!",
result,
exception );
}
return jsArray;
}
/**
* Use JSObject.getMember to get the length property of a JSObject.
*
* @param jsArray a JSObject with a property named "length"
* @param javaLength the expected length of the JSObject
*/
public void getLength( JSObject jsArray, int javaLength ) {
String exception = "";
int jsLength = 0;
try {
jsLength = ((Double) jsArray.getMember("length")).intValue();
} catch ( Exception e ) {
exception = "jsArray.getMember(\"length\") threw "+
e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
addTestCase(
"[length is " + jsLength +"] "+
"( jsArray.getMember(\"length\")).intValue() == " +
javaLength +" )",
"true",
(jsLength == javaLength) + "",
exception );
}
}
/**
* Use JSObject.getSlot to get an indexed member of a JSObject. In this
* test, the expected class of all objects is JSObject.
*
* @param jsArray the JSObject with indexed members
* @param slot the index property to retrieve
* @param data object array containing the string representation of the
* expected result of jsArray.getSlot(slot) and the JSObjectconstructor
* of the expected result, which allows us to verify the value and type
* of the result object.
*/
public void getSlot( JSObject jsArray, int slot, Object[] data ) {
String exception = "";
JSObject constructor = null;
JSObject result = null;
Class eClass = null;
Class aClass = null;
try {
result = (JSObject) jsArray.getSlot( slot );
if ( result != null ) {
eClass = Class.forName( "netscape.javascript.JSObject" );
aClass = result.getClass();
constructor = (JSObject) result.getMember( "constructor" );
}
} catch ( Exception e ) {
exception = "jsArray.getSlot( " + slot + " ) "+
"threw " + e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
if ( result == null ) {
addTestCase(
"[jsArray.getSlot(" + slot +").toString().trim() returned " + result +"] "+
"( " + data[1] +".equals( " + result +" )",
"true",
data[1].toString().trim().equals( result.toString() ) +"",
exception );
} else {
// check the string value of the result
addTestCase(
"[jsArray.getSlot(" + slot +") returned " + result +"] "+
data[1] +".toString().equals( " + result +" ) ",
"true",
data[1].equals( result.toString() ) +"",
exception );
// check the class of the result. all should be JSObjects.
addTestCase(
"( " + eClass +".equals( " + aClass +" ) )",
"true",
eClass.equals( aClass ) +"",
exception );
// check the constructor of the result
addTestCase(
"( " + constructor +".equals( " + data[2] +" ) )",
"true",
constructor.equals( data[2] ) +"",
exception );
}
}
}
/**
* JSObject.setSlot returns undefined. This just verifies that we can
* call setSlot without throwing an exception.
*
* @param jsArray the JSObject on which setSlot will be called
* @param slot the indexed member that will be set
* @param javaValue the value to set the indexed member
*/
public void setSlot( JSObject jsArray, int slot, Object[] data ) {
String exception = null;
String result = "passed!";
try {
jsArray.setSlot( slot, (Object) data[0] );
} catch ( Exception e ) {
result = "failed!";
exception = "jsArray.setSlot( " + slot +","+ data[0] +") "+
"threw " + e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
addTestCase(
"jsArray.setSlot( " + slot +", "+ data[0] +")",
"passed!",
result,
exception );
}
}
}

Просмотреть файл

@ -0,0 +1,229 @@
package com.netscape.javascript.qa.liveconnect.slot;
import netscape.javascript.*;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Create a JavaScript array. Set an indexed member of the array. Get an
* indexed member of the array.
*
* This covers the following JavaScript -> Java cases through getSlot:
* <table border = 1>
* <tr>
* <th> Java type
* <th> JavaScript type
* </tr>
* <tr>
* <td> Java Object
* <td> JavaScript JavaObject
* </tr>
* </table>
*
* @see netscape.javascript.JSObject#getSlot
* @see netscape.javascript.JSObject#setSlot
*
* @author christine m begle
*/
public class Slot_004 extends LiveConnectTest {
public Slot_004() {
super();
}
public static void main( String[] args ) {
Slot_004 test = new Slot_004();
test.start();
}
public void executeTest() {
Object testMatrix[] = getDataArray();
JSObject jsArray = createJSArray();
getLength( jsArray, 0 );
for ( int i = 0; i < testMatrix.length; i++ ) {
setSlot( jsArray, i, (Object[]) testMatrix[i] );
getSlot( jsArray, i, (Object[]) testMatrix[i] );
}
getLength( jsArray, testMatrix.length );
}
/**
* Get the data array, which is an array of arrays. Each of the internal
* arrays consists of three objects: a string whose value will be passed
* to the JavaScript array constructor; a String which is the expected
* string value of retreiving the JSObject via getSlot; and a JSObject,
* which is the JSObject's constructor, that allows us to verify the type
* of JSObject.
*
* @return the data array.
*/
public Object[] getDataArray() {
Object item0[] = {
new String("Java String"),
new String ("Java String"),
"java.lang.String" };
Object item1[] = {
new Integer(12345),
new String( "12345" ),
"java.lang.Integer" };
Object item2[] = {
new Boolean(false),
new String( "false" ),
"java.lang.Boolean" };
Object item3[] = {
new Double(12345.0),
new String( "12345.0" ),
"java.lang.Double" };
Object dataArray[] = { item0, item1, item2, item3 };
return dataArray;
}
/**
* Create an empty JavaScript Array named jsArray.
*
* @return the JSObject array object
*/
public JSObject createJSArray() {
JSObject jsArray = null;
String args = "var jsArray = new Array()";
String result = "passed!";
try {
System.out.println( args );
global.eval( args );
jsArray = (JSObject) global.getMember("jsArray");
} catch ( Exception e ) {
result = "failed!";
exception = "global.getMember(\"jsArray\")"+
"threw " + e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
addTestCase(
"global.eval(\"var jsArray = "+
"new Array(); " +
"JSObject jsArray = (JSObject) global.getMember(\"jsArray\")",
"passed!",
result,
exception );
}
return jsArray;
}
/**
* Use JSObject.getMember to get the length property of a JSObject.
*
* @param jsArray a JSObject with a property named "length"
* @param javaLength the expected length of the JSObject
*/
public void getLength( JSObject jsArray, int javaLength ) {
String exception = "";
int jsLength = 0;
try {
jsLength = ((Double) jsArray.getMember("length")).intValue();
} catch ( Exception e ) {
exception = "jsArray.getMember(\"length\") threw "+
e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
addTestCase(
"[length is " + jsLength +"] "+
"( jsArray.getMember(\"length\")).intValue() == " +
javaLength +" )",
"true",
(jsLength == javaLength) + "",
exception );
}
}
/**
* Use JSObject.getSlot to get an indexed member of a JSObject. In this
* test, the expected class of all objects is JSObject.
*
* @param jsArray the JSObject with indexed members
* @param slot the index property to retrieve
* @param data object array containing the string representation of the
* expected result of jsArray.getSlot(slot) and the JSObjectconstructor
* of the expected result, which allows us to verify the value and type
* of the result object.
*/
public void getSlot( JSObject jsArray, int slot, Object[] data ) {
String exception = "";
Object result = null;
Class eClass = null;
Class aClass = null;
try {
result = (Object) jsArray.getSlot( slot );
if ( result != null ) {
eClass = Class.forName((String) data[2]);
aClass = result.getClass();
}
} catch ( Exception e ) {
exception = "jsArray.getSlot( " + slot + " ) "+
"threw " + e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
if ( result == null ) {
addTestCase(
"[jsArray.getSlot(" + slot +").toString().trim() returned " + result +"] "+
"( " + data[1] +".equals( " + result +" )",
"true",
data[1].toString().trim().equals( result.toString() ) +"",
exception );
} else {
// check the string value of the result
addTestCase(
"[jsArray.getSlot(" + slot +") returned " + result +"] "+
data[1] +".toString().equals( " + result +" ) ",
"true",
data[1].equals( result.toString() ) +"",
exception );
// check the class of the result. all should be JSObjects.
addTestCase(
"( " + eClass +".equals( " + aClass +" ) )",
"true",
eClass.equals( aClass ) +"",
exception );
}
}
}
/**
* JSObject.setSlot returns undefined. This just verifies that we can
* call setSlot without throwing an exception.
*
* @param jsArray the JSObject on which setSlot will be called
* @param slot the indexed member that will be set
* @param javaValue the value to set the indexed member
*/
public void setSlot( JSObject jsArray, int slot, Object[] data ) {
String exception = null;
String result = "passed!";
try {
jsArray.setSlot( slot, (Object) data[0] );
} catch ( Exception e ) {
result = "failed!";
exception = "jsArray.setSlot( " + slot +","+ data[0] +") "+
"threw " + e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
addTestCase(
"jsArray.setSlot( " + slot +", "+ data[0] +")",
"passed!",
result,
exception );
}
}
}

Просмотреть файл

@ -0,0 +1,289 @@
package com.netscape.javascript.qa.liveconnect.slot;
import netscape.javascript.*;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Create a JS object/ Set indexed members of the object using
* JSObject.setSlot. Get indexed members of the object again using getSlot.
*
* This covers the following JavaScript -> Java cases through getSlot:
* <table border = 1>
* <tr>
* <th> Java type
* <th> JavaScript type
* </tr>
* <tr>
* <td> JSObject
* <td> the JavaScript object it refers to
* </tr>
* </table>
*
* @see netscape.javascript.JSObject#getSlot
* @see netscape.javascript.JSObject#setSlot
*
* @author christine m begle
*/
public class Slot_005 extends LiveConnectTest {
public Slot_005() {
super();
}
public static void main( String[] args ) {
Slot_005 test = new Slot_005();
test.start();
}
public void executeTest() {
getBaseObjects();
Object testMatrix[] = getDataArray();
for ( int i = 0; i < testMatrix.length; i++ ) {
JSObject jsObject = createJSObject((Object[]) testMatrix[i]);
setSlot( jsObject, i, (Object[]) testMatrix[i] );
getSlot( jsObject, i, (Object[]) testMatrix[i] );
}
}
public JSObject createJSObject( Object[] data ) {
return (JSObject) data[0];
}
public JSObject jsNumber;
public JSObject jsFunction;
public JSObject jsBoolean;
public JSObject jsObject;
public JSObject jsString;
public JSObject jsMath;
public JSObject jsDate;
public JSObject jsArray;
public JSObject jsRegExp;
/**
* Get the constructor of all the base JavaScript objects. The test
* will compare the instance constructor to the base object constructor
* to verify that the JavaScript type of the object is corret.
*
*/
public boolean getBaseObjects() {
try {
jsNumber = (JSObject) global.eval( "Number.prototype.constructor" );
jsString = (JSObject) global.eval( "String.prototype.constructor" );
jsFunction = (JSObject) global.eval( "Function.prototype.constructor" );
jsBoolean = (JSObject) global.eval( "Boolean.prototype.constructor" );
jsObject = (JSObject) global.eval( "Object.prototype.constructor" );
jsMath = (JSObject) global.eval("Math");
jsDate = (JSObject) global.eval( "Date.prototype.constructor" );
jsArray = (JSObject) global.eval( "Array.prototype.constructor" );
jsRegExp = (JSObject) global.eval("RegExp.prototype.constructor");
} catch ( Exception e ) {
System.err.println( "Failed in getBaseObjects: " + e.toString() );
e.printStackTrace();
return false;
}
return true;
}
/**
* Get the data array, which is an array of arrays. Each of the internal
* arrays consists of three objects: a string whose value will be passed
* to the JavaScript array constructor; a String which is the expected
* string value of retreiving the JSObject via getSlot; and a JSObject,
* which is the JSObject's constructor, that allows us to verify the type
* of JSObject.
*
* @return the data array.
*/
public Object[] getDataArray() {
Object item0[] = {
global.eval("new String(\"passed!\")"),
global.eval("new String(\"passed!\")"),
new String("passed!"),
jsString
};
Object item1[] = {
global.eval("new Number(12345)"),
global.eval( "new Number(98765)"),
new String("98765"),
jsNumber};
Object item2[] = {
global.eval("new Boolean(false)"),
global.eval("new Boolean(true)"),
new String("true"),
jsBoolean };
Object item3[] = {
global.eval("new Array(0,1,2,3,4)"),
global.eval("new Array(\"h\",\"i\")"),
new String( "h,i" ),
jsArray };
Object item4[] = {
global.eval("new Object()"),
global.eval("new Object()"),
new String( "[object Object]" ),
jsObject };
Object dataArray[] = { item0, item1, item2, item3, item4 };
return dataArray;
}
/**
* Create an empty JavaScript Array named jsArray.
*
* @return the JSObject array object
*/
public JSObject createJSArray() {
JSObject jsArray = null;
String args = "var jsArray = new Array()";
String result = "passed!";
try {
System.out.println( args );
global.eval( args );
jsArray = (JSObject) global.getMember("jsArray");
} catch ( Exception e ) {
result = "failed!";
exception = "global.getMember(\"jsArray\")"+
"threw " + e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
addTestCase(
"global.eval(\"var jsArray = "+
"new Array(); " +
"JSObject jsArray = (JSObject) global.getMember(\"jsArray\")",
"passed!",
result,
exception );
}
return jsArray;
}
/**
* Use JSObject.getMember to get the length property of a JSObject.
*
* @param jsArray a JSObject with a property named "length"
* @param javaLength the expected length of the JSObject
*/
public void getLength( JSObject jsArray, int javaLength ) {
String exception = "";
int jsLength = 0;
try {
jsLength = ((Double) jsArray.getMember("length")).intValue();
} catch ( Exception e ) {
exception = "jsArray.getMember(\"length\") threw "+
e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
addTestCase(
"[length is " + jsLength +"] "+
"( jsArray.getMember(\"length\")).intValue() == " +
javaLength +" )",
"true",
(jsLength == javaLength) + "",
exception );
}
}
/**
* Use JSObject.getSlot to get an indexed member of a JSObject. In this
* test, the expected class of all objects is JSObject.
*
* @param jsArray the JSObject with indexed members
* @param slot the index property to retrieve
* @param data object array containing the string representation of the
* expected result of jsArray.getSlot(slot) and the JSObjectconstructor
* of the expected result, which allows us to verify the value and type
* of the result object.
*/
public void getSlot( JSObject jsArray, int slot, Object[] data ) {
String exception = "";
JSObject constructor = null;
JSObject result = null;
Class eClass = null;
Class aClass = null;
try {
result = (JSObject) jsArray.getSlot( slot );
if ( result != null ) {
eClass = Class.forName( "netscape.javascript.JSObject" );
aClass = result.getClass();
constructor = (JSObject) result.getMember( "constructor" );
}
} catch ( Exception e ) {
exception = "jsArray.getSlot( " + slot + " ) "+
"threw " + e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
if ( result == null ) {
addTestCase(
"[jsArray.getSlot(" + slot +").toString().trim() returned " + result +"] "+
"( " + data[1] +".equals( " + result +" )",
"true",
data[1].toString().trim().equals( result.toString() ) +"",
exception );
} else {
/*
// check the string value of the result
addTestCase(
"[jsArray.getSlot(" + slot +") returned " + result +"] "+
data[2] +".toString().equals( " + result +" ) ",
"true",
data[2].equals( result.toString() ) +"",
exception );
*/
// check the class of the result. all should be JSObjects.
addTestCase(
"( " + eClass +".equals( " + aClass +" ) )",
"true",
eClass.equals( aClass ) +"",
exception );
// check the constructor of the result
addTestCase(
"( " + constructor +".equals( " + data[3] +" ) )",
"true",
constructor.equals( data[3] ) +"",
exception );
}
}
}
/**
* JSObject.setSlot returns undefined. This just verifies that we can
* call setSlot without throwing an exception.
*
* @param jsArray the JSObject on which setSlot will be called
* @param slot the indexed member that will be set
* @param javaValue the value to set the indexed member
*/
public void setSlot( JSObject jsArray, int slot, Object[] data ) {
String exception = null;
String result = "passed!";
try {
jsArray.setSlot( slot, (Object) data[1] );
} catch ( Exception e ) {
result = "failed!";
exception = "jsArray.setSlot( " + slot +","+ data[1] +") "+
"threw " + e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
addTestCase(
"jsArray.setSlot( " + slot +", "+ data[1] +")",
"passed!",
result,
exception );
}
}
}

Просмотреть файл

@ -0,0 +1,132 @@
package com.netscape.javascript.qa.liveconnect.slot;
import netscape.javascript.*;
import com.netscape.javascript.qa.liveconnect.*;
/**
* Create a JS String. Get the values of characters in that string using
* getSlot.
*
* This covers the following JavaScript -> Java cases through getSlot:
* <table border = 1>
* <tr>
* <th> Java type
* <th> JavaScript type
* </tr>
* <tr>
* <td> string
* <td> java.lang.String
* </tr>
* </table>
*
* @see netscape.javascript.JSObject#getSlot
* @see netscape.javascript.JSObject#setSlot
*
* @author christine m begle
*/
public class Slot_006 extends LiveConnectTest {
public Slot_006() {
super();
}
public static void main( String[] args ) {
Slot_006 test = new Slot_006();
test.start();
}
public void executeTest() {
Object testMatrix[] = getDataArray();
for ( int i = 0; i < testMatrix.length; i++ ) {
JSObject jsObject = getJSString( (Object[]) testMatrix[i] );
for ( int j = 0;
j < ((String) ((Object[]) testMatrix[i])[1]).length();
j++ )
{
getSlot( jsObject, j, (Object[]) testMatrix[i] );
}
}
}
public JSObject getJSString ( Object[] data ) {
return (JSObject) data[0];
}
/**
* Data in this test contains of :
* JavaScript String object
* Java object with the same string value
*
* @return the data array.
*/
public Object[] getDataArray() {
Object item0[] = {
global.eval("new String(\"passed!\")"),
new String("passed!")
};
Object dataArray[] = { item0 };
return dataArray;
}
/**
* Use JSObject.getSlot to get an indexed member of a JSObject. In this
* test, the expected class of all objects is JSObject.
*
* XXX propbably need to add a bunch of unicode characters here.
*
* @param jsSTring the JSObject with indexed members
* @param slot the index property to retrieve
* @param data object array containing the string representation of the
* expected result of jsArray.getSlot(slot) and the JSObjectconstructor
* of the expected result, which allows us to verify the value and type
* of the result object.
*/
public void getSlot( JSObject jsString, int slot, Object[] data ) {
String exception = "";
JSObject constructor = null;
Class eClass = null;
Class aClass = null;
String result = null;
String eResult = null;
try {
eResult = new Character( ((String)data[1]).charAt(slot) ).toString();
result = (String) jsString.getSlot( slot );
if ( result != null ) {
eClass = Class.forName( "java.lang.String" );
aClass = result.getClass();
}
} catch ( Exception e ) {
exception = "jsString.getSlot( " + slot + " ) "+
"threw " + e.toString();
file.exception += exception;
e.printStackTrace();
} finally {
if ( result == null ) {
addTestCase(
"[jsString.getSlot(" + slot +").toString(). returned " + result +"] "+
"( " + eResult +".equals( " + result +" )",
"true",
eResult.equals( result +"") +"",
exception );
} else {
// check the string value of the result
addTestCase(
"[jsString.getSlot(" + slot +") returned " + result +"] "+
eResult +".toString().equals( " + result +" ) ",
"true",
eResult.equals( result.toString() ) +"",
exception );
// check the class of the result. all should be java.lang.Strings.
addTestCase(
"( " + eClass +".equals( " + aClass +" ) )",
"true",
eClass.equals( aClass ) +"",
exception );
}
}
}
}

Просмотреть файл

@ -0,0 +1,141 @@
package com.netscape.javascript.qa.liveconnect.tostring;
import com.netscape.javascript.qa.liveconnect.*;
import netscape.javascript.*;
/**
* SomeJSObject.toString() should return the same String value as
* SomeJSObject.call( "toString", null ) and
* global.eval( "somejsobjectname +''" );
*
*
* this test:
* constructs a javascript object
* gets the javascript object
* gets the string value of the object using call
* gets the string value of the object using eval +""
* gets the string value of the object using toString
*
*
* ie it should return the JavaScript string representation of that object.
*
* @see netscape.javascript.JSObject
*
* @author christine m begle
*/
public class ToString_001 extends LiveConnectTest {
public ToString_001() {
super();
}
public static void main( String[] args ) {
ToString_001 test = new ToString_001();
test.start();
}
public void setupTestEnvironment() {
super.setupTestEnvironment();
}
public void executeTest() {
Object data[] = getDataArray();
for ( int i = 0; i < data.length; i++ ) {
JSObject jsObject = getJSObject( (Object[]) data[i] );
getStrings( jsObject, (Object[]) data[i] );
}
}
public void getStrings( JSObject jsObject, Object[] data ) {
String eString = (String) data[2];
String resultOfToString = null;
String resultOfCall = null;
String resultOfEval = null;
try {
resultOfToString = jsObject.toString();
resultOfCall = (String) jsObject.call( "toString", null );
} catch ( Exception e ) {
file.exception = e.toString();
p( "getStrings threw " + e.toString() );
e.printStackTrace();
} finally {
addTestCase(
"[ jsObject.toString returned " + jsObject.toString() +" ]"+
"( " + jsObject +" ).toString().equals( " + eString +" )",
"true",
jsObject.toString().equals(eString) +"",
file.exception );
addTestCase(
"[ calling toString returned " + resultOfCall +" ]"+
"( " + jsObject +".call( \"toString\", null ).equals(" + eString+")",
"true",
resultOfCall.equals(eString)+"",
file.exception );
}
}
/**
* Create and return a JSObject using data in the data array.
*
* @param data Object array containing name of JSObject, and assignment
* expression
* @return the JSObject
*/
public JSObject getJSObject( Object[] data ) {
global.eval( (String) data[1] );
JSObject theThis = (JSObject) global.getMember( (String) data[0] );
return theThis;
}
/**
* Get the data array, which is an object array data arrays, which are
* also object arrays. The data arrays consist of 8 items
*
* <ul>
* <li> Identifier for JavaScript object
* <li> Assignment expression to initialize JavaScript object
* <li> expected string value of the object
* </ul>
*
* To add test cases to this test, modify this method.
*
* @return the data array.
*/
public Object[] getDataArray() {
Object d0[] = {
new String( "o" ), // 0 identifier
new String( "var o = new Object()"), // 1 complete expression for instantiation or assignment
new String( "[object Object]" )
};
Object d1[] = {
new String( "num" ),
new String( "num = new Number(12345)" ),
new String( "12345" )
};
Object d2[] = {
new String( "number" ),
new String( "number = new Number(Infinity)"),
new String( "Infinity" )
};
Object d3[] = {
new String( "string" ),
new String( "string = new String(\"JavaScript\")" ),
new String( "JavaScript" )
};
Object d4[] = {
new String ("array"),
new String( "array = new Array(1,2,3,4,5)"),
new String( "1,2,3,4,5")
};
Object dataArray[] = { d0, d1, d2, d3, d4 };
return dataArray;
}
}