summaryrefslogtreecommitdiff
path: root/Examples/test-suite/java/smart_pointer_const_overload_runme.java
blob: bb4ae2c8f47967c1b7f478262e6c040cbeb69786 (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import smart_pointer_const_overload.*;

public class smart_pointer_const_overload_runme {
  static int CONST_ACCESS = 1;
  static int MUTABLE_ACCESS = 2;

  static {
    System.loadLibrary("smart_pointer_const_overload");
  }
  
  public static void test(Bar b, Foo f) {
    Assert(f.getX() == 0);

    // Test member variable get
    Assert(b.getX() == 0);
    Assert(f.getAccess() == CONST_ACCESS);

    // Test member variable set
    b.setX(1);
    Assert(f.getX() == 1);
    Assert(f.getAccess() == MUTABLE_ACCESS);
    
    // Test const method
    Assert(b.getx() == 1);
    Assert(f.getAccess() == CONST_ACCESS);
    
    // Test mutable method
    b.setx(2);

    Assert(f.getX() == 2);
    Assert(f.getAccess() == MUTABLE_ACCESS);
    
    // Test extended const method
    Assert(b.getx2() == 2);
    Assert(f.getAccess() == CONST_ACCESS);
    
    // Test extended mutable method
    b.setx2(3);

    Assert(f.getX() == 3);
    Assert(f.getAccess() == MUTABLE_ACCESS);
      
    // Test static method
    b.stat();

    Assert(f.getAccess() == CONST_ACCESS);

    // Test const member
    f.setAccess(MUTABLE_ACCESS);
    
    Assert(b.getY() == 0);
    Assert(f.getAccess() == CONST_ACCESS);
    
    // Test get through mutable pointer to const member
    f.setAccess(MUTABLE_ACCESS);
    
    Assert(smart_pointer_const_overload.get_int(b.getYp()) == 0);
    Assert(f.getAccess() == CONST_ACCESS);

    // Test get through const pointer to mutable member
    f.setX(4);
    f.setAccess(MUTABLE_ACCESS);
    
    Assert(smart_pointer_const_overload.get_int(b.getXp()) == 4);
    Assert(f.getAccess() == CONST_ACCESS);
      
    // Test set through const pointer to mutable member
    f.setAccess(MUTABLE_ACCESS);
    smart_pointer_const_overload.set_int(b.getXp(), 5);
    
    Assert(f.getX() == 5);
    Assert(f.getAccess() == CONST_ACCESS);
  
    // Test set pointer to const member
    b.setYp(smart_pointer_const_overload.new_int(6));
  
    Assert(f.getY() == 0);
    Assert(smart_pointer_const_overload.get_int(f.getYp()) == 6);
    Assert(f.getAccess() == MUTABLE_ACCESS);
  
    smart_pointer_const_overload.delete_int(f.getYp());
  }

  public static void main(String argv[]) {
    Foo f = new Foo();
    Bar b = new Bar(f);

    //Foo f2 = new Foo();
    //Bar b2 = new Bar2(f2);

    test(b, f);
    //test(b2, f2);
  }
  
  public static void Assert(boolean b) {
    if (!b)
      throw new RuntimeException("Assertion failed");
  }
}