1 /***************************************************************************************
2 * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3 * http://aspectwerkz.codehaus.org *
4 * ---------------------------------------------------------------------------------- *
5 * The software in this package is published under the terms of the LGPL license *
6 * a copy of which has been included with this distribution in the license.txt file. *
7 **************************************************************************************/
8 package test.fieldsetbug;
9
10
11 import test.ClassInfoTest;
12 import junit.framework.TestCase;
13
14 /***
15 * AW-437 set pc and around advice
16 *
17 * @author <a href='mailto:the_mindstorm@evolva.ro'>Alexandru Popescu</a>
18 */
19 public class FieldSetTest extends TestCase {
20 public void testNonLongDoublePublicFieldSet() {
21 TargetClass instance1ofA = new TargetClass();
22
23 instance1ofA.publicIntField = 2;
24 assertEquals("should not have access to the field", 1, instance1ofA.publicIntField);
25
26 instance1ofA.publicCharField = 'b';
27 assertEquals("should not have access to the field", 'a', instance1ofA.publicCharField);
28
29 try {
30 mayThrowException();
31 } catch(Exception e) {
32 ;
33 }
34 }
35
36 public void testLongDoublePublicFieldSet() {
37 TargetClass tc = new TargetClass();
38
39 tc.publicLongField = 2L;
40 assertEquals("should not have access to the field", 1L, tc.publicLongField);
41
42 tc.publicDoubleField = 2D;
43 assertEquals("should not have access to the field", 1D, tc.publicLongField, 0D);
44 }
45
46 /***
47 * java.lang.VerifyError: (class: test/fieldsetbug/FieldSetTest, method: testLongDoublePublicFieldSet signature: ()V)
48 * Inconsistent stack height 0 != 2
49 */
50 public void testLongDoublePublicFieldSetWithExceptionHandling() {
51 TargetClass instance1ofA = new TargetClass();
52
53 instance1ofA.publicLongField = 2L;
54 assertEquals("should not have access to the field", 1L, instance1ofA.publicLongField);
55
56 instance1ofA.publicDoubleField = 2D;
57 assertEquals("should not have access to the field", 1D, instance1ofA.publicLongField, 0D);
58
59 try {
60 mayThrowException();
61 } catch(Exception e) {
62 ;
63 }
64 }
65
66 public void testCtorAssignNonLongDoublePublicFieldSet() {
67 TargetClass tc = new TargetClass(2);
68 assertEquals("should have access to the field", 2, tc.publicIntField);
69
70 tc = new TargetClass('b');
71 assertEquals("should not have access to the field", 'b', tc.publicCharField);
72
73 try {
74 mayThrowException();
75 } catch(Exception ex) {
76 ;
77 }
78 }
79
80 public void testCtorAssignLongDoublePublicFieldSet() {
81 TargetClass tc = new TargetClass(2L);
82 assertEquals("should have access to the field", 2L, tc.publicLongField);
83
84 tc = new TargetClass(2D);
85 assertEquals("should have access to the field", 2D, tc.publicDoubleField, 0D);
86
87 try {
88 mayThrowException();
89 } catch(Exception e) {
90 ;
91 }
92 }
93
94 public void testCtorAndAssignLongPublicFieldSet() {
95 TargetClass tc = new TargetClass(2L);
96 assertEquals("should have access to the field", 2L, tc.publicLongField);
97
98 tc.publicLongField = 3L;
99 assertEquals("should not have access to the field", 2L, tc.publicLongField);
100 }
101
102 public void testCtorAndAssignNonLongWithExceptionHandling() {
103 TargetClass tc = new TargetClass(2);
104 assertEquals("should have access to the field", 2, tc.publicIntField);
105
106 tc.publicIntField = 3;
107 assertEquals("should not have access to the field", 2, tc.publicIntField);
108
109 try {
110 mayThrowException();
111 } catch(Exception ex) {
112 ;
113 }
114 }
115
116 /***
117 * java.lang.VerifyError: (class: test/fieldsetbug/FieldSetTest, method: testCtorAndAssignLongPublicFieldSetThreadSleep signature: ()V)
118 * Inconsistent stack height 0 != 2
119 */
120 public void testCtorAndAssignLongWithExceptionHandling() {
121 TargetClass tc = new TargetClass(2L);
122 assertEquals("should have access to the field", 2L, tc.publicLongField);
123
124 tc.publicLongField = 3L;
125 assertEquals("should have access to the field", 2L, tc.publicLongField);
126
127 try {
128 mayThrowException();
129 } catch(Exception e) {
130 ;
131 }
132 }
133
134 private void mayThrowException() throws Exception {
135 }
136
137
138 public static void main(String[] args) {
139 junit.textui.TestRunner.run(suite());
140 }
141
142 public static junit.framework.Test suite() {
143 return new junit.framework.TestSuite(FieldSetTest.class);
144 }
145 }