You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TraceJoinPointsTest.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* *******************************************************************
  2. * Copyright (c) 2005 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Wes Isberg initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.lib.tracing;
  13. import junit.framework.TestCase;
  14. import org.aspectj.lang.JoinPoint.StaticPart;
  15. /**
  16. *
  17. */
  18. public class TraceJoinPointsTest extends TestCase {
  19. public void testTraceJoinPoints() {
  20. checkTjp();
  21. TestTJP aspect = TestTJP.aspectOf();
  22. assertNotNull("aspect", aspect);
  23. assertTrue("checked", aspect.checked);
  24. }
  25. static final int NUMJP = 1;
  26. static void checkTjp() {
  27. // NUMJP: only 1 join point
  28. long l = System.currentTimeMillis();
  29. }
  30. /** poor design/test */
  31. static aspect TestTJP extends TraceJoinPoints {
  32. protected pointcut withinScope() : within(TraceJoinPointsTest)
  33. && !within(TestTJP);
  34. pointcut traceJoinPoints() :
  35. execution(static void TraceJoinPointsTest.testTraceJoinPoints());
  36. protected pointcut entry() :
  37. execution(static void TraceJoinPointsTest.checkTjp());
  38. boolean checked;
  39. int logEnter = 10;
  40. int logExit = 10;
  41. int startLog = 10;
  42. int completeLog = 10;
  43. protected void logEnter(StaticPart jp) {
  44. logEnter++;
  45. }
  46. protected void logExit(StaticPart jp) {
  47. logExit++;
  48. }
  49. protected void startLog() {
  50. startLog = 0;
  51. completeLog = 0;
  52. logEnter = 0;
  53. logExit = 0;
  54. startLog++;
  55. }
  56. protected void completeLog() {
  57. completeLog++;
  58. }
  59. after() returning : entry() {
  60. assertEquals("startLog", 1, startLog);
  61. assertEquals("completeLog", 1, startLog);
  62. assertEquals("logExit", NUMJP, startLog);
  63. assertEquals("logEntry", NUMJP, startLog);
  64. assertTrue(!checked);
  65. checked = true;
  66. }
  67. }
  68. }