001: //
002: // Copyright (C) 2005 United States Government as represented by the
003: // Administrator of the National Aeronautics and Space Administration
004: // (NASA). All Rights Reserved.
005: //
006: // This software is distributed under the NASA Open Source Agreement
007: // (NOSA), version 1.3. The NOSA has been approved by the Open Source
008: // Initiative. See the file NOSA-1.3-JPF at the top of the distribution
009: // directory tree for the complete NOSA document.
010: //
011: // THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
012: // KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
013: // LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
014: // SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
015: // A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
016: // THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
017: // DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
018: //
019: package gov.nasa.jpf.jvm;
020:
021: interface TMI {
022: void gna();
023: }
024:
025: class TestMethodBase implements TMI {
026:
027: int baseData;
028:
029: static int sData;
030:
031: static {
032: sData = -1;
033: }
034:
035: static void taz() {
036: sData = 24;
037: }
038:
039: TestMethodBase(int a) {
040: assert a == 42;
041: baseData = 42;
042: }
043:
044: boolean baz(boolean p, byte b, char c, short s, int i, long l,
045: float f, double d, Object o) {
046: assert p;
047: assert b == 4;
048: assert c == '?';
049: assert s == 42;
050: assert i == 4242;
051: assert l == 424242;
052: assert f == 4.2f;
053: assert d == 4.242;
054: assert o.equals(new Integer(42));
055:
056: baseData = 44;
057:
058: return p;
059: }
060:
061: void faz() {
062: gna();
063: }
064:
065: public void gna() {
066: baseData = 0;
067: }
068:
069: int har() {
070: return priv();
071: }
072:
073: private int priv() {
074: return 7;
075: }
076: }
077:
078: /**
079: * method invocation test
080: */
081: public class TestMethod extends TestMethodBase {
082:
083: int data;
084:
085: static void taz() {
086: sData = 9;
087: }
088:
089: TestMethod() {
090: super (42);
091:
092: data = 42;
093: }
094:
095: TestMethod(int a) {
096: super (a);
097:
098: data = a;
099: }
100:
101: double foo(boolean p, byte b, char c, short s, int i, long l,
102: float f, double d, Object o) {
103: assert p;
104: assert b == 4;
105: assert c == '?';
106: assert s == 42;
107: assert i == 4242;
108: assert l == 424242;
109: assert f == 4.2f;
110: assert d == 4.242;
111: assert o.equals(new Integer(42));
112:
113: data = 43;
114:
115: return d;
116: }
117:
118: public void gna() {
119: baseData = 45;
120: }
121:
122: int priv() {
123: return 8;
124: }
125:
126: public static void main(String[] args) {
127: TestMethod t = new TestMethod();
128:
129: if (args.length > 0) {
130: // just run the specified tests
131: for (int i = 0; i < args.length; i++) {
132: String func = args[i];
133:
134: // note that we don't use reflection here because this would
135: // blow up execution/test scope under JPF
136: if ("testCtor".equals(func)) {
137: testCtor();
138: } else if ("testCall".equals(func)) {
139: testCall();
140: } else if ("testInheritedCall".equals(func)) {
141: testInheritedCall();
142: } else if ("testVirtualCall".equals(func)) {
143: testVirtualCall();
144: } else if ("testSpecialCall".equals(func)) {
145: testSpecialCall();
146: } else if ("testStaticCall".equals(func)) {
147: testStaticCall();
148: } else {
149: throw new IllegalArgumentException(
150: "unknown test function");
151: }
152: }
153: } else {
154: testCtor();
155: testCall();
156: testInheritedCall();
157: testVirtualCall();
158: testSpecialCall();
159: testStaticCall();
160: }
161: }
162:
163: public static void testCtor() {
164: TestMethod o1 = new TestMethod();
165: assert o1.data == 42;
166: assert o1.baseData == 42;
167:
168: TestMethod o2 = new TestMethod(42);
169: assert o2.data == 42;
170: assert o2.baseData == 42;
171: }
172:
173: public static void testCall() {
174: TestMethod o = new TestMethod();
175: assert o.foo(true, (byte) 4, '?', (short) 42, 4242, 424242,
176: 4.2f, 4.242, new Integer(42)) == 4.242;
177: assert o.data == 43;
178: }
179:
180: public static void testInheritedCall() {
181: TestMethod o = new TestMethod();
182: assert o.baz(true, (byte) 4, '?', (short) 42, 4242, 424242,
183: 4.2f, 4.242, new Integer(42));
184: assert o.baseData == 44;
185: }
186:
187: public static void testVirtualCall() {
188: TestMethod o = new TestMethod();
189: TestMethodBase b = (TestMethodBase) o;
190:
191: b.faz();
192: assert o.baseData == 45;
193: }
194:
195: public static void testSpecialCall() {
196: TestMethod o = new TestMethod();
197: assert o.har() == 7;
198: }
199:
200: public static void testStaticCall() {
201: assert TestMethodBase.sData == -1;
202:
203: TestMethod.taz();
204: assert TestMethodBase.sData == 9;
205:
206: TestMethodBase.taz();
207: assert TestMethodBase.sData == 24;
208:
209: TestMethod o = new TestMethod();
210: o.taz();
211: assert TestMethodBase.sData == 9;
212: }
213:
214: public static void testInterfaceCall() {
215: TestMethod o = new TestMethod();
216: TMI ifc = (TMI) o;
217:
218: ifc.gna();
219: assert o.baseData == 45;
220: }
221: }
|