001: /*
002: * ConvertTest.java --
003: *
004: * This file contains the ConvertTest class used by convert.test to
005: * test conversion between Tcl and Java objects.
006: *
007: * Copyright (c) 1997 by Sun Microsystems, Inc.
008: *
009: * See the file "license.terms" for information on usage and redistribution
010: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
011: *
012: * RCS: @(#) $Id: ConvertTest.java,v 1.2 1999/05/16 00:04:10 dejong Exp $
013: *
014: */
015:
016: package tests;
017:
018: /*
019: * This class is used to test conversion between Tcl and Java objects.
020: */
021:
022: public class ConvertTest {
023: public static int staticTestParam(Object s) {
024: if (s == null) {
025: return 2;
026: }
027: if (s instanceof String) {
028: if (s.equals("")) {
029: return 1;
030: }
031: if (s.equals("null")) {
032: return 3;
033: } else if (s.toString().startsWith("java")) {
034: return 4;
035: } else {
036: return 5;
037: }
038: } else {
039: return 6;
040: }
041: }
042:
043: public int testParam(Object s) {
044: return staticTestParam(s);
045: }
046:
047: public String getString(int i) {
048: return staticGetString(i);
049: }
050:
051: public static String staticGetString(int i) {
052: if (i == 0) {
053: return null;
054: } else if (i == 1) {
055: return "";
056: } else if (i == 2) {
057: return "null";
058: } else {
059: return "foo";
060: }
061: }
062:
063: public String strField0 = null;
064: public String strField1 = "";
065: public String strField2 = "null";
066: public String strField3 = "foo";
067:
068: private String strProp0 = null;
069: private String strProp1 = "";
070: private String strProp2 = "null";
071: private String strProp3 = "foo";
072:
073: public String getStrProp0() {
074: return strProp0;
075: }
076:
077: public String getStrProp1() {
078: return strProp1;
079: }
080:
081: public String getStrProp2() {
082: return strProp2;
083: }
084:
085: public String getStrProp3() {
086: return strProp3;
087: }
088:
089: public void setStrProp0(String s) {
090: strProp0 = s;
091: }
092:
093: public void setStrProp1(String s) {
094: strProp1 = s;
095: }
096:
097: public void setStrProp2(String s) {
098: strProp2 = s;
099: }
100:
101: public void setStrProp3(String s) {
102: strProp3 = s;
103: }
104:
105: public void voidMethod() {
106: // A method of void return type. The Tcl result should
107: // be empty string.
108: }
109:
110: public Object nullMethod() {
111: // The Tcl result should be the same as [java::null].
112:
113: return null;
114: }
115:
116: public String emptyStringMethod() {
117: // The Tcl result should be "".
118:
119: return "";
120: }
121:
122: public Boolean trueBooleanObjectMethod() {
123: // The Tcl result should be a Boolean Java object.
124:
125: return new Boolean(true);
126: }
127:
128: public Boolean falseBooleanObjectMethod() {
129: // The Tcl result should be a Boolean Java object.
130:
131: return new Boolean(false);
132: }
133:
134: public boolean trueBooleanMethod() {
135: // The Tcl result should be 1
136:
137: return true;
138: }
139:
140: public boolean falseBooleanMethod() {
141: // The Tcl result should be 0
142:
143: return false;
144: }
145:
146: }
|