001: /**************************************************************************************
002: * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
003: * http://aspectwerkz.codehaus.org *
004: * ---------------------------------------------------------------------------------- *
005: * The software in this package is published under the terms of the LGPL license *
006: * a copy of which has been included with this distribution in the license.txt file. *
007: **************************************************************************************/package test.fieldsetbug;
008:
009: import test.ClassInfoTest;
010: import junit.framework.TestCase;
011:
012: /**
013: * AW-437 set pc and around advice
014: *
015: * @author <a href='mailto:the_mindstorm@evolva.ro'>Alexandru Popescu</a>
016: */
017: public class FieldSetTest extends TestCase {
018: public void testNonLongDoublePublicFieldSet() {
019: TargetClass instance1ofA = new TargetClass();
020:
021: instance1ofA.publicIntField = 2;
022: assertEquals("should not have access to the field", 1,
023: instance1ofA.publicIntField);
024:
025: instance1ofA.publicCharField = 'b';
026: assertEquals("should not have access to the field", 'a',
027: instance1ofA.publicCharField);
028:
029: try {
030: mayThrowException();
031: } catch (Exception e) {
032: ;
033: }
034: }
035:
036: public void testLongDoublePublicFieldSet() {
037: TargetClass tc = new TargetClass();
038:
039: tc.publicLongField = 2L;
040: assertEquals("should not have access to the field", 1L,
041: tc.publicLongField);
042:
043: tc.publicDoubleField = 2D;
044: assertEquals("should not have access to the field", 1D,
045: tc.publicLongField, 0D);
046: }
047:
048: /**
049: * java.lang.VerifyError: (class: test/fieldsetbug/FieldSetTest, method: testLongDoublePublicFieldSet signature: ()V)
050: * Inconsistent stack height 0 != 2
051: */
052: public void testLongDoublePublicFieldSetWithExceptionHandling() {
053: TargetClass instance1ofA = new TargetClass();
054:
055: instance1ofA.publicLongField = 2L;
056: assertEquals("should not have access to the field", 1L,
057: instance1ofA.publicLongField);
058:
059: instance1ofA.publicDoubleField = 2D;
060: assertEquals("should not have access to the field", 1D,
061: instance1ofA.publicLongField, 0D);
062:
063: try {
064: mayThrowException();
065: } catch (Exception e) {
066: ;
067: }
068: }
069:
070: public void testCtorAssignNonLongDoublePublicFieldSet() {
071: TargetClass tc = new TargetClass(2);
072: assertEquals("should have access to the field", 2,
073: tc.publicIntField);
074:
075: tc = new TargetClass('b');
076: assertEquals("should not have access to the field", 'b',
077: tc.publicCharField);
078:
079: try {
080: mayThrowException();
081: } catch (Exception ex) {
082: ;
083: }
084: }
085:
086: public void testCtorAssignLongDoublePublicFieldSet() {
087: TargetClass tc = new TargetClass(2L);
088: assertEquals("should have access to the field", 2L,
089: tc.publicLongField);
090:
091: tc = new TargetClass(2D);
092: assertEquals("should have access to the field", 2D,
093: tc.publicDoubleField, 0D);
094:
095: try {
096: mayThrowException();
097: } catch (Exception e) {
098: ;
099: }
100: }
101:
102: public void testCtorAndAssignLongPublicFieldSet() {
103: TargetClass tc = new TargetClass(2L);
104: assertEquals("should have access to the field", 2L,
105: tc.publicLongField);
106:
107: tc.publicLongField = 3L;
108: assertEquals("should not have access to the field", 2L,
109: tc.publicLongField);
110: }
111:
112: public void testCtorAndAssignNonLongWithExceptionHandling() {
113: TargetClass tc = new TargetClass(2);
114: assertEquals("should have access to the field", 2,
115: tc.publicIntField);
116:
117: tc.publicIntField = 3;
118: assertEquals("should not have access to the field", 2,
119: tc.publicIntField);
120:
121: try {
122: mayThrowException();
123: } catch (Exception ex) {
124: ;
125: }
126: }
127:
128: /**
129: * java.lang.VerifyError: (class: test/fieldsetbug/FieldSetTest, method: testCtorAndAssignLongPublicFieldSetThreadSleep signature: ()V)
130: * Inconsistent stack height 0 != 2
131: */
132: public void testCtorAndAssignLongWithExceptionHandling() {
133: TargetClass tc = new TargetClass(2L);
134: assertEquals("should have access to the field", 2L,
135: tc.publicLongField);
136:
137: tc.publicLongField = 3L;
138: assertEquals("should have access to the field", 2L,
139: tc.publicLongField);
140:
141: try {
142: mayThrowException();
143: } catch (Exception e) {
144: ;
145: }
146: }
147:
148: private void mayThrowException() throws Exception {
149: }
150:
151: //-- JUnit
152: public static void main(String[] args) {
153: junit.textui.TestRunner.run(suite());
154: }
155:
156: public static junit.framework.Test suite() {
157: return new junit.framework.TestSuite(FieldSetTest.class);
158: }
159: }
|