PageRenderTime 28ms CodeModel.GetById 2ms app.highlight 20ms RepoModel.GetById 2ms app.codeStats 0ms

/trunk/Examples/test-suite/java/smart_pointer_const_overload_runme.java

#
Java | 99 lines | 56 code | 28 blank | 15 comment | 26 complexity | d0d56abdc1eb1a4c509925133aa6f8ac MD5 | raw file
 1import smart_pointer_const_overload.*;
 2
 3public class smart_pointer_const_overload_runme {
 4  static int CONST_ACCESS = 1;
 5  static int MUTABLE_ACCESS = 2;
 6
 7  static {
 8    System.loadLibrary("smart_pointer_const_overload");
 9  }
10  
11  public static void test(Bar b, Foo f) {
12    Assert(f.getX() == 0);
13
14    // Test member variable get
15    Assert(b.getX() == 0);
16    Assert(f.getAccess() == CONST_ACCESS);
17
18    // Test member variable set
19    b.setX(1);
20    Assert(f.getX() == 1);
21    Assert(f.getAccess() == MUTABLE_ACCESS);
22    
23    // Test const method
24    Assert(b.getx() == 1);
25    Assert(f.getAccess() == CONST_ACCESS);
26    
27    // Test mutable method
28    b.setx(2);
29
30    Assert(f.getX() == 2);
31    Assert(f.getAccess() == MUTABLE_ACCESS);
32    
33    // Test extended const method
34    Assert(b.getx2() == 2);
35    Assert(f.getAccess() == CONST_ACCESS);
36    
37    // Test extended mutable method
38    b.setx2(3);
39
40    Assert(f.getX() == 3);
41    Assert(f.getAccess() == MUTABLE_ACCESS);
42      
43    // Test static method
44    b.stat();
45
46    Assert(f.getAccess() == CONST_ACCESS);
47
48    // Test const member
49    f.setAccess(MUTABLE_ACCESS);
50    
51    Assert(b.getY() == 0);
52    Assert(f.getAccess() == CONST_ACCESS);
53    
54    // Test get through mutable pointer to const member
55    f.setAccess(MUTABLE_ACCESS);
56    
57    Assert(smart_pointer_const_overload.get_int(b.getYp()) == 0);
58    Assert(f.getAccess() == CONST_ACCESS);
59
60    // Test get through const pointer to mutable member
61    f.setX(4);
62    f.setAccess(MUTABLE_ACCESS);
63    
64    Assert(smart_pointer_const_overload.get_int(b.getXp()) == 4);
65    Assert(f.getAccess() == CONST_ACCESS);
66      
67    // Test set through const pointer to mutable member
68    f.setAccess(MUTABLE_ACCESS);
69    smart_pointer_const_overload.set_int(b.getXp(), 5);
70    
71    Assert(f.getX() == 5);
72    Assert(f.getAccess() == CONST_ACCESS);
73  
74    // Test set pointer to const member
75    b.setYp(smart_pointer_const_overload.new_int(6));
76  
77    Assert(f.getY() == 0);
78    Assert(smart_pointer_const_overload.get_int(f.getYp()) == 6);
79    Assert(f.getAccess() == MUTABLE_ACCESS);
80  
81    smart_pointer_const_overload.delete_int(f.getYp());
82  }
83
84  public static void main(String argv[]) {
85    Foo f = new Foo();
86    Bar b = new Bar(f);
87
88    //Foo f2 = new Foo();
89    //Bar b2 = new Bar2(f2);
90
91    test(b, f);
92    //test(b2, f2);
93  }
94  
95  public static void Assert(boolean b) {
96    if (!b)
97      throw new RuntimeException("Assertion failed");
98  }
99}