1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
package regtest.basic;
/**
Tests various aspects of interfacing with Java bytecode:
- use of native code
- import of native classes
- inlined methods
- access (read and write) to (static and instance) fields
*/
import java.io.*;
//<T> T nop(T) = inline regtest.basic.Nop();
// rebind static and non-static fields
String stringS() = native Fields.stringS;
String stringI(Fields) = native Fields.stringI;
List<String> fieldsList(Fields) = native Fields.stringList;
void test_native();
test_native()
{
println("\n### Testing native methods and classes ###\n");
File f = new File("titi");
try {
java.net.ServerSocket s = new java.net.ServerSocket(1235);
} catch(java.net.BindException e) {}
java.lang.System.currentTimeMillis();
Fields.intS = 2;
Fields.stringS = "Static field is: ";
println(Fields.stringS + Fields.intS);
Fields fields = new Fields();
fields.intI = 3;
fields.stringI = "Instance field is: ";
println(fields.stringI + fields.intI);
String s = fields.fieldsList[0];
assert (s.equals("First"));
}
// Tests creation of an array with a native type component.
// java.lang.Void is exotic enough so that it has not been loaded in a previous package
// (nice.lang), so that we check that this specific situation works.
Array<?java.lang.Void> noVoids() = new java.lang.Void[0];
|