blob: bf6c802a0ceac4e4ca7f7d06ad06e879ca53c7a1 [file] [log] [blame]
jeffhao5d1ac922011-09-29 17:41:15 -07001/*
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
jeffhao5d1ac922011-09-29 17:41:15 -070017import junit.framework.Assert;
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +070018import java.util.Arrays;
19import java.lang.reflect.Method;
jeffhao5d1ac922011-09-29 17:41:15 -070020
21public class Main {
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +070022 public static void main(String args[]) throws Exception {
Elliott Hughes28c384b2012-06-15 16:46:25 -070023 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();
Serban Constantinescu23abec92014-07-02 16:13:38 +010029 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();
Chao-ying Fuff87d7b2015-01-19 15:51:57 -080037 test_Math_sqrt();
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010038 test_Math_ceil();
39 test_Math_floor();
40 test_Math_rint();
41 test_Math_round_D();
42 test_Math_round_F();
Zheng Xua3fe7422014-07-09 14:03:15 +080043 test_Short_reverseBytes();
44 test_Integer_reverseBytes();
45 test_Long_reverseBytes();
Serban Constantinescu23abec92014-07-02 16:13:38 +010046 test_Integer_reverse();
47 test_Long_reverse();
Sebastien Hertzbf1442d2013-03-05 15:12:40 +010048 test_StrictMath_abs_I();
49 test_StrictMath_abs_J();
Serban Constantinescu23abec92014-07-02 16:13:38 +010050 test_StrictMath_min_I();
51 test_StrictMath_max_I();
52 test_StrictMath_min_J();
53 test_StrictMath_max_J();
54 test_StrictMath_min_F();
55 test_StrictMath_max_F();
56 test_StrictMath_min_D();
57 test_StrictMath_max_D();
Chao-ying Fuff87d7b2015-01-19 15:51:57 -080058 test_StrictMath_sqrt();
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +010059 test_StrictMath_ceil();
60 test_StrictMath_floor();
61 test_StrictMath_rint();
62 test_StrictMath_round_D();
63 test_StrictMath_round_F();
Elliott Hughes28c384b2012-06-15 16:46:25 -070064 test_String_charAt();
65 test_String_compareTo();
66 test_String_indexOf();
67 test_String_isEmpty();
68 test_String_length();
Andreas Gampe7a949612014-07-08 11:03:59 -070069 test_Thread_currentThread();
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +070070 initSupportMethodsForPeekPoke();
71 test_Memory_peekByte();
72 test_Memory_peekShort();
73 test_Memory_peekInt();
74 test_Memory_peekLong();
75 test_Memory_pokeByte();
76 test_Memory_pokeShort();
77 test_Memory_pokeInt();
78 test_Memory_pokeLong();
Elliott Hughes28c384b2012-06-15 16:46:25 -070079 }
80
Andreas Gampe7a949612014-07-08 11:03:59 -070081 /**
82 * Will test inlining Thread.currentThread().
83 */
84 public static void test_Thread_currentThread() {
85 // 1. Do not use result.
86 Thread.currentThread();
87
88 // 2. Result should not be null.
89 Assert.assertNotNull(Thread.currentThread());
90 }
91
Elliott Hughes28c384b2012-06-15 16:46:25 -070092 public static void test_String_length() {
93 String str0 = "";
94 String str1 = "x";
95 String str80 = "01234567890123456789012345678901234567890123456789012345678901234567890123456789";
96
97 Assert.assertEquals(str0.length(), 0);
98 Assert.assertEquals(str1.length(), 1);
99 Assert.assertEquals(str80.length(), 80);
100
101 String strNull = null;
102 try {
103 strNull.length();
104 Assert.fail();
105 } catch (NullPointerException expected) {
106 }
107 }
108
109 public static void test_String_isEmpty() {
110 String str0 = "";
111 String str1 = "x";
112
113 Assert.assertTrue(str0.isEmpty());
114 Assert.assertFalse(str1.isEmpty());
115
116 String strNull = null;
117 try {
118 strNull.isEmpty();
119 Assert.fail();
120 } catch (NullPointerException expected) {
121 }
122 }
123
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800124 // Break up the charAt tests. The optimizing compiler doesn't optimize methods with try-catch yet,
125 // so we need to separate out the tests that are expected to throw exception
126
Elliott Hughes28c384b2012-06-15 16:46:25 -0700127 public static void test_String_charAt() {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800128 String testStr = "Now is the time to test some stuff";
Elliott Hughes28c384b2012-06-15 16:46:25 -0700129
Andreas Gampe878d58c2015-01-15 23:24:00 -0800130 Assert.assertEquals(testStr.length() - 1, 33); // 33 = testStr.length()-1 as a constant.
131 Assert.assertEquals('f', testStr.charAt(33));
Elliott Hughes28c384b2012-06-15 16:46:25 -0700132
Andreas Gampe878d58c2015-01-15 23:24:00 -0800133 test_String_charAt(testStr, 'N', 'o', ' ', 'f');
134 test_String_charAt(testStr.substring(3,15), ' ', 'i', 'm', 'e');
135 }
136 public static void test_String_charAt(String testStr, char a, char b, char c, char d) {
137 Assert.assertEquals(a, testStr.charAt(0));
138 Assert.assertEquals(b, testStr.charAt(1));
139 Assert.assertEquals(c, testStr.charAt(10));
140 Assert.assertEquals(d, testStr.charAt(testStr.length()-1));
141
142 test_String_charAtExc(testStr);
143 test_String_charAtExc2(testStr);
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800144 }
145
Andreas Gampe878d58c2015-01-15 23:24:00 -0800146 private static void test_String_charAtExc(String testStr) {
Elliott Hughes28c384b2012-06-15 16:46:25 -0700147 try {
148 testStr.charAt(-1);
149 Assert.fail();
150 } catch (StringIndexOutOfBoundsException expected) {
151 }
152 try {
153 testStr.charAt(80);
154 Assert.fail();
155 } catch (StringIndexOutOfBoundsException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700156 }
Vladimir Marko00ca8472015-01-26 14:06:46 +0000157 try {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800158 if (testStr.length() == 34) {
159 testStr.charAt(34); // 34 = "Now is the time to test some stuff".length()
160 } else {
161 Assert.assertEquals(testStr.length(), 12); // 12 = " is the time".length()
162 testStr.charAt(12);
163 }
Vladimir Marko00ca8472015-01-26 14:06:46 +0000164 Assert.fail();
165 } catch (StringIndexOutOfBoundsException expected) {
166 }
167 try {
168 test_String_charAt_inner(testStr, -1);
169 Assert.fail();
170 } catch (StringIndexOutOfBoundsException expected) {
171 }
172 try {
173 test_String_charAt_inner(testStr, 80);
174 Assert.fail();
175 } catch (StringIndexOutOfBoundsException expected) {
176 }
177 try {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800178 if (testStr.length() == 34) {
179 // 34 = "Now is the time to test some stuff".length()
180 test_String_charAt_inner(testStr, 34);
181 } else {
182 Assert.assertEquals(testStr.length(), 12); // 12 = " is the time".length()
183 test_String_charAt_inner(testStr, 12);
184 }
Vladimir Marko00ca8472015-01-26 14:06:46 +0000185 Assert.fail();
186 } catch (StringIndexOutOfBoundsException expected) {
187 }
188
189 String strEmpty = "";
190 try {
191 strEmpty.charAt(0);
192 Assert.fail();
193 } catch (StringIndexOutOfBoundsException expected) {
194 }
jeffhao5d1ac922011-09-29 17:41:15 -0700195
Elliott Hughes28c384b2012-06-15 16:46:25 -0700196 String strNull = null;
197 try {
198 strNull.charAt(0);
199 Assert.fail();
200 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700201 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700202 }
jeffhao5d1ac922011-09-29 17:41:15 -0700203
Vladimir Marko00ca8472015-01-26 14:06:46 +0000204 private static char test_String_charAt_inner(String s, int index) {
205 // Using non-constant index here (assuming that this method wasn't inlined).
206 return s.charAt(index);
207 }
208
Andreas Gampe878d58c2015-01-15 23:24:00 -0800209 private static void test_String_charAtExc2(String testStr) {
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800210 try {
Andreas Gampe878d58c2015-01-15 23:24:00 -0800211 test_String_charAtExc3(testStr);
212 Assert.fail();
213 } catch (StringIndexOutOfBoundsException expected) {
214 }
215 try {
216 test_String_charAtExc4(testStr);
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800217 Assert.fail();
218 } catch (StringIndexOutOfBoundsException expected) {
219 }
220 }
221
Andreas Gampe878d58c2015-01-15 23:24:00 -0800222 private static void test_String_charAtExc3(String testStr) {
Andreas Gampe71fb52f2014-12-29 17:43:08 -0800223 Assert.assertEquals('N', testStr.charAt(-1));
224 }
225
Andreas Gampe878d58c2015-01-15 23:24:00 -0800226 private static void test_String_charAtExc4(String testStr) {
227 Assert.assertEquals('N', testStr.charAt(100));
228 }
229
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700230 static int start;
Alexei Zavjalova1758d82014-04-17 01:55:43 +0700231 private static int[] negIndex = { -100000 };
Elliott Hughes28c384b2012-06-15 16:46:25 -0700232 public static void test_String_indexOf() {
233 String str0 = "";
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700234 String str1 = "/";
Elliott Hughes28c384b2012-06-15 16:46:25 -0700235 String str3 = "abc";
236 String str10 = "abcdefghij";
237 String str40 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabc";
jeffhao5d1ac922011-09-29 17:41:15 -0700238
Elliott Hughes28c384b2012-06-15 16:46:25 -0700239 int supplementaryChar = 0x20b9f;
240 String surrogatePair = "\ud842\udf9f";
241 String stringWithSurrogates = "hello " + surrogatePair + " world";
jeffhao5d1ac922011-09-29 17:41:15 -0700242
Elliott Hughes28c384b2012-06-15 16:46:25 -0700243 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar), "hello ".length());
244 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 2), "hello ".length());
245 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 6), 6);
246 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 7), -1);
jeffhao5d1ac922011-09-29 17:41:15 -0700247
Elliott Hughes28c384b2012-06-15 16:46:25 -0700248 Assert.assertEquals(str0.indexOf('a'), -1);
249 Assert.assertEquals(str3.indexOf('a'), 0);
250 Assert.assertEquals(str3.indexOf('b'), 1);
251 Assert.assertEquals(str3.indexOf('c'), 2);
252 Assert.assertEquals(str10.indexOf('j'), 9);
253 Assert.assertEquals(str40.indexOf('a'), 0);
254 Assert.assertEquals(str40.indexOf('b'), 38);
255 Assert.assertEquals(str40.indexOf('c'), 39);
256 Assert.assertEquals(str0.indexOf('a',20), -1);
257 Assert.assertEquals(str0.indexOf('a',0), -1);
258 Assert.assertEquals(str0.indexOf('a',-1), -1);
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700259 Assert.assertEquals(str1.indexOf('/',++start), -1);
Alexei Zavjalova1758d82014-04-17 01:55:43 +0700260 Assert.assertEquals(str1.indexOf('a',negIndex[0]), -1);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700261 Assert.assertEquals(str3.indexOf('a',0), 0);
262 Assert.assertEquals(str3.indexOf('a',1), -1);
263 Assert.assertEquals(str3.indexOf('a',1234), -1);
264 Assert.assertEquals(str3.indexOf('b',0), 1);
265 Assert.assertEquals(str3.indexOf('b',1), 1);
266 Assert.assertEquals(str3.indexOf('c',2), 2);
267 Assert.assertEquals(str10.indexOf('j',5), 9);
268 Assert.assertEquals(str10.indexOf('j',9), 9);
269 Assert.assertEquals(str40.indexOf('a',10), 10);
270 Assert.assertEquals(str40.indexOf('b',40), -1);
271
272 String strNull = null;
273 try {
274 strNull.indexOf('a');
275 Assert.fail();
276 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700277 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700278 try {
279 strNull.indexOf('a', 0);
280 Assert.fail();
281 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700282 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700283 try {
284 strNull.indexOf('a', -1);
285 Assert.fail();
286 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700287 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700288 }
jeffhao5d1ac922011-09-29 17:41:15 -0700289
Elliott Hughes28c384b2012-06-15 16:46:25 -0700290 public static void test_String_compareTo() {
291 String test = "0123456789";
292 String test1 = new String("0123456789"); // different object
293 String test2 = new String("0123456780"); // different value
294 String offset = new String("xxx0123456789yyy");
295 String sub = offset.substring(3, 13);
296 String str32 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
297 String str33 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxy";
298 String lc = "abcdefg";
299 String uc = "ABCDEFG";
300 Object blah = new Object();
301
302 Assert.assertTrue(lc.toUpperCase().equals(uc));
303
304 Assert.assertEquals(str32.compareTo(str33), -1);
305 Assert.assertEquals(str33.compareTo(str32), 1);
306
307 Assert.assertTrue(test.equals(test));
308 Assert.assertTrue(test.equals(test1));
309 Assert.assertFalse(test.equals(test2));
310
311 Assert.assertEquals(test.compareTo(test1), 0);
312 Assert.assertTrue(test1.compareTo(test2) > 0);
313 Assert.assertTrue(test2.compareTo(test1) < 0);
314
315 // Compare string with a nonzero offset, in left/right side.
316 Assert.assertEquals(test.compareTo(sub), 0);
317 Assert.assertEquals(sub.compareTo(test), 0);
318 Assert.assertTrue(test.equals(sub));
319 Assert.assertTrue(sub.equals(test));
320 // Same base, one is a substring.
321 Assert.assertFalse(offset.equals(sub));
322 Assert.assertFalse(sub.equals(offset));
323 // Wrong class.
324 Assert.assertFalse(test.equals(blah));
325
326 // Null lhs - throw.
327 try {
328 test.compareTo(null);
329 Assert.fail("didn't get expected npe");
330 } catch (NullPointerException npe) {
331 }
332 // Null rhs - okay.
333 Assert.assertFalse(test.equals(null));
334
335 test = test.substring(1);
336 Assert.assertTrue(test.equals("123456789"));
337 Assert.assertFalse(test.equals(test1));
338
339 test = test.substring(1);
340 Assert.assertTrue(test.equals("23456789"));
341
342 test = test.substring(1);
343 Assert.assertTrue(test.equals("3456789"));
344
345 test = test.substring(1);
346 Assert.assertTrue(test.equals("456789"));
347
348 test = test.substring(3,5);
349 Assert.assertTrue(test.equals("78"));
350
351 test = "this/is/a/path";
352 String[] strings = test.split("/");
353 Assert.assertEquals(4, strings.length);
354
355 Assert.assertEquals("this is a path", test.replaceAll("/", " "));
356 Assert.assertEquals("this is a path", test.replace("/", " "));
357 }
358
359 public static void test_Math_abs_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800360 Math.abs(-1);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700361 Assert.assertEquals(Math.abs(0), 0);
362 Assert.assertEquals(Math.abs(123), 123);
363 Assert.assertEquals(Math.abs(-123), 123);
364 Assert.assertEquals(Math.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
365 Assert.assertEquals(Math.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
366 Assert.assertEquals(Math.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100367 Assert.assertEquals(Math.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700368 }
369
370 public static void test_Math_abs_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800371 Math.abs(-1L);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700372 Assert.assertEquals(Math.abs(0L), 0L);
373 Assert.assertEquals(Math.abs(123L), 123L);
374 Assert.assertEquals(Math.abs(-123L), 123L);
375 Assert.assertEquals(Math.abs(Long.MAX_VALUE), Long.MAX_VALUE);
376 Assert.assertEquals(Math.abs(Long.MIN_VALUE), Long.MIN_VALUE);
377 Assert.assertEquals(Math.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
378 }
379
Serban Constantinescu23abec92014-07-02 16:13:38 +0100380 public static void test_Math_min_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800381 Math.min(1, 0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700382 Assert.assertEquals(Math.min(0, 0), 0);
383 Assert.assertEquals(Math.min(1, 0), 0);
384 Assert.assertEquals(Math.min(0, 1), 0);
385 Assert.assertEquals(Math.min(0, Integer.MAX_VALUE), 0);
386 Assert.assertEquals(Math.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
387 Assert.assertEquals(Math.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
388 }
389
Serban Constantinescu23abec92014-07-02 16:13:38 +0100390 public static void test_Math_max_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800391 Math.max(1, 0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700392 Assert.assertEquals(Math.max(0, 0), 0);
393 Assert.assertEquals(Math.max(1, 0), 1);
394 Assert.assertEquals(Math.max(0, 1), 1);
395 Assert.assertEquals(Math.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
396 Assert.assertEquals(Math.max(Integer.MIN_VALUE, 0), 0);
397 Assert.assertEquals(Math.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
398 }
399
Serban Constantinescu23abec92014-07-02 16:13:38 +0100400 public static void test_Math_min_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800401 Math.min(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100402 Assert.assertEquals(Math.min(0L, 0L), 0L);
403 Assert.assertEquals(Math.min(1L, 0L), 0L);
404 Assert.assertEquals(Math.min(0L, 1L), 0L);
405 Assert.assertEquals(Math.min(0L, Long.MAX_VALUE), 0L);
406 Assert.assertEquals(Math.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
407 Assert.assertEquals(Math.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
408 }
409
410 public static void test_Math_max_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800411 Math.max(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100412 Assert.assertEquals(Math.max(0L, 0L), 0L);
413 Assert.assertEquals(Math.max(1L, 0L), 1L);
414 Assert.assertEquals(Math.max(0L, 1L), 1L);
415 Assert.assertEquals(Math.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
416 Assert.assertEquals(Math.max(Long.MIN_VALUE, 0L), 0L);
417 Assert.assertEquals(Math.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
418 }
419
420 public static void test_Math_min_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800421 Math.min(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700422 Assert.assertTrue(Float.isNaN(Math.min(1.0f, Float.NaN)));
423 Assert.assertTrue(Float.isNaN(Math.min(Float.NaN, 1.0f)));
424 Assert.assertEquals(Math.min(-0.0f, 0.0f), -0.0f);
425 Assert.assertEquals(Math.min(0.0f, -0.0f), -0.0f);
426 Assert.assertEquals(Math.min(-0.0f, -0.0f), -0.0f);
427 Assert.assertEquals(Math.min(0.0f, 0.0f), 0.0f);
428 Assert.assertEquals(Math.min(1.0f, 0.0f), 0.0f);
429 Assert.assertEquals(Math.min(0.0f, 1.0f), 0.0f);
430 Assert.assertEquals(Math.min(0.0f, Float.MAX_VALUE), 0.0f);
431 Assert.assertEquals(Math.min(Float.MIN_VALUE, 0.0f), 0.0f);
432 Assert.assertEquals(Math.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100433 }
434
435 public static void test_Math_max_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800436 Math.max(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700437 Assert.assertTrue(Float.isNaN(Math.max(1.0f, Float.NaN)));
438 Assert.assertTrue(Float.isNaN(Math.max(Float.NaN, 1.0f)));
439 Assert.assertEquals(Math.max(-0.0f, 0.0f), 0.0f);
440 Assert.assertEquals(Math.max(0.0f, -0.0f), 0.0f);
441 Assert.assertEquals(Math.max(-0.0f, -0.0f), -0.0f);
442 Assert.assertEquals(Math.max(0.0f, 0.0f), 0.0f);
443 Assert.assertEquals(Math.max(1.0f, 0.0f), 1.0f);
444 Assert.assertEquals(Math.max(0.0f, 1.0f), 1.0f);
445 Assert.assertEquals(Math.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
446 Assert.assertEquals(Math.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
447 Assert.assertEquals(Math.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100448 }
449
450 public static void test_Math_min_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800451 Math.min(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700452 Assert.assertTrue(Double.isNaN(Math.min(1.0d, Double.NaN)));
453 Assert.assertTrue(Double.isNaN(Math.min(Double.NaN, 1.0d)));
454 Assert.assertEquals(Math.min(-0.0d, 0.0d), -0.0d);
455 Assert.assertEquals(Math.min(0.0d, -0.0d), -0.0d);
456 Assert.assertEquals(Math.min(-0.0d, -0.0d), -0.0d);
457 Assert.assertEquals(Math.min(0.0d, 0.0d), 0.0d);
458 Assert.assertEquals(Math.min(1.0d, 0.0d), 0.0d);
459 Assert.assertEquals(Math.min(0.0d, 1.0d), 0.0d);
460 Assert.assertEquals(Math.min(0.0d, Double.MAX_VALUE), 0.0d);
461 Assert.assertEquals(Math.min(Double.MIN_VALUE, 0.0d), 0.0d);
462 Assert.assertEquals(Math.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100463 }
464
465 public static void test_Math_max_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800466 Math.max(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700467 Assert.assertTrue(Double.isNaN(Math.max(1.0d, Double.NaN)));
468 Assert.assertTrue(Double.isNaN(Math.max(Double.NaN, 1.0d)));
469 Assert.assertEquals(Math.max(-0.0d, 0.0d), 0.0d);
470 Assert.assertEquals(Math.max(0.0d, -0.0d), 0.0d);
471 Assert.assertEquals(Math.max(-0.0d, -0.0d), -0.0d);
472 Assert.assertEquals(Math.max(0.0d, 0.0d), 0.0d);
473 Assert.assertEquals(Math.max(1.0d, 0.0d), 1.0d);
474 Assert.assertEquals(Math.max(0.0d, 1.0d), 1.0d);
475 Assert.assertEquals(Math.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
476 Assert.assertEquals(Math.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
477 Assert.assertEquals(Math.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100478 }
479
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800480 public static void test_Math_sqrt() {
481 Math.sqrt(+4.0);
482 Assert.assertEquals(Math.sqrt(+4.0), +2.0d, 0.0);
483 Assert.assertEquals(Math.sqrt(+49.0), +7.0d, 0.0);
484 Assert.assertEquals(Math.sqrt(+1.44), +1.2d, 0.0);
485 }
486
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100487 public static void test_Math_ceil() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800488 Math.ceil(-0.9);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100489 Assert.assertEquals(Math.ceil(+0.0), +0.0d, 0.0);
490 Assert.assertEquals(Math.ceil(-0.0), -0.0d, 0.0);
491 Assert.assertEquals(Math.ceil(-0.9), -0.0d, 0.0);
492 Assert.assertEquals(Math.ceil(-0.5), -0.0d, 0.0);
493 Assert.assertEquals(Math.ceil(0.0), -0.0d, 0.0);
494 Assert.assertEquals(Math.ceil(+2.0), +2.0d, 0.0);
495 Assert.assertEquals(Math.ceil(+2.1), +3.0d, 0.0);
496 Assert.assertEquals(Math.ceil(+2.5), +3.0d, 0.0);
497 Assert.assertEquals(Math.ceil(+2.9), +3.0d, 0.0);
498 Assert.assertEquals(Math.ceil(+3.0), +3.0d, 0.0);
499 Assert.assertEquals(Math.ceil(-2.0), -2.0d, 0.0);
500 Assert.assertEquals(Math.ceil(-2.1), -2.0d, 0.0);
501 Assert.assertEquals(Math.ceil(-2.5), -2.0d, 0.0);
502 Assert.assertEquals(Math.ceil(-2.9), -2.0d, 0.0);
503 Assert.assertEquals(Math.ceil(-3.0), -3.0d, 0.0);
504 Assert.assertEquals(Math.ceil(Double.NaN), Double.NaN, 0.0);
505 Assert.assertEquals(Math.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
506 Assert.assertEquals(Math.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
507 }
508
509 public static void test_Math_floor() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800510 Math.floor(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100511 Assert.assertEquals(Math.floor(+0.0), +0.0d, 0.0);
512 Assert.assertEquals(Math.floor(-0.0), -0.0d, 0.0);
513 Assert.assertEquals(Math.floor(+2.0), +2.0d, 0.0);
514 Assert.assertEquals(Math.floor(+2.1), +2.0d, 0.0);
515 Assert.assertEquals(Math.floor(+2.5), +2.0d, 0.0);
516 Assert.assertEquals(Math.floor(+2.9), +2.0d, 0.0);
517 Assert.assertEquals(Math.floor(+3.0), +3.0d, 0.0);
518 Assert.assertEquals(Math.floor(-2.0), -2.0d, 0.0);
519 Assert.assertEquals(Math.floor(-2.1), -3.0d, 0.0);
520 Assert.assertEquals(Math.floor(-2.5), -3.0d, 0.0);
521 Assert.assertEquals(Math.floor(-2.9), -3.0d, 0.0);
522 Assert.assertEquals(Math.floor(-3.0), -3.0d, 0.0);
523 Assert.assertEquals(Math.floor(Double.NaN), Double.NaN, 0.0);
524 Assert.assertEquals(Math.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
525 Assert.assertEquals(Math.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
526 }
527
528 public static void test_Math_rint() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800529 Math.rint(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100530 Assert.assertEquals(Math.rint(+0.0), +0.0d, 0.0);
531 Assert.assertEquals(Math.rint(-0.0), -0.0d, 0.0);
532 Assert.assertEquals(Math.rint(+2.0), +2.0d, 0.0);
533 Assert.assertEquals(Math.rint(+2.1), +2.0d, 0.0);
534 Assert.assertEquals(Math.rint(+2.5), +2.0d, 0.0);
535 Assert.assertEquals(Math.rint(+2.9), +3.0d, 0.0);
536 Assert.assertEquals(Math.rint(+3.0), +3.0d, 0.0);
537 Assert.assertEquals(Math.rint(-2.0), -2.0d, 0.0);
538 Assert.assertEquals(Math.rint(-2.1), -2.0d, 0.0);
539 Assert.assertEquals(Math.rint(-2.5), -2.0d, 0.0);
540 Assert.assertEquals(Math.rint(-2.9), -3.0d, 0.0);
541 Assert.assertEquals(Math.rint(-3.0), -3.0d, 0.0);
542 Assert.assertEquals(Math.rint(Double.NaN), Double.NaN, 0.0);
543 Assert.assertEquals(Math.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
544 Assert.assertEquals(Math.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
545 }
546
547 public static void test_Math_round_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800548 Math.round(2.1d);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100549 Assert.assertEquals(Math.round(+0.0d), (long)+0.0);
550 Assert.assertEquals(Math.round(-0.0d), (long)+0.0);
551 Assert.assertEquals(Math.round(2.0d), 2l);
552 Assert.assertEquals(Math.round(2.1d), 2l);
553 Assert.assertEquals(Math.round(2.5d), 3l);
554 Assert.assertEquals(Math.round(2.9d), 3l);
555 Assert.assertEquals(Math.round(3.0d), 3l);
556 Assert.assertEquals(Math.round(-2.0d), -2l);
557 Assert.assertEquals(Math.round(-2.1d), -2l);
558 Assert.assertEquals(Math.round(-2.5d), -2l);
559 Assert.assertEquals(Math.round(-2.9d), -3l);
560 Assert.assertEquals(Math.round(-3.0d), -3l);
561 Assert.assertEquals(Math.round(0.49999999999999994d), 1l);
562 Assert.assertEquals(Math.round(Double.NaN), (long)+0.0d);
563 Assert.assertEquals(Math.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
564 Assert.assertEquals(Math.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
565 Assert.assertEquals(Math.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
566 Assert.assertEquals(Math.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
567 }
568
569 public static void test_Math_round_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800570 Math.round(2.1f);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100571 Assert.assertEquals(Math.round(+0.0f), (int)+0.0);
572 Assert.assertEquals(Math.round(-0.0f), (int)+0.0);
573 Assert.assertEquals(Math.round(2.0f), 2);
574 Assert.assertEquals(Math.round(2.1f), 2);
575 Assert.assertEquals(Math.round(2.5f), 3);
576 Assert.assertEquals(Math.round(2.9f), 3);
577 Assert.assertEquals(Math.round(3.0f), 3);
578 Assert.assertEquals(Math.round(-2.0f), -2);
579 Assert.assertEquals(Math.round(-2.1f), -2);
580 Assert.assertEquals(Math.round(-2.5f), -2);
581 Assert.assertEquals(Math.round(-2.9f), -3);
582 Assert.assertEquals(Math.round(-3.0f), -3);
583 Assert.assertEquals(Math.round(Float.NaN), (int)+0.0f);
584 Assert.assertEquals(Math.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
585 Assert.assertEquals(Math.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
586 Assert.assertEquals(Math.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
587 Assert.assertEquals(Math.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
588 }
589
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100590 public static void test_StrictMath_abs_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800591 StrictMath.abs(-1);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100592 Assert.assertEquals(StrictMath.abs(0), 0);
593 Assert.assertEquals(StrictMath.abs(123), 123);
594 Assert.assertEquals(StrictMath.abs(-123), 123);
595 Assert.assertEquals(StrictMath.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
596 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
597 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
598 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
599 }
600
601 public static void test_StrictMath_abs_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800602 StrictMath.abs(-1L);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100603 Assert.assertEquals(StrictMath.abs(0L), 0L);
604 Assert.assertEquals(StrictMath.abs(123L), 123L);
605 Assert.assertEquals(StrictMath.abs(-123L), 123L);
606 Assert.assertEquals(StrictMath.abs(Long.MAX_VALUE), Long.MAX_VALUE);
607 Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE), Long.MIN_VALUE);
608 Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
609 }
610
Serban Constantinescu23abec92014-07-02 16:13:38 +0100611 public static void test_StrictMath_min_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800612 StrictMath.min(1, 0);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100613 Assert.assertEquals(StrictMath.min(0, 0), 0);
614 Assert.assertEquals(StrictMath.min(1, 0), 0);
615 Assert.assertEquals(StrictMath.min(0, 1), 0);
616 Assert.assertEquals(StrictMath.min(0, Integer.MAX_VALUE), 0);
617 Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
618 Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
619 }
620
Serban Constantinescu23abec92014-07-02 16:13:38 +0100621 public static void test_StrictMath_max_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800622 StrictMath.max(1, 0);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100623 Assert.assertEquals(StrictMath.max(0, 0), 0);
624 Assert.assertEquals(StrictMath.max(1, 0), 1);
625 Assert.assertEquals(StrictMath.max(0, 1), 1);
626 Assert.assertEquals(StrictMath.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
627 Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, 0), 0);
628 Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
629 }
630
Serban Constantinescu23abec92014-07-02 16:13:38 +0100631 public static void test_StrictMath_min_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800632 StrictMath.min(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100633 Assert.assertEquals(StrictMath.min(0L, 0L), 0L);
634 Assert.assertEquals(StrictMath.min(1L, 0L), 0L);
635 Assert.assertEquals(StrictMath.min(0L, 1L), 0L);
636 Assert.assertEquals(StrictMath.min(0L, Long.MAX_VALUE), 0L);
637 Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
638 Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
639 }
640
641 public static void test_StrictMath_max_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800642 StrictMath.max(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100643 Assert.assertEquals(StrictMath.max(0L, 0L), 0L);
644 Assert.assertEquals(StrictMath.max(1L, 0L), 1L);
645 Assert.assertEquals(StrictMath.max(0L, 1L), 1L);
646 Assert.assertEquals(StrictMath.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
647 Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, 0L), 0L);
648 Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
649 }
650
651 public static void test_StrictMath_min_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800652 StrictMath.min(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700653 Assert.assertTrue(Float.isNaN(StrictMath.min(1.0f, Float.NaN)));
654 Assert.assertTrue(Float.isNaN(StrictMath.min(Float.NaN, 1.0f)));
655 Assert.assertEquals(StrictMath.min(-0.0f, 0.0f), -0.0f);
656 Assert.assertEquals(StrictMath.min(0.0f, -0.0f), -0.0f);
657 Assert.assertEquals(StrictMath.min(-0.0f, -0.0f), -0.0f);
658 Assert.assertEquals(StrictMath.min(0.0f, 0.0f), 0.0f);
659 Assert.assertEquals(StrictMath.min(1.0f, 0.0f), 0.0f);
660 Assert.assertEquals(StrictMath.min(0.0f, 1.0f), 0.0f);
661 Assert.assertEquals(StrictMath.min(0.0f, Float.MAX_VALUE), 0.0f);
662 Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, 0.0f), 0.0f);
663 Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100664 }
665
666 public static void test_StrictMath_max_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800667 StrictMath.max(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700668 Assert.assertTrue(Float.isNaN(StrictMath.max(1.0f, Float.NaN)));
669 Assert.assertTrue(Float.isNaN(StrictMath.max(Float.NaN, 1.0f)));
670 Assert.assertEquals(StrictMath.max(-0.0f, 0.0f), 0.0f);
671 Assert.assertEquals(StrictMath.max(0.0f, -0.0f), 0.0f);
672 Assert.assertEquals(StrictMath.max(-0.0f, -0.0f), -0.0f);
673 Assert.assertEquals(StrictMath.max(0.0f, 0.0f), 0.0f);
674 Assert.assertEquals(StrictMath.max(1.0f, 0.0f), 1.0f);
675 Assert.assertEquals(StrictMath.max(0.0f, 1.0f), 1.0f);
676 Assert.assertEquals(StrictMath.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
677 Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
678 Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100679 }
680
681 public static void test_StrictMath_min_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800682 StrictMath.min(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700683 Assert.assertTrue(Double.isNaN(StrictMath.min(1.0d, Double.NaN)));
684 Assert.assertTrue(Double.isNaN(StrictMath.min(Double.NaN, 1.0d)));
685 Assert.assertEquals(StrictMath.min(-0.0d, 0.0d), -0.0d);
686 Assert.assertEquals(StrictMath.min(0.0d, -0.0d), -0.0d);
687 Assert.assertEquals(StrictMath.min(-0.0d, -0.0d), -0.0d);
688 Assert.assertEquals(StrictMath.min(0.0d, 0.0d), 0.0d);
689 Assert.assertEquals(StrictMath.min(1.0d, 0.0d), 0.0d);
690 Assert.assertEquals(StrictMath.min(0.0d, 1.0d), 0.0d);
691 Assert.assertEquals(StrictMath.min(0.0d, Double.MAX_VALUE), 0.0d);
692 Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, 0.0d), 0.0d);
693 Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100694 }
695
696 public static void test_StrictMath_max_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800697 StrictMath.max(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700698 Assert.assertTrue(Double.isNaN(StrictMath.max(1.0d, Double.NaN)));
699 Assert.assertTrue(Double.isNaN(StrictMath.max(Double.NaN, 1.0d)));
700 Assert.assertEquals(StrictMath.max(-0.0d, 0.0d), 0.0d);
701 Assert.assertEquals(StrictMath.max(0.0d, -0.0d), 0.0d);
702 Assert.assertEquals(StrictMath.max(-0.0d, -0.0d), -0.0d);
703 Assert.assertEquals(StrictMath.max(0.0d, 0.0d), 0.0d);
704 Assert.assertEquals(StrictMath.max(1.0d, 0.0d), 1.0d);
705 Assert.assertEquals(StrictMath.max(0.0d, 1.0d), 1.0d);
706 Assert.assertEquals(StrictMath.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
707 Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
708 Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100709 }
710
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800711 public static void test_StrictMath_sqrt() {
712 StrictMath.sqrt(+4.0);
713 Assert.assertEquals(StrictMath.sqrt(+4.0), +2.0d, 0.0);
714 Assert.assertEquals(StrictMath.sqrt(+49.0), +7.0d, 0.0);
715 Assert.assertEquals(StrictMath.sqrt(+1.44), +1.2d, 0.0);
716 }
717
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100718 public static void test_StrictMath_ceil() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800719 StrictMath.ceil(-0.9);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100720 Assert.assertEquals(StrictMath.ceil(+0.0), +0.0d, 0.0);
721 Assert.assertEquals(StrictMath.ceil(-0.0), -0.0d, 0.0);
722 Assert.assertEquals(StrictMath.ceil(-0.9), -0.0d, 0.0);
723 Assert.assertEquals(StrictMath.ceil(-0.5), -0.0d, 0.0);
724 Assert.assertEquals(StrictMath.ceil(0.0), -0.0d, 0.0);
725 Assert.assertEquals(StrictMath.ceil(+2.0), +2.0d, 0.0);
726 Assert.assertEquals(StrictMath.ceil(+2.1), +3.0d, 0.0);
727 Assert.assertEquals(StrictMath.ceil(+2.5), +3.0d, 0.0);
728 Assert.assertEquals(StrictMath.ceil(+2.9), +3.0d, 0.0);
729 Assert.assertEquals(StrictMath.ceil(+3.0), +3.0d, 0.0);
730 Assert.assertEquals(StrictMath.ceil(-2.0), -2.0d, 0.0);
731 Assert.assertEquals(StrictMath.ceil(-2.1), -2.0d, 0.0);
732 Assert.assertEquals(StrictMath.ceil(-2.5), -2.0d, 0.0);
733 Assert.assertEquals(StrictMath.ceil(-2.9), -2.0d, 0.0);
734 Assert.assertEquals(StrictMath.ceil(-3.0), -3.0d, 0.0);
735 Assert.assertEquals(StrictMath.ceil(Double.NaN), Double.NaN, 0.0);
736 Assert.assertEquals(StrictMath.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
737 Assert.assertEquals(StrictMath.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
738 }
739
740 public static void test_StrictMath_floor() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800741 StrictMath.floor(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100742 Assert.assertEquals(StrictMath.floor(+0.0), +0.0d, 0.0);
743 Assert.assertEquals(StrictMath.floor(-0.0), -0.0d, 0.0);
744 Assert.assertEquals(StrictMath.floor(+2.0), +2.0d, 0.0);
745 Assert.assertEquals(StrictMath.floor(+2.1), +2.0d, 0.0);
746 Assert.assertEquals(StrictMath.floor(+2.5), +2.0d, 0.0);
747 Assert.assertEquals(StrictMath.floor(+2.9), +2.0d, 0.0);
748 Assert.assertEquals(StrictMath.floor(+3.0), +3.0d, 0.0);
749 Assert.assertEquals(StrictMath.floor(-2.0), -2.0d, 0.0);
750 Assert.assertEquals(StrictMath.floor(-2.1), -3.0d, 0.0);
751 Assert.assertEquals(StrictMath.floor(-2.5), -3.0d, 0.0);
752 Assert.assertEquals(StrictMath.floor(-2.9), -3.0d, 0.0);
753 Assert.assertEquals(StrictMath.floor(-3.0), -3.0d, 0.0);
754 Assert.assertEquals(StrictMath.floor(Double.NaN), Double.NaN, 0.0);
755 Assert.assertEquals(StrictMath.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
756 Assert.assertEquals(StrictMath.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
757 }
758
759 public static void test_StrictMath_rint() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800760 StrictMath.rint(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100761 Assert.assertEquals(StrictMath.rint(+0.0), +0.0d, 0.0);
762 Assert.assertEquals(StrictMath.rint(-0.0), -0.0d, 0.0);
763 Assert.assertEquals(StrictMath.rint(+2.0), +2.0d, 0.0);
764 Assert.assertEquals(StrictMath.rint(+2.1), +2.0d, 0.0);
765 Assert.assertEquals(StrictMath.rint(+2.5), +2.0d, 0.0);
766 Assert.assertEquals(StrictMath.rint(+2.9), +3.0d, 0.0);
767 Assert.assertEquals(StrictMath.rint(+3.0), +3.0d, 0.0);
768 Assert.assertEquals(StrictMath.rint(-2.0), -2.0d, 0.0);
769 Assert.assertEquals(StrictMath.rint(-2.1), -2.0d, 0.0);
770 Assert.assertEquals(StrictMath.rint(-2.5), -2.0d, 0.0);
771 Assert.assertEquals(StrictMath.rint(-2.9), -3.0d, 0.0);
772 Assert.assertEquals(StrictMath.rint(-3.0), -3.0d, 0.0);
773 Assert.assertEquals(StrictMath.rint(Double.NaN), Double.NaN, 0.0);
774 Assert.assertEquals(StrictMath.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
775 Assert.assertEquals(StrictMath.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
776 }
777
778 public static void test_StrictMath_round_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800779 StrictMath.round(2.1d);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100780 Assert.assertEquals(StrictMath.round(+0.0d), (long)+0.0);
781 Assert.assertEquals(StrictMath.round(-0.0d), (long)+0.0);
782 Assert.assertEquals(StrictMath.round(2.0d), 2l);
783 Assert.assertEquals(StrictMath.round(2.1d), 2l);
784 Assert.assertEquals(StrictMath.round(2.5d), 3l);
785 Assert.assertEquals(StrictMath.round(2.9d), 3l);
786 Assert.assertEquals(StrictMath.round(3.0d), 3l);
787 Assert.assertEquals(StrictMath.round(-2.0d), -2l);
788 Assert.assertEquals(StrictMath.round(-2.1d), -2l);
789 Assert.assertEquals(StrictMath.round(-2.5d), -2l);
790 Assert.assertEquals(StrictMath.round(-2.9d), -3l);
791 Assert.assertEquals(StrictMath.round(-3.0d), -3l);
792 Assert.assertEquals(StrictMath.round(0.49999999999999994d), 1l);
793 Assert.assertEquals(StrictMath.round(Double.NaN), (long)+0.0d);
794 Assert.assertEquals(StrictMath.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
795 Assert.assertEquals(StrictMath.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
796 Assert.assertEquals(StrictMath.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
797 Assert.assertEquals(StrictMath.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
798 }
799
800 public static void test_StrictMath_round_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800801 StrictMath.round(2.1f);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100802 Assert.assertEquals(StrictMath.round(+0.0f), (int)+0.0);
803 Assert.assertEquals(StrictMath.round(-0.0f), (int)+0.0);
804 Assert.assertEquals(StrictMath.round(2.0f), 2);
805 Assert.assertEquals(StrictMath.round(2.1f), 2);
806 Assert.assertEquals(StrictMath.round(2.5f), 3);
807 Assert.assertEquals(StrictMath.round(2.9f), 3);
808 Assert.assertEquals(StrictMath.round(3.0f), 3);
809 Assert.assertEquals(StrictMath.round(-2.0f), -2);
810 Assert.assertEquals(StrictMath.round(-2.1f), -2);
811 Assert.assertEquals(StrictMath.round(-2.5f), -2);
812 Assert.assertEquals(StrictMath.round(-2.9f), -3);
813 Assert.assertEquals(StrictMath.round(-3.0f), -3);
814 Assert.assertEquals(StrictMath.round(Float.NaN), (int)+0.0f);
815 Assert.assertEquals(StrictMath.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
816 Assert.assertEquals(StrictMath.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
817 Assert.assertEquals(StrictMath.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
818 Assert.assertEquals(StrictMath.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
819 }
820
Elliott Hughes28c384b2012-06-15 16:46:25 -0700821 public static void test_Float_floatToRawIntBits() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800822 Float.floatToRawIntBits(-1.0f);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700823 Assert.assertEquals(Float.floatToRawIntBits(-1.0f), 0xbf800000);
824 Assert.assertEquals(Float.floatToRawIntBits(0.0f), 0);
825 Assert.assertEquals(Float.floatToRawIntBits(1.0f), 0x3f800000);
826 Assert.assertEquals(Float.floatToRawIntBits(Float.NaN), 0x7fc00000);
827 Assert.assertEquals(Float.floatToRawIntBits(Float.POSITIVE_INFINITY), 0x7f800000);
828 Assert.assertEquals(Float.floatToRawIntBits(Float.NEGATIVE_INFINITY), 0xff800000);
829 }
830
831 public static void test_Float_intBitsToFloat() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800832 Float.intBitsToFloat(0xbf800000);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700833 Assert.assertEquals(Float.intBitsToFloat(0xbf800000), -1.0f);
834 Assert.assertEquals(Float.intBitsToFloat(0x00000000), 0.0f);
835 Assert.assertEquals(Float.intBitsToFloat(0x3f800000), 1.0f);
836 Assert.assertEquals(Float.intBitsToFloat(0x7fc00000), Float.NaN);
837 Assert.assertEquals(Float.intBitsToFloat(0x7f800000), Float.POSITIVE_INFINITY);
838 Assert.assertEquals(Float.intBitsToFloat(0xff800000), Float.NEGATIVE_INFINITY);
839 }
840
841 public static void test_Double_doubleToRawLongBits() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800842 Double.doubleToRawLongBits(-1.0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700843 Assert.assertEquals(Double.doubleToRawLongBits(-1.0), 0xbff0000000000000L);
844 Assert.assertEquals(Double.doubleToRawLongBits(0.0), 0x0000000000000000L);
845 Assert.assertEquals(Double.doubleToRawLongBits(1.0), 0x3ff0000000000000L);
846 Assert.assertEquals(Double.doubleToRawLongBits(Double.NaN), 0x7ff8000000000000L);
847 Assert.assertEquals(Double.doubleToRawLongBits(Double.POSITIVE_INFINITY), 0x7ff0000000000000L);
848 Assert.assertEquals(Double.doubleToRawLongBits(Double.NEGATIVE_INFINITY), 0xfff0000000000000L);
849 }
850
851 public static void test_Double_longBitsToDouble() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800852 Double.longBitsToDouble(0xbff0000000000000L);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700853 Assert.assertEquals(Double.longBitsToDouble(0xbff0000000000000L), -1.0);
854 Assert.assertEquals(Double.longBitsToDouble(0x0000000000000000L), 0.0);
855 Assert.assertEquals(Double.longBitsToDouble(0x3ff0000000000000L), 1.0);
856 Assert.assertEquals(Double.longBitsToDouble(0x7ff8000000000000L), Double.NaN);
857 Assert.assertEquals(Double.longBitsToDouble(0x7ff0000000000000L), Double.POSITIVE_INFINITY);
858 Assert.assertEquals(Double.longBitsToDouble(0xfff0000000000000L), Double.NEGATIVE_INFINITY);
859 }
Serban Constantinescu23abec92014-07-02 16:13:38 +0100860
Zheng Xua3fe7422014-07-09 14:03:15 +0800861 public static void test_Short_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800862 Short.reverseBytes((short)0x1357);
Zheng Xua3fe7422014-07-09 14:03:15 +0800863 Assert.assertEquals(Short.reverseBytes((short)0x0000), (short)0x0000);
864 Assert.assertEquals(Short.reverseBytes((short)0xffff), (short)0xffff);
865 Assert.assertEquals(Short.reverseBytes((short)0x8000), (short)0x0080);
866 Assert.assertEquals(Short.reverseBytes((short)0x0080), (short)0x8000);
867 Assert.assertEquals(Short.reverseBytes((short)0x0123), (short)0x2301);
868 Assert.assertEquals(Short.reverseBytes((short)0x4567), (short)0x6745);
869 Assert.assertEquals(Short.reverseBytes((short)0x89ab), (short)0xab89);
870 Assert.assertEquals(Short.reverseBytes((short)0xcdef), (short)0xefcd);
871 }
872
873 public static void test_Integer_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800874 Integer.reverseBytes(0x13579bdf);
Zheng Xua3fe7422014-07-09 14:03:15 +0800875 Assert.assertEquals(Integer.reverseBytes(0x00000000), 0x00000000);
876 Assert.assertEquals(Integer.reverseBytes(0xffffffff), 0xffffffff);
877 Assert.assertEquals(Integer.reverseBytes(0x80000000), 0x00000080);
878 Assert.assertEquals(Integer.reverseBytes(0x00000080), 0x80000000);
879 Assert.assertEquals(Integer.reverseBytes(0x01234567), 0x67452301);
880 Assert.assertEquals(Integer.reverseBytes(0x89abcdef), 0xefcdab89);
881 }
882
883 public static void test_Long_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800884 Long.reverseBytes(0x13579bdf2468ace0L);
Zheng Xua3fe7422014-07-09 14:03:15 +0800885 Assert.assertEquals(Long.reverseBytes(0x0000000000000000L), 0x0000000000000000L);
886 Assert.assertEquals(Long.reverseBytes(0xffffffffffffffffL), 0xffffffffffffffffL);
887 Assert.assertEquals(Long.reverseBytes(0x8000000000000000L), 0x0000000000000080L);
888 Assert.assertEquals(Long.reverseBytes(0x0000000000000080L), 0x8000000000000000L);
889 Assert.assertEquals(Long.reverseBytes(0x0123456789abcdefL), 0xefcdab8967452301L);
890 }
891
Serban Constantinescu23abec92014-07-02 16:13:38 +0100892 public static void test_Integer_reverse() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800893 Integer.reverse(0x12345678);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100894 Assert.assertEquals(Integer.reverse(1), 0x80000000);
895 Assert.assertEquals(Integer.reverse(-1), 0xffffffff);
896 Assert.assertEquals(Integer.reverse(0), 0);
897 Assert.assertEquals(Integer.reverse(0x12345678), 0x1e6a2c48);
898 Assert.assertEquals(Integer.reverse(0x87654321), 0x84c2a6e1);
899 Assert.assertEquals(Integer.reverse(Integer.MAX_VALUE), 0xfffffffe);
900 Assert.assertEquals(Integer.reverse(Integer.MIN_VALUE), 1);
901 }
902
903 public static void test_Long_reverse() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800904 Long.reverse(0x1234567812345678L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100905 Assert.assertEquals(Long.reverse(1L), 0x8000000000000000L);
906 Assert.assertEquals(Long.reverse(-1L), 0xffffffffffffffffL);
907 Assert.assertEquals(Long.reverse(0L), 0L);
Zheng Xua3fe7422014-07-09 14:03:15 +0800908 Assert.assertEquals(Long.reverse(0x1234567812345678L), 0x1e6a2c481e6a2c48L);
909 Assert.assertEquals(Long.reverse(0x8765432187654321L), 0x84c2a6e184c2a6e1L);
910 Assert.assertEquals(Long.reverse(Long.MAX_VALUE), 0xfffffffffffffffeL);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100911 Assert.assertEquals(Long.reverse(Long.MIN_VALUE), 1L);
912 }
913
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700914 static Object runtime;
915 static Method address_of;
Zuo Wangf37a88b2014-07-10 04:26:41 -0700916 static Method new_non_movable_array;
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700917 static Method peek_byte;
918 static Method peek_short;
919 static Method peek_int;
920 static Method peek_long;
921 static Method poke_byte;
922 static Method poke_short;
923 static Method poke_int;
924 static Method poke_long;
925
926 public static void initSupportMethodsForPeekPoke() throws Exception {
927 Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
928 Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
929 runtime = get_runtime.invoke(null);
930 address_of = vm_runtime.getDeclaredMethod("addressOf", Object.class);
Zuo Wangf37a88b2014-07-10 04:26:41 -0700931 new_non_movable_array = vm_runtime.getDeclaredMethod("newNonMovableArray", Class.class, Integer.TYPE);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700932
933 Class<?> io_memory = Class.forName("libcore.io.Memory");
934 peek_byte = io_memory.getDeclaredMethod("peekByte", Long.TYPE);
935 peek_int = io_memory.getDeclaredMethod("peekInt", Long.TYPE, Boolean.TYPE);
936 peek_short = io_memory.getDeclaredMethod("peekShort", Long.TYPE, Boolean.TYPE);
937 peek_long = io_memory.getDeclaredMethod("peekLong", Long.TYPE, Boolean.TYPE);
938 poke_byte = io_memory.getDeclaredMethod("pokeByte", Long.TYPE, Byte.TYPE);
939 poke_short = io_memory.getDeclaredMethod("pokeShort", Long.TYPE, Short.TYPE, Boolean.TYPE);
940 poke_int = io_memory.getDeclaredMethod("pokeInt", Long.TYPE, Integer.TYPE, Boolean.TYPE);
941 poke_long = io_memory.getDeclaredMethod("pokeLong", Long.TYPE, Long.TYPE, Boolean.TYPE);
942 }
943
944 public static void test_Memory_peekByte() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700945 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700946 b[0] = 0x12;
947 b[1] = 0x11;
948 long address = (long)address_of.invoke(runtime, b);
949 Assert.assertEquals((byte)peek_byte.invoke(null, address), 0x12);
950 Assert.assertEquals((byte)peek_byte.invoke(null, address + 1), 0x11);
951 }
952
953 public static void test_Memory_peekShort() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700954 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700955 b[0] = 0x13;
956 b[1] = 0x12;
957 b[2] = 0x11;
958 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800959 peek_short.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700960 Assert.assertEquals((short)peek_short.invoke(null, address, false), 0x1213); // Aligned read
961 Assert.assertEquals((short)peek_short.invoke(null, address + 1, false), 0x1112); // Unaligned read
962 }
963
964 public static void test_Memory_peekInt() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700965 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700966 b[0] = 0x15;
967 b[1] = 0x14;
968 b[2] = 0x13;
969 b[3] = 0x12;
970 b[4] = 0x11;
971 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800972 peek_int.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700973 Assert.assertEquals((int)peek_int.invoke(null, address, false), 0x12131415);
974 Assert.assertEquals((int)peek_int.invoke(null, address + 1, false), 0x11121314);
975 }
976
977 public static void test_Memory_peekLong() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700978 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700979 b[0] = 0x19;
980 b[1] = 0x18;
981 b[2] = 0x17;
982 b[3] = 0x16;
983 b[4] = 0x15;
984 b[5] = 0x14;
985 b[6] = 0x13;
986 b[7] = 0x12;
987 b[8] = 0x11;
988 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800989 peek_long.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700990 Assert.assertEquals((long)peek_long.invoke(null, address, false), 0x1213141516171819L);
991 Assert.assertEquals((long)peek_long.invoke(null, address + 1, false), 0x1112131415161718L);
992 }
993
994 public static void test_Memory_pokeByte() throws Exception {
995 byte[] r = {0x11, 0x12};
Zuo Wangf37a88b2014-07-10 04:26:41 -0700996 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700997 long address = (long)address_of.invoke(runtime, b);
998 poke_byte.invoke(null, address, (byte)0x11);
999 poke_byte.invoke(null, address + 1, (byte)0x12);
1000 Assert.assertTrue(Arrays.equals(r, b));
1001 }
1002
1003 public static void test_Memory_pokeShort() throws Exception {
1004 byte[] ra = {0x12, 0x11, 0x13};
1005 byte[] ru = {0x12, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001006 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001007 long address = (long)address_of.invoke(runtime, b);
1008
1009 // Aligned write
1010 b[2] = 0x13;
1011 poke_short.invoke(null, address, (short)0x1112, false);
1012 Assert.assertTrue(Arrays.equals(ra, b));
1013
1014 // Unaligned write
1015 poke_short.invoke(null, address + 1, (short)0x2122, false);
1016 Assert.assertTrue(Arrays.equals(ru, b));
1017 }
1018
1019 public static void test_Memory_pokeInt() throws Exception {
1020 byte[] ra = {0x14, 0x13, 0x12, 0x11, 0x15};
1021 byte[] ru = {0x14, 0x24, 0x23, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001022 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001023 long address = (long)address_of.invoke(runtime, b);
1024
1025 b[4] = 0x15;
1026 poke_int.invoke(null, address, (int)0x11121314, false);
1027 Assert.assertTrue(Arrays.equals(ra, b));
1028
1029 poke_int.invoke(null, address + 1, (int)0x21222324, false);
1030 Assert.assertTrue(Arrays.equals(ru, b));
1031 }
1032
1033 public static void test_Memory_pokeLong() throws Exception {
1034 byte[] ra = {0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x19};
1035 byte[] ru = {0x18, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001036 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001037 long address = (long)address_of.invoke(runtime, b);
1038
1039 b[8] = 0x19;
1040 poke_long.invoke(null, address, (long)0x1112131415161718L, false);
1041 Assert.assertTrue(Arrays.equals(ra, b));
1042
1043 poke_long.invoke(null, address + 1, (long)0x2122232425262728L, false);
1044 Assert.assertTrue(Arrays.equals(ru, b));
1045 }
jeffhao5d1ac922011-09-29 17:41:15 -07001046}