1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package libcore.java.lang; 18 19 import junit.framework.TestCase; 20 21 /** 22 * Tests that all intrinsic methods are still invokable via reflection. 23 */ 24 public final class IntrinsicTest extends TestCase { 25 public void testString_charAt() throws Exception { 26 "hello".charAt(0); 27 String.class.getMethod("charAt", int.class).invoke("hello", 0); 28 } 29 30 public void testString_compareTo() throws Exception { 31 "hello".compareTo("world"); 32 String.class.getMethod("compareTo", String.class).invoke("hello", "world"); 33 } 34 35 public void testString_equals() throws Exception { 36 "hello".equals("world"); 37 String.class.getMethod("equals", Object.class).invoke("hello", "world"); 38 } 39 40 public void testString_fastIndexOf_II() throws Exception { 41 "hello".indexOf('l'); 42 String.class.getMethod("indexOf", int.class).invoke("hello", 'l'); 43 } 44 45 public void testString_isEmpty() throws Exception { 46 "hello".isEmpty(); 47 String.class.getMethod("isEmpty").invoke("hello"); 48 } 49 50 public void testString_length() throws Exception { 51 "hello".length(); 52 String.class.getMethod("length").invoke("hello"); 53 } 54 55 public void testMath_abs() throws Exception { 56 Math.abs(1); 57 Math.class.getMethod("abs", int.class).invoke(null, 1); 58 Math.abs(1L); 59 Math.class.getMethod("abs", long.class).invoke(null, 1L); 60 Math.abs(1.0f); 61 Math.class.getMethod("abs", float.class).invoke(null, 1.0f); 62 Math.abs(1.0); 63 Math.class.getMethod("abs", double.class).invoke(null, 1.0); 64 } 65 66 public void testStrictMath_abs() throws Exception { 67 StrictMath.abs(1); 68 StrictMath.class.getMethod("abs", int.class).invoke(null, 1); 69 StrictMath.abs(1L); 70 StrictMath.class.getMethod("abs", long.class).invoke(null, 1L); 71 StrictMath.abs(1.0f); 72 StrictMath.class.getMethod("abs", float.class).invoke(null, 1.0f); 73 StrictMath.abs(1.0); 74 StrictMath.class.getMethod("abs", double.class).invoke(null, 1.0); 75 } 76 77 public void testStrictMath_min() throws Exception { 78 StrictMath.min(1, 2); 79 StrictMath.class.getMethod("min", int.class, int.class).invoke(null, 1, 2); 80 } 81 82 public void testStrictMath_max() throws Exception { 83 StrictMath.max(1, 2); 84 StrictMath.class.getMethod("max", int.class, int.class).invoke(null, 1, 2); 85 } 86 87 public void testStrictMath_sqrt() throws Exception { 88 StrictMath.sqrt(2.0); 89 StrictMath.class.getMethod("sqrt", double.class).invoke(null, 2.0); 90 } 91 92 public void testMath_min() throws Exception { 93 Math.min(1, 2); 94 Math.class.getMethod("min", int.class, int.class).invoke(null, 1, 2); 95 } 96 97 public void testMath_max() throws Exception { 98 Math.max(1, 2); 99 Math.class.getMethod("max", int.class, int.class).invoke(null, 1, 2); 100 } 101 102 public void testMath_sqrt() throws Exception { 103 Math.sqrt(2.0); 104 Math.class.getMethod("sqrt", double.class).invoke(null, 2.0); 105 } 106 107 public void testMath_cos() throws Exception { 108 Math.cos(Math.PI); 109 Math.class.getMethod("cos", double.class).invoke(null, Math.PI); 110 } 111 112 public void testMath_sin() throws Exception { 113 Math.sin(Math.PI); 114 Math.class.getMethod("sin", double.class).invoke(null, Math.PI); 115 } 116 117 public void testFloat_floatToIntBits() throws Exception { 118 Float.floatToIntBits(0.0f); 119 Float.class.getMethod("floatToIntBits", float.class).invoke(null, 0.0f); 120 } 121 122 public void testFloat_floatToRawIntBits() throws Exception { 123 Float.floatToRawIntBits(0.0f); 124 Float.class.getMethod("floatToRawIntBits", float.class).invoke(null, 0.0f); 125 } 126 127 public void testFloat_intBitsToFloat() throws Exception { 128 Float.intBitsToFloat(0); 129 Float.class.getMethod("intBitsToFloat", int.class).invoke(null, 0); 130 } 131 132 public void testDouble_doubleToLongBits() throws Exception { 133 Double.doubleToLongBits(0.0); 134 Double.class.getMethod("doubleToLongBits", double.class).invoke(null, 0.0); 135 } 136 137 public void testDouble_doubleToRawLongBits() throws Exception { 138 Double.doubleToRawLongBits(0.0); 139 Double.class.getMethod("doubleToRawLongBits", double.class).invoke(null, 0.0); 140 } 141 142 public void testDouble_longBitsToDouble() throws Exception { 143 Double.longBitsToDouble(0L); 144 Double.class.getMethod("longBitsToDouble", long.class).invoke(null, 0L); 145 } 146 } 147