001: /*
002: * JavaTest.java --
003: *
004: * This file contains the JavaTest class used by java.test.
005: *
006: * Copyright (c) 1997 by Sun Microsystems, Inc.
007: *
008: * See the file "license.terms" for information on usage and redistribution
009: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
010: *
011: * RCS: @(#) $Id: JavaTest.java,v 1.5 2006/06/19 02:54:27 mdejong Exp $
012: */
013:
014: package tests;
015:
016: import tcl.lang.*;
017: import java.util.*;
018:
019: public class JavaTest implements CommandWithDispose {
020:
021: // Constructors.
022:
023: public JavaTest() {
024: }
025:
026: public JavaTest(String s) {
027: }
028:
029: public JavaTest(String s, int i) {
030: }
031:
032: public JavaTest(boolean b) {
033: throw new NullPointerException();
034: }
035:
036: // Constants.
037:
038: public static final int JT1 = 3;
039: public final int JT2 = 4;
040: private static final int JT3 = 5;
041: private final int JT4 = 6;
042:
043: // Static fields for each primitive type.
044:
045: public static boolean sboolean;
046: public static byte sbyte;
047: public static short sshort;
048: public static int sint;
049: public static long slong;
050: public static float sfloat;
051: public static double sdouble;
052: public static char schar;
053: public static String sstr;
054:
055: public static JavaTest sobj;
056:
057: // Static methods.
058:
059: public static String smethod() {
060: return "static";
061: }
062:
063: public static String nullsmethod() {
064: return null;
065: }
066:
067: public static void voidsmethod() {
068: return;
069: }
070:
071: // Instance fields for each type.
072:
073: public int iint = 123;
074: public boolean iboolean = false;
075: public long ilong = 123;
076: public short ishort = 123;
077: public byte ibyte = 123;
078: public float ifloat = (float) 123.0;
079: public double idouble = 123.0;
080: public char ichar = 'J';
081: public String istr = "test string";
082:
083: public Integer iobj1 = new Integer(123);
084: public String iobj2 = new String("test string obj");
085: public Object iobj3 = new Vector();
086: public Object iobjnull = null;
087:
088: public JavaTest iobj;
089:
090: // Instance methods.
091:
092: public int imethod() {
093: return 6;
094: }
095:
096: public int imethod(int i) {
097: return i + 1;
098: }
099:
100: public String nullimethod() {
101: return null;
102: }
103:
104: public void voidimethod() {
105: return;
106: }
107:
108: public void failMethod() {
109: throw new NullPointerException();
110: }
111:
112: // Simple Tcl command implementation.
113:
114: public void cmdProc(Interp interp, TclObject argv[])
115: throws TclException {
116: String s = argv[0].toString();
117: for (int i = 1; i < argv.length; i++) {
118: s = s + ", " + argv[i].toString();
119: }
120:
121: if (iboolean) {
122: interp.setResult(s + ": success");
123: } else {
124: throw new TclException(interp, s + ": failure", TCL.ERROR);
125: }
126: }
127:
128: public void disposeCmd() {
129: istr = "disposed";
130: }
131:
132: // Returns the java.lang.String that was passed in
133: // used to test argument conversion.
134:
135: public static String retStr(String str) {
136: return str;
137: }
138:
139: // Throw Tcl error from Java method.
140:
141: public static void throwTclException(Interp interp)
142: throws TclException {
143: throw new TclException(interp, "no nuts in my fudge please!");
144: }
145:
146: // Raise NullPointerException if Interp.setResult()
147: // is invoked with a null pointer.
148:
149: public static String testSetResultNPE(Interp interp)
150: throws TclException {
151: try {
152: interp.setResult((TclObject) null);
153: } catch (NullPointerException npe) {
154: return "OK";
155: }
156: return "ERROR";
157: }
158:
159: public static String testResetResultNPE(Interp interp)
160: throws TclException {
161: try {
162: interp.resetResult();
163: interp.setResult((TclObject) null);
164: } catch (NullPointerException npe) {
165: return "OK";
166: }
167: return "ERROR";
168: }
169: }
|