Browse Source

additional test cases to cover matching Pointcuts against

JoinPoints
tags/for_ajdt1_1_12
acolyer 20 years ago
parent
commit
cf8974d359

+ 36
- 0
weaver/testsrc/org/aspectj/weaver/patterns/AndOrNotTestCase.java View File

@@ -15,6 +15,10 @@ package org.aspectj.weaver.patterns;

import java.io.*;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.runtime.reflect.Factory;
import org.aspectj.util.FuzzyBoolean;
import org.aspectj.weaver.bcel.*;

import junit.framework.TestCase;
@@ -65,6 +69,31 @@ public class AndOrNotTestCase extends TestCase {
checkEquals("!!this(Foo)", new NotPointcut(new NotPointcut(foo)));
}
public void testJoinPointMatch() {
Pointcut foo = makePointcut("this(org.aspectj.weaver.patterns.AndOrNotTestCase.Foo)").resolve();
Pointcut bar = makePointcut("this(org.aspectj.weaver.patterns.AndOrNotTestCase.Bar)").resolve();
Pointcut c = makePointcut("this(org.aspectj.weaver.patterns.AndOrNotTestCase.C)").resolve();
Factory f = new Factory("AndOrNotTestCase.java",AndOrNotTestCase.class);
Signature methodSig = f.makeMethodSig("void aMethod()");
JoinPoint.StaticPart jpsp = f.makeSJP(JoinPoint.METHOD_EXECUTION,methodSig,1);
JoinPoint jp = Factory.makeJP(jpsp,new Foo(),new Foo());
checkMatches(new AndPointcut(foo,bar),jp,null,FuzzyBoolean.NO);
checkMatches(new AndPointcut(foo,foo),jp,null,FuzzyBoolean.YES);
checkMatches(new AndPointcut(bar,foo),jp,null,FuzzyBoolean.NO);
checkMatches(new AndPointcut(bar,c),jp,null,FuzzyBoolean.NO);
checkMatches(new OrPointcut(foo,bar),jp,null,FuzzyBoolean.YES);
checkMatches(new OrPointcut(foo,foo),jp,null,FuzzyBoolean.YES);
checkMatches(new OrPointcut(bar,foo),jp,null,FuzzyBoolean.YES);
checkMatches(new OrPointcut(bar,c),jp,null,FuzzyBoolean.NO);
checkMatches(new NotPointcut(foo),jp,null,FuzzyBoolean.NO);
checkMatches(new NotPointcut(bar),jp,null,FuzzyBoolean.YES);
}

private Pointcut makePointcut(String pattern) {
return new PatternParser(pattern).parsePointcut();
@@ -75,6 +104,9 @@ public class AndOrNotTestCase extends TestCase {
checkSerialization(pattern);
}

private void checkMatches(Pointcut p, JoinPoint jp, JoinPoint.StaticPart jpsp, FuzzyBoolean expected) {
assertEquals(expected,p.match(jp,jpsp));
}
// private void checkMatch(Pointcut p, Signature[] matches, boolean shouldMatch) {
// for (int i=0; i<matches.length; i++) {
@@ -116,4 +148,8 @@ public class AndOrNotTestCase extends TestCase {
assertEquals("write/read", p, newP);
}
private static class Foo{};
private static class Bar{};
private static class C{};
}

+ 91
- 0
weaver/testsrc/org/aspectj/weaver/patterns/ArgsTestCase.java View File

@@ -0,0 +1,91 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.aspectj.weaver.patterns;

import junit.framework.TestCase;

import org.aspectj.lang.JoinPoint;
import org.aspectj.runtime.reflect.Factory;
import org.aspectj.util.FuzzyBoolean;

