PageRenderTime 13ms CodeModel.GetById 9ms app.highlight 3ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/rel-1-3-29/SWIG/Examples/test-suite/java/director_protected_runme.java

#
Java | 85 lines | 68 code | 17 blank | 0 comment | 7 complexity | e1bae96118c82746f1f4cac8c6195af4 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
 1
 2import director_protected.*;
 3import java.lang.reflect.*;
 4
 5public class director_protected_runme {
 6
 7  static {
 8    try {
 9      System.loadLibrary("director_protected");
10    } catch (UnsatisfiedLinkError e) {
11      System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
12      System.exit(1);
13    }
14  }
15
16  public static void main(String argv[]) {
17
18    Bar b = new Bar();
19    Foo f = b.create();
20    director_protected_FooBar fb = new director_protected_FooBar();
21    director_protected_FooBar2 fb2 = new director_protected_FooBar2();
22
23    {
24      String s = fb.used();
25      if (!s.equals("Foo::pang();Bar::pong();Foo::pong();director_protected_FooBar::ping();"))
26        throw new RuntimeException( "bad director_protected_FooBar::used" );
27    }
28
29    {
30      String s = fb2.used();
31      if (!s.equals("director_protected_FooBar2::pang();Bar::pong();Foo::pong();director_protected_FooBar2::ping();"))
32        throw new RuntimeException( "bad director_protected_FooBar2::used" );
33    }
34
35    {
36      String s = b.pong();
37      if (!s.equals("Bar::pong();Foo::pong();Bar::ping();"))
38        throw new RuntimeException( "bad Bar::pong" );
39    }
40
41    {
42      String s = f.pong();
43      if (!s.equals("Bar::pong();Foo::pong();Bar::ping();"))
44        throw new RuntimeException(" bad Foo::pong" );
45    }
46
47    {
48      String s3 = fb.pong();
49      if (!s3.equals("Bar::pong();Foo::pong();director_protected_FooBar::ping();"))
50        throw new RuntimeException(" bad director_protected_FooBar::pong" );
51    }
52
53    try {
54
55      Method method = b.getClass().getDeclaredMethod("ping", (java.lang.Class[])null);
56      if ( !Modifier.isProtected(method.getModifiers()) )
57        throw new RuntimeException("Bar::ping should be protected" );
58
59      method = f.getClass().getDeclaredMethod("ping", (java.lang.Class[])null);
60      if ( !Modifier.isProtected(method.getModifiers()) )
61        throw new RuntimeException("Foo::ping should be protected" );
62
63    } catch (NoSuchMethodException n) {
64      throw new RuntimeException("NoSuchmethodException caught. Test failed.");
65    } catch (SecurityException s) {
66      throw new RuntimeException("SecurityException caught. Test failed.");
67    }
68  }
69}
70
71class director_protected_FooBar extends Bar {
72  public String ping() {
73    return "director_protected_FooBar::ping();";
74  }
75}
76
77class director_protected_FooBar2 extends Bar {
78  public String ping() {
79    return "director_protected_FooBar2::ping();";
80  }
81  public String pang() {
82    return "director_protected_FooBar2::pang();";
83  }
84}
85