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: /**
022: * field access test
023: */
024: class TestFieldBase {
025: static boolean s_base_Z = true;
026: static byte s_base_B = 16;
027: static char s_base_C = 'A';
028: static short s_base_S = 2048;
029: static int s_base_I = 0x8000;
030: static long s_base_J = 0x800000;
031: static float s_base_F = 1.23f;
032: static double s_base_D = 3.45;
033: static Object s_base_o = new String("a static string");
034: boolean base_Z = true;
035: byte base_B = 16;
036: char base_C = 'A';
037: short base_S = 2048;
038: int base_I = 0x8000;
039: long base_J = 0x800000;
040: float base_F = 1.23f;
041: double base_D = 3.45;
042: Object base_o = new String("a instance string");
043: }
044:
045: /**
046: * DOCUMENT ME!
047: */
048: public class TestField extends TestFieldBase {
049: boolean s_Z = s_base_Z;
050: byte s_B = s_base_B;
051: char s_C = s_base_C;
052: short s_S = s_base_S;
053: int s_I = s_base_I;
054: long s_J = s_base_J;
055: float s_F = s_base_F;
056: double s_D = s_base_D;
057: Object s_o = s_base_o;
058: boolean _Z = base_Z;
059: byte _B = base_B;
060: char _C = base_C;
061: short _S = base_S;
062: int _I = base_I;
063: long _J = base_J;
064: float _F = base_F;
065: double _D = base_D;
066: Object _o = base_o;
067:
068: public static void main(String[] args) {
069: TestField t = new TestField();
070:
071: if (args.length > 0) {
072: // just run the specified tests
073: for (int i = 0; i < args.length; i++) {
074: String func = args[i];
075:
076: // note that we don't use reflection here because this would
077: // blow up execution/test scope under JPF
078: if ("testReadInstance".equals(func)) {
079: t.testReadInstance();
080: } else if ("testWriteInstance".equals(func)) {
081: t.testWriteInstance();
082: } else if ("testReadStatic".equals(func)) {
083: t.testReadStatic();
084: } else if ("testWriteStatic".equals(func)) {
085: t.testWriteStatic();
086: } else {
087: throw new IllegalArgumentException(
088: "unknown test function");
089: }
090: }
091: } else {
092: // that's mainly for our standalone test verification
093: t.testReadInstance();
094: t.testWriteInstance();
095: t.testReadStatic();
096: t.testWriteStatic();
097: }
098: }
099:
100: public void testReadInstance() {
101: assert _Z == base_Z;
102: assert _Z == true;
103:
104: assert _B == base_B;
105: assert _B == 16;
106:
107: assert _C == base_C;
108: assert _C == 'A';
109:
110: assert _I == base_I;
111: assert _I == 0x8000;
112:
113: assert _J == base_J;
114: assert _J == 0x800000;
115:
116: assert _F == base_F;
117: assert _F == 1.23f;
118:
119: assert _D == base_D;
120: assert _D == 3.45;
121:
122: assert _o.equals(base_o);
123: assert _o.equals("a instance string");
124: }
125:
126: public void testReadStatic() {
127: assert s_Z == s_base_Z;
128: assert s_Z == true;
129:
130: assert s_B == s_base_B;
131: assert s_B == 16;
132:
133: assert s_C == s_base_C;
134: assert s_C == 'A';
135:
136: assert s_I == s_base_I;
137: assert s_I == 0x8000;
138:
139: assert s_J == s_base_J;
140: assert s_J == 0x800000;
141:
142: assert s_F == s_base_F;
143: assert s_F == 1.23f;
144:
145: assert s_D == s_base_D;
146: assert s_D == 3.45;
147:
148: assert s_o.equals(s_base_o);
149: assert s_o.equals("a static string");
150: }
151:
152: public void testWriteInstance() {
153: _Z = false;
154: assert _Z == false;
155: base_Z = _Z;
156: assert base_Z == _Z;
157:
158: _B = 17;
159: assert _B == 17;
160: base_B = _B;
161: assert base_B == _B;
162:
163: _C = 'B';
164: assert _C == 'B';
165: base_C = _C;
166: assert base_C == _C;
167:
168: _I = 12345;
169: assert _I == 12345;
170: base_I = _I;
171: assert base_I == _I;
172:
173: _J = 12345678;
174: assert _J == 12345678;
175: base_J = _J;
176: assert base_J == _J;
177:
178: _F = 7.65f;
179: assert _F == 7.65f;
180: base_F = _F;
181: assert base_F == _F;
182:
183: _D = 6.54;
184: assert _D == 6.54;
185: base_D = _D;
186: assert base_D == _D;
187:
188: _o = new Integer(42);
189: assert _o.equals(new Integer(42));
190: base_o = _o;
191: assert base_o.equals(_o);
192: }
193:
194: public void testWriteStatic() {
195: s_Z = false;
196: assert s_Z == false;
197: s_base_Z = s_Z;
198: assert s_base_Z == s_Z;
199:
200: s_B = 17;
201: assert s_B == 17;
202: s_base_B = s_B;
203: assert s_base_B == s_B;
204:
205: s_C = 'B';
206: assert s_C == 'B';
207: s_base_C = s_C;
208: assert s_base_C == s_C;
209:
210: s_I = 12345;
211: assert s_I == 12345;
212: s_base_I = s_I;
213: assert s_base_I == s_I;
214:
215: s_J = 12345678;
216: assert s_J == 12345678;
217: s_base_J = s_J;
218: assert s_base_J == s_J;
219:
220: s_F = 7.65f;
221: assert s_F == 7.65f;
222: s_base_F = s_F;
223: assert s_base_F == s_F;
224:
225: s_D = 6.54;
226: assert s_D == 6.54;
227: s_base_D = s_D;
228: assert s_base_D == s_D;
229:
230: s_o = new Integer(42);
231: assert s_o.equals(new Integer(42));
232: s_base_o = s_o;
233: assert s_base_o.equals(s_o);
234: }
235: }
|