blob: 0e90c4d6a2e2bd01485e7f473ba2e480210bca58 [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);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800378 Assert.assertEquals(Math.abs(2147483648L), 2147483648L);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700379 }
380
Serban Constantinescu23abec92014-07-02 16:13:38 +0100381 public static void test_Math_min_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800382 Math.min(1, 0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700383 Assert.assertEquals(Math.min(0, 0), 0);
384 Assert.assertEquals(Math.min(1, 0), 0);
385 Assert.assertEquals(Math.min(0, 1), 0);
386 Assert.assertEquals(Math.min(0, Integer.MAX_VALUE), 0);
387 Assert.assertEquals(Math.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
388 Assert.assertEquals(Math.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
389 }
390
Serban Constantinescu23abec92014-07-02 16:13:38 +0100391 public static void test_Math_max_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800392 Math.max(1, 0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700393 Assert.assertEquals(Math.max(0, 0), 0);
394 Assert.assertEquals(Math.max(1, 0), 1);
395 Assert.assertEquals(Math.max(0, 1), 1);
396 Assert.assertEquals(Math.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
397 Assert.assertEquals(Math.max(Integer.MIN_VALUE, 0), 0);
398 Assert.assertEquals(Math.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
399 }
400
Serban Constantinescu23abec92014-07-02 16:13:38 +0100401 public static void test_Math_min_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800402 Math.min(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100403 Assert.assertEquals(Math.min(0L, 0L), 0L);
404 Assert.assertEquals(Math.min(1L, 0L), 0L);
405 Assert.assertEquals(Math.min(0L, 1L), 0L);
406 Assert.assertEquals(Math.min(0L, Long.MAX_VALUE), 0L);
407 Assert.assertEquals(Math.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
408 Assert.assertEquals(Math.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
409 }
410
411 public static void test_Math_max_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800412 Math.max(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100413 Assert.assertEquals(Math.max(0L, 0L), 0L);
414 Assert.assertEquals(Math.max(1L, 0L), 1L);
415 Assert.assertEquals(Math.max(0L, 1L), 1L);
416 Assert.assertEquals(Math.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
417 Assert.assertEquals(Math.max(Long.MIN_VALUE, 0L), 0L);
418 Assert.assertEquals(Math.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
419 }
420
421 public static void test_Math_min_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800422 Math.min(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700423 Assert.assertTrue(Float.isNaN(Math.min(1.0f, Float.NaN)));
424 Assert.assertTrue(Float.isNaN(Math.min(Float.NaN, 1.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(0.0f, 0.0f), 0.0f);
429 Assert.assertEquals(Math.min(1.0f, 0.0f), 0.0f);
430 Assert.assertEquals(Math.min(0.0f, 1.0f), 0.0f);
431 Assert.assertEquals(Math.min(0.0f, Float.MAX_VALUE), 0.0f);
432 Assert.assertEquals(Math.min(Float.MIN_VALUE, 0.0f), 0.0f);
433 Assert.assertEquals(Math.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100434 }
435
436 public static void test_Math_max_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800437 Math.max(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700438 Assert.assertTrue(Float.isNaN(Math.max(1.0f, Float.NaN)));
439 Assert.assertTrue(Float.isNaN(Math.max(Float.NaN, 1.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(0.0f, 0.0f), 0.0f);
444 Assert.assertEquals(Math.max(1.0f, 0.0f), 1.0f);
445 Assert.assertEquals(Math.max(0.0f, 1.0f), 1.0f);
446 Assert.assertEquals(Math.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
447 Assert.assertEquals(Math.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
448 Assert.assertEquals(Math.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100449 }
450
451 public static void test_Math_min_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800452 Math.min(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700453 Assert.assertTrue(Double.isNaN(Math.min(1.0d, Double.NaN)));
454 Assert.assertTrue(Double.isNaN(Math.min(Double.NaN, 1.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(0.0d, 0.0d), 0.0d);
459 Assert.assertEquals(Math.min(1.0d, 0.0d), 0.0d);
460 Assert.assertEquals(Math.min(0.0d, 1.0d), 0.0d);
461 Assert.assertEquals(Math.min(0.0d, Double.MAX_VALUE), 0.0d);
462 Assert.assertEquals(Math.min(Double.MIN_VALUE, 0.0d), 0.0d);
463 Assert.assertEquals(Math.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100464 }
465
466 public static void test_Math_max_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800467 Math.max(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700468 Assert.assertTrue(Double.isNaN(Math.max(1.0d, Double.NaN)));
469 Assert.assertTrue(Double.isNaN(Math.max(Double.NaN, 1.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(0.0d, 0.0d), 0.0d);
474 Assert.assertEquals(Math.max(1.0d, 0.0d), 1.0d);
475 Assert.assertEquals(Math.max(0.0d, 1.0d), 1.0d);
476 Assert.assertEquals(Math.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
477 Assert.assertEquals(Math.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
478 Assert.assertEquals(Math.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100479 }
480
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800481 public static void test_Math_sqrt() {
482 Math.sqrt(+4.0);
483 Assert.assertEquals(Math.sqrt(+4.0), +2.0d, 0.0);
484 Assert.assertEquals(Math.sqrt(+49.0), +7.0d, 0.0);
485 Assert.assertEquals(Math.sqrt(+1.44), +1.2d, 0.0);
486 }
487
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100488 public static void test_Math_ceil() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800489 Math.ceil(-0.9);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100490 Assert.assertEquals(Math.ceil(+0.0), +0.0d, 0.0);
491 Assert.assertEquals(Math.ceil(-0.0), -0.0d, 0.0);
492 Assert.assertEquals(Math.ceil(-0.9), -0.0d, 0.0);
493 Assert.assertEquals(Math.ceil(-0.5), -0.0d, 0.0);
494 Assert.assertEquals(Math.ceil(0.0), -0.0d, 0.0);
495 Assert.assertEquals(Math.ceil(+2.0), +2.0d, 0.0);
496 Assert.assertEquals(Math.ceil(+2.1), +3.0d, 0.0);
497 Assert.assertEquals(Math.ceil(+2.5), +3.0d, 0.0);
498 Assert.assertEquals(Math.ceil(+2.9), +3.0d, 0.0);
499 Assert.assertEquals(Math.ceil(+3.0), +3.0d, 0.0);
500 Assert.assertEquals(Math.ceil(-2.0), -2.0d, 0.0);
501 Assert.assertEquals(Math.ceil(-2.1), -2.0d, 0.0);
502 Assert.assertEquals(Math.ceil(-2.5), -2.0d, 0.0);
503 Assert.assertEquals(Math.ceil(-2.9), -2.0d, 0.0);
504 Assert.assertEquals(Math.ceil(-3.0), -3.0d, 0.0);
505 Assert.assertEquals(Math.ceil(Double.NaN), Double.NaN, 0.0);
506 Assert.assertEquals(Math.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
507 Assert.assertEquals(Math.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
508 }
509
510 public static void test_Math_floor() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800511 Math.floor(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100512 Assert.assertEquals(Math.floor(+0.0), +0.0d, 0.0);
513 Assert.assertEquals(Math.floor(-0.0), -0.0d, 0.0);
514 Assert.assertEquals(Math.floor(+2.0), +2.0d, 0.0);
515 Assert.assertEquals(Math.floor(+2.1), +2.0d, 0.0);
516 Assert.assertEquals(Math.floor(+2.5), +2.0d, 0.0);
517 Assert.assertEquals(Math.floor(+2.9), +2.0d, 0.0);
518 Assert.assertEquals(Math.floor(+3.0), +3.0d, 0.0);
519 Assert.assertEquals(Math.floor(-2.0), -2.0d, 0.0);
520 Assert.assertEquals(Math.floor(-2.1), -3.0d, 0.0);
521 Assert.assertEquals(Math.floor(-2.5), -3.0d, 0.0);
522 Assert.assertEquals(Math.floor(-2.9), -3.0d, 0.0);
523 Assert.assertEquals(Math.floor(-3.0), -3.0d, 0.0);
524 Assert.assertEquals(Math.floor(Double.NaN), Double.NaN, 0.0);
525 Assert.assertEquals(Math.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
526 Assert.assertEquals(Math.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
527 }
528
529 public static void test_Math_rint() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800530 Math.rint(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100531 Assert.assertEquals(Math.rint(+0.0), +0.0d, 0.0);
532 Assert.assertEquals(Math.rint(-0.0), -0.0d, 0.0);
533 Assert.assertEquals(Math.rint(+2.0), +2.0d, 0.0);
534 Assert.assertEquals(Math.rint(+2.1), +2.0d, 0.0);
535 Assert.assertEquals(Math.rint(+2.5), +2.0d, 0.0);
536 Assert.assertEquals(Math.rint(+2.9), +3.0d, 0.0);
537 Assert.assertEquals(Math.rint(+3.0), +3.0d, 0.0);
538 Assert.assertEquals(Math.rint(-2.0), -2.0d, 0.0);
539 Assert.assertEquals(Math.rint(-2.1), -2.0d, 0.0);
540 Assert.assertEquals(Math.rint(-2.5), -2.0d, 0.0);
541 Assert.assertEquals(Math.rint(-2.9), -3.0d, 0.0);
542 Assert.assertEquals(Math.rint(-3.0), -3.0d, 0.0);
543 Assert.assertEquals(Math.rint(Double.NaN), Double.NaN, 0.0);
544 Assert.assertEquals(Math.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
545 Assert.assertEquals(Math.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
546 }
547
548 public static void test_Math_round_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800549 Math.round(2.1d);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100550 Assert.assertEquals(Math.round(+0.0d), (long)+0.0);
551 Assert.assertEquals(Math.round(-0.0d), (long)+0.0);
552 Assert.assertEquals(Math.round(2.0d), 2l);
553 Assert.assertEquals(Math.round(2.1d), 2l);
554 Assert.assertEquals(Math.round(2.5d), 3l);
555 Assert.assertEquals(Math.round(2.9d), 3l);
556 Assert.assertEquals(Math.round(3.0d), 3l);
557 Assert.assertEquals(Math.round(-2.0d), -2l);
558 Assert.assertEquals(Math.round(-2.1d), -2l);
559 Assert.assertEquals(Math.round(-2.5d), -2l);
560 Assert.assertEquals(Math.round(-2.9d), -3l);
561 Assert.assertEquals(Math.round(-3.0d), -3l);
562 Assert.assertEquals(Math.round(0.49999999999999994d), 1l);
563 Assert.assertEquals(Math.round(Double.NaN), (long)+0.0d);
564 Assert.assertEquals(Math.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
565 Assert.assertEquals(Math.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
566 Assert.assertEquals(Math.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
567 Assert.assertEquals(Math.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
568 }
569
570 public static void test_Math_round_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800571 Math.round(2.1f);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100572 Assert.assertEquals(Math.round(+0.0f), (int)+0.0);
573 Assert.assertEquals(Math.round(-0.0f), (int)+0.0);
574 Assert.assertEquals(Math.round(2.0f), 2);
575 Assert.assertEquals(Math.round(2.1f), 2);
576 Assert.assertEquals(Math.round(2.5f), 3);
577 Assert.assertEquals(Math.round(2.9f), 3);
578 Assert.assertEquals(Math.round(3.0f), 3);
579 Assert.assertEquals(Math.round(-2.0f), -2);
580 Assert.assertEquals(Math.round(-2.1f), -2);
581 Assert.assertEquals(Math.round(-2.5f), -2);
582 Assert.assertEquals(Math.round(-2.9f), -3);
583 Assert.assertEquals(Math.round(-3.0f), -3);
584 Assert.assertEquals(Math.round(Float.NaN), (int)+0.0f);
585 Assert.assertEquals(Math.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
586 Assert.assertEquals(Math.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
587 Assert.assertEquals(Math.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
588 Assert.assertEquals(Math.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
589 }
590
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100591 public static void test_StrictMath_abs_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800592 StrictMath.abs(-1);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100593 Assert.assertEquals(StrictMath.abs(0), 0);
594 Assert.assertEquals(StrictMath.abs(123), 123);
595 Assert.assertEquals(StrictMath.abs(-123), 123);
596 Assert.assertEquals(StrictMath.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
597 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
598 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
599 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
600 }
601
602 public static void test_StrictMath_abs_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800603 StrictMath.abs(-1L);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100604 Assert.assertEquals(StrictMath.abs(0L), 0L);
605 Assert.assertEquals(StrictMath.abs(123L), 123L);
606 Assert.assertEquals(StrictMath.abs(-123L), 123L);
607 Assert.assertEquals(StrictMath.abs(Long.MAX_VALUE), Long.MAX_VALUE);
608 Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE), Long.MIN_VALUE);
609 Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
610 }
611
Serban Constantinescu23abec92014-07-02 16:13:38 +0100612 public static void test_StrictMath_min_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800613 StrictMath.min(1, 0);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100614 Assert.assertEquals(StrictMath.min(0, 0), 0);
615 Assert.assertEquals(StrictMath.min(1, 0), 0);
616 Assert.assertEquals(StrictMath.min(0, 1), 0);
617 Assert.assertEquals(StrictMath.min(0, Integer.MAX_VALUE), 0);
618 Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
619 Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
620 }
621
Serban Constantinescu23abec92014-07-02 16:13:38 +0100622 public static void test_StrictMath_max_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800623 StrictMath.max(1, 0);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100624 Assert.assertEquals(StrictMath.max(0, 0), 0);
625 Assert.assertEquals(StrictMath.max(1, 0), 1);
626 Assert.assertEquals(StrictMath.max(0, 1), 1);
627 Assert.assertEquals(StrictMath.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
628 Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, 0), 0);
629 Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
630 }
631
Serban Constantinescu23abec92014-07-02 16:13:38 +0100632 public static void test_StrictMath_min_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800633 StrictMath.min(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100634 Assert.assertEquals(StrictMath.min(0L, 0L), 0L);
635 Assert.assertEquals(StrictMath.min(1L, 0L), 0L);
636 Assert.assertEquals(StrictMath.min(0L, 1L), 0L);
637 Assert.assertEquals(StrictMath.min(0L, Long.MAX_VALUE), 0L);
638 Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
639 Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
640 }
641
642 public static void test_StrictMath_max_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800643 StrictMath.max(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100644 Assert.assertEquals(StrictMath.max(0L, 0L), 0L);
645 Assert.assertEquals(StrictMath.max(1L, 0L), 1L);
646 Assert.assertEquals(StrictMath.max(0L, 1L), 1L);
647 Assert.assertEquals(StrictMath.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
648 Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, 0L), 0L);
649 Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
650 }
651
652 public static void test_StrictMath_min_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800653 StrictMath.min(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700654 Assert.assertTrue(Float.isNaN(StrictMath.min(1.0f, Float.NaN)));
655 Assert.assertTrue(Float.isNaN(StrictMath.min(Float.NaN, 1.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(0.0f, 0.0f), 0.0f);
660 Assert.assertEquals(StrictMath.min(1.0f, 0.0f), 0.0f);
661 Assert.assertEquals(StrictMath.min(0.0f, 1.0f), 0.0f);
662 Assert.assertEquals(StrictMath.min(0.0f, Float.MAX_VALUE), 0.0f);
663 Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, 0.0f), 0.0f);
664 Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100665 }
666
667 public static void test_StrictMath_max_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800668 StrictMath.max(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700669 Assert.assertTrue(Float.isNaN(StrictMath.max(1.0f, Float.NaN)));
670 Assert.assertTrue(Float.isNaN(StrictMath.max(Float.NaN, 1.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(0.0f, 0.0f), 0.0f);
675 Assert.assertEquals(StrictMath.max(1.0f, 0.0f), 1.0f);
676 Assert.assertEquals(StrictMath.max(0.0f, 1.0f), 1.0f);
677 Assert.assertEquals(StrictMath.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
678 Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
679 Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100680 }
681
682 public static void test_StrictMath_min_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800683 StrictMath.min(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700684 Assert.assertTrue(Double.isNaN(StrictMath.min(1.0d, Double.NaN)));
685 Assert.assertTrue(Double.isNaN(StrictMath.min(Double.NaN, 1.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(0.0d, 0.0d), 0.0d);
690 Assert.assertEquals(StrictMath.min(1.0d, 0.0d), 0.0d);
691 Assert.assertEquals(StrictMath.min(0.0d, 1.0d), 0.0d);
692 Assert.assertEquals(StrictMath.min(0.0d, Double.MAX_VALUE), 0.0d);
693 Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, 0.0d), 0.0d);
694 Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100695 }
696
697 public static void test_StrictMath_max_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800698 StrictMath.max(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700699 Assert.assertTrue(Double.isNaN(StrictMath.max(1.0d, Double.NaN)));
700 Assert.assertTrue(Double.isNaN(StrictMath.max(Double.NaN, 1.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(0.0d, 0.0d), 0.0d);
705 Assert.assertEquals(StrictMath.max(1.0d, 0.0d), 1.0d);
706 Assert.assertEquals(StrictMath.max(0.0d, 1.0d), 1.0d);
707 Assert.assertEquals(StrictMath.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
708 Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
709 Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100710 }
711
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800712 public static void test_StrictMath_sqrt() {
713 StrictMath.sqrt(+4.0);
714 Assert.assertEquals(StrictMath.sqrt(+4.0), +2.0d, 0.0);
715 Assert.assertEquals(StrictMath.sqrt(+49.0), +7.0d, 0.0);
716 Assert.assertEquals(StrictMath.sqrt(+1.44), +1.2d, 0.0);
717 }
718
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100719 public static void test_StrictMath_ceil() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800720 StrictMath.ceil(-0.9);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100721 Assert.assertEquals(StrictMath.ceil(+0.0), +0.0d, 0.0);
722 Assert.assertEquals(StrictMath.ceil(-0.0), -0.0d, 0.0);
723 Assert.assertEquals(StrictMath.ceil(-0.9), -0.0d, 0.0);
724 Assert.assertEquals(StrictMath.ceil(-0.5), -0.0d, 0.0);
725 Assert.assertEquals(StrictMath.ceil(0.0), -0.0d, 0.0);
726 Assert.assertEquals(StrictMath.ceil(+2.0), +2.0d, 0.0);
727 Assert.assertEquals(StrictMath.ceil(+2.1), +3.0d, 0.0);
728 Assert.assertEquals(StrictMath.ceil(+2.5), +3.0d, 0.0);
729 Assert.assertEquals(StrictMath.ceil(+2.9), +3.0d, 0.0);
730 Assert.assertEquals(StrictMath.ceil(+3.0), +3.0d, 0.0);
731 Assert.assertEquals(StrictMath.ceil(-2.0), -2.0d, 0.0);
732 Assert.assertEquals(StrictMath.ceil(-2.1), -2.0d, 0.0);
733 Assert.assertEquals(StrictMath.ceil(-2.5), -2.0d, 0.0);
734 Assert.assertEquals(StrictMath.ceil(-2.9), -2.0d, 0.0);
735 Assert.assertEquals(StrictMath.ceil(-3.0), -3.0d, 0.0);
736 Assert.assertEquals(StrictMath.ceil(Double.NaN), Double.NaN, 0.0);
737 Assert.assertEquals(StrictMath.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
738 Assert.assertEquals(StrictMath.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
739 }
740
741 public static void test_StrictMath_floor() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800742 StrictMath.floor(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100743 Assert.assertEquals(StrictMath.floor(+0.0), +0.0d, 0.0);
744 Assert.assertEquals(StrictMath.floor(-0.0), -0.0d, 0.0);
745 Assert.assertEquals(StrictMath.floor(+2.0), +2.0d, 0.0);
746 Assert.assertEquals(StrictMath.floor(+2.1), +2.0d, 0.0);
747 Assert.assertEquals(StrictMath.floor(+2.5), +2.0d, 0.0);
748 Assert.assertEquals(StrictMath.floor(+2.9), +2.0d, 0.0);
749 Assert.assertEquals(StrictMath.floor(+3.0), +3.0d, 0.0);
750 Assert.assertEquals(StrictMath.floor(-2.0), -2.0d, 0.0);
751 Assert.assertEquals(StrictMath.floor(-2.1), -3.0d, 0.0);
752 Assert.assertEquals(StrictMath.floor(-2.5), -3.0d, 0.0);
753 Assert.assertEquals(StrictMath.floor(-2.9), -3.0d, 0.0);
754 Assert.assertEquals(StrictMath.floor(-3.0), -3.0d, 0.0);
755 Assert.assertEquals(StrictMath.floor(Double.NaN), Double.NaN, 0.0);
756 Assert.assertEquals(StrictMath.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
757 Assert.assertEquals(StrictMath.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
758 }
759
760 public static void test_StrictMath_rint() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800761 StrictMath.rint(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100762 Assert.assertEquals(StrictMath.rint(+0.0), +0.0d, 0.0);
763 Assert.assertEquals(StrictMath.rint(-0.0), -0.0d, 0.0);
764 Assert.assertEquals(StrictMath.rint(+2.0), +2.0d, 0.0);
765 Assert.assertEquals(StrictMath.rint(+2.1), +2.0d, 0.0);
766 Assert.assertEquals(StrictMath.rint(+2.5), +2.0d, 0.0);
767 Assert.assertEquals(StrictMath.rint(+2.9), +3.0d, 0.0);
768 Assert.assertEquals(StrictMath.rint(+3.0), +3.0d, 0.0);
769 Assert.assertEquals(StrictMath.rint(-2.0), -2.0d, 0.0);
770 Assert.assertEquals(StrictMath.rint(-2.1), -2.0d, 0.0);
771 Assert.assertEquals(StrictMath.rint(-2.5), -2.0d, 0.0);
772 Assert.assertEquals(StrictMath.rint(-2.9), -3.0d, 0.0);
773 Assert.assertEquals(StrictMath.rint(-3.0), -3.0d, 0.0);
774 Assert.assertEquals(StrictMath.rint(Double.NaN), Double.NaN, 0.0);
775 Assert.assertEquals(StrictMath.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
776 Assert.assertEquals(StrictMath.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
777 }
778
779 public static void test_StrictMath_round_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800780 StrictMath.round(2.1d);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100781 Assert.assertEquals(StrictMath.round(+0.0d), (long)+0.0);
782 Assert.assertEquals(StrictMath.round(-0.0d), (long)+0.0);
783 Assert.assertEquals(StrictMath.round(2.0d), 2l);
784 Assert.assertEquals(StrictMath.round(2.1d), 2l);
785 Assert.assertEquals(StrictMath.round(2.5d), 3l);
786 Assert.assertEquals(StrictMath.round(2.9d), 3l);
787 Assert.assertEquals(StrictMath.round(3.0d), 3l);
788 Assert.assertEquals(StrictMath.round(-2.0d), -2l);
789 Assert.assertEquals(StrictMath.round(-2.1d), -2l);
790 Assert.assertEquals(StrictMath.round(-2.5d), -2l);
791 Assert.assertEquals(StrictMath.round(-2.9d), -3l);
792 Assert.assertEquals(StrictMath.round(-3.0d), -3l);
793 Assert.assertEquals(StrictMath.round(0.49999999999999994d), 1l);
794 Assert.assertEquals(StrictMath.round(Double.NaN), (long)+0.0d);
795 Assert.assertEquals(StrictMath.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
796 Assert.assertEquals(StrictMath.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
797 Assert.assertEquals(StrictMath.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
798 Assert.assertEquals(StrictMath.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
799 }
800
801 public static void test_StrictMath_round_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800802 StrictMath.round(2.1f);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100803 Assert.assertEquals(StrictMath.round(+0.0f), (int)+0.0);
804 Assert.assertEquals(StrictMath.round(-0.0f), (int)+0.0);
805 Assert.assertEquals(StrictMath.round(2.0f), 2);
806 Assert.assertEquals(StrictMath.round(2.1f), 2);
807 Assert.assertEquals(StrictMath.round(2.5f), 3);
808 Assert.assertEquals(StrictMath.round(2.9f), 3);
809 Assert.assertEquals(StrictMath.round(3.0f), 3);
810 Assert.assertEquals(StrictMath.round(-2.0f), -2);
811 Assert.assertEquals(StrictMath.round(-2.1f), -2);
812 Assert.assertEquals(StrictMath.round(-2.5f), -2);
813 Assert.assertEquals(StrictMath.round(-2.9f), -3);
814 Assert.assertEquals(StrictMath.round(-3.0f), -3);
815 Assert.assertEquals(StrictMath.round(Float.NaN), (int)+0.0f);
816 Assert.assertEquals(StrictMath.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
817 Assert.assertEquals(StrictMath.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
818 Assert.assertEquals(StrictMath.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
819 Assert.assertEquals(StrictMath.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
820 }
821
Elliott Hughes28c384b2012-06-15 16:46:25 -0700822 public static void test_Float_floatToRawIntBits() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800823 Float.floatToRawIntBits(-1.0f);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700824 Assert.assertEquals(Float.floatToRawIntBits(-1.0f), 0xbf800000);
825 Assert.assertEquals(Float.floatToRawIntBits(0.0f), 0);
826 Assert.assertEquals(Float.floatToRawIntBits(1.0f), 0x3f800000);
827 Assert.assertEquals(Float.floatToRawIntBits(Float.NaN), 0x7fc00000);
828 Assert.assertEquals(Float.floatToRawIntBits(Float.POSITIVE_INFINITY), 0x7f800000);
829 Assert.assertEquals(Float.floatToRawIntBits(Float.NEGATIVE_INFINITY), 0xff800000);
830 }
831
832 public static void test_Float_intBitsToFloat() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800833 Float.intBitsToFloat(0xbf800000);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700834 Assert.assertEquals(Float.intBitsToFloat(0xbf800000), -1.0f);
835 Assert.assertEquals(Float.intBitsToFloat(0x00000000), 0.0f);
836 Assert.assertEquals(Float.intBitsToFloat(0x3f800000), 1.0f);
837 Assert.assertEquals(Float.intBitsToFloat(0x7fc00000), Float.NaN);
838 Assert.assertEquals(Float.intBitsToFloat(0x7f800000), Float.POSITIVE_INFINITY);
839 Assert.assertEquals(Float.intBitsToFloat(0xff800000), Float.NEGATIVE_INFINITY);
840 }
841
842 public static void test_Double_doubleToRawLongBits() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800843 Double.doubleToRawLongBits(-1.0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700844 Assert.assertEquals(Double.doubleToRawLongBits(-1.0), 0xbff0000000000000L);
845 Assert.assertEquals(Double.doubleToRawLongBits(0.0), 0x0000000000000000L);
846 Assert.assertEquals(Double.doubleToRawLongBits(1.0), 0x3ff0000000000000L);
847 Assert.assertEquals(Double.doubleToRawLongBits(Double.NaN), 0x7ff8000000000000L);
848 Assert.assertEquals(Double.doubleToRawLongBits(Double.POSITIVE_INFINITY), 0x7ff0000000000000L);
849 Assert.assertEquals(Double.doubleToRawLongBits(Double.NEGATIVE_INFINITY), 0xfff0000000000000L);
850 }
851
852 public static void test_Double_longBitsToDouble() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800853 Double.longBitsToDouble(0xbff0000000000000L);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700854 Assert.assertEquals(Double.longBitsToDouble(0xbff0000000000000L), -1.0);
855 Assert.assertEquals(Double.longBitsToDouble(0x0000000000000000L), 0.0);
856 Assert.assertEquals(Double.longBitsToDouble(0x3ff0000000000000L), 1.0);
857 Assert.assertEquals(Double.longBitsToDouble(0x7ff8000000000000L), Double.NaN);
858 Assert.assertEquals(Double.longBitsToDouble(0x7ff0000000000000L), Double.POSITIVE_INFINITY);
859 Assert.assertEquals(Double.longBitsToDouble(0xfff0000000000000L), Double.NEGATIVE_INFINITY);
860 }
Serban Constantinescu23abec92014-07-02 16:13:38 +0100861
Zheng Xua3fe7422014-07-09 14:03:15 +0800862 public static void test_Short_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800863 Short.reverseBytes((short)0x1357);
Zheng Xua3fe7422014-07-09 14:03:15 +0800864 Assert.assertEquals(Short.reverseBytes((short)0x0000), (short)0x0000);
865 Assert.assertEquals(Short.reverseBytes((short)0xffff), (short)0xffff);
866 Assert.assertEquals(Short.reverseBytes((short)0x8000), (short)0x0080);
867 Assert.assertEquals(Short.reverseBytes((short)0x0080), (short)0x8000);
868 Assert.assertEquals(Short.reverseBytes((short)0x0123), (short)0x2301);
869 Assert.assertEquals(Short.reverseBytes((short)0x4567), (short)0x6745);
870 Assert.assertEquals(Short.reverseBytes((short)0x89ab), (short)0xab89);
871 Assert.assertEquals(Short.reverseBytes((short)0xcdef), (short)0xefcd);
872 }
873
874 public static void test_Integer_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800875 Integer.reverseBytes(0x13579bdf);
Zheng Xua3fe7422014-07-09 14:03:15 +0800876 Assert.assertEquals(Integer.reverseBytes(0x00000000), 0x00000000);
877 Assert.assertEquals(Integer.reverseBytes(0xffffffff), 0xffffffff);
878 Assert.assertEquals(Integer.reverseBytes(0x80000000), 0x00000080);
879 Assert.assertEquals(Integer.reverseBytes(0x00000080), 0x80000000);
880 Assert.assertEquals(Integer.reverseBytes(0x01234567), 0x67452301);
881 Assert.assertEquals(Integer.reverseBytes(0x89abcdef), 0xefcdab89);
882 }
883
884 public static void test_Long_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800885 Long.reverseBytes(0x13579bdf2468ace0L);
Zheng Xua3fe7422014-07-09 14:03:15 +0800886 Assert.assertEquals(Long.reverseBytes(0x0000000000000000L), 0x0000000000000000L);
887 Assert.assertEquals(Long.reverseBytes(0xffffffffffffffffL), 0xffffffffffffffffL);
888 Assert.assertEquals(Long.reverseBytes(0x8000000000000000L), 0x0000000000000080L);
889 Assert.assertEquals(Long.reverseBytes(0x0000000000000080L), 0x8000000000000000L);
890 Assert.assertEquals(Long.reverseBytes(0x0123456789abcdefL), 0xefcdab8967452301L);
891 }
892
Serban Constantinescu23abec92014-07-02 16:13:38 +0100893 public static void test_Integer_reverse() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800894 Integer.reverse(0x12345678);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100895 Assert.assertEquals(Integer.reverse(1), 0x80000000);
896 Assert.assertEquals(Integer.reverse(-1), 0xffffffff);
897 Assert.assertEquals(Integer.reverse(0), 0);
898 Assert.assertEquals(Integer.reverse(0x12345678), 0x1e6a2c48);
899 Assert.assertEquals(Integer.reverse(0x87654321), 0x84c2a6e1);
900 Assert.assertEquals(Integer.reverse(Integer.MAX_VALUE), 0xfffffffe);
901 Assert.assertEquals(Integer.reverse(Integer.MIN_VALUE), 1);
902 }
903
904 public static void test_Long_reverse() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800905 Long.reverse(0x1234567812345678L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100906 Assert.assertEquals(Long.reverse(1L), 0x8000000000000000L);
907 Assert.assertEquals(Long.reverse(-1L), 0xffffffffffffffffL);
908 Assert.assertEquals(Long.reverse(0L), 0L);
Zheng Xua3fe7422014-07-09 14:03:15 +0800909 Assert.assertEquals(Long.reverse(0x1234567812345678L), 0x1e6a2c481e6a2c48L);
910 Assert.assertEquals(Long.reverse(0x8765432187654321L), 0x84c2a6e184c2a6e1L);
911 Assert.assertEquals(Long.reverse(Long.MAX_VALUE), 0xfffffffffffffffeL);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100912 Assert.assertEquals(Long.reverse(Long.MIN_VALUE), 1L);
913 }
914
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700915 static Object runtime;
916 static Method address_of;
Zuo Wangf37a88b2014-07-10 04:26:41 -0700917 static Method new_non_movable_array;
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700918 static Method peek_byte;
919 static Method peek_short;
920 static Method peek_int;
921 static Method peek_long;
922 static Method poke_byte;
923 static Method poke_short;
924 static Method poke_int;
925 static Method poke_long;
926
927 public static void initSupportMethodsForPeekPoke() throws Exception {
928 Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
929 Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
930 runtime = get_runtime.invoke(null);
931 address_of = vm_runtime.getDeclaredMethod("addressOf", Object.class);
Zuo Wangf37a88b2014-07-10 04:26:41 -0700932 new_non_movable_array = vm_runtime.getDeclaredMethod("newNonMovableArray", Class.class, Integer.TYPE);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700933
934 Class<?> io_memory = Class.forName("libcore.io.Memory");
935 peek_byte = io_memory.getDeclaredMethod("peekByte", Long.TYPE);
936 peek_int = io_memory.getDeclaredMethod("peekInt", Long.TYPE, Boolean.TYPE);
937 peek_short = io_memory.getDeclaredMethod("peekShort", Long.TYPE, Boolean.TYPE);
938 peek_long = io_memory.getDeclaredMethod("peekLong", Long.TYPE, Boolean.TYPE);
939 poke_byte = io_memory.getDeclaredMethod("pokeByte", Long.TYPE, Byte.TYPE);
940 poke_short = io_memory.getDeclaredMethod("pokeShort", Long.TYPE, Short.TYPE, Boolean.TYPE);
941 poke_int = io_memory.getDeclaredMethod("pokeInt", Long.TYPE, Integer.TYPE, Boolean.TYPE);
942 poke_long = io_memory.getDeclaredMethod("pokeLong", Long.TYPE, Long.TYPE, Boolean.TYPE);
943 }
944
945 public static void test_Memory_peekByte() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700946 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700947 b[0] = 0x12;
948 b[1] = 0x11;
949 long address = (long)address_of.invoke(runtime, b);
950 Assert.assertEquals((byte)peek_byte.invoke(null, address), 0x12);
951 Assert.assertEquals((byte)peek_byte.invoke(null, address + 1), 0x11);
952 }
953
954 public static void test_Memory_peekShort() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700955 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700956 b[0] = 0x13;
957 b[1] = 0x12;
958 b[2] = 0x11;
959 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800960 peek_short.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700961 Assert.assertEquals((short)peek_short.invoke(null, address, false), 0x1213); // Aligned read
962 Assert.assertEquals((short)peek_short.invoke(null, address + 1, false), 0x1112); // Unaligned read
963 }
964
965 public static void test_Memory_peekInt() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700966 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700967 b[0] = 0x15;
968 b[1] = 0x14;
969 b[2] = 0x13;
970 b[3] = 0x12;
971 b[4] = 0x11;
972 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800973 peek_int.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700974 Assert.assertEquals((int)peek_int.invoke(null, address, false), 0x12131415);
975 Assert.assertEquals((int)peek_int.invoke(null, address + 1, false), 0x11121314);
976 }
977
978 public static void test_Memory_peekLong() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700979 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700980 b[0] = 0x19;
981 b[1] = 0x18;
982 b[2] = 0x17;
983 b[3] = 0x16;
984 b[4] = 0x15;
985 b[5] = 0x14;
986 b[6] = 0x13;
987 b[7] = 0x12;
988 b[8] = 0x11;
989 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800990 peek_long.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700991 Assert.assertEquals((long)peek_long.invoke(null, address, false), 0x1213141516171819L);
992 Assert.assertEquals((long)peek_long.invoke(null, address + 1, false), 0x1112131415161718L);
993 }
994
995 public static void test_Memory_pokeByte() throws Exception {
996 byte[] r = {0x11, 0x12};
Zuo Wangf37a88b2014-07-10 04:26:41 -0700997 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700998 long address = (long)address_of.invoke(runtime, b);
999 poke_byte.invoke(null, address, (byte)0x11);
1000 poke_byte.invoke(null, address + 1, (byte)0x12);
1001 Assert.assertTrue(Arrays.equals(r, b));
1002 }
1003
1004 public static void test_Memory_pokeShort() throws Exception {
1005 byte[] ra = {0x12, 0x11, 0x13};
1006 byte[] ru = {0x12, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001007 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001008 long address = (long)address_of.invoke(runtime, b);
1009
1010 // Aligned write
1011 b[2] = 0x13;
1012 poke_short.invoke(null, address, (short)0x1112, false);
1013 Assert.assertTrue(Arrays.equals(ra, b));
1014
1015 // Unaligned write
1016 poke_short.invoke(null, address + 1, (short)0x2122, false);
1017 Assert.assertTrue(Arrays.equals(ru, b));
1018 }
1019
1020 public static void test_Memory_pokeInt() throws Exception {
1021 byte[] ra = {0x14, 0x13, 0x12, 0x11, 0x15};
1022 byte[] ru = {0x14, 0x24, 0x23, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001023 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001024 long address = (long)address_of.invoke(runtime, b);
1025
1026 b[4] = 0x15;
1027 poke_int.invoke(null, address, (int)0x11121314, false);
1028 Assert.assertTrue(Arrays.equals(ra, b));
1029
1030 poke_int.invoke(null, address + 1, (int)0x21222324, false);
1031 Assert.assertTrue(Arrays.equals(ru, b));
1032 }
1033
1034 public static void test_Memory_pokeLong() throws Exception {
1035 byte[] ra = {0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x19};
1036 byte[] ru = {0x18, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001037 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001038 long address = (long)address_of.invoke(runtime, b);
1039
1040 b[8] = 0x19;
1041 poke_long.invoke(null, address, (long)0x1112131415161718L, false);
1042 Assert.assertTrue(Arrays.equals(ra, b));
1043
1044 poke_long.invoke(null, address + 1, (long)0x2122232425262728L, false);
1045 Assert.assertTrue(Arrays.equals(ru, b));
1046 }
jeffhao5d1ac922011-09-29 17:41:15 -07001047}