Nice/testsuite/compiler/overloading dynamic.nice,NONE,1.1

Artem Gr Kozarezov <[email protected]> Mon, 29 Aug 2005 14:29:08 +0000
Newsgroups gmane.comp.lang.nice.cvs
Message-ID <[email protected]>
Update of /cvsroot/nice/Nice/testsuite/compiler/overloading
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12450/testsuite/compiler/overloading

Added Files:
	dynamic.nice 
Log Message:
Demonstrate dynamic loading problems.

--- NEW FILE: dynamic.nice ---
/// COMMENT Dynamic dispatch and handling of a wrong classloading order.

import testsuite;

void invokeMain( String packageName, java.net.URL[] jars ){
  let cl = new java.net.URLClassLoader( jars, fun.class.getClassLoader() );
  let clazz = cl.loadClass( packageName + ".fun" );
  let main = clazz.getMethod( "main", [ String[].class ] );
  try{
    main.invoke( null, [ [""] ] );
  }catch( java.lang.reflect.InvocationTargetException error ){
    let source = TMP.getPath() + '/' + packageName.replace( '.', "/" ) + "/main.nice";
    printSourceWithLNums( new java.io.File( source ) );
    let cause = error.getTargetException(); ?assert cause != null;
    cause.printStackTraceWithSourceInfo( System.err, cl );
    !assert false;
  }
}

void _testExtendsDispatch(){
  let jarA = compile( "_testExtendsDispatch.a",
    toplevel: "enum Result { FOO, BAR } class Foo { Result foo() = FOO; }" );
  let jarB = compile( "_testExtendsDispatch.b",
    toplevel: "class Bar extends Foo { foo() = BAR; }",
    imp: "_testExtendsDispatch.a",
    main: "Foo foo = new Bar(); !assert foo.foo() == BAR;" );
  let urlNice = new java.io.File( NICE_JAR ).toURL();
  // This should be okay:
  invokeMain( "_testExtendsDispatch.b", [ jarB.toURL(), jarA.toURL(), urlNice ] );
  // Wrong classloading order, extending class is loaded after the extended one:
  invokeMain( "_testExtendsDispatch.b", [ urlNice, jarA.toURL(), jarB.toURL() ] );
}

void _testImplementsDispatch(){
  let jarA = compile( "_testImplementsDispatch.a",
    toplevel: "enum Result { FOO, BAR }\n" +
              "interface IF { Result foo(); }\n" +
              "class Foo implements IF { foo() = FOO; }" );
  let jarB = compile( "_testImplementsDispatch.b",
    toplevel: "class Bar implements IF { foo() = BAR; }",
    imp: "_testImplementsDispatch.a",
    main: "IF bar = new Bar(); !assert bar.foo() == BAR;" );
  let urlNice = new java.io.File( NICE_JAR ).toURL();
  // This should be okay:
  invokeMain( "_testImplementsDispatch.b", [ jarB.toURL(), jarA.toURL(), urlNice ] );
  // Wrong classloading order, extending class is loaded after the extended one:
  invokeMain( "_testImplementsDispatch.b", [ urlNice, jarA.toURL(), jarB.toURL() ] );
}



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf