From cf8974d359278832b73d10890eca625f485acb5c Mon Sep 17 00:00:00 2001 From: acolyer Date: Tue, 8 Jun 2004 15:05:10 +0000 Subject: [PATCH] additional test cases to cover matching Pointcuts against JoinPoints --- .../weaver/patterns/AndOrNotTestCase.java | 36 +++++++ .../aspectj/weaver/patterns/ArgsTestCase.java | 91 ++++++++++++++++ .../weaver/patterns/HandlerTestCase.java | 65 +++++++++++ .../weaver/patterns/KindedTestCase.java | 102 ++++++++++++++++++ .../weaver/patterns/PatternsTests.java | 5 + .../weaver/patterns/PointcutTestCase.java | 79 ++++++++++++++ .../weaver/patterns/ThisOrTargetTestCase.java | 43 ++++++++ .../weaver/patterns/WithinCodeTestCase.java | 63 +++++++++++ .../weaver/patterns/WithinTestCase.java | 25 +++++ 9 files changed, 509 insertions(+) create mode 100644 weaver/testsrc/org/aspectj/weaver/patterns/ArgsTestCase.java create mode 100644 weaver/testsrc/org/aspectj/weaver/patterns/HandlerTestCase.java create mode 100644 weaver/testsrc/org/aspectj/weaver/patterns/KindedTestCase.java create mode 100644 weaver/testsrc/org/aspectj/weaver/patterns/PointcutTestCase.java create mode 100644 weaver/testsrc/org/aspectj/weaver/patterns/WithinCodeTestCase.java diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/AndOrNotTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/AndOrNotTestCase.java index 26d8e1207..45f9b59d5 100644 --- a/weaver/testsrc/org/aspectj/weaver/patterns/AndOrNotTestCase.java +++ b/weaver/testsrc/org/aspectj/weaver/patterns/AndOrNotTestCase.java @@ -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