corda/test/Misc.java

111 lines
2.4 KiB
Java
Raw Normal View History

2007-10-24 21:06:02 +00:00
public class Misc {
private static int alpha;
private static int beta;
2007-12-16 00:24:15 +00:00
private int gamma;
private String foo(String s) {
return s;
}
public String bar(String s) {
return s;
}
private static String baz(String s) {
return s;
}
2007-12-16 00:24:15 +00:00
private static void expect(boolean v) {
if (! v) throw new RuntimeException();
}
private synchronized byte sync() {
byte[] array = new byte[123];
return array[42];
}
private static synchronized byte syncStatic(boolean throw_) {
byte[] array = new byte[123];
if (throw_) {
throw new RuntimeException();
} else {
return array[42];
}
}
2008-01-10 20:47:55 +00:00
public static void putInt(int val, byte[] dst, int offset) {
System.out.println("put " + val);
dst[offset] = (byte)((val >> 24) & 0xff);
dst[offset+1] = (byte)((val >> 16) & 0xff);
dst[offset+2] = (byte)((val >> 8) & 0xff);
dst[offset+3] = (byte)((val ) & 0xff);
}
public static void putLong(long val, byte[] dst, int offset) {
putInt((int)(val >> 32), dst, offset);
putInt((int)val, dst, offset + 4);
}
2007-11-05 14:28:46 +00:00
public static void main(String[] args) {
2008-01-10 22:47:54 +00:00
expect(Long.valueOf(231L) == 231L);
2008-01-10 20:47:55 +00:00
long x = 231;
expect((x >> 32) == 0);
expect((x >>> 32) == 0);
expect((x << 32) == 992137445376L);
long y = -231;
expect((y >> 32) == 0xffffffffffffffffL);
expect((y >>> 32) == 0xffffffffL);
byte[] array = new byte[8];
putLong(231, array, 0);
expect((array[0] & 0xff) == 0);
expect((array[1] & 0xff) == 0);
expect((array[2] & 0xff) == 0);
expect((array[3] & 0xff) == 0);
expect((array[4] & 0xff) == 0);
expect((array[5] & 0xff) == 0);
expect((array[6] & 0xff) == 0);
expect((array[7] & 0xff) == 231);
java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocate(8);
buffer.putLong(231);
buffer.flip();
expect(buffer.getLong() == 231);
boolean v = Boolean.valueOf("true");
2007-12-16 00:24:15 +00:00
ClassLoader.getSystemClassLoader().toString();
int a = 2;
int b = 2;
int c = a + b;
2007-12-11 23:52:28 +00:00
Misc m = new Misc();
String s = "hello";
m.foo(s);
m.bar(s);
baz(s);
2007-12-11 21:26:59 +00:00
m.sync();
syncStatic(false);
try {
syncStatic(true);
} catch (RuntimeException e) {
e.printStackTrace();
}
2007-12-16 00:24:15 +00:00
int d = alpha;
beta = 42;
alpha = 43;
int e = beta;
int f = alpha;
m.gamma = 44;
expect(beta == 42);
expect(alpha == 43);
expect(m.gamma == 44);
}
}