⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.java

📁 This is a resource based on j2me embedded,if you dont understand,you can connection with me .
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	}    }    static int testStaticInitalizers() {	//return StaticB.foo2;	try {	    return StaticD.foo1 + StaticE.x;	} catch (Throwable t) {	    System.out.println("*<clinit> threw " + t);	}	try {	    return StaticE.x;	} catch (Throwable t) {	    System.out.println("*<clinit> threw " + t);	    return 0;	}    }        static int arrayGetLengthCatchException(Object[] arr) {	try {	    return arr.length;	} catch (NullPointerException e) {	    System.out.println("test6: Caught inner "+e);	    return -1;	}    }    static int arrayGetLengthDontCatchException(Object[] arr) {	return arr.length;    }    //    // Testing stackmaps while throwing exception    //    static void test6() {	boolean didCatchOuter = false;	assert0( arrayGetLengthCatchException(null) == -1,	    "test 6: arrayGetLengthCatchException(null)" );	try {	    arrayGetLengthDontCatchException(null);	} catch (NullPointerException e) {	    System.out.println("test6: Caught outer "+e);	    didCatchOuter = true;	}	assert0( didCatchOuter, "test6: outer catch");    }    static void testArrayCopy() {	char[]    carr1 = new char[3], carr2 = new char[4];	float[]   farr1 = new float[3], farr2 = new float[4];	double[]  darr1 = new double[3], darr2 = new double[4];	int[]     iarr1 = new int[3], iarr2 = new int[4];	long[]    larr1 = new long[3], larr2 = new long[4];	Object[]  oarr1 = new Object[3], oarr2 = new Object[4];	System.out.println("Testing Array Copy");	/*	 * A copy of a 16-bit size. Char in this case	 */	carr1[0] = 'a'; carr1[1] = 'b'; carr1[2] = 'c';	System.arraycopy(carr1, 0, carr2, 1, carr1.length);	assert0 ((carr2[0] == '\0') && (carr2[1] == 'a') &&	    (carr2[2] == 'b') && (carr2[3] == 'c'), "testArrayCopy: Char copy");	/*	 * A copy of a 32-bit floating point	 */	farr1[0] = (float)1.0; farr1[1] = (float)2.0; farr1[2] = (float)3.0;	System.arraycopy(farr1, 0, farr2, 1, farr1.length);	assert0((farr2[0] == 0) && (farr2[1] == 1.0) &&	    (farr2[2] == 2.0) && (farr2[3] == 3.0), "testArrayCopy: Float copy");	/*	 * A copy of a 32-bit integer	 */	iarr1[0] = 1; iarr1[1] = 2; iarr1[2] = 3;	System.arraycopy(iarr1, 0, iarr2, 1, iarr1.length);	assert0( (iarr2[0] == 0) && (iarr2[1] == 1) &&	    (iarr2[2] == 2) && (iarr2[3] == 3), "testArrayCopy: Int copy");	/*	 * A copy of a double precision floating point	 */	darr1[0] = 1.0; darr1[1] = 2.0; darr1[2] = 3.0;	System.arraycopy(darr1, 0, darr2, 1, darr1.length);	assert0( (darr2[0] == 0.0) && (darr2[1] == 1.0) &&	    (darr2[2] == 2.0) && (darr2[3] == 3.0), "testArrayCopy: Double copy");	/*	 * A copy of a long	 */	larr1[0] = 1L; larr1[1] = 2L; larr1[2] = 3L;	System.arraycopy(larr1, 0, larr2, 1, larr1.length);	assert0( (larr2[0] == 0L) && (larr2[1] == 1L) &&	    (larr2[2] == 2L) && (larr2[3] == 3L), "testArrayCopy: Long copy");	/* 	 * Reference copy	 */	oarr1[0] = new Integer(1); oarr1[1] = new Integer(2); 	oarr1[2] = new Integer(3);	System.arraycopy(oarr1, 0, oarr2, 1, oarr1.length);	assert0( (oarr2[0] == null) && (oarr2[1] == oarr1[0]) &&	    (oarr2[2] == oarr1[1]) && (oarr2[3] == oarr1[2]), "testArrayCopy: Object copy");    }        static void testArrayClassAccess() {	Test[] tt1 = new Test[4];	Test[][] tt2 = new Test[1][2];	C[] cc1 = new C[4];	C[][] cc2 = new C[1][2];	cc1[1] = null;	tt2[0][0] = null;	Class c1 = tt1.getClass();	Class c2 =  tt2.getClass();		Class c3 = cc1.getClass();	Class c4 =  cc2.getClass();	System.out.println("c1 = "+c1);	System.out.println("c2 = "+c2);	System.out.println("c3 = "+c3);	System.out.println("c4 = "+c4);	System.out.println("c1.modifiers = "+c1.getModifiers());	System.out.println("c2.modifiers = "+c2.getModifiers());	System.out.println("c3.modifiers = "+c3.getModifiers());	System.out.println("c4.modifiers = "+c4.getModifiers());	assert0( (c1.getModifiers() & java.lang.reflect.Modifier.PUBLIC) ==	    (Test.class.getModifiers() & java.lang.reflect.Modifier.PUBLIC),	    "testArrayClassAccess: c1 is NOT as public as Test!");	assert0( (c2.getModifiers() & java.lang.reflect.Modifier.PUBLIC) ==	    (Test.class.getModifiers() & java.lang.reflect.Modifier.PUBLIC),	    "testArrayClassAccess: c2 is NOT as public as Test!");	assert0( (c3.getModifiers() & java.lang.reflect.Modifier.PUBLIC) ==	    (C.class.getModifiers() & java.lang.reflect.Modifier.PUBLIC),	    "testArrayClassAccess: c3 is NOT as public as class C!");	assert0( (c4.getModifiers() & java.lang.reflect.Modifier.PUBLIC) ==	    (C.class.getModifiers() & java.lang.reflect.Modifier.PUBLIC),	    "testArrayClassAccess: c4 is NOT as public as class C!");    }    static void testCloning() {	try {	    /* should succeed on cloneable objects */	    CloneableObject co = new CloneableObject();	    Object o = co.clone();	    assert0( co.equals(o),		"testCloning: Cloned object not the same as original");	} catch (Throwable e) {	    System.out.println("Failed clone test: Cloneable cloning failed!");	    nFailure += 1;	}	Object y = null;	Object[] x = new Object[3];	try {	    y = x.clone(); /* should succeed on arrays */	} catch (Throwable e) {	    System.out.println("Failed clone test: array cloning failed!");	    nFailure += 1;	}	boolean cloneExceptionThrown = false;	try {	    /* should fail on non-cloneable objects */	    NonCloneableObject nco = new NonCloneableObject();	    Object o = nco.clone();	} catch (CloneNotSupportedException e) {	    cloneExceptionThrown = true;	} catch (Throwable e) {	    cloneExceptionThrown = false;	} finally {	    assert0( cloneExceptionThrown,		"testCloning: CloneNotSupportedException not thrown" );	}    }    final static int expectedFloatMinIntBits = 1;    final static int expectedFloatMaxIntBits = 0x7f7fffff;    static void testFloatBits() {	System.out.println("*FloatMIN ="+Float.MIN_VALUE);		System.out.println("*FloatMAX ="+Float.MAX_VALUE);	System.out.println("FloatMIN (the int bits) ="+			   Float.floatToIntBits(Float.MIN_VALUE));	System.out.println("FloatMAX (the int bits) ="+			   Float.floatToIntBits(Float.MAX_VALUE));	assert0( Float.floatToIntBits(Float.MIN_VALUE) == expectedFloatMinIntBits,	    "testFloatBits: Float.MIN_VALUE as int bits");	assert0( Float.floatToIntBits(Float.MAX_VALUE) == expectedFloatMaxIntBits,	    "testFloatBits: Float.MAX_VALUE as int bits");	assert0( Float.intBitsToFloat(Float.floatToIntBits(Float.MIN_VALUE))		== Float.MIN_VALUE, "FloatMIN (the two-way transformation)" );	assert0( Float.intBitsToFloat(Float.floatToIntBits(Float.MAX_VALUE))		== Float.MAX_VALUE, "FloatMAX (the two-way transformation)" );    }    static final int expectedNDimensions = 255;    static void testDeepArrayConstruction(){	Object res = null;	int nDimensions = 0;	try {	    int [] dim = {1};	    int depth = 287;	    Class basetype = (new Test()).getClass();	    for ( int i = 0 ; i < depth; i ++ ){		res = java.lang.reflect.Array.newInstance( basetype, dim );		basetype = res.getClass();		nDimensions += 1;	    }	} catch ( Exception e ){	    e.printStackTrace();	}	if ( res != null ){	    System.out.print("Constructed an object of type ");	    System.out.println( res.getClass().getName());	}	assert0( nDimensions == expectedNDimensions, "testDeepArrayConstruction: constructed array depth of "+nDimensions );	/*	 * As an ancillary test, instantiate an array of a basetype class,	 * which is in a package, and that package is not preloaded.	 * Later on (when this whole program is done) that array type will be	 * unloaded, and packagename typeid refcounting will get exercised.	 * See bugid 4333203	 */	Object bug_o = new cvmtest.TypeidRefcountHelper[1][][][][][][][][];    }    static void testManyFieldsAndMethods() {	ManyFieldsAndMethods many = new ManyFieldsAndMethods();	Class c = many.getClass();	int i;	try {	    for (i = 0; i < 4*256; i++) {		if (i % 25 == 0) {		    System.out.print(".");		}		if (i == 100) i+= 100;		if (i == 300) i+= 200;		if (i == 600) i+= 400;		java.lang.reflect.Method m = c.getMethod("method" + i, null);		Integer result = (Integer)m.invoke(many, null);		if ( !assert0( result.intValue() == i,		    "testManyFieldsAndMethods: method"+i ) ){		    return;		}	    }	} catch (Throwable e) {	    System.out.println("\ntestManyFieldsAndMethods() failed: ");	    e.printStackTrace();	    nFailure += 1;	}	many.field678 = -1;	assert0( many.method499() + many.method678() == 498,	    "testManyFieldsAndMethods: many.method499() + many.method678() == 498");    }}class CloneableObject implements Cloneable {    int a;    float b;    Object o;    double d;    boolean z;    long l;    short s;    CloneableObject() {	a = 5;	b = (float)6.0;	o = new Object();	d = 7.0;	z = true;	l = 8L;	s = 9;    }    protected Object clone() {	try {	    return super.clone();	} catch (CloneNotSupportedException e) {	    return null;	}    }    public boolean equals(Object o) {	try {	    CloneableObject co = (CloneableObject)o;	    return ((co.a == this.a) &&		    (co.b == this.b) &&		    (co.o.equals(this.o)) &&		    (co.d == this.d) &&		    (co.z == this.z) &&		    (co.l == this.l) &&		    (co.s == this.s));	} catch (Throwable e) {	    System.out.println("Casting to CloneableObject failed: "+o);	    return false;	}    }    public String toString() {	return 	    "a = "+a+", "+	    "b = "+b+", "+	    "o = "+o+", "+	    "d = "+d+", "+	    "z = "+z+", "+	    "l = "+l+", "+	    "s = "+s;    }}class NonCloneableObject {    int justData;    protected Object clone() throws CloneNotSupportedException {	return super.clone();    }}interface simpleA {    public int aMethod();}interface simpleB {    public int bMethod();}class C implements simpleA, simpleB {    final static int Avalue = 1;    final static int Bvalue = 2;    final static int Cvalue = 3;    public int aMethod(){	return Avalue;    }    public int bMethod(){	return Bvalue;    }    // public abstract int cMethod();}class subC extends C {    final static int subCvalue = 3;    public int cMethod(){ 	return subCvalue;    }}class StaticA {    static {	Test.clinitIndicator <<= Test.clinitShift;	Test.clinitIndicator |= Test.clinitA;    }    static int foo1 = 3;    static int foo2 = StaticB.foo1 + StaticB.foo2;  /* 4 + 3 */}/* * <clinit> tests. */class StaticB extends StaticA {    static {	Test.clinitIndicator <<= Test.clinitShift;	Test.clinitIndicator |= Test.clinitB;    }    static int foo1 = 4;    static int foo2 = StaticA.foo1;   /* 3 */    static int foo3 = StaticA.foo2;   /* 0 */}interface StaticI1 {    static int foo1 = 88;}interface StaticI2 {    static int foo1 = StaticC.init();}class TestE extends Throwable {    TestE(String msg) {	super(msg);    }};class StaticC {    static {	Test.clinitIndicator <<= Test.clinitShift;	Test.clinitIndicator |= Test.clinitC;	StaticD.foo1 = 2;	try {	    StaticD.foo2 = StaticD.init2(6);	} catch (TestE e) {	    System.out.print("*TestE exception thrown because \"" +			 e.getMessage() + "\"\n");	    StaticD.foo2 = 5;	}    }    static int init() {return StaticD.foo1;}}class StaticD implements StaticI1, StaticI2 {    static {	Test.clinitIndicator <<= Test.clinitShift;	Test.clinitIndicator |= Test.clinitD;    }    static int foo1 = StaticI1.foo1 + StaticC.init();   /* 7 + 2 */    static int foo2;    static int init2(int val) throws TestE {	if (val == 6)	    throw new TestE("I'm feeling Testy");	return 5;    }}class StaticE {    static {	Test.clinitIndicator <<= Test.clinitShift;	Test.clinitIndicator |= Test.clinitE;    }    static int x;    static {	x = StaticF.x;    }}class StaticF {    static {	Test.clinitIndicator <<= Test.clinitShift;	Test.clinitIndicator |= Test.clinitF;    }    static int x;    static {	x = StaticG.x;    }}class StaticG {    static {	Test.clinitIndicator <<= Test.clinitShift;	Test.clinitIndicator |= Test.clinitG;    }    static int x;    static {	x = 1;	if (x > 0) {	    throw new RuntimeException("StaticG Error");	}    }}class InternStringHelper1 {    static String getUniqueString() {	return "UniqueStringXYZ";    }}class InternStringHelper2 {    static String getUniqueString() {	return "UniqueStringXYZ";    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -