KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gov > nasa > jpf > jvm > TestField


1 //
2
// Copyright (C) 2005 United States Government as represented by the
3
// Administrator of the National Aeronautics and Space Administration
4
// (NASA). All Rights Reserved.
5
//
6
// This software is distributed under the NASA Open Source Agreement
7
// (NOSA), version 1.3. The NOSA has been approved by the Open Source
8
// Initiative. See the file NOSA-1.3-JPF at the top of the distribution
9
// directory tree for the complete NOSA document.
10
//
11
// THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
12
// KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
13
// LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
14
// SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
15
// A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
16
// THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
17
// DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
18
//
19
package gov.nasa.jpf.jvm;
20
21 /**
22  * field access test
23  */

24 class TestFieldBase {
25   static boolean s_base_Z = true;
26   static byte s_base_B = 16;
27   static char s_base_C = 'A';
28   static short s_base_S = 2048;
29   static int s_base_I = 0x8000;
30   static long s_base_J = 0x800000;
31   static float s_base_F = 1.23f;
32   static double s_base_D = 3.45;
33   static Object JavaDoc s_base_o = new String JavaDoc("a static string");
34   boolean base_Z = true;
35   byte base_B = 16;
36   char base_C = 'A';
37   short base_S = 2048;
38   int base_I = 0x8000;
39   long base_J = 0x800000;
40   float base_F = 1.23f;
41   double base_D = 3.45;
42   Object JavaDoc base_o = new String JavaDoc("a instance string");
43 }
44
45 /**
46  * DOCUMENT ME!
47  */

48 public class TestField extends TestFieldBase {
49   boolean s_Z = s_base_Z;
50   byte s_B = s_base_B;
51   char s_C = s_base_C;
52   short s_S = s_base_S;
53   int s_I = s_base_I;
54   long s_J = s_base_J;
55   float s_F = s_base_F;
56   double s_D = s_base_D;
57   Object JavaDoc s_o = s_base_o;
58   boolean _Z = base_Z;
59   byte _B = base_B;
60   char _C = base_C;
61   short _S = base_S;
62   int _I = base_I;
63   long _J = base_J;
64   float _F = base_F;
65   double _D = base_D;
66   Object JavaDoc _o = base_o;
67
68   public static void main (String JavaDoc[] args) {
69     TestField t = new TestField();
70
71     if (args.length > 0) {
72       // just run the specified tests
73
for (int i = 0; i < args.length; i++) {
74         String JavaDoc func = args[i];
75
76         // note that we don't use reflection here because this would
77
// blow up execution/test scope under JPF
78
if ("testReadInstance".equals(func)) {
79           t.testReadInstance();
80         } else if ("testWriteInstance".equals(func)) {
81           t.testWriteInstance();
82         } else if ("testReadStatic".equals(func)) {
83           t.testReadStatic();
84         } else if ("testWriteStatic".equals(func)) {
85           t.testWriteStatic();
86         } else {
87           throw new IllegalArgumentException JavaDoc("unknown test function");
88         }
89       }
90     } else {
91       // that's mainly for our standalone test verification
92
t.testReadInstance();
93       t.testWriteInstance();
94       t.testReadStatic();
95       t.testWriteStatic();
96     }
97   }
98
99   public void testReadInstance () {
100     assert _Z == base_Z;
101     assert _Z == true;
102
103     assert _B == base_B;
104     assert _B == 16;
105
106     assert _C == base_C;
107     assert _C == 'A';
108
109     assert _I == base_I;
110     assert _I == 0x8000;
111
112     assert _J == base_J;
113     assert _J == 0x800000;
114
115     assert _F == base_F;
116     assert _F == 1.23f;
117
118     assert _D == base_D;
119     assert _D == 3.45;
120
121     assert _o.equals(base_o);
122     assert _o.equals("a instance string");
123   }
124
125   public void testReadStatic () {
126     assert s_Z == s_base_Z;
127     assert s_Z == true;
128
129     assert s_B == s_base_B;
130     assert s_B == 16;
131
132     assert s_C == s_base_C;
133     assert s_C == 'A';
134
135     assert s_I == s_base_I;
136     assert s_I == 0x8000;
137
138     assert s_J == s_base_J;
139     assert s_J == 0x800000;
140
141     assert s_F == s_base_F;
142     assert s_F == 1.23f;
143
144     assert s_D == s_base_D;
145     assert s_D == 3.45;
146
147     assert s_o.equals(s_base_o);
148     assert s_o.equals("a static string");
149   }
150
151   public void testWriteInstance () {
152     _Z = false;
153     assert _Z == false;
154     base_Z = _Z;
155     assert base_Z == _Z;
156
157     _B = 17;
158     assert _B == 17;
159     base_B = _B;
160     assert base_B == _B;
161
162     _C = 'B';
163     assert _C == 'B';
164     base_C = _C;
165     assert base_C == _C;
166
167     _I = 12345;
168     assert _I == 12345;
169     base_I = _I;
170     assert base_I == _I;
171
172     _J = 12345678;
173     assert _J == 12345678;
174     base_J = _J;
175     assert base_J == _J;
176
177     _F = 7.65f;
178     assert _F == 7.65f;
179     base_F = _F;
180     assert base_F == _F;
181
182     _D = 6.54;
183     assert _D == 6.54;
184     base_D = _D;
185     assert base_D == _D;
186
187     _o = new Integer JavaDoc(42);
188     assert _o.equals(new Integer JavaDoc(42));
189     base_o = _o;
190     assert base_o.equals(_o);
191   }
192
193   public void testWriteStatic () {
194     s_Z = false;
195     assert s_Z == false;
196     s_base_Z = s_Z;
197     assert s_base_Z == s_Z;
198
199     s_B = 17;
200     assert s_B == 17;
201     s_base_B = s_B;
202     assert s_base_B == s_B;
203
204     s_C = 'B';
205     assert s_C == 'B';
206     s_base_C = s_C;
207     assert s_base_C == s_C;
208
209     s_I = 12345;
210     assert s_I == 12345;
211     s_base_I = s_I;
212     assert s_base_I == s_I;
213
214     s_J = 12345678;
215     assert s_J == 12345678;
216     s_base_J = s_J;
217     assert s_base_J == s_J;
218
219     s_F = 7.65f;
220     assert s_F == 7.65f;
221     s_base_F = s_F;
222     assert s_base_F == s_F;
223
224     s_D = 6.54;
225     assert s_D == 6.54;
226     s_base_D = s_D;
227     assert s_base_D == s_D;
228
229     s_o = new Integer JavaDoc(42);
230     assert s_o.equals(new Integer JavaDoc(42));
231     s_base_o = s_o;
232     assert s_base_o.equals(s_o);
233   }
234 }
Popular Tags