/**
* @author colyer
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class ArgsTestCase extends TestCase {
Pointcut wildcardArgs;
Pointcut oneA;
Pointcut oneAandaC;
Pointcut BthenAnything;
Pointcut singleArg;
public void testMatchJP() {
Factory f = new Factory("ArgsTestCase.java",ArgsTestCase.A.class);
JoinPoint.StaticPart jpsp1 = f.makeSJP(JoinPoint.METHOD_EXECUTION,f.makeMethodSig(0,"aMethod",A.class,new Class[] {A.class},new String[] {"a"},new Class[] {},null) ,1);
JoinPoint.StaticPart jpsp2 = f.makeSJP(JoinPoint.METHOD_EXECUTION,f.makeMethodSig(0,"aMethod",A.class,new Class[] {B.class},new String[] {"b"},new Class[] {},null),1);
JoinPoint.StaticPart jpsp3 = f.makeSJP(JoinPoint.METHOD_EXECUTION,f.makeMethodSig(0,"aMethod",A.class,new Class[] {A.class,C.class},new String[] {"a","c"},new Class[] {},null),1);
JoinPoint.StaticPart jpsp4 = f.makeSJP(JoinPoint.METHOD_EXECUTION,f.makeMethodSig(0,"aMethod",A.class,new Class[] {A.class,A.class},new String[] {"a","a2"},new Class[] {},null),1);
JoinPoint oneAArg = Factory.makeJP(jpsp1,new A(),new A(),new A());
JoinPoint oneBArg = Factory.makeJP(jpsp2,new A(), new A(), new B());
JoinPoint acArgs = Factory.makeJP(jpsp3,new A(), new A(), new A(), new C());
JoinPoint baArgs = Factory.makeJP(jpsp4,new A(), new A(), new B(), new A());
checkMatches(wildcardArgs,oneAArg,null,FuzzyBoolean.YES);
checkMatches(wildcardArgs,oneBArg,null,FuzzyBoolean.YES);
checkMatches(wildcardArgs,acArgs,null,FuzzyBoolean.YES);
checkMatches(wildcardArgs,baArgs,null,FuzzyBoolean.YES);
checkMatches(oneA,oneAArg,null,FuzzyBoolean.YES);
checkMatches(oneA,oneBArg,null,FuzzyBoolean.YES);
checkMatches(oneA,acArgs,null,FuzzyBoolean.NO);
checkMatches(oneA,baArgs,null,FuzzyBoolean.NO);

checkMatches(oneAandaC,oneAArg,null,FuzzyBoolean.NO);
checkMatches(oneAandaC,oneBArg,null,FuzzyBoolean.NO);
checkMatches(oneAandaC,acArgs,null,FuzzyBoolean.YES);
checkMatches(oneAandaC,baArgs,null,FuzzyBoolean.NO);
checkMatches(BthenAnything,oneAArg,null,FuzzyBoolean.NO);
checkMatches(BthenAnything,oneBArg,null,FuzzyBoolean.YES);
checkMatches(BthenAnything,acArgs,null,FuzzyBoolean.NO);
checkMatches(BthenAnything,baArgs,null,FuzzyBoolean.YES);

checkMatches(singleArg,oneAArg,null,FuzzyBoolean.YES);
checkMatches(singleArg,oneBArg,null,FuzzyBoolean.YES);
checkMatches(singleArg,acArgs,null,FuzzyBoolean.NO);
checkMatches(singleArg,baArgs,null,FuzzyBoolean.NO);

}
private void checkMatches(Pointcut p, JoinPoint jp, JoinPoint.StaticPart jpsp, FuzzyBoolean expected) {
assertEquals(expected,p.match(jp,jpsp));
}
private static class A {};
private static class B extends A {};
private static class C {};

/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
wildcardArgs = new PatternParser("args(..)").parsePointcut().resolve();
oneA = new PatternParser("args(org.aspectj.weaver.patterns.ArgsTestCase.A)").parsePointcut().resolve();
oneAandaC = new PatternParser("args(org.aspectj.weaver.patterns.ArgsTestCase.A,org.aspectj.weaver.patterns.ArgsTestCase.C)").parsePointcut().resolve();
BthenAnything = new PatternParser("args(org.aspectj.weaver.patterns.ArgsTestCase.B,..)").parsePointcut().resolve();
singleArg = new PatternParser("args(*)").parsePointcut().resolve();
}
}

+ 65
- 0
weaver/testsrc/org/aspectj/weaver/patterns/HandlerTestCase.java View File

@@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.aspectj.weaver.patterns;

import java.io.IOException;

import org.aspectj.lang.JoinPoint;
import org.aspectj.runtime.reflect.Factory;
import org.aspectj.util.FuzzyBoolean;

import junit.framework.TestCase;


public class HandlerTestCase extends TestCase {

private Pointcut hEx;
private Pointcut hExPlus;
private Pointcut hIOEx;
public void testHandlerMatch() {
Factory f = new Factory("HandlerTestCase.java",HandlerTestCase.class);
JoinPoint.StaticPart jpsp1 = f.makeSJP(JoinPoint.EXCEPTION_HANDLER,f.makeCatchClauseSig(HandlerTestCase.class,Exception.class,"ex"),1);
JoinPoint ex = Factory.makeJP(jpsp1,this,this,new Exception());
JoinPoint ioex = Factory.makeJP(jpsp1,this,this,new IOException());
JoinPoint myex = Factory.makeJP(jpsp1,this,this,new MyException());
checkMatches(hEx,ex,null,FuzzyBoolean.YES);
checkMatches(hEx,ioex,null,FuzzyBoolean.NO);
checkMatches(hEx,myex,null,FuzzyBoolean.NO);

checkMatches(hExPlus,ex,null,FuzzyBoolean.YES);
checkMatches(hExPlus,ioex,null,FuzzyBoolean.YES);
checkMatches(hExPlus,myex,null,FuzzyBoolean.YES);

checkMatches(hIOEx,ex,null,FuzzyBoolean.NO);
checkMatches(hIOEx,ioex,null,FuzzyBoolean.YES);
checkMatches(hIOEx,myex,null,FuzzyBoolean.NO);

}
private void checkMatches(Pointcut p, JoinPoint jp, JoinPoint.StaticPart jpsp, FuzzyBoolean expected) {
assertEquals(expected,p.match(jp,jpsp));
}
private static class MyException extends Exception {}
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
hEx = new PatternParser("handler(Exception)").parsePointcut().resolve();
hExPlus = new PatternParser("handler(Exception+)").parsePointcut().resolve();
hIOEx = new PatternParser("handler(java.io.IOException)").parsePointcut().resolve();
}
}

+ 102
- 0
weaver/testsrc/org/aspectj/weaver/patterns/KindedTestCase.java View File

@@ -0,0 +1,102 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.aspectj.weaver.patterns;

import java.lang.reflect.Modifier;

import org.aspectj.lang.JoinPoint;
import org.aspectj.runtime.reflect.Factory;
import org.aspectj.util.FuzzyBoolean;

import junit.framework.TestCase;

/**
* @author colyer
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class KindedTestCase extends TestCase {
Pointcut callpc;
Pointcut exepc;
Pointcut exepcplus;
Pointcut exepcCons;
Pointcut adviceexepc;
Pointcut initpc;
Pointcut preinitpc;
Pointcut staticinitpc;
Pointcut getpc;
Pointcut setpc;
public void testKindedMatch() {
Factory f = new Factory("KindedTestCase.java",KindedTestCase.class);
// JoinPoints to match against...
JoinPoint.StaticPart calljp1 = f.makeSJP(JoinPoint.METHOD_CALL,f.makeMethodSig(0,"main",Hello.class,new Class[] {String.class},new String[] {"s"},new Class[0],String.class),1);
JoinPoint.StaticPart calljp2 = f.makeSJP(JoinPoint.METHOD_CALL,f.makeMethodSig(0,"sayHi",Hello.class,new Class[] {String.class},new String[] {"s"},new Class[0],String.class),1);
JoinPoint.StaticPart exejp1 = f.makeSJP(JoinPoint.METHOD_EXECUTION,f.makeMethodSig(0,"main",Hello.class,new Class[] {String.class},new String[] {"s"},new Class[0],String.class),1);
JoinPoint.StaticPart exejp2 = f.makeSJP(JoinPoint.METHOD_EXECUTION,f.makeMethodSig(0,"sayHi",Hello.class,new Class[] {String.class},new String[] {"s"},new Class[0],void.class),1);
JoinPoint.StaticPart execonsjp1 = f.makeSJP(JoinPoint.CONSTRUCTOR_EXECUTION,f.makeConstructorSig(0,Hello.class,new Class[0],new String[0],new Class[0]),1);
JoinPoint.StaticPart execonsjp2 = f.makeSJP(JoinPoint.CONSTRUCTOR_EXECUTION,f.makeConstructorSig(0,String.class,new Class[] {String.class},new String[]{"s"},new Class[0]),1);
JoinPoint.StaticPart initjp1 = f.makeSJP(JoinPoint.INITIALIZATION,f.makeConstructorSig(0,Hello.class,new Class[0],new String[0],new Class[0]),1);
JoinPoint.StaticPart initjp2 = f.makeSJP(JoinPoint.PREINTIALIZATION,f.makeConstructorSig(0,Hello.class,new Class[]{int.class, int.class},new String[]{"a","b"},new Class[0]),1);
JoinPoint.StaticPart sinitjp1 = f.makeSJP(JoinPoint.STATICINITIALIZATION,f.makeInitializerSig(Modifier.STATIC,Hello.class),1);
JoinPoint.StaticPart sinitjp2 = f.makeSJP(JoinPoint.STATICINITIALIZATION,f.makeInitializerSig(Modifier.STATIC,String.class),1);
JoinPoint.StaticPart getjp1 = f.makeSJP(JoinPoint.FIELD_GET,f.makeFieldSig(0,"x",Hello.class,int.class),1);
JoinPoint.StaticPart getjp2 = f.makeSJP(JoinPoint.FIELD_GET,f.makeFieldSig(0,"y",String.class,String.class),1);
JoinPoint.StaticPart setjp1 = f.makeSJP(JoinPoint.FIELD_SET,f.makeFieldSig(0,"x",Hello.class,int.class),1);
JoinPoint.StaticPart setjp2 = f.makeSJP(JoinPoint.FIELD_SET,f.makeFieldSig(0,"y",String.class,String.class),1);
JoinPoint.StaticPart advjp = f.makeSJP(JoinPoint.ADVICE_EXECUTION,f.makeAdviceSig(0,"foo",Hello.class,new Class[0],new String[0],new Class[0],void.class),1);
checkMatches(callpc,calljp1,FuzzyBoolean.YES);
checkMatches(callpc,calljp2,FuzzyBoolean.NO);
checkMatches(callpc,exejp1,FuzzyBoolean.NO);
checkMatches(exepc,exejp1,FuzzyBoolean.NO);
checkMatches(exepc,exejp2,FuzzyBoolean.YES);
checkMatches(exepcplus,exejp1,FuzzyBoolean.NO);
checkMatches(exepcplus,exejp2,FuzzyBoolean.YES);
checkMatches(exepcCons,execonsjp1,FuzzyBoolean.YES);
checkMatches(exepcCons,execonsjp2,FuzzyBoolean.NO);
checkMatches(exepcCons,exejp1,FuzzyBoolean.NO);
checkMatches(initpc,initjp1,FuzzyBoolean.YES);
checkMatches(initpc,initjp2,FuzzyBoolean.NO);
checkMatches(preinitpc,initjp1,FuzzyBoolean.NO);
checkMatches(preinitpc,initjp2,FuzzyBoolean.YES);
checkMatches(staticinitpc,sinitjp1,FuzzyBoolean.YES);
checkMatches(staticinitpc,sinitjp2,FuzzyBoolean.NO);
checkMatches(getpc,getjp1,FuzzyBoolean.YES);
checkMatches(getpc,getjp2,FuzzyBoolean.YES);
checkMatches(setpc,setjp1,FuzzyBoolean.YES);
checkMatches(setpc,setjp2,FuzzyBoolean.NO);
checkMatches(adviceexepc,advjp,FuzzyBoolean.YES);
}
private void checkMatches(Pointcut p, JoinPoint.StaticPart jpsp, FuzzyBoolean expected) {
assertEquals(expected,p.match(jpsp));
}
protected void setUp() throws Exception {
super.setUp();
callpc = new PatternParser("call(* main(..))").parsePointcut().resolve();
exepc = new PatternParser("execution(void org.aspectj.weaver.patterns.KindedTestCase.Hello.sayHi(String))").parsePointcut().resolve();
exepcplus = new PatternParser("execution(void Object+.sayHi(String))").parsePointcut().resolve();
exepcCons = new PatternParser("execution(org.aspectj.weaver.patterns.KindedTestCase.Hello.new(..))").parsePointcut().resolve();
initpc = new PatternParser("initialization(new(..))").parsePointcut().resolve();
preinitpc = new PatternParser("preinitialization(*..H*.new(int,int))").parsePointcut().resolve();
staticinitpc = new PatternParser("staticinitialization(org.aspectj.weaver.patterns.KindedTestCase.Hello)").parsePointcut().resolve();
getpc = new PatternParser("get(* *)").parsePointcut().resolve();
setpc = new PatternParser("set(int x)").parsePointcut().resolve();
adviceexepc = new PatternParser("adviceexecution()").parsePointcut().resolve();
}
private static class Hello {};
}

+ 5
- 0
weaver/testsrc/org/aspectj/weaver/patterns/PatternsTests.java View File

@@ -32,6 +32,11 @@ public class PatternsTests extends TestCase {
suite.addTestSuite(TypePatternListTestCase.class);
suite.addTestSuite(TypePatternTestCase.class);
suite.addTestSuite(WithinTestCase.class);
suite.addTestSuite(PointcutTestCase.class);
suite.addTestSuite(ArgsTestCase.class);
suite.addTestSuite(HandlerTestCase.class);
suite.addTestSuite(KindedTestCase.class);
suite.addTestSuite(WithinCodeTestCase.class);
//$JUnit-END$
return suite;
}

+ 79
- 0
weaver/testsrc/org/aspectj/weaver/patterns/PointcutTestCase.java View File

@@ -0,0 +1,79 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.aspectj.weaver.patterns;

import java.io.DataOutputStream;
import java.io.IOException;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.runtime.reflect.Factory;
import org.aspectj.util.FuzzyBoolean;
import org.aspectj.weaver.IntMap;
import org.aspectj.weaver.ResolvedTypeX;
import org.aspectj.weaver.Shadow;
import org.aspectj.weaver.ast.Test;

import junit.framework.TestCase;


public class PointcutTestCase extends TestCase {
public void testMatchJP() {
Pointcut p = new Pointcut() {

public FuzzyBoolean fastMatch(FastMatchInfo info) {
return null;
}

public FuzzyBoolean match(Shadow shadow) {
return null;
}

protected void resolveBindings(IScope scope, Bindings bindings) {
}
protected void resolveBindingsFromRTTI() {}

protected Pointcut concretize1(ResolvedTypeX inAspect, IntMap bindings) {
return null;
}

public Test findResidue(Shadow shadow, ExposedState state) {
return null;
}

public void write(DataOutputStream s) throws IOException {
}};
Factory f = new Factory("PointcutTestCase.java",PointcutTestCase.class);
Signature methodSig = f.makeMethodSig("void aMethod()");
JoinPoint.StaticPart jpsp = f.makeSJP(JoinPoint.METHOD_EXECUTION,methodSig,1);
JoinPoint jp = Factory.makeJP(jpsp,this,this);
try {
p.match(jp,null);
fail("Expected UnsupportedOperationException to be thrown");
} catch (UnsupportedOperationException unEx) {
// ok
}
try {
p.match(jpsp);
fail("Expected UnsupportedOperationException to be thrown");
} catch (UnsupportedOperationException unEx) {
// ok
}
}
}

+ 43
- 0
weaver/testsrc/org/aspectj/weaver/patterns/ThisOrTargetTestCase.java View File

@@ -15,6 +15,9 @@ package org.aspectj.weaver.patterns;

import java.io.*;

import org.aspectj.lang.JoinPoint;
import org.aspectj.runtime.reflect.Factory;
import org.aspectj.util.FuzzyBoolean;
import org.aspectj.weaver.bcel.*;

import junit.framework.TestCase;
@@ -46,6 +49,46 @@ public class ThisOrTargetTestCase extends TestCase {

}
public void testMatchJP() {
Factory f = new Factory("ThisOrTargetTestCase.java",ThisOrTargetTestCase.class);
Pointcut thisEx = new PatternParser("this(Exception)").parsePointcut().resolve();
Pointcut thisIOEx = new PatternParser("this(java.io.IOException)").parsePointcut().resolve();

Pointcut targetEx = new PatternParser("target(Exception)").parsePointcut().resolve();
Pointcut targetIOEx = new PatternParser("target(java.io.IOException)").parsePointcut().resolve();

JoinPoint.StaticPart jpsp1 = f.makeSJP(JoinPoint.EXCEPTION_HANDLER,f.makeCatchClauseSig(HandlerTestCase.class,Exception.class,"ex"),1);
JoinPoint thisExJP = Factory.makeJP(jpsp1,new Exception(),this);
JoinPoint thisIOExJP = Factory.makeJP(jpsp1,new IOException(),this);
JoinPoint targetExJP = Factory.makeJP(jpsp1,this,new Exception());
JoinPoint targetIOExJP = Factory.makeJP(jpsp1,this,new IOException());
checkMatches(thisEx,thisExJP,null,FuzzyBoolean.YES);
checkMatches(thisIOEx,thisExJP,null,FuzzyBoolean.NO);
checkMatches(targetEx,thisExJP,null,FuzzyBoolean.NO);
checkMatches(targetIOEx,thisExJP,null,FuzzyBoolean.NO);

checkMatches(thisEx,thisIOExJP,null,FuzzyBoolean.YES);
checkMatches(thisIOEx,thisIOExJP,null,FuzzyBoolean.YES);
checkMatches(targetEx,thisIOExJP,null,FuzzyBoolean.NO);
checkMatches(targetIOEx,thisIOExJP,null,FuzzyBoolean.NO);

checkMatches(thisEx,targetExJP,null,FuzzyBoolean.NO);
checkMatches(thisIOEx,targetExJP,null,FuzzyBoolean.NO);
checkMatches(targetEx,targetExJP,null,FuzzyBoolean.YES);
checkMatches(targetIOEx,targetExJP,null,FuzzyBoolean.NO);

checkMatches(thisEx,targetIOExJP,null,FuzzyBoolean.NO);
checkMatches(thisIOEx,targetIOExJP,null,FuzzyBoolean.NO);
checkMatches(targetEx,targetIOExJP,null,FuzzyBoolean.YES);
checkMatches(targetIOEx,targetIOExJP,null,FuzzyBoolean.YES);
}
private void checkMatches(Pointcut p, JoinPoint jp, JoinPoint.StaticPart jpsp, FuzzyBoolean expected) {
assertEquals(expected,p.match(jp,jpsp));
}

// private Pointcut makePointcut(String pattern) {
// return new PatternParser(pattern).parsePointcut();

+ 63
- 0
weaver/testsrc/org/aspectj/weaver/patterns/WithinCodeTestCase.java View File

@@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.aspectj.weaver.patterns;

import org.aspectj.lang.JoinPoint;
import org.aspectj.runtime.reflect.Factory;
import org.aspectj.util.FuzzyBoolean;

import junit.framework.TestCase;


public class WithinCodeTestCase extends TestCase {
Pointcut withinCode1;
Pointcut withinCode2;
Pointcut withinCode3;

public void testMatchJP() {
Factory f = new Factory("WithinCodeTestCase.java",WithinCodeTestCase.class);
// JoinPoints to match against...
JoinPoint.StaticPart exejp1 = f.makeSJP(JoinPoint.METHOD_EXECUTION,f.makeMethodSig(0,"toString",Object.class,new Class[] {},new String[] {},new Class[0],String.class),1);
JoinPoint.StaticPart exejp2 = f.makeSJP(JoinPoint.METHOD_EXECUTION,f.makeMethodSig(0,"sayHi",Hello.class,new Class[] {String.class},new String[] {"s"},new Class[0],void.class),1);
JoinPoint.StaticPart execonsjp1 = f.makeSJP(JoinPoint.CONSTRUCTOR_EXECUTION,f.makeConstructorSig(0,Object.class,new Class[0],new String[0],new Class[0]),1);
JoinPoint.StaticPart execonsjp2 = f.makeSJP(JoinPoint.CONSTRUCTOR_EXECUTION,f.makeConstructorSig(0,String.class,new Class[] {String.class},new String[]{"s"},new Class[0]),1);
checkMatches(withinCode1,exejp1,FuzzyBoolean.YES);
checkMatches(withinCode1,exejp2,FuzzyBoolean.NO);
checkMatches(withinCode1,execonsjp1,FuzzyBoolean.NO);
checkMatches(withinCode1,execonsjp2,FuzzyBoolean.NO);

checkMatches(withinCode2,exejp1,FuzzyBoolean.NO);
checkMatches(withinCode2,exejp2,FuzzyBoolean.NO);
checkMatches(withinCode2,execonsjp1,FuzzyBoolean.YES);
checkMatches(withinCode2,execonsjp2,FuzzyBoolean.YES);

checkMatches(withinCode3,exejp1,FuzzyBoolean.NO);
checkMatches(withinCode3,exejp2,FuzzyBoolean.NO);
checkMatches(withinCode3,execonsjp1,FuzzyBoolean.NO);
checkMatches(withinCode3,execonsjp2,FuzzyBoolean.YES);

}
private void checkMatches(Pointcut p, JoinPoint.StaticPart jpsp, FuzzyBoolean expected) {
assertEquals(expected,p.match(null,jpsp));
}
protected void setUp() throws Exception {
super.setUp();
withinCode1 = new PatternParser("withincode(String Object.toString())").parsePointcut().resolve();
withinCode2 = new PatternParser("withincode(new(..))").parsePointcut().resolve();
withinCode3 = new PatternParser("withincode(String.new(..))").parsePointcut().resolve();
}
private static class Hello {};
}

+ 25
- 0
weaver/testsrc/org/aspectj/weaver/patterns/WithinTestCase.java View File

@@ -19,6 +19,8 @@ import junit.framework.TestCase;

import org.aspectj.weaver.*;
import org.aspectj.weaver.bcel.BcelWorld;
import org.aspectj.lang.JoinPoint;
import org.aspectj.runtime.reflect.Factory;
import org.aspectj.util.FuzzyBoolean;

public class WithinTestCase extends TestCase {
@@ -67,6 +69,29 @@ public class WithinTestCase extends TestCase {

}

public void testMatchJP() {
Factory f = new Factory("WithinTestCase.java",WithinTestCase.class);
JoinPoint.StaticPart inString = f.makeSJP(JoinPoint.CONSTRUCTOR_EXECUTION,f.makeConstructorSig(0,String.class,new Class[] {String.class},new String[]{"s"},new Class[0]),1);
JoinPoint.StaticPart inObject = f.makeSJP(JoinPoint.CONSTRUCTOR_EXECUTION,f.makeConstructorSig(0,Object.class,new Class[] {},new String[]{},new Class[0]),1);

Pointcut withinString = new PatternParser("within(String)").parsePointcut().resolve();
Pointcut withinObject = new PatternParser("within(Object)").parsePointcut().resolve();
Pointcut withinObjectPlus = new PatternParser("within(Object+)").parsePointcut().resolve();
checkMatches(withinString,inString,FuzzyBoolean.YES);
checkMatches(withinString,inObject,FuzzyBoolean.NO);
checkMatches(withinObject,inString,FuzzyBoolean.NO);
checkMatches(withinObject,inObject, FuzzyBoolean.YES);
checkMatches(withinObjectPlus,inString,FuzzyBoolean.YES);
checkMatches(withinObjectPlus,inObject,FuzzyBoolean.YES);
}
private void checkMatches(Pointcut p, JoinPoint.StaticPart jpsp, FuzzyBoolean expected) {
assertEquals(expected,p.match(null,jpsp));
}
public Pointcut makePointcut(String pattern) {
Pointcut pointcut0 = Pointcut.fromString(pattern);

Loading…
Cancel
Save