| 1 |
/* |
| 2 |
* Copyright (C) 2017 The Android Open Source Project |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
import java.lang.reflect.Method; |
| 18 |
import java.lang.reflect.Field; |
| 19 |
|
| 20 |
public class Main { |
| 21 |
public static void main(String[] args) throws Exception { |
| 22 |
Class<?> c = Class.forName("StoreLoad"); |
| 23 |
Method m = c.getMethod("test", int.class); |
| 24 |
int result = (Integer)m.invoke(null, 0x12345678); |
| 25 |
if (result != (0x78 + 0x78)) { |
| 26 |
throw new Error("Expected 240, got " + result); |
| 27 |
} |
| 28 |
m = c.getMethod("test2", int.class); |
| 29 |
result = (Integer)m.invoke(null, 0xdeadbeef); |
| 30 |
if (result != 0xdeadbeef) { |
| 31 |
throw new Error("Expected 0xdeadbeef, got " + result); |
| 32 |
} |
| 33 |
Field f = c.getDeclaredField("byteField"); |
| 34 |
byte b = f.getByte(null); |
| 35 |
if (b != (byte)0xef) { |
| 36 |
throw new Error("Expected 0xef, got " + b); |
| 37 |
} |
| 38 |
f = c.getDeclaredField("byteField2"); |
| 39 |
b = f.getByte(null); |
| 40 |
if (b != (byte)0x78) { |
| 41 |
throw new Error("Expected 0xef, got " + b); |
| 42 |
} |
| 43 |
|
| 44 |
m = c.getMethod("test3", int.class); |
| 45 |
result = (Integer)m.invoke(null, 300); |
| 46 |
assertIntEquals(result, 300); |
| 47 |
result = (Integer)m.invoke(null, 301); |
| 48 |
assertIntEquals(result, 90); |
| 49 |
|
| 50 |
m = c.getMethod("test4", int.class); |
| 51 |
result = (Integer)m.invoke(null, 5); |
| 52 |
assertIntEquals(result, 5); |
| 53 |
result = (Integer)m.invoke(null, 10); |
| 54 |
assertIntEquals(result, 10); |
| 55 |
} |
| 56 |
|
| 57 |
private static void assertIntEquals(int result, int expected) { |
| 58 |
if (result != expected) { |
| 59 |
throw new Error("Expected " + expected + ", got " + result); |
| 60 |
} |
| 61 |
} |
| 62 |
} |