aboutsummaryrefslogtreecommitdiffstats
path: root/tests/new/AssignOps.java
blob: f33d1dd05dead98d578af1b626678ab4cf0067f8 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import org.aspectj.testing.Tester; 
import org.aspectj.testing.Tester;

aspect A {    
    static boolean start = false;
    static int bset;
    static int bget;
    static int siset;
    static int siget;
    static int iset;
    static int iget;
    static void start() {
        siset = siget = iset = iget = 0;
        start = true;
    }
    static String p() {
        return 
            " siset=" + siset
            + " siget=" + siget
            + " iset=" + iset
            + " iget=" + iget ;
    }
    before() : get(int AssignOps.staticInt) {
        signal(AssignOps.sigetStr+ siget++);
        check(siget == (1+siset), "siget == (1+siset)" + p());
    }
    before() : set(int AssignOps.staticInt) {
        signal(AssignOps.sisetStr + siset++);
        check(siget == siset, "siget == siset" + p());
    }
    before() : get(int AssignOps.instanceInt) {
        signal(AssignOps.igetStr + iget++);
        check(iget == (1+iset), "iget == (1+iset)" + p());
    }
    before() : set(int AssignOps.instanceInt) {
        signal(AssignOps.isetStr + iset++);
        check(iget == iset, "iget == iset" + p());
    }
    before() : get(boolean AssignOps.bool) {
        signal(AssignOps.bgetStr + bget++);
        check(bget == (1+bset), "bget == (1+bset)" + p());
    }
    before() : set(boolean AssignOps.bool) {
        signal(AssignOps.bsetStr + bset++);
        check(bget == bset, "bget == bset" + p());
    }
    static void check(boolean b, String s) { 
        if (start) Tester.check(b, s);
    }
    static void signal(String s) { 
        if (start) Tester.event(s); 
    }
}

/** @testcase operators ++ += etc. result in a get and set join point */
public class AssignOps {
    static int staticInt;
    int instanceInt;
    boolean bool;
    static final String sisetStr = "before() : set(int AssignOps.staticInt)";
    static final String sigetStr = "before() : get(int AssignOps.staticInt)";
    static final String isetStr = "before() : set(int AssignOps.instanceInt)";
    static final String igetStr = "before() : get(int AssignOps.instanceInt)";
    static final String bsetStr = "before() : set(boolean AssignOps.bool)";
    static final String bgetStr = "before() : get(boolean AssignOps.bool)";
    public static void main(String[] args) {
        new AssignOps(3).run();
        Tester.checkAllEvents();
    }
    static void t(String s) { Tester.expectEvent(s); }
    AssignOps(int i) { instanceInt = i; }
    void run() {
        A.start();
        t(igetStr + "0");
        t(isetStr + "0");
        instanceInt++;
        t(sigetStr + "0");
        t(sisetStr + "0");
        staticInt++;
        t(igetStr + "1");
        t(isetStr + "1");
        instanceInt += 2;
        t(sigetStr + "1");
        t(sisetStr + "1");
        staticInt += 2;

        t(igetStr + "2");
        t(isetStr + "2");
        instanceInt--;
        t(sigetStr + "2");
        t(sisetStr + "2");
        staticInt--;
        t(igetStr + "3");
        t(isetStr + "3");
        instanceInt -= 2;
        t(sigetStr + "3");
        t(sisetStr + "3");
        staticInt -= 2;

        t(igetStr + "4");
        t(isetStr + "4");
        instanceInt *= 2;
        t(sigetStr + "4");
        t(sisetStr + "4");
        staticInt *= 2;

        t(igetStr + "5");
        t(isetStr + "5");
        instanceInt /= 2;
        t(sigetStr + "5");
        t(sisetStr + "5");
        staticInt /= 2;

        t(igetStr + "6");
        t(isetStr + "6");
        instanceInt %= 2;
        t(sigetStr + "6");
        t(sisetStr + "6");
        staticInt %= 2;

        t(igetStr + "7");
        t(isetStr + "7");
        instanceInt >>= 2;
        t(sigetStr + "7");
        t(sisetStr + "7");
        staticInt >>= 2;

        t(igetStr + "8");
        t(isetStr + "8");
        instanceInt <<= 2;
        t(sigetStr + "8");
        t(sisetStr + "8");
        staticInt <<= 2;

        t(igetStr + "9");
        t(isetStr + "9");
        instanceInt >>>= 2;
        t(sigetStr + "9");
        t(sisetStr + "9");
        staticInt >>>= 2;

        t(bgetStr + "0");
        t(bsetStr + "0");
        bool &= true;
        t(bgetStr + "1");
        t(bsetStr + "1");
        bool |= false;
        t(bgetStr + "2");
        t(bsetStr + "2");
        bool ^= false;
    }
}