Added javain, javout and newfree throws attributes tests

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4931 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2003-06-27 13:17:20 +00:00
commit 098e9be695
2 changed files with 55 additions and 7 deletions

View file

@ -27,20 +27,34 @@ public class java_throws_runme {
catch (CloneNotSupportedException e) {}
catch (IllegalAccessException e) {}
if (!pass) {
System.err.println("Test 1 failed");
System.exit(1);
}
if (!pass)
throw new RuntimeException("Test 1 failed");
// Check the exception class in the throw typemap
pass = false;
try {
java_throws.throw_spec_function(100);
}
catch (IllegalAccessException e) { pass = true; }
if (!pass) {
System.err.println("Test 2 failed");
System.exit(1);
if (!pass)
throw new RuntimeException("Test 2 failed");
// Check newfree typemap throws attribute
try {
TestClass tc = java_throws.makeTestClass();
}
catch (NoSuchMethodException e) {}
// Check javaout typemap throws attribute
pass = false;
try {
int myInt = java_throws.ioTest();
}
catch (java.io.IOException e) { pass = true; }
if (!pass)
throw new RuntimeException("Test 4 failed");
}
}

View file

@ -39,3 +39,37 @@ short full_of_exceptions(int num) {
void throw_spec_function(int value) throw (int) { throw (int)0; }
%}
// Check newfree typemap throws attribute
%newobject makeTestClass;
%typemap(newfree, throws="NoSuchMethodException") TestClass* "/*not written*/"
%inline %{
class TestClass {
int x;
public:
TestClass(int xx) : x(xx) {}
};
TestClass* makeTestClass() { return new TestClass(1000); }
%}
// javain typemap throws attribute
// Will only compile if the fileFunction has a java.io.IOException throws clause as getCanonicalPath() throws this exception
%typemap(jstype) char* someFileArgument "java.io.File"
%typemap(javain, throws="java.io.IOException") char* someFileArgument "$javainput.getCanonicalPath()"
%inline %{
void fileFunction(char* someFileArgument) {}
%}
// javout typemap throws attribute
%typemap(javaout, throws="java.io.IOException") int {
int returnValue=$jnicall;
if (returnValue==0) throw new java.io.IOException("some IOException");
return returnValue;
}
%inline %{
int ioTest() { return 0; }
%}