aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/test/java/org/aspectj/systemtest/ajc190/EfficientTJPTests.java
blob: dc0392089d1ca71c88dfb50b300acccd802b87d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*******************************************************************************
 * Copyright (c) 2018 Contributors
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
 *******************************************************************************/
package org.aspectj.systemtest.ajc190;

import org.aspectj.apache.bcel.classfile.JavaClass;
import org.aspectj.apache.bcel.classfile.Method;
import org.aspectj.testing.XMLBasedAjcTestCase;

import org.junit.Assert;
import junit.framework.Test;

/**
 *
 * @author Andy Clement
 */
public class EfficientTJPTests extends XMLBasedAjcTestCase {

	public void testThisJoinPointMethodExecution() {
		// Test setting it via sys props rather than passing the option directly
		try {
			System.setProperty("ASPECTJ_OPTS", "-Xajruntimetarget:1.9");
			runTest("tjp 1");
			checkPreClinitContains("One","Factory.makeMethodSJP");
		} finally {
			System.setProperty("ASPECTJ_OPTS", "");
		}
	}

	public void testThisEnclosingJoinPointMethodExecution() {
		runTest("tjp 2");
		checkPreClinitContains("Two","Factory.makeMethodESJP");
	}

	public void testThisJoinPointConstructorExecution() {
		runTest("tjp 3");
		checkPreClinitContains("Three","Factory.makeConstructorSJP");
	}

	public void testThisEnclosingJoinPointConstructorExecution() {
		runTest("tjp 3a");
		checkPreClinitContains("ThreeA","Factory.makeConstructorESJP");
	}

	public void testThisJoinPointHandler() {
		runTest("tjp 4");
		checkPreClinitContains("Four","Factory.makeCatchClauseSJP");
	}

	public void testThisEnclosingJoinPointHandler() {
		runTest("tjp 4a");
		checkPreClinitContains("FourA","Factory.makeMethodESJP");
	}

	public void testThisJoinPointFieldGet() {
		runTest("tjp get fields");
		checkPreClinitContains("Fields","Factory.makeFieldSJP");
	}

	public void testThisEnclosingJoinPointFieldGet() {
		runTest("tjp get fieldsE");
		checkPreClinitContains("FieldsE","Factory.makeMethodESJP");
	}

	public void testThisJoinPointFieldSet() {
		runTest("tjp set fields");
		checkPreClinitContains("Fields2","Factory.makeFieldSJP");
	}

	public void testThisJoinPointClinit() {
		runTest("tjp clinit");
		checkPreClinitContains("Clinit","Factory.makeInitializerSJP");
	}

	public void testThisEnclosingJoinPointClinit() {
		runTest("tejp clinit");
		checkPreClinitContains("ClinitE","Factory.makeInitializerESJP");
	}

	public void testThisJoinPointAdvice() {
		// covers enclosing joinpoint too
		runTest("tjp advice");
		checkPreClinitContains("X","Factory.makeAdviceESJP");
	}

	public void testThisJoinPointInitialization() {
		runTest("tjp init");
		checkPreClinitContains("A","Factory.makeConstructorESJP");
		checkPreClinitContains("B","Factory.makeConstructorESJP");
	}

	// ///////////////////////////////////////
	public static Test suite() {
		return XMLBasedAjcTestCase.loadSuite(EfficientTJPTests.class);
	}

	@Override
	protected java.net.URL getSpecFile() {
		return getClassResource("features190.xml");
	}

	public void checkPreClinitContains(String classname, String text) {
		try {
			JavaClass jc = getClassFrom(ajc.getSandboxDirectory(), classname);
			Method[] meths = jc.getMethods();
			for (Method method : meths) {
				if (method.getName().equals("ajc$preClinit")) {
					String code = method.getCode().getCodeString();
					assertTrue("Expected to contain '" + text + "':\n" + code, code.contains(text));
					return;
				}
			}
			Assert.fail("Unable to find ajc$preClinit in class "+classname);
		} catch (Exception e) {
			Assert.fail(e.toString());
		}
	}

}