blob: 5185f9720165f32ea20d80125e6c3cb4acc5c8d9 [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 Assert.assertEquals(str0.indexOf('a'), -1);
240 Assert.assertEquals(str3.indexOf('a'), 0);
241 Assert.assertEquals(str3.indexOf('b'), 1);
242 Assert.assertEquals(str3.indexOf('c'), 2);
243 Assert.assertEquals(str10.indexOf('j'), 9);
244 Assert.assertEquals(str40.indexOf('a'), 0);
245 Assert.assertEquals(str40.indexOf('b'), 38);
246 Assert.assertEquals(str40.indexOf('c'), 39);
247 Assert.assertEquals(str0.indexOf('a',20), -1);
248 Assert.assertEquals(str0.indexOf('a',0), -1);
249 Assert.assertEquals(str0.indexOf('a',-1), -1);
Yevgeny Rouban34fa0d92014-03-13 12:15:58 +0700250 Assert.assertEquals(str1.indexOf('/',++start), -1);
Alexei Zavjalova1758d82014-04-17 01:55:43 +0700251 Assert.assertEquals(str1.indexOf('a',negIndex[0]), -1);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700252 Assert.assertEquals(str3.indexOf('a',0), 0);
253 Assert.assertEquals(str3.indexOf('a',1), -1);
254 Assert.assertEquals(str3.indexOf('a',1234), -1);
255 Assert.assertEquals(str3.indexOf('b',0), 1);
256 Assert.assertEquals(str3.indexOf('b',1), 1);
257 Assert.assertEquals(str3.indexOf('c',2), 2);
258 Assert.assertEquals(str10.indexOf('j',5), 9);
259 Assert.assertEquals(str10.indexOf('j',9), 9);
260 Assert.assertEquals(str40.indexOf('a',10), 10);
261 Assert.assertEquals(str40.indexOf('b',40), -1);
262
Andreas Gampe678e6952015-05-07 16:44:58 -0700263 testIndexOfNull();
264
265 testSurrogateIndexOf();
266 }
267
268 private static void testSurrogateIndexOf() {
269 int supplementaryChar = 0x20b9f;
270 String surrogatePair = "\ud842\udf9f";
271 String stringWithSurrogates = "hello " + surrogatePair + " world";
272
273 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar), "hello ".length());
274 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 2), "hello ".length());
275 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 6), 6);
276 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar, 7), -1);
Andreas Gampeba6fdbc2015-05-07 22:31:55 -0700277
278 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar - 0x10000), -1);
279 Assert.assertEquals(stringWithSurrogates.indexOf(supplementaryChar | 0x80000000), -1);
Andreas Gampe678e6952015-05-07 16:44:58 -0700280 }
281
282 private static void testIndexOfNull() {
Elliott Hughes28c384b2012-06-15 16:46:25 -0700283 String strNull = null;
284 try {
Andreas Gampe678e6952015-05-07 16:44:58 -0700285 testNullIndex(strNull, 'a');
Elliott Hughes28c384b2012-06-15 16:46:25 -0700286 Assert.fail();
287 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700288 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700289 try {
Andreas Gampe678e6952015-05-07 16:44:58 -0700290 testNullIndex(strNull, 'a', 0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700291 Assert.fail();
292 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700293 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700294 try {
Andreas Gampe678e6952015-05-07 16:44:58 -0700295 testNullIndex(strNull, 'a', -1);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700296 Assert.fail();
297 } catch (NullPointerException expected) {
jeffhao5d1ac922011-09-29 17:41:15 -0700298 }
Elliott Hughes28c384b2012-06-15 16:46:25 -0700299 }
jeffhao5d1ac922011-09-29 17:41:15 -0700300
Andreas Gampe678e6952015-05-07 16:44:58 -0700301 private static int testNullIndex(String strNull, int c) {
302 return strNull.indexOf(c);
303 }
304
305 private static int testNullIndex(String strNull, int c, int startIndex) {
306 return strNull.indexOf(c, startIndex);
307 }
308
Elliott Hughes28c384b2012-06-15 16:46:25 -0700309 public static void test_String_compareTo() {
310 String test = "0123456789";
311 String test1 = new String("0123456789"); // different object
312 String test2 = new String("0123456780"); // different value
313 String offset = new String("xxx0123456789yyy");
314 String sub = offset.substring(3, 13);
315 String str32 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
316 String str33 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxy";
317 String lc = "abcdefg";
318 String uc = "ABCDEFG";
319 Object blah = new Object();
320
321 Assert.assertTrue(lc.toUpperCase().equals(uc));
322
323 Assert.assertEquals(str32.compareTo(str33), -1);
324 Assert.assertEquals(str33.compareTo(str32), 1);
325
326 Assert.assertTrue(test.equals(test));
327 Assert.assertTrue(test.equals(test1));
328 Assert.assertFalse(test.equals(test2));
329
330 Assert.assertEquals(test.compareTo(test1), 0);
331 Assert.assertTrue(test1.compareTo(test2) > 0);
332 Assert.assertTrue(test2.compareTo(test1) < 0);
333
334 // Compare string with a nonzero offset, in left/right side.
335 Assert.assertEquals(test.compareTo(sub), 0);
336 Assert.assertEquals(sub.compareTo(test), 0);
337 Assert.assertTrue(test.equals(sub));
338 Assert.assertTrue(sub.equals(test));
339 // Same base, one is a substring.
340 Assert.assertFalse(offset.equals(sub));
341 Assert.assertFalse(sub.equals(offset));
342 // Wrong class.
343 Assert.assertFalse(test.equals(blah));
344
345 // Null lhs - throw.
346 try {
347 test.compareTo(null);
348 Assert.fail("didn't get expected npe");
349 } catch (NullPointerException npe) {
350 }
351 // Null rhs - okay.
352 Assert.assertFalse(test.equals(null));
353
354 test = test.substring(1);
355 Assert.assertTrue(test.equals("123456789"));
356 Assert.assertFalse(test.equals(test1));
357
358 test = test.substring(1);
359 Assert.assertTrue(test.equals("23456789"));
360
361 test = test.substring(1);
362 Assert.assertTrue(test.equals("3456789"));
363
364 test = test.substring(1);
365 Assert.assertTrue(test.equals("456789"));
366
367 test = test.substring(3,5);
368 Assert.assertTrue(test.equals("78"));
369
370 test = "this/is/a/path";
371 String[] strings = test.split("/");
372 Assert.assertEquals(4, strings.length);
373
374 Assert.assertEquals("this is a path", test.replaceAll("/", " "));
375 Assert.assertEquals("this is a path", test.replace("/", " "));
376 }
377
378 public static void test_Math_abs_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800379 Math.abs(-1);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700380 Assert.assertEquals(Math.abs(0), 0);
381 Assert.assertEquals(Math.abs(123), 123);
382 Assert.assertEquals(Math.abs(-123), 123);
383 Assert.assertEquals(Math.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
384 Assert.assertEquals(Math.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
385 Assert.assertEquals(Math.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100386 Assert.assertEquals(Math.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700387 }
388
389 public static void test_Math_abs_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800390 Math.abs(-1L);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700391 Assert.assertEquals(Math.abs(0L), 0L);
392 Assert.assertEquals(Math.abs(123L), 123L);
393 Assert.assertEquals(Math.abs(-123L), 123L);
394 Assert.assertEquals(Math.abs(Long.MAX_VALUE), Long.MAX_VALUE);
395 Assert.assertEquals(Math.abs(Long.MIN_VALUE), Long.MIN_VALUE);
396 Assert.assertEquals(Math.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
Andreas Gampe2bcf9bf2015-01-29 09:56:07 -0800397 Assert.assertEquals(Math.abs(2147483648L), 2147483648L);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700398 }
399
Serban Constantinescu23abec92014-07-02 16:13:38 +0100400 public static void test_Math_min_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800401 Math.min(1, 0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700402 Assert.assertEquals(Math.min(0, 0), 0);
403 Assert.assertEquals(Math.min(1, 0), 0);
404 Assert.assertEquals(Math.min(0, 1), 0);
405 Assert.assertEquals(Math.min(0, Integer.MAX_VALUE), 0);
406 Assert.assertEquals(Math.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
407 Assert.assertEquals(Math.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
408 }
409
Serban Constantinescu23abec92014-07-02 16:13:38 +0100410 public static void test_Math_max_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800411 Math.max(1, 0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700412 Assert.assertEquals(Math.max(0, 0), 0);
413 Assert.assertEquals(Math.max(1, 0), 1);
414 Assert.assertEquals(Math.max(0, 1), 1);
415 Assert.assertEquals(Math.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
416 Assert.assertEquals(Math.max(Integer.MIN_VALUE, 0), 0);
417 Assert.assertEquals(Math.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
418 }
419
Serban Constantinescu23abec92014-07-02 16:13:38 +0100420 public static void test_Math_min_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800421 Math.min(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100422 Assert.assertEquals(Math.min(0L, 0L), 0L);
423 Assert.assertEquals(Math.min(1L, 0L), 0L);
424 Assert.assertEquals(Math.min(0L, 1L), 0L);
425 Assert.assertEquals(Math.min(0L, Long.MAX_VALUE), 0L);
426 Assert.assertEquals(Math.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
427 Assert.assertEquals(Math.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
428 }
429
430 public static void test_Math_max_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800431 Math.max(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100432 Assert.assertEquals(Math.max(0L, 0L), 0L);
433 Assert.assertEquals(Math.max(1L, 0L), 1L);
434 Assert.assertEquals(Math.max(0L, 1L), 1L);
435 Assert.assertEquals(Math.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
436 Assert.assertEquals(Math.max(Long.MIN_VALUE, 0L), 0L);
437 Assert.assertEquals(Math.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
438 }
439
440 public static void test_Math_min_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800441 Math.min(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700442 Assert.assertTrue(Float.isNaN(Math.min(1.0f, Float.NaN)));
443 Assert.assertTrue(Float.isNaN(Math.min(Float.NaN, 1.0f)));
444 Assert.assertEquals(Math.min(-0.0f, 0.0f), -0.0f);
445 Assert.assertEquals(Math.min(0.0f, -0.0f), -0.0f);
446 Assert.assertEquals(Math.min(-0.0f, -0.0f), -0.0f);
447 Assert.assertEquals(Math.min(0.0f, 0.0f), 0.0f);
448 Assert.assertEquals(Math.min(1.0f, 0.0f), 0.0f);
449 Assert.assertEquals(Math.min(0.0f, 1.0f), 0.0f);
450 Assert.assertEquals(Math.min(0.0f, Float.MAX_VALUE), 0.0f);
451 Assert.assertEquals(Math.min(Float.MIN_VALUE, 0.0f), 0.0f);
452 Assert.assertEquals(Math.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100453 }
454
455 public static void test_Math_max_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800456 Math.max(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700457 Assert.assertTrue(Float.isNaN(Math.max(1.0f, Float.NaN)));
458 Assert.assertTrue(Float.isNaN(Math.max(Float.NaN, 1.0f)));
459 Assert.assertEquals(Math.max(-0.0f, 0.0f), 0.0f);
460 Assert.assertEquals(Math.max(0.0f, -0.0f), 0.0f);
461 Assert.assertEquals(Math.max(-0.0f, -0.0f), -0.0f);
462 Assert.assertEquals(Math.max(0.0f, 0.0f), 0.0f);
463 Assert.assertEquals(Math.max(1.0f, 0.0f), 1.0f);
464 Assert.assertEquals(Math.max(0.0f, 1.0f), 1.0f);
465 Assert.assertEquals(Math.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
466 Assert.assertEquals(Math.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
467 Assert.assertEquals(Math.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100468 }
469
470 public static void test_Math_min_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800471 Math.min(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700472 Assert.assertTrue(Double.isNaN(Math.min(1.0d, Double.NaN)));
473 Assert.assertTrue(Double.isNaN(Math.min(Double.NaN, 1.0d)));
474 Assert.assertEquals(Math.min(-0.0d, 0.0d), -0.0d);
475 Assert.assertEquals(Math.min(0.0d, -0.0d), -0.0d);
476 Assert.assertEquals(Math.min(-0.0d, -0.0d), -0.0d);
477 Assert.assertEquals(Math.min(0.0d, 0.0d), 0.0d);
478 Assert.assertEquals(Math.min(1.0d, 0.0d), 0.0d);
479 Assert.assertEquals(Math.min(0.0d, 1.0d), 0.0d);
480 Assert.assertEquals(Math.min(0.0d, Double.MAX_VALUE), 0.0d);
481 Assert.assertEquals(Math.min(Double.MIN_VALUE, 0.0d), 0.0d);
482 Assert.assertEquals(Math.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100483 }
484
485 public static void test_Math_max_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800486 Math.max(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700487 Assert.assertTrue(Double.isNaN(Math.max(1.0d, Double.NaN)));
488 Assert.assertTrue(Double.isNaN(Math.max(Double.NaN, 1.0d)));
489 Assert.assertEquals(Math.max(-0.0d, 0.0d), 0.0d);
490 Assert.assertEquals(Math.max(0.0d, -0.0d), 0.0d);
491 Assert.assertEquals(Math.max(-0.0d, -0.0d), -0.0d);
492 Assert.assertEquals(Math.max(0.0d, 0.0d), 0.0d);
493 Assert.assertEquals(Math.max(1.0d, 0.0d), 1.0d);
494 Assert.assertEquals(Math.max(0.0d, 1.0d), 1.0d);
495 Assert.assertEquals(Math.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
496 Assert.assertEquals(Math.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
497 Assert.assertEquals(Math.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100498 }
499
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800500 public static void test_Math_sqrt() {
501 Math.sqrt(+4.0);
502 Assert.assertEquals(Math.sqrt(+4.0), +2.0d, 0.0);
503 Assert.assertEquals(Math.sqrt(+49.0), +7.0d, 0.0);
504 Assert.assertEquals(Math.sqrt(+1.44), +1.2d, 0.0);
505 }
506
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100507 public static void test_Math_ceil() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800508 Math.ceil(-0.9);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100509 Assert.assertEquals(Math.ceil(+0.0), +0.0d, 0.0);
510 Assert.assertEquals(Math.ceil(-0.0), -0.0d, 0.0);
511 Assert.assertEquals(Math.ceil(-0.9), -0.0d, 0.0);
512 Assert.assertEquals(Math.ceil(-0.5), -0.0d, 0.0);
513 Assert.assertEquals(Math.ceil(0.0), -0.0d, 0.0);
514 Assert.assertEquals(Math.ceil(+2.0), +2.0d, 0.0);
515 Assert.assertEquals(Math.ceil(+2.1), +3.0d, 0.0);
516 Assert.assertEquals(Math.ceil(+2.5), +3.0d, 0.0);
517 Assert.assertEquals(Math.ceil(+2.9), +3.0d, 0.0);
518 Assert.assertEquals(Math.ceil(+3.0), +3.0d, 0.0);
519 Assert.assertEquals(Math.ceil(-2.0), -2.0d, 0.0);
520 Assert.assertEquals(Math.ceil(-2.1), -2.0d, 0.0);
521 Assert.assertEquals(Math.ceil(-2.5), -2.0d, 0.0);
522 Assert.assertEquals(Math.ceil(-2.9), -2.0d, 0.0);
523 Assert.assertEquals(Math.ceil(-3.0), -3.0d, 0.0);
524 Assert.assertEquals(Math.ceil(Double.NaN), Double.NaN, 0.0);
525 Assert.assertEquals(Math.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
526 Assert.assertEquals(Math.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
527 }
528
529 public static void test_Math_floor() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800530 Math.floor(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100531 Assert.assertEquals(Math.floor(+0.0), +0.0d, 0.0);
532 Assert.assertEquals(Math.floor(-0.0), -0.0d, 0.0);
533 Assert.assertEquals(Math.floor(+2.0), +2.0d, 0.0);
534 Assert.assertEquals(Math.floor(+2.1), +2.0d, 0.0);
535 Assert.assertEquals(Math.floor(+2.5), +2.0d, 0.0);
536 Assert.assertEquals(Math.floor(+2.9), +2.0d, 0.0);
537 Assert.assertEquals(Math.floor(+3.0), +3.0d, 0.0);
538 Assert.assertEquals(Math.floor(-2.0), -2.0d, 0.0);
539 Assert.assertEquals(Math.floor(-2.1), -3.0d, 0.0);
540 Assert.assertEquals(Math.floor(-2.5), -3.0d, 0.0);
541 Assert.assertEquals(Math.floor(-2.9), -3.0d, 0.0);
542 Assert.assertEquals(Math.floor(-3.0), -3.0d, 0.0);
543 Assert.assertEquals(Math.floor(Double.NaN), Double.NaN, 0.0);
544 Assert.assertEquals(Math.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
545 Assert.assertEquals(Math.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
546 }
547
548 public static void test_Math_rint() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800549 Math.rint(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100550 Assert.assertEquals(Math.rint(+0.0), +0.0d, 0.0);
551 Assert.assertEquals(Math.rint(-0.0), -0.0d, 0.0);
552 Assert.assertEquals(Math.rint(+2.0), +2.0d, 0.0);
553 Assert.assertEquals(Math.rint(+2.1), +2.0d, 0.0);
554 Assert.assertEquals(Math.rint(+2.5), +2.0d, 0.0);
555 Assert.assertEquals(Math.rint(+2.9), +3.0d, 0.0);
556 Assert.assertEquals(Math.rint(+3.0), +3.0d, 0.0);
557 Assert.assertEquals(Math.rint(-2.0), -2.0d, 0.0);
558 Assert.assertEquals(Math.rint(-2.1), -2.0d, 0.0);
559 Assert.assertEquals(Math.rint(-2.5), -2.0d, 0.0);
560 Assert.assertEquals(Math.rint(-2.9), -3.0d, 0.0);
561 Assert.assertEquals(Math.rint(-3.0), -3.0d, 0.0);
562 Assert.assertEquals(Math.rint(Double.NaN), Double.NaN, 0.0);
563 Assert.assertEquals(Math.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
564 Assert.assertEquals(Math.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
565 }
566
567 public static void test_Math_round_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800568 Math.round(2.1d);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100569 Assert.assertEquals(Math.round(+0.0d), (long)+0.0);
570 Assert.assertEquals(Math.round(-0.0d), (long)+0.0);
571 Assert.assertEquals(Math.round(2.0d), 2l);
572 Assert.assertEquals(Math.round(2.1d), 2l);
573 Assert.assertEquals(Math.round(2.5d), 3l);
574 Assert.assertEquals(Math.round(2.9d), 3l);
575 Assert.assertEquals(Math.round(3.0d), 3l);
576 Assert.assertEquals(Math.round(-2.0d), -2l);
577 Assert.assertEquals(Math.round(-2.1d), -2l);
578 Assert.assertEquals(Math.round(-2.5d), -2l);
579 Assert.assertEquals(Math.round(-2.9d), -3l);
580 Assert.assertEquals(Math.round(-3.0d), -3l);
581 Assert.assertEquals(Math.round(0.49999999999999994d), 1l);
582 Assert.assertEquals(Math.round(Double.NaN), (long)+0.0d);
583 Assert.assertEquals(Math.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
584 Assert.assertEquals(Math.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
585 Assert.assertEquals(Math.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
586 Assert.assertEquals(Math.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
587 }
588
589 public static void test_Math_round_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800590 Math.round(2.1f);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100591 Assert.assertEquals(Math.round(+0.0f), (int)+0.0);
592 Assert.assertEquals(Math.round(-0.0f), (int)+0.0);
593 Assert.assertEquals(Math.round(2.0f), 2);
594 Assert.assertEquals(Math.round(2.1f), 2);
595 Assert.assertEquals(Math.round(2.5f), 3);
596 Assert.assertEquals(Math.round(2.9f), 3);
597 Assert.assertEquals(Math.round(3.0f), 3);
598 Assert.assertEquals(Math.round(-2.0f), -2);
599 Assert.assertEquals(Math.round(-2.1f), -2);
600 Assert.assertEquals(Math.round(-2.5f), -2);
601 Assert.assertEquals(Math.round(-2.9f), -3);
602 Assert.assertEquals(Math.round(-3.0f), -3);
603 Assert.assertEquals(Math.round(Float.NaN), (int)+0.0f);
604 Assert.assertEquals(Math.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
605 Assert.assertEquals(Math.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
606 Assert.assertEquals(Math.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
607 Assert.assertEquals(Math.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
608 }
609
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100610 public static void test_StrictMath_abs_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800611 StrictMath.abs(-1);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100612 Assert.assertEquals(StrictMath.abs(0), 0);
613 Assert.assertEquals(StrictMath.abs(123), 123);
614 Assert.assertEquals(StrictMath.abs(-123), 123);
615 Assert.assertEquals(StrictMath.abs(Integer.MAX_VALUE), Integer.MAX_VALUE);
616 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE), Integer.MIN_VALUE);
617 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE - 1), Integer.MAX_VALUE);
618 Assert.assertEquals(StrictMath.abs(Integer.MIN_VALUE + 1), Integer.MAX_VALUE);
619 }
620
621 public static void test_StrictMath_abs_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800622 StrictMath.abs(-1L);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100623 Assert.assertEquals(StrictMath.abs(0L), 0L);
624 Assert.assertEquals(StrictMath.abs(123L), 123L);
625 Assert.assertEquals(StrictMath.abs(-123L), 123L);
626 Assert.assertEquals(StrictMath.abs(Long.MAX_VALUE), Long.MAX_VALUE);
627 Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE), Long.MIN_VALUE);
628 Assert.assertEquals(StrictMath.abs(Long.MIN_VALUE - 1), Long.MAX_VALUE);
629 }
630
Serban Constantinescu23abec92014-07-02 16:13:38 +0100631 public static void test_StrictMath_min_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800632 StrictMath.min(1, 0);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100633 Assert.assertEquals(StrictMath.min(0, 0), 0);
634 Assert.assertEquals(StrictMath.min(1, 0), 0);
635 Assert.assertEquals(StrictMath.min(0, 1), 0);
636 Assert.assertEquals(StrictMath.min(0, Integer.MAX_VALUE), 0);
637 Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, 0), Integer.MIN_VALUE);
638 Assert.assertEquals(StrictMath.min(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MIN_VALUE);
639 }
640
Serban Constantinescu23abec92014-07-02 16:13:38 +0100641 public static void test_StrictMath_max_I() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800642 StrictMath.max(1, 0);
Sebastien Hertzbf1442d2013-03-05 15:12:40 +0100643 Assert.assertEquals(StrictMath.max(0, 0), 0);
644 Assert.assertEquals(StrictMath.max(1, 0), 1);
645 Assert.assertEquals(StrictMath.max(0, 1), 1);
646 Assert.assertEquals(StrictMath.max(0, Integer.MAX_VALUE), Integer.MAX_VALUE);
647 Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, 0), 0);
648 Assert.assertEquals(StrictMath.max(Integer.MIN_VALUE, Integer.MAX_VALUE), Integer.MAX_VALUE);
649 }
650
Serban Constantinescu23abec92014-07-02 16:13:38 +0100651 public static void test_StrictMath_min_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800652 StrictMath.min(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100653 Assert.assertEquals(StrictMath.min(0L, 0L), 0L);
654 Assert.assertEquals(StrictMath.min(1L, 0L), 0L);
655 Assert.assertEquals(StrictMath.min(0L, 1L), 0L);
656 Assert.assertEquals(StrictMath.min(0L, Long.MAX_VALUE), 0L);
657 Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, 0L), Long.MIN_VALUE);
658 Assert.assertEquals(StrictMath.min(Long.MIN_VALUE, Long.MAX_VALUE), Long.MIN_VALUE);
659 }
660
661 public static void test_StrictMath_max_J() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800662 StrictMath.max(1L, 0L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100663 Assert.assertEquals(StrictMath.max(0L, 0L), 0L);
664 Assert.assertEquals(StrictMath.max(1L, 0L), 1L);
665 Assert.assertEquals(StrictMath.max(0L, 1L), 1L);
666 Assert.assertEquals(StrictMath.max(0L, Long.MAX_VALUE), Long.MAX_VALUE);
667 Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, 0L), 0L);
668 Assert.assertEquals(StrictMath.max(Long.MIN_VALUE, Long.MAX_VALUE), Long.MAX_VALUE);
669 }
670
671 public static void test_StrictMath_min_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800672 StrictMath.min(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700673 Assert.assertTrue(Float.isNaN(StrictMath.min(1.0f, Float.NaN)));
674 Assert.assertTrue(Float.isNaN(StrictMath.min(Float.NaN, 1.0f)));
675 Assert.assertEquals(StrictMath.min(-0.0f, 0.0f), -0.0f);
676 Assert.assertEquals(StrictMath.min(0.0f, -0.0f), -0.0f);
677 Assert.assertEquals(StrictMath.min(-0.0f, -0.0f), -0.0f);
678 Assert.assertEquals(StrictMath.min(0.0f, 0.0f), 0.0f);
679 Assert.assertEquals(StrictMath.min(1.0f, 0.0f), 0.0f);
680 Assert.assertEquals(StrictMath.min(0.0f, 1.0f), 0.0f);
681 Assert.assertEquals(StrictMath.min(0.0f, Float.MAX_VALUE), 0.0f);
682 Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, 0.0f), 0.0f);
683 Assert.assertEquals(StrictMath.min(Float.MIN_VALUE, Float.MAX_VALUE), Float.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100684 }
685
686 public static void test_StrictMath_max_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800687 StrictMath.max(1.0f, Float.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700688 Assert.assertTrue(Float.isNaN(StrictMath.max(1.0f, Float.NaN)));
689 Assert.assertTrue(Float.isNaN(StrictMath.max(Float.NaN, 1.0f)));
690 Assert.assertEquals(StrictMath.max(-0.0f, 0.0f), 0.0f);
691 Assert.assertEquals(StrictMath.max(0.0f, -0.0f), 0.0f);
692 Assert.assertEquals(StrictMath.max(-0.0f, -0.0f), -0.0f);
693 Assert.assertEquals(StrictMath.max(0.0f, 0.0f), 0.0f);
694 Assert.assertEquals(StrictMath.max(1.0f, 0.0f), 1.0f);
695 Assert.assertEquals(StrictMath.max(0.0f, 1.0f), 1.0f);
696 Assert.assertEquals(StrictMath.max(0.0f, Float.MAX_VALUE), Float.MAX_VALUE);
697 Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, 0.0f), Float.MIN_VALUE);
698 Assert.assertEquals(StrictMath.max(Float.MIN_VALUE, Float.MAX_VALUE), Float.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100699 }
700
701 public static void test_StrictMath_min_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800702 StrictMath.min(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700703 Assert.assertTrue(Double.isNaN(StrictMath.min(1.0d, Double.NaN)));
704 Assert.assertTrue(Double.isNaN(StrictMath.min(Double.NaN, 1.0d)));
705 Assert.assertEquals(StrictMath.min(-0.0d, 0.0d), -0.0d);
706 Assert.assertEquals(StrictMath.min(0.0d, -0.0d), -0.0d);
707 Assert.assertEquals(StrictMath.min(-0.0d, -0.0d), -0.0d);
708 Assert.assertEquals(StrictMath.min(0.0d, 0.0d), 0.0d);
709 Assert.assertEquals(StrictMath.min(1.0d, 0.0d), 0.0d);
710 Assert.assertEquals(StrictMath.min(0.0d, 1.0d), 0.0d);
711 Assert.assertEquals(StrictMath.min(0.0d, Double.MAX_VALUE), 0.0d);
712 Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, 0.0d), 0.0d);
713 Assert.assertEquals(StrictMath.min(Double.MIN_VALUE, Double.MAX_VALUE), Double.MIN_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100714 }
715
716 public static void test_StrictMath_max_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800717 StrictMath.max(1.0d, Double.NaN);
Alexei Zavjalov1222c962014-07-16 00:54:13 +0700718 Assert.assertTrue(Double.isNaN(StrictMath.max(1.0d, Double.NaN)));
719 Assert.assertTrue(Double.isNaN(StrictMath.max(Double.NaN, 1.0d)));
720 Assert.assertEquals(StrictMath.max(-0.0d, 0.0d), 0.0d);
721 Assert.assertEquals(StrictMath.max(0.0d, -0.0d), 0.0d);
722 Assert.assertEquals(StrictMath.max(-0.0d, -0.0d), -0.0d);
723 Assert.assertEquals(StrictMath.max(0.0d, 0.0d), 0.0d);
724 Assert.assertEquals(StrictMath.max(1.0d, 0.0d), 1.0d);
725 Assert.assertEquals(StrictMath.max(0.0d, 1.0d), 1.0d);
726 Assert.assertEquals(StrictMath.max(0.0d, Double.MAX_VALUE), Double.MAX_VALUE);
727 Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, 0.0d), Double.MIN_VALUE);
728 Assert.assertEquals(StrictMath.max(Double.MIN_VALUE, Double.MAX_VALUE), Double.MAX_VALUE);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100729 }
730
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800731 public static void test_StrictMath_sqrt() {
732 StrictMath.sqrt(+4.0);
733 Assert.assertEquals(StrictMath.sqrt(+4.0), +2.0d, 0.0);
734 Assert.assertEquals(StrictMath.sqrt(+49.0), +7.0d, 0.0);
735 Assert.assertEquals(StrictMath.sqrt(+1.44), +1.2d, 0.0);
736 }
737
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100738 public static void test_StrictMath_ceil() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800739 StrictMath.ceil(-0.9);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100740 Assert.assertEquals(StrictMath.ceil(+0.0), +0.0d, 0.0);
741 Assert.assertEquals(StrictMath.ceil(-0.0), -0.0d, 0.0);
742 Assert.assertEquals(StrictMath.ceil(-0.9), -0.0d, 0.0);
743 Assert.assertEquals(StrictMath.ceil(-0.5), -0.0d, 0.0);
744 Assert.assertEquals(StrictMath.ceil(0.0), -0.0d, 0.0);
745 Assert.assertEquals(StrictMath.ceil(+2.0), +2.0d, 0.0);
746 Assert.assertEquals(StrictMath.ceil(+2.1), +3.0d, 0.0);
747 Assert.assertEquals(StrictMath.ceil(+2.5), +3.0d, 0.0);
748 Assert.assertEquals(StrictMath.ceil(+2.9), +3.0d, 0.0);
749 Assert.assertEquals(StrictMath.ceil(+3.0), +3.0d, 0.0);
750 Assert.assertEquals(StrictMath.ceil(-2.0), -2.0d, 0.0);
751 Assert.assertEquals(StrictMath.ceil(-2.1), -2.0d, 0.0);
752 Assert.assertEquals(StrictMath.ceil(-2.5), -2.0d, 0.0);
753 Assert.assertEquals(StrictMath.ceil(-2.9), -2.0d, 0.0);
754 Assert.assertEquals(StrictMath.ceil(-3.0), -3.0d, 0.0);
755 Assert.assertEquals(StrictMath.ceil(Double.NaN), Double.NaN, 0.0);
756 Assert.assertEquals(StrictMath.ceil(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
757 Assert.assertEquals(StrictMath.ceil(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
758 }
759
760 public static void test_StrictMath_floor() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800761 StrictMath.floor(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100762 Assert.assertEquals(StrictMath.floor(+0.0), +0.0d, 0.0);
763 Assert.assertEquals(StrictMath.floor(-0.0), -0.0d, 0.0);
764 Assert.assertEquals(StrictMath.floor(+2.0), +2.0d, 0.0);
765 Assert.assertEquals(StrictMath.floor(+2.1), +2.0d, 0.0);
766 Assert.assertEquals(StrictMath.floor(+2.5), +2.0d, 0.0);
767 Assert.assertEquals(StrictMath.floor(+2.9), +2.0d, 0.0);
768 Assert.assertEquals(StrictMath.floor(+3.0), +3.0d, 0.0);
769 Assert.assertEquals(StrictMath.floor(-2.0), -2.0d, 0.0);
770 Assert.assertEquals(StrictMath.floor(-2.1), -3.0d, 0.0);
771 Assert.assertEquals(StrictMath.floor(-2.5), -3.0d, 0.0);
772 Assert.assertEquals(StrictMath.floor(-2.9), -3.0d, 0.0);
773 Assert.assertEquals(StrictMath.floor(-3.0), -3.0d, 0.0);
774 Assert.assertEquals(StrictMath.floor(Double.NaN), Double.NaN, 0.0);
775 Assert.assertEquals(StrictMath.floor(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
776 Assert.assertEquals(StrictMath.floor(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
777 }
778
779 public static void test_StrictMath_rint() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800780 StrictMath.rint(+2.1);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100781 Assert.assertEquals(StrictMath.rint(+0.0), +0.0d, 0.0);
782 Assert.assertEquals(StrictMath.rint(-0.0), -0.0d, 0.0);
783 Assert.assertEquals(StrictMath.rint(+2.0), +2.0d, 0.0);
784 Assert.assertEquals(StrictMath.rint(+2.1), +2.0d, 0.0);
785 Assert.assertEquals(StrictMath.rint(+2.5), +2.0d, 0.0);
786 Assert.assertEquals(StrictMath.rint(+2.9), +3.0d, 0.0);
787 Assert.assertEquals(StrictMath.rint(+3.0), +3.0d, 0.0);
788 Assert.assertEquals(StrictMath.rint(-2.0), -2.0d, 0.0);
789 Assert.assertEquals(StrictMath.rint(-2.1), -2.0d, 0.0);
790 Assert.assertEquals(StrictMath.rint(-2.5), -2.0d, 0.0);
791 Assert.assertEquals(StrictMath.rint(-2.9), -3.0d, 0.0);
792 Assert.assertEquals(StrictMath.rint(-3.0), -3.0d, 0.0);
793 Assert.assertEquals(StrictMath.rint(Double.NaN), Double.NaN, 0.0);
794 Assert.assertEquals(StrictMath.rint(Double.POSITIVE_INFINITY), Double.POSITIVE_INFINITY, 0.0);
795 Assert.assertEquals(StrictMath.rint(Double.NEGATIVE_INFINITY), Double.NEGATIVE_INFINITY, 0.0);
796 }
797
798 public static void test_StrictMath_round_D() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800799 StrictMath.round(2.1d);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100800 Assert.assertEquals(StrictMath.round(+0.0d), (long)+0.0);
801 Assert.assertEquals(StrictMath.round(-0.0d), (long)+0.0);
802 Assert.assertEquals(StrictMath.round(2.0d), 2l);
803 Assert.assertEquals(StrictMath.round(2.1d), 2l);
804 Assert.assertEquals(StrictMath.round(2.5d), 3l);
805 Assert.assertEquals(StrictMath.round(2.9d), 3l);
806 Assert.assertEquals(StrictMath.round(3.0d), 3l);
807 Assert.assertEquals(StrictMath.round(-2.0d), -2l);
808 Assert.assertEquals(StrictMath.round(-2.1d), -2l);
809 Assert.assertEquals(StrictMath.round(-2.5d), -2l);
810 Assert.assertEquals(StrictMath.round(-2.9d), -3l);
811 Assert.assertEquals(StrictMath.round(-3.0d), -3l);
812 Assert.assertEquals(StrictMath.round(0.49999999999999994d), 1l);
813 Assert.assertEquals(StrictMath.round(Double.NaN), (long)+0.0d);
814 Assert.assertEquals(StrictMath.round(Long.MAX_VALUE + 1.0d), Long.MAX_VALUE);
815 Assert.assertEquals(StrictMath.round(Long.MIN_VALUE - 1.0d), Long.MIN_VALUE);
816 Assert.assertEquals(StrictMath.round(Double.POSITIVE_INFINITY), Long.MAX_VALUE);
817 Assert.assertEquals(StrictMath.round(Double.NEGATIVE_INFINITY), Long.MIN_VALUE);
818 }
819
820 public static void test_StrictMath_round_F() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800821 StrictMath.round(2.1f);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +0100822 Assert.assertEquals(StrictMath.round(+0.0f), (int)+0.0);
823 Assert.assertEquals(StrictMath.round(-0.0f), (int)+0.0);
824 Assert.assertEquals(StrictMath.round(2.0f), 2);
825 Assert.assertEquals(StrictMath.round(2.1f), 2);
826 Assert.assertEquals(StrictMath.round(2.5f), 3);
827 Assert.assertEquals(StrictMath.round(2.9f), 3);
828 Assert.assertEquals(StrictMath.round(3.0f), 3);
829 Assert.assertEquals(StrictMath.round(-2.0f), -2);
830 Assert.assertEquals(StrictMath.round(-2.1f), -2);
831 Assert.assertEquals(StrictMath.round(-2.5f), -2);
832 Assert.assertEquals(StrictMath.round(-2.9f), -3);
833 Assert.assertEquals(StrictMath.round(-3.0f), -3);
834 Assert.assertEquals(StrictMath.round(Float.NaN), (int)+0.0f);
835 Assert.assertEquals(StrictMath.round(Integer.MAX_VALUE + 1.0f), Integer.MAX_VALUE);
836 Assert.assertEquals(StrictMath.round(Integer.MIN_VALUE - 1.0f), Integer.MIN_VALUE);
837 Assert.assertEquals(StrictMath.round(Float.POSITIVE_INFINITY), Integer.MAX_VALUE);
838 Assert.assertEquals(StrictMath.round(Float.NEGATIVE_INFINITY), Integer.MIN_VALUE);
839 }
840
Elliott Hughes28c384b2012-06-15 16:46:25 -0700841 public static void test_Float_floatToRawIntBits() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800842 Float.floatToRawIntBits(-1.0f);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700843 Assert.assertEquals(Float.floatToRawIntBits(-1.0f), 0xbf800000);
844 Assert.assertEquals(Float.floatToRawIntBits(0.0f), 0);
845 Assert.assertEquals(Float.floatToRawIntBits(1.0f), 0x3f800000);
846 Assert.assertEquals(Float.floatToRawIntBits(Float.NaN), 0x7fc00000);
847 Assert.assertEquals(Float.floatToRawIntBits(Float.POSITIVE_INFINITY), 0x7f800000);
848 Assert.assertEquals(Float.floatToRawIntBits(Float.NEGATIVE_INFINITY), 0xff800000);
849 }
850
851 public static void test_Float_intBitsToFloat() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800852 Float.intBitsToFloat(0xbf800000);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700853 Assert.assertEquals(Float.intBitsToFloat(0xbf800000), -1.0f);
854 Assert.assertEquals(Float.intBitsToFloat(0x00000000), 0.0f);
855 Assert.assertEquals(Float.intBitsToFloat(0x3f800000), 1.0f);
856 Assert.assertEquals(Float.intBitsToFloat(0x7fc00000), Float.NaN);
857 Assert.assertEquals(Float.intBitsToFloat(0x7f800000), Float.POSITIVE_INFINITY);
858 Assert.assertEquals(Float.intBitsToFloat(0xff800000), Float.NEGATIVE_INFINITY);
859 }
860
861 public static void test_Double_doubleToRawLongBits() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800862 Double.doubleToRawLongBits(-1.0);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700863 Assert.assertEquals(Double.doubleToRawLongBits(-1.0), 0xbff0000000000000L);
864 Assert.assertEquals(Double.doubleToRawLongBits(0.0), 0x0000000000000000L);
865 Assert.assertEquals(Double.doubleToRawLongBits(1.0), 0x3ff0000000000000L);
866 Assert.assertEquals(Double.doubleToRawLongBits(Double.NaN), 0x7ff8000000000000L);
867 Assert.assertEquals(Double.doubleToRawLongBits(Double.POSITIVE_INFINITY), 0x7ff0000000000000L);
868 Assert.assertEquals(Double.doubleToRawLongBits(Double.NEGATIVE_INFINITY), 0xfff0000000000000L);
869 }
870
871 public static void test_Double_longBitsToDouble() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800872 Double.longBitsToDouble(0xbff0000000000000L);
Elliott Hughes28c384b2012-06-15 16:46:25 -0700873 Assert.assertEquals(Double.longBitsToDouble(0xbff0000000000000L), -1.0);
874 Assert.assertEquals(Double.longBitsToDouble(0x0000000000000000L), 0.0);
875 Assert.assertEquals(Double.longBitsToDouble(0x3ff0000000000000L), 1.0);
876 Assert.assertEquals(Double.longBitsToDouble(0x7ff8000000000000L), Double.NaN);
877 Assert.assertEquals(Double.longBitsToDouble(0x7ff0000000000000L), Double.POSITIVE_INFINITY);
878 Assert.assertEquals(Double.longBitsToDouble(0xfff0000000000000L), Double.NEGATIVE_INFINITY);
879 }
Serban Constantinescu23abec92014-07-02 16:13:38 +0100880
Zheng Xua3fe7422014-07-09 14:03:15 +0800881 public static void test_Short_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800882 Short.reverseBytes((short)0x1357);
Zheng Xua3fe7422014-07-09 14:03:15 +0800883 Assert.assertEquals(Short.reverseBytes((short)0x0000), (short)0x0000);
884 Assert.assertEquals(Short.reverseBytes((short)0xffff), (short)0xffff);
885 Assert.assertEquals(Short.reverseBytes((short)0x8000), (short)0x0080);
886 Assert.assertEquals(Short.reverseBytes((short)0x0080), (short)0x8000);
887 Assert.assertEquals(Short.reverseBytes((short)0x0123), (short)0x2301);
888 Assert.assertEquals(Short.reverseBytes((short)0x4567), (short)0x6745);
889 Assert.assertEquals(Short.reverseBytes((short)0x89ab), (short)0xab89);
890 Assert.assertEquals(Short.reverseBytes((short)0xcdef), (short)0xefcd);
891 }
892
893 public static void test_Integer_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800894 Integer.reverseBytes(0x13579bdf);
Zheng Xua3fe7422014-07-09 14:03:15 +0800895 Assert.assertEquals(Integer.reverseBytes(0x00000000), 0x00000000);
896 Assert.assertEquals(Integer.reverseBytes(0xffffffff), 0xffffffff);
897 Assert.assertEquals(Integer.reverseBytes(0x80000000), 0x00000080);
898 Assert.assertEquals(Integer.reverseBytes(0x00000080), 0x80000000);
899 Assert.assertEquals(Integer.reverseBytes(0x01234567), 0x67452301);
900 Assert.assertEquals(Integer.reverseBytes(0x89abcdef), 0xefcdab89);
901 }
902
903 public static void test_Long_reverseBytes() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800904 Long.reverseBytes(0x13579bdf2468ace0L);
Zheng Xua3fe7422014-07-09 14:03:15 +0800905 Assert.assertEquals(Long.reverseBytes(0x0000000000000000L), 0x0000000000000000L);
906 Assert.assertEquals(Long.reverseBytes(0xffffffffffffffffL), 0xffffffffffffffffL);
907 Assert.assertEquals(Long.reverseBytes(0x8000000000000000L), 0x0000000000000080L);
908 Assert.assertEquals(Long.reverseBytes(0x0000000000000080L), 0x8000000000000000L);
909 Assert.assertEquals(Long.reverseBytes(0x0123456789abcdefL), 0xefcdab8967452301L);
910 }
911
Serban Constantinescu23abec92014-07-02 16:13:38 +0100912 public static void test_Integer_reverse() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800913 Integer.reverse(0x12345678);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100914 Assert.assertEquals(Integer.reverse(1), 0x80000000);
915 Assert.assertEquals(Integer.reverse(-1), 0xffffffff);
916 Assert.assertEquals(Integer.reverse(0), 0);
917 Assert.assertEquals(Integer.reverse(0x12345678), 0x1e6a2c48);
918 Assert.assertEquals(Integer.reverse(0x87654321), 0x84c2a6e1);
919 Assert.assertEquals(Integer.reverse(Integer.MAX_VALUE), 0xfffffffe);
920 Assert.assertEquals(Integer.reverse(Integer.MIN_VALUE), 1);
921 }
922
923 public static void test_Long_reverse() {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800924 Long.reverse(0x1234567812345678L);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100925 Assert.assertEquals(Long.reverse(1L), 0x8000000000000000L);
926 Assert.assertEquals(Long.reverse(-1L), 0xffffffffffffffffL);
927 Assert.assertEquals(Long.reverse(0L), 0L);
Zheng Xua3fe7422014-07-09 14:03:15 +0800928 Assert.assertEquals(Long.reverse(0x1234567812345678L), 0x1e6a2c481e6a2c48L);
929 Assert.assertEquals(Long.reverse(0x8765432187654321L), 0x84c2a6e184c2a6e1L);
930 Assert.assertEquals(Long.reverse(Long.MAX_VALUE), 0xfffffffffffffffeL);
Serban Constantinescu23abec92014-07-02 16:13:38 +0100931 Assert.assertEquals(Long.reverse(Long.MIN_VALUE), 1L);
932 }
933
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700934 static Object runtime;
935 static Method address_of;
Zuo Wangf37a88b2014-07-10 04:26:41 -0700936 static Method new_non_movable_array;
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700937 static Method peek_byte;
938 static Method peek_short;
939 static Method peek_int;
940 static Method peek_long;
941 static Method poke_byte;
942 static Method poke_short;
943 static Method poke_int;
944 static Method poke_long;
945
946 public static void initSupportMethodsForPeekPoke() throws Exception {
947 Class<?> vm_runtime = Class.forName("dalvik.system.VMRuntime");
948 Method get_runtime = vm_runtime.getDeclaredMethod("getRuntime");
949 runtime = get_runtime.invoke(null);
950 address_of = vm_runtime.getDeclaredMethod("addressOf", Object.class);
Zuo Wangf37a88b2014-07-10 04:26:41 -0700951 new_non_movable_array = vm_runtime.getDeclaredMethod("newNonMovableArray", Class.class, Integer.TYPE);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700952
953 Class<?> io_memory = Class.forName("libcore.io.Memory");
954 peek_byte = io_memory.getDeclaredMethod("peekByte", Long.TYPE);
955 peek_int = io_memory.getDeclaredMethod("peekInt", Long.TYPE, Boolean.TYPE);
956 peek_short = io_memory.getDeclaredMethod("peekShort", Long.TYPE, Boolean.TYPE);
957 peek_long = io_memory.getDeclaredMethod("peekLong", Long.TYPE, Boolean.TYPE);
958 poke_byte = io_memory.getDeclaredMethod("pokeByte", Long.TYPE, Byte.TYPE);
959 poke_short = io_memory.getDeclaredMethod("pokeShort", Long.TYPE, Short.TYPE, Boolean.TYPE);
960 poke_int = io_memory.getDeclaredMethod("pokeInt", Long.TYPE, Integer.TYPE, Boolean.TYPE);
961 poke_long = io_memory.getDeclaredMethod("pokeLong", Long.TYPE, Long.TYPE, Boolean.TYPE);
962 }
963
964 public static void test_Memory_peekByte() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700965 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700966 b[0] = 0x12;
967 b[1] = 0x11;
968 long address = (long)address_of.invoke(runtime, b);
969 Assert.assertEquals((byte)peek_byte.invoke(null, address), 0x12);
970 Assert.assertEquals((byte)peek_byte.invoke(null, address + 1), 0x11);
971 }
972
973 public static void test_Memory_peekShort() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700974 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700975 b[0] = 0x13;
976 b[1] = 0x12;
977 b[2] = 0x11;
978 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800979 peek_short.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700980 Assert.assertEquals((short)peek_short.invoke(null, address, false), 0x1213); // Aligned read
981 Assert.assertEquals((short)peek_short.invoke(null, address + 1, false), 0x1112); // Unaligned read
982 }
983
984 public static void test_Memory_peekInt() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700985 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700986 b[0] = 0x15;
987 b[1] = 0x14;
988 b[2] = 0x13;
989 b[3] = 0x12;
990 b[4] = 0x11;
991 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -0800992 peek_int.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700993 Assert.assertEquals((int)peek_int.invoke(null, address, false), 0x12131415);
994 Assert.assertEquals((int)peek_int.invoke(null, address + 1, false), 0x11121314);
995 }
996
997 public static void test_Memory_peekLong() throws Exception {
Zuo Wangf37a88b2014-07-10 04:26:41 -0700998 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +0700999 b[0] = 0x19;
1000 b[1] = 0x18;
1001 b[2] = 0x17;
1002 b[3] = 0x16;
1003 b[4] = 0x15;
1004 b[5] = 0x14;
1005 b[6] = 0x13;
1006 b[7] = 0x12;
1007 b[8] = 0x11;
1008 long address = (long)address_of.invoke(runtime, b);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001009 peek_long.invoke(null, address, false);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001010 Assert.assertEquals((long)peek_long.invoke(null, address, false), 0x1213141516171819L);
1011 Assert.assertEquals((long)peek_long.invoke(null, address + 1, false), 0x1112131415161718L);
1012 }
1013
1014 public static void test_Memory_pokeByte() throws Exception {
1015 byte[] r = {0x11, 0x12};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001016 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 2);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001017 long address = (long)address_of.invoke(runtime, b);
1018 poke_byte.invoke(null, address, (byte)0x11);
1019 poke_byte.invoke(null, address + 1, (byte)0x12);
1020 Assert.assertTrue(Arrays.equals(r, b));
1021 }
1022
1023 public static void test_Memory_pokeShort() throws Exception {
1024 byte[] ra = {0x12, 0x11, 0x13};
1025 byte[] ru = {0x12, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001026 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 3);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001027 long address = (long)address_of.invoke(runtime, b);
1028
1029 // Aligned write
1030 b[2] = 0x13;
1031 poke_short.invoke(null, address, (short)0x1112, false);
1032 Assert.assertTrue(Arrays.equals(ra, b));
1033
1034 // Unaligned write
1035 poke_short.invoke(null, address + 1, (short)0x2122, false);
1036 Assert.assertTrue(Arrays.equals(ru, b));
1037 }
1038
1039 public static void test_Memory_pokeInt() throws Exception {
1040 byte[] ra = {0x14, 0x13, 0x12, 0x11, 0x15};
1041 byte[] ru = {0x14, 0x24, 0x23, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001042 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 5);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001043 long address = (long)address_of.invoke(runtime, b);
1044
1045 b[4] = 0x15;
1046 poke_int.invoke(null, address, (int)0x11121314, false);
1047 Assert.assertTrue(Arrays.equals(ra, b));
1048
1049 poke_int.invoke(null, address + 1, (int)0x21222324, false);
1050 Assert.assertTrue(Arrays.equals(ru, b));
1051 }
1052
1053 public static void test_Memory_pokeLong() throws Exception {
1054 byte[] ra = {0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x19};
1055 byte[] ru = {0x18, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21};
Zuo Wangf37a88b2014-07-10 04:26:41 -07001056 byte[] b = (byte[])new_non_movable_array.invoke(runtime, Byte.TYPE, 9);
Alexei Zavjaloveb24bae2014-07-08 16:27:17 +07001057 long address = (long)address_of.invoke(runtime, b);
1058
1059 b[8] = 0x19;
1060 poke_long.invoke(null, address, (long)0x1112131415161718L, false);
1061 Assert.assertTrue(Arrays.equals(ra, b));
1062
1063 poke_long.invoke(null, address + 1, (long)0x2122232425262728L, false);
1064 Assert.assertTrue(Arrays.equals(ru, b));
1065 }
jeffhao5d1ac922011-09-29 17:41:15 -07001066}