• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 import junit.framework.Assert;
18 import java.util.Arrays;
19 import java.lang.reflect.Method;
20 
21 public class Main {
main(String args[])22   public static void main(String args[]) throws Exception {
23     test_Double_doubleToRawLongBits();
24     test_Double_longBitsToDouble();
25     test_Float_floatToRawIntBits();
26     test_Float_intBitsToFloat();
27     test_Math_abs_I();
28     test_Math_abs_J();
29     test_Math_min_I();
30     test_Math_max_I();
31     test_Math_min_J();
32     test_Math_max_J();
33     test_Math_min_F();
34     test_Math_max_F();
35     test_Math_min_D();
36     test_Math_max_D();
37     test_Math_ceil();
38     test_Math_floor();
39     test_Math_rint();
40     test_Math_round_D();
41     test_Math_round_F();
42     test_Short_reverseBytes();
43     test_Integer_reverseBytes();
44     test_Long_reverseBytes();
45     test_Integer_reverse();
46     test_Long_reverse();
47     test_StrictMath_abs_I();
48     test_StrictMath_abs_J();
49     test_StrictMath_min_I();
50     test_StrictMath_max_I();
51     test_StrictMath_min_J();
52     test_StrictMath_max_J();
53     test_StrictMath_min_F();
54     test_StrictMath_max_F();
55     test_StrictMath_min_D();
56     test_StrictMath_max_D();
57     test_StrictMath_ceil();
58     test_StrictMath_floor();
59     test_StrictMath_rint();
60     test_StrictMath_round_D();
61     test_StrictMath_round_F();
62     test_String_charAt();
63     test_String_compareTo();
64     test_String_indexOf();
65     test_String_isEmpty();
66     test_String_length();
67     test_Thread_currentThread();
68     initSupportMethodsForPeekPoke();
69     test_Memory_peekByte();
70     test_Memory_peekShort();
71     test_Memory_peekInt();
72     test_Memory_peekLong();
73     test_Memory_pokeByte();
74     test_Memory_pokeShort();
75     test_Memory_pokeInt();
76     test_Memory_pokeLong();
77   }
78 
79   /**
80    * Will test inlining Thread.currentThread().
81    */
test_Thread_currentThread()82   public static void test_Thread_currentThread() {
83     // 1. Do not use result.
84     Thread.currentThread();
85 
86     // 2. Result should not be null.
87     Assert.assertNotNull(Thread.currentThread());
88   }
89 
test_String_length()90   public static void test_String_length() {
91     String str0 = "";
92     String str1 = "x";
93     String str80 = "01234567890123456789012345678901234567890123456789012345678901234567890123456789";
94 
95     Assert.assertEquals(str0.length(), 0);
96     Assert.assertEquals(str1.length(), 1);
97     Assert.assertEquals(str80.length(), 80);
98 
99     String strNull = null;
100     try {
101       strNull.length();
102       Assert.fail();
103     } catch (NullPointerException expected) {
104     }
105   }
106 
test_String_isEmpty()107   public static void test_String_isEmpty() {
108     String str0 = "";
109     String str1 = "x";
110 
111     Assert.assertTrue(str0.isEmpty());
112     Assert.assertFalse(str1.isEmpty());
113 
114     String strNull = null;
115     try {
116       strNull.isEmpty();
117       Assert.fail();
118     } catch (NullPointerException expected) {
119     }
120   }
121 
test_String_charAt()122   public static void test_String_charAt() {
123     String testStr = "Now is the time";
124 
125     Assert.assertEquals('N', testStr.charAt(0));
126     Assert.assertEquals('o', testStr.charAt(1));
127     Assert.assertEquals(' ', testStr.charAt(10));
128     Assert.assertEquals('e', testStr.charAt(14));  // 14 = testStr.length()-1 as a constant.
129     Assert.assertEquals('N', test_String_charAt_inner(testStr, 0));
130     Assert.assertEquals('o', test_String_charAt_inner(testStr, 1));
131     Assert.assertEquals(' ', test_String_charAt_inner(testStr, 10));
132     Assert.assertEquals('e', test_String_charAt_inner(testStr, testStr.length()-1));
133 
134     try {
135       testStr.charAt(-1);
136       Assert.fail();
137     } catch (StringIndexOutOfBoundsException expected) {
138     }
139     try {
140       testStr.charAt(80);
141       Assert.fail();
142     } catch (StringIndexOutOfBoundsException expected) {
143     }
144     try {
145       testStr.charAt(15);  // 15 = "Now is the time".length()
146       Assert.fail();
147     } catch (StringIndexOutOfBoundsException expected) {
148     }
149     try {
150       test_String_charAt_inner(testStr, -1);
151       Assert.fail();
152     } catch (StringIndexOutOfBoundsException expected) {
153     }
154     try {
155       test_String_charAt_inner(testStr, 80);
156       Assert.fail();
157     } catch (StringIndexOutOfBoundsException expected) {
158     }
159     try {
160       test_String_charAt_inner(testStr, 15);  // 15 = "Now is the time".length()
161       Assert.fail();
162     } catch (StringIndexOutOfBoundsException expected) {
163     }
164 
165     String strEmpty = "";
166     try {
167       strEmpty.charAt(0);
168       Assert.fail();
169     } catch (StringIndexOutOfBoundsException expected) {
170     }
171 
172     String strNull = null;
173     try {
174       strNull.charAt(0);
175       Assert.fail();
176     } catch (NullPointerException expected) {
177     }
178   }
179 
test_String_charAt_inner(String s, int index)180   private static char test_String_charAt_inner(String s, int index) {
181     // Using non-constant index here (assuming that this method wasn't inlined).
182     return s.charAt(index);
183   }
184 
185   static int start;
186   private static int[] negIndex = { -100000 };
test_String_indexOf()187   public static void test_String_indexOf() {
188     String str0 = "";
189     String str1 = "/";
190     String str3 = "abc";
191     String str10 = "abcdefghij";
192     String str40 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabc";
193 
194     int supplementaryChar = 0x20b9f;
195     String surrogatePair = "\ud842\udf9f";
196     String stringWithSurrogates = "hello " + surrogatePair + " world";
197 
198     Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar), "hello ".length());
199     Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 2), "hello ".length());
200     Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 6), 6);
201     Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 7), -1);
202 
203     Assert.assertEquals(str0.indexOf('a'), -1);
204     Assert.assertEquals(str3.indexOf('a'), 0);
205     Assert.assertEquals(str3.indexOf('b'), 1);
206     Assert.assertEquals(str3.indexOf('c'), 2);
207     Assert.assertEquals(str10.indexOf('j'), 9);
208     Assert.assertEquals(str40.indexOf('a'), 0);
209     Assert.assertEquals(str40.indexOf('b'), 38);
210     Assert.assertEquals(str40.indexOf('c'), 39);
211     Assert.assertEquals(str0.indexOf('a',20), -1);
212     Assert.assertEquals(str0.indexOf('a',0), -1);
213     Assert.assertEquals(str0.indexOf('a',-1), -1);
214     Assert.assertEquals(str1.indexOf('/',++start), -1);
215     Assert.assertEquals(str1.indexOf('a',negIndex[0]), -1);
216     Assert.assertEquals(str3.indexOf('a',0), 0);
217     Assert.assertEquals(str3.indexOf('a',1), -1);
218     Assert.assertEquals(str3.indexOf('a',1234), -1);
219     Assert.assertEquals(str3.indexOf('b',0), 1);
220     Assert.assertEquals(str3.indexOf('b',1), 1);
221     Assert.assertEquals(str3.indexOf('c',2), 2);
222     Assert.assertEquals(str10.indexOf('j',5), 9);
223     Assert.assertEquals(str10.indexOf('j',9), 9);
224     Assert.assertEquals(str40.indexOf('a',10), 10);
225     Assert.assertEquals(str40.indexOf('b',40), -1);
226 
227     String strNull = null;
228     try {
229       strNull.indexOf('a');
230       Assert.fail();
231     } catch (NullPointerException expected) {
232     }
233     try {
234       strNull.indexOf('a', 0);
235       Assert.fail();
236     } catch (NullPointerException expected) {
237     }
238     try {
239       strNull.indexOf('a', -1);
240       Assert.fail();
241     } catch (NullPointerException expected) {
242     }
243   }
244 
test_String_compareTo()245   public static void test_String_compareTo() {
246     String test = "0123456789";
247     String test1 = new String("0123456789");    // different object
248     String test2 = new String("0123456780");    // different value
249     String offset = new String("xxx0123456789yyy");
250     String sub = offset.substring(3, 13);
251     String str32 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
252     String str33 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxy";
253     String lc = "abcdefg";
254     String uc = "ABCDEFG";
255     Object blah = new Object();
256 
257     Assert.assertTrue(lc.toUpperCase().equals(uc));
258 
259     Assert.assertEquals(str32.compareTo(str33), -1);
260     Assert.assertEquals(str33.compareTo(str32), 1);
261 
262     Assert.assertTrue(test.equals(test));
263     Assert.assertTrue(test.equals(test1));
264     Assert.assertFalse(test.equals(test2));
265 
266     Assert.assertEquals(test.compareTo(test1), 0);
267     Assert.assertTrue(test1.compareTo(test2) > 0);
268     Assert.assertTrue(test2.compareTo(test1) < 0);
269 
270     // Compare string with a nonzero offset, in left/right side.
271     Assert.assertEquals(test.compareTo(sub), 0);
272     Assert.assertEquals(sub.compareTo(test), 0);
273     Assert.assertTrue(test.equals(sub));
274     Assert.assertTrue(sub.equals(test));
275     // Same base, one is a substring.
276     Assert.assertFalse(offset.equals(sub));
277     Assert.assertFalse(sub.equals(offset));
278     // Wrong class.
279     Assert.assertFalse(test.equals(blah));
280 
281     // Null lhs - throw.
282     try {
283       test.compareTo(null);
284       Assert.fail("didn't get expected npe");
285     } catch (NullPointerException npe) {
286     }
287     // Null rhs - okay.
288     Assert.assertFalse(test.equals(null));
289 
290     test = test.substring(1);
291     Assert.assertTrue(test.equals("123456789"));
292     Assert.assertFalse(test.equals(test1));
293 
294     test = test.substring(1);
295     Assert.assertTrue(test.equals("23456789"));
296 
297     test = test.substring(1);
298     Assert.assertTrue(test.equals("3456789"));
299 
300     test = test.substring(1);
301     Assert.assertTrue(test.equals("456789"));
302 
303     test = test.substring(3,5);
304     Assert.assertTrue(test.equals("78"));
305 
306     test = "this/is/a/path";
307     String[] strings = test.split("/");
308     Assert.assertEquals(4, strings.length);
309 
310     Assert.assertEquals("this is a path", test.replaceAll("/", " "));
311     Assert.assertEquals("this is a path", test.replace("/", " "));
312   }
313 
314   public static void test_Math_abs_I() {
315     Assert.assertEquals(Math.abs(0), 0);
316     Assert.assertEquals(Math.abs(123), 123);
317     Assert.assertEquals(Math.abs(-123), 123);
318     Assert.assertEquals(Math.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
319     Assert.assertEquals(Math.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
320     Assert.assertEquals(Math.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
321     Assert.assertEquals(Math.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
322   }
323 
324   public static void test_Math_abs_J() {
325     Assert.assertEquals(Math.abs(0L), 0L);
326     Assert.assertEquals(Math.abs(123L), 123L);
327     Assert.assertEquals(Math.abs(-123L), 123L);
328     Assert.assertEquals(Math.abs(Long.MAX_VALUE), Long.MAX_VALUE);
329     Assert.assertEquals(Math.abs(Long.MIN_VALUE), Long.MIN_VALUE);
330     Assert.assertEquals(Math.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
331   }
332 
333   public static void test_Math_min_I() {
334     Assert.assertEquals(Math.min(0, 0), 0);
335     Assert.assertEquals(Math.min(1, 0), 0);
336     Assert.assertEquals(Math.min(0, 1), 0);
337     Assert.assertEquals(Math.min(0, Integer.MAX_VALUE), 0);
338     Assert.assertEquals(Math.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
339     Assert.assertEquals(Math.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
340   }
341 
342   public static void test_Math_max_I() {
343     Assert.assertEquals(Math.max(0, 0), 0);
344     Assert.assertEquals(Math.max(1, 0), 1);
345     Assert.assertEquals(Math.max(0, 1), 1);
346     Assert.assertEquals(Math.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
347     Assert.assertEquals(Math.max(Integer.MIN_VALUE, 0), 0);
348     Assert.assertEquals(Math.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
349   }
350 
351   public static void test_Math_min_J() {
352     Assert.assertEquals(Math.min(0L, 0L), 0L);
353     Assert.assertEquals(Math.min(1L, 0L), 0L);
354     Assert.assertEquals(Math.min(0L, 1L), 0L);
355     Assert.assertEquals(Math.min(0L, Long.MAX_VALUE), 0L);
356     Assert.assertEquals(Math.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
357     Assert.assertEquals(Math.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
358   }
359 
360   public static void test_Math_max_J() {
361     Assert.assertEquals(Math.max(0L, 0L), 0L);
362     Assert.assertEquals(Math.max(1L, 0L), 1L);
363     Assert.assertEquals(Math.max(0L, 1L), 1L);
364     Assert.assertEquals(Math.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
365     Assert.assertEquals(Math.max(Long.MIN_VALUE, 0L), 0L);
366     Assert.assertEquals(Math.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
367   }
368 
369   public static void test_Math_min_F() {
370     Assert.assertTrue(Float.isNaN(Math.min(1.0f, Float.NaN)));
371     Assert.assertTrue(Float.isNaN(Math.min(Float.NaN, 1.0f)));
372     Assert.assertEquals(Math.min(-0.0f, 0.0f), -0.0f);
373     Assert.assertEquals(Math.min(0.0f, -0.0f), -0.0f);
374     Assert.assertEquals(Math.min(-0.0f, -0.0f), -0.0f);
375     Assert.assertEquals(Math.min(0.0f, 0.0f), 0.0f);
376     Assert.assertEquals(Math.min(1.0f, 0.0f), 0.0f);
377     Assert.assertEquals(Math.min(0.0f, 1.0f), 0.0f);
378     Assert.assertEquals(Math.min(0.0f, Float.MAX_VALUE), 0.0f);
379     Assert.assertEquals(Math.min(Float.MIN_VALUE, 0.0f), 0.0f);
380     Assert.assertEquals(Math.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
381   }
382 
383   public static void test_Math_max_F() {
384     Assert.assertTrue(Float.isNaN(Math.max(1.0f, Float.NaN)));
385     Assert.assertTrue(Float.isNaN(Math.max(Float.NaN, 1.0f)));
386     Assert.assertEquals(Math.max(-0.0f, 0.0f), 0.0f);
387     Assert.assertEquals(Math.max(0.0f, -0.0f), 0.0f);
388     Assert.assertEquals(Math.max(-0.0f, -0.0f), -0.0f);
389     Assert.assertEquals(Math.max(0.0f, 0.0f), 0.0f);
390     Assert.assertEquals(Math.max(1.0f, 0.0f), 1.0f);
391     Assert.assertEquals(Math.max(0.0f, 1.0f), 1.0f);
392     Assert.assertEquals(Math.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
393     Assert.assertEquals(Math.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
394     Assert.assertEquals(Math.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
395   }
396 
397   public static void test_Math_min_D() {
398     Assert.assertTrue(Double.isNaN(Math.min(1.0d, Double.NaN)));
399     Assert.assertTrue(Double.isNaN(Math.min(Double.NaN, 1.0d)));
400     Assert.assertEquals(Math.min(-0.0d, 0.0d), -0.0d);
401     Assert.assertEquals(Math.min(0.0d, -0.0d), -0.0d);
402     Assert.assertEquals(Math.min(-0.0d, -0.0d), -0.0d);
403     Assert.assertEquals(Math.min(0.0d, 0.0d), 0.0d);
404     Assert.assertEquals(Math.min(1.0d, 0.0d), 0.0d);
405     Assert.assertEquals(Math.min(0.0d, 1.0d), 0.0d);
406     Assert.assertEquals(Math.min(0.0d, Double.MAX_VALUE), 0.0d);
407     Assert.assertEquals(Math.min(Double.MIN_VALUE, 0.0d), 0.0d);
408     Assert.assertEquals(Math.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
409   }
410 
411   public static void test_Math_max_D() {
412     Assert.assertTrue(Double.isNaN(Math.max(1.0d, Double.NaN)));
413     Assert.assertTrue(Double.isNaN(Math.max(Double.NaN, 1.0d)));
414     Assert.assertEquals(Math.max(-0.0d, 0.0d), 0.0d);
415     Assert.assertEquals(Math.max(0.0d, -0.0d), 0.0d);
416     Assert.assertEquals(Math.max(-0.0d, -0.0d), -0.0d);
417     Assert.assertEquals(Math.max(0.0d, 0.0d), 0.0d);
418     Assert.assertEquals(Math.max(1.0d, 0.0d), 1.0d);
419     Assert.assertEquals(Math.max(0.0d, 1.0d), 1.0d);
420     Assert.assertEquals(Math.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
421     Assert.assertEquals(Math.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
422     Assert.assertEquals(Math.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
423   }
424 
425   public static void test_Math_ceil() {
426     Assert.assertEquals(Math.ceil(+0.0), +0.0d, 0.0);
427     Assert.assertEquals(Math.ceil(-0.0), -0.0d, 0.0);
428     Assert.assertEquals(Math.ceil(-0.9), -0.0d, 0.0);
429     Assert.assertEquals(Math.ceil(-0.5), -0.0d, 0.0);
430     Assert.assertEquals(Math.ceil(0.0), -0.0d, 0.0);
431     Assert.assertEquals(Math.ceil(+2.0), +2.0d, 0.0);
432     Assert.assertEquals(Math.ceil(+2.1), +3.0d, 0.0);
433     Assert.assertEquals(Math.ceil(+2.5), +3.0d, 0.0);
434     Assert.assertEquals(Math.ceil(+2.9), +3.0d, 0.0);
435     Assert.assertEquals(Math.ceil(+3.0), +3.0d, 0.0);
436     Assert.assertEquals(Math.ceil(-2.0), -2.0d, 0.0);
437     Assert.assertEquals(Math.ceil(-2.1), -2.0d, 0.0);
438     Assert.assertEquals(Math.ceil(-2.5), -2.0d, 0.0);
439     Assert.assertEquals(Math.ceil(-2.9), -2.0d, 0.0);
440     Assert.assertEquals(Math.ceil(-3.0), -3.0d, 0.0);
441     Assert.assertEquals(Math.ceil(Double.NaN), Double.NaN, 0.0);
442     Assert.assertEquals(Math.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
443     Assert.assertEquals(Math.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
444   }
445 
446   public static void test_Math_floor() {
447     Assert.assertEquals(Math.floor(+0.0), +0.0d, 0.0);
448     Assert.assertEquals(Math.floor(-0.0), -0.0d, 0.0);
449     Assert.assertEquals(Math.floor(+2.0), +2.0d, 0.0);
450     Assert.assertEquals(Math.floor(+2.1), +2.0d, 0.0);
451     Assert.assertEquals(Math.floor(+2.5), +2.0d, 0.0);
452     Assert.assertEquals(Math.floor(+2.9), +2.0d, 0.0);
453     Assert.assertEquals(Math.floor(+3.0), +3.0d, 0.0);
454     Assert.assertEquals(Math.floor(-2.0), -2.0d, 0.0);
455     Assert.assertEquals(Math.floor(-2.1), -3.0d, 0.0);
456     Assert.assertEquals(Math.floor(-2.5), -3.0d, 0.0);
457     Assert.assertEquals(Math.floor(-2.9), -3.0d, 0.0);
458     Assert.assertEquals(Math.floor(-3.0), -3.0d, 0.0);
459     Assert.assertEquals(Math.floor(Double.NaN), Double.NaN, 0.0);
460     Assert.assertEquals(Math.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
461     Assert.assertEquals(Math.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
462   }
463 
464   public static void test_Math_rint() {
465     Assert.assertEquals(Math.rint(+0.0), +0.0d, 0.0);
466     Assert.assertEquals(Math.rint(-0.0), -0.0d, 0.0);
467     Assert.assertEquals(Math.rint(+2.0), +2.0d, 0.0);
468     Assert.assertEquals(Math.rint(+2.1), +2.0d, 0.0);
469     Assert.assertEquals(Math.rint(+2.5), +2.0d, 0.0);
470     Assert.assertEquals(Math.rint(+2.9), +3.0d, 0.0);
471     Assert.assertEquals(Math.rint(+3.0), +3.0d, 0.0);
472     Assert.assertEquals(Math.rint(-2.0), -2.0d, 0.0);
473     Assert.assertEquals(Math.rint(-2.1), -2.0d, 0.0);
474     Assert.assertEquals(Math.rint(-2.5), -2.0d, 0.0);
475     Assert.assertEquals(Math.rint(-2.9), -3.0d, 0.0);
476     Assert.assertEquals(Math.rint(-3.0), -3.0d, 0.0);
477     Assert.assertEquals(Math.rint(Double.NaN), Double.NaN, 0.0);
478     Assert.assertEquals(Math.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
479     Assert.assertEquals(Math.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
480   }
481 
482   public static void test_Math_round_D() {
483     Assert.assertEquals(Math.round(+0.0d), (long)+0.0);
484     Assert.assertEquals(Math.round(-0.0d), (long)+0.0);
485     Assert.assertEquals(Math.round(2.0d), 2l);
486     Assert.assertEquals(Math.round(2.1d), 2l);
487     Assert.assertEquals(Math.round(2.5d), 3l);
488     Assert.assertEquals(Math.round(2.9d), 3l);
489     Assert.assertEquals(Math.round(3.0d), 3l);
490     Assert.assertEquals(Math.round(-2.0d), -2l);
491     Assert.assertEquals(Math.round(-2.1d), -2l);
492     Assert.assertEquals(Math.round(-2.5d), -2l);
493     Assert.assertEquals(Math.round(-2.9d), -3l);
494     Assert.assertEquals(Math.round(-3.0d), -3l);
495     Assert.assertEquals(Math.round(0.49999999999999994d), 1l);
496     Assert.assertEquals(Math.round(Double.NaN), (long)+0.0d);
497     Assert.assertEquals(Math.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
498     Assert.assertEquals(Math.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
499     Assert.assertEquals(Math.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
500     Assert.assertEquals(Math.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
501   }
502 
503   public static void test_Math_round_F() {
504     Assert.assertEquals(Math.round(+0.0f), (int)+0.0);
505     Assert.assertEquals(Math.round(-0.0f), (int)+0.0);
506     Assert.assertEquals(Math.round(2.0f), 2);
507     Assert.assertEquals(Math.round(2.1f), 2);
508     Assert.assertEquals(Math.round(2.5f), 3);
509     Assert.assertEquals(Math.round(2.9f), 3);
510     Assert.assertEquals(Math.round(3.0f), 3);
511     Assert.assertEquals(Math.round(-2.0f), -2);
512     Assert.assertEquals(Math.round(-2.1f), -2);
513     Assert.assertEquals(Math.round(-2.5f), -2);
514     Assert.assertEquals(Math.round(-2.9f), -3);
515     Assert.assertEquals(Math.round(-3.0f), -3);
516     Assert.assertEquals(Math.round(Float.NaN), (int)+0.0f);
517     Assert.assertEquals(Math.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
518     Assert.assertEquals(Math.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
519     Assert.assertEquals(Math.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
520     Assert.assertEquals(Math.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
521   }
522 
523   public static void test_StrictMath_abs_I() {
524     Assert.assertEquals(StrictMath.abs(0), 0);
525     Assert.assertEquals(StrictMath.abs(123), 123);
526     Assert.assertEquals(StrictMath.abs(-123), 123);
527     Assert.assertEquals(StrictMath.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
528     Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
529     Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
530     Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
531   }
532 
533   public static void test_StrictMath_abs_J() {
534     Assert.assertEquals(StrictMath.abs(0L), 0L);
535     Assert.assertEquals(StrictMath.abs(123L), 123L);
536     Assert.assertEquals(StrictMath.abs(-123L), 123L);
537     Assert.assertEquals(StrictMath.abs(Long.MAX_VALUE), Long.MAX_VALUE);
538     Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE), Long.MIN_VALUE);
539     Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
540   }
541 
542   public static void test_StrictMath_min_I() {
543     Assert.assertEquals(StrictMath.min(0, 0), 0);
544     Assert.assertEquals(StrictMath.min(1, 0), 0);
545     Assert.assertEquals(StrictMath.min(0, 1), 0);
546     Assert.assertEquals(StrictMath.min(0, Integer.MAX_VALUE), 0);
547     Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
548     Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
549   }
550 
551   public static void test_StrictMath_max_I() {
552     Assert.assertEquals(StrictMath.max(0, 0), 0);
553     Assert.assertEquals(StrictMath.max(1, 0), 1);
554     Assert.assertEquals(StrictMath.max(0, 1), 1);
555     Assert.assertEquals(StrictMath.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
556     Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, 0), 0);
557     Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
558   }
559 
560   public static void test_StrictMath_min_J() {
561     Assert.assertEquals(StrictMath.min(0L, 0L), 0L);
562     Assert.assertEquals(StrictMath.min(1L, 0L), 0L);
563     Assert.assertEquals(StrictMath.min(0L, 1L), 0L);
564     Assert.assertEquals(StrictMath.min(0L, Long.MAX_VALUE), 0L);
565     Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
566     Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
567   }
568 
569   public static void test_StrictMath_max_J() {
570     Assert.assertEquals(StrictMath.max(0L, 0L), 0L);
571     Assert.assertEquals(StrictMath.max(1L, 0L), 1L);
572     Assert.assertEquals(StrictMath.max(0L, 1L), 1L);
573     Assert.assertEquals(StrictMath.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
574     Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, 0L), 0L);
575     Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
576   }
577 
578   public static void test_StrictMath_min_F() {
579     Assert.assertTrue(Float.isNaN(StrictMath.min(1.0f, Float.NaN)));
580     Assert.assertTrue(Float.isNaN(StrictMath.min(Float.NaN, 1.0f)));
581     Assert.assertEquals(StrictMath.min(-0.0f, 0.0f), -0.0f);
582     Assert.assertEquals(StrictMath.min(0.0f, -0.0f), -0.0f);
583     Assert.assertEquals(StrictMath.min(-0.0f, -0.0f), -0.0f);
584     Assert.assertEquals(StrictMath.min(0.0f, 0.0f), 0.0f);
585     Assert.assertEquals(StrictMath.min(1.0f, 0.0f), 0.0f);
586     Assert.assertEquals(StrictMath.min(0.0f, 1.0f), 0.0f);
587     Assert.assertEquals(StrictMath.min(0.0f, Float.MAX_VALUE), 0.0f);
588     Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, 0.0f), 0.0f);
589     Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
590   }
591 
592   public static void test_StrictMath_max_F() {
593     Assert.assertTrue(Float.isNaN(StrictMath.max(1.0f, Float.NaN)));
594     Assert.assertTrue(Float.isNaN(StrictMath.max(Float.NaN, 1.0f)));
595     Assert.assertEquals(StrictMath.max(-0.0f, 0.0f), 0.0f);
596     Assert.assertEquals(StrictMath.max(0.0f, -0.0f), 0.0f);
597     Assert.assertEquals(StrictMath.max(-0.0f, -0.0f), -0.0f);
598     Assert.assertEquals(StrictMath.max(0.0f, 0.0f), 0.0f);
599     Assert.assertEquals(StrictMath.max(1.0f, 0.0f), 1.0f);
600     Assert.assertEquals(StrictMath.max(0.0f, 1.0f), 1.0f);
601     Assert.assertEquals(StrictMath.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
602     Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
603     Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
604   }
605 
606   public static void test_StrictMath_min_D() {
607     Assert.assertTrue(Double.isNaN(StrictMath.min(1.0d, Double.NaN)));
608     Assert.assertTrue(Double.isNaN(StrictMath.min(Double.NaN, 1.0d)));
609     Assert.assertEquals(StrictMath.min(-0.0d, 0.0d), -0.0d);
610     Assert.assertEquals(StrictMath.min(0.0d, -0.0d), -0.0d);
611     Assert.assertEquals(StrictMath.min(-0.0d, -0.0d), -0.0d);
612     Assert.assertEquals(StrictMath.min(0.0d, 0.0d), 0.0d);
613     Assert.assertEquals(StrictMath.min(1.0d, 0.0d), 0.0d);
614     Assert.assertEquals(StrictMath.min(0.0d, 1.0d), 0.0d);
615     Assert.assertEquals(StrictMath.min(0.0d, Double.MAX_VALUE), 0.0d);
616     Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, 0.0d), 0.0d);
617     Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
618   }
619 
620   public static void test_StrictMath_max_D() {
621     Assert.assertTrue(Double.isNaN(StrictMath.max(1.0d, Double.NaN)));
622     Assert.assertTrue(Double.isNaN(StrictMath.max(Double.NaN, 1.0d)));
623     Assert.assertEquals(StrictMath.max(-0.0d, 0.0d), 0.0d);
624     Assert.assertEquals(StrictMath.max(0.0d, -0.0d), 0.0d);
625     Assert.assertEquals(StrictMath.max(-0.0d, -0.0d), -0.0d);
626     Assert.assertEquals(StrictMath.max(0.0d, 0.0d), 0.0d);
627     Assert.assertEquals(StrictMath.max(1.0d, 0.0d), 1.0d);
628     Assert.assertEquals(StrictMath.max(0.0d, 1.0d), 1.0d);
629     Assert.assertEquals(StrictMath.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
630     Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
631     Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
632   }
633 
634   public static void test_StrictMath_ceil() {
635     Assert.assertEquals(StrictMath.ceil(+0.0), +0.0d, 0.0);
636     Assert.assertEquals(StrictMath.ceil(-0.0), -0.0d, 0.0);
637     Assert.assertEquals(StrictMath.ceil(-0.9), -0.0d, 0.0);
638     Assert.assertEquals(StrictMath.ceil(-0.5), -0.0d, 0.0);
639     Assert.assertEquals(StrictMath.ceil(0.0), -0.0d, 0.0);
640     Assert.assertEquals(StrictMath.ceil(+2.0), +2.0d, 0.0);
641     Assert.assertEquals(StrictMath.ceil(+2.1), +3.0d, 0.0);
642     Assert.assertEquals(StrictMath.ceil(+2.5), +3.0d, 0.0);
643     Assert.assertEquals(StrictMath.ceil(+2.9), +3.0d, 0.0);
644     Assert.assertEquals(StrictMath.ceil(+3.0), +3.0d, 0.0);
645     Assert.assertEquals(StrictMath.ceil(-2.0), -2.0d, 0.0);
646     Assert.assertEquals(StrictMath.ceil(-2.1), -2.0d, 0.0);
647     Assert.assertEquals(StrictMath.ceil(-2.5), -2.0d, 0.0);
648     Assert.assertEquals(StrictMath.ceil(-2.9), -2.0d, 0.0);
649     Assert.assertEquals(StrictMath.ceil(-3.0), -3.0d, 0.0);
650     Assert.assertEquals(StrictMath.ceil(Double.NaN), Double.NaN, 0.0);
651     Assert.assertEquals(StrictMath.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
652     Assert.assertEquals(StrictMath.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
653   }
654 
655   public static void test_StrictMath_floor() {
656     Assert.assertEquals(StrictMath.floor(+0.0), +0.0d, 0.0);
657     Assert.assertEquals(StrictMath.floor(-0.0), -0.0d, 0.0);
658     Assert.assertEquals(StrictMath.floor(+2.0), +2.0d, 0.0);
659     Assert.assertEquals(StrictMath.floor(+2.1), +2.0d, 0.0);
660     Assert.assertEquals(StrictMath.floor(+2.5), +2.0d, 0.0);
661     Assert.assertEquals(StrictMath.floor(+2.9), +2.0d, 0.0);
662     Assert.assertEquals(StrictMath.floor(+3.0), +3.0d, 0.0);
663     Assert.assertEquals(StrictMath.floor(-2.0), -2.0d, 0.0);
664     Assert.assertEquals(StrictMath.floor(-2.1), -3.0d, 0.0);
665     Assert.assertEquals(StrictMath.floor(-2.5), -3.0d, 0.0);
666     Assert.assertEquals(StrictMath.floor(-2.9), -3.0d, 0.0);
667     Assert.assertEquals(StrictMath.floor(-3.0), -3.0d, 0.0);
668     Assert.assertEquals(StrictMath.floor(Double.NaN), Double.NaN, 0.0);
669     Assert.assertEquals(StrictMath.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
670     Assert.assertEquals(StrictMath.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
671   }
672 
673   public static void test_StrictMath_rint() {
674     Assert.assertEquals(StrictMath.rint(+0.0), +0.0d, 0.0);
675     Assert.assertEquals(StrictMath.rint(-0.0), -0.0d, 0.0);
676     Assert.assertEquals(StrictMath.rint(+2.0), +2.0d, 0.0);
677     Assert.assertEquals(StrictMath.rint(+2.1), +2.0d, 0.0);
678     Assert.assertEquals(StrictMath.rint(+2.5), +2.0d, 0.0);
679     Assert.assertEquals(StrictMath.rint(+2.9), +3.0d, 0.0);
680     Assert.assertEquals(StrictMath.rint(+3.0), +3.0d, 0.0);
681     Assert.assertEquals(StrictMath.rint(-2.0), -2.0d, 0.0);
682     Assert.assertEquals(StrictMath.rint(-2.1), -2.0d, 0.0);
683     Assert.assertEquals(StrictMath.rint(-2.5), -2.0d, 0.0);
684     Assert.assertEquals(StrictMath.rint(-2.9), -3.0d, 0.0);
685     Assert.assertEquals(StrictMath.rint(-3.0), -3.0d, 0.0);
686     Assert.assertEquals(StrictMath.rint(Double.NaN), Double.NaN, 0.0);
687     Assert.assertEquals(StrictMath.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
688     Assert.assertEquals(StrictMath.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
689   }
690 
691   public static void test_StrictMath_round_D() {
692     Assert.assertEquals(StrictMath.round(+0.0d), (long)+0.0);
693     Assert.assertEquals(StrictMath.round(-0.0d), (long)+0.0);
694     Assert.assertEquals(StrictMath.round(2.0d), 2l);
695     Assert.assertEquals(StrictMath.round(2.1d), 2l);
696     Assert.assertEquals(StrictMath.round(2.5d), 3l);
697     Assert.assertEquals(StrictMath.round(2.9d), 3l);
698     Assert.assertEquals(StrictMath.round(3.0d), 3l);
699     Assert.assertEquals(StrictMath.round(-2.0d), -2l);
700     Assert.assertEquals(StrictMath.round(-2.1d), -2l);
701     Assert.assertEquals(StrictMath.round(-2.5d), -2l);
702     Assert.assertEquals(StrictMath.round(-2.9d), -3l);
703     Assert.assertEquals(StrictMath.round(-3.0d), -3l);
704     Assert.assertEquals(StrictMath.round(0.49999999999999994d), 1l);
705     Assert.assertEquals(StrictMath.round(Double.NaN), (long)+0.0d);
706     Assert.assertEquals(StrictMath.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
707     Assert.assertEquals(StrictMath.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
708     Assert.assertEquals(StrictMath.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
709     Assert.assertEquals(StrictMath.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
710   }
711 
712   public static void test_StrictMath_round_F() {
713     Assert.assertEquals(StrictMath.round(+0.0f), (int)+0.0);
714     Assert.assertEquals(StrictMath.round(-0.0f), (int)+0.0);
715     Assert.assertEquals(StrictMath.round(2.0f), 2);
716     Assert.assertEquals(StrictMath.round(2.1f), 2);
717     Assert.assertEquals(StrictMath.round(2.5f), 3);
718     Assert.assertEquals(StrictMath.round(2.9f), 3);
719     Assert.assertEquals(StrictMath.round(3.0f), 3);
720     Assert.assertEquals(StrictMath.round(-2.0f), -2);
721     Assert.assertEquals(StrictMath.round(-2.1f), -2);
722     Assert.assertEquals(StrictMath.round(-2.5f), -2);
723     Assert.assertEquals(StrictMath.round(-2.9f), -3);
724     Assert.assertEquals(StrictMath.round(-3.0f), -3);
725     Assert.assertEquals(StrictMath.round(Float.NaN), (int)+0.0f);
726     Assert.assertEquals(StrictMath.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
727     Assert.assertEquals(StrictMath.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
728     Assert.assertEquals(StrictMath.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
729     Assert.assertEquals(StrictMath.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
730   }
731 
732   public static void test_Float_floatToRawIntBits() {
733     Assert.assertEquals(Float.floatToRawIntBits(-1.0f), 0xbf800000);
734     Assert.assertEquals(Float.floatToRawIntBits(0.0f), 0);
735     Assert.assertEquals(Float.floatToRawIntBits(1.0f), 0x3f800000);
736     Assert.assertEquals(Float.floatToRawIntBits(Float.NaN), 0x7fc00000);
737     Assert.assertEquals(Float.floatToRawIntBits(Float.POSITIVE_INFINITY), 0x7f800000);
738     Assert.assertEquals(Float.floatToRawIntBits(Float.NEGATIVE_INFINITY), 0xff800000);
739   }
740 
741   public static void test_Float_intBitsToFloat() {
742     Assert.assertEquals(Float.intBitsToFloat(0xbf800000), -1.0f);
743     Assert.assertEquals(Float.intBitsToFloat(0x00000000), 0.0f);
744     Assert.assertEquals(Float.intBitsToFloat(0x3f800000), 1.0f);
745     Assert.assertEquals(Float.intBitsToFloat(0x7fc00000), Float.NaN);
746     Assert.assertEquals(Float.intBitsToFloat(0x7f800000), Float.POSITIVE_INFINITY);
747     Assert.assertEquals(Float.intBitsToFloat(0xff800000), Float.NEGATIVE_INFINITY);
748   }
749 
750   public static void test_Double_doubleToRawLongBits() {
751     Assert.assertEquals(Double.doubleToRawLongBits(-1.0), 0xbff0000000000000L);
752     Assert.assertEquals(Double.doubleToRawLongBits(0.0), 0x0000000000000000L);
753     Assert.assertEquals(Double.doubleToRawLongBits(1.0), 0x3ff0000000000000L);
754     Assert.assertEquals(Double.doubleToRawLongBits(Double.NaN), 0x7ff8000000000000L);
755     Assert.assertEquals(Double.doubleToRawLongBits(Double.POSITIVE_INFINITY), 0x7ff0000000000000L);
756     Assert.assertEquals(Double.doubleToRawLongBits(Double.NEGATIVE_INFINITY), 0xfff0000000000000L);
757   }
758 
759   public static void test_Double_longBitsToDouble() {
760     Assert.assertEquals(Double.longBitsToDouble(0xbff0000000000000L), -1.0);
761     Assert.assertEquals(Double.longBitsToDouble(0x0000000000000000L), 0.0);
762     Assert.assertEquals(Double.longBitsToDouble(0x3ff0000000000000L), 1.0);
763     Assert.assertEquals(Double.longBitsToDouble(0x7ff8000000000000L), Double.NaN);
764     Assert.assertEquals(Double.longBitsToDouble(0x7ff0000000000000L), Double.POSITIVE_INFINITY);
765     Assert.assertEquals(Double.longBitsToDouble(0xfff0000000000000L), Double.NEGATIVE_INFINITY);
766   }
767 
768   public static void test_Short_reverseBytes() {
769       Assert.assertEquals(Short.reverseBytes((short)0x0000), (short)0x0000);
770       Assert.assertEquals(Short.reverseBytes((short)0xffff), (short)0xffff);
771       Assert.assertEquals(Short.reverseBytes((short)0x8000), (short)0x0080);
772       Assert.assertEquals(Short.reverseBytes((short)0x0080), (short)0x8000);
773       Assert.assertEquals(Short.reverseBytes((short)0x0123), (short)0x2301);
774       Assert.assertEquals(Short.reverseBytes((short)0x4567), (short)0x6745);
775       Assert.assertEquals(Short.reverseBytes((short)0x89ab), (short)0xab89);
776       Assert.assertEquals(Short.reverseBytes((short)0xcdef), (short)0xefcd);
777   }
778 
779   public static void test_Integer_reverseBytes() {
780       Assert.assertEquals(Integer.reverseBytes(0x00000000), 0x00000000);
781       Assert.assertEquals(Integer.reverseBytes(0xffffffff), 0xffffffff);
782       Assert.assertEquals(Integer.reverseBytes(0x80000000), 0x00000080);
783       Assert.assertEquals(Integer.reverseBytes(0x00000080), 0x80000000);
784       Assert.assertEquals(Integer.reverseBytes(0x01234567), 0x67452301);
785       Assert.assertEquals(Integer.reverseBytes(0x89abcdef), 0xefcdab89);
786   }
787 
788   public static void test_Long_reverseBytes() {
789       Assert.assertEquals(Long.reverseBytes(0x0000000000000000L), 0x0000000000000000L);
790       Assert.assertEquals(Long.reverseBytes(0xffffffffffffffffL), 0xffffffffffffffffL);
791       Assert.assertEquals(Long.reverseBytes(0x8000000000000000L), 0x0000000000000080L);
792       Assert.assertEquals(Long.reverseBytes(0x0000000000000080L), 0x8000000000000000L);
793       Assert.assertEquals(Long.reverseBytes(0x0123456789abcdefL), 0xefcdab8967452301L);
794   }
795 
796   public static void test_Integer_reverse() {
797     Assert.assertEquals(Integer.reverse(1), 0x80000000);
798     Assert.assertEquals(Integer.reverse(-1), 0xffffffff);
799     Assert.assertEquals(Integer.reverse(0), 0);
800     Assert.assertEquals(Integer.reverse(0x12345678), 0x1e6a2c48);
801     Assert.assertEquals(Integer.reverse(0x87654321), 0x84c2a6e1);
802     Assert.assertEquals(Integer.reverse(Integer.MAX_VALUE), 0xfffffffe);
803     Assert.assertEquals(Integer.reverse(Integer.MIN_VALUE), 1);
804   }
805 
806   public static void test_Long_reverse() {
807     Assert.assertEquals(Long.reverse(1L), 0x8000000000000000L);
808     Assert.assertEquals(Long.reverse(-1L), 0xffffffffffffffffL);
809     Assert.assertEquals(Long.reverse(0L), 0L);
810     Assert.assertEquals(Long.reverse(0x1234567812345678L), 0x1e6a2c481e6a2c48L);
811     Assert.assertEquals(Long.reverse(0x8765432187654321L), 0x84c2a6e184c2a6e1L);
812     Assert.assertEquals(Long.reverse(Long.MAX_VALUE), 0xfffffffffffffffeL);
813     Assert.assertEquals(Long.reverse(Long.MIN_VALUE), 1L);
814   }
815 
816   static Object runtime;
817   static Method address_of;
818   static Method new_non_movable_array;
819   static Method peek_byte;
820   static Method peek_short;
821   static Method peek_int;
822   static Method peek_long;
823   static Method poke_byte;
824   static Method poke_short;
825   static Method poke_int;
826   static Method poke_long;
827 
828   public static void initSupportMethodsForPeekPoke() throws Exception {
829     Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
830     Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
831     runtime = get_runtime.invoke(null);
832     address_of = vm_runtime.getDeclaredMethod("addressOf", Object.class);
833     new_non_movable_array = vm_runtime.getDeclaredMethod("newNonMovableArray", Class.class, Integer.TYPE);
834 
835     Class<?> io_memory = Class.forName("libcore.io.Memory");
836     peek_byte = io_memory.getDeclaredMethod("peekByte", Long.TYPE);
837     peek_int = io_memory.getDeclaredMethod("peekInt", Long.TYPE, Boolean.TYPE);
838     peek_short = io_memory.getDeclaredMethod("peekShort", Long.TYPE, Boolean.TYPE);
839     peek_long = io_memory.getDeclaredMethod("peekLong", Long.TYPE, Boolean.TYPE);
840     poke_byte = io_memory.getDeclaredMethod("pokeByte", Long.TYPE, Byte.TYPE);
841     poke_short = io_memory.getDeclaredMethod("pokeShort", Long.TYPE, Short.TYPE, Boolean.TYPE);
842     poke_int = io_memory.getDeclaredMethod("pokeInt", Long.TYPE, Integer.TYPE, Boolean.TYPE);
843     poke_long = io_memory.getDeclaredMethod("pokeLong", Long.TYPE, Long.TYPE, Boolean.TYPE);
844   }
845 
846   public static void test_Memory_peekByte() throws Exception {
847     byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
848     b[0] = 0x12;
849     b[1] = 0x11;
850     long address = (long)address_of.invoke(runtime, b);
851     Assert.assertEquals((byte)peek_byte.invoke(null, address), 0x12);
852     Assert.assertEquals((byte)peek_byte.invoke(null, address + 1), 0x11);
853   }
854 
855   public static void test_Memory_peekShort() throws Exception {
856     byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
857     b[0] = 0x13;
858     b[1] = 0x12;
859     b[2] = 0x11;
860     long address = (long)address_of.invoke(runtime, b);
861     Assert.assertEquals((short)peek_short.invoke(null, address, false), 0x1213);  // Aligned read
862     Assert.assertEquals((short)peek_short.invoke(null, address + 1, false), 0x1112);  // Unaligned read
863   }
864 
865   public static void test_Memory_peekInt() throws Exception {
866     byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
867     b[0] = 0x15;
868     b[1] = 0x14;
869     b[2] = 0x13;
870     b[3] = 0x12;
871     b[4] = 0x11;
872     long address = (long)address_of.invoke(runtime, b);
873     Assert.assertEquals((int)peek_int.invoke(null, address, false), 0x12131415);
874     Assert.assertEquals((int)peek_int.invoke(null, address + 1, false), 0x11121314);
875   }
876 
877   public static void test_Memory_peekLong() throws Exception {
878     byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
879     b[0] = 0x19;
880     b[1] = 0x18;
881     b[2] = 0x17;
882     b[3] = 0x16;
883     b[4] = 0x15;
884     b[5] = 0x14;
885     b[6] = 0x13;
886     b[7] = 0x12;
887     b[8] = 0x11;
888     long address = (long)address_of.invoke(runtime, b);
889     Assert.assertEquals((long)peek_long.invoke(null, address, false), 0x1213141516171819L);
890     Assert.assertEquals((long)peek_long.invoke(null, address + 1, false), 0x1112131415161718L);
891   }
892 
893   public static void test_Memory_pokeByte() throws Exception {
894     byte[] r = {0x11, 0x12};
895     byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
896     long address = (long)address_of.invoke(runtime, b);
897     poke_byte.invoke(null, address, (byte)0x11);
898     poke_byte.invoke(null, address + 1, (byte)0x12);
899     Assert.assertTrue(Arrays.equals(r, b));
900   }
901 
902   public static void test_Memory_pokeShort() throws Exception {
903     byte[] ra = {0x12, 0x11, 0x13};
904     byte[] ru = {0x12, 0x22, 0x21};
905     byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
906     long address = (long)address_of.invoke(runtime, b);
907 
908     // Aligned write
909     b[2] = 0x13;
910     poke_short.invoke(null, address, (short)0x1112, false);
911     Assert.assertTrue(Arrays.equals(ra, b));
912 
913     // Unaligned write
914     poke_short.invoke(null, address + 1, (short)0x2122, false);
915     Assert.assertTrue(Arrays.equals(ru, b));
916   }
917 
918   public static void test_Memory_pokeInt() throws Exception {
919     byte[] ra = {0x14, 0x13, 0x12, 0x11, 0x15};
920     byte[] ru = {0x14, 0x24, 0x23, 0x22, 0x21};
921     byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
922     long address = (long)address_of.invoke(runtime, b);
923 
924     b[4] = 0x15;
925     poke_int.invoke(null, address, (int)0x11121314, false);
926     Assert.assertTrue(Arrays.equals(ra, b));
927 
928     poke_int.invoke(null, address + 1, (int)0x21222324, false);
929     Assert.assertTrue(Arrays.equals(ru, b));
930   }
931 
932   public static void test_Memory_pokeLong() throws Exception {
933     byte[] ra = {0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x19};
934     byte[] ru = {0x18, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21};
935     byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
936     long address = (long)address_of.invoke(runtime, b);
937 
938     b[8] = 0x19;
939     poke_long.invoke(null, address, (long)0x1112131415161718L, false);
940     Assert.assertTrue(Arrays.equals(ra, b));
941 
942     poke_long.invoke(null, address + 1, (long)0x2122232425262728L, false);
943     Assert.assertTrue(Arrays.equals(ru, b));
944   }
945 }
946