aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/test/java/org/aspectj/systemtest/ajc151/NewarrayJoinpointTests.java
blob: 140a3ee1e46b258fd07276ab3e41c971f7d07e76 (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
124
125
126
127
128
129
130
131
132
133
134
135
/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation and others.
 * 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
 *
 * Contributors:
 *     Andy Clement - initial implementation
 *******************************************************************************/
package org.aspectj.systemtest.ajc151;

import java.util.List;

import org.aspectj.asm.AsmManager;
import org.aspectj.asm.IProgramElement;
import org.aspectj.asm.IRelationship;
import org.aspectj.testing.XMLBasedAjcTestCase;

import junit.framework.Test;

/*
 * The design:
 *
 * There are 3 instructions that create arrays:
 *
 * - NEWARRAY for primitive arrays
 * - ANEWARRAY for object arrays
 * - MULTIANEWARRAY for multidimensional arrays
 *
 * The changes to expose the new joinpoint are in:
 *   BcelClassWeaver.match(LazyMethodGen mg,InstructionHandle ih,BcelShadow enclosingShadow,List shadowAccumulator)
 *
 * Determining the type of the array is easy.  Determining the size of the array is not easy statically, it is on the stack.
 *
 *
 * What still needs testing:
 * - structure model
 *
 */

public class NewarrayJoinpointTests extends XMLBasedAjcTestCase {

	// when its the creation of a new 'object' (not a primitive) single dimension array
	public void testTheBasics_1() {
		runTest("basics");
	}

	public void testTheBasics_2() {
		runTest("basics - 2");
	}

	public void testWhatShouldntMatch() {
		runTest("shouldnt match");
	}

	public void testThisJoinPoint() {
		runTest("thisjoinpoint");
	}

	public void testThisJoinPoint19() {
		try {
			System.setProperty("ASPECTJ_OPTS", "-Xajruntimetarget:1.9");
			runTest("thisjoinpoint");
		} finally {
			System.setProperty("ASPECTJ_OPTS", "");
		}
	}

	public void testDifferentAdviceKinds() {
		runTest("different advice kinds");
	}

	public void testArgs() {
		runTest("args");
	}

	// when it is the creation of a new array of primitives
	public void testBasicWithAPrimitiveArray() {
		runTest("basic primitive array creation");
	}

	// when it is the creation of a new multi-dimensional array
	public void testBasicWithAMultiDimensionalArray() {
		runTest("multi dimensional array creation");
	}

	public void testArgsWithAMultiDimensionalArray() {
		runTest("multi dimensional array args");
	}

	// various
	public void testOptionoff() {
		runTest("option deactivated - no match expected");
	}

	public void testUsingTargetAndAfterReturningAdvice() {
		runTest("using target and after returning");
	}

	public void testUsingItForReal() {
		runTest("using it for real");
	}

	public void testDifferentiatingArrayTypes() {
		runTest("differentiating array types");
	}

	public void testStructureModel() {
		// AsmManager.setReporting("c:/foo.txt",true,true,true,true);
		runTest("structure model");
		IProgramElement ipe = AsmManager.lastActiveStructureModel.getHierarchy().findElementForType("", "Five");
		assertTrue("Couldnt find 'Five' type in the model", ipe != null);
		List<IProgramElement> kids = ipe.getChildren();
		assertTrue("Couldn't find 'main' method in the 'Five' type", kids != null && kids.size() == 1);
		List<IProgramElement> codenodes = kids.get(0).getChildren();
		assertTrue("Couldn't find nodes below 'main' method", codenodes != null && codenodes.size() == 1);
		IProgramElement arrayCtorCallNode = codenodes.get(0);
		String exp = "constructor-call(void java.lang.Integer[].<init>(int))";
		assertTrue("Expected '" + exp + "' but found " + arrayCtorCallNode.toString(), arrayCtorCallNode.toString().equals(exp));
		List<IRelationship> rels = AsmManager.lastActiveStructureModel.getRelationshipMap().get(arrayCtorCallNode);
		assertTrue("Should have a relationship from the ctorcall node, but didn't find one?", rels != null && rels.size() == 1);
	}

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

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

}