From: aclement Date: Wed, 5 Oct 2005 12:49:53 +0000 (+0000) Subject: testcase for pr85132 X-Git-Tag: V1_5_0M4~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8d098f969f5ef67fb15b2b56f44bdd21f7929bc6;p=aspectj.git testcase for pr85132 --- diff --git a/tests/multiIncremental/PR85132/base/bean/BoundPoint.java b/tests/multiIncremental/PR85132/base/bean/BoundPoint.java new file mode 100644 index 000000000..36c85819c --- /dev/null +++ b/tests/multiIncremental/PR85132/base/bean/BoundPoint.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 1998-2002 Xerox Corporation, + * 2004 Contributors. All rights reserved. + * + * Use and copying of this software and preparation of derivative works based + * upon this software are permitted. Any distribution of this software or + * derivative works must comply with all applicable United States export + * control laws. + * + * This software is made available AS IS, and Xerox Corporation makes no + * warranty about the software, its performance or its conformity to any + * specification. + */ + +package bean; + +import java.beans.*; +import java.io.Serializable; + +/** + * Add bound properties and serialization to Point objects + */ +aspect BoundPoint { + /* + * privately declare a field on Point to hold the property + * change support object. `this' is a reference to a Point object. + */ + private PropertyChangeSupport Point.support = new PropertyChangeSupport(this); + + /* + * Declare property change registration methods on Point, + * and introduce implementation of the Serializable interface. + */ + + public void Point.addPropertyChangeListener(PropertyChangeListener listener){ + support.addPropertyChangeListener(listener); + } + + public void Point.addPropertyChangeListener(String propertyName, + PropertyChangeListener listener){ + support.addPropertyChangeListener(propertyName, listener); + } + + public void Point.removePropertyChangeListener(String propertyName, + PropertyChangeListener listener) { + support.removePropertyChangeListener(propertyName, listener); + } + + public void Point.removePropertyChangeListener(PropertyChangeListener listener) { + support.removePropertyChangeListener(listener); + } + + public void Point.hasListeners(String propertyName) { + support.hasListeners(propertyName); + } + + declare parents: Point implements Serializable; + + /** + * Send property change event after X setter completes normally. + * Use around advice to keep the old value on the stack. + */ + void around(Point p): execution(void Point.setX(int)) && target(p) { + int oldValue = p.getX(); + proceed(p); + firePropertyChange(p, "x", oldValue, p.getX()); + } + + /** + * Send property change event after Y setter completes normally. + * Use around advice to keep the old value on the stack. + */ + void around(Point p): execution(void Point.setY(int)) && target(p) { + int oldValue = p.getY(); + proceed(p); + firePropertyChange(p, "y", oldValue, p.getY()); + } + + /* + * Utility to fire the property change event. + */ + void firePropertyChange(Point p, + String property, + double oldval, + double newval) { + p.support.firePropertyChange(property, + new Double(oldval), + new Double(newval)); + } +} diff --git a/tests/multiIncremental/PR85132/base/bean/Demo.java b/tests/multiIncremental/PR85132/base/bean/Demo.java new file mode 100644 index 000000000..e16be245e --- /dev/null +++ b/tests/multiIncremental/PR85132/base/bean/Demo.java @@ -0,0 +1,80 @@ +/* +Copyright (c) Xerox Corporation 1998-2002. All rights reserved. + +Use and copying of this software and preparation of derivative works based +upon this software are permitted. Any distribution of this software or +derivative works must comply with all applicable United States export control +laws. +*/ + +package bean; + +import java.beans.*; +import java.io.*; + +public class Demo implements PropertyChangeListener { + + static final String fileName = "test.tmp"; + + /** + * when Demo is playing the listener role, + * this method reports that a propery has changed + */ + public void propertyChange(PropertyChangeEvent e){ + System.out.println("Property " + e.getPropertyName() + " changed from " + + e.getOldValue() + " to " + e.getNewValue() ); + } + + /** + * main: test the program + */ + public static void main(String[] args){ + Point p1 = new Point(); + p1.addPropertyChangeListener(new Demo()); + System.out.println("p1 =" + p1); + p1.setRectangular(5,2); + System.out.println("p1 =" + p1); + p1.setX( 6 ); + p1.setY( 3 ); + System.out.println("p1 =" + p1); + p1.offset(6,4); + System.out.println("p1 =" + p1); + save(p1, fileName); + Point p2 = (Point) restore(fileName); + System.out.println("Had: " + p1); + System.out.println("Got: " + p2); + } + + /** + * Save a serializable object to a file + */ + static void save(Serializable p, String fn){ + try { + System.out.println("Writing to file: " + p); + FileOutputStream fo = new FileOutputStream(fn); + ObjectOutputStream so = new ObjectOutputStream(fo); + so.writeObject(p); + so.flush(); + } catch (Exception e) { + System.out.println(e); + System.exit(1); + } + } + + /** + * Restore a serializable object from the file + */ + static Object restore(String fn){ + try { + Object result; + System.out.println("Reading from file: " + fn); + FileInputStream fi = new FileInputStream(fn); + ObjectInputStream si = new ObjectInputStream(fi); + return si.readObject(); + } catch (Exception e) { + System.out.println(e); + System.exit(1); + } + return null; + } +} diff --git a/tests/multiIncremental/PR85132/base/bean/Point.java b/tests/multiIncremental/PR85132/base/bean/Point.java new file mode 100644 index 000000000..a6ea703cd --- /dev/null +++ b/tests/multiIncremental/PR85132/base/bean/Point.java @@ -0,0 +1,69 @@ +/* +Copyright (c) Xerox Corporation 1998-2002. All rights reserved. + +Use and copying of this software and preparation of derivative works based +upon this software are permitted. Any distribution of this software or +derivative works must comply with all applicable United States export control +laws. + +This software is made available AS IS, and Xerox Corporation makes no warranty +about the software, its performance or its conformity to any specification. +*/ + +package bean; + +class Point { + + protected int x = 0; + protected int y = 0; + + /** + * Return the X coordinate + */ + public int getX(){ + return x; + } + + /** + * Return the y coordinate + */ + public int getY(){ + return y; + } + + /** + * Set the x and y coordinates + */ + public void setRectangular(int newX, int newY){ + setX(newX); + setY(newY); + } + + /** + * Set the X coordinate + */ + public void setX(int newX) { + x = newX; + } + + /** + * set the y coordinate + */ + public void setY(int newY) { + y = newY; + } + + /** + * Move the point by the specified x and y offset + */ + public void offset(int deltaX, int deltaY){ + setRectangular(x + deltaX, y + deltaY); + } + + /** + * Make a string of this + */ + public String toString(){ + return "(" + getX() + ", " + getY() + ")" ; + } +} diff --git a/tests/multiIncremental/PR85132/inc1/bean/Demo.java b/tests/multiIncremental/PR85132/inc1/bean/Demo.java new file mode 100644 index 000000000..a4ef0472c --- /dev/null +++ b/tests/multiIncremental/PR85132/inc1/bean/Demo.java @@ -0,0 +1,81 @@ +/* +Copyright (c) Xerox Corporation 1998-2002. All rights reserved. + + +Use and copying of this software and preparation of derivative works based +upon this software are permitted. Any distribution of this software or +derivative works must comply with all applicable United States export control +laws. +*/ + +package bean; + +import java.beans.*; +import java.io.*; + +public class Demo implements PropertyChangeListener { + + static final String fileName = "test.tmp"; + + /** + * when Demo is playing the listener role, + * this method reports that a propery has changed + */ + public void propertyChange(PropertyChangeEvent e){ + System.out.println("Property " + e.getPropertyName() + " changed from " + + e.getOldValue() + " to " + e.getNewValue() ); + } + + /** + * main: test the program + */ + public static void main(String[] args){ + Point p1 = new Point(); + p1.addPropertyChangeListener(new Demo()); + System.out.println("p1 =" + p1); + p1.setRectangular(5,2); + System.out.println("p1 =" + p1); + p1.setX( 6 ); + p1.setY( 3 ); + System.out.println("p1 =" + p1); + p1.offset(6,4); + System.out.println("p1 =" + p1); + save(p1, fileName); + Point p2 = (Point) restore(fileName); + System.out.println("Had: " + p1); + System.out.println("Got: " + p2); + } + + /** + * Save a serializable object to a file + */ + static void save(Serializable p, String fn){ + try { + System.out.println("Writing to file: " + p); + FileOutputStream fo = new FileOutputStream(fn); + ObjectOutputStream so = new ObjectOutputStream(fo); + so.writeObject(p); + so.flush(); + } catch (Exception e) { + System.out.println(e); + System.exit(1); + } + } + + /** + * Restore a serializable object from the file + */ + static Object restore(String fn){ + try { + Object result; + System.out.println("Reading from file: " + fn); + FileInputStream fi = new FileInputStream(fn); + ObjectInputStream si = new ObjectInputStream(fi); + return si.readObject(); + } catch (Exception e) { + System.out.println(e); + System.exit(1); + } + return null; + } +} diff --git a/tests/src/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java b/tests/src/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java index 0bbe1f7f6..67a1bd7b8 100644 --- a/tests/src/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java +++ b/tests/src/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java @@ -277,6 +277,15 @@ public class MultiProjectIncrementalTests extends AjdeInteractionTestbed { // - memory usage (freemem calls?) // - relationship map + +// public void testPr85132() { +// super.VERBOSE=true; +// initialiseProject("PR85132"); +// build("PR85132"); +// alter("PR85132","inc1"); +// build("PR85132"); +// } + // --------------------------------------------------------------------------------------------------- /**